OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef CONTENT_BROWSER_BROWSER_URL_HANDLER_IMPL_H_ | 5 #ifndef CONTENT_BROWSER_BROWSER_URL_HANDLER_IMPL_H_ |
6 #define CONTENT_BROWSER_BROWSER_URL_HANDLER_IMPL_H_ | 6 #define CONTENT_BROWSER_BROWSER_URL_HANDLER_IMPL_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
11 #include "base/gtest_prod_util.h" | 11 #include "base/gtest_prod_util.h" |
12 #include "base/memory/singleton.h" | 12 #include "base/memory/singleton.h" |
13 #include "content/public/browser/browser_url_handler.h" | 13 #include "content/public/browser/browser_url_handler.h" |
14 | 14 |
15 class GURL; | 15 class GURL; |
16 | 16 |
17 namespace content { | 17 namespace content { |
18 class BrowserContext; | 18 class BrowserContext; |
19 | 19 |
20 class CONTENT_EXPORT BrowserURLHandlerImpl : public BrowserURLHandler { | 20 class CONTENT_EXPORT BrowserURLHandlerImpl : public BrowserURLHandler { |
21 public: | 21 public: |
22 // Returns the singleton instance. | 22 // Returns the singleton instance. |
23 static BrowserURLHandlerImpl* GetInstance(); | 23 static BrowserURLHandlerImpl* GetInstance(); |
24 | 24 |
25 // BrowserURLHandler implementation: | 25 // BrowserURLHandler implementation: |
26 void RewriteURLIfNecessary(GURL* url, | 26 void RewriteURLIfNecessary(GURL* url, |
27 BrowserContext* browser_context, | 27 BrowserContext* browser_context, |
28 bool* reverse_on_redirect) override; | 28 bool* reverse_on_redirect) override; |
| 29 void SetFixupHandler(URLHandler handler) override; |
29 // Add the specified handler pair to the list of URL handlers. | 30 // Add the specified handler pair to the list of URL handlers. |
30 void AddHandlerPair(URLHandler handler, URLHandler reverse_handler) override; | 31 void AddHandlerPair(URLHandler handler, URLHandler reverse_handler) override; |
31 | 32 |
| 33 // Fixes up the URL before rewriting occurs. |
| 34 void FixupURLBeforeRewrite(GURL* url, BrowserContext* browser_context); |
| 35 |
32 // Reverses the rewriting that was done for |original| using the new |url|. | 36 // Reverses the rewriting that was done for |original| using the new |url|. |
33 bool ReverseURLRewrite(GURL* url, const GURL& original, | 37 bool ReverseURLRewrite(GURL* url, const GURL& original, |
34 BrowserContext* browser_context); | 38 BrowserContext* browser_context); |
35 | 39 |
36 private: | 40 private: |
37 // This object is a singleton: | 41 // This object is a singleton: |
38 BrowserURLHandlerImpl(); | 42 BrowserURLHandlerImpl(); |
39 ~BrowserURLHandlerImpl() override; | 43 ~BrowserURLHandlerImpl() override; |
40 friend struct DefaultSingletonTraits<BrowserURLHandlerImpl>; | 44 friend struct DefaultSingletonTraits<BrowserURLHandlerImpl>; |
41 | 45 |
| 46 // A URLHandler to run in a preliminary phase, before rewriting is done. |
| 47 URLHandler fixup_handler_; |
| 48 |
42 // The list of known URLHandlers, optionally with reverse-rewriters. | 49 // The list of known URLHandlers, optionally with reverse-rewriters. |
43 typedef std::pair<URLHandler, URLHandler> HandlerPair; | 50 typedef std::pair<URLHandler, URLHandler> HandlerPair; |
44 std::vector<HandlerPair> url_handlers_; | 51 std::vector<HandlerPair> url_handlers_; |
45 | 52 |
46 FRIEND_TEST_ALL_PREFIXES(BrowserURLHandlerImplTest, BasicRewriteAndReverse); | 53 FRIEND_TEST_ALL_PREFIXES(BrowserURLHandlerImplTest, BasicRewriteAndReverse); |
47 FRIEND_TEST_ALL_PREFIXES(BrowserURLHandlerImplTest, NullHandlerReverse); | 54 FRIEND_TEST_ALL_PREFIXES(BrowserURLHandlerImplTest, NullHandlerReverse); |
48 FRIEND_TEST_ALL_PREFIXES(BrowserURLHandlerImplTest, ViewSourceReverse); | 55 FRIEND_TEST_ALL_PREFIXES(BrowserURLHandlerImplTest, ViewSourceReverse); |
49 | 56 |
50 DISALLOW_COPY_AND_ASSIGN(BrowserURLHandlerImpl); | 57 DISALLOW_COPY_AND_ASSIGN(BrowserURLHandlerImpl); |
51 }; | 58 }; |
52 | 59 |
53 } // namespace content | 60 } // namespace content |
54 | 61 |
55 #endif // CONTENT_BROWSER_BROWSER_URL_HANDLER_IMPL_H_ | 62 #endif // CONTENT_BROWSER_BROWSER_URL_HANDLER_IMPL_H_ |
OLD | NEW |