summaryrefslogtreecommitdiffstats
path: root/content/browser
diff options
context:
space:
mode:
authorjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-12 19:07:31 +0000
committerjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-12 19:07:31 +0000
commit825b16687e0de3ef4ec3b7dd60fc1dfb237947c9 (patch)
tree8831f3f038a28b69c8dd976a7381aa66c1406ff4 /content/browser
parenta60de956ec71ec185684f6d6167d5c8547f3639f (diff)
downloadchromium_src-825b16687e0de3ef4ec3b7dd60fc1dfb237947c9.zip
chromium_src-825b16687e0de3ef4ec3b7dd60fc1dfb237947c9.tar.gz
chromium_src-825b16687e0de3ef4ec3b7dd60fc1dfb237947c9.tar.bz2
Add a Content API around BrowserURLHandler.
BUG=98716 Review URL: https://chromiumcodereview.appspot.com/9688019 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@126180 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/browser')
-rw-r--r--content/browser/browser_url_handler.h77
-rw-r--r--content/browser/browser_url_handler_impl.cc (renamed from content/browser/browser_url_handler.cc)25
-rw-r--r--content/browser/browser_url_handler_impl.h55
-rw-r--r--content/browser/browser_url_handler_impl_unittest.cc (renamed from content/browser/browser_url_handler_unittest.cc)16
-rw-r--r--content/browser/renderer_host/test_render_view_host.cc1
-rw-r--r--content/browser/tab_contents/navigation_controller_impl.cc6
-rw-r--r--content/browser/tab_contents/render_view_host_manager_unittest.cc1
-rw-r--r--content/browser/tab_contents/test_tab_contents.cc4
8 files changed, 84 insertions, 101 deletions
diff --git a/content/browser/browser_url_handler.h b/content/browser/browser_url_handler.h
deleted file mode 100644
index 4fd625b..0000000
--- a/content/browser/browser_url_handler.h
+++ /dev/null
@@ -1,77 +0,0 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// We handle some special browser-level URLs (like "about:version")
-// before they're handed to a renderer. This lets us do the URL handling
-// on the browser side (which has access to more information than the
-// renderers do) as well as sidestep the risk of exposing data to
-// random web pages (because from the resource loader's perspective, these
-// URL schemes don't exist).
-
-#ifndef CONTENT_BROWSER_BROWSER_URL_HANDLER_H_
-#define CONTENT_BROWSER_BROWSER_URL_HANDLER_H_
-#pragma once
-
-#include <vector>
-#include <utility>
-
-#include "base/gtest_prod_util.h"
-#include "base/memory/singleton.h"
-#include "content/common/content_export.h"
-
-class GURL;
-
-namespace content {
-class BrowserContext;
-}
-
-// BrowserURLHandler manages the list of all special URLs and manages
-// dispatching the URL handling to registered handlers.
-class CONTENT_EXPORT BrowserURLHandler {
- public:
- // The type of functions that can process a URL.
- // If a handler handles |url|, it should :
- // - optionally modify |url| to the URL that should be sent to the renderer
- // If the URL is not handled by a handler, it should return false.
- typedef bool (*URLHandler)(GURL* url,
- content::BrowserContext* browser_context);
-
- // Returns the singleton instance.
- static BrowserURLHandler* GetInstance();
-
- // RewriteURLIfNecessary gives all registered URLHandlers a shot at processing
- // the given URL, and modifies it in place.
- // If the original URL needs to be adjusted if the modified URL is redirected,
- // this function sets |reverse_on_redirect| to true.
- void RewriteURLIfNecessary(GURL* url,
- content::BrowserContext* browser_context,
- bool* reverse_on_redirect);
-
- // Reverses the rewriting that was done for |original| using the new |url|.
- bool ReverseURLRewrite(GURL* url, const GURL& original,
- content::BrowserContext* browser_context);
-
- // Add the specified handler pair to the list of URL handlers.
- void AddHandlerPair(URLHandler handler, URLHandler reverse_handler);
-
- // Returns the null handler for use with |AddHandlerPair()|.
- static URLHandler null_handler();
-
- private:
- // This object is a singleton:
- BrowserURLHandler();
- ~BrowserURLHandler();
- friend struct DefaultSingletonTraits<BrowserURLHandler>;
-
- // The list of known URLHandlers, optionally with reverse-rewriters.
- typedef std::pair<URLHandler, URLHandler> HandlerPair;
- std::vector<HandlerPair> url_handlers_;
-
- FRIEND_TEST_ALL_PREFIXES(BrowserURLHandlerTest, BasicRewriteAndReverse);
- FRIEND_TEST_ALL_PREFIXES(BrowserURLHandlerTest, NullHandlerReverse);
-
- DISALLOW_COPY_AND_ASSIGN(BrowserURLHandler);
-};
-
-#endif // CONTENT_BROWSER_BROWSER_URL_HANDLER_H_
diff --git a/content/browser/browser_url_handler.cc b/content/browser/browser_url_handler_impl.cc
index 15f947b..7eef43f 100644
--- a/content/browser/browser_url_handler.cc
+++ b/content/browser/browser_url_handler_impl.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "content/browser/browser_url_handler.h"
+#include "content/browser/browser_url_handler_impl.h"
#include "base/string_util.h"
#include "content/browser/webui/web_ui_impl.h"
@@ -10,6 +10,8 @@
#include "content/public/common/url_constants.h"
#include "googleurl/src/gurl.h"
+using content::BrowserURLHandler;
+
// Handles rewriting view-source URLs for what we'll actually load.
static bool HandleViewSource(GURL* url,
content::BrowserContext* browser_context) {
@@ -70,7 +72,7 @@ static bool HandleDebugUrl(GURL* url,
// static
BrowserURLHandler* BrowserURLHandler::GetInstance() {
- return Singleton<BrowserURLHandler>::get();
+ return BrowserURLHandlerImpl::GetInstance();
}
// static
@@ -79,8 +81,13 @@ BrowserURLHandler::URLHandler BrowserURLHandler::null_handler() {
return NULL;
}
-BrowserURLHandler::BrowserURLHandler() {
- AddHandlerPair(&HandleDebugUrl, BrowserURLHandler::null_handler());
+// static
+BrowserURLHandlerImpl* BrowserURLHandlerImpl::GetInstance() {
+ return Singleton<BrowserURLHandlerImpl>::get();
+}
+
+BrowserURLHandlerImpl::BrowserURLHandlerImpl() {
+ AddHandlerPair(&HandleDebugUrl, BrowserURLHandlerImpl::null_handler());
content::GetContentClient()->browser()->BrowserURLHandlerCreated(this);
@@ -88,15 +95,15 @@ BrowserURLHandler::BrowserURLHandler() {
AddHandlerPair(&HandleViewSource, &ReverseViewSource);
}
-BrowserURLHandler::~BrowserURLHandler() {
+BrowserURLHandlerImpl::~BrowserURLHandlerImpl() {
}
-void BrowserURLHandler::AddHandlerPair(URLHandler handler,
- URLHandler reverse_handler) {
+void BrowserURLHandlerImpl::AddHandlerPair(URLHandler handler,
+ URLHandler reverse_handler) {
url_handlers_.push_back(HandlerPair(handler, reverse_handler));
}
-void BrowserURLHandler::RewriteURLIfNecessary(
+void BrowserURLHandlerImpl::RewriteURLIfNecessary(
GURL* url,
content::BrowserContext* browser_context,
bool* reverse_on_redirect) {
@@ -109,7 +116,7 @@ void BrowserURLHandler::RewriteURLIfNecessary(
}
}
-bool BrowserURLHandler::ReverseURLRewrite(
+bool BrowserURLHandlerImpl::ReverseURLRewrite(
GURL* url, const GURL& original, content::BrowserContext* browser_context) {
for (size_t i = 0; i < url_handlers_.size(); ++i) {
URLHandler reverse_rewriter = *url_handlers_[i].second;
diff --git a/content/browser/browser_url_handler_impl.h b/content/browser/browser_url_handler_impl.h
new file mode 100644
index 0000000..d6136a6
--- /dev/null
+++ b/content/browser/browser_url_handler_impl.h
@@ -0,0 +1,55 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CONTENT_BROWSER_BROWSER_URL_HANDLER_IMPL_H_
+#define CONTENT_BROWSER_BROWSER_URL_HANDLER_IMPL_H_
+#pragma once
+
+#include <vector>
+#include <utility>
+
+#include "base/gtest_prod_util.h"
+#include "base/memory/singleton.h"
+#include "content/public/browser/browser_url_handler.h"
+
+class GURL;
+
+namespace content {
+class BrowserContext;
+}
+
+class CONTENT_EXPORT BrowserURLHandlerImpl : public content::BrowserURLHandler {
+ public:
+ // Returns the singleton instance.
+ static BrowserURLHandlerImpl* GetInstance();
+
+ // BrowserURLHandler implementation:
+ virtual void RewriteURLIfNecessary(GURL* url,
+ content::BrowserContext* browser_context,
+ bool* reverse_on_redirect) OVERRIDE;
+ // Add the specified handler pair to the list of URL handlers.
+ virtual void AddHandlerPair(URLHandler handler,
+ URLHandler reverse_handler) OVERRIDE;
+
+ // Reverses the rewriting that was done for |original| using the new |url|.
+ bool ReverseURLRewrite(GURL* url, const GURL& original,
+ content::BrowserContext* browser_context);
+
+ private:
+ // This object is a singleton:
+ BrowserURLHandlerImpl();
+ virtual ~BrowserURLHandlerImpl();
+ friend struct DefaultSingletonTraits<BrowserURLHandlerImpl>;
+
+ // The list of known URLHandlers, optionally with reverse-rewriters.
+ typedef std::pair<URLHandler, URLHandler> HandlerPair;
+ std::vector<HandlerPair> url_handlers_;
+
+ FRIEND_TEST_ALL_PREFIXES(BrowserURLHandlerImplTest, BasicRewriteAndReverse);
+ FRIEND_TEST_ALL_PREFIXES(BrowserURLHandlerImplTest, NullHandlerReverse);
+
+ DISALLOW_COPY_AND_ASSIGN(BrowserURLHandlerImpl);
+};
+
+#endif // CONTENT_BROWSER_BROWSER_URL_HANDLER_IMPL_H_
diff --git a/content/browser/browser_url_handler_unittest.cc b/content/browser/browser_url_handler_impl_unittest.cc
index ed133a2..7109d5d 100644
--- a/content/browser/browser_url_handler_unittest.cc
+++ b/content/browser/browser_url_handler_impl_unittest.cc
@@ -2,12 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "content/browser/browser_url_handler.h"
+#include "content/browser/browser_url_handler_impl.h"
#include "content/test/test_browser_context.h"
#include "googleurl/src/gurl.h"
#include "testing/gtest/include/gtest/gtest.h"
-class BrowserURLHandlerTest : public testing::Test {
+class BrowserURLHandlerImplTest : public testing::Test {
};
// Test URL rewriter that rewrites all "foo://" URLs to "bar://bar".
@@ -28,9 +28,9 @@ static bool BarRewriter(GURL* url, content::BrowserContext* browser_context) {
return false;
}
-TEST_F(BrowserURLHandlerTest, BasicRewriteAndReverse) {
+TEST_F(BrowserURLHandlerImplTest, BasicRewriteAndReverse) {
TestBrowserContext browser_context;
- BrowserURLHandler handler;
+ BrowserURLHandlerImpl handler;
handler.AddHandlerPair(FooRewriter, BarRewriter);
@@ -57,21 +57,21 @@ TEST_F(BrowserURLHandlerTest, BasicRewriteAndReverse) {
ASSERT_EQ(saved_url, url);
}
-TEST_F(BrowserURLHandlerTest, NullHandlerReverse) {
+TEST_F(BrowserURLHandlerImplTest, NullHandlerReverse) {
TestBrowserContext browser_context;
- BrowserURLHandler handler;
+ BrowserURLHandlerImpl handler;
GURL url("bar://foo");
GURL original_url(url);
- handler.AddHandlerPair(BrowserURLHandler::null_handler(), FooRewriter);
+ handler.AddHandlerPair(BrowserURLHandlerImpl::null_handler(), FooRewriter);
bool reversed = handler.ReverseURLRewrite(&url,
original_url,
&browser_context);
ASSERT_FALSE(reversed);
ASSERT_EQ(original_url, url);
- handler.AddHandlerPair(BrowserURLHandler::null_handler(), BarRewriter);
+ handler.AddHandlerPair(BrowserURLHandlerImpl::null_handler(), BarRewriter);
reversed = handler.ReverseURLRewrite(&url, original_url, &browser_context);
ASSERT_TRUE(reversed);
ASSERT_EQ("foo://foo", url.spec());
diff --git a/content/browser/renderer_host/test_render_view_host.cc b/content/browser/renderer_host/test_render_view_host.cc
index 0d96498..0f28eafa8 100644
--- a/content/browser/renderer_host/test_render_view_host.cc
+++ b/content/browser/renderer_host/test_render_view_host.cc
@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "content/browser/browser_url_handler.h"
#include "content/browser/renderer_host/test_backing_store.h"
#include "content/browser/renderer_host/test_render_view_host.h"
#include "content/browser/site_instance_impl.h"
diff --git a/content/browser/tab_contents/navigation_controller_impl.cc b/content/browser/tab_contents/navigation_controller_impl.cc
index 1f2d8a6..3de187b 100644
--- a/content/browser/tab_contents/navigation_controller_impl.cc
+++ b/content/browser/tab_contents/navigation_controller_impl.cc
@@ -10,7 +10,7 @@
#include "base/string_util.h"
#include "base/time.h"
#include "base/utf_string_conversions.h"
-#include "content/browser/browser_url_handler.h"
+#include "content/browser/browser_url_handler_impl.h"
#include "content/browser/child_process_security_policy_impl.h"
#include "content/browser/in_process_webkit/dom_storage_context_impl.h"
#include "content/browser/in_process_webkit/session_storage_namespace_impl.h"
@@ -143,7 +143,7 @@ NavigationEntry* NavigationController::CreateNavigationEntry(
// used internally.
GURL loaded_url(url);
bool reverse_on_redirect = false;
- BrowserURLHandler::GetInstance()->RewriteURLIfNecessary(
+ BrowserURLHandlerImpl::GetInstance()->RewriteURLIfNecessary(
&loaded_url, browser_context, &reverse_on_redirect);
NavigationEntryImpl* entry = new NavigationEntryImpl(
@@ -534,7 +534,7 @@ void NavigationControllerImpl::RemoveEntryAtIndex(int index) {
void NavigationControllerImpl::UpdateVirtualURLToURL(
NavigationEntryImpl* entry, const GURL& new_url) {
GURL new_virtual_url(new_url);
- if (BrowserURLHandler::GetInstance()->ReverseURLRewrite(
+ if (BrowserURLHandlerImpl::GetInstance()->ReverseURLRewrite(
&new_virtual_url, entry->GetVirtualURL(), browser_context_)) {
entry->SetVirtualURL(new_virtual_url);
}
diff --git a/content/browser/tab_contents/render_view_host_manager_unittest.cc b/content/browser/tab_contents/render_view_host_manager_unittest.cc
index bffb7bd..20ef0c2 100644
--- a/content/browser/tab_contents/render_view_host_manager_unittest.cc
+++ b/content/browser/tab_contents/render_view_host_manager_unittest.cc
@@ -4,7 +4,6 @@
#include "base/utf_string_conversions.h"
#include "content/browser/browser_thread_impl.h"
-#include "content/browser/browser_url_handler.h"
#include "content/browser/mock_content_browser_client.h"
#include "content/browser/renderer_host/test_render_view_host.h"
#include "content/browser/site_instance_impl.h"
diff --git a/content/browser/tab_contents/test_tab_contents.cc b/content/browser/tab_contents/test_tab_contents.cc
index fc6bf57..16f43ad 100644
--- a/content/browser/tab_contents/test_tab_contents.cc
+++ b/content/browser/tab_contents/test_tab_contents.cc
@@ -6,7 +6,7 @@
#include <utility>
-#include "content/browser/browser_url_handler.h"
+#include "content/browser/browser_url_handler_impl.h"
#include "content/browser/renderer_host/mock_render_process_host.h"
#include "content/browser/renderer_host/render_view_host_impl.h"
#include "content/browser/renderer_host/test_render_view_host.h"
@@ -101,7 +101,7 @@ void TestTabContents::NavigateAndCommit(const GURL& url) {
url, content::Referrer(), content::PAGE_TRANSITION_LINK, std::string());
GURL loaded_url(url);
bool reverse_on_redirect = false;
- BrowserURLHandler::GetInstance()->RewriteURLIfNecessary(
+ BrowserURLHandlerImpl::GetInstance()->RewriteURLIfNecessary(
&loaded_url, GetBrowserContext(), &reverse_on_redirect);
// LoadURL created a navigation entry, now simulate the RenderView sending