Re-subimission of https://codereview.chromium.org/1041213003/
[chromium-blink-merge.git] / content / public / browser / browser_url_handler.h
blob964741f6861d6fc72f97f54b3a7d566a5059a82b
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.
5 #ifndef CONTENT_PUBLIC_BROWSER_BROWSER_URL_HANDLER_H_
6 #define CONTENT_PUBLIC_BROWSER_BROWSER_URL_HANDLER_H_
8 #include "content/common/content_export.h"
10 class GURL;
12 namespace content {
13 class BrowserContext;
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);
32 // Returns the null handler for use with |AddHandlerPair()|.
33 static URLHandler null_handler();
35 // Returns the singleton instance.
36 static BrowserURLHandler* GetInstance();
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;
46 // Set the specified handler as a preliminary fixup phase to be done before
47 // rewriting. This allows minor cleanup for the URL without having it affect
48 // the virtual URL.
49 virtual void SetFixupHandler(URLHandler handler) = 0;
51 // Add the specified handler pair to the list of URL handlers.
53 // Note that normally, the reverse handler is only used if the modified URL is
54 // not modified, e.g., by adding a hash fragment. To support this behavior,
55 // register the forward and reverse handlers separately, each with a
56 // null_handler() for the opposite direction.
57 virtual void AddHandlerPair(URLHandler handler,
58 URLHandler reverse_handler) = 0;
60 protected:
61 virtual ~BrowserURLHandler() {}
64 } // namespace content
66 #endif // CONTENT_PUBLIC_BROWSER_BROWSER_URL_HANDLER_H_