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

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

Issue 1167423002: Use V8 Maybe APIs in extensions/renderer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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/blob_native_handler.cc ('k') | extensions/renderer/dispatcher.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/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 "content/public/renderer/render_view.h" 13 #include "content/public/renderer/render_view.h"
14 #include "content/public/renderer/render_view_visitor.h" 14 #include "content/public/renderer/render_view_visitor.h"
15 #include "extensions/renderer/dispatcher.h" 15 #include "extensions/renderer/dispatcher.h"
16 #include "extensions/renderer/extension_helper.h" 16 #include "extensions/renderer/extension_helper.h"
17 #include "extensions/renderer/v8_maybe_helpers.h"
17 #include "third_party/WebKit/public/web/WebConsoleMessage.h" 18 #include "third_party/WebKit/public/web/WebConsoleMessage.h"
18 #include "third_party/WebKit/public/web/WebFrame.h" 19 #include "third_party/WebKit/public/web/WebFrame.h"
19 #include "third_party/WebKit/public/web/WebView.h" 20 #include "third_party/WebKit/public/web/WebView.h"
20 21
21 namespace extensions { 22 namespace extensions {
22 namespace console { 23 namespace console {
23 24
24 namespace { 25 namespace {
25 26
26 // Finds the RenderView associated with a context. Note: there will be multiple 27 // Finds the RenderView associated with a context. Note: there will be multiple
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 message += " "; 76 message += " ";
76 message += *v8::String::Utf8Value(info[i]); 77 message += *v8::String::Utf8Value(info[i]);
77 } 78 }
78 (*log_method)(info.GetIsolate()->GetCallingContext(), message); 79 (*log_method)(info.GetIsolate()->GetCallingContext(), message);
79 } 80 }
80 81
81 void BindLogMethod(v8::Isolate* isolate, 82 void BindLogMethod(v8::Isolate* isolate,
82 v8::Local<v8::Object> target, 83 v8::Local<v8::Object> target,
83 const std::string& name, 84 const std::string& name,
84 LogMethod log_method) { 85 LogMethod log_method) {
86 CHECK(name.size() < v8::String::kMaxLength);
85 v8::Local<v8::FunctionTemplate> tmpl = v8::FunctionTemplate::New( 87 v8::Local<v8::FunctionTemplate> tmpl = v8::FunctionTemplate::New(
86 isolate, 88 isolate,
87 &BoundLogMethodCallback, 89 &BoundLogMethodCallback,
88 v8::External::New(isolate, reinterpret_cast<void*>(log_method))); 90 v8::External::New(isolate, reinterpret_cast<void*>(log_method)));
89 target->Set(v8::String::NewFromUtf8(isolate, name.c_str()), 91 v8::Local<v8::String> property = ToV8String(isolate, name.c_str());
90 tmpl->GetFunction()); 92 v8::Local<v8::Context> context = isolate->GetCurrentContext();
93 v8::Local<v8::Function> function;
94 if (!tmpl->GetFunction(context).ToLocal(&function))
95 NOTREACHED();
96 SetProperty(context, target, property, function);
91 } 97 }
92 98
93 } // namespace 99 } // namespace
94 100
95 void Debug(content::RenderView* render_view, const std::string& message) { 101 void Debug(content::RenderView* render_view, const std::string& message) {
96 AddMessage(render_view, content::CONSOLE_MESSAGE_LEVEL_DEBUG, message); 102 AddMessage(render_view, content::CONSOLE_MESSAGE_LEVEL_DEBUG, message);
97 } 103 }
98 104
99 void Log(content::RenderView* render_view, const std::string& message) { 105 void Log(content::RenderView* render_view, const std::string& message) {
100 AddMessage(render_view, content::CONSOLE_MESSAGE_LEVEL_LOG, message); 106 AddMessage(render_view, content::CONSOLE_MESSAGE_LEVEL_LOG, message);
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 v8::Local<v8::Object> console_object = v8::Object::New(isolate); 186 v8::Local<v8::Object> console_object = v8::Object::New(isolate);
181 BindLogMethod(isolate, console_object, "debug", &Debug); 187 BindLogMethod(isolate, console_object, "debug", &Debug);
182 BindLogMethod(isolate, console_object, "log", &Log); 188 BindLogMethod(isolate, console_object, "log", &Log);
183 BindLogMethod(isolate, console_object, "warn", &Warn); 189 BindLogMethod(isolate, console_object, "warn", &Warn);
184 BindLogMethod(isolate, console_object, "error", &Error); 190 BindLogMethod(isolate, console_object, "error", &Error);
185 return handle_scope.Escape(console_object); 191 return handle_scope.Escape(console_object);
186 } 192 }
187 193
188 } // namespace console 194 } // namespace console
189 } // namespace extensions 195 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/renderer/blob_native_handler.cc ('k') | extensions/renderer/dispatcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698