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 |