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

Side by Side Diff: extensions/renderer/script_context.cc

Issue 983793003: Replace extensions::ScopedPersistent with v8::UniquePersistent. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 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
« no previous file with comments | « extensions/renderer/script_context.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "extensions/renderer/script_context.h" 5 #include "extensions/renderer/script_context.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/strings/string_split.h" 9 #include "base/strings/string_split.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 private: 73 private:
74 ScriptContext* context_; 74 ScriptContext* context_;
75 }; 75 };
76 76
77 ScriptContext::ScriptContext(const v8::Handle<v8::Context>& v8_context, 77 ScriptContext::ScriptContext(const v8::Handle<v8::Context>& v8_context,
78 blink::WebFrame* web_frame, 78 blink::WebFrame* web_frame,
79 const Extension* extension, 79 const Extension* extension,
80 Feature::Context context_type, 80 Feature::Context context_type,
81 const Extension* effective_extension, 81 const Extension* effective_extension,
82 Feature::Context effective_context_type) 82 Feature::Context effective_context_type)
83 : v8_context_(v8_context), 83 : v8_context_(v8_context->GetIsolate(), v8_context),
84 web_frame_(web_frame), 84 web_frame_(web_frame),
85 extension_(extension), 85 extension_(extension),
86 context_type_(context_type), 86 context_type_(context_type),
87 effective_extension_(effective_extension), 87 effective_extension_(effective_extension),
88 effective_context_type_(effective_context_type), 88 effective_context_type_(effective_context_type),
89 safe_builtins_(this), 89 safe_builtins_(this),
90 isolate_(v8_context->GetIsolate()), 90 isolate_(v8_context->GetIsolate()),
91 url_(web_frame_ ? GetDataSourceURLForFrame(web_frame_) : GURL()), 91 url_(web_frame_ ? GetDataSourceURLForFrame(web_frame_) : GURL()),
92 runner_(new Runner(this)) { 92 runner_(new Runner(this)) {
93 VLOG(1) << "Created context:\n" 93 VLOG(1) << "Created context:\n"
(...skipping 15 matching lines...) Expand all
109 << (effective_extension_.get() ? effective_extension_->id() : ""); 109 << (effective_extension_.get() ? effective_extension_->id() : "");
110 Invalidate(); 110 Invalidate();
111 } 111 }
112 112
113 void ScriptContext::Invalidate() { 113 void ScriptContext::Invalidate() {
114 if (!is_valid()) 114 if (!is_valid())
115 return; 115 return;
116 if (module_system_) 116 if (module_system_)
117 module_system_->Invalidate(); 117 module_system_->Invalidate();
118 web_frame_ = NULL; 118 web_frame_ = NULL;
119 v8_context_.reset(); 119 v8_context_.Reset();
120 runner_.reset(); 120 runner_.reset();
121 } 121 }
122 122
123 const std::string& ScriptContext::GetExtensionID() const { 123 const std::string& ScriptContext::GetExtensionID() const {
124 return extension_.get() ? extension_->id() : base::EmptyString(); 124 return extension_.get() ? extension_->id() : base::EmptyString();
125 } 125 }
126 126
127 content::RenderView* ScriptContext::GetRenderView() const { 127 content::RenderView* ScriptContext::GetRenderView() const {
128 if (web_frame_ && web_frame_->view()) 128 if (web_frame_ && web_frame_->view())
129 return content::RenderView::FromWebView(web_frame_->view()); 129 return content::RenderView::FromWebView(web_frame_->view());
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 bool success, 258 bool success,
259 const base::ListValue& response, 259 const base::ListValue& response,
260 const std::string& error) { 260 const std::string& error) {
261 v8::HandleScope handle_scope(isolate()); 261 v8::HandleScope handle_scope(isolate());
262 262
263 scoped_ptr<V8ValueConverter> converter(V8ValueConverter::create()); 263 scoped_ptr<V8ValueConverter> converter(V8ValueConverter::create());
264 v8::Handle<v8::Value> argv[] = { 264 v8::Handle<v8::Value> argv[] = {
265 v8::Integer::New(isolate(), request_id), 265 v8::Integer::New(isolate(), request_id),
266 v8::String::NewFromUtf8(isolate(), name.c_str()), 266 v8::String::NewFromUtf8(isolate(), name.c_str()),
267 v8::Boolean::New(isolate(), success), 267 v8::Boolean::New(isolate(), success),
268 converter->ToV8Value(&response, v8_context_.NewHandle(isolate())), 268 converter->ToV8Value(&response,
269 v8::Local<v8::Context>::New(isolate(), v8_context_)),
269 v8::String::NewFromUtf8(isolate(), error.c_str())}; 270 v8::String::NewFromUtf8(isolate(), error.c_str())};
270 271
271 v8::Handle<v8::Value> retval = module_system()->CallModuleMethod( 272 v8::Handle<v8::Value> retval = module_system()->CallModuleMethod(
272 "sendRequest", "handleResponse", arraysize(argv), argv); 273 "sendRequest", "handleResponse", arraysize(argv), argv);
273 274
274 // In debug, the js will validate the callback parameters and return a 275 // In debug, the js will validate the callback parameters and return a
275 // string if a validation error has occured. 276 // string if a validation error has occured.
276 DCHECK(retval.IsEmpty() || retval->IsUndefined()) 277 DCHECK(retval.IsEmpty() || retval->IsUndefined())
277 << *v8::String::Utf8Value(retval); 278 << *v8::String::Utf8Value(retval);
278 } 279 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 v8::Handle<v8::Value> argv[]) { 311 v8::Handle<v8::Value> argv[]) {
311 return context_->CallFunction(function, argc, argv); 312 return context_->CallFunction(function, argc, argv);
312 } 313 }
313 314
314 gin::ContextHolder* ScriptContext::Runner::GetContextHolder() { 315 gin::ContextHolder* ScriptContext::Runner::GetContextHolder() {
315 v8::HandleScope handle_scope(context_->isolate()); 316 v8::HandleScope handle_scope(context_->isolate());
316 return gin::PerContextData::From(context_->v8_context())->context_holder(); 317 return gin::PerContextData::From(context_->v8_context())->context_holder();
317 } 318 }
318 319
319 } // namespace extensions 320 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/renderer/script_context.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698