diff options
author | cpu@chromium.org <cpu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-02 22:02:53 +0000 |
---|---|---|
committer | cpu@chromium.org <cpu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-02 22:02:53 +0000 |
commit | cc7b110103885020aaaac291c102f2a17e17953e (patch) | |
tree | e55778b605777370774a1ba4ca98983fdac0a401 | |
parent | 065d974a023bfc7bff9e1c3590b797bc0f2738fb (diff) | |
download | chromium_src-cc7b110103885020aaaac291c102f2a17e17953e.zip chromium_src-cc7b110103885020aaaac291c102f2a17e17953e.tar.gz chromium_src-cc7b110103885020aaaac291c102f2a17e17953e.tar.bz2 |
Changes to block NPAPI plugins in ash-metro mode
The problem is that metro mode can't handle windowed plugins, the window
appears on the desktop while the user is looking at the metro chrome.
In the stable channel (non-aura) we have different browser processes in
desktop and metro so blocking is simply checking if we are in metro
mode which we can do with a single OS call in any thread.
For aura we have a single browser process so we need to tell each
renderview if it can or cannot allow NPAPI plugins.
1) At navigation
browser:
AboutToNavigate()->PluginObserver --> message_to_renderer
renderer:
ChromeRenderViewObserver->ContentSettingsObserver->BlockNPAPIPlugins()
2) When a plugin is going to be created:
renderer:
ChromeContentRendererClient-:OverrideCreatePlugin->observer->AreNPAPIPluginsBlocked()
BUG=230127
TEST=see bug
Review URL: https://chromiumcodereview.appspot.com/14333024
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@197981 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/plugins/plugin_observer.cc | 32 | ||||
-rw-r--r-- | chrome/browser/plugins/plugin_observer.h | 2 | ||||
-rw-r--r-- | chrome/common/render_messages.h | 3 | ||||
-rw-r--r-- | chrome/renderer/chrome_content_renderer_client.cc | 13 | ||||
-rw-r--r-- | chrome/renderer/chrome_render_view_observer.cc | 9 | ||||
-rw-r--r-- | chrome/renderer/chrome_render_view_observer.h | 1 | ||||
-rw-r--r-- | chrome/renderer/content_settings_observer.cc | 11 | ||||
-rw-r--r-- | chrome/renderer/content_settings_observer.h | 7 |
8 files changed, 72 insertions, 6 deletions
diff --git a/chrome/browser/plugins/plugin_observer.cc b/chrome/browser/plugins/plugin_observer.cc index 61c2bc4..3aa2460 100644 --- a/chrome/browser/plugins/plugin_observer.cc +++ b/chrome/browser/plugins/plugin_observer.cc @@ -27,6 +27,7 @@ #include "content/public/browser/render_view_host.h" #include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents_delegate.h" +#include "content/public/browser/web_contents_view.h" #include "grit/generated_resources.h" #include "grit/theme_resources.h" #include "ui/base/l10n/l10n_util.h" @@ -118,7 +119,6 @@ void ConfirmInstallDialogDelegate::OnlyWeakObserversLeft() { Cancel(); } #endif // defined(ENABLE_PLUGIN_INSTALLATION) - } // namespace // PluginObserver ------------------------------------------------------------- @@ -257,6 +257,31 @@ bool PluginObserver::OnMessageReceived(const IPC::Message& message) { return true; } +void PluginObserver::AboutToNavigateRenderView( + content::RenderViewHost* render_view_host) { +#if defined(USE_AURA) && defined(OS_WIN) + // If the window belongs to the Ash desktop, before we navigate we need + // to tell the renderview that NPAPI plugins are not supported so it does + // not try to instantiate them. The final decision is actually done in + // the IO thread by PluginInfoMessageFilter of this proces,s but it's more + // complex to manage a map of Ash views in PluginInfoMessageFilter than + // just telling the renderer via IPC. + if (!web_contents()) + return; + + content::WebContentsView* wcv = web_contents()->GetView(); + if (!wcv) + return; + + aura::Window* window = wcv->GetNativeView(); + if (chrome::GetHostDesktopTypeForNativeView(window) == + chrome::HOST_DESKTOP_TYPE_ASH) { + int routing_id = render_view_host->GetRoutingID(); + render_view_host->Send(new ChromeViewMsg_NPAPINotSupported(routing_id)); + } +#endif +} + void PluginObserver::OnBlockedUnauthorizedPlugin( const string16& name, const std::string& identifier) { @@ -366,7 +391,10 @@ void PluginObserver::OnCouldNotLoadPlugin(const base::FilePath& plugin_path) { void PluginObserver::OnNPAPINotSupported(const std::string& identifier) { #if defined(OS_WIN) && defined(ENABLE_PLUGIN_INSTALLATION) +#if !defined(USE_AURA) DCHECK(base::win::IsMetroProcess()); +#endif + Profile* profile = Profile::FromBrowserContext(web_contents()->GetBrowserContext()); if (profile->IsOffTheRecord()) @@ -390,7 +418,5 @@ void PluginObserver::OnNPAPINotSupported(const std::string& identifier) { PluginMetroModeInfoBarDelegate::Create( InfoBarService::FromWebContents(web_contents()), PluginMetroModeInfoBarDelegate::DESKTOP_MODE_REQUIRED, plugin->name()); -#else - NOTREACHED(); #endif } diff --git a/chrome/browser/plugins/plugin_observer.h b/chrome/browser/plugins/plugin_observer.h index 4264d62..08aa950 100644 --- a/chrome/browser/plugins/plugin_observer.h +++ b/chrome/browser/plugins/plugin_observer.h @@ -37,6 +37,8 @@ class PluginObserver : public content::WebContentsObserver, virtual void PluginCrashed(const base::FilePath& plugin_path, base::ProcessId plugin_pid) OVERRIDE; virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; + virtual void AboutToNavigateRenderView( + content::RenderViewHost* render_view_host) OVERRIDE; private: explicit PluginObserver(content::WebContents* web_contents); diff --git a/chrome/common/render_messages.h b/chrome/common/render_messages.h index 4c1876d..a20743b 100644 --- a/chrome/common/render_messages.h +++ b/chrome/common/render_messages.h @@ -550,6 +550,9 @@ IPC_MESSAGE_ROUTED1(ChromeViewHostMsg_CouldNotLoadPlugin, IPC_MESSAGE_ROUTED1(ChromeViewHostMsg_NPAPINotSupported, std::string /* identifer */) +// Tells the renderer that the NPAPI cannot be used. For example Ash on windows. +IPC_MESSAGE_ROUTED0(ChromeViewMsg_NPAPINotSupported) + // A message for an external host. IPC_MESSAGE_ROUTED3(ChromeViewHostMsg_ForwardMessageToExternalHost, std::string /* message */, diff --git a/chrome/renderer/chrome_content_renderer_client.cc b/chrome/renderer/chrome_content_renderer_client.cc index 87d01c4..732ad28a 100644 --- a/chrome/renderer/chrome_content_renderer_client.cc +++ b/chrome/renderer/chrome_content_renderer_client.cc @@ -4,8 +4,6 @@ #include "chrome/renderer/chrome_content_renderer_client.h" -#include <string> - #include "base/command_line.h" #include "base/logging.h" #include "base/metrics/histogram.h" @@ -556,6 +554,17 @@ WebPlugin* ChromeContentRendererClient::CreatePlugin( status_value = ChromeViewHostMsg_GetPluginInfo_Status::kAllowed; } +#if defined(USE_AURA) && defined(OS_WIN) + // In Aura for Windows we need to check if we can load NPAPI plugins. + // For example, if the render view is in the Ash desktop, we should not. + if (status_value == ChromeViewHostMsg_GetPluginInfo_Status::kAllowed && + plugin.type == webkit::WebPluginInfo::PLUGIN_TYPE_NPAPI) { + if (observer->AreNPAPIPluginsBlocked()) + status_value = + ChromeViewHostMsg_GetPluginInfo_Status::kNPAPINotSupported; + } +#endif + switch (status_value) { case ChromeViewHostMsg_GetPluginInfo_Status::kNotFound: { NOTREACHED(); diff --git a/chrome/renderer/chrome_render_view_observer.cc b/chrome/renderer/chrome_render_view_observer.cc index cfe0f83..8903e42 100644 --- a/chrome/renderer/chrome_render_view_observer.cc +++ b/chrome/renderer/chrome_render_view_observer.cc @@ -213,6 +213,7 @@ bool ChromeRenderViewObserver::OnMessageReceived(const IPC::Message& message) { IPC_MESSAGE_HANDLER(ChromeViewMsg_GetFPS, OnGetFPS) IPC_MESSAGE_HANDLER(ChromeViewMsg_AddStrictSecurityHost, OnAddStrictSecurityHost) + IPC_MESSAGE_HANDLER(ChromeViewMsg_NPAPINotSupported, OnNPAPINotSupported) IPC_MESSAGE_UNHANDLED(handled = false) IPC_END_MESSAGE_MAP() @@ -272,6 +273,14 @@ void ChromeRenderViewObserver::OnAddStrictSecurityHost( strict_security_hosts_.insert(host); } +void ChromeRenderViewObserver::OnNPAPINotSupported() { +#if defined(USE_AURA) && defined(OS_WIN) + content_settings_->BlockNPAPIPlugins(); +#else + NOTREACHED(); +#endif +} + 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 d5297c8..eda1d90 100644 --- a/chrome/renderer/chrome_render_view_observer.h +++ b/chrome/renderer/chrome_render_view_observer.h @@ -138,6 +138,7 @@ class ChromeRenderViewObserver : public content::RenderViewObserver, void OnStartFrameSniffer(const string16& frame_name); void OnGetFPS(); void OnAddStrictSecurityHost(const std::string& host); + void OnNPAPINotSupported(); void CapturePageInfoLater(bool preliminary_capture, base::TimeDelta delay); diff --git a/chrome/renderer/content_settings_observer.cc b/chrome/renderer/content_settings_observer.cc index c648736..d2eaa55 100644 --- a/chrome/renderer/content_settings_observer.cc +++ b/chrome/renderer/content_settings_observer.cc @@ -72,7 +72,8 @@ ContentSettingsObserver::ContentSettingsObserver( : content::RenderViewObserver(render_view), content::RenderViewObserverTracker<ContentSettingsObserver>(render_view), content_setting_rules_(NULL), - is_interstitial_page_(false) { + is_interstitial_page_(false), + npapi_plugins_blocked_(false) { ClearBlockedContentSettings(); } @@ -303,6 +304,14 @@ void ContentSettingsObserver::DidNotAllowMixedScript() { DidBlockContentType(CONTENT_SETTINGS_TYPE_MIXEDSCRIPT, std::string()); } +void ContentSettingsObserver::BlockNPAPIPlugins() { + npapi_plugins_blocked_ = true; +} + +bool ContentSettingsObserver::AreNPAPIPluginsBlocked() const { + return npapi_plugins_blocked_; +} + void ContentSettingsObserver::OnLoadBlockedPlugins( const std::string& identifier) { temporarily_allowed_plugins_.insert(identifier); diff --git a/chrome/renderer/content_settings_observer.h b/chrome/renderer/content_settings_observer.h index 52446ef..92cf5b8 100644 --- a/chrome/renderer/content_settings_observer.h +++ b/chrome/renderer/content_settings_observer.h @@ -60,10 +60,16 @@ class ContentSettingsObserver bool AllowScriptFromSource(WebKit::WebFrame* frame, bool enabled_per_settings, const WebKit::WebURL& script_url); bool AllowStorage(WebKit::WebFrame* frame, bool local); + void DidNotAllowPlugins(); void DidNotAllowScript(); void DidNotAllowMixedScript(); + // These two methods are not related to content settings, they are used + // for cases when the NPAPI plugins malfunction if used. + void BlockNPAPIPlugins(); + bool AreNPAPIPluginsBlocked() const; + private: FRIEND_TEST_ALL_PREFIXES(ContentSettingsObserverTest, WhitelistedSchemes); FRIEND_TEST_ALL_PREFIXES(ChromeRenderViewTest, @@ -106,6 +112,7 @@ class ContentSettingsObserver std::set<std::string> temporarily_allowed_plugins_; bool is_interstitial_page_; + bool npapi_plugins_blocked_; DISALLOW_COPY_AND_ASSIGN(ContentSettingsObserver); }; |