Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(292)

Unified Diff: webkit/glue/plugins/pepper_var.cc

Issue 3358006: Revert 58328 - Pull new PPAPI, reland 58319 and 58321.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 10 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webkit/glue/plugins/pepper_var.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webkit/glue/plugins/pepper_var.cc
===================================================================
--- webkit/glue/plugins/pepper_var.cc (revision 58353)
+++ webkit/glue/plugins/pepper_var.cc (working copy)
@@ -24,6 +24,38 @@
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 @@
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 @@
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 @@
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
« no previous file with comments | « webkit/glue/plugins/pepper_var.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698