summaryrefslogtreecommitdiffstats
path: root/webkit
diff options
context:
space:
mode:
authorbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-09-02 05:19:55 +0000
committerbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-09-02 05:19:55 +0000
commita11d8fb8c2305aee8bec5babc4939f386fecd274 (patch)
treee7f3ae9fb1f7af40814fe3519429020acccd83aa /webkit
parent0f6ece87ab03c4ef89bce8cb7877aed3501cf6b5 (diff)
downloadchromium_src-a11d8fb8c2305aee8bec5babc4939f386fecd274.zip
chromium_src-a11d8fb8c2305aee8bec5babc4939f386fecd274.tar.gz
chromium_src-a11d8fb8c2305aee8bec5babc4939f386fecd274.tar.bz2
Revert 58321 - Implement ExecuteScript on an instance, add support for running the instance
tests. TEST=unit test in PPAPI BUG=52926 Review URL: http://codereview.chromium.org/3226020 TBR=brettw@chromium.org Review URL: http://codereview.chromium.org/3353007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@58322 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-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
4 files changed, 56 insertions, 126 deletions
diff --git a/webkit/glue/plugins/pepper_plugin_instance.cc b/webkit/glue/plugins/pepper_plugin_instance.cc
index 02dc515..9b5f10e 100644
--- a/webkit/glue/plugins/pepper_plugin_instance.cc
+++ b/webkit/glue/plugins/pepper_plugin_instance.cc
@@ -33,7 +33,6 @@
#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"
@@ -51,7 +50,6 @@
#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;
@@ -162,21 +160,11 @@ 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,
@@ -338,44 +326,6 @@ 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 1260beb8..d8663ea 100644
--- a/webkit/glue/plugins/pepper_plugin_instance.h
+++ b/webkit/glue/plugins/pepper_plugin_instance.h
@@ -93,7 +93,6 @@ 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 f34ac6d..e578523 100644
--- a/webkit/glue/plugins/pepper_var.cc
+++ b/webkit/glue/plugins/pepper_var.cc
@@ -24,6 +24,38 @@ 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";
@@ -46,6 +78,30 @@ 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) {
@@ -789,29 +845,6 @@ 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;
@@ -829,28 +862,4 @@ 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 a678d4d..58aaa7d 100644
--- a/webkit/glue/plugins/pepper_var.h
+++ b/webkit/glue/plugins/pepper_var.h
@@ -26,10 +26,6 @@ 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
@@ -46,30 +42,6 @@ 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_