diff options
author | sehr@google.com <sehr@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-12 19:50:19 +0000 |
---|---|---|
committer | sehr@google.com <sehr@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-12 19:50:19 +0000 |
commit | 36219a2b0fa0f23f2e5965c644b98c8b0df6e7ec (patch) | |
tree | 4eedce1b5008632ab49e4efca238d2b43fda452d | |
parent | d6d6d586d2a91d13d06a8bce53a2d03f2458f9c2 (diff) | |
download | chromium_src-36219a2b0fa0f23f2e5965c644b98c8b0df6e7ec.zip chromium_src-36219a2b0fa0f23f2e5965c644b98c8b0df6e7ec.tar.gz chromium_src-36219a2b0fa0f23f2e5965c644b98c8b0df6e7ec.tar.bz2 |
First version of pepper api implementation:
Adds a severely pared down version of webplugin_delegate files
that are not currently used to create any instances.
Also adds calls for render APIs that remain to be
connected to the impelementation. The function pointers are
returned by NPN_GetValue calls with new enumerated values.
I have also added Nicholas' NPEvent definitions.
These changes are to permit further collaboration between
sehr, brettw, and cpu.
Review URL: http://codereview.chromium.org/270024
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@28730 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | third_party/npapi/bindings/npapi.h | 144 | ||||
-rw-r--r-- | webkit/glue/plugins/plugin_host.cc | 68 | ||||
-rw-r--r-- | webkit/glue/plugins/plugin_instance.cc | 55 | ||||
-rw-r--r-- | webkit/glue/plugins/plugin_instance.h | 17 | ||||
-rw-r--r-- | webkit/glue/plugins/webplugin_delegate_pepper_impl.cc | 286 | ||||
-rw-r--r-- | webkit/glue/plugins/webplugin_delegate_pepper_impl.h | 127 | ||||
-rw-r--r-- | webkit/webkit.gyp | 2 |
7 files changed, 665 insertions, 34 deletions
diff --git a/third_party/npapi/bindings/npapi.h b/third_party/npapi/bindings/npapi.h index 628f00d..aac35e3 100644 --- a/third_party/npapi/bindings/npapi.h +++ b/third_party/npapi/bindings/npapi.h @@ -437,6 +437,15 @@ typedef enum { #endif , NPNVsupportsCocoaBool = 3001 /* TRUE if the browser supports the Cocoa event model */ #endif +#ifdef PEPPER_APIS_ENABLED + /* + * Note: these APIs have not been ratified by Mozilla, et al. + * Until they are, they need to be distinct values from other enum + * elements here. + */ + , NPNVInitializeRenderContextFunc = 4000 /* A pointer to the InitializeRenderContext function */ + , NPNVFlushRenderContextFunc = 4001 /* A pointer to the FlushRenderContext function */ +#endif } NPNVariable; typedef enum { @@ -607,6 +616,7 @@ typedef enum { NPCoordinateSpaceFlippedScreen } NPCoordinateSpace; +#if !defined(PEPPER_APIS_ENABLED) #if defined(XP_MAC) || defined(XP_MACOSX) #ifndef NP_NO_CARBON @@ -737,6 +747,140 @@ enum NPEventType { #endif /* XP_MACOSX */ +#else // defined(PEPPER_APIS_ENABLED) +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; + uint32 text; + uint32 unmodifiedText; +} 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 _NPEvent +{ + uint32 size; + int32 type; + double timeStampSeconds; + union { + NPKeyEvent key; + NPCharacterEvent character; + NPMouseEvent mouse; + NPMouseWheelEvent wheel; + NPMinimizeEvent minimize; + NPFocusEvent focus; + NPDeviceEvent device; + } u; +} NPEvent; + +typedef struct _NPRegion +{ + int32 x; + int32 y; + int32 w; + int32 h; +} NPRegion; + +typedef enum _NPRenderType +{ + NPRenderGraphicsRGBA +} NPRenderType; + +typedef struct _NPRenderContext +{ + union { + struct { + void* region; + int32 stride; + } 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); +#endif // defined(PEPPER_APIS_ENABLED) + /* * Values for mode passed to NPP_New: */ diff --git a/webkit/glue/plugins/plugin_host.cc b/webkit/glue/plugins/plugin_host.cc index 343a1f4..c21fcc9 100644 --- a/webkit/glue/plugins/plugin_host.cc +++ b/webkit/glue/plugins/plugin_host.cc @@ -2,6 +2,9 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +// Pepper API support should be turned on for this module. +#define PEPPER_APIS_ENABLED + #include "webkit/glue/plugins/plugin_host.h" #include "base/file_util.h" @@ -104,7 +107,6 @@ void PluginHost::InitializeHostFuncs() { host_funcs_.getvalueforurl = NPN_GetValueForURL; host_funcs_.setvalueforurl = NPN_SetValueForURL; host_funcs_.getauthenticationinfo = NPN_GetAuthenticationInfo; - } void PluginHost::PatchNPNetscapeFuncs(NPNetscapeFuncs* overrides) { @@ -659,6 +661,29 @@ void NPN_ForceRedraw(NPP id) { NOTIMPLEMENTED(); } +#if defined(PEPPER_APIS_ENABLED) +static NPError InitializeRenderContext(NPP id, + NPRenderType type, + NPRenderContext* context) { + scoped_refptr<NPAPI::PluginInstance> plugin = FindInstance(id); + if (plugin) { + return plugin->InitializeRenderContext(type, context); + } + return NPERR_GENERIC_ERROR; +} + +static NPError FlushRenderContext(NPP id, + NPRenderContext* context, + NPFlushRenderContextCallbackPtr callback, + void* userData) { + scoped_refptr<NPAPI::PluginInstance> plugin = FindInstance(id); + if (plugin) { + return plugin->FlushRenderContext(context, callback, userData); + } + return NPERR_GENERIC_ERROR; +} +#endif // defined(PEPPER_APIS_ENABLED) + NPError NPN_GetValue(NPP id, NPNVariable variable, void *value) { // Allows the plugin to query the browser for information // @@ -791,6 +816,24 @@ NPError NPN_GetValue(NPP id, NPNVariable variable, void *value) { break; } #endif +#if defined(PEPPER_APIS_ENABLED) + case NPNVInitializeRenderContextFunc: + { + NPInitializeRenderContextPtr* func = + reinterpret_cast<NPInitializeRenderContextPtr*>(value); + *func = InitializeRenderContext; + rv = NPERR_NO_ERROR; + break; + } + case NPNVFlushRenderContextFunc: + { + NPFlushRenderContextPtr* func = + reinterpret_cast<NPFlushRenderContextPtr*>(value); + *func = FlushRenderContext; + rv = NPERR_NO_ERROR; + break; + } +#endif // defined(PEPPER_APIS_ENABLED) default: { // TODO: implement me @@ -892,6 +935,29 @@ void NPN_PluginThreadAsyncCall(NPP id, } } +#if defined(PEPPER_APIS_ENABLED) +NPError NPN_InitializeRenderContext(NPP id, + NPRenderType type, + NPRenderContext* context) { + scoped_refptr<NPAPI::PluginInstance> plugin = FindInstance(id); + if (plugin) { + return plugin->InitializeRenderContext(type, context); + } + return NPERR_GENERIC_ERROR; +} + +NPError NPN_FlushRenderContext(NPP id, + NPRenderContext* context, + NPFlushRenderContextCallbackPtr callback, + void* userData) { + scoped_refptr<NPAPI::PluginInstance> plugin = FindInstance(id); + if (plugin) { + return plugin->FlushRenderContext(context, callback, userData); + } + return NPERR_GENERIC_ERROR; +} +#endif // defined(PEPPER_APIS_ENABLED) + NPError NPN_GetValueForURL(NPP id, NPNURLVariable variable, const char *url, diff --git a/webkit/glue/plugins/plugin_instance.cc b/webkit/glue/plugins/plugin_instance.cc index db5954a..c21180a 100644 --- a/webkit/glue/plugins/plugin_instance.cc +++ b/webkit/glue/plugins/plugin_instance.cc @@ -2,6 +2,9 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +// Pepper API support should be enabled for this file. +#define PEPPER_APIS_ENABLED + #include "build/build_config.h" #include "webkit/glue/plugins/plugin_instance.h" @@ -105,25 +108,6 @@ void PluginInstance::CloseStreams() { in_close_streams_ = false; } -#if defined(OS_WIN) -bool PluginInstance::HandleEvent(UINT message, WPARAM wParam, LPARAM lParam) { - if (!windowless_) - return false; - - NPEvent windowEvent; - windowEvent.event = message; - windowEvent.lParam = static_cast<uint32>(lParam); - windowEvent.wParam = static_cast<uint32>(wParam); - return NPP_HandleEvent(&windowEvent) != 0; -} -#elif defined(OS_LINUX) -bool PluginInstance::HandleEvent(XEvent* event) { - if (!windowless_) - return false; - return NPP_HandleEvent(event); -} -#endif - bool PluginInstance::Start(const GURL& url, char** const param_names, char** const param_values, @@ -291,7 +275,7 @@ NPError PluginInstance::NPP_SetValue(NPNVariable variable, void *value) { return NPERR_INVALID_FUNCTABLE_ERROR; } -short PluginInstance::NPP_HandleEvent(NPEvent *event) { +short PluginInstance::NPP_HandleEvent(void* event) { DCHECK(npp_functions_ != 0); DCHECK(npp_functions_->event != 0); if (npp_functions_->event != 0) { @@ -367,26 +351,47 @@ void PluginInstance::DidManualLoadFail() { } } +#ifndef PEPPER_APIS_DISABLED +NPError PluginInstance::InitializeRenderContext(NPRenderType type, + NPRenderContext* context) { + // Set up the renderer for the specified type. + // Return no errors. + return NPERR_NO_ERROR; +} + +NPError PluginInstance::FlushRenderContext(NPRenderContext* context, + NPFlushRenderContextCallbackPtr callback, void* user_data) { + // Do the flush. + NPError err = NPERR_NO_ERROR; + // Invoke the callback to inform the caller the work was done. + if (callback != NULL) { + (*callback)(context, err, user_data); + } + // Return no errors. + return NPERR_NO_ERROR; +} +#endif // PEPPER_APIS_DISABLED + void PluginInstance::PluginThreadAsyncCall(void (*func)(void *), - void *userData) { + void *user_data) { message_loop_->PostTask(FROM_HERE, NewRunnableMethod( - this, &PluginInstance::OnPluginThreadAsyncCall, func, userData)); + this, &PluginInstance::OnPluginThreadAsyncCall, func, user_data)); } void PluginInstance::OnPluginThreadAsyncCall(void (*func)(void *), - void *userData) { + void *user_data) { #if defined(OS_WIN) // We are invoking an arbitrary callback provided by a third // party plugin. It's better to wrap this into an exception // block to protect us from crashes. __try { - func(userData); + func(user_data); } __except(EXCEPTION_EXECUTE_HANDLER) { // Maybe we can disable a crashing plugin. // But for now, just continue. } #else - func(userData); + func(user_data); #endif } diff --git a/webkit/glue/plugins/plugin_instance.h b/webkit/glue/plugins/plugin_instance.h index 24dd090..8042484 100644 --- a/webkit/glue/plugins/plugin_instance.h +++ b/webkit/glue/plugins/plugin_instance.h @@ -100,13 +100,14 @@ class PluginInstance : public base::RefCountedThreadSafe<PluginInstance> { NPAPI::PluginLib* plugin_lib() { return plugin_; } -#if defined(OS_WIN) - // Handles a windows native message which this PluginInstance should deal - // with. Returns true if the event is handled, false otherwise. - bool HandleEvent(UINT message, WPARAM wParam, LPARAM lParam); -#elif defined(OS_LINUX) - bool HandleEvent(union _XEvent* event); -#endif +#if defined(PEPPER_APIS_ENABLED) + NPError InitializeRenderContext(NPRenderType type, + NPRenderContext* context); + NPError FlushRenderContext(NPRenderContext* context, + NPFlushRenderContextCallbackPtr callback, + void* userData); + +#endif // defined(PEPPER_APIS_ENABLED) // Creates a stream for sending an URL. If notify_needed // is true, it will send a notification to the plugin @@ -163,7 +164,7 @@ class PluginInstance : public base::RefCountedThreadSafe<PluginInstance> { void NPP_URLNotify(const char *, NPReason, void *); NPError NPP_GetValue(NPPVariable, void *); NPError NPP_SetValue(NPNVariable, void *); - short NPP_HandleEvent(NPEvent *); + short NPP_HandleEvent(void*); void NPP_Destroy(); bool NPP_Print(NPPrint* platform_print); diff --git a/webkit/glue/plugins/webplugin_delegate_pepper_impl.cc b/webkit/glue/plugins/webplugin_delegate_pepper_impl.cc new file mode 100644 index 0000000..227f09b --- /dev/null +++ b/webkit/glue/plugins/webplugin_delegate_pepper_impl.cc @@ -0,0 +1,286 @@ +// Copyright (c) 2006-2008 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/glue/plugins/webplugin_delegate_pepper_impl.h" + +#include <string> +#include <vector> + +#include "base/file_util.h" +#include "base/message_loop.h" +#include "base/process_util.h" +#include "base/scoped_ptr.h" +#include "base/stats_counters.h" +#include "base/string_util.h" +#include "webkit/api/public/WebInputEvent.h" +#include "webkit/glue/glue_util.h" +#include "webkit/glue/plugins/plugin_constants_win.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 "webkit/glue/webkit_glue.h" + +using webkit_glue::WebPlugin; +using webkit_glue::WebPluginDelegate; +using webkit_glue::WebPluginResourceClient; +using WebKit::WebCursorInfo; +using WebKit::WebKeyboardEvent; +using WebKit::WebInputEvent; +using WebKit::WebMouseEvent; + + +WebPluginDelegatePepperImpl* WebPluginDelegatePepperImpl::Create( + const FilePath& filename, + const std::string& mime_type, + gfx::PluginWindowHandle containing_view) { + scoped_refptr<NPAPI::PluginLib> plugin_lib = + NPAPI::PluginLib::CreatePluginLib(filename); + if (plugin_lib.get() == NULL) + return NULL; + + NPError err = plugin_lib->NP_Initialize(); + if (err != NPERR_NO_ERROR) + return NULL; + + scoped_refptr<NPAPI::PluginInstance> instance = + plugin_lib->CreateInstance(mime_type); + return new WebPluginDelegatePepperImpl(containing_view, instance.get()); +} + +bool WebPluginDelegatePepperImpl::Initialize( + const GURL& url, + const std::vector<std::string>& arg_names, + const std::vector<std::string>& arg_values, + WebPlugin* plugin, + bool load_manually) { + plugin_ = plugin; + + instance_->set_web_plugin(plugin_); + int argc = 0; + scoped_array<char*> argn(new char*[arg_names.size()]); + scoped_array<char*> argv(new char*[arg_names.size()]); + for (size_t i = 0; i < arg_names.size(); ++i) { + argn[argc] = const_cast<char*>(arg_names[i].c_str()); + argv[argc] = const_cast<char*>(arg_values[i].c_str()); + argc++; + } + + bool start_result = instance_->Start( + url, argn.get(), argv.get(), argc, load_manually); + if (!start_result) + return false; + + // For windowless plugins we should set the containing window handle + // as the instance window handle. This is what Safari does. Not having + // a valid window handle causes subtle bugs with plugins which retreive + // the window handle and validate the same. The window handle can be + // retreived via NPN_GetValue of NPNVnetscapeWindow. + instance_->set_window_handle(parent_); + + plugin_url_ = url.spec(); + + return true; +} + +void WebPluginDelegatePepperImpl::DestroyInstance() { + if (instance_ && (instance_->npp()->ndata != NULL)) { + // Shutdown all streams before destroying so that + // no streams are left "in progress". Need to do + // this before calling set_web_plugin(NULL) because the + // instance uses the helper to do the download. + instance_->CloseStreams(); + + window_.window = NULL; + instance_->NPP_SetWindow(&window_); + + instance_->NPP_Destroy(); + + instance_->set_web_plugin(NULL); + + instance_ = 0; + } +} + +void WebPluginDelegatePepperImpl::UpdateGeometry( + const gfx::Rect& window_rect, + const gfx::Rect& clip_rect) { + WindowlessUpdateGeometry(window_rect, clip_rect); +} + +NPObject* WebPluginDelegatePepperImpl::GetPluginScriptableObject() { + return instance_->GetPluginScriptableObject(); +} + +void WebPluginDelegatePepperImpl::DidFinishLoadWithReason( + const GURL& url, + NPReason reason, + intptr_t notify_data) { + instance()->DidFinishLoadWithReason( + url, reason, reinterpret_cast<void*>(notify_data)); +} + +int WebPluginDelegatePepperImpl::GetProcessId() { + // We are in process, so the plugin pid is this current process pid. + return base::GetCurrentProcId(); +} + +void WebPluginDelegatePepperImpl::SendJavaScriptStream( + const GURL& url, + const std::string& result, + bool success, + bool notify_needed, + intptr_t notify_data) { + instance()->SendJavaScriptStream(url, result, success, notify_needed, + notify_data); +} + +void WebPluginDelegatePepperImpl::DidReceiveManualResponse( + const GURL& url, const std::string& mime_type, + const std::string& headers, uint32 expected_length, uint32 last_modified) { + instance()->DidReceiveManualResponse(url, mime_type, headers, + expected_length, last_modified); +} + +void WebPluginDelegatePepperImpl::DidReceiveManualData(const char* buffer, + int length) { + instance()->DidReceiveManualData(buffer, length); +} + +void WebPluginDelegatePepperImpl::DidFinishManualLoading() { + instance()->DidFinishManualLoading(); +} + +void WebPluginDelegatePepperImpl::DidManualLoadFail() { + instance()->DidManualLoadFail(); +} + +FilePath WebPluginDelegatePepperImpl::GetPluginPath() { + return instance()->plugin_lib()->plugin_info().path; +} + +WebPluginResourceClient* WebPluginDelegatePepperImpl::CreateResourceClient( + int resource_id, const GURL& url, bool notify_needed, + intptr_t notify_data, intptr_t existing_stream) { + // Stream already exists. This typically happens for range requests + // initiated via NPN_RequestRead. + if (existing_stream) { + NPAPI::PluginStream* plugin_stream = + reinterpret_cast<NPAPI::PluginStream*>(existing_stream); + + return plugin_stream->AsResourceClient(); + } + + std::string mime_type; + NPAPI::PluginStreamUrl *stream = instance()->CreateStream( + resource_id, url, mime_type, notify_needed, + reinterpret_cast<void*>(notify_data)); + return stream; +} + +bool WebPluginDelegatePepperImpl::IsPluginDelegateWindow( + gfx::NativeWindow window) { + return false; +} + +bool WebPluginDelegatePepperImpl::GetPluginNameFromWindow( + gfx::NativeWindow window, std::wstring *plugin_name) { + return false; +} + +bool WebPluginDelegatePepperImpl::IsDummyActivationWindow( + gfx::NativeWindow window) { + return false; +} + +WebPluginDelegatePepperImpl::WebPluginDelegatePepperImpl( + gfx::PluginWindowHandle containing_view, + NPAPI::PluginInstance *instance) + : plugin_(NULL), + instance_(instance), + parent_(containing_view) { + memset(&window_, 0, sizeof(window_)); +} + +WebPluginDelegatePepperImpl::~WebPluginDelegatePepperImpl() { + DestroyInstance(); +} + +void WebPluginDelegatePepperImpl::PluginDestroyed() { + delete this; +} + +void WebPluginDelegatePepperImpl::Paint(gfx::NativeDrawingContext context, const gfx::Rect& rect) { + NOTIMPLEMENTED(); +} + +void WebPluginDelegatePepperImpl::Print(gfx::NativeDrawingContext context) { + NOTIMPLEMENTED(); +} + +void WebPluginDelegatePepperImpl::InstallMissingPlugin() { + NOTIMPLEMENTED(); +} + +void WebPluginDelegatePepperImpl::WindowlessUpdateGeometry( + const gfx::Rect& window_rect, + const gfx::Rect& clip_rect) { + // Only resend to the instance if the geometry has changed. + if (window_rect == window_rect_ && clip_rect == clip_rect_) + return; + + // We will inform the instance of this change when we call NPP_SetWindow. + clip_rect_ = clip_rect; + cutout_rects_.clear(); + + if (window_rect_ != window_rect) { + window_rect_ = window_rect; + WindowlessSetWindow(true); + // TODO(sehr): update the context here? + } +} + +void WebPluginDelegatePepperImpl::WindowlessPaint( + gfx::NativeDrawingContext context, + const gfx::Rect& damage_rect) { + static StatsRate plugin_paint("Plugin.Paint"); + StatsScope<StatsRate> scope(plugin_paint); + // TODO(sehr): save the context here? +} + +void WebPluginDelegatePepperImpl::WindowlessSetWindow(bool force_set_window) { + if (!instance()) + return; + + if (window_rect_.IsEmpty()) // wait for geometry to be set. + return; + + DCHECK(instance()->windowless()); + + window_.clipRect.top = clip_rect_.y(); + window_.clipRect.left = clip_rect_.x(); + window_.clipRect.bottom = clip_rect_.y() + clip_rect_.height(); + window_.clipRect.right = clip_rect_.x() + clip_rect_.width(); + window_.height = window_rect_.height(); + window_.width = window_rect_.width(); + window_.x = window_rect_.x(); + window_.y = window_rect_.y(); + window_.type = NPWindowTypeDrawable; + + NPError err = instance()->NPP_SetWindow(&window_); + DCHECK(err == NPERR_NO_ERROR); +} + +void WebPluginDelegatePepperImpl::SetFocus() { + // TODO(sehr): what to do here? +} + +bool WebPluginDelegatePepperImpl::HandleInputEvent(const WebInputEvent& event, + WebCursorInfo* cursor_info) { + bool ret = false; + // TODO(sehr): pass event to plugin. + // instance()->NPP_HandleEvent(&np_event) != 0; + + return ret; +} diff --git a/webkit/glue/plugins/webplugin_delegate_pepper_impl.h b/webkit/glue/plugins/webplugin_delegate_pepper_impl.h new file mode 100644 index 0000000..8a21340 --- /dev/null +++ b/webkit/glue/plugins/webplugin_delegate_pepper_impl.h @@ -0,0 +1,127 @@ +// Copyright (c) 2006-2008 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_PLUGIN_WEBPLUGIN_DELEGATE_PEPPER_IMPL_H_ +#define WEBKIT_GLUE_PLUGIN_WEBPLUGIN_DELEGATE_PEPPER_IMPL_H_ + +#include "build/build_config.h" + +#include <list> +#include <string> +#include <vector> + +#include "app/gfx/native_widget_types.h" +#include "base/file_path.h" +#include "base/gfx/rect.h" +#include "base/ref_counted.h" +#include "base/task.h" +#include "third_party/npapi/bindings/npapi.h" +#include "webkit/glue/webcursor.h" +#include "webkit/glue/webplugin_delegate.h" + +namespace NPAPI { +class PluginInstance; +} + +// An implementation of WebPluginDelegate for Pepper in-process plugins. +class WebPluginDelegatePepperImpl : public webkit_glue::WebPluginDelegate { + public: + static WebPluginDelegatePepperImpl* Create(const FilePath& filename, + const std::string& mime_type, gfx::PluginWindowHandle containing_view); + + static bool IsPluginDelegateWindow(gfx::NativeWindow window); + static bool GetPluginNameFromWindow(gfx::NativeWindow window, + std::wstring *plugin_name); + + // Returns true if the window handle passed in is that of the dummy + // activation window for windowless plugins. + static bool IsDummyActivationWindow(gfx::NativeWindow window); + + // WebPluginDelegate implementation + virtual bool Initialize(const GURL& url, + const std::vector<std::string>& arg_names, + const std::vector<std::string>& arg_values, + webkit_glue::WebPlugin* plugin, + bool load_manually); + virtual void PluginDestroyed(); + virtual void UpdateGeometry(const gfx::Rect& window_rect, + const gfx::Rect& clip_rect); + virtual void Paint(gfx::NativeDrawingContext context, const gfx::Rect& rect); + virtual void Print(gfx::NativeDrawingContext context); + virtual void SetFocus(); + virtual bool HandleInputEvent(const WebKit::WebInputEvent& event, + WebKit::WebCursorInfo* cursor); + virtual NPObject* GetPluginScriptableObject(); + virtual void DidFinishLoadWithReason(const GURL& url, NPReason reason, + intptr_t notify_data); + virtual int GetProcessId(); + virtual void SendJavaScriptStream(const GURL& url, + const std::string& result, + bool success, bool notify_needed, + intptr_t notify_data); + virtual void DidReceiveManualResponse(const GURL& url, + const std::string& mime_type, + const std::string& headers, + uint32 expected_length, + uint32 last_modified); + virtual void DidReceiveManualData(const char* buffer, int length); + virtual void DidFinishManualLoading(); + virtual void DidManualLoadFail(); + virtual void InstallMissingPlugin(); + virtual webkit_glue::WebPluginResourceClient* CreateResourceClient( + int resource_id, + const GURL& url, + bool notify_needed, + intptr_t notify_data, + intptr_t stream); + // End of WebPluginDelegate implementation. + + bool IsWindowless() const { return true; } + gfx::Rect GetRect() const { return window_rect_; } + gfx::Rect GetClipRect() const { return clip_rect_; } + + // Returns the path for the library implementing this plugin. + FilePath GetPluginPath(); + + private: + friend class DeleteTask<WebPluginDelegatePepperImpl>; + + WebPluginDelegatePepperImpl(gfx::PluginWindowHandle containing_view, + NPAPI::PluginInstance *instance); + ~WebPluginDelegatePepperImpl(); + + //---------------------------- + // used for windowless plugins + void WindowlessUpdateGeometry(const gfx::Rect& window_rect, + const gfx::Rect& clip_rect); + void WindowlessPaint(gfx::NativeDrawingContext hdc, const gfx::Rect& rect); + + // Tells the plugin about the current state of the window. + // See NPAPI NPP_SetWindow for more information. + void WindowlessSetWindow(bool force_set_window); + + //----------------------------------------- + // used for windowed and windowless plugins + + NPAPI::PluginInstance* instance() { return instance_.get(); } + + // Closes down and destroys our plugin instance. + void DestroyInstance(); + + webkit_glue::WebPlugin* plugin_; + scoped_refptr<NPAPI::PluginInstance> instance_; + + gfx::PluginWindowHandle parent_; + NPWindow window_; + gfx::Rect window_rect_; + gfx::Rect clip_rect_; + std::vector<gfx::Rect> cutout_rects_; + + // The url with which the plugin was instantiated. + std::string plugin_url_; + + DISALLOW_COPY_AND_ASSIGN(WebPluginDelegatePepperImpl); +}; + +#endif // WEBKIT_GLUE_PLUGIN_WEBPLUGIN_DELEGATE_PEPPER_IMPL_H_ diff --git a/webkit/webkit.gyp b/webkit/webkit.gyp index 0aa3e04..5c04aac 100644 --- a/webkit/webkit.gyp +++ b/webkit/webkit.gyp @@ -529,6 +529,8 @@ 'glue/plugins/webplugin_delegate_impl_gtk.cc', 'glue/plugins/webplugin_delegate_impl_mac.mm', 'glue/plugins/webplugin_delegate_impl_win.cc', + 'glue/plugins/webplugin_delegate_pepper_impl.cc', + 'glue/plugins/webplugin_delegate_pepper_impl.h', 'glue/alt_error_page_resource_fetcher.cc', 'glue/alt_error_page_resource_fetcher.h', 'glue/autofill_form.cc', |