summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--DEPS2
-rw-r--r--chrome/test/ui/ppapi_uitest.cc4
-rw-r--r--remoting/client/plugin/pepper_entrypoints.cc2
-rw-r--r--webkit/glue/plugins/pepper_plugin_instance.cc50
-rw-r--r--webkit/glue/plugins/pepper_plugin_instance.h1
-rw-r--r--webkit/glue/plugins/pepper_var.cc103
-rw-r--r--webkit/glue/plugins/pepper_var.h28
7 files changed, 132 insertions, 58 deletions
diff --git a/DEPS b/DEPS
index 0691918..00c2ce2 100644
--- a/DEPS
+++ b/DEPS
@@ -166,7 +166,7 @@ deps = {
Var("libvpx_revision"),
"src/third_party/ppapi":
- "http://ppapi.googlecode.com/svn/trunk@226",
+ "http://ppapi.googlecode.com/svn/trunk@233",
"src/third_party/libjingle/source":
"http://libjingle.googlecode.com/svn/branches/nextsnap@" +
diff --git a/chrome/test/ui/ppapi_uitest.cc b/chrome/test/ui/ppapi_uitest.cc
index 5099815..efe0f70 100644
--- a/chrome/test/ui/ppapi_uitest.cc
+++ b/chrome/test/ui/ppapi_uitest.cc
@@ -87,6 +87,10 @@ class PPAPITest : public UITest {
}
};
+TEST_F(PPAPITest, FAILS_Instance) {
+ RunTest("Instance");
+}
+
// http://crbug.com/54150
TEST_F(PPAPITest, FLAKY_Graphics2D) {
RunTest("Graphics2D");
diff --git a/remoting/client/plugin/pepper_entrypoints.cc b/remoting/client/plugin/pepper_entrypoints.cc
index 6bcc814..77307b3 100644
--- a/remoting/client/plugin/pepper_entrypoints.cc
+++ b/remoting/client/plugin/pepper_entrypoints.cc
@@ -56,7 +56,7 @@ void PPP_ShutdownModule() {
const void* PPP_GetInterface(const char* interface_name) {
if (!pp::Module::Get())
return NULL;
- return pp::Module::Get()->GetInstanceInterface(interface_name);
+ return pp::Module::Get()->GetPluginInterface(interface_name);
}
} // namespace remoting
diff --git a/webkit/glue/plugins/pepper_plugin_instance.cc b/webkit/glue/plugins/pepper_plugin_instance.cc
index 9b5f10e..02dc515 100644
--- a/webkit/glue/plugins/pepper_plugin_instance.cc
+++ b/webkit/glue/plugins/pepper_plugin_instance.cc
@@ -33,6 +33,7 @@
#include "third_party/ppapi/c/ppb_core.h"
#include "third_party/ppapi/c/ppb_instance.h"
#include "third_party/ppapi/c/ppp_instance.h"
+#include "third_party/WebKit/WebKit/chromium/public/WebBindings.h"
#include "third_party/WebKit/WebKit/chromium/public/WebCursorInfo.h"
#include "third_party/WebKit/WebKit/chromium/public/WebDocument.h"
#include "third_party/WebKit/WebKit/chromium/public/WebElement.h"
@@ -50,6 +51,7 @@
#include "webkit/glue/plugins/pepper_url_loader.h"
#include "webkit/glue/plugins/pepper_var.h"
+using WebKit::WebBindings;
using WebKit::WebCanvas;
using WebKit::WebCursorInfo;
using WebKit::WebFrame;
@@ -160,11 +162,21 @@ bool IsFullFrame(PP_Instance instance_id) {
return instance->full_frame();
}
+PP_Var ExecuteScript(PP_Instance instance_id,
+ PP_Var script,
+ PP_Var* exception) {
+ PluginInstance* instance = PluginInstance::FromPPInstance(instance_id);
+ if (!instance)
+ return PP_MakeVoid();
+ return instance->ExecuteScript(script, exception);
+}
+
const PPB_Instance ppb_instance = {
&GetWindowObject,
&GetOwnerElementObject,
&BindGraphics,
&IsFullFrame,
+ &ExecuteScript,
};
void NumberOfFindResultsChanged(PP_Instance instance_id,
@@ -326,6 +338,44 @@ bool PluginInstance::SetCursor(PP_CursorType_Dev type) {
return true;
}
+PP_Var PluginInstance::ExecuteScript(PP_Var script, PP_Var* exception) {
+ TryCatch try_catch(exception);
+ if (try_catch.HasException())
+ return PP_MakeVoid();
+
+ // Convert the script into an inconvenient NPString object.
+ String* script_string = GetString(script);
+ if (!script_string) {
+ try_catch.SetException("Script param to ExecuteScript must be a string.");
+ return PP_MakeVoid();
+ }
+ NPString np_script;
+ np_script.UTF8Characters = script_string->value().c_str();
+ np_script.UTF8Length = script_string->value().length();
+
+ // Get the current frame to pass to the evaluate function.
+ WebFrame* frame = container_->element().document().frame();
+ if (!frame) {
+ try_catch.SetException("No frame to execute script in.");
+ return PP_MakeVoid();
+ }
+
+ NPVariant result;
+ bool ok = WebBindings::evaluate(NULL, frame->windowObject(), &np_script,
+ &result);
+ if (!ok) {
+ // TODO(brettw) bug 54011: The TryCatch isn't working properly and
+ // doesn't actually catch this exception.
+ try_catch.SetException("Exception caught");
+ WebBindings::releaseVariantValue(&result);
+ return PP_MakeVoid();
+ }
+
+ PP_Var ret = NPVariantToPPVar(&result);
+ WebBindings::releaseVariantValue(&result);
+ return ret;
+}
+
void PluginInstance::Delete() {
instance_interface_->Delete(GetPPInstance());
diff --git a/webkit/glue/plugins/pepper_plugin_instance.h b/webkit/glue/plugins/pepper_plugin_instance.h
index d8663ea..1260beb8 100644
--- a/webkit/glue/plugins/pepper_plugin_instance.h
+++ b/webkit/glue/plugins/pepper_plugin_instance.h
@@ -93,6 +93,7 @@ class PluginInstance : public base::RefCounted<PluginInstance> {
bool BindGraphics(PP_Resource device_id);
bool full_frame() const { return full_frame_; }
bool SetCursor(PP_CursorType_Dev type);
+ PP_Var ExecuteScript(PP_Var script, PP_Var* exception);
// PPP_Instance pass-through.
void Delete();
diff --git a/webkit/glue/plugins/pepper_var.cc b/webkit/glue/plugins/pepper_var.cc
index e578523..f34ac6d 100644
--- a/webkit/glue/plugins/pepper_var.cc
+++ b/webkit/glue/plugins/pepper_var.cc
@@ -24,38 +24,6 @@ namespace {
void Release(PP_Var var);
PP_Var VarFromUtf8(const char* data, uint32_t len);
-// ---------------------------------------------------------------------------
-// Exceptions
-
-class TryCatch {
- public:
- TryCatch(PP_Var* exception) : exception_(exception) {
- WebBindings::pushExceptionHandler(&TryCatch::Catch, this);
- }
-
- ~TryCatch() {
- WebBindings::popExceptionHandler();
- }
-
- bool HasException() const {
- return exception_ && exception_->type != PP_VARTYPE_VOID;
- }
-
- void SetException(const char* message) {
- DCHECK(!HasException());
- if (exception_)
- *exception_ = VarFromUtf8(message, strlen(message));
- }
-
- private:
- static void Catch(void* self, const NPUTF8* message) {
- static_cast<TryCatch*>(self)->SetException(message);
- }
-
- // May be null if the consumer isn't interesting in catching exceptions.
- PP_Var* exception_;
-};
-
const char kInvalidObjectException[] = "Error: Invalid object";
const char kInvalidPropertyException[] = "Error: Invalid property";
const char kUnableToGetPropertyException[] = "Error: Unable to get property";
@@ -78,30 +46,6 @@ NPObject* GetNPObjectUnchecked(PP_Var var) {
return reinterpret_cast<NPObject*>(var.value.as_id);
}
-// 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) {
- switch (variant->type) {
- case NPVariantType_Void:
- return PP_MakeVoid();
- case NPVariantType_Null:
- return PP_MakeNull();
- case NPVariantType_Bool:
- return PP_MakeBool(NPVARIANT_TO_BOOLEAN(*variant));
- case NPVariantType_Int32:
- return PP_MakeInt32(NPVARIANT_TO_INT32(*variant));
- case NPVariantType_Double:
- return PP_MakeDouble(NPVARIANT_TO_DOUBLE(*variant));
- case NPVariantType_String:
- return VarFromUtf8(NPVARIANT_TO_STRING(*variant).UTF8Characters,
- NPVARIANT_TO_STRING(*variant).UTF8Length);
- case NPVariantType_Object:
- return NPObjectToPPVar(NPVARIANT_TO_OBJECT(*variant));
- }
- NOTREACHED();
- return PP_MakeVoid();
-}
-
// Returns a NPVariant that corresponds to the given PP_Var. The contents of
// the PP_Var will be copied unless the PP_Var corresponds to an object.
NPVariant PPVarToNPVariant(PP_Var var) {
@@ -845,6 +789,29 @@ PP_Var NPObjectToPPVar(NPObject* object) {
return ret;
}
+PP_Var NPVariantToPPVar(const NPVariant* variant) {
+ switch (variant->type) {
+ case NPVariantType_Void:
+ return PP_MakeVoid();
+ case NPVariantType_Null:
+ return PP_MakeNull();
+ case NPVariantType_Bool:
+ return PP_MakeBool(NPVARIANT_TO_BOOLEAN(*variant));
+ case NPVariantType_Int32:
+ return PP_MakeInt32(NPVARIANT_TO_INT32(*variant));
+ case NPVariantType_Double:
+ return PP_MakeDouble(NPVARIANT_TO_DOUBLE(*variant));
+ case NPVariantType_String:
+ return VarFromUtf8(NPVARIANT_TO_STRING(*variant).UTF8Characters,
+ NPVARIANT_TO_STRING(*variant).UTF8Length);
+ case NPVariantType_Object:
+ return NPObjectToPPVar(NPVARIANT_TO_OBJECT(*variant));
+ }
+ NOTREACHED();
+ return PP_MakeVoid();
+}
+
+
NPObject* GetNPObject(PP_Var var) {
if (var.type != PP_VARTYPE_OBJECT)
return NULL;
@@ -862,4 +829,28 @@ String* GetString(PP_Var var) {
return GetStringUnchecked(var);
}
+TryCatch::TryCatch(PP_Var* exception) : exception_(exception) {
+ WebBindings::pushExceptionHandler(&TryCatch::Catch, this);
+}
+
+TryCatch::~TryCatch() {
+ WebBindings::popExceptionHandler();
+}
+
+bool TryCatch::HasException() const {
+ return exception_ && exception_->type != PP_VARTYPE_VOID;
+}
+
+void TryCatch::SetException(const char* message) {
+ DCHECK(!HasException());
+ if (exception_)
+ *exception_ = VarFromUtf8(message, strlen(message));
+}
+
+// static
+void TryCatch::Catch(void* self, const char* message) {
+ static_cast<TryCatch*>(self)->SetException(message);
+}
+
+
} // namespace pepper
diff --git a/webkit/glue/plugins/pepper_var.h b/webkit/glue/plugins/pepper_var.h
index 58aaa7d..a678d4d 100644
--- a/webkit/glue/plugins/pepper_var.h
+++ b/webkit/glue/plugins/pepper_var.h
@@ -26,6 +26,10 @@ const PPB_Var* GetVarInterface();
// function multiple times given the same NPObject results in the same PP_Var.
PP_Var NPObjectToPPVar(NPObject* object);
+// 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);
+
// 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. Returns NULL if the PP_Var is not an object
@@ -42,6 +46,30 @@ PP_Var StringToPPVar(const std::string& str);
// a string type.
String* GetString(PP_Var var);
+// Instantiate this object on the stack to catch V8 exceptions and pass them
+// to an optional out parameter supplied by the plugin.
+class TryCatch {
+ public:
+ // The given exception may be NULL if the consumer isn't interested in
+ // catching exceptions. If non-NULL, the given var will be updated if any
+ // exception is thrown (so it must outlive the TryCatch object).
+ TryCatch(PP_Var* exception);
+ ~TryCatch();
+
+ // Returns true is an exception has been thrown. This can be true immediately
+ // after construction if the var passed to the constructor is non-void.
+ bool HasException() const;
+
+ // Sets the given exception.
+ void SetException(const char* message);
+
+ private:
+ static void Catch(void* self, const char* message);
+
+ // May be null if the consumer isn't interesting in catching exceptions.
+ PP_Var* exception_;
+};
+
} // namespace pepper
#endif // WEBKIT_GLUE_PLUGINS_PEPPER_VAR_H_