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   virtual void RewriteURLIfNecessary(GURL* url,
41                                      BrowserContext* browser_context) = 0;
42 
43   // Set the specified handler as a preliminary fixup phase to be done before
44   // rewriting.  This allows minor cleanup for the URL without having it affect
45   // the virtual URL.
46   virtual void SetFixupHandler(URLHandler handler) = 0;
47 
48   // Add the specified handler pair to the list of URL handlers.
49   //
50   // Note that normally, the reverse handler is only used if the modified URL is
51   // not modified, e.g., by adding a hash fragment. To support this behavior,
52   // register the forward and reverse handlers separately, each with a
53   // null_handler() for the opposite direction.
54   virtual void AddHandlerPair(URLHandler handler,
55                               URLHandler reverse_handler) = 0;
56 
57  protected:
~BrowserURLHandler()58   virtual ~BrowserURLHandler() {}
59 };
60 
61 }  // namespace content
62 
63 #endif  // CONTENT_PUBLIC_BROWSER_BROWSER_URL_HANDLER_H_
64