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

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

Issue 1136953017: Add fallback mechanism to release Extension ports if the JS context has been destroyed. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comments 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
« 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 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 return NULL; 169 return NULL;
170 } 170 }
171 171
172 content::RenderFrame* ScriptContext::GetRenderFrame() const { 172 content::RenderFrame* ScriptContext::GetRenderFrame() const {
173 if (web_frame_) 173 if (web_frame_)
174 return content::RenderFrame::FromWebFrame(web_frame_); 174 return content::RenderFrame::FromWebFrame(web_frame_);
175 return NULL; 175 return NULL;
176 } 176 }
177 177
178 v8::Local<v8::Value> ScriptContext::CallFunction( 178 v8::Local<v8::Value> ScriptContext::CallFunction(
179 v8::Local<v8::Function> function, 179 const v8::Local<v8::Function>& function,
180 int argc, 180 int argc,
181 v8::Local<v8::Value> argv[]) const { 181 v8::Local<v8::Value> argv[]) const {
182 v8::EscapableHandleScope handle_scope(isolate()); 182 v8::EscapableHandleScope handle_scope(isolate());
183 v8::Context::Scope scope(v8_context()); 183 v8::Context::Scope scope(v8_context());
184 184
185 blink::WebScopedMicrotaskSuppression suppression; 185 blink::WebScopedMicrotaskSuppression suppression;
186 if (!is_valid_) { 186 if (!is_valid_) {
187 return handle_scope.Escape( 187 return handle_scope.Escape(
188 v8::Local<v8::Primitive>(v8::Undefined(isolate()))); 188 v8::Local<v8::Primitive>(v8::Undefined(isolate())));
189 } 189 }
190 190
191 v8::Local<v8::Object> global = v8_context()->Global(); 191 v8::Local<v8::Object> global = v8_context()->Global();
192 if (!web_frame_) 192 if (!web_frame_)
193 return handle_scope.Escape(function->Call(global, argc, argv)); 193 return handle_scope.Escape(function->Call(global, argc, argv));
194 return handle_scope.Escape( 194 return handle_scope.Escape(
195 v8::Local<v8::Value>(web_frame_->callFunctionEvenIfScriptDisabled( 195 v8::Local<v8::Value>(web_frame_->callFunctionEvenIfScriptDisabled(
196 function, global, argc, argv))); 196 function, global, argc, argv)));
197 } 197 }
198 198
199 v8::Local<v8::Value> ScriptContext::CallFunction(
200 const v8::Local<v8::Function>& function) const {
201 return CallFunction(function, 0, nullptr);
202 }
203
199 Feature::Availability ScriptContext::GetAvailability( 204 Feature::Availability ScriptContext::GetAvailability(
200 const std::string& api_name) { 205 const std::string& api_name) {
201 // Hack: Hosted apps should have the availability of messaging APIs based on 206 // Hack: Hosted apps should have the availability of messaging APIs based on
202 // the URL of the page (which might have access depending on some extension 207 // the URL of the page (which might have access depending on some extension
203 // with externally_connectable), not whether the app has access to messaging 208 // with externally_connectable), not whether the app has access to messaging
204 // (which it won't). 209 // (which it won't).
205 const Extension* extension = extension_.get(); 210 const Extension* extension = extension_.get();
206 if (extension && extension->is_hosted_app() && 211 if (extension && extension->is_hosted_app() &&
207 (api_name == "runtime.connect" || api_name == "runtime.sendMessage")) { 212 (api_name == "runtime.connect" || api_name == "runtime.sendMessage")) {
208 extension = NULL; 213 extension = NULL;
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 v8::Local<v8::Value> argv[]) { 388 v8::Local<v8::Value> argv[]) {
384 return context_->CallFunction(function, argc, argv); 389 return context_->CallFunction(function, argc, argv);
385 } 390 }
386 391
387 gin::ContextHolder* ScriptContext::Runner::GetContextHolder() { 392 gin::ContextHolder* ScriptContext::Runner::GetContextHolder() {
388 v8::HandleScope handle_scope(context_->isolate()); 393 v8::HandleScope handle_scope(context_->isolate());
389 return gin::PerContextData::From(context_->v8_context())->context_holder(); 394 return gin::PerContextData::From(context_->v8_context())->context_holder();
390 } 395 }
391 396
392 } // namespace extensions 397 } // 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