diff options
author | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-01 23:07:02 +0000 |
---|---|---|
committer | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-01 23:07:02 +0000 |
commit | 66b4e8dfc5cce75c998889d5b968ecb72a204447 (patch) | |
tree | 215d020b5bb8a5cfa43debf580e9bd3d55091b77 | |
parent | 3984b4b1edee2b14b0ebd41d31fc9fedfc7a0ef9 (diff) | |
download | chromium_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
-rw-r--r-- | chrome/browser/renderer_host/resource_message_filter.cc | 19 | ||||
-rw-r--r-- | chrome/browser/renderer_host/resource_message_filter.h | 3 | ||||
-rw-r--r-- | chrome/common/render_messages.h | 20 | ||||
-rw-r--r-- | chrome/common/render_messages_internal.h | 7 | ||||
-rw-r--r-- | chrome/renderer/webplugin_delegate_pepper.cc | 244 | ||||
-rw-r--r-- | chrome/renderer/webplugin_delegate_pepper.h | 27 | ||||
-rw-r--r-- | third_party/npapi/bindings/npapi.h | 7 | ||||
-rw-r--r-- | third_party/npapi/bindings/npapi_extensions.h | 231 | ||||
-rw-r--r-- | third_party/npapi/npapi.gyp | 14 | ||||
-rw-r--r-- | webkit/glue/pepper/pepper.h | 179 | ||||
-rw-r--r-- | webkit/glue/plugins/nphostapi.h | 2 | ||||
-rw-r--r-- | webkit/glue/plugins/plugin_host.cc | 127 | ||||
-rw-r--r-- | webkit/glue/webplugin_delegate.h | 36 | ||||
-rw-r--r-- | webkit/tools/pepper_test_plugin/plugin_object.cc | 45 | ||||
-rw-r--r-- | webkit/tools/pepper_test_plugin/plugin_object.h | 2 |
15 files changed, 522 insertions, 441 deletions
diff --git a/chrome/browser/renderer_host/resource_message_filter.cc b/chrome/browser/renderer_host/resource_message_filter.cc index 8006960..4f6c141 100644 --- a/chrome/browser/renderer_host/resource_message_filter.cc +++ b/chrome/browser/renderer_host/resource_message_filter.cc @@ -390,7 +390,6 @@ bool ResourceMessageFilter::OnMessageReceived(const IPC::Message& msg) { IPC_MESSAGE_HANDLER(ViewHostMsg_SetCacheMode, OnSetCacheMode) IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_GetFileSize, OnGetFileSize) IPC_MESSAGE_HANDLER(ViewHostMsg_Keygen, OnKeygen) - IPC_MESSAGE_HANDLER(ViewMsg_OpenFileForPlugin, OnOpenFileForPlugin) #if defined(USE_TCMALLOC) IPC_MESSAGE_HANDLER(ViewHostMsg_RendererTcmalloc, OnRendererTcmalloc) #endif @@ -1149,24 +1148,6 @@ void ResourceMessageFilter::OnKeygen(uint32 key_size_index, *signed_public_key = keygen_handler->GenKeyAndSignChallenge(); } -void ResourceMessageFilter::OnOpenFileForPlugin( - const FilePath& file_name, - ViewMsg_OpenFileForPluginResponse_Params* result) { - // TODO(brettw) finish up this API. This will allow sandboxed plugins to open - // certain restricted files by opening the file from the browser and - // duplicating the file into the renderer. - // - // This needs to be done with care because of the security implications. Don't - // implement this without getting a thorough security review. -#if defined(OS_WIN) - result->file_handle = NULL; -#elif defined(OS_POSIX) - // TODO(brettw) this currently violates the API provided since it specifies - // NULL means error, and this will give -1. We need to be consistent. - result->file_handle = base::FileDescriptor(); -#endif -} - #if defined(USE_TCMALLOC) void ResourceMessageFilter::OnRendererTcmalloc(base::ProcessId pid, const std::string& output) { diff --git a/chrome/browser/renderer_host/resource_message_filter.h b/chrome/browser/renderer_host/resource_message_filter.h index 53c78dd..7d0eb01 100644 --- a/chrome/browser/renderer_host/resource_message_filter.h +++ b/chrome/browser/renderer_host/resource_message_filter.h @@ -59,7 +59,6 @@ struct WebScreenInfo; } struct ViewHostMsg_ScriptedPrint_Params; -struct ViewMsg_OpenFileForPluginResponse_Params; #if defined(OS_LINUX) struct ViewHostMsg_DidPrintPage_Params; #endif @@ -297,8 +296,6 @@ class ResourceMessageFilter : public IPC::ChannelProxy::MessageFilter, void OnGetFileSizeOnFileThread(const FilePath& path, IPC::Message* reply_msg); void OnKeygen(uint32 key_size_index, const std::string& challenge_string, const GURL& url, std::string* signed_public_key); - void OnOpenFileForPlugin(const FilePath& file_path, - ViewMsg_OpenFileForPluginResponse_Params* result); #if defined(OS_LINUX) void SendDelayedReply(IPC::Message* reply_msg); void DoOnGetScreenInfo(gfx::NativeViewId view, IPC::Message* reply_msg); diff --git a/chrome/common/render_messages.h b/chrome/common/render_messages.h index f960d65..100f224 100644 --- a/chrome/common/render_messages.h +++ b/chrome/common/render_messages.h @@ -413,12 +413,6 @@ struct ViewMsg_DatabaseOpenFileResponse_Params { #endif }; -struct ViewMsg_OpenFileForPluginResponse_Params { - // Note: if we end up having to add a directory handle, this should be - // combined with the DatabaseOpenFileResponse_Params struct. - IPC::PlatformFileForTransit file_handle; -}; - // Parameters to describe a rendered page. struct ViewHostMsg_DidPrintPage_Params { // A shared memory handle to the EMF data. This data can be quite large so a @@ -1869,20 +1863,6 @@ struct ParamTraits<ViewMsg_DatabaseOpenFileResponse_Params> { }; template <> -struct ParamTraits<ViewMsg_OpenFileForPluginResponse_Params> { - typedef ViewMsg_OpenFileForPluginResponse_Params param_type; - static void Write(Message* m, const param_type& p) { - WriteParam(m, p.file_handle); - } - static bool Read(const Message* m, void** iter, param_type* p) { - return ReadParam(m, iter, &p->file_handle); - } - static void Log(const param_type& p, std::wstring* l) { - LogParam(p.file_handle, l); - } -}; - -template <> struct ParamTraits<appcache::Status> { typedef appcache::Status param_type; static void Write(Message* m, const param_type& p) { diff --git a/chrome/common/render_messages_internal.h b/chrome/common/render_messages_internal.h index 618b46d..ff93124 100644 --- a/chrome/common/render_messages_internal.h +++ b/chrome/common/render_messages_internal.h @@ -783,13 +783,6 @@ IPC_BEGIN_MESSAGES(View) bool /* on or off */) #endif - // Opens the given file for the sandboxed plugin, returning a handle - // duplicated into the destination process. On error, or if the file is not - // permitted by the security policy, the response will contain a 0 handle. - IPC_SYNC_MESSAGE_CONTROL1_1(ViewMsg_OpenFileForPlugin, - FilePath, /* file_name */ - ViewMsg_OpenFileForPluginResponse_Params) - //--------------------------------------------------------------------------- // Utility process messages: // These are messages from the browser to the utility process. They're here 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; -} diff --git a/chrome/renderer/webplugin_delegate_pepper.h b/chrome/renderer/webplugin_delegate_pepper.h index 7e2f09b..5a7ebf5 100644 --- a/chrome/renderer/webplugin_delegate_pepper.h +++ b/chrome/renderer/webplugin_delegate_pepper.h @@ -21,7 +21,7 @@ #include "chrome/common/transport_dib.h" #include "skia/ext/platform_canvas.h" #include "third_party/npapi/bindings/npapi.h" -#include "webkit/glue/pepper/pepper.h" +#include "third_party/npapi/bindings/npapi_extensions.h" #include "webkit/glue/webcursor.h" #include "webkit/glue/webplugin_delegate.h" @@ -80,6 +80,22 @@ class WebPluginDelegatePepper : public webkit_glue::WebPluginDelegate { bool notify_needed, intptr_t notify_data, intptr_t stream); + virtual NPError Device2DQueryCapability(int32 capability, int32* value); + virtual NPError Device2DQueryConfig(const NPDeviceContext2DConfig* request, + NPDeviceContext2DConfig* obtain); + virtual NPError Device2DInitializeContext( + const NPDeviceContext2DConfig* config, + NPDeviceContext2D* context); + virtual NPError Device2DSetStateContext(NPDeviceContext2D* context, + int32 state, + int32 value); + virtual NPError Device2DGetStateContext(NPDeviceContext2D* context, + int32 state, + int32* value); + virtual NPError Device2DFlushContext(NPDeviceContext2D* context, + NPDeviceFlushContextCallbackPtr callback, + void* user_data); + virtual NPError Device2DDestroyContext(NPDeviceContext2D* context); // End of WebPluginDelegate implementation. bool IsWindowless() const { return true; } @@ -94,15 +110,6 @@ class WebPluginDelegatePepper : public webkit_glue::WebPluginDelegate { NPAPI::PluginInstance *instance); ~WebPluginDelegatePepper(); - //---------------------------- - // used for windowless plugins - virtual NPError InitializeRenderContext(NPRenderType type, - NPRenderContext* context); - virtual NPError DestroyRenderContext(NPRenderContext* context); - virtual NPError FlushRenderContext(NPRenderContext* context); - - virtual NPError OpenFileInSandbox(const char* file_name, void** handle); - // Tells the plugin about the current state of the window. // See NPAPI NPP_SetWindow for more information. void WindowlessSetWindow(bool force_set_window); diff --git a/third_party/npapi/bindings/npapi.h b/third_party/npapi/bindings/npapi.h index 6bb7153..4f08e45 100644 --- a/third_party/npapi/bindings/npapi.h +++ b/third_party/npapi/bindings/npapi.h @@ -741,13 +741,6 @@ enum NPEventType { #endif /* XP_MACOSX */ -#if !defined(PEPPER_APIS_ENABLED) -/* Stub typedefs for interfaces requiring Pepper types. */ -typedef int NPRenderType; -typedef struct _NPRenderContext NPRenderContext; -typedef struct _NPPepperExtensions NPPepperExtensions; -#endif /* defined(PEPPER_APIS_ENABLED) */ - /* * Values for mode passed to NPP_New: */ diff --git a/third_party/npapi/bindings/npapi_extensions.h b/third_party/npapi/bindings/npapi_extensions.h new file mode 100644 index 0000000..7ca636d --- /dev/null +++ b/third_party/npapi/bindings/npapi_extensions.h @@ -0,0 +1,231 @@ +/* Copyright (c) 2006-2009 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 _NP_EXTENSIONS_H_ +#define _NP_EXTENSIONS_H_ + +#include "third_party/npapi/bindings/npapi.h" + +/* + * A fake "enum" value for getting Pepper extensions. + * The variable returns a pointer to an NPPepperExtensions structure + */ +#define NPNVPepperExtensions ((NPNVariable) 4000) + +typedef void NPDeviceConfig; +typedef void NPDeviceContext; +typedef void NPUserData; + +/* unique id for each device interface */ +typedef int32 NPDeviceID; + +/* completion callback for flush device */ +typedef void (*NPDeviceFlushContextCallbackPtr)( + NPP instace, + NPDeviceContext* context, + NPError err, + NPUserData* userData); + +/* query single capabilities of device */ +typedef NPError ( + *NPDeviceQueryCapabilityPtr)(NPP instance, + int32 capability, + int32 *value); +/* query config (configuration == a set of capabilities) */ +typedef NPError ( + *NPDeviceQueryConfigPtr)(NPP instance, + const NPDeviceConfig* request, + NPDeviceConfig* obtain); +/* device initialization */ +typedef NPError (*NPDeviceInitializeContextPtr)( + NPP instance, + const NPDeviceConfig* config, + NPDeviceContext* context); +/* peek at device state */ +typedef NPError (*NPDeviceGetStateContextPtr) ( + NPP instance, + NPDeviceContext* context, + int32 state, + int32 *value); +/* poke device state */ +typedef NPError (*NPDeviceSetStateContextPtr) ( + NPP instance, + NPDeviceContext* context, + int32 state, + int32 value); +/* flush context, if callback, userData are NULL */ +/* this becomes a blocking call */ +typedef NPError (*NPDeviceFlushContextPtr)( + NPP instance, + NPDeviceContext* context, + NPDeviceFlushContextCallbackPtr callback, + void* userData); +/* destroy device context. Application responsible for */ +/* freeing context, if applicable */ +typedef NPError (*NPDeviceDestroyContextPtr)( + NPP instance, + NPDeviceContext* context); + +/* forward decl typdef structs */ +typedef struct NPDevice NPDevice; +typedef struct NPExtensions NPExtensions; + +/* generic device interface */ +struct NPDevice { + NPDeviceQueryCapabilityPtr queryCapability; + NPDeviceQueryConfigPtr queryConfig; + NPDeviceInitializeContextPtr initializeContext; + NPDeviceSetStateContextPtr setStateContext; + NPDeviceGetStateContextPtr getStateContext; + NPDeviceFlushContextPtr flushContext; + NPDeviceDestroyContextPtr destroyContext; +}; + +/* returns NULL if deviceID unavailable / unrecognized */ +typedef NPDevice* (*NPAcquireDevicePtr)( + NPP instance, + NPDeviceID device); + +/* Pepper extensions */ +struct NPExtensions { + /* Device interface acquisition */ + NPAcquireDevicePtr acquireDevice; +}; + +/* Events -------------------------------------------------------------------*/ + +typedef enum { + NPMouseButton_None = -1, + NPMouseButton_Left = 0, + NPMouseButton_Middle = 1, + NPMouseButton_Right = 2, +} NPMouseButtons; + +typedef enum { + NPEventType_Undefined = -1, + NPEventType_MouseDown = 0, + NPEventType_MouseUp = 1, + NPEventType_MouseMove = 2, + NPEventType_MouseEnter = 3, + NPEventType_MouseLeave = 4, + NPEventType_MouseWheel = 5, + NPEventType_RawKeyDown = 6, + NPEventType_KeyDown = 7, + NPEventType_KeyUp = 8, + NPEventType_Char = 9, + NPEventType_Minimize = 10, + NPEventType_Focus = 11, + NPEventType_Device = 12 +} NPEventTypes; + +typedef enum { + NPEventModifier_ShiftKey = 1 << 0, + NPEventModifier_ControlKey = 1 << 1, + NPEventModifier_AltKey = 1 << 2, + NPEventModifier_MetaKey = 1 << 3, + NPEventModifier_IsKeyPad = 1 << 4, + NPEventModifier_IsAutoRepeat = 1 << 5, + NPEventModifier_LeftButtonDown = 1 << 6, + NPEventModifier_MiddleButtonDown = 1 << 7, + NPEventModifier_RightButtonDown = 1 << 8 +} NPEventModifiers; + +typedef struct _NPKeyEvent +{ + uint32 modifier; + uint32 normalizedKeyCode; +} NPKeyEvent; + +typedef struct _NPCharacterEvent +{ + uint32 modifier; + uint16 text[4]; + uint16 unmodifiedText[4]; +} NPCharacterEvent; + +typedef struct _NPMouseEvent +{ + uint32 modifier; + int32 button; + int32 x; + int32 y; + int32 clickCount; +} NPMouseEvent; + +typedef struct _NPMouseWheelEvent +{ + uint32 modifier; + float deltaX; + float deltaY; + float wheelTicksX; + float wheelTicksY; + uint32 scrollByPage; +} NPMouseWheelEvent; + +typedef struct _NPDeviceEvent { + uint32 device_uid; + uint32 subtype; + /* uint8 generic[0]; */ +} NPDeviceEvent; + +typedef struct _NPMinimizeEvent { + int32 value; +} NPMinimizeEvent; + +typedef struct _NPFocusEvent { + int32 value; +} NPFocusEvent; + +typedef struct _NPPepperEvent +{ + uint32 size; + int32 type; + double timeStampSeconds; + union { + NPKeyEvent key; + NPCharacterEvent character; + NPMouseEvent mouse; + NPMouseWheelEvent wheel; + NPMinimizeEvent minimize; + NPFocusEvent focus; + NPDeviceEvent device; + } u; +} NPPepperEvent; + +/* 2D -----------------------------------------------------------------------*/ + +#define NPPepper2DDevice 1 + +typedef enum _NPRenderType +{ + NPRenderGraphicsRGBA +} NPRenderType; + +typedef struct _NPDeviceContext2DConfig { +} NPDeviceContext2DConfig; + +typedef struct _NPDeviceContext2D +{ + union { + struct { + void* region; + int32 stride; + + /* The dirty region that the plugin has painted into the buffer. This + * will be initialized to the size of the plugin image in + * initializeRenderContextPtr. The plugin can change the values to only + * update portions of the image. + */ + struct { + int32 left; + int32 top; + int32 right; + int32 bottom; + } dirty; + } graphicsRgba; + } u; +} NPDeviceContext2D; + +#endif /* _NP_EXTENSIONS_H_ */ diff --git a/third_party/npapi/npapi.gyp b/third_party/npapi/npapi.gyp index 796f3ca..d518240 100644 --- a/third_party/npapi/npapi.gyp +++ b/third_party/npapi/npapi.gyp @@ -15,6 +15,20 @@ 'bindings', ], }, + # Even though these are just headers and aren't compiled, adding them to + # the project makes it possible to open them in various IDEs. + 'sources': [ + 'bindings/npapi.h', + 'bindings/npapi_extensions.h', + 'bindings/npruntime.h', + ], + 'conditions': [ + ['OS=="linux"', { + 'sources': [ + 'bindings/npapi_x11.h', + ], + }], + ], }, ], } diff --git a/webkit/glue/pepper/pepper.h b/webkit/glue/pepper/pepper.h deleted file mode 100644 index 269cea8..0000000 --- a/webkit/glue/pepper/pepper.h +++ /dev/null @@ -1,179 +0,0 @@ -// Copyright (c) 2006-2009 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_GLUE_PEPPER_PEPPER_H_ -#define WEBKIT_GLUE_PEPPER_PEPPER_H_ - -#ifdef PEPPER_APIS_ENABLED - -#include "base/basictypes.h" -#include "third_party/npapi/bindings/npapi.h" - -/* - * A fake "enum" value for getting Pepper extensions. - * The variable returns a pointer to an NPPepperExtensions structure - */ -#define NPNVPepperExtensions ((NPNVariable) 4000) - -typedef enum { - NPMouseButton_None = -1, - NPMouseButton_Left = 0, - NPMouseButton_Middle = 1, - NPMouseButton_Right = 2, -} NPMouseButtons; - -typedef enum { - NPEventType_Undefined = -1, - NPEventType_MouseDown = 0, - NPEventType_MouseUp = 1, - NPEventType_MouseMove = 2, - NPEventType_MouseEnter = 3, - NPEventType_MouseLeave = 4, - NPEventType_MouseWheel = 5, - NPEventType_RawKeyDown = 6, - NPEventType_KeyDown = 7, - NPEventType_KeyUp = 8, - NPEventType_Char = 9, - NPEventType_Minimize = 10, - NPEventType_Focus = 11, - NPEventType_Device = 12 -} NPEventTypes; - -typedef enum { - NPEventModifier_ShiftKey = 1 << 0, - NPEventModifier_ControlKey = 1 << 1, - NPEventModifier_AltKey = 1 << 2, - NPEventModifier_MetaKey = 1 << 3, - NPEventModifier_IsKeyPad = 1 << 4, - NPEventModifier_IsAutoRepeat = 1 << 5, - NPEventModifier_LeftButtonDown = 1 << 6, - NPEventModifier_MiddleButtonDown = 1 << 7, - NPEventModifier_RightButtonDown = 1 << 8 -} NPEventModifiers; - -typedef struct _NPKeyEvent -{ - uint32 modifier; - uint32 normalizedKeyCode; -} NPKeyEvent; - -typedef struct _NPCharacterEvent -{ - uint32 modifier; - uint16 text[4]; - uint16 unmodifiedText[4]; -} NPCharacterEvent; - -typedef struct _NPMouseEvent -{ - uint32 modifier; - int32 button; - int32 x; - int32 y; - int32 clickCount; -} NPMouseEvent; - -typedef struct _NPMouseWheelEvent -{ - uint32 modifier; - float deltaX; - float deltaY; - float wheelTicksX; - float wheelTicksY; - uint32 scrollByPage; -} NPMouseWheelEvent; - -typedef struct _NPDeviceEvent { - uint32 device_uid; - uint32 subtype; - /* uint8 generic[0]; */ -} NPDeviceEvent; - -typedef struct _NPMinimizeEvent { - int32 value; -} NPMinimizeEvent; - -typedef struct _NPFocusEvent { - int32 value; -} NPFocusEvent; - -typedef struct _NPPepprEvent -{ - uint32 size; - int32 type; - double timeStampSeconds; - union { - NPKeyEvent key; - NPCharacterEvent character; - NPMouseEvent mouse; - NPMouseWheelEvent wheel; - NPMinimizeEvent minimize; - NPFocusEvent focus; - NPDeviceEvent device; - } u; -} NPPepperEvent; - -typedef struct _NPPepperRegion -{ - int32 x; - int32 y; - int32 w; - int32 h; -} NPPepperRegion; - -typedef enum _NPRenderType -{ - NPRenderGraphicsRGBA -} NPRenderType; - -typedef struct _NPRenderContext -{ - union { - struct { - void* region; - int32 stride; - - // The dirty region that the plugin has painted into the buffer. This - // will be initialized to the size of the plugin image in - // initializeRenderContextPtr. The plugin can change the values to only - // update portions of the image. - struct { - int32 left; - int32 top; - int32 right; - int32 bottom; - } dirty; - } graphicsRgba; - } u; -} NPRenderContext; - -typedef void (*NPFlushRenderContextCallbackPtr)(NPRenderContext* context, - NPError err, - void* userData); -typedef NPError (*NPInitializeRenderContextPtr)(NPP instance, - NPRenderType type, - NPRenderContext* context); -typedef NPError (*NPFlushRenderContextPtr)(NPP instance, - NPRenderContext* context, - NPFlushRenderContextCallbackPtr callback, - void* userData); -typedef NPError (*NPDestroyRenderContextPtr)(NPP instance, - NPRenderContext* context); -typedef NPError (*NPOpenFilePtr)(NPP instance, const char* fileName, void** handle); - -typedef struct _NPPepperExtensions -{ - /* Renderer extensions */ - NPInitializeRenderContextPtr initializeRender; - NPFlushRenderContextPtr flushRender; - NPDestroyRenderContextPtr destroyRender; - /* Shared memory extensions */ - - /* I/O extensions */ - NPOpenFilePtr openFile; -} NPPepperExtensions; - -#endif /* PEPPER_APIS_ENABLED */ - -#endif /* WEBKIT_GLUE_PEPPER_PEPPER_H_ */ diff --git a/webkit/glue/plugins/nphostapi.h b/webkit/glue/plugins/nphostapi.h index f840954..53c684c 100644 --- a/webkit/glue/plugins/nphostapi.h +++ b/webkit/glue/plugins/nphostapi.h @@ -8,8 +8,8 @@ #define WEBKIT_GLUE_PLUGIN_NPHOSTAPI_H__ #include "base/port.h" -#include "webkit/glue/pepper/pepper.h" #include "third_party/npapi/bindings/npapi.h" +#include "third_party/npapi/bindings/npapi_extensions.h" #include "third_party/npapi/bindings/npruntime.h" #ifdef __cplusplus diff --git a/webkit/glue/plugins/plugin_host.cc b/webkit/glue/plugins/plugin_host.cc index 7abe811..8cc094f 100644 --- a/webkit/glue/plugins/plugin_host.cc +++ b/webkit/glue/plugins/plugin_host.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2009 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,11 +20,11 @@ #include "webkit/glue/webplugininfo.h" #include "webkit/glue/webplugin_delegate.h" #include "webkit/glue/webkit_glue.h" -#include "webkit/glue/pepper/pepper.h" #include "webkit/glue/plugins/plugin_instance.h" #include "webkit/glue/plugins/plugin_lib.h" #include "webkit/glue/plugins/plugin_list.h" #include "webkit/glue/plugins/plugin_stream_url.h" +#include "third_party/npapi/bindings/npapi_extensions.h" #include "third_party/npapi/bindings/npruntime.h" using WebKit::WebBindings; @@ -666,31 +666,81 @@ void NPN_ForceRedraw(NPP id) { } #if defined(PEPPER_APIS_ENABLED) -static NPError InitializeRenderContext(NPP id, - NPRenderType type, - NPRenderContext* context) { +// Pepper 2D device API -------------------------------------------------------- + +static NPError Device2DQueryCapability(NPP id, int32 capability, int32* value) { + scoped_refptr<NPAPI::PluginInstance> plugin = FindInstance(id); + if (plugin) { + plugin->webplugin()->delegate()->Device2DQueryCapability(capability, value); + return NPERR_NO_ERROR; + } else { + return NPERR_GENERIC_ERROR; + } +} + +static NPError Device2DQueryConfig(NPP id, + const NPDeviceConfig* request, + NPDeviceConfig* obtain) { scoped_refptr<NPAPI::PluginInstance> plugin = FindInstance(id); if (plugin) { - webkit_glue::WebPluginDelegate* delegate = plugin->webplugin()->delegate(); - // Set up the renderer for the specified type. - return delegate->InitializeRenderContext(type, context); + return plugin->webplugin()->delegate()->Device2DQueryConfig( + static_cast<const NPDeviceContext2DConfig*>(request), + static_cast<NPDeviceContext2DConfig*>(obtain)); } return NPERR_GENERIC_ERROR; } -static NPError FlushRenderContext(NPP id, - NPRenderContext* context, - NPFlushRenderContextCallbackPtr callback, - void* user_data) { +static NPError Device2DInitializeContext(NPP id, + const NPDeviceConfig* config, + NPDeviceContext* context) { scoped_refptr<NPAPI::PluginInstance> plugin = FindInstance(id); if (plugin) { - webkit_glue::WebPluginDelegate* delegate = plugin->webplugin()->delegate(); - // Do the flush. - NPError err = delegate->FlushRenderContext(context); + return plugin->webplugin()->delegate()->Device2DInitializeContext( + static_cast<const NPDeviceContext2DConfig*>(config), + static_cast<NPDeviceContext2D*>(context)); + } + return NPERR_GENERIC_ERROR; +} + +static NPError Device2DSetStateContext(NPP id, + NPDeviceContext* context, + int32 state, + int32 value) { + scoped_refptr<NPAPI::PluginInstance> plugin = FindInstance(id); + if (plugin) { + return plugin->webplugin()->delegate()->Device2DSetStateContext( + static_cast<NPDeviceContext2D*>(context), state, value); + } + return NPERR_GENERIC_ERROR; +} + +static NPError Device2DGetStateContext(NPP id, + NPDeviceContext* context, + int32 state, + int32* value) { + scoped_refptr<NPAPI::PluginInstance> plugin = FindInstance(id); + if (plugin) { + return plugin->webplugin()->delegate()->Device2DGetStateContext( + static_cast<NPDeviceContext2D*>(context), state, value); + } + return NPERR_GENERIC_ERROR; +} + +static NPError Device2DFlushContext(NPP id, + NPDeviceContext* context, + NPDeviceFlushContextCallbackPtr callback, + void* user_data) { + scoped_refptr<NPAPI::PluginInstance> plugin = FindInstance(id); + if (plugin) { + NPError err = plugin->webplugin()->delegate()->Device2DFlushContext( + static_cast<NPDeviceContext2D*>(context), callback, user_data); // Invoke the callback to inform the caller the work was done. + // TODO(brettw) this is probably not how we want this to work, this should + // happen when the frame is painted so the plugin knows when it can draw + // the next frame. if (callback != NULL) - (*callback)(context, err, user_data); + (*callback)(id, context, err, user_data); // Return any errors. return err; @@ -698,23 +748,36 @@ static NPError FlushRenderContext(NPP id, return NPERR_GENERIC_ERROR; } -static NPError DestroyRenderContext(NPP id, - NPRenderContext* context) { +static NPError Device2DDestroyContext(NPP id, + NPDeviceContext* context) { scoped_refptr<NPAPI::PluginInstance> plugin = FindInstance(id); if (plugin) { - webkit_glue::WebPluginDelegate* delegate = plugin->webplugin()->delegate(); - return delegate->DestroyRenderContext(context); + return plugin->webplugin()->delegate()->Device2DDestroyContext( + static_cast<NPDeviceContext2D*>(context)); } return NPERR_GENERIC_ERROR; } -static NPError OpenFileInSandbox(NPP id, const char* file_name, void** handle) { - scoped_refptr<NPAPI::PluginInstance> plugin = FindInstance(id); - if (!plugin) - return NPERR_GENERIC_ERROR; - webkit_glue::WebPluginDelegate* delegate = plugin->webplugin()->delegate(); - return delegate->OpenFileInSandbox(file_name, handle); +// ----------------------------------------------------------------------------- + +static NPDevice* AcquireDevice(NPP id, NPDeviceID device_id) { + static NPDevice device_2d = { + Device2DQueryCapability, + Device2DQueryConfig, + Device2DInitializeContext, + Device2DSetStateContext, + Device2DGetStateContext, + Device2DFlushContext, + Device2DDestroyContext, + }; + switch (device_id) { + case NPPepper2DDevice: + return const_cast<NPDevice*>(&device_2d); + default: + return NULL; + } } + #endif // defined(PEPPER_APIS_ENABLED) NPError NPN_GetValue(NPP id, NPNVariable variable, void *value) { @@ -872,16 +935,12 @@ NPError NPN_GetValue(NPP id, NPNVariable variable, void *value) { #if defined(PEPPER_APIS_ENABLED) case NPNVPepperExtensions: { - static const NPPepperExtensions kExtensions = { - InitializeRenderContext, - FlushRenderContext, - DestroyRenderContext, - OpenFileInSandbox, + static const NPExtensions kExtensions = { + AcquireDevice, }; // Return a pointer to the canonical function table. - NPPepperExtensions* extensions = - const_cast<NPPepperExtensions*>(&kExtensions); - NPPepperExtensions** exts = reinterpret_cast<NPPepperExtensions**>(value); + NPExtensions* extensions = const_cast<NPExtensions*>(&kExtensions); + NPExtensions** exts = reinterpret_cast<NPExtensions**>(value); *exts = extensions; rv = NPERR_NO_ERROR; break; diff --git a/webkit/glue/webplugin_delegate.h b/webkit/glue/webplugin_delegate.h index 2b9c5bb..5a724f1 100644 --- a/webkit/glue/webplugin_delegate.h +++ b/webkit/glue/webplugin_delegate.h @@ -12,7 +12,7 @@ #include "base/string16.h" #include "build/build_config.h" #include "third_party/npapi/bindings/npapi.h" -#include "webkit/glue/pepper/pepper.h" +#include "third_party/npapi/bindings/npapi_extensions.h" #include "third_party/WebKit/WebKit/chromium/public/WebCanvas.h" class FilePath; @@ -127,22 +127,38 @@ class WebPluginDelegate { intptr_t notify_data, intptr_t stream) = 0; - // The following two methods are for use in implementing Pepper renderers. + // The following methods are for use in implementing Pepper renderers. // They should not be called outside of that context. - virtual NPError InitializeRenderContext(NPRenderType type, - NPRenderContext* context) { + + // Pepper 2D device API. + virtual NPError Device2DQueryCapability(int32 capability, int32* value) { return NPERR_GENERIC_ERROR; } - - virtual NPError DestroyRenderContext(NPRenderContext* context) { + virtual NPError Device2DQueryConfig(const NPDeviceContext2DConfig* request, + NPDeviceContext2DConfig* obtain) { return NPERR_GENERIC_ERROR; } - - virtual NPError FlushRenderContext(NPRenderContext* context) { + virtual NPError Device2DInitializeContext( + const NPDeviceContext2DConfig* config, + NPDeviceContext2D* context) { return NPERR_GENERIC_ERROR; } - - virtual NPError OpenFileInSandbox(const char* file_name, void** handle) { + virtual NPError Device2DSetStateContext(NPDeviceContext2D* context, + int32 state, + int32 value) { + return NPERR_GENERIC_ERROR; + } + virtual NPError Device2DGetStateContext(NPDeviceContext2D* context, + int32 state, + int32* value) { + return NPERR_GENERIC_ERROR; + } + virtual NPError Device2DFlushContext(NPDeviceContext2D* context, + NPDeviceFlushContextCallbackPtr callback, + void* user_data) { + return NPERR_GENERIC_ERROR; + } + virtual NPError Device2DDestroyContext(NPDeviceContext2D* context) { return NPERR_GENERIC_ERROR; } }; diff --git a/webkit/tools/pepper_test_plugin/plugin_object.cc b/webkit/tools/pepper_test_plugin/plugin_object.cc index 8af7591..432bfc4 100644 --- a/webkit/tools/pepper_test_plugin/plugin_object.cc +++ b/webkit/tools/pepper_test_plugin/plugin_object.cc @@ -224,11 +224,12 @@ void DrawSampleBitmap(SkCanvas& canvas, int width, int height) { canvas.drawPath(path, paint); } -NPPepperExtensions* pepper = NULL; - -void FlushCallback(NPRenderContext* context, void* user_data) { +void FlushCallback(NPP instance, NPDeviceContext* context, + NPError err, void* user_data) { } +NPExtensions* extensions = NULL; + } // namespace @@ -236,15 +237,19 @@ void FlushCallback(NPRenderContext* context, void* user_data) { PluginObject::PluginObject(NPP npp) : npp_(npp), - test_object_(browser->createobject(npp, GetTestClass())) { - if (!pepper) { + test_object_(browser->createobject(npp, GetTestClass())), + device2d_(NULL) { + if (!extensions) { browser->getvalue(npp_, NPNVPepperExtensions, - reinterpret_cast<void*>(&pepper)); - CHECK(pepper); + reinterpret_cast<void*>(&extensions)); + CHECK(extensions); } + device2d_ = extensions->acquireDevice(npp, NPPepper2DDevice); + CHECK(device2d_); } PluginObject::~PluginObject() { + // FIXME(brettw) destroy the context. browser->releaseobject(test_object_); } @@ -254,26 +259,12 @@ NPClass* PluginObject::GetPluginClass() { } void PluginObject::SetWindow(const NPWindow& window) { - // File test - /* TODO(brettw): remove this when the file stuff is complete. This code is for - testing the OpenFileInSandbox function which is not complete. - { - void* handle = (void*)112358; - NPError err = pepper->openFile(npp_, - "q:\\prj\\src2\\src\\webkit\\tools\\pepper_test_plugin\\README", - &handle); - CHECK(err == NPERR_NO_ERROR); - - char buf[256]; - sprintf(buf, "Got the handle %d", (int)handle); - ::MessageBoxA(NULL, buf, "pepper", 0); - }*/ - size_.set_width(window.width); size_.set_height(window.height); - NPRenderContext context; - pepper->initializeRender(npp_, NPRenderGraphicsRGBA, &context); + NPDeviceContext2DConfig config; + NPDeviceContext2D context; + device2d_->initializeContext(npp_, &config, &context); SkBitmap bitmap; bitmap.setConfig(SkBitmap::kARGB_8888_Config, window.width, window.height); @@ -284,7 +275,7 @@ void PluginObject::SetWindow(const NPWindow& window) { // TODO(brettw) figure out why this cast is necessary, the functions seem to // match. Could be a calling convention mismatch? - NPFlushRenderContextCallbackPtr callback = - reinterpret_cast<NPFlushRenderContextCallbackPtr>(&FlushCallback); - pepper->flushRender(npp_, &context, callback, NULL); + NPDeviceFlushContextCallbackPtr callback = + reinterpret_cast<NPDeviceFlushContextCallbackPtr>(&FlushCallback); + device2d_->flushContext(npp_, &context, callback, NULL); } diff --git a/webkit/tools/pepper_test_plugin/plugin_object.h b/webkit/tools/pepper_test_plugin/plugin_object.h index a45bdc4..1dcbb80 100644 --- a/webkit/tools/pepper_test_plugin/plugin_object.h +++ b/webkit/tools/pepper_test_plugin/plugin_object.h @@ -49,6 +49,8 @@ class PluginObject { NPP npp_; NPObject* test_object_; + NPDevice* device2d_; + gfx::Size size_; DISALLOW_COPY_AND_ASSIGN(PluginObject); |