Revert "Fix broken channel icon in chrome://help on CrOS" and try again
[chromium-blink-merge.git] / extensions / shell / browser / shell_extensions_browser_client.cc
blob62b2a5fedcdeed3654d502fd9f8c140a42330a35
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/shell/browser/shell_extensions_browser_client.h"
7 #include "content/public/browser/browser_context.h"
8 #include "content/public/browser/browser_thread.h"
9 #include "content/public/browser/render_frame_host.h"
10 #include "extensions/browser/api/extensions_api_client.h"
11 #include "extensions/browser/api/generated_api_registration.h"
12 #include "extensions/browser/event_router.h"
13 #include "extensions/browser/extension_function_registry.h"
14 #include "extensions/browser/mojo/service_registration.h"
15 #include "extensions/browser/null_app_sorting.h"
16 #include "extensions/browser/updater/null_extension_cache.h"
17 #include "extensions/browser/url_request_util.h"
18 #include "extensions/shell/browser/api/generated_api_registration.h"
19 #include "extensions/shell/browser/shell_extension_host_delegate.h"
20 #include "extensions/shell/browser/shell_extension_system_factory.h"
21 #include "extensions/shell/browser/shell_extension_web_contents_observer.h"
22 #include "extensions/shell/browser/shell_extensions_api_client.h"
23 #include "extensions/shell/browser/shell_runtime_api_delegate.h"
25 #if defined(OS_CHROMEOS)
26 #include "chromeos/login/login_state.h"
27 #endif
29 using content::BrowserContext;
30 using content::BrowserThread;
32 namespace extensions {
34 ShellExtensionsBrowserClient::ShellExtensionsBrowserClient(
35 BrowserContext* context,
36 PrefService* pref_service)
37 : browser_context_(context),
38 pref_service_(pref_service),
39 api_client_(new ShellExtensionsAPIClient),
40 extension_cache_(new NullExtensionCache()) {
43 ShellExtensionsBrowserClient::~ShellExtensionsBrowserClient() {
46 bool ShellExtensionsBrowserClient::IsShuttingDown() {
47 return false;
50 bool ShellExtensionsBrowserClient::AreExtensionsDisabled(
51 const base::CommandLine& command_line,
52 BrowserContext* context) {
53 return false;
56 bool ShellExtensionsBrowserClient::IsValidContext(BrowserContext* context) {
57 return context == browser_context_;
60 bool ShellExtensionsBrowserClient::IsSameContext(BrowserContext* first,
61 BrowserContext* second) {
62 return first == second;
65 bool ShellExtensionsBrowserClient::HasOffTheRecordContext(
66 BrowserContext* context) {
67 return false;
70 BrowserContext* ShellExtensionsBrowserClient::GetOffTheRecordContext(
71 BrowserContext* context) {
72 // app_shell only supports a single context.
73 return NULL;
76 BrowserContext* ShellExtensionsBrowserClient::GetOriginalContext(
77 BrowserContext* context) {
78 return context;
81 #if defined(OS_CHROMEOS)
82 std::string ShellExtensionsBrowserClient::GetUserIdHashFromContext(
83 content::BrowserContext* context) {
84 return chromeos::LoginState::Get()->primary_user_hash();;
86 #endif
88 bool ShellExtensionsBrowserClient::IsGuestSession(
89 BrowserContext* context) const {
90 return false;
93 bool ShellExtensionsBrowserClient::IsExtensionIncognitoEnabled(
94 const std::string& extension_id,
95 content::BrowserContext* context) const {
96 return false;
99 bool ShellExtensionsBrowserClient::CanExtensionCrossIncognito(
100 const Extension* extension,
101 content::BrowserContext* context) const {
102 return false;
105 net::URLRequestJob*
106 ShellExtensionsBrowserClient::MaybeCreateResourceBundleRequestJob(
107 net::URLRequest* request,
108 net::NetworkDelegate* network_delegate,
109 const base::FilePath& directory_path,
110 const std::string& content_security_policy,
111 bool send_cors_header) {
112 return NULL;
115 bool ShellExtensionsBrowserClient::AllowCrossRendererResourceLoad(
116 net::URLRequest* request,
117 bool is_incognito,
118 const Extension* extension,
119 InfoMap* extension_info_map) {
120 bool allowed = false;
121 if (url_request_util::AllowCrossRendererResourceLoad(
122 request, is_incognito, extension, extension_info_map, &allowed)) {
123 return allowed;
126 // Couldn't determine if resource is allowed. Block the load.
127 return false;
130 PrefService* ShellExtensionsBrowserClient::GetPrefServiceForContext(
131 BrowserContext* context) {
132 return pref_service_;
135 void ShellExtensionsBrowserClient::GetEarlyExtensionPrefsObservers(
136 content::BrowserContext* context,
137 std::vector<ExtensionPrefsObserver*>* observers) const {
140 ProcessManagerDelegate*
141 ShellExtensionsBrowserClient::GetProcessManagerDelegate() const {
142 return NULL;
145 scoped_ptr<ExtensionHostDelegate>
146 ShellExtensionsBrowserClient::CreateExtensionHostDelegate() {
147 return scoped_ptr<ExtensionHostDelegate>(new ShellExtensionHostDelegate);
150 bool ShellExtensionsBrowserClient::DidVersionUpdate(BrowserContext* context) {
151 // TODO(jamescook): We might want to tell extensions when app_shell updates.
152 return false;
155 void ShellExtensionsBrowserClient::PermitExternalProtocolHandler() {
158 bool ShellExtensionsBrowserClient::IsRunningInForcedAppMode() {
159 return false;
162 ApiActivityMonitor* ShellExtensionsBrowserClient::GetApiActivityMonitor(
163 BrowserContext* context) {
164 // app_shell doesn't monitor API function calls or events.
165 return NULL;
168 ExtensionSystemProvider*
169 ShellExtensionsBrowserClient::GetExtensionSystemFactory() {
170 return ShellExtensionSystemFactory::GetInstance();
173 void ShellExtensionsBrowserClient::RegisterExtensionFunctions(
174 ExtensionFunctionRegistry* registry) const {
175 // Register core extension-system APIs.
176 api::GeneratedFunctionRegistry::RegisterAll(registry);
178 // app_shell-only APIs.
179 shell::api::ShellGeneratedFunctionRegistry::RegisterAll(registry);
182 void ShellExtensionsBrowserClient::RegisterMojoServices(
183 content::RenderFrameHost* render_frame_host,
184 const Extension* extension) const {
185 RegisterServicesForFrame(render_frame_host, extension);
188 scoped_ptr<RuntimeAPIDelegate>
189 ShellExtensionsBrowserClient::CreateRuntimeAPIDelegate(
190 content::BrowserContext* context) const {
191 return scoped_ptr<RuntimeAPIDelegate>(new ShellRuntimeAPIDelegate());
194 const ComponentExtensionResourceManager*
195 ShellExtensionsBrowserClient::GetComponentExtensionResourceManager() {
196 return NULL;
199 void ShellExtensionsBrowserClient::BroadcastEventToRenderers(
200 events::HistogramValue histogram_value,
201 const std::string& event_name,
202 scoped_ptr<base::ListValue> args) {
203 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
204 BrowserThread::PostTask(
205 BrowserThread::UI, FROM_HERE,
206 base::Bind(&ShellExtensionsBrowserClient::BroadcastEventToRenderers,
207 base::Unretained(this), histogram_value, event_name,
208 base::Passed(&args)));
209 return;
212 scoped_ptr<Event> event(new Event(histogram_value, event_name, args.Pass()));
213 EventRouter::Get(browser_context_)->BroadcastEvent(event.Pass());
216 net::NetLog* ShellExtensionsBrowserClient::GetNetLog() {
217 return NULL;
220 ExtensionCache* ShellExtensionsBrowserClient::GetExtensionCache() {
221 return extension_cache_.get();
224 bool ShellExtensionsBrowserClient::IsBackgroundUpdateAllowed() {
225 return true;
228 bool ShellExtensionsBrowserClient::IsMinBrowserVersionSupported(
229 const std::string& min_version) {
230 return true;
233 void ShellExtensionsBrowserClient::SetAPIClientForTest(
234 ExtensionsAPIClient* api_client) {
235 api_client_.reset(api_client);
238 ExtensionWebContentsObserver*
239 ShellExtensionsBrowserClient::GetExtensionWebContentsObserver(
240 content::WebContents* web_contents) {
241 return ShellExtensionWebContentsObserver::FromWebContents(web_contents);
244 } // namespace extensions