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

Side by Side Diff: content/renderer/pepper/v8object_var.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, 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 unified diff | Download patch | Annotate | Revision Log
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/v8object_var.h" 5 #include "content/renderer/pepper/v8object_var.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "content/public/renderer/pepper_plugin_instance.h" 8 #include "content/public/renderer/pepper_plugin_instance.h"
9 #include "content/renderer/pepper/host_globals.h" 9 #include "content/renderer/pepper/host_globals.h"
10 #include "content/renderer/pepper/pepper_plugin_instance_impl.h"
10 #include "ppapi/c/pp_var.h" 11 #include "ppapi/c/pp_var.h"
11 12
12 namespace ppapi { 13 namespace ppapi {
13 14
14 // V8ObjectVar ----------------------------------------------------------------- 15 // V8ObjectVar -----------------------------------------------------------------
15 16
16 V8ObjectVar::V8ObjectVar(PP_Instance instance, 17 V8ObjectVar::V8ObjectVar(PP_Instance instance,
17 v8::Handle<v8::Object> v8_object) 18 v8::Handle<v8::Object> v8_object)
18 : instance_(instance) { 19 : instance_(content::HostGlobals::Get()->GetInstance(instance)) {
19 v8_object_.Reset( 20 v8_object_.Reset(instance_->GetIsolate(), v8_object);
20 content::PepperPluginInstance::Get(instance_)->GetIsolate(), v8_object);
21 content::HostGlobals::Get()->host_var_tracker()->AddV8ObjectVar(this); 21 content::HostGlobals::Get()->host_var_tracker()->AddV8ObjectVar(this);
22 } 22 }
23 23
24 V8ObjectVar::~V8ObjectVar() { 24 V8ObjectVar::~V8ObjectVar() {
25 if (instance_) 25 if (instance_)
26 content::HostGlobals::Get()->host_var_tracker()->RemoveV8ObjectVar(this); 26 content::HostGlobals::Get()->host_var_tracker()->RemoveV8ObjectVar(this);
27 v8_object_.Reset(); 27 v8_object_.Reset();
28 } 28 }
29 29
30 V8ObjectVar* V8ObjectVar::AsV8ObjectVar() { 30 V8ObjectVar* V8ObjectVar::AsV8ObjectVar() {
31 return this; 31 return this;
32 } 32 }
33 33
34 PP_VarType V8ObjectVar::GetType() const { 34 PP_VarType V8ObjectVar::GetType() const {
35 return PP_VARTYPE_OBJECT; 35 return PP_VARTYPE_OBJECT;
36 } 36 }
37 37
38 v8::Local<v8::Object> V8ObjectVar::GetHandle() const { 38 v8::Local<v8::Object> V8ObjectVar::GetHandle() const {
39 content::PepperPluginInstance* instance = 39 if (instance_)
40 content::PepperPluginInstance::Get(instance_); 40 return v8::Local<v8::Object>::New(instance_->GetIsolate(), v8_object_);
41 if (instance)
42 return v8::Local<v8::Object>::New(instance->GetIsolate(), v8_object_);
43 return v8::Local<v8::Object>(); 41 return v8::Local<v8::Object>();
44 } 42 }
45 43
46 void V8ObjectVar::InstanceDeleted() { 44 void V8ObjectVar::InstanceDeleted() {
47 // This is called by the HostVarTracker which will take care of removing us 45 // This is called by the HostVarTracker which will take care of removing us
48 // from its set. 46 // from its set.
49 DCHECK(instance_); 47 DCHECK(instance_);
50 instance_ = 0; 48 instance_ = NULL;
51 } 49 }
52 50
53 // static 51 // static
54 scoped_refptr<V8ObjectVar> V8ObjectVar::FromPPVar(PP_Var var) { 52 scoped_refptr<V8ObjectVar> V8ObjectVar::FromPPVar(PP_Var var) {
55 if (var.type != PP_VARTYPE_OBJECT) 53 if (var.type != PP_VARTYPE_OBJECT)
56 return scoped_refptr<V8ObjectVar>(NULL); 54 return scoped_refptr<V8ObjectVar>(NULL);
57 scoped_refptr<Var> var_object( 55 scoped_refptr<Var> var_object(
58 PpapiGlobals::Get()->GetVarTracker()->GetVar(var)); 56 PpapiGlobals::Get()->GetVarTracker()->GetVar(var));
59 if (!var_object.get()) 57 if (!var_object.get())
60 return scoped_refptr<V8ObjectVar>(); 58 return scoped_refptr<V8ObjectVar>();
61 return scoped_refptr<V8ObjectVar>(var_object->AsV8ObjectVar()); 59 return scoped_refptr<V8ObjectVar>(var_object->AsV8ObjectVar());
62 } 60 }
63 61
64 } // namespace ppapi 62 } // namespace ppapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698