diff options
author | darin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-24 20:38:38 +0000 |
---|---|---|
committer | darin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-24 20:38:38 +0000 |
commit | 760b2822b77c2e85983b3a860e6c527b6adb4edb (patch) | |
tree | 7ae6075a338573f83b8856a010652603521b11cf | |
parent | 413dfc0904b3a2670d38e97d334ecd63aae7ff5a (diff) | |
download | chromium_src-760b2822b77c2e85983b3a860e6c527b6adb4edb.zip chromium_src-760b2822b77c2e85983b3a860e6c527b6adb4edb.tar.gz chromium_src-760b2822b77c2e85983b3a860e6c527b6adb4edb.tar.bz2 |
Chromium side of supporting property enumeration, memory allocation, querying
the time according to the browser, and dispatching work to the main thread.
This CL also enables catching exceptions thrown by JS during a PPB_Var method.
R=brettw
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/2148001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@48075 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | DEPS | 2 | ||||
-rw-r--r-- | webkit/glue/plugins/pepper_plugin_instance.cc | 4 | ||||
-rw-r--r-- | webkit/glue/plugins/pepper_plugin_instance.h | 1 | ||||
-rw-r--r-- | webkit/glue/plugins/pepper_plugin_module.cc | 32 | ||||
-rw-r--r-- | webkit/glue/plugins/pepper_var.cc | 82 | ||||
-rw-r--r-- | webkit/glue/plugins/pepper_var.h | 5 | ||||
-rw-r--r-- | webkit/glue/plugins/pepper_webplugin_impl.cc | 5 |
7 files changed, 110 insertions, 21 deletions
@@ -151,7 +151,7 @@ deps = { Var("libvpx_revision"), "src/third_party/ppapi": - "http://ppapi.googlecode.com/svn/trunk@48", + "http://ppapi.googlecode.com/svn/trunk@50", } diff --git a/webkit/glue/plugins/pepper_plugin_instance.cc b/webkit/glue/plugins/pepper_plugin_instance.cc index 13fd302..15bff8c 100644 --- a/webkit/glue/plugins/pepper_plugin_instance.cc +++ b/webkit/glue/plugins/pepper_plugin_instance.cc @@ -264,6 +264,10 @@ bool PluginInstance::HandleInputEvent(const WebKit::WebInputEvent& event, return instance_interface_->HandleEvent(GetPPInstance(), &pp_event); } +PP_Var PluginInstance::GetInstanceObject() { + return instance_interface_->GetInstanceObject(GetPPInstance()); +} + void PluginInstance::ViewChanged(const gfx::Rect& position, const gfx::Rect& clip) { PP_Rect pp_position, pp_clip; diff --git a/webkit/glue/plugins/pepper_plugin_instance.h b/webkit/glue/plugins/pepper_plugin_instance.h index 3286928..3b045d4 100644 --- a/webkit/glue/plugins/pepper_plugin_instance.h +++ b/webkit/glue/plugins/pepper_plugin_instance.h @@ -67,6 +67,7 @@ class PluginInstance : public base::RefCounted<PluginInstance> { const std::vector<std::string>& arg_values); bool HandleInputEvent(const WebKit::WebInputEvent& event, WebKit::WebCursorInfo* cursor_info); + PP_Var GetInstanceObject(); void ViewChanged(const gfx::Rect& position, const gfx::Rect& clip); private: diff --git a/webkit/glue/plugins/pepper_plugin_module.cc b/webkit/glue/plugins/pepper_plugin_module.cc index 37c090c..261f2e5 100644 --- a/webkit/glue/plugins/pepper_plugin_module.cc +++ b/webkit/glue/plugins/pepper_plugin_module.cc @@ -6,8 +6,10 @@ #include <set> +#include "base/message_loop_proxy.h" #include "base/logging.h" #include "base/scoped_ptr.h" +#include "base/time.h" #include "third_party/ppapi/c/ppb_core.h" #include "third_party/ppapi/c/ppb_device_context_2d.h" #include "third_party/ppapi/c/ppb_image_data.h" @@ -40,6 +42,12 @@ PluginModuleSet* GetLivePluginSet() { return &live_plugin_libs; } +base::MessageLoopProxy* GetMainThreadMessageLoop() { + static scoped_refptr<base::MessageLoopProxy> proxy( + base::MessageLoopProxy::CreateForCurrentThread()); + return proxy.get(); +} + // PPB_Core -------------------------------------------------------------------- void AddRefResource(PP_Resource resource) { @@ -60,9 +68,32 @@ void ReleaseResource(PP_Resource resource) { res->Release(); } +void* MemAlloc(size_t num_bytes) { + return malloc(num_bytes); +} + +void MemFree(void* ptr) { + free(ptr); +} + +double GetTime() { + return base::Time::Now().ToDoubleT(); +} + +void CallOnMainThread(int delay_in_msec, void (*func)(void*), void* context) { + GetMainThreadMessageLoop()->PostDelayedTask( + FROM_HERE, + NewRunnableFunction(func, context), + delay_in_msec); +} + const PPB_Core core_interface = { &AddRefResource, &ReleaseResource, + &MemAlloc, + &MemFree, + &GetTime, + &CallOnMainThread }; // GetInterface ---------------------------------------------------------------- @@ -88,6 +119,7 @@ PluginModule::PluginModule(const FilePath& filename) initialized_(false), library_(0), ppp_get_interface_(NULL) { + GetMainThreadMessageLoop(); // Initialize the main thread message loop. GetLivePluginSet()->insert(this); } diff --git a/webkit/glue/plugins/pepper_var.cc b/webkit/glue/plugins/pepper_var.cc index 07150d2..68f4439 100644 --- a/webkit/glue/plugins/pepper_var.cc +++ b/webkit/glue/plugins/pepper_var.cc @@ -14,9 +14,6 @@ #include "webkit/glue/plugins/pepper_string.h" #include "v8/include/v8.h" -// Uncomment to enable catching JS exceptions -// #define HAVE_WEBBINDINGS_EXCEPTION_HANDLER 1 - using WebKit::WebBindings; namespace pepper { @@ -32,15 +29,11 @@ PP_Var VarFromUtf8(const char* data, uint32_t len); class TryCatch { public: TryCatch(PP_Var* exception) : exception_(exception) { -#ifdef HAVE_WEBBINDINGS_EXCEPTION_HANDLER WebBindings::pushExceptionHandler(&TryCatch::Catch, this); -#endif } ~TryCatch() { -#ifdef HAVE_WEBBINDINGS_EXCEPTION_HANDLER WebBindings::popExceptionHandler(); -#endif } bool HasException() const { @@ -90,12 +83,6 @@ NPObject* GetNPObjectUnchecked(PP_Var var) { return reinterpret_cast<NPObject*>(var.value.as_id); } -NPObject* GetNPObject(PP_Var var) { - if (var.type != PP_VarType_Object) - return NULL; - return GetNPObjectUnchecked(var); -} - // Returns a PP_Var that corresponds to the given NPVariant. The contents of // the NPVariant will be copied unless the NPVariant corresponds to an object. PP_Var NPVariantToPPVar(const NPVariant* variant) { @@ -417,9 +404,39 @@ bool WrapperClass_RemoveProperty(NPObject* object, NPIdentifier property_name) { bool WrapperClass_Enumerate(NPObject* object, NPIdentifier** values, uint32_t* count) { - // TODO(darin): Implement this method! - WebBindings::setException(object, kUnableToGetAllPropertiesException); - return false; + WrapperObject* wrapper = ToWrapper(object); + + uint32_t property_count = 0; + PP_Var* properties = NULL; + PP_Var exception = PP_MakeVoid(); + wrapper->ppp_class->GetAllPropertyNames(wrapper->ppp_class_data, + &property_count, + &properties, + &exception); + + bool rv; + if (exception.type == PP_VarType_Void) { + rv = true; + if (property_count == 0) { + *values = NULL; + *count = 0; + } else { + *values = static_cast<NPIdentifier*>( + malloc(sizeof(NPIdentifier) * property_count)); + *count = property_count; + for (uint32_t i = 0; i < property_count; ++i) + (*values)[i] = PPVarToNPIdentifier(properties[i]); + } + } else { + rv = false; + ThrowException(object, exception); + Release(exception); + } + + for (uint32_t i = 0; i < property_count; ++i) + Release(properties[i]); + free(properties); + return rv; } bool WrapperClass_Construct(NPObject* object, const NPVariant* argv, @@ -591,12 +608,35 @@ void GetAllPropertyNames(PP_Var var, uint32_t* property_count, PP_Var** properties, PP_Var* exception) { + *properties = NULL; + *property_count = 0; + TryCatch try_catch(exception); if (try_catch.HasException()) return; - // TODO(darin): Implement this method! - try_catch.SetException(kUnableToGetAllPropertiesException); + NPObject* object = GetNPObject(var); + if (!object) { + try_catch.SetException(kInvalidObjectException); + return; + } + + NPIdentifier* identifiers = NULL; + uint32_t count = 0; + if (!WebBindings::enumerate(NULL, object, &identifiers, &count)) { + if (!try_catch.HasException()) + try_catch.SetException(kUnableToGetAllPropertiesException); + return; + } + + if (count == 0) + return; + + *property_count = count; + *properties = static_cast<PP_Var*>(malloc(sizeof(PP_Var) * count)); + for (uint32_t i = 0; i < count; ++i) + (*properties)[i] = NPIdentifierToPPVar(identifiers[i]); + free(identifiers); } void SetProperty(PP_Var var, @@ -799,4 +839,10 @@ PP_Var NPObjectToPPVar(NPObject* object) { return ret; } +NPObject* GetNPObject(PP_Var var) { + if (var.type != PP_VarType_Object) + return NULL; + return GetNPObjectUnchecked(var); +} + } // namespace pepper diff --git a/webkit/glue/plugins/pepper_var.h b/webkit/glue/plugins/pepper_var.h index 4c5c221..2d0c2e4 100644 --- a/webkit/glue/plugins/pepper_var.h +++ b/webkit/glue/plugins/pepper_var.h @@ -22,6 +22,11 @@ const PPB_Var* GetVarInterface(); // function multiple times given the same NPObject results in the same PP_Var. PP_Var NPObjectToPPVar(NPObject* object); +// Returns the NPObject corresponding to the PP_Var. This pointer has not been +// retained, so you should not call WebBindings::releaseObject unless you first +// call WebBindings::retainObject. +NPObject* GetNPObject(PP_Var var); + } // namespace pepper #endif // WEBKIT_GLUE_PLUGINS_PEPPER_VAR_H_ diff --git a/webkit/glue/plugins/pepper_webplugin_impl.cc b/webkit/glue/plugins/pepper_webplugin_impl.cc index de83339..638149e 100644 --- a/webkit/glue/plugins/pepper_webplugin_impl.cc +++ b/webkit/glue/plugins/pepper_webplugin_impl.cc @@ -6,10 +6,12 @@ #include "base/file_path.h" #include "base/message_loop.h" +#include "third_party/ppapi/c/pp_var.h" #include "third_party/WebKit/WebKit/chromium/public/WebPluginParams.h" #include "third_party/WebKit/WebKit/chromium/public/WebRect.h" #include "webkit/glue/plugins/pepper_plugin_instance.h" #include "webkit/glue/plugins/pepper_plugin_module.h" +#include "webkit/glue/plugins/pepper_var.h" using WebKit::WebCanvas; using WebKit::WebPluginContainer; @@ -69,8 +71,7 @@ void WebPluginImpl::destroy() { } NPObject* WebPluginImpl::scriptableObject() { - // TODO(brettw): implement getting this from the plugin instance. - return NULL; + return GetNPObject(instance_->GetInstanceObject()); } void WebPluginImpl::paint(WebCanvas* canvas, const WebRect& rect) { |