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