| OLD | NEW |
| 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/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( | 14 RouteFunction( |
| 15 "DCHECK", | 15 "DCHECK", |
| 16 base::Bind(&LoggingNativeHandler::Dcheck, base::Unretained(this))); | 16 base::Bind(&LoggingNativeHandler::Dcheck, base::Unretained(this))); |
| 17 RouteFunction( | 17 RouteFunction( |
| 18 "CHECK", | 18 "CHECK", |
| 19 base::Bind(&LoggingNativeHandler::Check, base::Unretained(this))); | 19 base::Bind(&LoggingNativeHandler::Check, base::Unretained(this))); |
| 20 RouteFunction( | 20 RouteFunction("DCHECK_IS_OFF", base::Bind(&LoggingNativeHandler::DcheckIsOff, |
| 21 "DCHECK_IS_ON", | 21 base::Unretained(this))); |
| 22 base::Bind(&LoggingNativeHandler::DcheckIsOn, base::Unretained(this))); | |
| 23 RouteFunction("LOG", | 22 RouteFunction("LOG", |
| 24 base::Bind(&LoggingNativeHandler::Log, base::Unretained(this))); | 23 base::Bind(&LoggingNativeHandler::Log, base::Unretained(this))); |
| 25 RouteFunction( | 24 RouteFunction( |
| 26 "WARNING", | 25 "WARNING", |
| 27 base::Bind(&LoggingNativeHandler::Warning, base::Unretained(this))); | 26 base::Bind(&LoggingNativeHandler::Warning, base::Unretained(this))); |
| 28 } | 27 } |
| 29 | 28 |
| 30 LoggingNativeHandler::~LoggingNativeHandler() {} | 29 LoggingNativeHandler::~LoggingNativeHandler() {} |
| 31 | 30 |
| 32 void LoggingNativeHandler::Check( | 31 void LoggingNativeHandler::Check( |
| 33 const v8::FunctionCallbackInfo<v8::Value>& args) { | 32 const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 34 bool check_value; | 33 bool check_value; |
| 35 std::string error_message; | 34 std::string error_message; |
| 36 ParseArgs(args, &check_value, &error_message); | 35 ParseArgs(args, &check_value, &error_message); |
| 37 CHECK(check_value) << error_message; | 36 CHECK(check_value) << error_message; |
| 38 } | 37 } |
| 39 | 38 |
| 40 void LoggingNativeHandler::Dcheck( | 39 void LoggingNativeHandler::Dcheck( |
| 41 const v8::FunctionCallbackInfo<v8::Value>& args) { | 40 const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 42 bool check_value; | 41 bool check_value; |
| 43 std::string error_message; | 42 std::string error_message; |
| 44 ParseArgs(args, &check_value, &error_message); | 43 ParseArgs(args, &check_value, &error_message); |
| 45 DCHECK(check_value) << error_message; | 44 DCHECK(check_value) << error_message; |
| 46 } | 45 } |
| 47 | 46 |
| 48 void LoggingNativeHandler::DcheckIsOn( | 47 void LoggingNativeHandler::DcheckIsOff( |
| 49 const v8::FunctionCallbackInfo<v8::Value>& args) { | 48 const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 50 args.GetReturnValue().Set(DCHECK_IS_ON); | 49 args.GetReturnValue().Set(DCHECK_IS_OFF); |
| 51 } | 50 } |
| 52 | 51 |
| 53 void LoggingNativeHandler::Log( | 52 void LoggingNativeHandler::Log( |
| 54 const v8::FunctionCallbackInfo<v8::Value>& args) { | 53 const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 55 CHECK_EQ(1, args.Length()); | 54 CHECK_EQ(1, args.Length()); |
| 56 LOG(INFO) << *v8::String::Utf8Value(args[0]); | 55 LOG(INFO) << *v8::String::Utf8Value(args[0]); |
| 57 } | 56 } |
| 58 | 57 |
| 59 void LoggingNativeHandler::Warning( | 58 void LoggingNativeHandler::Warning( |
| 60 const v8::FunctionCallbackInfo<v8::Value>& args) { | 59 const v8::FunctionCallbackInfo<v8::Value>& args) { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 std::string LoggingNativeHandler::ToStringOrDefault( | 92 std::string LoggingNativeHandler::ToStringOrDefault( |
| 94 const v8::Handle<v8::String>& v8_string, | 93 const v8::Handle<v8::String>& v8_string, |
| 95 const std::string& dflt) { | 94 const std::string& dflt) { |
| 96 if (v8_string.IsEmpty()) | 95 if (v8_string.IsEmpty()) |
| 97 return dflt; | 96 return dflt; |
| 98 std::string ascii_value = *v8::String::Utf8Value(v8_string); | 97 std::string ascii_value = *v8::String::Utf8Value(v8_string); |
| 99 return ascii_value.empty() ? dflt : ascii_value; | 98 return ascii_value.empty() ? dflt : ascii_value; |
| 100 } | 99 } |
| 101 | 100 |
| 102 } // namespace extensions | 101 } // namespace extensions |
| OLD | NEW |