Commit 6f9f7d8e authored by dgozman@chromium.org's avatar dgozman@chromium.org

Revert 113591 - Revert 113579 - Content settings: allow scripts on...

Revert 113591 - Revert 113579 - Content settings: allow scripts on interstitial pages even if JavaScript is blocked.


BUG=104700
TEST=ChromeRenderViewTest.ContentSettingsInterstitialPages


Review URL: http://codereview.chromium.org/8773035

TBR=marja@chromium.org
Review URL: http://codereview.chromium.org/8889008

TBR=dgozman@chromium.org
Review URL: http://codereview.chromium.org/8873015

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@113594 0039d316-1c4b-4281-b951-d872f2087c98
parent 1464ce1e
...@@ -8,6 +8,8 @@ ...@@ -8,6 +8,8 @@
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/renderer_preferences_util.h" #include "chrome/browser/renderer_preferences_util.h"
#include "chrome/common/chrome_notification_types.h" #include "chrome/common/chrome_notification_types.h"
#include "chrome/common/render_messages.h"
#include "content/browser/renderer_host/render_view_host.h"
#include "content/browser/tab_contents/tab_contents.h" #include "content/browser/tab_contents/tab_contents.h"
#include "content/public/browser/notification_details.h" #include "content/public/browser/notification_details.h"
#include "content/public/browser/notification_source.h" #include "content/public/browser/notification_source.h"
...@@ -31,6 +33,8 @@ void ChromeInterstitialPage::Show() { ...@@ -31,6 +33,8 @@ void ChromeInterstitialPage::Show() {
notification_registrar_.Add( notification_registrar_.Add(
this, chrome::NOTIFICATION_DOM_OPERATION_RESPONSE, this, chrome::NOTIFICATION_DOM_OPERATION_RESPONSE,
content::Source<RenderViewHost>(render_view_host())); content::Source<RenderViewHost>(render_view_host()));
render_view_host()->Send(
new ChromeViewMsg_SetAsInterstitial(render_view_host()->routing_id()));
} }
void ChromeInterstitialPage::Observe( void ChromeInterstitialPage::Observe(
......
...@@ -347,6 +347,9 @@ IPC_MESSAGE_ROUTED2(ChromeViewMsg_JavaScriptStressTestControl, ...@@ -347,6 +347,9 @@ IPC_MESSAGE_ROUTED2(ChromeViewMsg_JavaScriptStressTestControl,
// Asks the renderer to send back FPS. // Asks the renderer to send back FPS.
IPC_MESSAGE_ROUTED0(ChromeViewMsg_GetFPS) IPC_MESSAGE_ROUTED0(ChromeViewMsg_GetFPS)
// Tells the view it is displaying an interstitial page.
IPC_MESSAGE_ROUTED0(ChromeViewMsg_SetAsInterstitial)
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// TabContents messages // TabContents messages
// These are messages sent from the renderer to the browser process. // These are messages sent from the renderer to the browser process.
......
...@@ -269,6 +269,7 @@ bool ChromeRenderViewObserver::OnMessageReceived(const IPC::Message& message) { ...@@ -269,6 +269,7 @@ bool ChromeRenderViewObserver::OnMessageReceived(const IPC::Message& message) {
IPC_MESSAGE_HANDLER(ChromeViewMsg_GetFPS, OnGetFPS) IPC_MESSAGE_HANDLER(ChromeViewMsg_GetFPS, OnGetFPS)
IPC_MESSAGE_HANDLER(ChromeViewMsg_AddStrictSecurityHost, IPC_MESSAGE_HANDLER(ChromeViewMsg_AddStrictSecurityHost,
OnAddStrictSecurityHost) OnAddStrictSecurityHost)
IPC_MESSAGE_HANDLER(ChromeViewMsg_SetAsInterstitial, OnSetAsInterstitial)
IPC_MESSAGE_UNHANDLED(handled = false) IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP() IPC_END_MESSAGE_MAP()
...@@ -366,6 +367,10 @@ void ChromeRenderViewObserver::OnAddStrictSecurityHost( ...@@ -366,6 +367,10 @@ void ChromeRenderViewObserver::OnAddStrictSecurityHost(
strict_security_hosts_.insert(host); strict_security_hosts_.insert(host);
} }
void ChromeRenderViewObserver::OnSetAsInterstitial() {
content_settings_->SetAsInterstitial();
}
void ChromeRenderViewObserver::Navigate(const GURL& url) { void ChromeRenderViewObserver::Navigate(const GURL& url) {
// Execute cache clear operations that were postponed until a navigation // Execute cache clear operations that were postponed until a navigation
// event (including tab reload). // event (including tab reload).
......
...@@ -133,6 +133,7 @@ class ChromeRenderViewObserver : public content::RenderViewObserver, ...@@ -133,6 +133,7 @@ class ChromeRenderViewObserver : public content::RenderViewObserver,
void OnStartFrameSniffer(const string16& frame_name); void OnStartFrameSniffer(const string16& frame_name);
void OnGetFPS(); void OnGetFPS();
void OnAddStrictSecurityHost(const std::string& host); void OnAddStrictSecurityHost(const std::string& host);
void OnSetAsInterstitial();
// Captures the thumbnail and text contents for indexing for the given load // 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 // ID. If the view's load ID is different than the parameter, this call is
......
...@@ -68,7 +68,8 @@ ContentSettingsObserver::ContentSettingsObserver( ...@@ -68,7 +68,8 @@ ContentSettingsObserver::ContentSettingsObserver(
: content::RenderViewObserver(render_view), : content::RenderViewObserver(render_view),
content::RenderViewObserverTracker<ContentSettingsObserver>(render_view), content::RenderViewObserverTracker<ContentSettingsObserver>(render_view),
content_setting_rules_(NULL), content_setting_rules_(NULL),
plugins_temporarily_allowed_(false) { plugins_temporarily_allowed_(false),
is_interstitial_page_(false) {
ClearBlockedContentSettings(); ClearBlockedContentSettings();
} }
...@@ -162,6 +163,8 @@ bool ContentSettingsObserver::AllowFileSystem(WebFrame* frame) { ...@@ -162,6 +163,8 @@ bool ContentSettingsObserver::AllowFileSystem(WebFrame* frame) {
bool ContentSettingsObserver::AllowImage(WebFrame* frame, bool ContentSettingsObserver::AllowImage(WebFrame* frame,
bool enabled_per_settings, bool enabled_per_settings,
const WebURL& image_url) { const WebURL& image_url) {
if (is_interstitial_page_)
return true;
if (IsWhitelistedForContentSettings(frame)) if (IsWhitelistedForContentSettings(frame))
return true; return true;
...@@ -200,6 +203,8 @@ bool ContentSettingsObserver::AllowPlugins(WebFrame* frame, ...@@ -200,6 +203,8 @@ bool ContentSettingsObserver::AllowPlugins(WebFrame* frame,
bool ContentSettingsObserver::AllowScript(WebFrame* frame, bool ContentSettingsObserver::AllowScript(WebFrame* frame,
bool enabled_per_settings) { bool enabled_per_settings) {
if (is_interstitial_page_)
return true;
if (!enabled_per_settings) if (!enabled_per_settings)
return false; return false;
...@@ -229,6 +234,8 @@ bool ContentSettingsObserver::AllowScriptFromSource( ...@@ -229,6 +234,8 @@ bool ContentSettingsObserver::AllowScriptFromSource(
WebFrame* frame, WebFrame* frame,
bool enabled_per_settings, bool enabled_per_settings,
const WebKit::WebURL& script_url) { const WebKit::WebURL& script_url) {
if (is_interstitial_page_)
return true;
if (!enabled_per_settings) if (!enabled_per_settings)
return false; return false;
...@@ -272,6 +279,10 @@ void ContentSettingsObserver::DidNotAllowScript(WebFrame* frame) { ...@@ -272,6 +279,10 @@ void ContentSettingsObserver::DidNotAllowScript(WebFrame* frame) {
DidBlockContentType(CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string()); DidBlockContentType(CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string());
} }
void ContentSettingsObserver::SetAsInterstitial() {
is_interstitial_page_ = true;
}
void ContentSettingsObserver::OnLoadBlockedPlugins() { void ContentSettingsObserver::OnLoadBlockedPlugins() {
plugins_temporarily_allowed_ = true; plugins_temporarily_allowed_ = true;
} }
......
...@@ -65,6 +65,10 @@ class ContentSettingsObserver ...@@ -65,6 +65,10 @@ class ContentSettingsObserver
void DidNotAllowPlugins(WebKit::WebFrame* frame); void DidNotAllowPlugins(WebKit::WebFrame* frame);
void DidNotAllowScript(WebKit::WebFrame* frame); void DidNotAllowScript(WebKit::WebFrame* frame);
// Used for allowing scripts and images on views displaying interstitial
// pages.
void SetAsInterstitial();
private: private:
FRIEND_TEST_ALL_PREFIXES(ContentSettingsObserverTest, WhitelistedSchemes); FRIEND_TEST_ALL_PREFIXES(ContentSettingsObserverTest, WhitelistedSchemes);
...@@ -103,6 +107,7 @@ class ContentSettingsObserver ...@@ -103,6 +107,7 @@ class ContentSettingsObserver
std::map<WebKit::WebFrame*, bool> cached_script_permissions_; std::map<WebKit::WebFrame*, bool> cached_script_permissions_;
bool plugins_temporarily_allowed_; bool plugins_temporarily_allowed_;
bool is_interstitial_page_;
DISALLOW_COPY_AND_ASSIGN(ContentSettingsObserver); DISALLOW_COPY_AND_ASSIGN(ContentSettingsObserver);
}; };
......
...@@ -322,3 +322,55 @@ TEST_F(ChromeRenderViewTest, ContentSettingsAllowScripts) { ...@@ -322,3 +322,55 @@ TEST_F(ChromeRenderViewTest, ContentSettingsAllowScripts) {
} }
EXPECT_FALSE(was_blocked); 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);
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment