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.
4
5 #include "extensions/browser/test_extensions_browser_client.h"
6
7 #include "content/public/browser/browser_context.h"
8 #include "extensions/browser/app_sorting.h"
9 #include "extensions/browser/extension_host_delegate.h"
10 #include "extensions/browser/test_runtime_api_delegate.h"
11
12 using content::BrowserContext;
13
14 namespace extensions {
15
TestExtensionsBrowserClient(BrowserContext * main_context)16 TestExtensionsBrowserClient::TestExtensionsBrowserClient(
17 BrowserContext* main_context)
18 : main_context_(main_context),
19 incognito_context_(NULL),
20 process_manager_delegate_(NULL),
21 extension_system_factory_(NULL) {
22 DCHECK(main_context_);
23 DCHECK(!main_context_->IsOffTheRecord());
24 }
25
~TestExtensionsBrowserClient()26 TestExtensionsBrowserClient::~TestExtensionsBrowserClient() {}
27
SetIncognitoContext(BrowserContext * context)28 void TestExtensionsBrowserClient::SetIncognitoContext(BrowserContext* context) {
29 // If a context is provided it must be off-the-record.
30 DCHECK(!context || context->IsOffTheRecord());
31 incognito_context_ = context;
32 }
33
IsShuttingDown()34 bool TestExtensionsBrowserClient::IsShuttingDown() { return false; }
35
AreExtensionsDisabled(const base::CommandLine & command_line,BrowserContext * context)36 bool TestExtensionsBrowserClient::AreExtensionsDisabled(
37 const base::CommandLine& command_line,
38 BrowserContext* context) {
39 return false;
40 }
41
IsValidContext(BrowserContext * context)42 bool TestExtensionsBrowserClient::IsValidContext(BrowserContext* context) {
43 return context == main_context_ ||
44 (incognito_context_ && context == incognito_context_);
45 }
46
IsSameContext(BrowserContext * first,BrowserContext * second)47 bool TestExtensionsBrowserClient::IsSameContext(BrowserContext* first,
48 BrowserContext* second) {
49 DCHECK(first);
50 DCHECK(second);
51 return first == second ||
52 (first == main_context_ && second == incognito_context_) ||
53 (first == incognito_context_ && second == main_context_);
54 }
55
HasOffTheRecordContext(BrowserContext * context)56 bool TestExtensionsBrowserClient::HasOffTheRecordContext(
57 BrowserContext* context) {
58 return context == main_context_ && incognito_context_ != NULL;
59 }
60
GetOffTheRecordContext(BrowserContext * context)61 BrowserContext* TestExtensionsBrowserClient::GetOffTheRecordContext(
62 BrowserContext* context) {
63 if (context == main_context_)
64 return incognito_context_;
65 return NULL;
66 }
67
GetOriginalContext(BrowserContext * context)68 BrowserContext* TestExtensionsBrowserClient::GetOriginalContext(
69 BrowserContext* context) {
70 return main_context_;
71 }
72
IsGuestSession(BrowserContext * context) const73 bool TestExtensionsBrowserClient::IsGuestSession(
74 BrowserContext* context) const {
75 return false;
76 }
77
IsExtensionIncognitoEnabled(const std::string & extension_id,content::BrowserContext * context) const78 bool TestExtensionsBrowserClient::IsExtensionIncognitoEnabled(
79 const std::string& extension_id,
80 content::BrowserContext* context) const {
81 return false;
82 }
83
CanExtensionCrossIncognito(const extensions::Extension * extension,content::BrowserContext * context) const84 bool TestExtensionsBrowserClient::CanExtensionCrossIncognito(
85 const extensions::Extension* extension,
86 content::BrowserContext* context) const {
87 return false;
88 }
89
90 net::URLRequestJob*
MaybeCreateResourceBundleRequestJob(net::URLRequest * request,net::NetworkDelegate * network_delegate,const base::FilePath & directory_path,const std::string & content_security_policy,bool send_cors_header)91 TestExtensionsBrowserClient::MaybeCreateResourceBundleRequestJob(
92 net::URLRequest* request,
93 net::NetworkDelegate* network_delegate,
94 const base::FilePath& directory_path,
95 const std::string& content_security_policy,
96 bool send_cors_header) {
97 return NULL;
98 }
99
AllowCrossRendererResourceLoad(net::URLRequest * request,bool is_incognito,const Extension * extension,InfoMap * extension_info_map)100 bool TestExtensionsBrowserClient::AllowCrossRendererResourceLoad(
101 net::URLRequest* request,
102 bool is_incognito,
103 const Extension* extension,
104 InfoMap* extension_info_map) {
105 return false;
106 }
107
GetPrefServiceForContext(BrowserContext * context)108 PrefService* TestExtensionsBrowserClient::GetPrefServiceForContext(
109 BrowserContext* context) {
110 return NULL;
111 }
112
GetEarlyExtensionPrefsObservers(content::BrowserContext * context,std::vector<ExtensionPrefsObserver * > * observers) const113 void TestExtensionsBrowserClient::GetEarlyExtensionPrefsObservers(
114 content::BrowserContext* context,
115 std::vector<ExtensionPrefsObserver*>* observers) const {}
116
GetProcessManagerDelegate() const117 ProcessManagerDelegate* TestExtensionsBrowserClient::GetProcessManagerDelegate()
118 const {
119 return process_manager_delegate_;
120 }
121
122 scoped_ptr<ExtensionHostDelegate>
CreateExtensionHostDelegate()123 TestExtensionsBrowserClient::CreateExtensionHostDelegate() {
124 return scoped_ptr<ExtensionHostDelegate>();
125 }
126
DidVersionUpdate(BrowserContext * context)127 bool TestExtensionsBrowserClient::DidVersionUpdate(BrowserContext* context) {
128 return false;
129 }
130
PermitExternalProtocolHandler()131 void TestExtensionsBrowserClient::PermitExternalProtocolHandler() {
132 }
133
CreateAppSorting()134 scoped_ptr<AppSorting> TestExtensionsBrowserClient::CreateAppSorting() {
135 return scoped_ptr<AppSorting>();
136 }
137
IsRunningInForcedAppMode()138 bool TestExtensionsBrowserClient::IsRunningInForcedAppMode() { return false; }
139
GetApiActivityMonitor(BrowserContext * context)140 ApiActivityMonitor* TestExtensionsBrowserClient::GetApiActivityMonitor(
141 BrowserContext* context) {
142 return NULL;
143 }
144
145 ExtensionSystemProvider*
GetExtensionSystemFactory()146 TestExtensionsBrowserClient::GetExtensionSystemFactory() {
147 DCHECK(extension_system_factory_);
148 return extension_system_factory_;
149 }
150
RegisterExtensionFunctions(ExtensionFunctionRegistry * registry) const151 void TestExtensionsBrowserClient::RegisterExtensionFunctions(
152 ExtensionFunctionRegistry* registry) const {}
153
154 scoped_ptr<RuntimeAPIDelegate>
CreateRuntimeAPIDelegate(content::BrowserContext * context) const155 TestExtensionsBrowserClient::CreateRuntimeAPIDelegate(
156 content::BrowserContext* context) const {
157 return scoped_ptr<RuntimeAPIDelegate>(new TestRuntimeAPIDelegate());
158 }
159
160 ComponentExtensionResourceManager*
GetComponentExtensionResourceManager()161 TestExtensionsBrowserClient::GetComponentExtensionResourceManager() {
162 return NULL;
163 }
164
BroadcastEventToRenderers(const std::string & event_name,scoped_ptr<base::ListValue> args)165 void TestExtensionsBrowserClient::BroadcastEventToRenderers(
166 const std::string& event_name,
167 scoped_ptr<base::ListValue> args) {
168 }
169
GetNetLog()170 net::NetLog* TestExtensionsBrowserClient::GetNetLog() {
171 return NULL;
172 }
173
174 } // namespace extensions
175