summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/chrome_content_browser_client.cc4
-rw-r--r--chrome/browser/chrome_content_browser_client.h1
-rw-r--r--chrome/browser/chrome_content_browser_client_unittest.cc22
-rw-r--r--chrome/chrome_tests_unit.gypi1
-rw-r--r--chrome/common/url_constants.cc1
-rw-r--r--chrome/common/url_constants.h4
-rw-r--r--chrome/renderer/chrome_render_process_observer.cc20
-rw-r--r--chrome/renderer/chrome_render_process_observer.h1
-rw-r--r--content/browser/web_contents/web_contents_impl.cc13
-rw-r--r--content/browser/web_contents/web_contents_impl_unittest.cc30
-rw-r--r--content/public/browser/content_browser_client.cc4
-rw-r--r--content/public/browser/content_browser_client.h4
-rw-r--r--content/public/common/url_constants.cc1
-rw-r--r--content/public/common/url_constants.h1
-rw-r--r--content/renderer/render_thread_impl.cc13
-rw-r--r--content/renderer/render_view_browsertest.cc24
-rw-r--r--content/renderer/render_view_impl.h2
17 files changed, 97 insertions, 49 deletions
diff --git a/chrome/browser/chrome_content_browser_client.cc b/chrome/browser/chrome_content_browser_client.cc
index ebcc8ed..84765ef 100644
--- a/chrome/browser/chrome_content_browser_client.cc
+++ b/chrome/browser/chrome_content_browser_client.cc
@@ -1253,6 +1253,10 @@ bool ChromeContentBrowserClient::ShouldSwapProcessesForRedirect(
ExtensionURLInfo(current_url), ExtensionURLInfo(new_url), false);
}
+bool ChromeContentBrowserClient::ShouldAssignSiteForURL(const GURL& url) {
+ return !url.SchemeIs(chrome::kChromeNativeScheme);
+}
+
std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
const std::string& alias_name) {
return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name);
diff --git a/chrome/browser/chrome_content_browser_client.h b/chrome/browser/chrome_content_browser_client.h
index 9d93ddd..608a277 100644
--- a/chrome/browser/chrome_content_browser_client.h
+++ b/chrome/browser/chrome_content_browser_client.h
@@ -109,6 +109,7 @@ class ChromeContentBrowserClient : public content::ContentBrowserClient {
content::ResourceContext* resource_context,
const GURL& current_url,
const GURL& new_url) OVERRIDE;
+ virtual bool ShouldAssignSiteForURL(const GURL& url) OVERRIDE;
virtual std::string GetCanonicalEncodingNameByAliasName(
const std::string& alias_name) OVERRIDE;
virtual void AppendExtraCommandLineSwitches(CommandLine* command_line,
diff --git a/chrome/browser/chrome_content_browser_client_unittest.cc b/chrome/browser/chrome_content_browser_client_unittest.cc
new file mode 100644
index 0000000..d393105
--- /dev/null
+++ b/chrome/browser/chrome_content_browser_client_unittest.cc
@@ -0,0 +1,22 @@
+// Copyright 2013 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.
+
+#include "chrome/browser/chrome_content_browser_client.h"
+
+#include "googleurl/src/gurl.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace chrome {
+
+typedef testing::Test ChromeContentBrowserClientTest;
+
+
+TEST_F(ChromeContentBrowserClientTest, ShouldAssignSiteForURL) {
+ ChromeContentBrowserClient client;
+ EXPECT_FALSE(client.ShouldAssignSiteForURL(GURL("chrome-native://test")));
+ EXPECT_TRUE(client.ShouldAssignSiteForURL(GURL("http://www.google.com")));
+ EXPECT_TRUE(client.ShouldAssignSiteForURL(GURL("https://www.google.com")));
+}
+
+} // namespace chrome
diff --git a/chrome/chrome_tests_unit.gypi b/chrome/chrome_tests_unit.gypi
index 6506386..2c981c4 100644
--- a/chrome/chrome_tests_unit.gypi
+++ b/chrome/chrome_tests_unit.gypi
@@ -1607,6 +1607,7 @@
'browser/ui/window_sizer/window_sizer_unittest.cc',
'browser/ui/zoom/zoom_controller_unittest.cc',
'browser/upload_list_unittest.cc',
+ 'browser/chrome_content_browser_client_unittest.cc',
'browser/chrome_to_mobile_service_unittest.cc',
'browser/user_style_sheet_watcher_unittest.cc',
'browser/value_store/leveldb_value_store_unittest.cc',
diff --git a/chrome/common/url_constants.cc b/chrome/common/url_constants.cc
index b6d5553..10bc939b 100644
--- a/chrome/common/url_constants.cc
+++ b/chrome/common/url_constants.cc
@@ -523,6 +523,7 @@ const int kNumberOfChromeDebugURLs =
static_cast<int>(arraysize(kChromeDebugURLs));
const char kExtensionResourceScheme[] = "chrome-extension-resource";
+const char kChromeNativeScheme[] = "chrome-native";
const char kChromeSearchScheme[] = "chrome-search";
const char kChromeSearchLocalNtpHost[] = "local-ntp";
diff --git a/chrome/common/url_constants.h b/chrome/common/url_constants.h
index 7b686f1..6efc4ac 100644
--- a/chrome/common/url_constants.h
+++ b/chrome/common/url_constants.h
@@ -424,6 +424,10 @@ extern const int kNumberOfChromeDebugURLs;
// Canonical schemes you can use as input to GURL.SchemeIs().
extern const char kExtensionResourceScheme[];
+// The chrome-native: scheme is used show pages rendered with platform specific
+// widgets instead of using HTML.
+extern const char kChromeNativeScheme[];
+
// The chrome-search: scheme is served by the same backend as chrome:. However,
// only specific URLDataSources are enabled to serve requests via the
// chrome-search: scheme. See |InstantIOContext::ShouldServiceRequest| and its
diff --git a/chrome/renderer/chrome_render_process_observer.cc b/chrome/renderer/chrome_render_process_observer.cc
index e55baee..b46dbac 100644
--- a/chrome/renderer/chrome_render_process_observer.cc
+++ b/chrome/renderer/chrome_render_process_observer.cc
@@ -19,6 +19,7 @@
#include "base/native_library.h"
#include "base/path_service.h"
#include "base/process_util.h"
+#include "base/strings/utf_string_conversions.h"
#include "base/threading/platform_thread.h"
#include "chrome/common/child_process_logging.h"
#include "chrome/common/chrome_paths.h"
@@ -27,6 +28,7 @@
#include "chrome/common/metrics/variations/variations_util.h"
#include "chrome/common/net/net_resource_provider.h"
#include "chrome/common/render_messages.h"
+#include "chrome/common/url_constants.h"
#include "chrome/renderer/chrome_content_renderer_client.h"
#include "chrome/renderer/content_settings_observer.h"
#include "chrome/renderer/extensions/extension_localization_peer.h"
@@ -46,6 +48,7 @@
#include "third_party/WebKit/public/web/WebFontCache.h"
#include "third_party/WebKit/public/web/WebFrame.h"
#include "third_party/WebKit/public/web/WebRuntimeFeatures.h"
+#include "third_party/WebKit/public/web/WebSecurityPolicy.h"
#include "third_party/WebKit/public/web/WebView.h"
#include "v8/include/v8.h"
@@ -57,6 +60,8 @@ using WebKit::WebCache;
using WebKit::WebCrossOriginPreflightResultCache;
using WebKit::WebFontCache;
using WebKit::WebRuntimeFeatures;
+using WebKit::WebSecurityPolicy;
+using WebKit::WebString;
using content::RenderThread;
namespace {
@@ -333,6 +338,21 @@ bool ChromeRenderProcessObserver::OnControlMessageReceived(
return handled;
}
+void ChromeRenderProcessObserver::WebKitInitialized() {
+ // chrome-native: is a scheme used for placeholder navigations that allow
+ // UIs to be drawn with platform native widgets instead of HTML. These pages
+ // should not be accessible, and should also be treated as empty documents
+ // that can commit synchronously. No code should be runnable in these pages,
+ // so it should not need to access anything nor should it allow javascript
+ // URLs since it should never be visible to the user.
+ WebString native_scheme(ASCIIToUTF16(chrome::kChromeNativeScheme));
+ WebSecurityPolicy::registerURLSchemeAsDisplayIsolated(native_scheme);
+ WebSecurityPolicy::registerURLSchemeAsEmptyDocument(native_scheme);
+ WebSecurityPolicy::registerURLSchemeAsNoAccess(native_scheme);
+ WebSecurityPolicy::registerURLSchemeAsNotAllowingJavascriptURLs(
+ native_scheme);
+}
+
void ChromeRenderProcessObserver::OnSetIsIncognitoProcess(
bool is_incognito_process) {
is_incognito_process_ = is_incognito_process;
diff --git a/chrome/renderer/chrome_render_process_observer.h b/chrome/renderer/chrome_render_process_observer.h
index 288da2e..1ba175b 100644
--- a/chrome/renderer/chrome_render_process_observer.h
+++ b/chrome/renderer/chrome_render_process_observer.h
@@ -51,6 +51,7 @@ class ChromeRenderProcessObserver : public content::RenderProcessObserver {
private:
// RenderProcessObserver implementation.
virtual bool OnControlMessageReceived(const IPC::Message& message) OVERRIDE;
+ virtual void WebKitInitialized() OVERRIDE;
void OnSetIsIncognitoProcess(bool is_incognito_process);
void OnSetExtensionActivityLogEnabled(bool extension_activity_log_enabled);
diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc
index 27ce609..3842e88 100644
--- a/content/browser/web_contents/web_contents_impl.cc
+++ b/content/browser/web_contents/web_contents_impl.cc
@@ -2677,11 +2677,14 @@ void WebContentsImpl::DidNavigateAnyFramePostCommit(
}
bool WebContentsImpl::ShouldAssignSiteForURL(const GURL& url) {
- // Neither about:blank nor the chrome-native: scheme should "use up" a new
- // SiteInstance. In both cases, the SiteInstance can still be used for a
- // normal web site.
- return !url.SchemeIs(chrome::kChromeNativeScheme) &&
- url != GURL(kAboutBlankURL);
+ // about:blank should not "use up" a new SiteInstance. The SiteInstance can
+ // still be used for a normal web site.
+ if (url == GURL(kAboutBlankURL))
+ return false;
+
+ // The embedder will then have the opportunity to determine if the URL
+ // should "use up" the SiteInstance.
+ return GetContentClient()->browser()->ShouldAssignSiteForURL(url);
}
void WebContentsImpl::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
diff --git a/content/browser/web_contents/web_contents_impl_unittest.cc b/content/browser/web_contents/web_contents_impl_unittest.cc
index acb9ef8..f93e097 100644
--- a/content/browser/web_contents/web_contents_impl_unittest.cc
+++ b/content/browser/web_contents/web_contents_impl_unittest.cc
@@ -234,6 +234,25 @@ class TestInterstitialPageStateGuard : public TestInterstitialPage::Delegate {
TestInterstitialPage* interstitial_page_;
};
+class WebContentsImplTestBrowserClient : public TestContentBrowserClient {
+ public:
+ WebContentsImplTestBrowserClient()
+ : assign_site_for_url_(false) {}
+
+ virtual ~WebContentsImplTestBrowserClient() {}
+
+ virtual bool ShouldAssignSiteForURL(const GURL& url) OVERRIDE {
+ return assign_site_for_url_;
+ }
+
+ void set_assign_site_for_url(bool assign) {
+ assign_site_for_url_ = assign;
+ }
+
+ private:
+ bool assign_site_for_url_;
+};
+
class WebContentsImplTest : public RenderViewHostImplTestHarness {
public:
virtual void SetUp() {
@@ -578,7 +597,10 @@ TEST_F(WebContentsImplTest, NavigateTwoTabsCrossSite) {
EXPECT_EQ(instance2a, instance2b);
}
-TEST_F(WebContentsImplTest, NavigateFromChromeNativeKeepsSiteInstance) {
+TEST_F(WebContentsImplTest, NavigateDoesNotUseUpSiteInstance) {
+ WebContentsImplTestBrowserClient browser_client;
+ SetBrowserClientForTesting(&browser_client);
+
contents()->transition_cross_site = true;
TestRenderViewHost* orig_rvh = test_rvh();
int orig_rvh_delete_count = 0;
@@ -586,8 +608,9 @@ TEST_F(WebContentsImplTest, NavigateFromChromeNativeKeepsSiteInstance) {
SiteInstanceImpl* orig_instance =
static_cast<SiteInstanceImpl*>(contents()->GetSiteInstance());
- // Navigate to a chrome-native URL.
- const GURL native_url("chrome-native://nativestuffandthings");
+ browser_client.set_assign_site_for_url(false);
+ // Navigate to an URL that will not assign a new SiteInstance.
+ const GURL native_url("non-site-url://stuffandthings");
controller().LoadURL(
native_url, Referrer(), PAGE_TRANSITION_TYPED, std::string());
contents()->TestDidNavigate(orig_rvh, 1, native_url, PAGE_TRANSITION_TYPED);
@@ -600,6 +623,7 @@ TEST_F(WebContentsImplTest, NavigateFromChromeNativeKeepsSiteInstance) {
EXPECT_EQ(GURL(), contents()->GetSiteInstance()->GetSiteURL());
EXPECT_FALSE(orig_instance->HasSite());
+ browser_client.set_assign_site_for_url(true);
// Navigate to new site (should keep same site instance).
const GURL url("http://www.google.com");
controller().LoadURL(
diff --git a/content/public/browser/content_browser_client.cc b/content/public/browser/content_browser_client.cc
index ff431bc..367eede 100644
--- a/content/public/browser/content_browser_client.cc
+++ b/content/public/browser/content_browser_client.cc
@@ -91,6 +91,10 @@ bool ContentBrowserClient::ShouldSwapProcessesForRedirect(
return false;
}
+bool ContentBrowserClient::ShouldAssignSiteForURL(const GURL& url) {
+ return true;
+}
+
std::string ContentBrowserClient::GetCanonicalEncodingNameByAliasName(
const std::string& alias_name) {
return std::string();
diff --git a/content/public/browser/content_browser_client.h b/content/public/browser/content_browser_client.h
index 5bbba9a..29c8a28 100644
--- a/content/public/browser/content_browser_client.h
+++ b/content/public/browser/content_browser_client.h
@@ -262,6 +262,10 @@ class CONTENT_EXPORT ContentBrowserClient {
const GURL& current_url,
const GURL& new_url);
+ // Returns true if the passed in URL should be assigned as the site of the
+ // current SiteInstance, if it does not yet have a site.
+ virtual bool ShouldAssignSiteForURL(const GURL& url);
+
// See CharacterEncoding's comment.
virtual std::string GetCanonicalEncodingNameByAliasName(
const std::string& alias_name);
diff --git a/content/public/common/url_constants.cc b/content/public/common/url_constants.cc
index 1fa9611..7cec38a 100644
--- a/content/public/common/url_constants.cc
+++ b/content/public/common/url_constants.cc
@@ -13,7 +13,6 @@ const char kBlobScheme[] = "blob";
// There are security implications associated with introducing new schemes.
const char kChromeDevToolsScheme[] = "chrome-devtools";
const char kChromeInternalScheme[] = "chrome-internal";
-const char kChromeNativeScheme[] = "chrome-native";
const char kChromeUIScheme[] = "chrome";
const char kDataScheme[] = "data";
const char kFileScheme[] = "file";
diff --git a/content/public/common/url_constants.h b/content/public/common/url_constants.h
index de60527..58ee895 100644
--- a/content/public/common/url_constants.h
+++ b/content/public/common/url_constants.h
@@ -19,7 +19,6 @@ CONTENT_EXPORT extern const char kAboutScheme[];
CONTENT_EXPORT extern const char kBlobScheme[];
CONTENT_EXPORT extern const char kChromeDevToolsScheme[];
CONTENT_EXPORT extern const char kChromeInternalScheme[];
-CONTENT_EXPORT extern const char kChromeNativeScheme[];
CONTENT_EXPORT extern const char kChromeUIScheme[]; // Used for WebUIs.
CONTENT_EXPORT extern const char kDataScheme[];
CONTENT_EXPORT extern const char kFileScheme[];
diff --git a/content/renderer/render_thread_impl.cc b/content/renderer/render_thread_impl.cc
index 32109c0..aaf2b41 100644
--- a/content/renderer/render_thread_impl.cc
+++ b/content/renderer/render_thread_impl.cc
@@ -731,19 +731,6 @@ void RenderThreadImpl::RegisterSchemes() {
WebString swappedout_scheme(ASCIIToUTF16(chrome::kSwappedOutScheme));
WebSecurityPolicy::registerURLSchemeAsDisplayIsolated(swappedout_scheme);
WebSecurityPolicy::registerURLSchemeAsEmptyDocument(swappedout_scheme);
-
- // chrome-native: is a scheme used for placeholder navigations that allow
- // UIs to be drawn with platform native widgets instead of HTML. These pages
- // should not be accessible, and should also be treated as empty documents
- // that can commit synchronously. No code should be runnable in these pages,
- // so it should not need to access anything nor should it allow javascript
- // URLs since it should never be visible to the user.
- WebString native_scheme(ASCIIToUTF16(chrome::kChromeNativeScheme));
- WebSecurityPolicy::registerURLSchemeAsDisplayIsolated(native_scheme);
- WebSecurityPolicy::registerURLSchemeAsEmptyDocument(native_scheme);
- WebSecurityPolicy::registerURLSchemeAsNoAccess(native_scheme);
- WebSecurityPolicy::registerURLSchemeAsNotAllowingJavascriptURLs(
- native_scheme);
}
void RenderThreadImpl::RecordUserMetrics(const std::string& action) {
diff --git a/content/renderer/render_view_browsertest.cc b/content/renderer/render_view_browsertest.cc
index 4ab21a4..4831c6a 100644
--- a/content/renderer/render_view_browsertest.cc
+++ b/content/renderer/render_view_browsertest.cc
@@ -417,30 +417,6 @@ TEST_F(RenderViewImplTest, DecideNavigationPolicyForWebUI) {
new_view->Release();
}
-TEST_F(RenderViewImplTest, ChromeNativeSchemeCommitsSynchronously) {
- LoadHTML("<div>Page A</div>");
- int initial_page_id = view()->GetPageId();
-
- // Issue a navigation to a chrome-native page.
- ViewMsg_Navigate_Params nav_params;
- nav_params.url = GURL("chrome-native://testpage");
- nav_params.navigation_type = ViewMsg_Navigate_Type::NORMAL;
- nav_params.transition = PAGE_TRANSITION_TYPED;
- nav_params.current_history_list_length = 1;
- nav_params.current_history_list_offset = 0;
- nav_params.pending_history_list_offset = 1;
- nav_params.page_id = -1;
- view()->OnNavigate(nav_params);
-
- // Ensure the chrome-native:// navigate commits synchronously.
- EXPECT_NE(initial_page_id, view()->GetPageId());
-
- ProcessPendingMessages();
- const IPC::Message* msg = render_thread_->sink().GetUniqueMessageMatching(
- ViewHostMsg_UpdateState::ID);
- EXPECT_TRUE(msg);
-}
-
// Ensure the RenderViewImpl sends an ACK to a SwapOut request, even if it is
// already swapped out. http://crbug.com/93427.
TEST_F(RenderViewImplTest, SendSwapOutACK) {
diff --git a/content/renderer/render_view_impl.h b/content/renderer/render_view_impl.h
index 7beac39..603c80ed 100644
--- a/content/renderer/render_view_impl.h
+++ b/content/renderer/render_view_impl.h
@@ -861,8 +861,6 @@ class CONTENT_EXPORT RenderViewImpl
FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest, OnNavStateChanged);
FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest, OnSetTextDirection);
FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest, OnUpdateWebPreferences);
- FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest,
- ChromeNativeSchemeCommitsSynchronously);
FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest, SendSwapOutACK);
FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest, ReloadWhileSwappedOut);
FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest,