Hi Eric,

I have just tried the code that you have suggested, however, if I
enter a URL in the Chromium location bar and hit enter, Chromium is
still defaulting to a Google search.

I have tried placing a breakpoint within the constructor and each of
the virtual methods, and the factory method. When running in debug
mode, none of these breakpoints are being hit. I tried adding a
breakpoint directly after the factory is being registered, and the
program is breaking at this point.

Thanks for your help!

On 29 July, 22:32, Eric Roman <ero...@chromium.org> wrote:
> You are pretty close.
>
> What you want to do is override URLRequestJob::IsRedirectResponse(),
> rather than trying to do the redirect in the factory.
>
> Something like this should work:
>
> class URLRequestCustomJob : public URLRequestJob {
>  public:
>   explicit URLRequestCustomJob(URLRequest* request) : URLRequestJob(request) 
> {}
>
>   // URLRequestJob methods:
>   virtual void Start() {
>     NotifyHeadersComplete();
>   }
>
>   virtual bool IsRedirectResponse(GURL* location, int* http_status_code) {
>     *http_status_code = 301;
>     *location = GURL("http://i-redirected-you/cuz-im-the-awesome";);
>     return true;
>   }
>
>   static URLRequestJob* Factory(URLRequest* request, const
> std::string& scheme) {
>     return new URLRequestCustomJob(request);
>   }
>
>
>
> };
> On Mon, Jul 27, 2009 at 5:44 PM, Kruncher<leaha...@gmail.com> wrote:
>
> > Hi,
>
> > I am trying to add a custom scheme to the Chromium browser. I am
> > trying to write a scheme that will transparently redirect requests to
> > another URL.
>
> > For some reason, however, my custom scheme does not appear to get
> > recognized. Could somebody tell me what I am doing wrong?
>
> > For the time being I have added the following code to the
> > "chrome_exe_main.cc" source.
>
> > //
> > // Added above the main Windows function.
> > //
>
> > #include "net/url_request/url_request.h"
> > #include "net/url_request/url_request_http_job.h"
>
> > static const char kCustomURLScheme[] = "my-scheme";
>
> > class URLRequestCustomJob : public URLRequestJob {
> >  public:
> >  static URLRequestJob* Factory(URLRequest* request, const
> > std::string& scheme) {
> >          DCHECK(scheme == "my-scheme");
>
> >          // Redirect response to a local network resource.
> >          std::string& requestPath = request->url().PathForRequest().replace
> > (0, 10, "http://192.168.1.4:8080";);
>
> >          // I tried using the following line, but it turns out that the
> > "Redirect" function is protected.
> >          //request->Redirect(GURL(requestPath), request->status().status());
> >          // So instead I am attempting to create a new request.
> >          request = new URLRequest(GURL(requestPath), request->delegate());
>
> >          // Proceed with regular HTTP scheme factory.
> >          return URLRequestHttpJob::Factory(request, "http");
> >        }
> > };
>
> > //
> > // Added above "#if defined(GOOGLE_CHROME_BUILD)" inside Windows main
> > function.
> > //
>
> > // Register custom scheme:
> > url_util::AddStandardScheme(kCustomURLScheme);
> > URLRequest::RegisterProtocolFactory(kCustomURLScheme,
> > &URLRequestCustomJob::Factory);
>
> > Many thanks,
> > Lea Hayes
--~--~---------~--~----~------------~-------~--~----~
Chromium Developers mailing list: chromium-dev@googlegroups.com 
View archives, change email options, or unsubscribe: 
    http://groups.google.com/group/chromium-dev
-~----------~----~----~----~------~----~------~--~---

Reply via email to