Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(149)

Side by Side Diff: content/browser/browser_url_handler_impl.h

Issue 9688019: Add a Content API around BrowserURLHandler. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: fix gypis Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/browser/browser_url_handler.cc ('k') | content/browser/browser_url_handler_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #ifndef CONTENT_BROWSER_BROWSER_URL_HANDLER_IMPL_H_
6 // before they're handed to a renderer. This lets us do the URL handling 6 #define CONTENT_BROWSER_BROWSER_URL_HANDLER_IMPL_H_
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
9 // random web pages (because from the resource loader's perspective, these
10 // URL schemes don't exist).
11
12 #ifndef CONTENT_BROWSER_BROWSER_URL_HANDLER_H_
13 #define CONTENT_BROWSER_BROWSER_URL_HANDLER_H_
14 #pragma once 7 #pragma once
15 8
16 #include <vector> 9 #include <vector>
17 #include <utility> 10 #include <utility>
18 11
19 #include "base/gtest_prod_util.h" 12 #include "base/gtest_prod_util.h"
20 #include "base/memory/singleton.h" 13 #include "base/memory/singleton.h"
21 #include "content/common/content_export.h" 14 #include "content/public/browser/browser_url_handler.h"
22 15
23 class GURL; 16 class GURL;
24 17
25 namespace content { 18 namespace content {
26 class BrowserContext; 19 class BrowserContext;
27 } 20 }
28 21
29 // BrowserURLHandler manages the list of all special URLs and manages 22 class CONTENT_EXPORT BrowserURLHandlerImpl : public content::BrowserURLHandler {
30 // dispatching the URL handling to registered handlers.
31 class CONTENT_EXPORT BrowserURLHandler {
32 public: 23 public:
33 // The type of functions that can process a URL. 24 // Returns the singleton instance.
34 // If a handler handles |url|, it should : 25 static BrowserURLHandlerImpl* GetInstance();
35 // - optionally modify |url| to the URL that should be sent to the renderer
36 // If the URL is not handled by a handler, it should return false.
37 typedef bool (*URLHandler)(GURL* url,
38 content::BrowserContext* browser_context);
39 26
40 // Returns the singleton instance. 27 // BrowserURLHandler implementation:
41 static BrowserURLHandler* GetInstance(); 28 virtual void RewriteURLIfNecessary(GURL* url,
42 29 content::BrowserContext* browser_context,
43 // RewriteURLIfNecessary gives all registered URLHandlers a shot at processing 30 bool* reverse_on_redirect) OVERRIDE;
44 // the given URL, and modifies it in place. 31 // Add the specified handler pair to the list of URL handlers.
45 // If the original URL needs to be adjusted if the modified URL is redirected, 32 virtual void AddHandlerPair(URLHandler handler,
46 // this function sets |reverse_on_redirect| to true. 33 URLHandler reverse_handler) OVERRIDE;
47 void RewriteURLIfNecessary(GURL* url,
48 content::BrowserContext* browser_context,
49 bool* reverse_on_redirect);
50 34
51 // Reverses the rewriting that was done for |original| using the new |url|. 35 // Reverses the rewriting that was done for |original| using the new |url|.
52 bool ReverseURLRewrite(GURL* url, const GURL& original, 36 bool ReverseURLRewrite(GURL* url, const GURL& original,
53 content::BrowserContext* browser_context); 37 content::BrowserContext* browser_context);
54 38
55 // Add the specified handler pair to the list of URL handlers.
56 void AddHandlerPair(URLHandler handler, URLHandler reverse_handler);
57
58 // Returns the null handler for use with |AddHandlerPair()|.
59 static URLHandler null_handler();
60
61 private: 39 private:
62 // This object is a singleton: 40 // This object is a singleton:
63 BrowserURLHandler(); 41 BrowserURLHandlerImpl();
64 ~BrowserURLHandler(); 42 virtual ~BrowserURLHandlerImpl();
65 friend struct DefaultSingletonTraits<BrowserURLHandler>; 43 friend struct DefaultSingletonTraits<BrowserURLHandlerImpl>;
66 44
67 // The list of known URLHandlers, optionally with reverse-rewriters. 45 // The list of known URLHandlers, optionally with reverse-rewriters.
68 typedef std::pair<URLHandler, URLHandler> HandlerPair; 46 typedef std::pair<URLHandler, URLHandler> HandlerPair;
69 std::vector<HandlerPair> url_handlers_; 47 std::vector<HandlerPair> url_handlers_;
70 48
71 FRIEND_TEST_ALL_PREFIXES(BrowserURLHandlerTest, BasicRewriteAndReverse); 49 FRIEND_TEST_ALL_PREFIXES(BrowserURLHandlerImplTest, BasicRewriteAndReverse);
72 FRIEND_TEST_ALL_PREFIXES(BrowserURLHandlerTest, NullHandlerReverse); 50 FRIEND_TEST_ALL_PREFIXES(BrowserURLHandlerImplTest, NullHandlerReverse);
73 51
74 DISALLOW_COPY_AND_ASSIGN(BrowserURLHandler); 52 DISALLOW_COPY_AND_ASSIGN(BrowserURLHandlerImpl);
75 }; 53 };
76 54
77 #endif // CONTENT_BROWSER_BROWSER_URL_HANDLER_H_ 55 #endif // CONTENT_BROWSER_BROWSER_URL_HANDLER_IMPL_H_
OLDNEW
« no previous file with comments | « content/browser/browser_url_handler.cc ('k') | content/browser/browser_url_handler_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698