OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chrome/renderer/extensions/console.h" | 5 #include "extensions/renderer/console.h" |
6 | 6 |
7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
8 #include "base/debug/alias.h" | 8 #include "base/debug/alias.h" |
9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
13 #include "chrome/renderer/extensions/dispatcher.h" | 13 #include "chrome/renderer/extensions/dispatcher.h" |
14 #include "chrome/renderer/extensions/extension_helper.h" | 14 #include "chrome/renderer/extensions/extension_helper.h" |
15 #include "content/public/renderer/render_view.h" | 15 #include "content/public/renderer/render_view.h" |
(...skipping 12 matching lines...) Expand all Loading... | |
28 class ByContextFinder : public content::RenderViewVisitor { | 28 class ByContextFinder : public content::RenderViewVisitor { |
29 public: | 29 public: |
30 static content::RenderView* Find(v8::Handle<v8::Context> context) { | 30 static content::RenderView* Find(v8::Handle<v8::Context> context) { |
31 ByContextFinder finder(context); | 31 ByContextFinder finder(context); |
32 content::RenderView::ForEach(&finder); | 32 content::RenderView::ForEach(&finder); |
33 return finder.found_; | 33 return finder.found_; |
34 } | 34 } |
35 | 35 |
36 private: | 36 private: |
37 explicit ByContextFinder(v8::Handle<v8::Context> context) | 37 explicit ByContextFinder(v8::Handle<v8::Context> context) |
38 : context_(context), found_(NULL) { | 38 : context_(context), found_(NULL) {} |
39 } | |
40 | 39 |
41 virtual bool Visit(content::RenderView* render_view) OVERRIDE { | 40 virtual bool Visit(content::RenderView* render_view) OVERRIDE { |
42 ExtensionHelper* helper = ExtensionHelper::Get(render_view); | 41 ExtensionHelper* helper = ExtensionHelper::Get(render_view); |
43 if (helper && | 42 if (helper && |
44 helper->dispatcher()->v8_context_set().GetByV8Context(context_)) { | 43 helper->dispatcher()->v8_context_set().GetByV8Context(context_)) { |
not at google - send to devlin
2014/04/11 15:38:55
cool. it seems like you should eventually be able
| |
45 found_ = render_view; | 44 found_ = render_view; |
46 } | 45 } |
47 return !found_; | 46 return !found_; |
48 } | 47 } |
49 | 48 |
50 v8::Handle<v8::Context> context_; | 49 v8::Handle<v8::Context> context_; |
51 content::RenderView* found_; | 50 content::RenderView* found_; |
52 | 51 |
53 DISALLOW_COPY_AND_ASSIGN(ByContextFinder); | 52 DISALLOW_COPY_AND_ASSIGN(ByContextFinder); |
54 }; | 53 }; |
55 | 54 |
56 // Writes |message| to stack to show up in minidump, then crashes. | 55 // Writes |message| to stack to show up in minidump, then crashes. |
57 void CheckWithMinidump(const std::string& message) { | 56 void CheckWithMinidump(const std::string& message) { |
58 char minidump[1024]; | 57 char minidump[1024]; |
59 base::debug::Alias(&minidump); | 58 base::debug::Alias(&minidump); |
60 base::snprintf(minidump, arraysize(minidump), | 59 base::snprintf( |
61 "e::console: %s", message.c_str()); | 60 minidump, arraysize(minidump), "e::console: %s", message.c_str()); |
62 CHECK(false) << message; | 61 CHECK(false) << message; |
63 } | 62 } |
64 | 63 |
65 typedef void (*LogMethod)(v8::Handle<v8::Context> context, | 64 typedef void (*LogMethod)(v8::Handle<v8::Context> context, |
66 const std::string& message); | 65 const std::string& message); |
67 | 66 |
68 void BoundLogMethodCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { | 67 void BoundLogMethodCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { |
69 LogMethod log_method = reinterpret_cast<LogMethod>( | 68 LogMethod log_method = |
70 info.Data().As<v8::External>()->Value()); | 69 reinterpret_cast<LogMethod>(info.Data().As<v8::External>()->Value()); |
71 std::string message; | 70 std::string message; |
72 for (int i = 0; i < info.Length(); ++i) { | 71 for (int i = 0; i < info.Length(); ++i) { |
73 if (i > 0) | 72 if (i > 0) |
74 message += " "; | 73 message += " "; |
75 message += *v8::String::Utf8Value(info[i]); | 74 message += *v8::String::Utf8Value(info[i]); |
76 } | 75 } |
77 (*log_method)(info.GetIsolate()->GetCallingContext(), message); | 76 (*log_method)(info.GetIsolate()->GetCallingContext(), message); |
78 } | 77 } |
79 | 78 |
80 void BindLogMethod(v8::Isolate* isolate, | 79 void BindLogMethod(v8::Isolate* isolate, |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
180 v8::Local<v8::Object> console_object = v8::Object::New(isolate); | 179 v8::Local<v8::Object> console_object = v8::Object::New(isolate); |
181 BindLogMethod(isolate, console_object, "debug", &Debug); | 180 BindLogMethod(isolate, console_object, "debug", &Debug); |
182 BindLogMethod(isolate, console_object, "log", &Log); | 181 BindLogMethod(isolate, console_object, "log", &Log); |
183 BindLogMethod(isolate, console_object, "warn", &Warn); | 182 BindLogMethod(isolate, console_object, "warn", &Warn); |
184 BindLogMethod(isolate, console_object, "error", &Error); | 183 BindLogMethod(isolate, console_object, "error", &Error); |
185 return handle_scope.Escape(console_object); | 184 return handle_scope.Escape(console_object); |
186 } | 185 } |
187 | 186 |
188 } // namespace console | 187 } // namespace console |
189 } // namespace extensions | 188 } // namespace extensions |
OLD | NEW |