1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "extensions/renderer/process_info_native_handler.h"
#include <stdint.h>
#include "base/bind.h"
#include "base/command_line.h"
#include "extensions/renderer/script_context.h"
namespace extensions {
ProcessInfoNativeHandler::ProcessInfoNativeHandler(
ScriptContext* context,
const std::string& extension_id,
const std::string& context_type,
bool is_incognito_context,
bool is_component_extension,
int manifest_version,
bool send_request_disabled)
: ObjectBackedNativeHandler(context),
extension_id_(extension_id),
context_type_(context_type),
is_incognito_context_(is_incognito_context),
is_component_extension_(is_component_extension),
manifest_version_(manifest_version),
send_request_disabled_(send_request_disabled) {
RouteFunction("GetExtensionId",
base::Bind(&ProcessInfoNativeHandler::GetExtensionId,
base::Unretained(this)));
RouteFunction("GetContextType",
base::Bind(&ProcessInfoNativeHandler::GetContextType,
base::Unretained(this)));
RouteFunction("InIncognitoContext",
base::Bind(&ProcessInfoNativeHandler::InIncognitoContext,
base::Unretained(this)));
RouteFunction("IsComponentExtension",
base::Bind(&ProcessInfoNativeHandler::IsComponentExtension,
base::Unretained(this)));
RouteFunction("GetManifestVersion",
base::Bind(&ProcessInfoNativeHandler::GetManifestVersion,
base::Unretained(this)));
RouteFunction("IsSendRequestDisabled",
base::Bind(&ProcessInfoNativeHandler::IsSendRequestDisabled,
base::Unretained(this)));
RouteFunction(
"HasSwitch",
base::Bind(&ProcessInfoNativeHandler::HasSwitch, base::Unretained(this)));
}
void ProcessInfoNativeHandler::GetExtensionId(
const v8::FunctionCallbackInfo<v8::Value>& args) {
args.GetReturnValue().Set(
v8::String::NewFromUtf8(args.GetIsolate(), extension_id_.c_str()));
}
void ProcessInfoNativeHandler::GetContextType(
const v8::FunctionCallbackInfo<v8::Value>& args) {
args.GetReturnValue().Set(
v8::String::NewFromUtf8(args.GetIsolate(), context_type_.c_str()));
}
void ProcessInfoNativeHandler::InIncognitoContext(
const v8::FunctionCallbackInfo<v8::Value>& args) {
args.GetReturnValue().Set(is_incognito_context_);
}
void ProcessInfoNativeHandler::IsComponentExtension(
const v8::FunctionCallbackInfo<v8::Value>& args) {
args.GetReturnValue().Set(is_component_extension_);
}
void ProcessInfoNativeHandler::GetManifestVersion(
const v8::FunctionCallbackInfo<v8::Value>& args) {
args.GetReturnValue().Set(static_cast<int32_t>(manifest_version_));
}
void ProcessInfoNativeHandler::IsSendRequestDisabled(
const v8::FunctionCallbackInfo<v8::Value>& args) {
if (send_request_disabled_) {
args.GetReturnValue().Set(v8::String::NewFromUtf8(
args.GetIsolate(),
"sendRequest and onRequest are obsolete."
" Please use sendMessage and onMessage instead."));
}
}
void ProcessInfoNativeHandler::HasSwitch(
const v8::FunctionCallbackInfo<v8::Value>& args) {
CHECK(args.Length() == 1 && args[0]->IsString());
bool has_switch = base::CommandLine::ForCurrentProcess()->HasSwitch(
*v8::String::Utf8Value(args[0]));
args.GetReturnValue().Set(v8::Boolean::New(args.GetIsolate(), has_switch));
}
} // namespace extensions
|