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

Unified Diff: content/renderer/pepper/pepper_try_catch.cc

Issue 459553003: Replace NPObject usage in ppapi with gin (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 3 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 | « content/renderer/pepper/pepper_try_catch.h ('k') | content/renderer/pepper/pepper_webplugin_impl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/renderer/pepper/pepper_try_catch.cc
diff --git a/content/renderer/pepper/pepper_try_catch.cc b/content/renderer/pepper/pepper_try_catch.cc
index f5d8b3bf47b045861f67de5e38c85e9bb6624085..0d1aacc97a884a86222b632deebf0bb0ad620c3b 100644
--- a/content/renderer/pepper/pepper_try_catch.cc
+++ b/content/renderer/pepper/pepper_try_catch.cc
@@ -5,7 +5,6 @@
#include "content/renderer/pepper/pepper_try_catch.h"
#include "content/renderer/pepper/pepper_plugin_instance_impl.h"
-#include "content/renderer/pepper/v8_var_converter.h"
#include "gin/converter.h"
#include "ppapi/shared_impl/ppapi_globals.h"
#include "ppapi/shared_impl/var_tracker.h"
@@ -21,7 +20,7 @@ const char kInvalidException[] = "Error: An invalid exception was thrown.";
} // namespace
PepperTryCatch::PepperTryCatch(PepperPluginInstanceImpl* instance,
- bool convert_objects)
+ V8VarConverter::AllowObjectVars convert_objects)
: instance_(instance),
convert_objects_(convert_objects) {}
@@ -32,6 +31,11 @@ v8::Handle<v8::Context> PepperTryCatch::GetContext() {
}
v8::Handle<v8::Value> PepperTryCatch::ToV8(PP_Var var) {
+ if (HasException()) {
+ SetException(kConversionException);
+ return v8::Handle<v8::Value>();
+ }
+
V8VarConverter converter(instance_->pp_instance(), convert_objects_);
v8::Handle<v8::Value> result;
bool success = converter.ToV8Value(var, GetContext(), &result);
@@ -43,7 +47,7 @@ v8::Handle<v8::Value> PepperTryCatch::ToV8(PP_Var var) {
}
ppapi::ScopedPPVar PepperTryCatch::FromV8(v8::Handle<v8::Value> v8_value) {
- if (v8_value.IsEmpty()) {
+ if (HasException() || v8_value.IsEmpty()) {
SetException(kConversionException);
return ppapi::ScopedPPVar();
}
@@ -57,9 +61,10 @@ ppapi::ScopedPPVar PepperTryCatch::FromV8(v8::Handle<v8::Value> v8_value) {
return result;
}
-PepperTryCatchV8::PepperTryCatchV8(PepperPluginInstanceImpl* instance,
- bool convert_objects,
- v8::Isolate* isolate)
+PepperTryCatchV8::PepperTryCatchV8(
+ PepperPluginInstanceImpl* instance,
+ V8VarConverter::AllowObjectVars convert_objects,
+ v8::Isolate* isolate)
: PepperTryCatch(instance, convert_objects),
exception_(PP_MakeUndefined()) {
// Typically when using PepperTryCatchV8 we are passed an isolate. We verify
@@ -74,13 +79,18 @@ PepperTryCatchV8::~PepperTryCatchV8() {
}
bool PepperTryCatchV8::HasException() {
- return exception_.type != PP_VARTYPE_UNDEFINED;
+ return GetContext().IsEmpty() || exception_.type != PP_VARTYPE_UNDEFINED;
}
bool PepperTryCatchV8::ThrowException() {
if (!HasException())
return false;
+ // If the plugin context is gone, then we have an exception but we don't try
+ // to throw it into v8.
+ if (GetContext().IsEmpty())
+ return true;
+
std::string message(kInvalidException);
ppapi::StringVar* message_var = ppapi::StringVar::FromPPVar(exception_);
if (message_var)
@@ -107,29 +117,39 @@ void PepperTryCatchV8::SetException(const char* message) {
}
PepperTryCatchVar::PepperTryCatchVar(PepperPluginInstanceImpl* instance,
- bool convert_objects,
PP_Var* exception)
- : PepperTryCatch(instance, convert_objects),
+ : PepperTryCatch(instance, V8VarConverter::kAllowObjectVars),
handle_scope_(instance_->GetIsolate()),
exception_(exception),
exception_is_set_(false) {
// We switch to the plugin context.
- GetContext()->Enter();
+ v8::Handle<v8::Context> context = GetContext();
+ if (!context.IsEmpty())
+ context->Enter();
}
PepperTryCatchVar::~PepperTryCatchVar() {
- GetContext()->Exit();
+ v8::Handle<v8::Context> context = GetContext();
+ if (!context.IsEmpty())
+ context->Exit();
}
bool PepperTryCatchVar::HasException() {
- // Check if a v8 exception was caught.
- if (!exception_is_set_ && try_catch_.HasCaught()) {
+ if (exception_is_set_)
+ return true;
+
+ std::string exception_message;
+ if (GetContext().IsEmpty()) {
+ exception_message = "The v8 context has been destroyed.";
+ } else if (try_catch_.HasCaught()) {
v8::String::Utf8Value utf8(try_catch_.Message()->Get());
- if (exception_) {
- *exception_ = ppapi::StringVar::StringToPPVar(
- std::string(*utf8, utf8.length()));
- }
+ exception_message = std::string(*utf8, utf8.length());
+ }
+
+ if (!exception_message.empty()) {
exception_is_set_ = true;
+ if (exception_)
+ *exception_ = ppapi::StringVar::StringToPPVar(exception_message);
}
return exception_is_set_;
« no previous file with comments | « content/renderer/pepper/pepper_try_catch.h ('k') | content/renderer/pepper/pepper_webplugin_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698