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

Side by Side Diff: content/renderer/pepper/pepper_try_catch.cc

Issue 1113783002: Use Local instead of Handle in src/content/* (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/renderer/pepper/pepper_try_catch.h" 5 #include "content/renderer/pepper/pepper_try_catch.h"
6 6
7 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" 7 #include "content/renderer/pepper/pepper_plugin_instance_impl.h"
8 #include "content/renderer/pepper/v8_var_converter.h" 8 #include "content/renderer/pepper/v8_var_converter.h"
9 #include "gin/converter.h" 9 #include "gin/converter.h"
10 #include "ppapi/shared_impl/ppapi_globals.h" 10 #include "ppapi/shared_impl/ppapi_globals.h"
11 #include "ppapi/shared_impl/var_tracker.h" 11 #include "ppapi/shared_impl/var_tracker.h"
12 12
13 namespace content { 13 namespace content {
14 14
15 namespace { 15 namespace {
16 16
17 const char kConversionException[] = 17 const char kConversionException[] =
18 "Error: Failed conversion between PP_Var and V8 value"; 18 "Error: Failed conversion between PP_Var and V8 value";
19 const char kInvalidException[] = "Error: An invalid exception was thrown."; 19 const char kInvalidException[] = "Error: An invalid exception was thrown.";
20 20
21 } // namespace 21 } // namespace
22 22
23 PepperTryCatch::PepperTryCatch(PepperPluginInstanceImpl* instance, 23 PepperTryCatch::PepperTryCatch(PepperPluginInstanceImpl* instance,
24 V8VarConverter* var_converter) 24 V8VarConverter* var_converter)
25 : instance_(instance), var_converter_(var_converter) {} 25 : instance_(instance), var_converter_(var_converter) {}
26 26
27 PepperTryCatch::~PepperTryCatch() {} 27 PepperTryCatch::~PepperTryCatch() {}
28 28
29 v8::Handle<v8::Value> PepperTryCatch::ToV8(PP_Var var) { 29 v8::Local<v8::Value> PepperTryCatch::ToV8(PP_Var var) {
30 if (HasException()) { 30 if (HasException()) {
31 SetException(kConversionException); 31 SetException(kConversionException);
32 return v8::Handle<v8::Value>(); 32 return v8::Local<v8::Value>();
33 } 33 }
34 34
35 v8::Handle<v8::Value> result; 35 v8::Local<v8::Value> result;
36 bool success = var_converter_->ToV8Value(var, GetContext(), &result); 36 bool success = var_converter_->ToV8Value(var, GetContext(), &result);
37 if (!success) { 37 if (!success) {
38 SetException(kConversionException); 38 SetException(kConversionException);
39 return v8::Handle<v8::Value>(); 39 return v8::Local<v8::Value>();
40 } 40 }
41 return result; 41 return result;
42 } 42 }
43 43
44 ppapi::ScopedPPVar PepperTryCatch::FromV8(v8::Handle<v8::Value> v8_value) { 44 ppapi::ScopedPPVar PepperTryCatch::FromV8(v8::Local<v8::Value> v8_value) {
45 if (HasException() || v8_value.IsEmpty()) { 45 if (HasException() || v8_value.IsEmpty()) {
46 SetException(kConversionException); 46 SetException(kConversionException);
47 return ppapi::ScopedPPVar(); 47 return ppapi::ScopedPPVar();
48 } 48 }
49 ppapi::ScopedPPVar result; 49 ppapi::ScopedPPVar result;
50 bool success = 50 bool success =
51 var_converter_->FromV8ValueSync(v8_value, GetContext(), &result); 51 var_converter_->FromV8ValueSync(v8_value, GetContext(), &result);
52 if (!success) { 52 if (!success) {
53 SetException(kConversionException); 53 SetException(kConversionException);
54 return ppapi::ScopedPPVar(); 54 return ppapi::ScopedPPVar();
(...skipping 17 matching lines...) Expand all
72 } 72 }
73 73
74 PepperTryCatchV8::~PepperTryCatchV8() { 74 PepperTryCatchV8::~PepperTryCatchV8() {
75 ppapi::PpapiGlobals::Get()->GetVarTracker()->ReleaseVar(exception_); 75 ppapi::PpapiGlobals::Get()->GetVarTracker()->ReleaseVar(exception_);
76 } 76 }
77 77
78 bool PepperTryCatchV8::HasException() { 78 bool PepperTryCatchV8::HasException() {
79 return GetContext().IsEmpty() || exception_.type != PP_VARTYPE_UNDEFINED; 79 return GetContext().IsEmpty() || exception_.type != PP_VARTYPE_UNDEFINED;
80 } 80 }
81 81
82 v8::Handle<v8::Context> PepperTryCatchV8::GetContext() { 82 v8::Local<v8::Context> PepperTryCatchV8::GetContext() {
83 // When calling from JS into the plugin always use the current context. 83 // When calling from JS into the plugin always use the current context.
84 return instance_->GetIsolate()->GetCurrentContext(); 84 return instance_->GetIsolate()->GetCurrentContext();
85 } 85 }
86 86
87 bool PepperTryCatchV8::ThrowException() { 87 bool PepperTryCatchV8::ThrowException() {
88 if (!HasException()) 88 if (!HasException())
89 return false; 89 return false;
90 90
91 // If there is no context then we have an exception but we don't try to throw 91 // If there is no context then we have an exception but we don't try to throw
92 // it into v8. 92 // it into v8.
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 157
158 if (!exception_message.empty()) { 158 if (!exception_message.empty()) {
159 exception_is_set_ = true; 159 exception_is_set_ = true;
160 if (exception_) 160 if (exception_)
161 *exception_ = ppapi::StringVar::StringToPPVar(exception_message); 161 *exception_ = ppapi::StringVar::StringToPPVar(exception_message);
162 } 162 }
163 163
164 return exception_is_set_; 164 return exception_is_set_;
165 } 165 }
166 166
167 v8::Handle<v8::Context> PepperTryCatchVar::GetContext() { 167 v8::Local<v8::Context> PepperTryCatchVar::GetContext() {
168 return context_; 168 return context_;
169 } 169 }
170 170
171 void PepperTryCatchVar::SetException(const char* message) { 171 void PepperTryCatchVar::SetException(const char* message) {
172 if (exception_is_set_) 172 if (exception_is_set_)
173 return; 173 return;
174 174
175 if (exception_) 175 if (exception_)
176 *exception_ = ppapi::StringVar::StringToPPVar(message, strlen(message)); 176 *exception_ = ppapi::StringVar::StringToPPVar(message, strlen(message));
177 exception_is_set_ = true; 177 exception_is_set_ = true;
178 } 178 }
179 179
180 } // namespace content 180 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/pepper/pepper_try_catch.h ('k') | content/renderer/pepper/pepper_webplugin_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698