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/process_info_native_handler.h" | 5 #include "extensions/renderer/process_info_native_handler.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "extensions/renderer/script_context.h" | 9 #include "extensions/renderer/script_context.h" |
| 10 #include "extensions/renderer/v8_maybe_helpers.h" |
10 | 11 |
11 namespace extensions { | 12 namespace extensions { |
12 | 13 |
13 ProcessInfoNativeHandler::ProcessInfoNativeHandler( | 14 ProcessInfoNativeHandler::ProcessInfoNativeHandler( |
14 ScriptContext* context, | 15 ScriptContext* context, |
15 const std::string& extension_id, | 16 const std::string& extension_id, |
16 const std::string& context_type, | 17 const std::string& context_type, |
17 bool is_incognito_context, | 18 bool is_incognito_context, |
18 bool is_component_extension, | 19 bool is_component_extension, |
19 int manifest_version, | 20 int manifest_version, |
(...skipping 23 matching lines...) Expand all Loading... |
43 RouteFunction("IsSendRequestDisabled", | 44 RouteFunction("IsSendRequestDisabled", |
44 base::Bind(&ProcessInfoNativeHandler::IsSendRequestDisabled, | 45 base::Bind(&ProcessInfoNativeHandler::IsSendRequestDisabled, |
45 base::Unretained(this))); | 46 base::Unretained(this))); |
46 RouteFunction( | 47 RouteFunction( |
47 "HasSwitch", | 48 "HasSwitch", |
48 base::Bind(&ProcessInfoNativeHandler::HasSwitch, base::Unretained(this))); | 49 base::Bind(&ProcessInfoNativeHandler::HasSwitch, base::Unretained(this))); |
49 } | 50 } |
50 | 51 |
51 void ProcessInfoNativeHandler::GetExtensionId( | 52 void ProcessInfoNativeHandler::GetExtensionId( |
52 const v8::FunctionCallbackInfo<v8::Value>& args) { | 53 const v8::FunctionCallbackInfo<v8::Value>& args) { |
53 args.GetReturnValue().Set( | 54 if (extension_id_.size() >= v8::String::kMaxLength) |
54 v8::String::NewFromUtf8(args.GetIsolate(), extension_id_.c_str())); | 55 return; |
| 56 args.GetReturnValue().Set(ToV8String(args.GetIsolate(), |
| 57 extension_id_.c_str())); |
55 } | 58 } |
56 | 59 |
57 void ProcessInfoNativeHandler::GetContextType( | 60 void ProcessInfoNativeHandler::GetContextType( |
58 const v8::FunctionCallbackInfo<v8::Value>& args) { | 61 const v8::FunctionCallbackInfo<v8::Value>& args) { |
59 args.GetReturnValue().Set( | 62 if (context_type_.size() >= v8::String::kMaxLength) |
60 v8::String::NewFromUtf8(args.GetIsolate(), context_type_.c_str())); | 63 return; |
| 64 args.GetReturnValue().Set(ToV8String(args.GetIsolate(), |
| 65 context_type_.c_str())); |
61 } | 66 } |
62 | 67 |
63 void ProcessInfoNativeHandler::InIncognitoContext( | 68 void ProcessInfoNativeHandler::InIncognitoContext( |
64 const v8::FunctionCallbackInfo<v8::Value>& args) { | 69 const v8::FunctionCallbackInfo<v8::Value>& args) { |
65 args.GetReturnValue().Set(is_incognito_context_); | 70 args.GetReturnValue().Set(is_incognito_context_); |
66 } | 71 } |
67 | 72 |
68 void ProcessInfoNativeHandler::IsComponentExtension( | 73 void ProcessInfoNativeHandler::IsComponentExtension( |
69 const v8::FunctionCallbackInfo<v8::Value>& args) { | 74 const v8::FunctionCallbackInfo<v8::Value>& args) { |
70 args.GetReturnValue().Set(is_component_extension_); | 75 args.GetReturnValue().Set(is_component_extension_); |
71 } | 76 } |
72 | 77 |
73 void ProcessInfoNativeHandler::GetManifestVersion( | 78 void ProcessInfoNativeHandler::GetManifestVersion( |
74 const v8::FunctionCallbackInfo<v8::Value>& args) { | 79 const v8::FunctionCallbackInfo<v8::Value>& args) { |
75 args.GetReturnValue().Set(static_cast<int32_t>(manifest_version_)); | 80 args.GetReturnValue().Set(static_cast<int32_t>(manifest_version_)); |
76 } | 81 } |
77 | 82 |
78 void ProcessInfoNativeHandler::IsSendRequestDisabled( | 83 void ProcessInfoNativeHandler::IsSendRequestDisabled( |
79 const v8::FunctionCallbackInfo<v8::Value>& args) { | 84 const v8::FunctionCallbackInfo<v8::Value>& args) { |
80 if (send_request_disabled_) { | 85 if (send_request_disabled_) { |
81 args.GetReturnValue().Set(v8::String::NewFromUtf8( | 86 args.GetReturnValue().Set(ToV8String( |
82 args.GetIsolate(), | 87 args.GetIsolate(), |
83 "sendRequest and onRequest are obsolete." | 88 "sendRequest and onRequest are obsolete." |
84 " Please use sendMessage and onMessage instead.")); | 89 " Please use sendMessage and onMessage instead.")); |
85 } | 90 } |
86 } | 91 } |
87 | 92 |
88 void ProcessInfoNativeHandler::HasSwitch( | 93 void ProcessInfoNativeHandler::HasSwitch( |
89 const v8::FunctionCallbackInfo<v8::Value>& args) { | 94 const v8::FunctionCallbackInfo<v8::Value>& args) { |
90 CHECK(args.Length() == 1 && args[0]->IsString()); | 95 CHECK(args.Length() == 1 && args[0]->IsString()); |
91 bool has_switch = base::CommandLine::ForCurrentProcess()->HasSwitch( | 96 bool has_switch = base::CommandLine::ForCurrentProcess()->HasSwitch( |
92 *v8::String::Utf8Value(args[0])); | 97 *v8::String::Utf8Value(args[0])); |
93 args.GetReturnValue().Set(v8::Boolean::New(args.GetIsolate(), has_switch)); | 98 args.GetReturnValue().Set(v8::Boolean::New(args.GetIsolate(), has_switch)); |
94 } | 99 } |
95 | 100 |
96 } // namespace extensions | 101 } // namespace extensions |
OLD | NEW |