From 3b48dbc794dd45719eb6047968eb1946d39fe59e Mon Sep 17 00:00:00 2001 From: "bauerb@chromium.org" Date: Fri, 6 Jan 2012 16:34:17 +0000 Subject: Automatically load newly installed plug-ins if they are missing on a page. To enable this on Mac OS, we also enable plug-in directory watching there. There shouldn't be any false positives causing unnecessary disk hits anymore. BUG=62079 TEST=go to http://www.corp.google.com/~bauerb/no_crawl/test/install_plugin.html, install the missing plug-in. It should automatically load. Review URL: http://codereview.chromium.org/9015025 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@116671 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/renderer/plugins/blocked_plugin.cc | 6 ++++-- chrome/renderer/plugins/missing_plugin.cc | 28 ++++++++++++++++++++++++--- chrome/renderer/plugins/missing_plugin.h | 23 ++++++++++++---------- chrome/renderer/plugins/plugin_placeholder.cc | 6 ++---- chrome/renderer/plugins/plugin_placeholder.h | 9 +++++---- 5 files changed, 49 insertions(+), 23 deletions(-) (limited to 'chrome/renderer/plugins') diff --git a/chrome/renderer/plugins/blocked_plugin.cc b/chrome/renderer/plugins/blocked_plugin.cc index 2438de6..3ae7cf2 100644 --- a/chrome/renderer/plugins/blocked_plugin.cc +++ b/chrome/renderer/plugins/blocked_plugin.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -202,7 +202,9 @@ void BlockedPlugin::LoadPlugin() { return; if (!allow_loading_) return; - LoadPluginInternal(plugin_info_); + WebPlugin* plugin = + render_view()->CreatePlugin(frame(), plugin_info_, plugin_params()); + LoadPluginInternal(plugin); } void BlockedPlugin::LoadCallback(const CppArgumentList& args, diff --git a/chrome/renderer/plugins/missing_plugin.cc b/chrome/renderer/plugins/missing_plugin.cc index 842817d..2484944 100644 --- a/chrome/renderer/plugins/missing_plugin.cc +++ b/chrome/renderer/plugins/missing_plugin.cc @@ -13,11 +13,13 @@ #include "chrome/common/jstemplate_builder.h" #include "chrome/common/render_messages.h" #include "chrome/renderer/custom_menu_commands.h" +#include "chrome/renderer/chrome_content_renderer_client.h" #include "content/public/renderer/render_thread.h" #include "content/public/renderer/render_view.h" #include "grit/generated_resources.h" #include "grit/renderer_resources.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebContextMenuData.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebMenuItemInfo.h" @@ -72,15 +74,16 @@ MissingPlugin::MissingPlugin(RenderView* render_view, const WebPluginParams& params, const std::string& html_data) : PluginPlaceholder(render_view, frame, params, html_data), - mime_type_(params.mimeType), placeholder_routing_id_(RenderThread::Get()->GenerateRoutingID()) { + RenderThread::Get()->AddObserver(this); RenderThread::Get()->AddRoute(placeholder_routing_id_, this); RenderThread::Get()->Send(new ChromeViewHostMsg_FindMissingPlugin( - routing_id(), placeholder_routing_id_, mime_type_.utf8())); + routing_id(), placeholder_routing_id_, params.mimeType.utf8())); } MissingPlugin::~MissingPlugin() { RenderThread::Get()->RemoveRoute(placeholder_routing_id_); + RenderThread::Get()->RemoveObserver(this); } void MissingPlugin::BindWebFrame(WebFrame* frame) { @@ -102,7 +105,7 @@ void MissingPlugin::ShowContextMenu(const WebKit::WebMouseEvent& event) { size_t i = 0; WebMenuItemInfo mime_type_item; - mime_type_item.label = mime_type_; + mime_type_item.label = plugin_params().mimeType; mime_type_item.hasTextDirectionOverride = false; mime_type_item.textDirection = WebKit::WebTextDirectionDefault; custom_items[i++] = mime_type_item; @@ -159,6 +162,25 @@ void MissingPlugin::OnFinishedDownloadingPlugin() { SetMessage(l10n_util::GetStringUTF16(IDS_PLUGIN_INSTALLING)); } +void MissingPlugin::PluginListChanged() { + ChromeViewHostMsg_GetPluginInfo_Status status; + webkit::WebPluginInfo plugin_info; + std::string mime_type(plugin_params().mimeType.utf8()); + std::string actual_mime_type; + render_view()->Send(new ChromeViewHostMsg_GetPluginInfo( + routing_id(), GURL(plugin_params().url), frame()->top()->document().url(), + mime_type, &status, &plugin_info, &actual_mime_type)); + if (status.value == ChromeViewHostMsg_GetPluginInfo_Status::kNotFound) + return; + chrome::ChromeContentRendererClient* client = + static_cast( + content::GetContentClient()->renderer()); + WebPlugin* new_plugin = + client->CreatePlugin(render_view(), frame(), plugin_params(), + status, plugin_info, actual_mime_type); + LoadPluginInternal(new_plugin); +} + void MissingPlugin::SetMessage(const string16& message) { message_ = message; if (!plugin()->web_view()->mainFrame()->isLoading()) diff --git a/chrome/renderer/plugins/missing_plugin.h b/chrome/renderer/plugins/missing_plugin.h index bcce19f..93ee8be 100644 --- a/chrome/renderer/plugins/missing_plugin.h +++ b/chrome/renderer/plugins/missing_plugin.h @@ -8,13 +8,15 @@ #include "base/string16.h" #include "chrome/renderer/plugins/plugin_placeholder.h" +#include "content/public/renderer/render_process_observer.h" #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" namespace content { class RenderThread; } -class MissingPlugin : public PluginPlaceholder { +class MissingPlugin : public PluginPlaceholder, + public content::RenderProcessObserver { public: // Creates a new WebViewPlugin with a MissingPlugin as a delegate. static webkit::WebViewPlugin* Create( @@ -22,13 +24,6 @@ class MissingPlugin : public PluginPlaceholder { WebKit::WebFrame* frame, const WebKit::WebPluginParams& params); - private: - MissingPlugin(content::RenderView* render_view, - WebKit::WebFrame* frame, - const WebKit::WebPluginParams& params, - const std::string& html_data); - virtual ~MissingPlugin(); - // WebViewPlugin::Delegate methods: virtual void BindWebFrame(WebKit::WebFrame* frame) OVERRIDE; virtual void ShowContextMenu(const WebKit::WebMouseEvent&) OVERRIDE; @@ -40,6 +35,16 @@ class MissingPlugin : public PluginPlaceholder { // content::RenderViewObserver methods: virtual void ContextMenuAction(unsigned id) OVERRIDE; + // content::RenderProcessObserver methods: + virtual void PluginListChanged() OVERRIDE; + + private: + MissingPlugin(content::RenderView* render_view, + WebKit::WebFrame* frame, + const WebKit::WebPluginParams& params, + const std::string& html_data); + virtual ~MissingPlugin(); + void HideCallback(const CppArgumentList& args, CppVariant* result); void OnFoundMissingPlugin(const string16& plugin_name); @@ -50,8 +55,6 @@ class MissingPlugin : public PluginPlaceholder { void SetMessage(const string16& message); void UpdateMessage(); - WebKit::WebString mime_type_; - // |routing_id()| is the routing ID of our associated RenderView, but we have // a separate routing ID for messages specific to this placeholder. int32 placeholder_routing_id_; diff --git a/chrome/renderer/plugins/plugin_placeholder.cc b/chrome/renderer/plugins/plugin_placeholder.cc index a483485..bb7cc03 100644 --- a/chrome/renderer/plugins/plugin_placeholder.cc +++ b/chrome/renderer/plugins/plugin_placeholder.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -50,11 +50,9 @@ void PluginPlaceholder::BindWebFrame(WebFrame* frame) { BindToJavascript(frame, "plugin"); } -void PluginPlaceholder::LoadPluginInternal(const WebPluginInfo& plugin_info) { +void PluginPlaceholder::LoadPluginInternal(WebPlugin* new_plugin) { CHECK(plugin_); WebPluginContainer* container = plugin_->container(); - WebPlugin* new_plugin = - render_view()->CreatePlugin(frame_, plugin_info, plugin_params_); if (new_plugin && new_plugin->initialize(container)) { plugin_->RestoreTitleText(); container->setPlugin(new_plugin); diff --git a/chrome/renderer/plugins/plugin_placeholder.h b/chrome/renderer/plugins/plugin_placeholder.h index fde0c47..1cf2fbe 100644 --- a/chrome/renderer/plugins/plugin_placeholder.h +++ b/chrome/renderer/plugins/plugin_placeholder.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -32,10 +32,11 @@ class PluginPlaceholder : public content::RenderViewObserver, webkit::WebViewPlugin* plugin() { return plugin_; } WebKit::WebFrame* frame() { return frame_; } + const WebKit::WebPluginParams& plugin_params() { return plugin_params_; } - // Can be called by a subclass to replace this placeholder with an actual - // plugin from |plugin_info|. - void LoadPluginInternal(const webkit::WebPluginInfo& plugin_info); + // Can be called by a subclass to replace this placeholder with a different + // plugin (which could be a placeholder again). + void LoadPluginInternal(WebKit::WebPlugin* new_plugin); // WebViewPlugin::Delegate methods: // Can be called by a subclass to hide this placeholder. -- cgit v1.1