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

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

Issue 2936083002: [Extensions] Remove unsafe variants of CallModuleMethod (Closed)
Patch Set: . Created 3 years, 6 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/command_line.h" 7 #include "base/command_line.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/strings/string_split.h" 10 #include "base/strings/string_split.h"
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 return extension_.get() ? extension_->id() : base::EmptyString(); 173 return extension_.get() ? extension_->id() : base::EmptyString();
174 } 174 }
175 175
176 content::RenderFrame* ScriptContext::GetRenderFrame() const { 176 content::RenderFrame* ScriptContext::GetRenderFrame() const {
177 DCHECK(thread_checker_.CalledOnValidThread()); 177 DCHECK(thread_checker_.CalledOnValidThread());
178 if (web_frame_) 178 if (web_frame_)
179 return content::RenderFrame::FromWebFrame(web_frame_); 179 return content::RenderFrame::FromWebFrame(web_frame_);
180 return NULL; 180 return NULL;
181 } 181 }
182 182
183 v8::Local<v8::Value> ScriptContext::CallFunction(
184 const v8::Local<v8::Function>& function,
185 int argc,
186 v8::Local<v8::Value> argv[]) const {
187 DCHECK(thread_checker_.CalledOnValidThread());
188 v8::EscapableHandleScope handle_scope(isolate());
189 v8::Context::Scope scope(v8_context());
190
191 v8::MicrotasksScope microtasks(
192 isolate(), v8::MicrotasksScope::kDoNotRunMicrotasks);
193 if (!is_valid_) {
194 return handle_scope.Escape(
195 v8::Local<v8::Primitive>(v8::Undefined(isolate())));
196 }
197
198 v8::Local<v8::Object> global = v8_context()->Global();
199 if (!web_frame_)
200 return handle_scope.Escape(function->Call(global, argc, argv));
201 return handle_scope.Escape(
202 v8::Local<v8::Value>(web_frame_->CallFunctionEvenIfScriptDisabled(
203 function, global, argc, argv)));
204 }
205
206 void ScriptContext::SafeCallFunction(const v8::Local<v8::Function>& function, 183 void ScriptContext::SafeCallFunction(const v8::Local<v8::Function>& function,
207 int argc, 184 int argc,
208 v8::Local<v8::Value> argv[]) { 185 v8::Local<v8::Value> argv[]) {
209 SafeCallFunction(function, argc, argv, 186 SafeCallFunction(function, argc, argv,
210 ScriptInjectionCallback::CompleteCallback()); 187 ScriptInjectionCallback::CompleteCallback());
211 } 188 }
212 189
213 void ScriptContext::SafeCallFunction( 190 void ScriptContext::SafeCallFunction(
214 const v8::Local<v8::Function>& function, 191 const v8::Local<v8::Function>& function,
215 int argc, 192 int argc,
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
523 int argc, 500 int argc,
524 v8::Local<v8::Value> argv[]) { 501 v8::Local<v8::Value> argv[]) {
525 return context_->CallFunction(function, argc, argv); 502 return context_->CallFunction(function, argc, argv);
526 } 503 }
527 504
528 gin::ContextHolder* ScriptContext::Runner::GetContextHolder() { 505 gin::ContextHolder* ScriptContext::Runner::GetContextHolder() {
529 v8::HandleScope handle_scope(context_->isolate()); 506 v8::HandleScope handle_scope(context_->isolate());
530 return gin::PerContextData::From(context_->v8_context())->context_holder(); 507 return gin::PerContextData::From(context_->v8_context())->context_holder();
531 } 508 }
532 509
510 v8::Local<v8::Value> ScriptContext::CallFunction(
511 const v8::Local<v8::Function>& function,
512 int argc,
513 v8::Local<v8::Value> argv[]) const {
514 DCHECK(thread_checker_.CalledOnValidThread());
515 v8::EscapableHandleScope handle_scope(isolate());
516 v8::Context::Scope scope(v8_context());
517
518 v8::MicrotasksScope microtasks(isolate(),
519 v8::MicrotasksScope::kDoNotRunMicrotasks);
520 if (!is_valid_) {
521 return handle_scope.Escape(
522 v8::Local<v8::Primitive>(v8::Undefined(isolate())));
523 }
524
525 v8::Local<v8::Object> global = v8_context()->Global();
526 if (!web_frame_)
527 return handle_scope.Escape(function->Call(global, argc, argv));
528 return handle_scope.Escape(
529 v8::Local<v8::Value>(web_frame_->CallFunctionEvenIfScriptDisabled(
530 function, global, argc, argv)));
531 }
532
533 } // namespace extensions 533 } // 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