diff options
author | thakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-03 04:52:35 +0000 |
---|---|---|
committer | thakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-03 04:52:35 +0000 |
commit | 0de8016abb321cb9a1c32dfb534cf16ec905b260 (patch) | |
tree | 8989f7d188bdc20f0cb3d64ef66053ccc953c5fb | |
parent | 1ff7a03b1ddb3032ce180c61da642cf38fd7c9ad (diff) | |
download | chromium_src-0de8016abb321cb9a1c32dfb534cf16ec905b260.zip chromium_src-0de8016abb321cb9a1c32dfb534cf16ec905b260.tar.gz chromium_src-0de8016abb321cb9a1c32dfb534cf16ec905b260.tar.bz2 |
Let renderer notify browser if content gets blocked.
BUG=
TEST=Go to a page with blocked stuff. Icons should appear in omnibox.
Review URL: http://codereview.chromium.org/565010
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@37951 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/renderer_host/render_view_host.cc | 8 | ||||
-rw-r--r-- | chrome/browser/renderer_host/render_view_host.h | 3 | ||||
-rw-r--r-- | chrome/browser/renderer_host/render_view_host_delegate.h | 5 | ||||
-rw-r--r-- | chrome/browser/tab_contents/tab_contents.cc | 46 | ||||
-rw-r--r-- | chrome/browser/tab_contents/tab_contents.h | 7 | ||||
-rw-r--r-- | chrome/common/common_param_traits.h | 20 | ||||
-rw-r--r-- | chrome/common/render_messages_internal.h | 5 | ||||
-rw-r--r-- | chrome/renderer/render_view.cc | 42 | ||||
-rw-r--r-- | chrome/renderer/render_view.h | 13 |
9 files changed, 124 insertions, 25 deletions
diff --git a/chrome/browser/renderer_host/render_view_host.cc b/chrome/browser/renderer_host/render_view_host.cc index ac79c08..58e379d 100644 --- a/chrome/browser/renderer_host/render_view_host.cc +++ b/chrome/browser/renderer_host/render_view_host.cc @@ -826,6 +826,7 @@ void RenderViewHost::OnMessageReceived(const IPC::Message& msg) { IPC_MESSAGE_HANDLER(ViewHostMsg_OnCSSInserted, OnCSSInserted) IPC_MESSAGE_HANDLER(ViewHostMsg_PageContents, OnPageContents) IPC_MESSAGE_HANDLER(ViewHostMsg_PageTranslated, OnPageTranslated) + IPC_MESSAGE_HANDLER(ViewHostMsg_ContentBlocked, OnContentBlocked) // Have the super handle all other messages. IPC_MESSAGE_UNHANDLED(RenderWidgetHost::OnMessageReceived(msg)) IPC_END_MESSAGE_MAP_EX() @@ -1807,3 +1808,10 @@ void RenderViewHost::OnPageTranslated(int32 page_id, integration_delegate->OnPageTranslated(page_id, original_lang, translated_lang); } + +void RenderViewHost::OnContentBlocked(ContentSettingsType type) { + RenderViewHostDelegate::Resource* resource_delegate = + delegate_->GetResourceDelegate(); + if (resource_delegate) + resource_delegate->OnContentBlocked(type); +} diff --git a/chrome/browser/renderer_host/render_view_host.h b/chrome/browser/renderer_host/render_view_host.h index 274df69..2fb8931 100644 --- a/chrome/browser/renderer_host/render_view_host.h +++ b/chrome/browser/renderer_host/render_view_host.h @@ -10,6 +10,7 @@ #include "base/scoped_ptr.h" #include "chrome/browser/renderer_host/render_widget_host.h" +#include "chrome/common/content_settings_types.h" #include "chrome/common/page_zoom.h" #include "chrome/common/view_types.h" #include "net/base/load_states.h" @@ -606,7 +607,7 @@ class RenderViewHost : public RenderWidgetHost { void OnPageTranslated(int32 page_id, const std::string& original_lang, const std::string& translated_lang); - + void OnContentBlocked(ContentSettingsType type); private: friend class TestRenderViewHost; diff --git a/chrome/browser/renderer_host/render_view_host_delegate.h b/chrome/browser/renderer_host/render_view_host_delegate.h index 6ac79f7..02c5d92 100644 --- a/chrome/browser/renderer_host/render_view_host_delegate.h +++ b/chrome/browser/renderer_host/render_view_host_delegate.h @@ -10,6 +10,7 @@ #include "base/basictypes.h" #include "base/string16.h" +#include "chrome/common/content_settings_types.h" #include "chrome/common/view_types.h" #include "net/base/load_states.h" #include "third_party/WebKit/WebKit/chromium/public/WebDragOperation.h" @@ -287,6 +288,10 @@ class RenderViewHostDelegate { // Notification that a document has been loaded in a frame. virtual void DocumentLoadedInFrame() = 0; + + // Called when content in the current page was blocked due to the user's + // content settings. + virtual void OnContentBlocked(ContentSettingsType type) = 0; }; // Save ---------------------------------------------------------------------- diff --git a/chrome/browser/tab_contents/tab_contents.cc b/chrome/browser/tab_contents/tab_contents.cc index 186e155..1b9bcf7 100644 --- a/chrome/browser/tab_contents/tab_contents.cc +++ b/chrome/browser/tab_contents/tab_contents.cc @@ -268,6 +268,7 @@ TabContents::TabContents(Profile* profile, renderer_preferences_(), opener_dom_ui_type_(DOMUIFactory::kNoDOMUI), app_(false) { + ClearBlockedContentSettings(); renderer_preferences_util::UpdateFromSystemSettings( &renderer_preferences_, profile); @@ -566,7 +567,12 @@ bool TabContents::IsContentBlocked(ContentSettingsType content_type) const { if (content_type == CONTENT_SETTINGS_TYPE_POPUPS) return blocked_popups_ != NULL; - // TODO(pkasting): Return meaningful values here. + if (content_type == CONTENT_SETTINGS_TYPE_IMAGES || + content_type == CONTENT_SETTINGS_TYPE_JAVASCRIPT || + content_type == CONTENT_SETTINGS_TYPE_PLUGINS) + return content_blocked_[content_type]; + + // TODO(pkasting): Return a meaningful values for cookies. return false; } @@ -864,7 +870,8 @@ void TabContents::PopupNotificationVisibilityChanged(bool visible) { return; if (!dont_notify_render_view_) render_view_host()->PopupNotificationVisibilityChanged(visible); - delegate_->OnBlockedContentChange(this); + if (delegate_) + delegate_->OnBlockedContentChange(this); } gfx::NativeView TabContents::GetContentNativeView() const { @@ -1238,6 +1245,14 @@ TabContents* TabContents::CloneAndMakePhantom() { return new_contents; } +// Resets the |content_blocked_| array. +void TabContents::ClearBlockedContentSettings() { + DCHECK_EQ(static_cast<size_t>(CONTENT_SETTINGS_NUM_TYPES), + arraysize(content_blocked_)); + for (int i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) + content_blocked_[i] = false; +} + // Notifies the RenderWidgetHost instance about the fact that the page is // loading, or done loading and calls the base implementation. void TabContents::SetIsLoading(bool is_loading, @@ -1391,8 +1406,8 @@ void TabContents::DidNavigateMainFramePostCommit( // Get the favicon, either from history or request it from the net. fav_icon_helper_.FetchFavIcon(details.entry->url()); - // Clear all page and browser action state for this tab, unless this is an - // in-page navigation. + // Clear all page actions, blocked content notifications and browser actions + // for this tab, unless this is an in-page navigation. url_canon::Replacements<char> replacements; replacements.ClearRef(); if (params.url.ReplaceComponents(replacements) != @@ -1418,6 +1433,17 @@ void TabContents::DidNavigateMainFramePostCommit( } } } + + // Close blocked popups. + if (blocked_popups_) { + AutoReset auto_reset(&dont_notify_render_view_, true); + blocked_popups_->Destroy(); + } + + // Clear "blocked" flags. + ClearBlockedContentSettings(); + if (delegate_) + delegate_->OnBlockedContentChange(this); } // Close constrained windows if necessary. @@ -1425,12 +1451,6 @@ void TabContents::DidNavigateMainFramePostCommit( details.previous_url, details.entry->url())) CloseConstrainedWindows(); - // Close blocked popups. - if (blocked_popups_) { - AutoReset auto_reset(&dont_notify_render_view_, true); - blocked_popups_->Destroy(); - } - // Update the starred state. UpdateStarredStateForCurrentURL(); } @@ -1945,6 +1965,12 @@ void TabContents::DocumentLoadedInFrame() { controller_.DocumentLoadedInFrame(); } +void TabContents::OnContentBlocked(ContentSettingsType type) { + content_blocked_[type] = true; + if (delegate_) + delegate_->OnBlockedContentChange(this); +} + RenderViewHostDelegate::View* TabContents::GetViewDelegate() { return view_.get(); } diff --git a/chrome/browser/tab_contents/tab_contents.h b/chrome/browser/tab_contents/tab_contents.h index 6615959..d74be111 100644 --- a/chrome/browser/tab_contents/tab_contents.h +++ b/chrome/browser/tab_contents/tab_contents.h @@ -692,6 +692,9 @@ class TabContents : public PageNavigator, // TODO(brettw) TestTabContents shouldn't exist! friend class TestTabContents; + // Resets the |content_blocked_| array. + void ClearBlockedContentSettings(); + // Changes the IsLoading state and notifies delegate as needed // |details| is used to provide details on the load that just finished // (but can be null if not applicable). Can be overridden. @@ -833,6 +836,7 @@ class TabContents : public PageNavigator, const GURL& url, bool showing_repost_interstitial); virtual void DocumentLoadedInFrame(); + virtual void OnContentBlocked(ContentSettingsType type); // RenderViewHostDelegate implementation. virtual RenderViewHostDelegate::View* GetViewDelegate(); @@ -1071,6 +1075,9 @@ class TabContents : public PageNavigator, // TODO(pkasting): Hack to try and fix Linux browser tests. bool dont_notify_render_view_; + // Stores which content setting types actually have blocked content. + bool content_blocked_[CONTENT_SETTINGS_NUM_TYPES]; + // Data for shelves and stuff ------------------------------------------------ // Delegates for InfoBars associated with this TabContents. diff --git a/chrome/common/common_param_traits.h b/chrome/common/common_param_traits.h index c82d497..97cf7e8 100644 --- a/chrome/common/common_param_traits.h +++ b/chrome/common/common_param_traits.h @@ -89,6 +89,26 @@ struct ParamTraits<gfx::Size> { }; template <> +struct ParamTraits<ContentSettingsType> { + typedef ContentSettingsType param_type; + static void Write(Message* m, const param_type& p) { + WriteParam(m, static_cast<int>(p)); + } + static bool Read(const Message* m, void** iter, param_type* r) { + int value; + if (!ReadParam(m, iter, &value)) + return false; + if (value < 0 || value >= static_cast<int>(CONTENT_SETTINGS_NUM_TYPES)) + return false; + *r = static_cast<param_type>(value); + return true; + } + static void Log(const param_type& p, std::wstring* l) { + LogParam(static_cast<int>(p), l); + } +}; + +template <> struct ParamTraits<ContentSettings> { typedef ContentSettings param_type; static void Write(Message* m, const param_type& p); diff --git a/chrome/common/render_messages_internal.h b/chrome/common/render_messages_internal.h index 7b25b7a..a3247ea 100644 --- a/chrome/common/render_messages_internal.h +++ b/chrome/common/render_messages_internal.h @@ -1156,6 +1156,11 @@ IPC_BEGIN_MESSAGES(ViewHost) IPC_MESSAGE_ROUTED1(ViewHostMsg_UpdateSpellingPanelWithMisspelledWord, string16 /* the word to update the panel with */) + // Tells the browser that content in the current page was blocked due to the + // user's content settings. + IPC_MESSAGE_ROUTED1(ViewHostMsg_ContentBlocked, + ContentSettingsType /* type of blocked content */) + // Initiates a download based on user actions like 'ALT+click'. IPC_MESSAGE_ROUTED2(ViewHostMsg_DownloadUrl, GURL /* url */, diff --git a/chrome/renderer/render_view.cc b/chrome/renderer/render_view.cc index 54cb6c2..268aa41 100644 --- a/chrome/renderer/render_view.cc +++ b/chrome/renderer/render_view.cc @@ -312,6 +312,7 @@ RenderView::RenderView(RenderThreadBase* render_thread, webkit_preferences_(webkit_preferences), session_storage_namespace_id_(session_storage_namespace_id), ALLOW_THIS_IN_INITIALIZER_LIST(text_translator_(this)) { + ClearBlockedContentSettings(); page_translator_.reset(new PageTranslator(&text_translator_, this)); } @@ -2037,19 +2038,11 @@ void RenderView::willClose(WebFrame* frame) { } bool RenderView::allowPlugins(WebFrame* frame, bool enabled_per_settings) { - if (!enabled_per_settings) - return false; - // CONTENT_SETTING_ASK is only valid for cookies. - return current_content_settings_.settings[CONTENT_SETTINGS_TYPE_PLUGINS] != - CONTENT_SETTING_BLOCK; + return allowContentType(CONTENT_SETTINGS_TYPE_PLUGINS, enabled_per_settings); } bool RenderView::allowImages(WebFrame* frame, bool enabled_per_settings) { - if (!enabled_per_settings) - return false; - // CONTENT_SETTING_ASK is only valid for cookies. - return current_content_settings_.settings[CONTENT_SETTINGS_TYPE_IMAGES] != - CONTENT_SETTING_BLOCK; + return allowContentType(CONTENT_SETTINGS_TYPE_IMAGES, enabled_per_settings); } void RenderView::loadURLExternally( @@ -2600,6 +2593,8 @@ void RenderView::didReceiveResponse( if (!frame->provisionalDataSource() || frame->parent()) return; + // A new page is about to be loaded. Clear "block" flags. + ClearBlockedContentSettings(); // If we are in view source mode, then just let the user see the source of // the server's 404 error page. if (frame->isViewSourceModeEnabled()) @@ -2681,10 +2676,8 @@ void RenderView::didRunInsecureContent( bool RenderView::allowScript(WebFrame* frame, bool enabled_per_settings) { if (enabled_per_settings) { - // CONTENT_SETTING_ASK is only valid for cookies. - return - current_content_settings_.settings[CONTENT_SETTINGS_TYPE_JAVASCRIPT] != - CONTENT_SETTING_BLOCK; + return allowContentType(CONTENT_SETTINGS_TYPE_JAVASCRIPT, + enabled_per_settings); } WebSecurityOrigin origin = frame->securityOrigin(); @@ -3184,6 +3177,27 @@ std::string RenderView::DetermineTextLanguage(const std::wstring& text) { return language; } +bool RenderView::allowContentType(ContentSettingsType settings_type, + bool enabled_per_settings) { + if (!enabled_per_settings) + return false; + // CONTENT_SETTING_ASK is only valid for cookies. + if (current_content_settings_.settings[settings_type] == CONTENT_SETTING_BLOCK + && !content_blocked_[settings_type]) { + content_blocked_[settings_type] = true; + Send(new ViewHostMsg_ContentBlocked(routing_id_, settings_type)); + return false; + } + return true; +} + +void RenderView::ClearBlockedContentSettings() { + DCHECK_EQ(static_cast<size_t>(CONTENT_SETTINGS_NUM_TYPES), + arraysize(content_blocked_)); + for (int i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) + content_blocked_[i] = false; +} + void RenderView::DnsPrefetch(const std::vector<std::string>& host_names) { Send(new ViewHostMsg_DnsPrefetch(host_names)); } diff --git a/chrome/renderer/render_view.h b/chrome/renderer/render_view.h index 1bb7c97..3e8e213 100644 --- a/chrome/renderer/render_view.h +++ b/chrome/renderer/render_view.h @@ -833,6 +833,15 @@ class RenderView : public RenderWidget, // on other platforms. static std::string DetermineTextLanguage(const std::wstring& text); + // Helper method that returns if the user wants to block content of type + // |content_type| and sends an IPC message to the browser if content will be + // blocked. + bool allowContentType(ContentSettingsType settings_type, + bool enabled_per_settings); + + // Resets the |content_blocked_| array. + void ClearBlockedContentSettings(); + // Bitwise-ORed set of extra bindings that have been enabled. See // BindingsPolicy for details. int enabled_bindings_; @@ -1071,8 +1080,12 @@ class RenderView : public RenderWidget, HostContentSettings host_content_settings_; HostZoomLevels host_zoom_levels_; + // Stores if loading of images, scripts, and plugins is allowed. ContentSettings current_content_settings_; + // Stores if images, scripts, and plugins have actually been blocked. + bool content_blocked_[CONTENT_SETTINGS_NUM_TYPES]; + // The SessionStorage namespace that we're assigned to has an ID, and that ID // is passed to us upon creation. WebKit asks for this ID upon first use and // uses it whenever asking the browser process to allocate new storage areas. |