1 // Copyright 2013 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 "apps/shell/shell_extensions_browser_client.h" 6 7 #include "apps/shell/shell_app_sorting.h" 8 #include "base/prefs/pref_service.h" 9 #include "base/prefs/pref_service_factory.h" 10 #include "base/prefs/testing_pref_store.h" 11 #include "chrome/browser/extensions/extension_prefs.h" 12 #include "components/user_prefs/pref_registry_syncable.h" 13 #include "components/user_prefs/user_prefs.h" 14 #include "extensions/browser/app_sorting.h" 15 16 using content::BrowserContext; 17 18 namespace { 19 20 // See chrome::RegisterProfilePrefs() in chrome/browser/prefs/browser_prefs.cc RegisterPrefs(user_prefs::PrefRegistrySyncable * registry)21void RegisterPrefs(user_prefs::PrefRegistrySyncable* registry) { 22 extensions::ExtensionPrefs::RegisterProfilePrefs(registry); 23 } 24 25 } // namespace 26 27 namespace apps { 28 ShellExtensionsBrowserClient(BrowserContext * context)29ShellExtensionsBrowserClient::ShellExtensionsBrowserClient( 30 BrowserContext* context) 31 : browser_context_(context) { 32 // Set up the preferences service. 33 base::PrefServiceFactory factory; 34 factory.set_user_prefs(new TestingPrefStore); 35 factory.set_extension_prefs(new TestingPrefStore); 36 // app_shell should not require syncable preferences, but for now we need to 37 // recycle some of the RegisterProfilePrefs() code in Chrome. 38 // TODO(jamescook): Convert this to user_prefs::PrefRegistrySimple. 39 user_prefs::PrefRegistrySyncable* pref_registry = 40 new user_prefs::PrefRegistrySyncable; 41 // Prefs should be registered before the PrefService is created. 42 RegisterPrefs(pref_registry); 43 prefs_ = factory.Create(pref_registry).Pass(); 44 user_prefs::UserPrefs::Set(browser_context_, prefs_.get()); 45 } 46 ~ShellExtensionsBrowserClient()47ShellExtensionsBrowserClient::~ShellExtensionsBrowserClient() {} 48 IsShuttingDown()49bool ShellExtensionsBrowserClient::IsShuttingDown() { 50 return false; 51 } 52 AreExtensionsDisabled(const CommandLine & command_line,BrowserContext * context)53bool ShellExtensionsBrowserClient::AreExtensionsDisabled( 54 const CommandLine& command_line, 55 BrowserContext* context) { 56 return false; 57 } 58 IsValidContext(BrowserContext * context)59bool ShellExtensionsBrowserClient::IsValidContext(BrowserContext* context) { 60 return context == browser_context_; 61 } 62 IsSameContext(BrowserContext * first,BrowserContext * second)63bool ShellExtensionsBrowserClient::IsSameContext(BrowserContext* first, 64 BrowserContext* second) { 65 return first == second; 66 } 67 HasOffTheRecordContext(BrowserContext * context)68bool ShellExtensionsBrowserClient::HasOffTheRecordContext( 69 BrowserContext* context) { 70 return false; 71 } 72 GetOffTheRecordContext(BrowserContext * context)73BrowserContext* ShellExtensionsBrowserClient::GetOffTheRecordContext( 74 BrowserContext* context) { 75 // app_shell only supports a single context. 76 return NULL; 77 } 78 GetOriginalContext(BrowserContext * context)79BrowserContext* ShellExtensionsBrowserClient::GetOriginalContext( 80 BrowserContext* context) { 81 return context; 82 } 83 GetPrefServiceForContext(BrowserContext * context)84PrefService* ShellExtensionsBrowserClient::GetPrefServiceForContext( 85 BrowserContext* context) { 86 return prefs_.get(); 87 } 88 DeferLoadingBackgroundHosts(BrowserContext * context) const89bool ShellExtensionsBrowserClient::DeferLoadingBackgroundHosts( 90 BrowserContext* context) const { 91 return false; 92 } 93 IsBackgroundPageAllowed(BrowserContext * context) const94bool ShellExtensionsBrowserClient::IsBackgroundPageAllowed( 95 BrowserContext* context) const { 96 return true; 97 } 98 DidVersionUpdate(BrowserContext * context)99bool ShellExtensionsBrowserClient::DidVersionUpdate(BrowserContext* context) { 100 // TODO(jamescook): We might want to tell extensions when app_shell updates. 101 return false; 102 } 103 104 scoped_ptr<extensions::AppSorting> CreateAppSorting()105ShellExtensionsBrowserClient::CreateAppSorting() { 106 return scoped_ptr<extensions::AppSorting>(new ShellAppSorting).Pass(); 107 } 108 IsRunningInForcedAppMode()109bool ShellExtensionsBrowserClient::IsRunningInForcedAppMode() { 110 return false; 111 } 112 113 content::JavaScriptDialogManager* GetJavaScriptDialogManager()114ShellExtensionsBrowserClient::GetJavaScriptDialogManager() { 115 // TODO(jamescook): Create a JavaScriptDialogManager or reuse the one from 116 // content_shell. 117 NOTREACHED(); 118 return NULL; 119 } 120 121 } // namespace apps 122