summaryrefslogtreecommitdiffstats
path: root/webkit
diff options
context:
space:
mode:
authorbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-19 06:03:56 +0000
committerbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-19 06:03:56 +0000
commit277a111a05b3c230cea9c68977eb5a130386c1ec (patch)
treee611cfe56303c124643d4adc47729d59af55db0d /webkit
parent01cec0a407740bd2b5b92a80b1cbaef8e5ee8f9b (diff)
downloadchromium_src-277a111a05b3c230cea9c68977eb5a130386c1ec.zip
chromium_src-277a111a05b3c230cea9c68977eb5a130386c1ec.tar.gz
chromium_src-277a111a05b3c230cea9c68977eb5a130386c1ec.tar.bz2
Hook up the sad plugin painting and the crashed plugin infobars for
out-of-process PPAPI plugins. This mostly just forwards notifications up and provides a way to get the sad plugin image in the PPAPI rendering code. I moved the NPAPI sad tab painting to a new file so that it could be shared between the NPAPI and PPAPI. This also hooks up the name and version information in the task manager for PPAPI plugins. R=jam@chromium.org Review URL: http://codereview.chromium.org/6685091 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@78816 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r--webkit/glue/webkit_glue.gypi2
-rw-r--r--webkit/plugins/ppapi/mock_plugin_delegate.cc7
-rw-r--r--webkit/plugins/ppapi/mock_plugin_delegate.h2
-rw-r--r--webkit/plugins/ppapi/plugin_delegate.h10
-rw-r--r--webkit/plugins/ppapi/plugin_module.cc2
-rw-r--r--webkit/plugins/ppapi/plugin_module.h8
-rw-r--r--webkit/plugins/ppapi/ppapi_plugin_instance.cc15
-rw-r--r--webkit/plugins/ppapi/ppapi_plugin_instance.h3
-rw-r--r--webkit/plugins/ppapi/ppapi_unittest.cc2
-rw-r--r--webkit/plugins/sad_plugin.cc49
-rw-r--r--webkit/plugins/sad_plugin.h26
11 files changed, 122 insertions, 4 deletions
diff --git a/webkit/glue/webkit_glue.gypi b/webkit/glue/webkit_glue.gypi
index 8c87826..9a4117a 100644
--- a/webkit/glue/webkit_glue.gypi
+++ b/webkit/glue/webkit_glue.gypi
@@ -356,6 +356,8 @@
'../plugins/ppapi/var.h',
'../plugins/ppapi/var_object_class.cc',
'../plugins/ppapi/var_object_class.h',
+ '../plugins/sad_plugin.cc',
+ '../plugins/sad_plugin.h',
'media/audio_decoder.cc',
'media/audio_decoder.h',
'media/buffered_data_source.cc',
diff --git a/webkit/plugins/ppapi/mock_plugin_delegate.cc b/webkit/plugins/ppapi/mock_plugin_delegate.cc
index 930b681..77b66ac 100644
--- a/webkit/plugins/ppapi/mock_plugin_delegate.cc
+++ b/webkit/plugins/ppapi/mock_plugin_delegate.cc
@@ -16,12 +16,19 @@ MockPluginDelegate::MockPluginDelegate() {
MockPluginDelegate::~MockPluginDelegate() {
}
+void MockPluginDelegate::PluginCrashed(PluginInstance* instance) {
+}
+
void MockPluginDelegate::InstanceCreated(PluginInstance* instance) {
}
void MockPluginDelegate::InstanceDeleted(PluginInstance* instance) {
}
+SkBitmap* MockPluginDelegate::GetSadPluginBitmap() {
+ 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 7980918..9a4113f 100644
--- a/webkit/plugins/ppapi/mock_plugin_delegate.h
+++ b/webkit/plugins/ppapi/mock_plugin_delegate.h
@@ -15,8 +15,10 @@ class MockPluginDelegate : public PluginDelegate {
MockPluginDelegate();
~MockPluginDelegate();
+ virtual void PluginCrashed(PluginInstance* instance);
virtual void InstanceCreated(PluginInstance* instance);
virtual void InstanceDeleted(PluginInstance* instance);
+ virtual SkBitmap* GetSadPluginBitmap();
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 1effed1..e2b3759 100644
--- a/webkit/plugins/ppapi/plugin_delegate.h
+++ b/webkit/plugins/ppapi/plugin_delegate.h
@@ -24,6 +24,7 @@
class AudioMessageFilter;
class GURL;
class P2PSocketDispatcher;
+class SkBitmap;
namespace base {
class MessageLoopProxy;
@@ -208,6 +209,11 @@ class PluginDelegate {
PP_VideoUncompressedDataBuffer_Dev& buffer) = 0;
};
+ // Notification that the given plugin has crashed. When a plugin crashes, all
+ // instances associated with that plugin will notify that they've crashed via
+ // this function.
+ virtual void PluginCrashed(PluginInstance* instance) = 0;
+
// Indicates that the given instance has been created.
virtual void InstanceCreated(PluginInstance* instance) = 0;
@@ -216,6 +222,10 @@ class PluginDelegate {
// from this call.
virtual void InstanceDeleted(PluginInstance* instance) = 0;
+ // Returns a pointer (ownership not transferred) to the bitmap to paint the
+ // sad plugin screen with. Returns NULL on failure.
+ virtual SkBitmap* GetSadPluginBitmap() = 0;
+
// The caller will own the pointer returned from this.
virtual PlatformImage2D* CreateImage2D(int width, int height) = 0;
diff --git a/webkit/plugins/ppapi/plugin_module.cc b/webkit/plugins/ppapi/plugin_module.cc
index 02d1276..638f113 100644
--- a/webkit/plugins/ppapi/plugin_module.cc
+++ b/webkit/plugins/ppapi/plugin_module.cc
@@ -381,12 +381,14 @@ PluginModule::EntryPoints::EntryPoints()
// PluginModule ----------------------------------------------------------------
PluginModule::PluginModule(const std::string& name,
+ const FilePath& path,
PluginDelegate::ModuleLifetime* lifetime_delegate)
: lifetime_delegate_(lifetime_delegate),
callback_tracker_(new CallbackTracker),
is_crashed_(false),
library_(NULL),
name_(name),
+ path_(path),
reserve_instance_id_(NULL) {
pp_module_ = ResourceTracker::Get()->AddModule(this);
GetMainThreadMessageLoop(); // Initialize the main thread message loop.
diff --git a/webkit/plugins/ppapi/plugin_module.h b/webkit/plugins/ppapi/plugin_module.h
index 45545c9..6107430 100644
--- a/webkit/plugins/ppapi/plugin_module.h
+++ b/webkit/plugins/ppapi/plugin_module.h
@@ -10,6 +10,7 @@
#include <string>
#include "base/basictypes.h"
+#include "base/file_path.h"
#include "base/native_library.h"
#include "base/process.h"
#include "base/ref_counted.h"
@@ -75,6 +76,7 @@ class PluginModule : public base::RefCounted<PluginModule>,
// all plugin modules. In practice it will be a global singleton that
// tracks which modules are alive.
PluginModule(const std::string& name,
+ const FilePath& path,
PluginDelegate::ModuleLifetime* lifetime_delegate);
~PluginModule();
@@ -103,6 +105,7 @@ class PluginModule : public base::RefCounted<PluginModule>,
PP_Module pp_module() const { return pp_module_; }
const std::string& name() const { return name_; }
+ const FilePath& path() const { return path_; }
PluginInstance* CreateInstance(PluginDelegate* delegate);
@@ -128,6 +131,8 @@ class PluginModule : public base::RefCounted<PluginModule>,
// release relevant resources and update all affected instances.
void PluginCrashed();
+ bool is_crashed() const { return is_crashed_; }
+
// Reserves the given instance is unique within the plugin, checking for
// collisions. See PPB_Proxy_Private for more information.
//
@@ -173,8 +178,9 @@ class PluginModule : public base::RefCounted<PluginModule>,
// presence of the out_of_process_proxy_ value.
EntryPoints entry_points_;
- // The name of the module.
+ // The name and file location of the module.
const std::string name_;
+ const FilePath path_;
// Non-owning pointers to all instances associated with this module. When
// there are no more instances, this object should be deleted.
diff --git a/webkit/plugins/ppapi/ppapi_plugin_instance.cc b/webkit/plugins/ppapi/ppapi_plugin_instance.cc
index 1b4d0be..fd234bf 100644
--- a/webkit/plugins/ppapi/ppapi_plugin_instance.cc
+++ b/webkit/plugins/ppapi/ppapi_plugin_instance.cc
@@ -53,6 +53,7 @@
#include "webkit/plugins/ppapi/ppp_pdf.h"
#include "webkit/plugins/ppapi/string.h"
#include "webkit/plugins/ppapi/var.h"
+#include "webkit/plugins/sad_plugin.h"
#if defined(OS_POSIX)
#include "printing/native_metafile.h"
@@ -335,7 +336,8 @@ PluginInstance::PluginInstance(PluginDelegate* delegate,
plugin_graphics_3d_interface_(NULL),
always_on_top_(false),
fullscreen_container_(NULL),
- fullscreen_(false) {
+ fullscreen_(false),
+ sad_plugin_(NULL) {
pp_instance_ = ResourceTracker::Get()->AddInstance(this);
memset(&current_print_settings_, 0, sizeof(current_print_settings_));
@@ -394,6 +396,15 @@ const PPB_Zoom_Dev* PluginInstance::GetZoomInterface() {
void PluginInstance::Paint(WebCanvas* canvas,
const gfx::Rect& plugin_rect,
const gfx::Rect& paint_rect) {
+ if (module()->is_crashed()) {
+ // Crashed plugin painting.
+ if (!sad_plugin_) // Lazily initialize bitmap.
+ sad_plugin_ = delegate_->GetSadPluginBitmap();
+ if (sad_plugin_)
+ webkit::PaintSadPlugin(canvas, plugin_rect, *sad_plugin_);
+ return;
+ }
+
if (bound_graphics_2d())
bound_graphics_2d()->Paint(canvas, plugin_rect, paint_rect);
}
@@ -451,7 +462,7 @@ void PluginInstance::InstanceCrashed() {
bound_graphics_ = NULL;
InvalidateRect(gfx::Rect());
- // TODO(brettw) show a crashed plugin screen.
+ delegate()->PluginCrashed(this);
}
PP_Var PluginInstance::GetWindowObject() {
diff --git a/webkit/plugins/ppapi/ppapi_plugin_instance.h b/webkit/plugins/ppapi/ppapi_plugin_instance.h
index b847c36..a8bba47 100644
--- a/webkit/plugins/ppapi/ppapi_plugin_instance.h
+++ b/webkit/plugins/ppapi/ppapi_plugin_instance.h
@@ -363,6 +363,9 @@ class PluginInstance : public base::RefCounted<PluginInstance> {
// True if we are in fullscreen mode. Note: it is false during the transition.
bool fullscreen_;
+ // Bitmap for crashed plugin. Lazily initialized, non-owning pointer.
+ SkBitmap* sad_plugin_;
+
typedef std::set<PluginObject*> PluginObjectSet;
PluginObjectSet live_plugin_objects_;
diff --git a/webkit/plugins/ppapi/ppapi_unittest.cc b/webkit/plugins/ppapi/ppapi_unittest.cc
index 56464e6..b5e4b5f 100644
--- a/webkit/plugins/ppapi/ppapi_unittest.cc
+++ b/webkit/plugins/ppapi/ppapi_unittest.cc
@@ -87,7 +87,7 @@ void PpapiUnittest::SetUp() {
delegate_.reset(new MockPluginDelegate);
// Initialize the mock module.
- module_ = new PluginModule("Mock plugin", this);
+ module_ = new PluginModule("Mock plugin", FilePath(), this);
PluginModule::EntryPoints entry_points;
entry_points.get_interface = &MockGetInterface;
entry_points.initialize_module = &MockInitializeModule;
diff --git a/webkit/plugins/sad_plugin.cc b/webkit/plugins/sad_plugin.cc
new file mode 100644
index 0000000..7512b4b
--- /dev/null
+++ b/webkit/plugins/sad_plugin.cc
@@ -0,0 +1,49 @@
+// Copyright (c) 2011 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.
+
+#include "webkit/plugins/sad_plugin.h"
+
+#include "third_party/skia/include/core/SkPaint.h"
+#include "third_party/skia/include/core/SkScalar.h"
+#include "ui/gfx/blit.h"
+#include "ui/gfx/canvas_skia.h"
+#include "ui/gfx/rect.h"
+
+namespace webkit {
+
+void PaintSadPlugin(WebKit::WebCanvas* webcanvas,
+ const gfx::Rect& plugin_rect,
+ const SkBitmap& sad_plugin_bitmap) {
+ // Make a temporary canvas for the background image.
+ const int width = plugin_rect.width();
+ const int height = plugin_rect.height();
+ gfx::CanvasSkia canvas(width, height, false);
+#if defined(OS_MACOSX)
+ // Flip the canvas, since the context expects flipped data.
+ canvas.translate(0, height);
+ canvas.scale(1, -1);
+#endif
+ SkPaint paint;
+
+ paint.setStyle(SkPaint::kFill_Style);
+ paint.setColor(SK_ColorBLACK);
+ canvas.drawRectCoords(0, 0, SkIntToScalar(width), SkIntToScalar(height),
+ paint);
+ canvas.DrawBitmapInt(sad_plugin_bitmap,
+ std::max(0, (width - sad_plugin_bitmap.width()) / 2),
+ std::max(0, (height - sad_plugin_bitmap.height()) / 2));
+
+ // It's slightly less code to make a big SkBitmap of the sad tab image and
+ // then copy that to the screen than to use the native APIs. The small speed
+ // penalty is not important when drawing crashed plugins.
+#if WEBKIT_USING_SKIA
+ gfx::NativeDrawingContext context = webcanvas->beginPlatformPaint();
+ BlitCanvasToContext(context, plugin_rect, &canvas, gfx::Point(0, 0));
+ webcanvas->endPlatformPaint();
+#elif WEBKIT_USING_CG
+ BlitCanvasToContext(webcanvas, plugin_rect, &canvas, gfx::Point(0, 0));
+#endif
+}
+
+} // namespace webkit
diff --git a/webkit/plugins/sad_plugin.h b/webkit/plugins/sad_plugin.h
new file mode 100644
index 0000000..63b0d7f
--- /dev/null
+++ b/webkit/plugins/sad_plugin.h
@@ -0,0 +1,26 @@
+// Copyright (c) 2011 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.
+
+#ifndef WEBKIT_PLUGINS_SAD_PLUGIN_H_
+#define WEBKIT_PLUGINS_SAD_PLUGIN_H_
+
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebCanvas.h"
+
+class SkBitmap;
+
+namespace gfx {
+class Rect;
+}
+
+namespace webkit {
+
+// Paints the sad plugin to the given canvas for the given plugin bounds. This
+// is used by both the NPAPI and the PPAPI out-of-process plugin impls.
+void PaintSadPlugin(WebKit::WebCanvas* canvas,
+ const gfx::Rect& plugin_rect,
+ const SkBitmap& sad_plugin_bitmap);
+
+} // namespace
+
+#endif // WEBKIT_PLUGINS_SAD_PLUGIN_H_