diff options
Diffstat (limited to 'chrome/browser/extensions')
-rw-r--r-- | chrome/browser/extensions/api/DEPS | 3 | ||||
-rw-r--r-- | chrome/browser/extensions/api/webstore_private/webstore_private_api.cc | 6 | ||||
-rw-r--r-- | chrome/browser/extensions/app_launcher.cc | 121 | ||||
-rw-r--r-- | chrome/browser/extensions/app_launcher.h | 34 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_install_ui_android.cc | 55 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_install_ui_android.h | 26 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_install_ui_default.cc | 273 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_install_ui_default.h | 45 |
8 files changed, 6 insertions, 557 deletions
diff --git a/chrome/browser/extensions/api/DEPS b/chrome/browser/extensions/api/DEPS new file mode 100644 index 0000000..6d699a6 --- /dev/null +++ b/chrome/browser/extensions/api/DEPS @@ -0,0 +1,3 @@ +include_rules = [ + "+apps", +] diff --git a/chrome/browser/extensions/api/webstore_private/webstore_private_api.cc b/chrome/browser/extensions/api/webstore_private/webstore_private_api.cc index 87b98ae..e1069be 100644 --- a/chrome/browser/extensions/api/webstore_private/webstore_private_api.cc +++ b/chrome/browser/extensions/api/webstore_private/webstore_private_api.cc @@ -4,6 +4,7 @@ #include "chrome/browser/extensions/api/webstore_private/webstore_private_api.h" +#include "apps/app_launcher.h" #include "base/bind_helpers.h" #include "base/command_line.h" #include "base/lazy_instance.h" @@ -14,7 +15,6 @@ #include "base/values.h" #include "chrome/browser/about_flags.h" #include "chrome/browser/browser_process.h" -#include "chrome/browser/extensions/app_launcher.h" #include "chrome/browser/extensions/crx_installer.h" #include "chrome/browser/extensions/extension_function_dispatcher.h" #include "chrome/browser/extensions/extension_prefs.h" @@ -458,7 +458,7 @@ bool CompleteInstallFunction::RunImpl() { } void CompleteInstallFunction::AfterMaybeInstallAppLauncher(bool ok) { - UpdateIsAppLauncherEnabled(base::Bind( + apps::GetIsAppLauncherEnabled(base::Bind( &CompleteInstallFunction::OnGetAppLauncherEnabled, this, approval_->extension_id)); } @@ -580,7 +580,7 @@ void GetWebGLStatusFunction::OnFeatureCheck(bool feature_allowed) { } bool GetIsLauncherEnabledFunction::RunImpl() { - UpdateIsAppLauncherEnabled(base::Bind( + apps::GetIsAppLauncherEnabled(base::Bind( &GetIsLauncherEnabledFunction::OnIsLauncherCheckCompleted, this)); return true; } diff --git a/chrome/browser/extensions/app_launcher.cc b/chrome/browser/extensions/app_launcher.cc deleted file mode 100644 index 5ca6fbf..0000000 --- a/chrome/browser/extensions/app_launcher.cc +++ /dev/null @@ -1,121 +0,0 @@ -// Copyright (c) 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/extensions/app_launcher.h" - -#include "base/command_line.h" -#include "base/prefs/pref_registry_simple.h" -#include "base/prefs/pref_service.h" -#include "base/threading/sequenced_worker_pool.h" -#include "chrome/browser/browser_process.h" -#include "chrome/common/chrome_switches.h" -#include "chrome/common/pref_names.h" -#include "content/public/browser/browser_thread.h" - -#if defined(OS_WIN) -#include "chrome/installer/launcher_support/chrome_launcher_support.h" -#include "chrome/installer/util/browser_distribution.h" -#endif - -namespace extensions { - -namespace { - -#if defined(OS_WIN) -void UpdatePrefAndCallCallbackOnUI( - bool result, - const OnAppLauncherEnabledCompleted& completion_callback) { - PrefService* prefs = g_browser_process->local_state(); - prefs->SetBoolean(prefs::kAppLauncherIsEnabled, result); - completion_callback.Run(result); -} - -void IsAppLauncherInstalledOnBlockingPool( - const OnAppLauncherEnabledCompleted& completion_callback) { - DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); - bool result = chrome_launcher_support::IsAppLauncherPresent(); - content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, - base::Bind(UpdatePrefAndCallCallbackOnUI, result, completion_callback)); -} -#endif - -} // namespace - -enum AppLauncherState { - APP_LAUNCHER_UNKNOWN, - APP_LAUNCHER_ENABLED, - APP_LAUNCHER_DISABLED, -}; - -AppLauncherState SynchronousAppLauncherChecks() { -#if defined(USE_ASH) - return APP_LAUNCHER_ENABLED; -#elif !defined(OS_WIN) - return APP_LAUNCHER_DISABLED; -#else - if (CommandLine::ForCurrentProcess()->HasSwitch( - switches::kShowAppListShortcut)) { - return APP_LAUNCHER_ENABLED; - } - - if (!BrowserDistribution::GetDistribution()->AppHostIsSupported()) - return APP_LAUNCHER_DISABLED; - - return APP_LAUNCHER_UNKNOWN; -#endif -} - -void UpdateIsAppLauncherEnabled( - const OnAppLauncherEnabledCompleted& completion_callback) { - DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); - - AppLauncherState state = SynchronousAppLauncherChecks(); - - if (state != APP_LAUNCHER_UNKNOWN) { - bool is_enabled = state == APP_LAUNCHER_ENABLED; - PrefService* prefs = g_browser_process->local_state(); - prefs->SetBoolean(prefs::kAppLauncherIsEnabled, is_enabled); - completion_callback.Run(is_enabled); - return; - } - -#if defined(OS_WIN) - content::BrowserThread::PostBlockingPoolTask( - FROM_HERE, - base::Bind(&IsAppLauncherInstalledOnBlockingPool, - completion_callback)); -#else - // SynchronousAppLauncherChecks() never returns APP_LAUNCHER_UNKNOWN on - // !defined(OS_WIN), so this path is never reached. - NOTREACHED(); -#endif -} - -bool IsAppLauncherEnabled() { - PrefService* prefs = g_browser_process->local_state(); - // In some tests, the prefs aren't initialised, but the NTP still needs to - // work. - if (!prefs) - return SynchronousAppLauncherChecks() == APP_LAUNCHER_ENABLED; - return prefs->GetBoolean(prefs::kAppLauncherIsEnabled); -} - -namespace app_launcher { - -void RegisterPrefs(PrefRegistrySimple* registry) { - // If it is impossible to synchronously determine whether the app launcher is - // enabled, assume it is disabled. Anything that needs to know the absolute - // truth should call UpdateIsAppLauncherEnabled(). - // - // This pref is just a cache of the value from the registry from last time - // Chrome ran. To avoid having the NTP block on a registry check, it guesses - // that the value hasn't changed since last time it was checked, using this - // preference. - bool is_enabled = SynchronousAppLauncherChecks() == APP_LAUNCHER_ENABLED; - registry->RegisterBooleanPref(prefs::kAppLauncherIsEnabled, is_enabled); -} - -} // namespace app_launcher - -} // namespace extensions diff --git a/chrome/browser/extensions/app_launcher.h b/chrome/browser/extensions/app_launcher.h deleted file mode 100644 index 5d07673..0000000 --- a/chrome/browser/extensions/app_launcher.h +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright (c) 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_EXTENSIONS_APP_LAUNCHER_H_ -#define CHROME_BROWSER_EXTENSIONS_APP_LAUNCHER_H_ - -#include "base/basictypes.h" -#include "base/callback_forward.h" - -class PrefRegistrySimple; - -namespace extensions { - -// Called on the UI thread after determining if the launcher is enabled. A -// boolean flag is passed, which is true if the app launcher is enabled. -typedef base::Callback<void(bool)> OnAppLauncherEnabledCompleted; - -// Determine whether the app launcher is enabled or not. This may involve a trip -// to a blocking thread. |completion_callback| is called when an answer is -// ready. This needs to be called on the UI thread. -void UpdateIsAppLauncherEnabled( - const OnAppLauncherEnabledCompleted& completion_callback); - -// returns value of pref. 'was app launcher enabled last time i checked'. -bool IsAppLauncherEnabled(); - -namespace app_launcher { -void RegisterPrefs(PrefRegistrySimple* registry); -} - -} // namespace extensions - -#endif // CHROME_BROWSER_EXTENSIONS_APP_LAUNCHER_H_ diff --git a/chrome/browser/extensions/extension_install_ui_android.cc b/chrome/browser/extensions/extension_install_ui_android.cc deleted file mode 100644 index 22f0be1..0000000 --- a/chrome/browser/extensions/extension_install_ui_android.cc +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/extensions/extension_install_ui_android.h" - -#include "base/logging.h" -#include "chrome/browser/extensions/extension_install_prompt.h" -#include "chrome/browser/profiles/profile.h" -#include "content/public/browser/web_contents.h" - -void ExtensionInstallUIAndroid::OnInstallSuccess( - const extensions::Extension* extension, SkBitmap* icon) { - NOTIMPLEMENTED(); -} - -void ExtensionInstallUIAndroid::OnInstallFailure( - const extensions::CrxInstallerError& error) { - NOTIMPLEMENTED(); -} - -void ExtensionInstallUIAndroid::SetSkipPostInstallUI(bool skip_ui) { - NOTIMPLEMENTED(); -} - -// static -ExtensionInstallUI* ExtensionInstallUI::Create(Profile* profile) { - NOTIMPLEMENTED(); - return NULL; -} - -// static -void ExtensionInstallUI::OpenAppInstalledUI( - Browser* browser, const std::string& app_id) { - NOTIMPLEMENTED(); -} - -// static -void ExtensionInstallUI::DisableFailureUIForTests() { - NOTIMPLEMENTED(); -} - -// static -ExtensionInstallPrompt* ExtensionInstallUI::CreateInstallPromptWithBrowser( - Browser* browser) { - NOTIMPLEMENTED(); - return NULL; -} - -// static -ExtensionInstallPrompt* ExtensionInstallUI::CreateInstallPromptWithProfile( - Profile* profile) { - NOTIMPLEMENTED(); - return NULL; -} diff --git a/chrome/browser/extensions/extension_install_ui_android.h b/chrome/browser/extensions/extension_install_ui_android.h deleted file mode 100644 index 84bfa24..0000000 --- a/chrome/browser/extensions/extension_install_ui_android.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_INSTALL_UI_ANDROID_H_ -#define CHROME_BROWSER_EXTENSIONS_EXTENSION_INSTALL_UI_ANDROID_H_ - -#include "chrome/browser/extensions/extension_install_ui.h" - -class ExtensionInstallUIAndroid : public ExtensionInstallUI { - public: - ExtensionInstallUIAndroid(); - virtual ~ExtensionInstallUIAndroid(); - - // ExtensionInstallUI implementation: - virtual void OnInstallSuccess(const extensions::Extension* extension, - SkBitmap* icon) OVERRIDE; - virtual void OnInstallFailure( - const extensions::CrxInstallerError& error) OVERRIDE; - virtual void SetSkipPostInstallUI(bool skip_ui) OVERRIDE; - - private: - DISALLOW_COPY_AND_ASSIGN(ExtensionInstallUIAndroid); -}; - -#endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_INSTALL_UI_ANDROID_H_ diff --git a/chrome/browser/extensions/extension_install_ui_default.cc b/chrome/browser/extensions/extension_install_ui_default.cc deleted file mode 100644 index 5fb4c15..0000000 --- a/chrome/browser/extensions/extension_install_ui_default.cc +++ /dev/null @@ -1,273 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/extensions/extension_install_ui_default.h" - -#include "base/bind.h" -#include "base/command_line.h" -#include "base/utf_string_conversions.h" -#include "chrome/browser/api/infobars/confirm_infobar_delegate.h" -#include "chrome/browser/api/infobars/infobar_service.h" -#include "chrome/browser/extensions/app_launcher.h" -#include "chrome/browser/extensions/extension_install_prompt.h" -#include "chrome/browser/extensions/theme_installed_infobar_delegate.h" -#include "chrome/browser/profiles/profile.h" -#include "chrome/browser/themes/theme_service.h" -#include "chrome/browser/themes/theme_service_factory.h" -#include "chrome/browser/ui/app_list/app_list_util.h" -#include "chrome/browser/ui/browser.h" -#include "chrome/browser/ui/browser_dialogs.h" -#include "chrome/browser/ui/browser_finder.h" -#include "chrome/browser/ui/browser_navigator.h" -#include "chrome/browser/ui/browser_tabstrip.h" -#include "chrome/browser/ui/browser_window.h" -#include "chrome/browser/ui/host_desktop.h" -#include "chrome/browser/ui/simple_message_box.h" -#include "chrome/browser/ui/singleton_tabs.h" -#include "chrome/browser/ui/tabs/tab_strip_model.h" -#include "chrome/browser/ui/webui/ntp/new_tab_ui.h" -#include "chrome/common/chrome_notification_types.h" -#include "chrome/common/chrome_switches.h" -#include "chrome/common/extensions/extension.h" -#include "chrome/common/url_constants.h" -#include "content/public/browser/browser_thread.h" -#include "content/public/browser/notification_service.h" -#include "content/public/browser/web_contents.h" -#include "grit/generated_resources.h" -#include "grit/theme_resources.h" -#include "ui/base/l10n/l10n_util.h" -#include "ui/base/resource/resource_bundle.h" - -#if defined(USE_ASH) -#include "ash/shell.h" -#endif - -using content::BrowserThread; -using content::WebContents; -using extensions::Extension; - -namespace { - -bool disable_failure_ui_for_tests = false; - -// Helper class to put up an infobar when installation fails. -class ErrorInfobarDelegate : public ConfirmInfoBarDelegate { - public: - // Creates an error delegate and adds it to |infobar_service|. - static void Create(InfoBarService* infobar_service, - Browser* browser, - const extensions::CrxInstallerError& error); - - private: - ErrorInfobarDelegate(InfoBarService* infobar_service, - Browser* browser, - const extensions::CrxInstallerError& error) - : ConfirmInfoBarDelegate(infobar_service), - browser_(browser), - error_(error) { - } - - virtual string16 GetMessageText() const OVERRIDE { - return error_.message(); - } - - virtual int GetButtons() const OVERRIDE { - return BUTTON_OK; - } - - virtual string16 GetLinkText() const OVERRIDE { - return error_.type() == extensions::CrxInstallerError::ERROR_OFF_STORE ? - l10n_util::GetStringUTF16(IDS_LEARN_MORE) : ASCIIToUTF16(""); - } - - virtual bool LinkClicked(WindowOpenDisposition disposition) OVERRIDE { - chrome::NavigateParams params( - browser_, - GURL("http://support.google.com/chrome_webstore/?p=crx_warning"), - content::PAGE_TRANSITION_LINK); - params.disposition = NEW_FOREGROUND_TAB; - chrome::Navigate(¶ms); - return false; - } - - Browser* browser_; - extensions::CrxInstallerError error_; -}; - -// static -void ErrorInfobarDelegate::Create(InfoBarService* infobar_service, - Browser* browser, - const extensions::CrxInstallerError& error) { - infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>( - new ErrorInfobarDelegate(infobar_service, browser, error))); -} - -void OnAppLauncherEnabledCompleted(const extensions::Extension* extension, - Browser* browser, - SkBitmap* icon, - bool use_bubble, - bool use_launcher) { -#if defined(ENABLE_APP_LIST) - if (use_launcher) { - chrome::ShowAppList(browser->profile()); - - content::NotificationService::current()->Notify( - chrome::NOTIFICATION_APP_INSTALLED_TO_APPLIST, - content::Source<Profile>(browser->profile()), - content::Details<const std::string>(&extension->id())); - return; - } -#endif - - if (use_bubble) { - chrome::ShowExtensionInstalledBubble(extension, browser, *icon); - return; - } - - ExtensionInstallUI::OpenAppInstalledUI(browser, extension->id()); -} - -} // namespace - -ExtensionInstallUIDefault::ExtensionInstallUIDefault(Profile* profile) - : skip_post_install_ui_(false), - previous_using_native_theme_(false), - use_app_installed_bubble_(false) { - profile_ = profile; - - // |profile_| can be NULL during tests. - if (profile_) { - // Remember the current theme in case the user presses undo. - const Extension* previous_theme = - ThemeServiceFactory::GetThemeForProfile(profile); - if (previous_theme) - previous_theme_id_ = previous_theme->id(); - previous_using_native_theme_ = - ThemeServiceFactory::GetForProfile(profile)->UsingNativeTheme(); - } -} - -ExtensionInstallUIDefault::~ExtensionInstallUIDefault() { -} - -void ExtensionInstallUIDefault::OnInstallSuccess(const Extension* extension, - SkBitmap* icon) { - if (skip_post_install_ui_) - return; - - if (!profile_) { - // TODO(zelidrag): Figure out what exact conditions cause crash - // http://crbug.com/159437 and write browser test to cover it. - NOTREACHED(); - return; - } - - if (extension->is_theme()) { - ThemeInstalledInfoBarDelegate::Create( - extension, profile_, previous_theme_id_, previous_using_native_theme_); - return; - } - - // Extensions aren't enabled by default in incognito so we confirm - // the install in a normal window. - Profile* current_profile = profile_->GetOriginalProfile(); - Browser* browser = - chrome::FindOrCreateTabbedBrowser(current_profile, - chrome::GetActiveDesktop()); - if (browser->tab_strip_model()->count() == 0) - chrome::AddBlankTabAt(browser, -1, true); - browser->window()->Show(); - - if (extension->is_app()) { - bool use_bubble = false; - -#if defined(TOOLKIT_VIEWS) || defined(OS_MACOSX) - CommandLine* cmdline = CommandLine::ForCurrentProcess(); - use_bubble = (use_app_installed_bubble_ || - cmdline->HasSwitch(switches::kAppsNewInstallBubble)); -#endif - - extensions::UpdateIsAppLauncherEnabled( - base::Bind(&OnAppLauncherEnabledCompleted, extension, browser, icon, - use_bubble)); - return; - } - - chrome::ShowExtensionInstalledBubble(extension, browser, *icon); -} - -void ExtensionInstallUIDefault::OnInstallFailure( - const extensions::CrxInstallerError& error) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - if (disable_failure_ui_for_tests || skip_post_install_ui_) - return; - - Browser* browser = chrome::FindLastActiveWithProfile(profile_, - chrome::GetActiveDesktop()); - if (!browser) // unit tests - return; - WebContents* web_contents = - browser->tab_strip_model()->GetActiveWebContents(); - if (!web_contents) - return; - ErrorInfobarDelegate::Create(InfoBarService::FromWebContents(web_contents), - browser, error); -} - -void ExtensionInstallUIDefault::SetSkipPostInstallUI(bool skip_ui) { - skip_post_install_ui_ = skip_ui; -} - -void ExtensionInstallUIDefault::SetUseAppInstalledBubble(bool use_bubble) { - use_app_installed_bubble_ = use_bubble; -} - -// static -ExtensionInstallUI* ExtensionInstallUI::Create(Profile* profile) { - return new ExtensionInstallUIDefault(profile); -} - -// static -void ExtensionInstallUI::OpenAppInstalledUI(Browser* browser, - const std::string& app_id) { -#if defined(OS_CHROMEOS) - chrome::ShowAppList(browser->profile()); - - content::NotificationService::current()->Notify( - chrome::NOTIFICATION_APP_INSTALLED_TO_APPLIST, - content::Source<Profile>(browser->profile()), - content::Details<const std::string>(&app_id)); -#else - chrome::NavigateParams params(chrome::GetSingletonTabNavigateParams( - browser, GURL(chrome::kChromeUINewTabURL))); - chrome::Navigate(¶ms); - - content::NotificationService::current()->Notify( - chrome::NOTIFICATION_APP_INSTALLED_TO_NTP, - content::Source<WebContents>(params.target_contents), - content::Details<const std::string>(&app_id)); -#endif -} - -// static -void ExtensionInstallUI::DisableFailureUIForTests() { - disable_failure_ui_for_tests = true; -} - -// static -ExtensionInstallPrompt* ExtensionInstallUI::CreateInstallPromptWithBrowser( - Browser* browser) { - content::WebContents* web_contents = NULL; - if (browser) - web_contents = browser->tab_strip_model()->GetActiveWebContents(); - return new ExtensionInstallPrompt(web_contents); -} - -// static -ExtensionInstallPrompt* ExtensionInstallUI::CreateInstallPromptWithProfile( - Profile* profile) { - Browser* browser = chrome::FindLastActiveWithProfile(profile, - chrome::GetActiveDesktop()); - return CreateInstallPromptWithBrowser(browser); -} diff --git a/chrome/browser/extensions/extension_install_ui_default.h b/chrome/browser/extensions/extension_install_ui_default.h deleted file mode 100644 index 5c719b9..0000000 --- a/chrome/browser/extensions/extension_install_ui_default.h +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_INSTALL_UI_DEFAULT_H_ -#define CHROME_BROWSER_EXTENSIONS_EXTENSION_INSTALL_UI_DEFAULT_H_ - -#include "chrome/browser/extensions/extension_install_ui.h" - -class InfoBarDelegate; -class Profile; - -namespace content { -class WebContents; -} - -class ExtensionInstallUIDefault : public ExtensionInstallUI { - public: - explicit ExtensionInstallUIDefault(Profile* profile); - virtual ~ExtensionInstallUIDefault(); - - // ExtensionInstallUI implementation: - virtual void OnInstallSuccess(const extensions::Extension* extension, - SkBitmap* icon) OVERRIDE; - virtual void OnInstallFailure( - const extensions::CrxInstallerError& error) OVERRIDE; - virtual void SetSkipPostInstallUI(bool skip_ui) OVERRIDE; - virtual void SetUseAppInstalledBubble(bool use_bubble) OVERRIDE; - - private: - // Whether or not to show the default UI after completing the installation. - bool skip_post_install_ui_; - - // Used to undo theme installation. - std::string previous_theme_id_; - bool previous_using_native_theme_; - - // Whether to show an installed bubble on app install, or use the default - // action of opening a new tab page. - bool use_app_installed_bubble_; - - DISALLOW_IMPLICIT_CONSTRUCTORS(ExtensionInstallUIDefault); -}; - -#endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_INSTALL_UI_DEFAULT_H_ |