summaryrefslogtreecommitdiffstats
path: root/chrome/renderer
diff options
context:
space:
mode:
authormarja@chromium.org <marja@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-08 08:52:52 +0000
committermarja@chromium.org <marja@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-08 08:52:52 +0000
commitc24e91a9bc8c9ec57c0f870687fa9f6e366c9f7e (patch)
treeedd48589e49370fef10b9c009b9f520df99fc376 /chrome/renderer
parent43cbd759bddfc293d3dfc315c7b7ee893fe50c4e (diff)
downloadchromium_src-c24e91a9bc8c9ec57c0f870687fa9f6e366c9f7e.zip
chromium_src-c24e91a9bc8c9ec57c0f870687fa9f6e366c9f7e.tar.gz
chromium_src-c24e91a9bc8c9ec57c0f870687fa9f6e366c9f7e.tar.bz2
Content settings: allow scripts on interstitial pages even if JavaScript is blocked.
BUG=104700 TEST=ChromeRenderViewTest.ContentSettingsInterstitialPages Review URL: http://codereview.chromium.org/8773035 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@113579 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer')
-rw-r--r--chrome/renderer/chrome_render_view_observer.cc5
-rw-r--r--chrome/renderer/chrome_render_view_observer.h1
-rw-r--r--chrome/renderer/content_settings_observer.cc13
-rw-r--r--chrome/renderer/content_settings_observer.h5
-rw-r--r--chrome/renderer/content_settings_observer_browsertest.cc52
5 files changed, 75 insertions, 1 deletions
diff --git a/chrome/renderer/chrome_render_view_observer.cc b/chrome/renderer/chrome_render_view_observer.cc
index 8367a83..98e28e8 100644
--- a/chrome/renderer/chrome_render_view_observer.cc
+++ b/chrome/renderer/chrome_render_view_observer.cc
@@ -269,6 +269,7 @@ bool ChromeRenderViewObserver::OnMessageReceived(const IPC::Message& message) {
IPC_MESSAGE_HANDLER(ChromeViewMsg_GetFPS, OnGetFPS)
IPC_MESSAGE_HANDLER(ChromeViewMsg_AddStrictSecurityHost,
OnAddStrictSecurityHost)
+ IPC_MESSAGE_HANDLER(ChromeViewMsg_SetAsInterstitial, OnSetAsInterstitial)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
@@ -366,6 +367,10 @@ void ChromeRenderViewObserver::OnAddStrictSecurityHost(
strict_security_hosts_.insert(host);
}
+void ChromeRenderViewObserver::OnSetAsInterstitial() {
+ content_settings_->SetAsInterstitial();
+}
+
void ChromeRenderViewObserver::Navigate(const GURL& url) {
// Execute cache clear operations that were postponed until a navigation
// event (including tab reload).
diff --git a/chrome/renderer/chrome_render_view_observer.h b/chrome/renderer/chrome_render_view_observer.h
index bbaa13e..4cb21e0 100644
--- a/chrome/renderer/chrome_render_view_observer.h
+++ b/chrome/renderer/chrome_render_view_observer.h
@@ -133,6 +133,7 @@ class ChromeRenderViewObserver : public content::RenderViewObserver,
void OnStartFrameSniffer(const string16& frame_name);
void OnGetFPS();
void OnAddStrictSecurityHost(const std::string& host);
+ void OnSetAsInterstitial();
// Captures the thumbnail and text contents for indexing for the given load
// ID. If the view's load ID is different than the parameter, this call is
diff --git a/chrome/renderer/content_settings_observer.cc b/chrome/renderer/content_settings_observer.cc
index beabcd7..246d831b 100644
--- a/chrome/renderer/content_settings_observer.cc
+++ b/chrome/renderer/content_settings_observer.cc
@@ -68,7 +68,8 @@ ContentSettingsObserver::ContentSettingsObserver(
: content::RenderViewObserver(render_view),
content::RenderViewObserverTracker<ContentSettingsObserver>(render_view),
content_setting_rules_(NULL),
- plugins_temporarily_allowed_(false) {
+ plugins_temporarily_allowed_(false),
+ is_interstitial_page_(false) {
ClearBlockedContentSettings();
}
@@ -162,6 +163,8 @@ bool ContentSettingsObserver::AllowFileSystem(WebFrame* frame) {
bool ContentSettingsObserver::AllowImage(WebFrame* frame,
bool enabled_per_settings,
const WebURL& image_url) {
+ if (is_interstitial_page_)
+ return true;
if (IsWhitelistedForContentSettings(frame))
return true;
@@ -200,6 +203,8 @@ bool ContentSettingsObserver::AllowPlugins(WebFrame* frame,
bool ContentSettingsObserver::AllowScript(WebFrame* frame,
bool enabled_per_settings) {
+ if (is_interstitial_page_)
+ return true;
if (!enabled_per_settings)
return false;
@@ -229,6 +234,8 @@ bool ContentSettingsObserver::AllowScriptFromSource(
WebFrame* frame,
bool enabled_per_settings,
const WebKit::WebURL& script_url) {
+ if (is_interstitial_page_)
+ return true;
if (!enabled_per_settings)
return false;
@@ -272,6 +279,10 @@ void ContentSettingsObserver::DidNotAllowScript(WebFrame* frame) {
DidBlockContentType(CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string());
}
+void ContentSettingsObserver::SetAsInterstitial() {
+ is_interstitial_page_ = true;
+}
+
void ContentSettingsObserver::OnLoadBlockedPlugins() {
plugins_temporarily_allowed_ = true;
}
diff --git a/chrome/renderer/content_settings_observer.h b/chrome/renderer/content_settings_observer.h
index 027867c..689a77d 100644
--- a/chrome/renderer/content_settings_observer.h
+++ b/chrome/renderer/content_settings_observer.h
@@ -65,6 +65,10 @@ class ContentSettingsObserver
void DidNotAllowPlugins(WebKit::WebFrame* frame);
void DidNotAllowScript(WebKit::WebFrame* frame);
+ // Used for allowing scripts and images on views displaying interstitial
+ // pages.
+ void SetAsInterstitial();
+
private:
FRIEND_TEST_ALL_PREFIXES(ContentSettingsObserverTest, WhitelistedSchemes);
@@ -103,6 +107,7 @@ class ContentSettingsObserver
std::map<WebKit::WebFrame*, bool> cached_script_permissions_;
bool plugins_temporarily_allowed_;
+ bool is_interstitial_page_;
DISALLOW_COPY_AND_ASSIGN(ContentSettingsObserver);
};
diff --git a/chrome/renderer/content_settings_observer_browsertest.cc b/chrome/renderer/content_settings_observer_browsertest.cc
index d05df62..db720f5 100644
--- a/chrome/renderer/content_settings_observer_browsertest.cc
+++ b/chrome/renderer/content_settings_observer_browsertest.cc
@@ -322,3 +322,55 @@ TEST_F(ChromeRenderViewTest, ContentSettingsAllowScripts) {
}
EXPECT_FALSE(was_blocked);
}
+
+TEST_F(ChromeRenderViewTest, ContentSettingsInterstitialPages) {
+ MockContentSettingsObserver mock_observer(view_);
+ // Block scripts.
+ RendererContentSettingRules content_setting_rules;
+ ContentSettingsForOneType& script_setting_rules =
+ content_setting_rules.script_rules;
+ script_setting_rules.push_back(
+ ContentSettingPatternSource(
+ ContentSettingsPattern::Wildcard(),
+ ContentSettingsPattern::Wildcard(),
+ CONTENT_SETTING_BLOCK, "", false));
+ // Block images.
+ ContentSettingsForOneType& image_setting_rules =
+ content_setting_rules.image_rules;
+ image_setting_rules.push_back(
+ ContentSettingPatternSource(
+ ContentSettingsPattern::Wildcard(),
+ ContentSettingsPattern::Wildcard(),
+ CONTENT_SETTING_BLOCK, "", false));
+
+ ContentSettingsObserver* observer = ContentSettingsObserver::Get(view_);
+ observer->SetContentSettingRules(&content_setting_rules);
+ observer->SetAsInterstitial();
+
+ // Load a page which contains a script.
+ std::string html = "<html>"
+ "<head>"
+ "<script src='data:foo'></script>"
+ "</head>"
+ "<body>"
+ "</body>"
+ "</html>";
+ LoadHTML(html.c_str());
+
+ // Verify that the script was allowed.
+ bool was_blocked = false;
+ for (size_t i = 0; i < render_thread_->sink().message_count(); ++i) {
+ const IPC::Message* msg = render_thread_->sink().GetMessageAt(i);
+ if (msg->type() == ChromeViewHostMsg_ContentBlocked::ID)
+ was_blocked = true;
+ }
+ EXPECT_FALSE(was_blocked);
+
+ // Verify that images are allowed.
+ EXPECT_CALL(
+ mock_observer,
+ OnContentBlocked(CONTENT_SETTINGS_TYPE_IMAGES, std::string())).Times(0);
+ EXPECT_TRUE(observer->AllowImage(GetMainFrame(), true,
+ mock_observer.image_url_));
+ ::testing::Mock::VerifyAndClearExpectations(&observer);
+}