Home | History | Annotate | Download | only in browser
      1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef CONTENT_PUBLIC_BROWSER_BROWSER_URL_HANDLER_H_
      6 #define CONTENT_PUBLIC_BROWSER_BROWSER_URL_HANDLER_H_
      7 
      8 #include "content/common/content_export.h"
      9 
     10 class GURL;
     11 
     12 namespace content {
     13 class BrowserContext;
     14 
     15 // We handle some special browser-level URLs (like "about:version")
     16 // before they're handed to a renderer.  This lets us do the URL handling
     17 // on the browser side (which has access to more information than the
     18 // renderers do) as well as sidestep the risk of exposing data to
     19 // random web pages (because from the resource loader's perspective, these
     20 // URL schemes don't exist).
     21 // BrowserURLHandler manages the list of all special URLs and manages
     22 // dispatching the URL handling to registered handlers.
     23 class CONTENT_EXPORT BrowserURLHandler {
     24  public:
     25   // The type of functions that can process a URL.
     26   // If a handler handles |url|, it should :
     27   // - optionally modify |url| to the URL that should be sent to the renderer
     28   // If the URL is not handled by a handler, it should return false.
     29   typedef bool (*URLHandler)(GURL* url,
     30                              BrowserContext* browser_context);
     31 
     32   // Returns the null handler for use with |AddHandlerPair()|.
     33   static URLHandler null_handler();
     34 
     35   // Returns the singleton instance.
     36   static  BrowserURLHandler* GetInstance();
     37 
     38   // RewriteURLIfNecessary gives all registered URLHandlers a shot at processing
     39   // the given URL, and modifies it in place.
     40   // If the original URL needs to be adjusted if the modified URL is redirected,
     41   // this function sets |reverse_on_redirect| to true.
     42   virtual void RewriteURLIfNecessary(GURL* url,
     43                                      BrowserContext* browser_context,
     44                                      bool* reverse_on_redirect) = 0;
     45 
     46   // Add the specified handler pair to the list of URL handlers.
     47   //
     48   // Note that normally, the reverse handler is only used if the modified URL is
     49   // not modified, e.g., by adding a hash fragment. To support this behavior,
     50   // register the forward and reverse handlers separately, each with a
     51   // null_handler() for the opposite direction.
     52   virtual void AddHandlerPair(URLHandler handler,
     53                               URLHandler reverse_handler) = 0;
     54 
     55  protected:
     56   virtual ~BrowserURLHandler() {}
     57 };
     58 
     59 }  // namespace content
     60 
     61 #endif  // CONTENT_PUBLIC_BROWSER_BROWSER_URL_HANDLER_H_
     62