summaryrefslogtreecommitdiffstats
path: root/chrome/renderer/webplugin_delegate_pepper.cc
diff options
context:
space:
mode:
authorbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-01 23:07:02 +0000
committerbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-01 23:07:02 +0000
commit66b4e8dfc5cce75c998889d5b968ecb72a204447 (patch)
tree215d020b5bb8a5cfa43debf580e9bd3d55091b77 /chrome/renderer/webplugin_delegate_pepper.cc
parent3984b4b1edee2b14b0ebd41d31fc9fedfc7a0ef9 (diff)
downloadchromium_src-66b4e8dfc5cce75c998889d5b968ecb72a204447.zip
chromium_src-66b4e8dfc5cce75c998889d5b968ecb72a204447.tar.gz
chromium_src-66b4e8dfc5cce75c998889d5b968ecb72a204447.tar.bz2
Update the Pepper APIs to the latest spec for the 2D demo plugin.
This also adds the npapi headers to the npapi.gyp file since I got tired of Visual Studio not finding the files. This removes the "open file in sandbox" feature which it doesn't look like we will use. One more significant change is that I changed to including pepper.h in all cases, even when pepper is disabled. We used to have a forward declare in npapi.h for the structs in question, but we'll be adding a lot more structs for the different contexts and I don't think this will scale. I think its OK fo rthe pepper API declarations to be available when Pepper isn't enabled. BUT=none TEST=none Review URL: http://codereview.chromium.org/453015 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@33501 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer/webplugin_delegate_pepper.cc')
-rw-r--r--chrome/renderer/webplugin_delegate_pepper.cc244
1 files changed, 120 insertions, 124 deletions
diff --git a/chrome/renderer/webplugin_delegate_pepper.cc b/chrome/renderer/webplugin_delegate_pepper.cc
index ecb4984..1c24bb4 100644
--- a/chrome/renderer/webplugin_delegate_pepper.cc
+++ b/chrome/renderer/webplugin_delegate_pepper.cc
@@ -18,9 +18,9 @@
#include "base/string_util.h"
#include "chrome/common/render_messages.h"
#include "chrome/renderer/render_thread.h"
+#include "third_party/npapi/bindings/npapi_extensions.h"
#include "third_party/WebKit/WebKit/chromium/public/WebInputEvent.h"
#include "webkit/glue/glue_util.h"
-#include "webkit/glue/pepper/pepper.h"
#include "webkit/glue/plugins/plugin_constants_win.h"
#include "webkit/glue/plugins/plugin_instance.h"
#include "webkit/glue/plugins/plugin_lib.h"
@@ -225,6 +225,125 @@ WebPluginResourceClient* WebPluginDelegatePepper::CreateResourceClient(
return stream;
}
+NPError WebPluginDelegatePepper::Device2DQueryCapability(int32 capability,
+ int32* value) {
+ return NPERR_GENERIC_ERROR;
+}
+
+NPError WebPluginDelegatePepper::Device2DQueryConfig(
+ const NPDeviceContext2DConfig* request,
+ NPDeviceContext2DConfig* obtain) {
+ return NPERR_GENERIC_ERROR;
+}
+
+NPError WebPluginDelegatePepper::Device2DInitializeContext(
+ const NPDeviceContext2DConfig* config,
+ NPDeviceContext2D* context) {
+ int width = window_rect_.width();
+ int height = window_rect_.height();
+ uint32 buffer_size = width * height * kBytesPerPixel;
+
+ // Allocate the transport DIB and the PlatformCanvas pointing to it.
+ scoped_ptr<OpenPaintContext> paint_context(new OpenPaintContext);
+ paint_context->transport_dib.reset(
+ TransportDIB::Create(buffer_size, ++next_buffer_id));
+ if (!paint_context->transport_dib.get())
+ return NPERR_OUT_OF_MEMORY_ERROR;
+ paint_context->canvas.reset(
+ paint_context->transport_dib->GetPlatformCanvas(width, height));
+ if (!paint_context->canvas.get())
+ return NPERR_OUT_OF_MEMORY_ERROR;
+
+ // Note that we need to get the address out of the bitmap rather than
+ // using plugin_buffer_->memory(). The memory() is when the bitmap data
+ // has had "Map" called on it. For Windows, this is separate than making a
+ // bitmap using the shared section.
+ const SkBitmap& plugin_bitmap =
+ paint_context->canvas->getTopPlatformDevice().accessBitmap(true);
+ SkAutoLockPixels locker(plugin_bitmap);
+
+ // TODO(brettw) this theoretically shouldn't be necessary. But the
+ // platform device on Windows will fill itself with green to help you
+ // catch areas you didn't paint.
+ plugin_bitmap.eraseARGB(0, 0, 0, 0);
+
+ // Save the canvas to the output context structure and save the
+ // OpenPaintContext for future reference.
+ context->u.graphicsRgba.region = plugin_bitmap.getAddr32(0, 0);
+ context->u.graphicsRgba.stride = width * kBytesPerPixel;
+ context->u.graphicsRgba.dirty.left = 0;
+ context->u.graphicsRgba.dirty.top = 0;
+ context->u.graphicsRgba.dirty.right = width;
+ context->u.graphicsRgba.dirty.bottom = height;
+ open_paint_contexts_[context->u.graphicsRgba.region] =
+ linked_ptr<OpenPaintContext>(paint_context.release());
+ return NPERR_NO_ERROR;
+}
+
+NPError WebPluginDelegatePepper::Device2DSetStateContext(
+ NPDeviceContext2D* context,
+ int32 state,
+ int32 value) {
+ return NPERR_GENERIC_ERROR;
+}
+
+NPError WebPluginDelegatePepper::Device2DGetStateContext(
+ NPDeviceContext2D* context,
+ int32 state,
+ int32* value) {
+ return NPERR_GENERIC_ERROR;
+}
+
+NPError WebPluginDelegatePepper::Device2DFlushContext(
+ NPDeviceContext2D* context,
+ NPDeviceFlushContextCallbackPtr callback,
+ void* user_data) {
+ // Get the bitmap data associated with the incoming context.
+ OpenPaintContextMap::iterator found = open_paint_contexts_.find(
+ context->u.graphicsRgba.region);
+ if (found == open_paint_contexts_.end())
+ return NPERR_INVALID_PARAM;
+
+ OpenPaintContext* paint_context = found->second.get();
+
+ // Draw the bitmap to the backing store.
+ //
+ // TODO(brettw) we can optimize this in the case where the entire canvas is
+ // updated by actually taking ownership of the buffer and not telling the
+ // plugin we're done using it. This wat we can avoid the copy when the entire
+ // canvas has been updated.
+ SkIRect src_rect = { context->u.graphicsRgba.dirty.left,
+ context->u.graphicsRgba.dirty.top,
+ context->u.graphicsRgba.dirty.right,
+ context->u.graphicsRgba.dirty.bottom };
+ SkRect dest_rect = { SkIntToScalar(context->u.graphicsRgba.dirty.left),
+ SkIntToScalar(context->u.graphicsRgba.dirty.top),
+ SkIntToScalar(context->u.graphicsRgba.dirty.right),
+ SkIntToScalar(context->u.graphicsRgba.dirty.bottom) };
+ SkCanvas committed_canvas(committed_bitmap_);
+
+ // We want to replace the contents of the bitmap rather than blend.
+ SkPaint paint;
+ paint.setXfermodeMode(SkXfermode::kSrc_Mode);
+ committed_canvas.drawBitmapRect(
+ paint_context->canvas->getTopPlatformDevice().accessBitmap(false),
+ &src_rect, dest_rect);
+
+ committed_bitmap_.setIsOpaque(false);
+ return NPERR_NO_ERROR;
+}
+
+NPError WebPluginDelegatePepper::Device2DDestroyContext(
+ NPDeviceContext2D* context) {
+ OpenPaintContextMap::iterator found = open_paint_contexts_.find(
+ context->u.graphicsRgba.region);
+ if (found == open_paint_contexts_.end())
+ return NPERR_INVALID_PARAM;
+
+ open_paint_contexts_.erase(found);
+ return NPERR_NO_ERROR;
+}
+
bool WebPluginDelegatePepper::IsPluginDelegateWindow(
gfx::NativeWindow window) {
return false;
@@ -405,126 +524,3 @@ bool WebPluginDelegatePepper::HandleInputEvent(const WebInputEvent& event,
}
return instance()->NPP_HandleEvent(&npevent) != 0;
}
-
-NPError WebPluginDelegatePepper::InitializeRenderContext(
- NPRenderType type, NPRenderContext* context) {
- switch (type) {
- case NPRenderGraphicsRGBA: {
- int width = window_rect_.width();
- int height = window_rect_.height();
- uint32 buffer_size = width * height * kBytesPerPixel;
-
- // Allocate the transport DIB and the PlatformCanvas pointing to it.
- scoped_ptr<OpenPaintContext> paint_context(new OpenPaintContext);
- paint_context->transport_dib.reset(
- TransportDIB::Create(buffer_size, ++next_buffer_id));
- if (!paint_context->transport_dib.get())
- return NPERR_OUT_OF_MEMORY_ERROR;
- paint_context->canvas.reset(
- paint_context->transport_dib->GetPlatformCanvas(width, height));
- if (!paint_context->canvas.get())
- return NPERR_OUT_OF_MEMORY_ERROR;
-
- // Note that we need to get the address out of the bitmap rather than
- // using plugin_buffer_->memory(). The memory() is when the bitmap data
- // has had "Map" called on it. For Windows, this is separate than making a
- // bitmap using the shared section.
- const SkBitmap& plugin_bitmap =
- paint_context->canvas->getTopPlatformDevice().accessBitmap(true);
- SkAutoLockPixels locker(plugin_bitmap);
-
- // TODO(brettw) this theoretically shouldn't be necessary. But the
- // platform device on Windows will fill itself with green to help you
- // catch areas you didn't paint.
- plugin_bitmap.eraseARGB(0, 0, 0, 0);
-
- // Save the canvas to the output context structure and save the
- // OpenPaintContext for future reference.
- context->u.graphicsRgba.region = plugin_bitmap.getAddr32(0, 0);
- context->u.graphicsRgba.stride = width * kBytesPerPixel;
- context->u.graphicsRgba.dirty.left = 0;
- context->u.graphicsRgba.dirty.top = 0;
- context->u.graphicsRgba.dirty.right = width;
- context->u.graphicsRgba.dirty.bottom = height;
- open_paint_contexts_[context->u.graphicsRgba.region] =
- linked_ptr<OpenPaintContext>(paint_context.release());
- return NPERR_NO_ERROR;
- }
- default:
- return NPERR_GENERIC_ERROR;
- }
-}
-
-NPError WebPluginDelegatePepper::DestroyRenderContext(
- NPRenderContext* context) {
- OpenPaintContextMap::iterator found = open_paint_contexts_.find(
- context->u.graphicsRgba.region);
- if (found == open_paint_contexts_.end())
- return NPERR_INVALID_PARAM;
-
- open_paint_contexts_.erase(found);
- return NPERR_NO_ERROR;
-}
-
-NPError WebPluginDelegatePepper::FlushRenderContext(NPRenderContext* context) {
- // Get the bitmap data associated with the incoming context.
- OpenPaintContextMap::iterator found = open_paint_contexts_.find(
- context->u.graphicsRgba.region);
- if (found == open_paint_contexts_.end())
- return NPERR_INVALID_PARAM;
-
- OpenPaintContext* paint_context = found->second.get();
-
- // Draw the bitmap to the backing store.
- //
- // TODO(brettw) we can optimize this in the case where the entire canvas is
- // updated by actually taking ownership of the buffer and not telling the
- // plugin we're done using it. This wat we can avoid the copy when the entire
- // canvas has been updated.
- SkIRect src_rect = { context->u.graphicsRgba.dirty.left,
- context->u.graphicsRgba.dirty.top,
- context->u.graphicsRgba.dirty.right,
- context->u.graphicsRgba.dirty.bottom };
- SkRect dest_rect = { SkIntToScalar(context->u.graphicsRgba.dirty.left),
- SkIntToScalar(context->u.graphicsRgba.dirty.top),
- SkIntToScalar(context->u.graphicsRgba.dirty.right),
- SkIntToScalar(context->u.graphicsRgba.dirty.bottom) };
- SkCanvas committed_canvas(committed_bitmap_);
-
- // We want to replace the contents of the bitmap rather than blend.
- SkPaint paint;
- paint.setXfermodeMode(SkXfermode::kSrc_Mode);
- committed_canvas.drawBitmapRect(
- paint_context->canvas->getTopPlatformDevice().accessBitmap(false),
- &src_rect, dest_rect);
-
- committed_bitmap_.setIsOpaque(false);
- return NPERR_NO_ERROR;
-}
-
-NPError WebPluginDelegatePepper::OpenFileInSandbox(const char* file_name,
- void** handle) {
- *handle = NULL;
-
-#if defined(OS_WIN)
- FilePath file_path(UTF8ToUTF16(file_name));
-#elif defined(OS_POSIX)
- FilePath file_path(file_name);
-#endif
-
- ViewMsg_OpenFileForPluginResponse_Params result;
- RenderThread::current()->Send(new ViewMsg_OpenFileForPlugin(
- file_path, &result));
-
-#if defined(OS_WIN)
- if (!result.file_handle)
- return NPERR_INVALID_PARAM;
- *handle = result.file_handle;
-#elif defined(OS_POSIX)
- if (result.file_handle.fd == -1)
- return NPERR_INVALID_PARAM;
- *reinterpret_cast<int*>(handle) = result.file_handle.fd;
-#endif
-
- return NPERR_NO_ERROR;
-}