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
3 // found in the LICENSE file.
5 #include "extensions/renderer/process_info_native_handler.h"
8 #include "base/command_line.h"
9 #include "extensions/renderer/script_context.h"
11 namespace extensions
{
13 ProcessInfoNativeHandler::ProcessInfoNativeHandler(
14 ScriptContext
* context
,
15 const std::string
& extension_id
,
16 const std::string
& context_type
,
17 bool is_incognito_context
,
18 bool is_component_extension
,
20 bool send_request_disabled
)
21 : ObjectBackedNativeHandler(context
),
22 extension_id_(extension_id
),
23 context_type_(context_type
),
24 is_incognito_context_(is_incognito_context
),
25 is_component_extension_(is_component_extension
),
26 manifest_version_(manifest_version
),
27 send_request_disabled_(send_request_disabled
) {
28 RouteFunction("GetExtensionId",
29 base::Bind(&ProcessInfoNativeHandler::GetExtensionId
,
30 base::Unretained(this)));
31 RouteFunction("GetContextType",
32 base::Bind(&ProcessInfoNativeHandler::GetContextType
,
33 base::Unretained(this)));
34 RouteFunction("InIncognitoContext",
35 base::Bind(&ProcessInfoNativeHandler::InIncognitoContext
,
36 base::Unretained(this)));
37 RouteFunction("IsComponentExtension",
38 base::Bind(&ProcessInfoNativeHandler::IsComponentExtension
,
39 base::Unretained(this)));
40 RouteFunction("GetManifestVersion",
41 base::Bind(&ProcessInfoNativeHandler::GetManifestVersion
,
42 base::Unretained(this)));
43 RouteFunction("IsSendRequestDisabled",
44 base::Bind(&ProcessInfoNativeHandler::IsSendRequestDisabled
,
45 base::Unretained(this)));
48 base::Bind(&ProcessInfoNativeHandler::HasSwitch
, base::Unretained(this)));
51 void ProcessInfoNativeHandler::GetExtensionId(
52 const v8::FunctionCallbackInfo
<v8::Value
>& args
) {
53 args
.GetReturnValue().Set(
54 v8::String::NewFromUtf8(args
.GetIsolate(), extension_id_
.c_str()));
57 void ProcessInfoNativeHandler::GetContextType(
58 const v8::FunctionCallbackInfo
<v8::Value
>& args
) {
59 args
.GetReturnValue().Set(
60 v8::String::NewFromUtf8(args
.GetIsolate(), context_type_
.c_str()));
63 void ProcessInfoNativeHandler::InIncognitoContext(
64 const v8::FunctionCallbackInfo
<v8::Value
>& args
) {
65 args
.GetReturnValue().Set(is_incognito_context_
);
68 void ProcessInfoNativeHandler::IsComponentExtension(
69 const v8::FunctionCallbackInfo
<v8::Value
>& args
) {
70 args
.GetReturnValue().Set(is_component_extension_
);
73 void ProcessInfoNativeHandler::GetManifestVersion(
74 const v8::FunctionCallbackInfo
<v8::Value
>& args
) {
75 args
.GetReturnValue().Set(static_cast<int32_t>(manifest_version_
));
78 void ProcessInfoNativeHandler::IsSendRequestDisabled(
79 const v8::FunctionCallbackInfo
<v8::Value
>& args
) {
80 if (send_request_disabled_
) {
81 args
.GetReturnValue().Set(v8::String::NewFromUtf8(
83 "sendRequest and onRequest are obsolete."
84 " Please use sendMessage and onMessage instead."));
88 void ProcessInfoNativeHandler::HasSwitch(
89 const v8::FunctionCallbackInfo
<v8::Value
>& args
) {
90 CHECK(args
.Length() == 1 && args
[0]->IsString());
91 bool has_switch
= base::CommandLine::ForCurrentProcess()->HasSwitch(
92 *v8::String::Utf8Value(args
[0]));
93 args
.GetReturnValue().Set(v8::Boolean::New(args
.GetIsolate(), has_switch
));
96 } // namespace extensions