OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // We handle some special browser-level URLs (like "about:version") | 5 // We handle some special browser-level URLs (like "about:version") |
6 // before they're handed to a renderer. This lets us do the URL handling | 6 // before they're handed to a renderer. This lets us do the URL handling |
7 // on the browser side (which has access to more information than the | 7 // on the browser side (which has access to more information than the |
8 // renderers do) as well as sidestep the risk of exposing data to | 8 // renderers do) as well as sidestep the risk of exposing data to |
9 // random web pages (because from the resource loader's perspective, these | 9 // random web pages (because from the resource loader's perspective, these |
10 // URL schemes don't exist). | 10 // URL schemes don't exist). |
11 | 11 |
12 #ifndef CONTENT_BROWSER_BROWSER_URL_HANDLER_H_ | 12 #ifndef CONTENT_BROWSER_BROWSER_URL_HANDLER_H_ |
13 #define CONTENT_BROWSER_BROWSER_URL_HANDLER_H_ | 13 #define CONTENT_BROWSER_BROWSER_URL_HANDLER_H_ |
14 #pragma once | 14 #pragma once |
15 | 15 |
16 #include <vector> | 16 #include <vector> |
17 #include <utility> | 17 #include <utility> |
18 | 18 |
19 #include "base/gtest_prod_util.h" | 19 #include "base/gtest_prod_util.h" |
20 #include "base/memory/singleton.h" | 20 #include "base/memory/singleton.h" |
21 | 21 |
22 class GURL; | 22 class GURL; |
23 class Profile; | 23 |
| 24 namespace content { |
| 25 class BrowserContext; |
| 26 } |
24 | 27 |
25 // BrowserURLHandler manages the list of all special URLs and manages | 28 // BrowserURLHandler manages the list of all special URLs and manages |
26 // dispatching the URL handling to registered handlers. | 29 // dispatching the URL handling to registered handlers. |
27 class BrowserURLHandler { | 30 class BrowserURLHandler { |
28 public: | 31 public: |
29 // The type of functions that can process a URL. | 32 // The type of functions that can process a URL. |
30 // If a handler handles |url|, it should : | 33 // If a handler handles |url|, it should : |
31 // - optionally modify |url| to the URL that should be sent to the renderer | 34 // - optionally modify |url| to the URL that should be sent to the renderer |
32 // If the URL is not handled by a handler, it should return false. | 35 // If the URL is not handled by a handler, it should return false. |
33 typedef bool (*URLHandler)(GURL* url, Profile* profile); | 36 typedef bool (*URLHandler)(GURL* url, |
| 37 content::BrowserContext* browser_context); |
34 | 38 |
35 // Returns the singleton instance. | 39 // Returns the singleton instance. |
36 static BrowserURLHandler* GetInstance(); | 40 static BrowserURLHandler* GetInstance(); |
37 | 41 |
38 // RewriteURLIfNecessary gives all registered URLHandlers a shot at processing | 42 // RewriteURLIfNecessary gives all registered URLHandlers a shot at processing |
39 // the given URL, and modifies it in place. | 43 // the given URL, and modifies it in place. |
40 // If the original URL needs to be adjusted if the modified URL is redirected, | 44 // If the original URL needs to be adjusted if the modified URL is redirected, |
41 // this function sets |reverse_on_redirect| to true. | 45 // this function sets |reverse_on_redirect| to true. |
42 void RewriteURLIfNecessary(GURL* url, Profile* profile, | 46 void RewriteURLIfNecessary(GURL* url, |
| 47 content::BrowserContext* browser_context, |
43 bool* reverse_on_redirect); | 48 bool* reverse_on_redirect); |
44 | 49 |
45 // Reverses the rewriting that was done for |original| using the new |url|. | 50 // Reverses the rewriting that was done for |original| using the new |url|. |
46 bool ReverseURLRewrite(GURL* url, const GURL& original, | 51 bool ReverseURLRewrite(GURL* url, const GURL& original, |
47 Profile* profile); | 52 content::BrowserContext* browser_context); |
48 | 53 |
49 // Add the specified handler pair to the list of URL handlers. | 54 // Add the specified handler pair to the list of URL handlers. |
50 void AddHandlerPair(URLHandler handler, URLHandler reverse_handler); | 55 void AddHandlerPair(URLHandler handler, URLHandler reverse_handler); |
51 | 56 |
52 // Returns the null handler for use with |AddHandlerPair()|. | 57 // Returns the null handler for use with |AddHandlerPair()|. |
53 static URLHandler null_handler(); | 58 static URLHandler null_handler(); |
54 | 59 |
55 private: | 60 private: |
56 // This object is a singleton: | 61 // This object is a singleton: |
57 BrowserURLHandler(); | 62 BrowserURLHandler(); |
58 ~BrowserURLHandler(); | 63 ~BrowserURLHandler(); |
59 friend struct DefaultSingletonTraits<BrowserURLHandler>; | 64 friend struct DefaultSingletonTraits<BrowserURLHandler>; |
60 | 65 |
61 // The list of known URLHandlers, optionally with reverse-rewriters. | 66 // The list of known URLHandlers, optionally with reverse-rewriters. |
62 typedef std::pair<URLHandler, URLHandler> HandlerPair; | 67 typedef std::pair<URLHandler, URLHandler> HandlerPair; |
63 std::vector<HandlerPair> url_handlers_; | 68 std::vector<HandlerPair> url_handlers_; |
64 | 69 |
65 FRIEND_TEST_ALL_PREFIXES(BrowserURLHandlerTest, BasicRewriteAndReverse); | 70 FRIEND_TEST_ALL_PREFIXES(BrowserURLHandlerTest, BasicRewriteAndReverse); |
66 FRIEND_TEST_ALL_PREFIXES(BrowserURLHandlerTest, NullHandlerReverse); | 71 FRIEND_TEST_ALL_PREFIXES(BrowserURLHandlerTest, NullHandlerReverse); |
67 | 72 |
68 DISALLOW_COPY_AND_ASSIGN(BrowserURLHandler); | 73 DISALLOW_COPY_AND_ASSIGN(BrowserURLHandler); |
69 }; | 74 }; |
70 | 75 |
71 #endif // CONTENT_BROWSER_BROWSER_URL_HANDLER_H_ | 76 #endif // CONTENT_BROWSER_BROWSER_URL_HANDLER_H_ |
OLD | NEW |