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

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

Issue 235943018: Move extensions bindings code out of //chrome (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: nit Created 6 years, 8 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 | Annotate | Revision Log
OLDNEW
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/logging_native_handler.h" 5 #include "extensions/renderer/logging_native_handler.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/strings/stringprintf.h" 8 #include "base/strings/stringprintf.h"
9 9
10 namespace extensions { 10 namespace extensions {
11 11
12 LoggingNativeHandler::LoggingNativeHandler(ScriptContext* context) 12 LoggingNativeHandler::LoggingNativeHandler(ScriptContext* context)
13 : ObjectBackedNativeHandler(context) { 13 : ObjectBackedNativeHandler(context) {
14 RouteFunction("DCHECK", 14 RouteFunction(
15 "DCHECK",
15 base::Bind(&LoggingNativeHandler::Dcheck, base::Unretained(this))); 16 base::Bind(&LoggingNativeHandler::Dcheck, base::Unretained(this)));
16 RouteFunction("CHECK", 17 RouteFunction(
18 "CHECK",
17 base::Bind(&LoggingNativeHandler::Check, base::Unretained(this))); 19 base::Bind(&LoggingNativeHandler::Check, base::Unretained(this)));
18 RouteFunction("DCHECK_IS_ON", 20 RouteFunction(
21 "DCHECK_IS_ON",
19 base::Bind(&LoggingNativeHandler::DcheckIsOn, base::Unretained(this))); 22 base::Bind(&LoggingNativeHandler::DcheckIsOn, base::Unretained(this)));
20 RouteFunction("LOG", 23 RouteFunction("LOG",
21 base::Bind(&LoggingNativeHandler::Log, base::Unretained(this))); 24 base::Bind(&LoggingNativeHandler::Log, base::Unretained(this)));
22 RouteFunction("WARNING", 25 RouteFunction(
26 "WARNING",
23 base::Bind(&LoggingNativeHandler::Warning, base::Unretained(this))); 27 base::Bind(&LoggingNativeHandler::Warning, base::Unretained(this)));
24 } 28 }
25 29
26 LoggingNativeHandler::~LoggingNativeHandler() {} 30 LoggingNativeHandler::~LoggingNativeHandler() {}
27 31
28 void LoggingNativeHandler::Check( 32 void LoggingNativeHandler::Check(
29 const v8::FunctionCallbackInfo<v8::Value>& args) { 33 const v8::FunctionCallbackInfo<v8::Value>& args) {
30 bool check_value; 34 bool check_value;
31 std::string error_message; 35 std::string error_message;
32 ParseArgs(args, &check_value, &error_message); 36 ParseArgs(args, &check_value, &error_message);
(...skipping 25 matching lines...) Expand all
58 LOG(WARNING) << *v8::String::Utf8Value(args[0]); 62 LOG(WARNING) << *v8::String::Utf8Value(args[0]);
59 } 63 }
60 64
61 void LoggingNativeHandler::ParseArgs( 65 void LoggingNativeHandler::ParseArgs(
62 const v8::FunctionCallbackInfo<v8::Value>& args, 66 const v8::FunctionCallbackInfo<v8::Value>& args,
63 bool* check_value, 67 bool* check_value,
64 std::string* error_message) { 68 std::string* error_message) {
65 CHECK_LE(args.Length(), 2); 69 CHECK_LE(args.Length(), 2);
66 *check_value = args[0]->BooleanValue(); 70 *check_value = args[0]->BooleanValue();
67 if (args.Length() == 2) { 71 if (args.Length() == 2) {
68 *error_message = "Error: " + std::string( 72 *error_message = "Error: " + std::string(*v8::String::Utf8Value(args[1]));
69 *v8::String::Utf8Value(args[1]));
70 } 73 }
71 74
72 v8::Handle<v8::StackTrace> stack_trace = 75 v8::Handle<v8::StackTrace> stack_trace =
73 v8::StackTrace::CurrentStackTrace(args.GetIsolate(), 10); 76 v8::StackTrace::CurrentStackTrace(args.GetIsolate(), 10);
74 if (stack_trace.IsEmpty() || stack_trace->GetFrameCount() <= 0) { 77 if (stack_trace.IsEmpty() || stack_trace->GetFrameCount() <= 0) {
75 *error_message += "\n <no stack trace>"; 78 *error_message += "\n <no stack trace>";
76 } else { 79 } else {
77 for (size_t i = 0; i < (size_t) stack_trace->GetFrameCount(); ++i) { 80 for (size_t i = 0; i < (size_t)stack_trace->GetFrameCount(); ++i) {
78 v8::Handle<v8::StackFrame> frame = stack_trace->GetFrame(i); 81 v8::Handle<v8::StackFrame> frame = stack_trace->GetFrame(i);
79 CHECK(!frame.IsEmpty()); 82 CHECK(!frame.IsEmpty());
80 *error_message += base::StringPrintf("\n at %s (%s:%d:%d)", 83 *error_message += base::StringPrintf(
84 "\n at %s (%s:%d:%d)",
81 ToStringOrDefault(frame->GetFunctionName(), "<anonymous>").c_str(), 85 ToStringOrDefault(frame->GetFunctionName(), "<anonymous>").c_str(),
82 ToStringOrDefault(frame->GetScriptName(), "<anonymous>").c_str(), 86 ToStringOrDefault(frame->GetScriptName(), "<anonymous>").c_str(),
83 frame->GetLineNumber(), 87 frame->GetLineNumber(),
84 frame->GetColumn()); 88 frame->GetColumn());
85 } 89 }
86 } 90 }
87 } 91 }
88 92
89 std::string LoggingNativeHandler::ToStringOrDefault( 93 std::string LoggingNativeHandler::ToStringOrDefault(
90 const v8::Handle<v8::String>& v8_string, 94 const v8::Handle<v8::String>& v8_string,
91 const std::string& dflt) { 95 const std::string& dflt) {
92 if (v8_string.IsEmpty()) 96 if (v8_string.IsEmpty())
93 return dflt; 97 return dflt;
94 std::string ascii_value = *v8::String::Utf8Value(v8_string); 98 std::string ascii_value = *v8::String::Utf8Value(v8_string);
95 return ascii_value.empty() ? dflt : ascii_value; 99 return ascii_value.empty() ? dflt : ascii_value;
96 } 100 }
97 101
98 } // namespace extensions 102 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/renderer/logging_native_handler.h ('k') | extensions/renderer/render_view_observer_natives.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698