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

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

Issue 11274038: content/browser: Move more files into the content namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix win - part2 Created 8 years, 2 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
OLDNEW
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 #include "content/browser/browser_url_handler_impl.h" 5 #include "content/browser/browser_url_handler_impl.h"
6 6
7 #include "base/string_util.h" 7 #include "base/string_util.h"
8 #include "content/browser/webui/web_ui_impl.h" 8 #include "content/browser/webui/web_ui_impl.h"
9 #include "content/public/browser/content_browser_client.h" 9 #include "content/public/browser/content_browser_client.h"
10 #include "content/public/common/url_constants.h" 10 #include "content/public/common/url_constants.h"
11 #include "googleurl/src/gurl.h" 11 #include "googleurl/src/gurl.h"
12 12
13 using content::BrowserURLHandler; 13 namespace content {
14
15 namespace {
14 16
15 // Handles rewriting view-source URLs for what we'll actually load. 17 // Handles rewriting view-source URLs for what we'll actually load.
16 static bool HandleViewSource(GURL* url, 18 bool HandleViewSource(GURL* url, BrowserContext* browser_context) {
17 content::BrowserContext* browser_context) {
18 if (url->SchemeIs(chrome::kViewSourceScheme)) { 19 if (url->SchemeIs(chrome::kViewSourceScheme)) {
19 // Load the inner URL instead. 20 // Load the inner URL instead.
20 *url = GURL(url->path()); 21 *url = GURL(url->path());
21 22
22 // Bug 26129: limit view-source to view the content and not any 23 // Bug 26129: limit view-source to view the content and not any
23 // other kind of 'active' url scheme like 'javascript' or 'data'. 24 // other kind of 'active' url scheme like 'javascript' or 'data'.
24 static const char* const allowed_sub_schemes[] = { 25 static const char* const allowed_sub_schemes[] = {
25 chrome::kHttpScheme, chrome::kHttpsScheme, chrome::kFtpScheme, 26 chrome::kHttpScheme, chrome::kHttpsScheme, chrome::kFtpScheme,
26 chrome::kChromeDevToolsScheme, chrome::kChromeUIScheme, 27 chrome::kChromeDevToolsScheme, chrome::kChromeUIScheme,
27 chrome::kFileScheme, chrome::kFileSystemScheme 28 chrome::kFileScheme, chrome::kFileSystemScheme
(...skipping 11 matching lines...) Expand all
39 *url = GURL(chrome::kAboutBlankURL); 40 *url = GURL(chrome::kAboutBlankURL);
40 return false; 41 return false;
41 } 42 }
42 43
43 return true; 44 return true;
44 } 45 }
45 return false; 46 return false;
46 } 47 }
47 48
48 // Turns a non view-source URL into the corresponding view-source URL. 49 // Turns a non view-source URL into the corresponding view-source URL.
49 static bool ReverseViewSource(GURL* url, 50 bool ReverseViewSource(GURL* url, BrowserContext* browser_context) {
50 content::BrowserContext* browser_context) {
51 // No action necessary if the URL is already view-source: 51 // No action necessary if the URL is already view-source:
52 if (url->SchemeIs(chrome::kViewSourceScheme)) 52 if (url->SchemeIs(chrome::kViewSourceScheme))
53 return false; 53 return false;
54 54
55 url_canon::Replacements<char> repl; 55 url_canon::Replacements<char> repl;
56 repl.SetScheme(chrome::kViewSourceScheme, 56 repl.SetScheme(chrome::kViewSourceScheme,
57 url_parse::Component(0, strlen(chrome::kViewSourceScheme))); 57 url_parse::Component(0, strlen(chrome::kViewSourceScheme)));
58 repl.SetPath(url->spec().c_str(), 58 repl.SetPath(url->spec().c_str(),
59 url_parse::Component(0, url->spec().size())); 59 url_parse::Component(0, url->spec().size()));
60 *url = url->ReplaceComponents(repl); 60 *url = url->ReplaceComponents(repl);
61 return true; 61 return true;
62 } 62 }
63 63
64 static bool HandleDebugUrl(GURL* url, 64 bool HandleDebugUrl(GURL* url, BrowserContext* browser_context) {
65 content::BrowserContext* browser_context) {
66 // Circumvent processing URLs that the renderer process will handle. 65 // Circumvent processing URLs that the renderer process will handle.
67 return *url == GURL(chrome::kChromeUICrashURL) || 66 return *url == GURL(chrome::kChromeUICrashURL) ||
68 *url == GURL(chrome::kChromeUIHangURL) || 67 *url == GURL(chrome::kChromeUIHangURL) ||
69 *url == GURL(chrome::kChromeUIKillURL) || 68 *url == GURL(chrome::kChromeUIKillURL) ||
70 *url == GURL(chrome::kChromeUIShorthangURL); 69 *url == GURL(chrome::kChromeUIShorthangURL);
71 } 70 }
72 71
72 } // namespace
73
73 // static 74 // static
74 BrowserURLHandler* BrowserURLHandler::GetInstance() { 75 BrowserURLHandler* BrowserURLHandler::GetInstance() {
75 return BrowserURLHandlerImpl::GetInstance(); 76 return BrowserURLHandlerImpl::GetInstance();
76 } 77 }
77 78
78 // static 79 // static
79 BrowserURLHandler::URLHandler BrowserURLHandler::null_handler() { 80 BrowserURLHandler::URLHandler BrowserURLHandler::null_handler() {
80 // Required for VS2010: http://connect.microsoft.com/VisualStudio/feedback/det ails/520043/error-converting-from-null-to-a-pointer-type-in-std-pair 81 // Required for VS2010: http://connect.microsoft.com/VisualStudio/feedback/det ails/520043/error-converting-from-null-to-a-pointer-type-in-std-pair
81 return NULL; 82 return NULL;
82 } 83 }
83 84
84 // static 85 // static
85 BrowserURLHandlerImpl* BrowserURLHandlerImpl::GetInstance() { 86 BrowserURLHandlerImpl* BrowserURLHandlerImpl::GetInstance() {
86 return Singleton<BrowserURLHandlerImpl>::get(); 87 return Singleton<BrowserURLHandlerImpl>::get();
87 } 88 }
88 89
89 BrowserURLHandlerImpl::BrowserURLHandlerImpl() { 90 BrowserURLHandlerImpl::BrowserURLHandlerImpl() {
90 AddHandlerPair(&HandleDebugUrl, BrowserURLHandlerImpl::null_handler()); 91 AddHandlerPair(&HandleDebugUrl, BrowserURLHandlerImpl::null_handler());
91 92
92 content::GetContentClient()->browser()->BrowserURLHandlerCreated(this); 93 GetContentClient()->browser()->BrowserURLHandlerCreated(this);
93 94
94 // view-source: 95 // view-source:
95 AddHandlerPair(&HandleViewSource, &ReverseViewSource); 96 AddHandlerPair(&HandleViewSource, &ReverseViewSource);
96 } 97 }
97 98
98 BrowserURLHandlerImpl::~BrowserURLHandlerImpl() { 99 BrowserURLHandlerImpl::~BrowserURLHandlerImpl() {
99 } 100 }
100 101
101 void BrowserURLHandlerImpl::AddHandlerPair(URLHandler handler, 102 void BrowserURLHandlerImpl::AddHandlerPair(URLHandler handler,
102 URLHandler reverse_handler) { 103 URLHandler reverse_handler) {
103 url_handlers_.push_back(HandlerPair(handler, reverse_handler)); 104 url_handlers_.push_back(HandlerPair(handler, reverse_handler));
104 } 105 }
105 106
106 void BrowserURLHandlerImpl::RewriteURLIfNecessary( 107 void BrowserURLHandlerImpl::RewriteURLIfNecessary(
107 GURL* url, 108 GURL* url,
108 content::BrowserContext* browser_context, 109 BrowserContext* browser_context,
109 bool* reverse_on_redirect) { 110 bool* reverse_on_redirect) {
110 for (size_t i = 0; i < url_handlers_.size(); ++i) { 111 for (size_t i = 0; i < url_handlers_.size(); ++i) {
111 URLHandler handler = *url_handlers_[i].first; 112 URLHandler handler = *url_handlers_[i].first;
112 if (handler && handler(url, browser_context)) { 113 if (handler && handler(url, browser_context)) {
113 *reverse_on_redirect = (url_handlers_[i].second != NULL); 114 *reverse_on_redirect = (url_handlers_[i].second != NULL);
114 return; 115 return;
115 } 116 }
116 } 117 }
117 } 118 }
118 119
119 bool BrowserURLHandlerImpl::ReverseURLRewrite( 120 bool BrowserURLHandlerImpl::ReverseURLRewrite(GURL* url,
120 GURL* url, const GURL& original, content::BrowserContext* browser_context) { 121 const GURL& original,
122 BrowserContext* browser_context) {
121 for (size_t i = 0; i < url_handlers_.size(); ++i) { 123 for (size_t i = 0; i < url_handlers_.size(); ++i) {
122 URLHandler reverse_rewriter = *url_handlers_[i].second; 124 URLHandler reverse_rewriter = *url_handlers_[i].second;
123 if (reverse_rewriter) { 125 if (reverse_rewriter) {
124 GURL test_url(original); 126 GURL test_url(original);
125 URLHandler handler = *url_handlers_[i].first; 127 URLHandler handler = *url_handlers_[i].first;
126 if (!handler) { 128 if (!handler) {
127 if (reverse_rewriter(url, browser_context)) 129 if (reverse_rewriter(url, browser_context))
128 return true; 130 return true;
129 } else if (handler(&test_url, browser_context)) { 131 } else if (handler(&test_url, browser_context)) {
130 return reverse_rewriter(url, browser_context); 132 return reverse_rewriter(url, browser_context);
131 } 133 }
132 } 134 }
133 } 135 }
134 return false; 136 return false;
135 } 137 }
138
139 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/browser_url_handler_impl.h ('k') | content/browser/browser_url_handler_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698