diff options
author | thakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-30 09:31:01 +0000 |
---|---|---|
committer | thakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-30 09:31:01 +0000 |
commit | f85f070f8fca83ca373929584218d7185ff89220 (patch) | |
tree | 0933796547053b57ac5cc69a17537f957879a0b1 /chrome/renderer | |
parent | eaa4d15649601d4ec30136264825ccde40d91907 (diff) | |
download | chromium_src-f85f070f8fca83ca373929584218d7185ff89220.zip chromium_src-f85f070f8fca83ca373929584218d7185ff89220.tar.gz chromium_src-f85f070f8fca83ca373929584218d7185ff89220.tar.bz2 |
IPC per-host content settings to the renderers.
BUG=32719
TEST=none
Review URL: http://codereview.chromium.org/549218
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@37628 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer')
-rw-r--r-- | chrome/renderer/render_thread.cc | 36 | ||||
-rw-r--r-- | chrome/renderer/render_thread.h | 5 | ||||
-rw-r--r-- | chrome/renderer/render_view.cc | 40 | ||||
-rw-r--r-- | chrome/renderer/render_view.h | 11 |
4 files changed, 85 insertions, 7 deletions
diff --git a/chrome/renderer/render_thread.cc b/chrome/renderer/render_thread.cc index 2d47a43..1123790 100644 --- a/chrome/renderer/render_thread.cc +++ b/chrome/renderer/render_thread.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 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. @@ -88,6 +88,7 @@ using WebKit::WebCache; using WebKit::WebCrossOriginPreflightResultCache; using WebKit::WebFontCache; +using WebKit::WebFrame; using WebKit::WebRuntimeFeatures; using WebKit::WebSecurityPolicy; using WebKit::WebScriptController; @@ -139,6 +140,30 @@ class SuicideOnChannelErrorFilter : public IPC::ChannelProxy::MessageFilter { }; #endif +class RenderViewContentSettingsSetter : public RenderViewVisitor { + public: + RenderViewContentSettingsSetter(const std::string& host, + const ContentSettings& content_settings) + : host_(host), + content_settings_(content_settings) { + } + + virtual bool Visit(RenderView* render_view) { + // |render_view->webview()| is guaranteed non-NULL. + WebFrame* frame = render_view->webview()->mainFrame(); + if (GURL(frame->url()).host() == host_) { + render_view->ApplyContentSettings(frame, content_settings_); + } + return true; + } + + private: + std::string host_; + ContentSettings content_settings_; + + DISALLOW_COPY_AND_ASSIGN(RenderViewContentSettingsSetter); +}; + class RenderViewZoomer : public RenderViewVisitor { public: RenderViewZoomer(const std::string& host, int zoom_level) @@ -284,6 +309,13 @@ void RenderThread::OnResetVisitedLinks() { WebView::resetVisitedLinkState(); } +void RenderThread::OnSetContentSettingsForCurrentHost( + const std::string& host, + const ContentSettings& content_settings) { + RenderViewContentSettingsSetter setter(host, content_settings); + RenderView::ForEach(&setter); +} + void RenderThread::OnSetZoomLevelForCurrentHost(const std::string& host, int zoom_level) { RenderViewZoomer zoomer(host, zoom_level); @@ -343,6 +375,8 @@ void RenderThread::OnControlMessageReceived(const IPC::Message& msg) { IPC_MESSAGE_HANDLER(ViewMsg_VisitedLink_NewTable, OnUpdateVisitedLinks) IPC_MESSAGE_HANDLER(ViewMsg_VisitedLink_Add, OnAddVisitedLinks) IPC_MESSAGE_HANDLER(ViewMsg_VisitedLink_Reset, OnResetVisitedLinks) + IPC_MESSAGE_HANDLER(ViewMsg_SetContentSettingsForCurrentHost, + OnSetContentSettingsForCurrentHost) IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForCurrentHost, OnSetZoomLevelForCurrentHost) IPC_MESSAGE_HANDLER(ViewMsg_SetNextPageID, OnSetNextPageID) diff --git a/chrome/renderer/render_thread.h b/chrome/renderer/render_thread.h index 559b7dc..4f992e4 100644 --- a/chrome/renderer/render_thread.h +++ b/chrome/renderer/render_thread.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 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. @@ -38,6 +38,7 @@ class SkBitmap; class UserScriptSlave; class URLPattern; +struct ContentSettings; struct RendererPreferences; struct ViewMsg_DOMStorageEvent_Params; struct ViewMsg_New_Params; @@ -159,6 +160,8 @@ class RenderThread : public RenderThreadBase, void OnAddVisitedLinks(const VisitedLinkSlave::Fingerprints& fingerprints); void OnResetVisitedLinks(); void OnSetZoomLevelForCurrentHost(const std::string& host, int zoom_level); + void OnSetContentSettingsForCurrentHost( + const std::string& host, const ContentSettings& content_settings); void OnUpdateUserScripts(base::SharedMemoryHandle table); void OnSetExtensionFunctionNames(const std::vector<std::string>& names); void OnPageActionsUpdated(const std::string& extension_id, diff --git a/chrome/renderer/render_view.cc b/chrome/renderer/render_view.cc index 98c754f..183fbd3 100644 --- a/chrome/renderer/render_view.cc +++ b/chrome/renderer/render_view.cc @@ -494,6 +494,8 @@ void RenderView::OnMessageReceived(const IPC::Message& message) { IPC_MESSAGE_HANDLER(ViewMsg_ExecuteEditCommand, OnExecuteEditCommand) IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind) IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom) + IPC_MESSAGE_HANDLER(ViewMsg_SetContentSettingsForLoadingHost, + OnSetContentSettingsForLoadingHost) IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForLoadingHost, OnSetZoomLevelForLoadingHost) IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding) @@ -1082,6 +1084,18 @@ void RenderView::OnSetInitialFocus(bool reverse) { /////////////////////////////////////////////////////////////////////////////// +void RenderView::ApplyContentSettings( + WebKit::WebFrame* frame, + const ContentSettings& settings) { + // CONTENT_SETTING_ASK is only valid for cookies. + allowImages(frame, settings.settings[CONTENT_SETTINGS_TYPE_IMAGES] == + CONTENT_SETTING_ALLOW); + allowScript(frame, settings.settings[CONTENT_SETTINGS_TYPE_JAVASCRIPT] == + CONTENT_SETTING_ALLOW); + allowPlugins(frame, settings.settings[CONTENT_SETTINGS_TYPE_PLUGINS] == + CONTENT_SETTING_ALLOW); +} + // Tell the embedding application that the URL of the active page has changed void RenderView::UpdateURL(WebFrame* frame) { WebDataSource* ds = frame->dataSource(); @@ -1135,15 +1149,27 @@ void RenderView::UpdateURL(WebFrame* frame) { if (!frame->parent()) { // Top-level navigation. + // Set content settings. + HostContentSettings::iterator host_content_settings = + host_content_settings_.find(GURL(request.url()).host()); + if (host_content_settings != host_content_settings_.end()) { + ApplyContentSettings(frame, host_content_settings->second); + + // These content settings were merely recorded transiently for this load. + // We can erase them now. If at some point we reload this page, the + // browser will send us new, up-to-date content settings. + host_content_settings_.erase(host_content_settings); + } + // Set zoom level. - HostZoomLevels::iterator host = + HostZoomLevels::iterator host_zoom = host_zoom_levels_.find(GURL(request.url()).host()); - if (host != host_zoom_levels_.end()) { - webview()->setZoomLevel(false, host->second); + if (host_zoom != host_zoom_levels_.end()) { + webview()->setZoomLevel(false, host_zoom->second); // This zoom level was merely recorded transiently for this load. We can // erase it now. If at some point we reload this page, the browser will // send us a new, up-to-date zoom level. - host_zoom_levels_.erase(host); + host_zoom_levels_.erase(host_zoom); } // Drop the translated nodes. @@ -3155,6 +3181,12 @@ void RenderView::OnZoom(PageZoom::Function function) { Send(new ViewHostMsg_DidZoomHost(host, new_zoom_level)); } +void RenderView::OnSetContentSettingsForLoadingHost( + std::string host, + const ContentSettings& content_settings) { + host_content_settings_[host] = content_settings; +} + void RenderView::OnSetZoomLevelForLoadingHost(std::string host, int zoom_level) { host_zoom_levels_[host] = zoom_level; diff --git a/chrome/renderer/render_view.h b/chrome/renderer/render_view.h index 940b404..c94229c 100644 --- a/chrome/renderer/render_view.h +++ b/chrome/renderer/render_view.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 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. @@ -22,6 +22,7 @@ #include "base/values.h" #include "base/weak_ptr.h" #include "build/build_config.h" +#include "chrome/common/content_settings.h" #include "chrome/common/edit_command.h" #include "chrome/common/navigation_gesture.h" #include "chrome/common/notification_type.h" @@ -261,6 +262,10 @@ class RenderView : public RenderWidget, return notification_provider_.get(); } + // Shortcut for calling allowImages(), allowScripts(), allowPlugins(). + void ApplyContentSettings(WebKit::WebFrame* frame, + const ContentSettings& settings); + // WebKit::WebWidgetClient // Most methods are handled by RenderWidget. virtual void show(WebKit::WebNavigationPolicy policy); @@ -478,6 +483,7 @@ class RenderView : public RenderWidget, FRIEND_TEST(RenderViewTest, MacTestCmdUp); #endif + typedef std::map<std::string, ContentSettings> HostContentSettings; typedef std::map<std::string, int> HostZoomLevels; explicit RenderView(RenderThreadBase* render_thread, @@ -582,6 +588,8 @@ class RenderView : public RenderWidget, void OnCancelDownload(int32 download_id); void OnFind(int request_id, const string16&, const WebKit::WebFindOptions&); void OnDeterminePageLanguage(); + void OnSetContentSettingsForLoadingHost( + std::string host, const ContentSettings& content_settings); void OnZoom(PageZoom::Function function); void OnSetZoomLevelForLoadingHost(std::string host, int zoom_level); void OnSetPageEncoding(const std::string& encoding_name); @@ -1024,6 +1032,7 @@ class RenderView : public RenderWidget, typedef std::map<WebKit::WebView*, RenderView*> ViewMap; + HostContentSettings host_content_settings_; HostZoomLevels host_zoom_levels_; // The SessionStorage namespace that we're assigned to has an ID, and that ID |