Commit 6ac77cba authored by bauerb@chromium.org's avatar bauerb@chromium.org

Show a replacement plug-in for loading errors.

This allows us to show a nicer placeholder when loading a plug-in fails then the one coming from WebKit.

BUG=123580
TEST=manual

Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=134620
Reverted: http://src.chromium.org/viewvc/chrome?view=rev&revision=134630

Review URL: http://codereview.chromium.org/10093011

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@134704 0039d316-1c4b-4281-b951-d872f2087c98
parent a7fb2513
......@@ -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,
......
......@@ -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(
......
......@@ -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,
......
......@@ -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,
......
......@@ -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
......
......@@ -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;
......
......@@ -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(
......
......@@ -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);
......
......@@ -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(
......
......@@ -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));
......
......@@ -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(
......
......@@ -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;
......
......@@ -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(
......
......@@ -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 || !replacement_plugin->initialize(container))
return false;
container->setPlugin(replacement_plugin);
return true;
}
delegate_ = plugin_delegate;
......
// 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(
......
......@@ -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) {
......
......@@ -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(
......
......@@ -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;
......
......@@ -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 || !replacement_plugin->initialize(container))
return false;
container->setPlugin(replacement_plugin);
return true;
}
init_data_.reset();
......
// 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();
}
......
// 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 {}
......
......@@ -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();
}
......
......@@ -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(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment