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

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

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