diff options
23 files changed, 151 insertions, 11 deletions
diff --git a/chrome/renderer/chrome_content_renderer_client.cc b/chrome/renderer/chrome_content_renderer_client.cc index 12ae141..46473c3 100644 --- a/chrome/renderer/chrome_content_renderer_client.cc +++ b/chrome/renderer/chrome_content_renderer_client.cc @@ -295,6 +295,14 @@ bool ChromeContentRendererClient::OverrideCreatePlugin( return true; } +WebPlugin* ChromeContentRendererClient::CreatePluginReplacement( + content::RenderView* render_view, + const FilePath& plugin_path) { + PluginPlaceholder* placeholder = + PluginPlaceholder::CreateErrorPlugin(render_view, plugin_path); + return placeholder->plugin(); +} + webkit_media::WebMediaPlayerImpl* ChromeContentRendererClient::OverrideCreateWebMediaPlayer( content::RenderView* render_view, diff --git a/chrome/renderer/chrome_content_renderer_client.h b/chrome/renderer/chrome_content_renderer_client.h index c18d866..c587e70 100644 --- a/chrome/renderer/chrome_content_renderer_client.h +++ b/chrome/renderer/chrome_content_renderer_client.h @@ -58,6 +58,9 @@ class ChromeContentRendererClient : public content::ContentRendererClient { WebKit::WebFrame* frame, const WebKit::WebPluginParams& params, WebKit::WebPlugin** plugin) OVERRIDE; + virtual WebKit::WebPlugin* CreatePluginReplacement( + content::RenderView* render_view, + const FilePath& plugin_path) OVERRIDE; virtual bool HasErrorPage(int http_status_code, std::string* error_domain) OVERRIDE; virtual void GetNavigationErrorStrings( diff --git a/chrome/renderer/plugins/plugin_placeholder.cc b/chrome/renderer/plugins/plugin_placeholder.cc index c0a09a9..595bb98 100644 --- a/chrome/renderer/plugins/plugin_placeholder.cc +++ b/chrome/renderer/plugins/plugin_placeholder.cc @@ -21,6 +21,7 @@ #include "content/public/renderer/render_view.h" #include "grit/generated_resources.h" #include "grit/renderer_resources.h" +#include "grit/webkit_strings.h" #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebData.h" #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPoint.h" #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h" @@ -39,6 +40,7 @@ #include "ui/base/resource/resource_bundle.h" #include "webkit/glue/webpreferences.h" #include "webkit/plugins/npapi/plugin_group.h" +#include "webkit/plugins/npapi/plugin_list.h" #include "webkit/plugins/webview_plugin.h" using content::RenderThread; @@ -97,6 +99,28 @@ PluginPlaceholder* PluginPlaceholder::CreateMissingPlugin( return missing_plugin; } +PluginPlaceholder* PluginPlaceholder::CreateErrorPlugin( + RenderView* render_view, + const FilePath& file_path) { + DictionaryValue values; + values.SetString("message", + l10n_util::GetStringUTF8(IDS_PLUGIN_INITIALIZATION_ERROR)); + + const base::StringPiece template_html( + ResourceBundle::GetSharedInstance().GetRawDataResource( + IDR_BLOCKED_PLUGIN_HTML)); + std::string html_data = + jstemplate_builder::GetI18nTemplateHtml(template_html, &values); + + WebPluginParams params; + // |missing_plugin| will destroy itself when its WebViewPlugin is going away. + PluginPlaceholder* plugin = new PluginPlaceholder( + render_view, NULL, params, html_data, params.mimeType); + plugin->set_allow_loading(true); + + return plugin; +} + // static PluginPlaceholder* PluginPlaceholder::CreateBlockedPlugin( RenderView* render_view, diff --git a/chrome/renderer/plugins/plugin_placeholder.h b/chrome/renderer/plugins/plugin_placeholder.h index eb70d35..6275284 100644 --- a/chrome/renderer/plugins/plugin_placeholder.h +++ b/chrome/renderer/plugins/plugin_placeholder.h @@ -16,10 +16,10 @@ struct ChromeViewHostMsg_GetPluginInfo_Status; namespace webkit { -struct WebPluginInfo; namespace npapi { class PluginGroup; } +struct WebPluginInfo; } // Placeholders can be used if a plug-in is missing or not available @@ -35,6 +35,10 @@ class PluginPlaceholder : public content::RenderViewObserver, WebKit::WebFrame* frame, const WebKit::WebPluginParams& params); + static PluginPlaceholder* CreateErrorPlugin( + content::RenderView* render_view, + const FilePath& plugin_path); + static PluginPlaceholder* CreateBlockedPlugin( content::RenderView* render_view, WebKit::WebFrame* frame, diff --git a/content/public/renderer/content_renderer_client.h b/content/public/renderer/content_renderer_client.h index 10b5902..1f6f108 100644 --- a/content/public/renderer/content_renderer_client.h +++ b/content/public/renderer/content_renderer_client.h @@ -14,6 +14,7 @@ #include "content/public/common/content_client.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebPageVisibilityState.h" +class FilePath; class GURL; class SkBitmap; @@ -31,6 +32,7 @@ namespace webkit { namespace ppapi { class PpapiInterfaceFactoryManager; } +struct WebPluginInfo; } namespace media { @@ -83,6 +85,12 @@ class ContentRendererClient { const WebKit::WebPluginParams& params, WebKit::WebPlugin** plugin) = 0; + // Creates a replacement plug-in that is shown when the plug-in at |file_path| + // couldn't be loaded. This allows the embedder to show a custom placeholder. + virtual WebKit::WebPlugin* CreatePluginReplacement( + RenderView* render_view, + const FilePath& plugin_path) = 0; + // Returns true if the embedder has an error page to show for the given http // status code. If so |error_domain| should be set to according to WebURLError // and the embedder's GetNavigationErrorHtml will be called afterwards to get diff --git a/content/renderer/mock_content_renderer_client.cc b/content/renderer/mock_content_renderer_client.cc index c86d0ac..664aff1 100644 --- a/content/renderer/mock_content_renderer_client.cc +++ b/content/renderer/mock_content_renderer_client.cc @@ -37,6 +37,12 @@ bool MockContentRendererClient::OverrideCreatePlugin( return false; } +WebKit::WebPlugin* MockContentRendererClient::CreatePluginReplacement( + RenderView* render_view, + const FilePath& plugin_path) { + return NULL; +} + bool MockContentRendererClient::HasErrorPage(int http_status_code, std::string* error_domain) { return false; diff --git a/content/renderer/mock_content_renderer_client.h b/content/renderer/mock_content_renderer_client.h index dfde022..82fae79 100644 --- a/content/renderer/mock_content_renderer_client.h +++ b/content/renderer/mock_content_renderer_client.h @@ -27,6 +27,9 @@ class MockContentRendererClient : public ContentRendererClient { WebKit::WebFrame* frame, const WebKit::WebPluginParams& params, WebKit::WebPlugin** plugin) OVERRIDE; + virtual WebKit::WebPlugin* CreatePluginReplacement( + RenderView* render_view, + const FilePath& plugin_path) OVERRIDE; virtual bool HasErrorPage(int http_status_code, std::string* error_domain) OVERRIDE; virtual void GetNavigationErrorStrings( diff --git a/content/renderer/pepper/pepper_plugin_delegate_impl.cc b/content/renderer/pepper/pepper_plugin_delegate_impl.cc index 2f7eb8b..569f94c 100644 --- a/content/renderer/pepper/pepper_plugin_delegate_impl.cc +++ b/content/renderer/pepper/pepper_plugin_delegate_impl.cc @@ -549,6 +549,12 @@ SkBitmap* PepperPluginDelegateImpl::GetSadPluginBitmap() { return GetContentClient()->renderer()->GetSadPluginBitmap(); } +WebKit::WebPlugin* PepperPluginDelegateImpl::CreatePluginReplacement( + const FilePath& file_path) { + return GetContentClient()->renderer()->CreatePluginReplacement( + render_view_, file_path); +} + webkit::ppapi::PluginDelegate::PlatformImage2D* PepperPluginDelegateImpl::CreateImage2D(int width, int height) { return PepperPlatformImage2DImpl::Create(width, height); diff --git a/content/renderer/pepper/pepper_plugin_delegate_impl.h b/content/renderer/pepper/pepper_plugin_delegate_impl.h index c003a07..b3ebb10 100644 --- a/content/renderer/pepper/pepper_plugin_delegate_impl.h +++ b/content/renderer/pepper/pepper_plugin_delegate_impl.h @@ -168,6 +168,8 @@ class PepperPluginDelegateImpl virtual void InstanceDeleted( webkit::ppapi::PluginInstance* instance) OVERRIDE; virtual SkBitmap* GetSadPluginBitmap() OVERRIDE; + virtual WebKit::WebPlugin* CreatePluginReplacement( + const FilePath& file_path) OVERRIDE; virtual uint32_t GetAudioHardwareOutputSampleRate() OVERRIDE; virtual uint32_t GetAudioHardwareOutputBufferSize() OVERRIDE; virtual PlatformAudioOutput* CreateAudioOutput( diff --git a/content/renderer/render_view_impl.cc b/content/renderer/render_view_impl.cc index a3696bd..e207b93 100644 --- a/content/renderer/render_view_impl.cc +++ b/content/renderer/render_view_impl.cc @@ -2135,6 +2135,17 @@ WebPlugin* RenderViewImpl::createPlugin(WebFrame* frame, return CreatePlugin(frame, info, params_to_use); } +WebPlugin* RenderViewImpl::createPluginReplacement( + WebFrame* frame, + const WebPluginParams& params) { + webkit::WebPluginInfo info; + std::string mime_type; + GetPluginInfo(params.url, frame->top()->document().url(), + params.mimeType.utf8(), &info, &mime_type); + return content::GetContentClient()->renderer()->CreatePluginReplacement( + this, info.path); +} + WebSharedWorker* RenderViewImpl::createSharedWorker( WebFrame* frame, const WebURL& url, const WebString& name, unsigned long long document_id) { @@ -3671,6 +3682,12 @@ webkit::npapi::WebPluginDelegate* RenderViewImpl::CreatePluginDelegate( return new WebPluginDelegateProxy(mime_type, AsWeakPtr()); } +WebKit::WebPlugin* RenderViewImpl::CreatePluginReplacement( + const FilePath& file_path) { + return content::GetContentClient()->renderer()->CreatePluginReplacement( + this, file_path); +} + void RenderViewImpl::CreatedPluginWindow(gfx::PluginWindowHandle window) { #if defined(USE_X11) Send(new ViewHostMsg_CreatePluginContainer(routing_id(), window)); diff --git a/content/renderer/render_view_impl.h b/content/renderer/render_view_impl.h index 9be49ba..77264de 100644 --- a/content/renderer/render_view_impl.h +++ b/content/renderer/render_view_impl.h @@ -445,6 +445,9 @@ class RenderViewImpl : public RenderWidget, virtual WebKit::WebPlugin* createPlugin( WebKit::WebFrame* frame, const WebKit::WebPluginParams& params); + virtual WebKit::WebPlugin* createPluginReplacement( + WebKit::WebFrame* frame, + const WebKit::WebPluginParams& params); virtual WebKit::WebSharedWorker* createSharedWorker( WebKit::WebFrame* frame, const WebKit::WebURL& url, const WebKit::WebString& name, unsigned long long documentId); @@ -637,6 +640,8 @@ class RenderViewImpl : public RenderWidget, virtual webkit::npapi::WebPluginDelegate* CreatePluginDelegate( const FilePath& file_path, const std::string& mime_type) OVERRIDE; + virtual WebKit::WebPlugin* CreatePluginReplacement( + const FilePath& file_path) OVERRIDE; virtual void CreatedPluginWindow(gfx::PluginWindowHandle handle) OVERRIDE; virtual void WillDestroyPluginWindow(gfx::PluginWindowHandle handle) OVERRIDE; virtual void DidMovePlugin( diff --git a/content/shell/shell_content_renderer_client.cc b/content/shell/shell_content_renderer_client.cc index 2bcb24e..ed789b1 100644 --- a/content/shell/shell_content_renderer_client.cc +++ b/content/shell/shell_content_renderer_client.cc @@ -43,6 +43,12 @@ bool ShellContentRendererClient::OverrideCreatePlugin( return false; } +WebKit::WebPlugin* ShellContentRendererClient::CreatePluginReplacement( + RenderView* render_view, + const FilePath& plugin_path) { + return NULL; +} + bool ShellContentRendererClient::HasErrorPage(int http_status_code, std::string* error_domain) { return false; diff --git a/content/shell/shell_content_renderer_client.h b/content/shell/shell_content_renderer_client.h index a28f4f0..06828ab 100644 --- a/content/shell/shell_content_renderer_client.h +++ b/content/shell/shell_content_renderer_client.h @@ -28,6 +28,9 @@ class ShellContentRendererClient : public ContentRendererClient { WebKit::WebFrame* frame, const WebKit::WebPluginParams& params, WebKit::WebPlugin** plugin) OVERRIDE; + virtual WebKit::WebPlugin* CreatePluginReplacement( + RenderView* render_view, + const FilePath& plugin_path) OVERRIDE; virtual bool HasErrorPage(int http_status_code, std::string* error_domain) OVERRIDE; virtual void GetNavigationErrorStrings( diff --git a/webkit/plugins/npapi/webplugin_impl.cc b/webkit/plugins/npapi/webplugin_impl.cc index f776559..595f5c9 100644 --- a/webkit/plugins/npapi/webplugin_impl.cc +++ b/webkit/plugins/npapi/webplugin_impl.cc @@ -256,10 +256,8 @@ bool WebPluginImpl::initialize(WebPluginContainer* container) { WebPluginDelegate* plugin_delegate = page_delegate_->CreatePluginDelegate( file_path_, mime_type_); - if (!plugin_delegate) { - LOG(ERROR) << "Couldn't create plug-in delegate"; + if (!plugin_delegate) return false; - } // Set the container before Initialize because the plugin may // synchronously call NPN_GetValue to get its container during its @@ -270,7 +268,14 @@ bool WebPluginImpl::initialize(WebPluginContainer* container) { if (!ok) { LOG(ERROR) << "Couldn't initialize plug-in"; plugin_delegate->PluginDestroyed(); - return false; + + WebKit::WebPlugin* replacement_plugin = + page_delegate_->CreatePluginReplacement(file_path_); + if (!replacement_plugin->initialize(container)) + return false; + + container->setPlugin(replacement_plugin); + return true; } delegate_ = plugin_delegate; diff --git a/webkit/plugins/npapi/webplugin_page_delegate.h b/webkit/plugins/npapi/webplugin_page_delegate.h index 3176ccd..496bd6f 100644 --- a/webkit/plugins/npapi/webplugin_page_delegate.h +++ b/webkit/plugins/npapi/webplugin_page_delegate.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. @@ -13,6 +13,7 @@ class FilePath; namespace WebKit { class WebCookieJar; +class WebPlugin; } namespace webkit { @@ -31,6 +32,10 @@ class WebPluginPageDelegate { const FilePath& file_path, const std::string& mime_type) = 0; + // Caled to create a replacement plug-in when loading a plug-in failed. + virtual WebKit::WebPlugin* CreatePluginReplacement( + const FilePath& file_path) = 0; + // Called when a windowed plugin is created. // Lets the view delegate create anything it is using to wrap the plugin. virtual void CreatedPluginWindow( diff --git a/webkit/plugins/ppapi/mock_plugin_delegate.cc b/webkit/plugins/ppapi/mock_plugin_delegate.cc index 12fe0e7..7944ac2 100644 --- a/webkit/plugins/ppapi/mock_plugin_delegate.cc +++ b/webkit/plugins/ppapi/mock_plugin_delegate.cc @@ -50,6 +50,11 @@ SkBitmap* MockPluginDelegate::GetSadPluginBitmap() { return NULL; } +WebKit::WebPlugin* MockPluginDelegate::CreatePluginReplacement( + const FilePath& file_path) { + return NULL; +} + MockPluginDelegate::PlatformImage2D* MockPluginDelegate::CreateImage2D( int width, int height) { diff --git a/webkit/plugins/ppapi/mock_plugin_delegate.h b/webkit/plugins/ppapi/mock_plugin_delegate.h index e62ecc0..93d14a9 100644 --- a/webkit/plugins/ppapi/mock_plugin_delegate.h +++ b/webkit/plugins/ppapi/mock_plugin_delegate.h @@ -28,6 +28,7 @@ class MockPluginDelegate : public PluginDelegate { virtual void InstanceCreated(PluginInstance* instance); virtual void InstanceDeleted(PluginInstance* instance); virtual SkBitmap* GetSadPluginBitmap(); + virtual WebKit::WebPlugin* CreatePluginReplacement(const FilePath& file_path); virtual PlatformImage2D* CreateImage2D(int width, int height); virtual PlatformContext3D* CreateContext3D(); virtual PlatformVideoDecoder* CreateVideoDecoder( diff --git a/webkit/plugins/ppapi/plugin_delegate.h b/webkit/plugins/ppapi/plugin_delegate.h index 1514a96..96a9681 100644 --- a/webkit/plugins/ppapi/plugin_delegate.h +++ b/webkit/plugins/ppapi/plugin_delegate.h @@ -32,10 +32,10 @@ #include "webkit/quota/quota_types.h" class GURL; -struct PP_HostResolver_Private_Hint; -struct PP_NetAddress_Private; class SkBitmap; class TransportDIB; +struct PP_HostResolver_Private_Hint; +struct PP_NetAddress_Private; namespace base { class MessageLoopProxy; @@ -69,6 +69,7 @@ class PlatformCanvas; namespace WebKit { class WebFileChooserCompletion; class WebGamepads; +class WebPlugin; struct WebCursorInfo; struct WebFileChooserParams; } @@ -333,6 +334,11 @@ class PluginDelegate { // sad plugin screen with. Returns NULL on failure. virtual SkBitmap* GetSadPluginBitmap() = 0; + // Creates a replacement plug-in that is shown when the plug-in at |file_path| + // couldn't be loaded. + virtual WebKit::WebPlugin* CreatePluginReplacement( + const FilePath& file_path) = 0; + // The caller will own the pointer returned from this. virtual PlatformImage2D* CreateImage2D(int width, int height) = 0; diff --git a/webkit/plugins/ppapi/ppapi_webplugin_impl.cc b/webkit/plugins/ppapi/ppapi_webplugin_impl.cc index fb01662..1c2fe51 100644 --- a/webkit/plugins/ppapi/ppapi_webplugin_impl.cc +++ b/webkit/plugins/ppapi/ppapi_webplugin_impl.cc @@ -27,6 +27,7 @@ using ppapi::NPObjectVar; using WebKit::WebCanvas; +using WebKit::WebPlugin; using WebKit::WebPluginContainer; using WebKit::WebPluginParams; using WebKit::WebPoint; @@ -84,7 +85,15 @@ bool WebPluginImpl::initialize(WebPluginContainer* container) { if (!success) { instance_->Delete(); instance_ = NULL; - return false; + + WebKit::WebPlugin* replacement_plugin = + init_data_->delegate->CreatePluginReplacement( + init_data_->module->path()); + if (!replacement_plugin->initialize(container)) + return false; + + container->setPlugin(replacement_plugin); + return true; } init_data_.reset(); diff --git a/webkit/support/test_webplugin_page_delegate.cc b/webkit/support/test_webplugin_page_delegate.cc index 0c54097..9ec4346 100644 --- a/webkit/support/test_webplugin_page_delegate.cc +++ b/webkit/support/test_webplugin_page_delegate.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 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. @@ -19,6 +19,11 @@ TestWebPluginPageDelegate::CreatePluginDelegate( file_path, mime_type, 0); } +WebKit::WebPlugin* TestWebPluginPageDelegate::CreatePluginReplacement( + const FilePath& file_path) { + return NULL; +} + WebKit::WebCookieJar* TestWebPluginPageDelegate::GetCookieJar() { return WebKit::webKitPlatformSupport()->cookieJar(); } diff --git a/webkit/support/test_webplugin_page_delegate.h b/webkit/support/test_webplugin_page_delegate.h index 27d8ba3..3949af7 100644 --- a/webkit/support/test_webplugin_page_delegate.h +++ b/webkit/support/test_webplugin_page_delegate.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. @@ -20,6 +20,8 @@ class TestWebPluginPageDelegate : public webkit::npapi::WebPluginPageDelegate { virtual webkit::npapi::WebPluginDelegate* CreatePluginDelegate( const FilePath& file_path, const std::string& mime_type) OVERRIDE; + virtual WebKit::WebPlugin* CreatePluginReplacement( + const FilePath& file_path) OVERRIDE; virtual void CreatedPluginWindow(gfx::PluginWindowHandle handle) OVERRIDE {} virtual void WillDestroyPluginWindow( gfx::PluginWindowHandle handle) OVERRIDE {} diff --git a/webkit/tools/test_shell/test_webview_delegate.cc b/webkit/tools/test_shell/test_webview_delegate.cc index 9c5d4f9..70fae86 100644 --- a/webkit/tools/test_shell/test_webview_delegate.cc +++ b/webkit/tools/test_shell/test_webview_delegate.cc @@ -944,6 +944,11 @@ void TestWebViewDelegate::openFileSystem( // WebPluginPageDelegate ----------------------------------------------------- +WebKit::WebPlugin* TestWebViewDelegate::CreatePluginReplacement( + const FilePath& file_path) { + return NULL; +} + WebCookieJar* TestWebViewDelegate::GetCookieJar() { return WebKit::webKitPlatformSupport()->cookieJar(); } diff --git a/webkit/tools/test_shell/test_webview_delegate.h b/webkit/tools/test_shell/test_webview_delegate.h index 8a87db3..435830a 100644 --- a/webkit/tools/test_shell/test_webview_delegate.h +++ b/webkit/tools/test_shell/test_webview_delegate.h @@ -241,6 +241,8 @@ class TestWebViewDelegate : public WebKit::WebViewClient, virtual webkit::npapi::WebPluginDelegate* CreatePluginDelegate( const FilePath& url, const std::string& mime_type) OVERRIDE; + virtual WebKit::WebPlugin* CreatePluginReplacement( + const FilePath& file_path) OVERRIDE; virtual void CreatedPluginWindow( gfx::PluginWindowHandle handle) OVERRIDE; virtual void WillDestroyPluginWindow( |