Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / extensions / shell / browser / shell_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/shell/browser/shell_extensions_browser_client.h"
6
7 #include "base/prefs/pref_service.h"
8 #include "base/prefs/pref_service_factory.h"
9 #include "base/prefs/testing_pref_store.h"
10 #include "components/pref_registry/pref_registry_syncable.h"
11 #include "components/user_prefs/user_prefs.h"
12 #include "extensions/browser/app_sorting.h"
13 #include "extensions/browser/extension_function_registry.h"
14 #include "extensions/browser/extension_host_delegate.h"
15 #include "extensions/browser/extension_prefs.h"
16 #include "extensions/common/api/generated_api.h"
17 #include "extensions/shell/browser/api/shell_extensions_api_client.h"
18 #include "extensions/shell/browser/shell_app_sorting.h"
19 #include "extensions/shell/browser/shell_extension_system_factory.h"
20 #include "extensions/shell/browser/shell_extension_web_contents_observer.h"
21 #include "extensions/shell/browser/shell_runtime_api_delegate.h"
22 #include "extensions/shell/common/api/generated_api.h"
23
24 using content::BrowserContext;
25
26 namespace extensions {
27 namespace {
28
29 // See chrome::RegisterProfilePrefs() in chrome/browser/prefs/browser_prefs.cc
30 void RegisterPrefs(user_prefs::PrefRegistrySyncable* registry) {
31   ExtensionPrefs::RegisterProfilePrefs(registry);
32 }
33
34 // A minimal ExtensionHostDelegate.
35 class ShellExtensionHostDelegate : public ExtensionHostDelegate {
36  public:
37   ShellExtensionHostDelegate() {}
38   virtual ~ShellExtensionHostDelegate() {}
39
40   // ExtensionHostDelegate implementation.
41   virtual void OnExtensionHostCreated(
42       content::WebContents* web_contents) OVERRIDE;
43
44   virtual void OnRenderViewCreatedForBackgroundPage(
45       ExtensionHost* host) OVERRIDE {}
46
47   virtual content::JavaScriptDialogManager* GetJavaScriptDialogManager()
48       OVERRIDE {
49     // TODO(jamescook): Create a JavaScriptDialogManager or reuse the one from
50     // content_shell.
51     NOTREACHED();
52     return NULL;
53   }
54
55   virtual void CreateTab(content::WebContents* web_contents,
56                          const std::string& extension_id,
57                          WindowOpenDisposition disposition,
58                          const gfx::Rect& initial_pos,
59                          bool user_gesture) OVERRIDE {
60     // TODO(jamescook): Should app_shell support opening popup windows?
61     NOTREACHED();
62   }
63
64   virtual void ProcessMediaAccessRequest(
65       content::WebContents* web_contents,
66       const content::MediaStreamRequest& request,
67       const content::MediaResponseCallback& callback,
68       const Extension* extension) OVERRIDE {
69     // app_shell does not support media capture.
70     NOTREACHED();
71   }
72 };
73
74 void ShellExtensionHostDelegate::OnExtensionHostCreated(
75     content::WebContents* web_contents) {
76   ShellExtensionWebContentsObserver::CreateForWebContents(web_contents);
77 }
78
79 }  // namespace
80
81 ShellExtensionsBrowserClient::ShellExtensionsBrowserClient(
82     BrowserContext* context)
83     : browser_context_(context), api_client_(new ShellExtensionsAPIClient) {
84   // Set up the preferences service.
85   base::PrefServiceFactory factory;
86   factory.set_user_prefs(new TestingPrefStore);
87   factory.set_extension_prefs(new TestingPrefStore);
88   // app_shell should not require syncable preferences, but for now we need to
89   // recycle some of the RegisterProfilePrefs() code in Chrome.
90   // TODO(jamescook): Convert this to PrefRegistrySimple.
91   user_prefs::PrefRegistrySyncable* pref_registry =
92       new user_prefs::PrefRegistrySyncable;
93   // Prefs should be registered before the PrefService is created.
94   RegisterPrefs(pref_registry);
95   prefs_ = factory.Create(pref_registry).Pass();
96   user_prefs::UserPrefs::Set(browser_context_, prefs_.get());
97 }
98
99 ShellExtensionsBrowserClient::~ShellExtensionsBrowserClient() {
100 }
101
102 bool ShellExtensionsBrowserClient::IsShuttingDown() {
103   return false;
104 }
105
106 bool ShellExtensionsBrowserClient::AreExtensionsDisabled(
107     const base::CommandLine& command_line,
108     BrowserContext* context) {
109   return false;
110 }
111
112 bool ShellExtensionsBrowserClient::IsValidContext(BrowserContext* context) {
113   return context == browser_context_;
114 }
115
116 bool ShellExtensionsBrowserClient::IsSameContext(BrowserContext* first,
117                                                  BrowserContext* second) {
118   return first == second;
119 }
120
121 bool ShellExtensionsBrowserClient::HasOffTheRecordContext(
122     BrowserContext* context) {
123   return false;
124 }
125
126 BrowserContext* ShellExtensionsBrowserClient::GetOffTheRecordContext(
127     BrowserContext* context) {
128   // app_shell only supports a single context.
129   return NULL;
130 }
131
132 BrowserContext* ShellExtensionsBrowserClient::GetOriginalContext(
133     BrowserContext* context) {
134   return context;
135 }
136
137 bool ShellExtensionsBrowserClient::IsGuestSession(
138     BrowserContext* context) const {
139   return false;
140 }
141
142 bool ShellExtensionsBrowserClient::IsExtensionIncognitoEnabled(
143     const std::string& extension_id,
144     content::BrowserContext* context) const {
145   return false;
146 }
147
148 bool ShellExtensionsBrowserClient::CanExtensionCrossIncognito(
149     const Extension* extension,
150     content::BrowserContext* context) const {
151   return false;
152 }
153
154 bool ShellExtensionsBrowserClient::IsWebViewRequest(
155     net::URLRequest* request) const {
156   return false;
157 }
158
159 net::URLRequestJob*
160 ShellExtensionsBrowserClient::MaybeCreateResourceBundleRequestJob(
161     net::URLRequest* request,
162     net::NetworkDelegate* network_delegate,
163     const base::FilePath& directory_path,
164     const std::string& content_security_policy,
165     bool send_cors_header) {
166   return NULL;
167 }
168
169 bool ShellExtensionsBrowserClient::AllowCrossRendererResourceLoad(
170     net::URLRequest* request,
171     bool is_incognito,
172     const Extension* extension,
173     InfoMap* extension_info_map) {
174   // Note: This may need to change if app_shell supports webview.
175   return false;
176 }
177
178 PrefService* ShellExtensionsBrowserClient::GetPrefServiceForContext(
179     BrowserContext* context) {
180   return prefs_.get();
181 }
182
183 void ShellExtensionsBrowserClient::GetEarlyExtensionPrefsObservers(
184     content::BrowserContext* context,
185     std::vector<ExtensionPrefsObserver*>* observers) const {
186 }
187
188 ProcessManagerDelegate*
189 ShellExtensionsBrowserClient::GetProcessManagerDelegate() const {
190   return NULL;
191 }
192
193 scoped_ptr<ExtensionHostDelegate>
194 ShellExtensionsBrowserClient::CreateExtensionHostDelegate() {
195   return scoped_ptr<ExtensionHostDelegate>(new ShellExtensionHostDelegate);
196 }
197
198 bool ShellExtensionsBrowserClient::DidVersionUpdate(BrowserContext* context) {
199   // TODO(jamescook): We might want to tell extensions when app_shell updates.
200   return false;
201 }
202
203 void ShellExtensionsBrowserClient::PermitExternalProtocolHandler() {
204 }
205
206 scoped_ptr<AppSorting> ShellExtensionsBrowserClient::CreateAppSorting() {
207   return scoped_ptr<AppSorting>(new ShellAppSorting);
208 }
209
210 bool ShellExtensionsBrowserClient::IsRunningInForcedAppMode() {
211   return false;
212 }
213
214 ApiActivityMonitor* ShellExtensionsBrowserClient::GetApiActivityMonitor(
215     BrowserContext* context) {
216   // app_shell doesn't monitor API function calls or events.
217   return NULL;
218 }
219
220 ExtensionSystemProvider*
221 ShellExtensionsBrowserClient::GetExtensionSystemFactory() {
222   return ShellExtensionSystemFactory::GetInstance();
223 }
224
225 void ShellExtensionsBrowserClient::RegisterExtensionFunctions(
226     ExtensionFunctionRegistry* registry) const {
227   // Register core extension-system APIs.
228   core_api::GeneratedFunctionRegistry::RegisterAll(registry);
229
230   // Register chrome.shell APIs.
231   shell_api::GeneratedFunctionRegistry::RegisterAll(registry);
232 }
233
234 scoped_ptr<RuntimeAPIDelegate>
235 ShellExtensionsBrowserClient::CreateRuntimeAPIDelegate(
236     content::BrowserContext* context) const {
237   return scoped_ptr<RuntimeAPIDelegate>(new ShellRuntimeAPIDelegate());
238 }
239
240 ComponentExtensionResourceManager*
241 ShellExtensionsBrowserClient::GetComponentExtensionResourceManager() {
242   return NULL;
243 }
244
245 net::NetLog* ShellExtensionsBrowserClient::GetNetLog() {
246   return NULL;
247 }
248
249 }  // namespace extensions