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

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

Issue 1231603009: Re-land: Reimplement automation API on top of C++-backed AXTree. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix nested event sending in AutomationManagerAura Created 5 years, 5 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') | ui/accessibility/ax_tree.cc » ('j') | 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 return "WEB_PAGE"; 51 return "WEB_PAGE";
52 case Feature::BLESSED_WEB_PAGE_CONTEXT: 52 case Feature::BLESSED_WEB_PAGE_CONTEXT:
53 return "BLESSED_WEB_PAGE"; 53 return "BLESSED_WEB_PAGE";
54 case Feature::WEBUI_CONTEXT: 54 case Feature::WEBUI_CONTEXT:
55 return "WEBUI"; 55 return "WEBUI";
56 } 56 }
57 NOTREACHED(); 57 NOTREACHED();
58 return std::string(); 58 return std::string();
59 } 59 }
60 60
61 static std::string ToStringOrDefault(
62 const v8::Local<v8::String>& v8_string,
63 const std::string& dflt) {
64 if (v8_string.IsEmpty())
65 return dflt;
66 std::string ascii_value = *v8::String::Utf8Value(v8_string);
67 return ascii_value.empty() ? dflt : ascii_value;
68 }
69
61 } // namespace 70 } // namespace
62 71
63 // A gin::Runner that delegates to its ScriptContext. 72 // A gin::Runner that delegates to its ScriptContext.
64 class ScriptContext::Runner : public gin::Runner { 73 class ScriptContext::Runner : public gin::Runner {
65 public: 74 public:
66 explicit Runner(ScriptContext* context); 75 explicit Runner(ScriptContext* context);
67 76
68 // gin::Runner overrides. 77 // gin::Runner overrides.
69 void Run(const std::string& source, 78 void Run(const std::string& source,
70 const std::string& resource_name) override; 79 const std::string& resource_name) override;
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 " context_type: %s\n" 375 " context_type: %s\n"
367 " effective extension id: %s\n" 376 " effective extension id: %s\n"
368 " effective context type: %s", 377 " effective context type: %s",
369 extension_.get() ? extension_->id().c_str() : "(none)", web_frame_, 378 extension_.get() ? extension_->id().c_str() : "(none)", web_frame_,
370 GetURL().spec().c_str(), GetContextTypeDescription().c_str(), 379 GetURL().spec().c_str(), GetContextTypeDescription().c_str(),
371 effective_extension_.get() ? effective_extension_->id().c_str() 380 effective_extension_.get() ? effective_extension_->id().c_str()
372 : "(none)", 381 : "(none)",
373 GetEffectiveContextTypeDescription().c_str()); 382 GetEffectiveContextTypeDescription().c_str());
374 } 383 }
375 384
385 std::string ScriptContext::GetStackTraceAsString() const {
386 v8::Local<v8::StackTrace> stack_trace =
387 v8::StackTrace::CurrentStackTrace(isolate(), 10);
388 if (stack_trace.IsEmpty() || stack_trace->GetFrameCount() <= 0) {
389 return " <no stack trace>";
390 } else {
391 std::string result;
392 for (int i = 0; i < stack_trace->GetFrameCount(); ++i) {
393 v8::Local<v8::StackFrame> frame = stack_trace->GetFrame(i);
394 CHECK(!frame.IsEmpty());
395 result += base::StringPrintf(
396 "\n at %s (%s:%d:%d)",
397 ToStringOrDefault(frame->GetFunctionName(), "<anonymous>").c_str(),
398 ToStringOrDefault(frame->GetScriptName(), "<anonymous>").c_str(),
399 frame->GetLineNumber(),
400 frame->GetColumn());
401 }
402 return result;
403 }
404 }
405
376 ScriptContext::Runner::Runner(ScriptContext* context) : context_(context) { 406 ScriptContext::Runner::Runner(ScriptContext* context) : context_(context) {
377 } 407 }
378 408
379 void ScriptContext::Runner::Run(const std::string& source, 409 void ScriptContext::Runner::Run(const std::string& source,
380 const std::string& resource_name) { 410 const std::string& resource_name) {
381 context_->module_system()->RunString(source, resource_name); 411 context_->module_system()->RunString(source, resource_name);
382 } 412 }
383 413
384 v8::Local<v8::Value> ScriptContext::Runner::Call( 414 v8::Local<v8::Value> ScriptContext::Runner::Call(
385 v8::Local<v8::Function> function, 415 v8::Local<v8::Function> function,
386 v8::Local<v8::Value> receiver, 416 v8::Local<v8::Value> receiver,
387 int argc, 417 int argc,
388 v8::Local<v8::Value> argv[]) { 418 v8::Local<v8::Value> argv[]) {
389 return context_->CallFunction(function, argc, argv); 419 return context_->CallFunction(function, argc, argv);
390 } 420 }
391 421
392 gin::ContextHolder* ScriptContext::Runner::GetContextHolder() { 422 gin::ContextHolder* ScriptContext::Runner::GetContextHolder() {
393 v8::HandleScope handle_scope(context_->isolate()); 423 v8::HandleScope handle_scope(context_->isolate());
394 return gin::PerContextData::From(context_->v8_context())->context_holder(); 424 return gin::PerContextData::From(context_->v8_context())->context_holder();
395 } 425 }
396 426
397 } // namespace extensions 427 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/renderer/script_context.h ('k') | ui/accessibility/ax_tree.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698