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

Side by Side Diff: content/browser/browser_url_handler.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 | « chrome/browser/ui/browser_navigator.cc ('k') | content/browser/browser_url_handler.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
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
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
15
16 #include <vector>
17 #include <utility>
18
19 #include "base/gtest_prod_util.h"
20 #include "base/memory/singleton.h"
21 #include "content/common/content_export.h"
22
23 class GURL;
24
25 namespace content {
26 class BrowserContext;
27 }
28
29 // BrowserURLHandler manages the list of all special URLs and manages
30 // dispatching the URL handling to registered handlers.
31 class CONTENT_EXPORT BrowserURLHandler {
32 public:
33 // The type of functions that can process a URL.
34 // If a handler handles |url|, it should :
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
40 // Returns the singleton instance.
41 static BrowserURLHandler* GetInstance();
42
43 // RewriteURLIfNecessary gives all registered URLHandlers a shot at processing
44 // the given URL, and modifies it in place.
45 // If the original URL needs to be adjusted if the modified URL is redirected,
46 // this function sets |reverse_on_redirect| to true.
47 void RewriteURLIfNecessary(GURL* url,
48 content::BrowserContext* browser_context,
49 bool* reverse_on_redirect);
50
51 // Reverses the rewriting that was done for |original| using the new |url|.
52 bool ReverseURLRewrite(GURL* url, const GURL& original,
53 content::BrowserContext* browser_context);
54
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:
62 // This object is a singleton:
63 BrowserURLHandler();
64 ~BrowserURLHandler();
65 friend struct DefaultSingletonTraits<BrowserURLHandler>;
66
67 // The list of known URLHandlers, optionally with reverse-rewriters.
68 typedef std::pair<URLHandler, URLHandler> HandlerPair;
69 std::vector<HandlerPair> url_handlers_;
70
71 FRIEND_TEST_ALL_PREFIXES(BrowserURLHandlerTest, BasicRewriteAndReverse);
72 FRIEND_TEST_ALL_PREFIXES(BrowserURLHandlerTest, NullHandlerReverse);
73
74 DISALLOW_COPY_AND_ASSIGN(BrowserURLHandler);
75 };
76
77 #endif // CONTENT_BROWSER_BROWSER_URL_HANDLER_H_
OLDNEW
« no previous file with comments | « chrome/browser/ui/browser_navigator.cc ('k') | content/browser/browser_url_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698