From dc63aab9a03d091b4c88a0967d19f52a61212e16 Mon Sep 17 00:00:00 2001 From: "benwells@chromium.org" Date: Tue, 12 Feb 2013 06:15:10 +0000 Subject: Move app_launcher.* out of chrome/browser/extensions and into apps/ This change also moves some UI code from chrome/browser/extensions into /chrome/browser/ui/, and cleans up the app_launcher.* code. BUG=159366 Review URL: https://chromiumcodereview.appspot.com/12095052 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@181875 0039d316-1c4b-4281-b951-d872f2087c98 --- apps/DEPS | 6 +- apps/app_launcher.cc | 107 ++++++++ apps/app_launcher.h | 38 +++ apps/apps.gypi | 6 + apps/pref_names.cc | 17 ++ apps/pref_names.h | 18 ++ apps/prefs.cc | 25 ++ apps/prefs.h | 17 ++ chrome/browser/extensions/api/DEPS | 3 + .../api/webstore_private/webstore_private_api.cc | 6 +- chrome/browser/extensions/app_launcher.cc | 121 --------- chrome/browser/extensions/app_launcher.h | 34 --- .../extensions/extension_install_ui_android.cc | 55 ----- .../extensions/extension_install_ui_android.h | 26 -- .../extensions/extension_install_ui_default.cc | 273 --------------------- .../extensions/extension_install_ui_default.h | 45 ---- chrome/browser/prefs/browser_prefs.cc | 4 +- .../extensions/extension_install_ui_android.cc | 55 +++++ .../extensions/extension_install_ui_android.h | 26 ++ .../ui/extensions/extension_install_ui_default.cc | 273 +++++++++++++++++++++ .../ui/extensions/extension_install_ui_default.h | 45 ++++ .../browser/ui/webui/ntp/new_tab_page_handler.cc | 4 +- chrome/browser/ui/webui/ntp/new_tab_ui.cc | 6 +- chrome/browser/ui/webui/ntp/ntp_resource_cache.cc | 4 +- chrome/chrome_browser_extensions.gypi | 8 - chrome/chrome_browser_ui.gypi | 6 + chrome/common/pref_names.cc | 4 - chrome/common/pref_names.h | 2 - 28 files changed, 654 insertions(+), 580 deletions(-) create mode 100644 apps/app_launcher.cc create mode 100644 apps/app_launcher.h create mode 100644 apps/pref_names.cc create mode 100644 apps/pref_names.h create mode 100644 apps/prefs.cc create mode 100644 apps/prefs.h create mode 100644 chrome/browser/extensions/api/DEPS delete mode 100644 chrome/browser/extensions/app_launcher.cc delete mode 100644 chrome/browser/extensions/app_launcher.h delete mode 100644 chrome/browser/extensions/extension_install_ui_android.cc delete mode 100644 chrome/browser/extensions/extension_install_ui_android.h delete mode 100644 chrome/browser/extensions/extension_install_ui_default.cc delete mode 100644 chrome/browser/extensions/extension_install_ui_default.h create mode 100644 chrome/browser/ui/android/extensions/extension_install_ui_android.cc create mode 100644 chrome/browser/ui/android/extensions/extension_install_ui_android.h create mode 100644 chrome/browser/ui/extensions/extension_install_ui_default.cc create mode 100644 chrome/browser/ui/extensions/extension_install_ui_default.h diff --git a/apps/DEPS b/apps/DEPS index 980e672..0fc9ed2 100644 --- a/apps/DEPS +++ b/apps/DEPS @@ -2,9 +2,13 @@ include_rules = [ "+base", "+content", # Temporary allowed includes. - # TODO(benwells): remove these. + # TODO(benwells): remove these (http://crbug.com/159366) + "+chrome/browser/browser_process.h", "+chrome/browser/extensions", + "+chrome/browser/prefs", "+chrome/browser/profiles", "+chrome/common/chrome_notification_types.h", + "+chrome/common/chrome_switches.h", "+chrome/common/extensions", + "+chrome/installer", ] diff --git a/apps/app_launcher.cc b/apps/app_launcher.cc new file mode 100644 index 0000000..73011bc --- /dev/null +++ b/apps/app_launcher.cc @@ -0,0 +1,107 @@ +// Copyright 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 "apps/app_launcher.h" + +#include "apps/pref_names.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 "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 apps { + +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 +} + +#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 + +bool MaybeIsAppLauncherEnabled() { + return SynchronousAppLauncherChecks() == APP_LAUNCHER_ENABLED; +} + +void GetIsAppLauncherEnabled( + 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 WasAppLauncherEnabled() { + PrefService* prefs = g_browser_process->local_state(); + // In some tests, the prefs aren't initialised. + if (!prefs) + return SynchronousAppLauncherChecks() == APP_LAUNCHER_ENABLED; + return prefs->GetBoolean(prefs::kAppLauncherIsEnabled); +} + +} // namespace apps diff --git a/apps/app_launcher.h b/apps/app_launcher.h new file mode 100644 index 0000000..b6bbed3 --- /dev/null +++ b/apps/app_launcher.h @@ -0,0 +1,38 @@ +// Copyright 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_APPS_APP_LAUNCHER_H_ +#define CHROME_APPS_APP_LAUNCHER_H_ + +#include "base/basictypes.h" +#include "base/callback_forward.h" + +class PrefRegistrySimple; + +namespace apps { + +// 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 OnAppLauncherEnabledCompleted; + +// A synchronous check to determine if the app launcher is enabled. If the +// registry needs to be determined to find an accurate answer, this function +// will NOT do so; instead if will default to false (the app launcher is not +// enabled). +// This function does not use the cached preference of whether the launcher +// was enabled or not. +bool MaybeIsAppLauncherEnabled(); + +// 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 GetIsAppLauncherEnabled( + const OnAppLauncherEnabledCompleted& completion_callback); + +// Returns whether the app launcher was enabled the last time it was checked. +bool WasAppLauncherEnabled(); + +} // namespace extensions + +#endif // CHROME_APPS_APP_LAUNCHER_H_ diff --git a/apps/apps.gypi b/apps/apps.gypi index 43f9cc5..257195d 100644 --- a/apps/apps.gypi +++ b/apps/apps.gypi @@ -22,10 +22,16 @@ '<(INTERMEDIATE_DIR)', ], 'sources': [ + 'app_launcher.cc', + 'app_launcher.h', 'app_restore_service.cc', 'app_restore_service.h', 'app_restore_service_factory.cc', 'app_restore_service_factory.h', + 'pref_names.cc', + 'pref_names.h', + 'prefs.cc', + 'prefs.h', ], 'conditions': [ ['enable_extensions==0', { diff --git a/apps/pref_names.cc b/apps/pref_names.cc new file mode 100644 index 0000000..15a33f9 --- /dev/null +++ b/apps/pref_names.cc @@ -0,0 +1,17 @@ +// Copyright 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 "apps/pref_names.h" + +namespace apps { + +namespace prefs { + +// Local state caching knowledge of whether the app launcher is installed. +const char kAppLauncherIsEnabled[] = + "apps.app_launcher.should_show_apps_page"; + +} // namespace prefs + +} // namespace apps diff --git a/apps/pref_names.h b/apps/pref_names.h new file mode 100644 index 0000000..1cca82f --- /dev/null +++ b/apps/pref_names.h @@ -0,0 +1,18 @@ +// Copyright 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 APPS_PREF_NAMES_H_ +#define APPS_PREF_NAMES_H_ + +namespace apps { + +namespace prefs { + +extern const char kAppLauncherIsEnabled[]; + +} // namespace prefs + +} // namespace apps + +#endif // APPS_PREF_NAMES_H_ diff --git a/apps/prefs.cc b/apps/prefs.cc new file mode 100644 index 0000000..b883fbb --- /dev/null +++ b/apps/prefs.cc @@ -0,0 +1,25 @@ +// Copyright 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 "apps/prefs.h" + +#include "apps/app_launcher.h" +#include "apps/pref_names.h" +#include "base/prefs/pref_registry_simple.h" + +namespace apps { + +void RegisterPrefs(PrefRegistrySimple* registry) { + // This pref is a cache of the value from the registry the last time it was + // checked. + // + // During the pref initialization, 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 + // GetIsAppLauncherEnabled(). + registry->RegisterBooleanPref(prefs::kAppLauncherIsEnabled, + MaybeIsAppLauncherEnabled()); +} + +} // namespace apps diff --git a/apps/prefs.h b/apps/prefs.h new file mode 100644 index 0000000..3734860 --- /dev/null +++ b/apps/prefs.h @@ -0,0 +1,17 @@ +// Copyright 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 APPS_PREFS_H_ +#define APPS_PREFS_H_ + +class PrefRegistrySimple; + +namespace apps { + +// Register preferences for the apps system. +void RegisterPrefs(PrefRegistrySimple* registry); + +} // namespace apps + +#endif // APPS_PREFS_H_ 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 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( - 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(browser->profile()), - content::Details(&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(browser->profile()), - content::Details(&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(params.target_contents), - content::Details(&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_ diff --git a/chrome/browser/prefs/browser_prefs.cc b/chrome/browser/prefs/browser_prefs.cc index 2f708c7..9e1c2c1 100644 --- a/chrome/browser/prefs/browser_prefs.cc +++ b/chrome/browser/prefs/browser_prefs.cc @@ -4,6 +4,7 @@ #include "chrome/browser/prefs/browser_prefs.h" +#include "apps/prefs.h" #include "base/prefs/pref_registry_simple.h" #include "base/prefs/pref_service.h" #include "chrome/browser/about_flags.h" @@ -21,7 +22,6 @@ #include "chrome/browser/download/download_prefs.h" #include "chrome/browser/extensions/api/commands/command_service.h" #include "chrome/browser/extensions/api/tabs/tabs_api.h" -#include "chrome/browser/extensions/app_launcher.h" #include "chrome/browser/extensions/component_loader.h" #include "chrome/browser/extensions/extension_prefs.h" #include "chrome/browser/extensions/extension_web_ui.h" @@ -159,10 +159,10 @@ void RegisterLocalState(PrefService* local_state, registry->RegisterIntegerPref(prefs::kMultipleProfilePrefMigration, 0); // Please keep this list alphabetized. + apps::RegisterPrefs(registry); browser_shutdown::RegisterPrefs(registry); BrowserProcessImpl::RegisterPrefs(registry); chrome::RegisterScreenshotPrefs(registry); - extensions::app_launcher::RegisterPrefs(registry); ExternalProtocolHandler::RegisterPrefs(registry); FlagsUI::RegisterPrefs(registry); geolocation::RegisterPrefs(registry); diff --git a/chrome/browser/ui/android/extensions/extension_install_ui_android.cc b/chrome/browser/ui/android/extensions/extension_install_ui_android.cc new file mode 100644 index 0000000..af476e0 --- /dev/null +++ b/chrome/browser/ui/android/extensions/extension_install_ui_android.cc @@ -0,0 +1,55 @@ +// 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/ui/android/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/ui/android/extensions/extension_install_ui_android.h b/chrome/browser/ui/android/extensions/extension_install_ui_android.h new file mode 100644 index 0000000..96d79dd4 --- /dev/null +++ b/chrome/browser/ui/android/extensions/extension_install_ui_android.h @@ -0,0 +1,26 @@ +// 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_UI_ANDROID_EXTENSIONS_EXTENSION_INSTALL_UI_ANDROID_H_ +#define CHROME_BROWSER_UI_ANDROID_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_UI_ANDROID_EXTENSIONS_EXTENSION_INSTALL_UI_ANDROID_H_ diff --git a/chrome/browser/ui/extensions/extension_install_ui_default.cc b/chrome/browser/ui/extensions/extension_install_ui_default.cc new file mode 100644 index 0000000..e8bd56f --- /dev/null +++ b/chrome/browser/ui/extensions/extension_install_ui_default.cc @@ -0,0 +1,273 @@ +// 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/ui/extensions/extension_install_ui_default.h" + +#include "apps/app_launcher.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/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( + 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(browser->profile()), + content::Details(&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 + + apps::GetIsAppLauncherEnabled( + 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(browser->profile()), + content::Details(&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(params.target_contents), + content::Details(&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/ui/extensions/extension_install_ui_default.h b/chrome/browser/ui/extensions/extension_install_ui_default.h new file mode 100644 index 0000000..a465d5d --- /dev/null +++ b/chrome/browser/ui/extensions/extension_install_ui_default.h @@ -0,0 +1,45 @@ +// 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_UI_EXTENSIONS_EXTENSION_INSTALL_UI_DEFAULT_H_ +#define CHROME_BROWSER_UI_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_UI_EXTENSIONS_EXTENSION_INSTALL_UI_DEFAULT_H_ diff --git a/chrome/browser/ui/webui/ntp/new_tab_page_handler.cc b/chrome/browser/ui/webui/ntp/new_tab_page_handler.cc index 31f18cb..78973b6 100644 --- a/chrome/browser/ui/webui/ntp/new_tab_page_handler.cc +++ b/chrome/browser/ui/webui/ntp/new_tab_page_handler.cc @@ -4,12 +4,12 @@ #include "chrome/browser/ui/webui/ntp/new_tab_page_handler.h" +#include "apps/app_launcher.h" #include "base/bind.h" #include "base/bind_helpers.h" #include "base/memory/scoped_ptr.h" #include "base/metrics/histogram.h" #include "base/prefs/pref_service.h" -#include "chrome/browser/extensions/app_launcher.h" #include "chrome/browser/prefs/pref_registry_syncable.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/sync/profile_sync_service.h" @@ -173,7 +173,7 @@ void NewTabPageHandler::HandleLogTimeToClick(const ListValue* args) { } void NewTabPageHandler::HandleGetShouldShowApps(const ListValue* args) { - extensions::UpdateIsAppLauncherEnabled( + apps::GetIsAppLauncherEnabled( base::Bind(&NewTabPageHandler::GotIsAppLauncherEnabled, AsWeakPtr())); } diff --git a/chrome/browser/ui/webui/ntp/new_tab_ui.cc b/chrome/browser/ui/webui/ntp/new_tab_ui.cc index 0808c47..968be06 100644 --- a/chrome/browser/ui/webui/ntp/new_tab_ui.cc +++ b/chrome/browser/ui/webui/ntp/new_tab_ui.cc @@ -8,6 +8,7 @@ #include +#include "apps/app_launcher.h" #include "base/bind.h" #include "base/bind_helpers.h" #include "base/command_line.h" @@ -20,7 +21,6 @@ #include "base/threading/thread.h" #include "base/utf_string_conversions.h" #include "chrome/browser/defaults.h" -#include "chrome/browser/extensions/app_launcher.h" #include "chrome/browser/prefs/pref_registry_syncable.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/sessions/session_types.h" @@ -300,7 +300,9 @@ bool NewTabUI::ShouldShowApps() { // Android does not have apps. return false; #else - return !extensions::IsAppLauncherEnabled(); + // This needs to be synchronous, so we use the value the last time it + // was checked. + return !apps::WasAppLauncherEnabled(); #endif } diff --git a/chrome/browser/ui/webui/ntp/ntp_resource_cache.cc b/chrome/browser/ui/webui/ntp/ntp_resource_cache.cc index 3718bf3..983adde 100644 --- a/chrome/browser/ui/webui/ntp/ntp_resource_cache.cc +++ b/chrome/browser/ui/webui/ntp/ntp_resource_cache.cc @@ -7,6 +7,7 @@ #include #include +#include "apps/app_launcher.h" #include "base/command_line.h" #include "base/file_util.h" #include "base/memory/ref_counted_memory.h" @@ -17,7 +18,6 @@ #include "base/utf_string_conversions.h" #include "base/values.h" #include "chrome/browser/browser_process.h" -#include "chrome/browser/extensions/app_launcher.h" #include "chrome/browser/first_run/first_run.h" #include "chrome/browser/google/google_util.h" #include "chrome/browser/policy/browser_policy_connector.h" @@ -194,7 +194,7 @@ bool NTPResourceCache::NewTabCacheNeedsRefresh() { return true; } #endif - bool should_show_apps_page = !extensions::IsAppLauncherEnabled(); + bool should_show_apps_page = !apps::WasAppLauncherEnabled(); if (should_show_apps_page != should_show_apps_page_) { should_show_apps_page_ = should_show_apps_page; return true; diff --git a/chrome/chrome_browser_extensions.gypi b/chrome/chrome_browser_extensions.gypi index 05a036e..9d66d25 100644 --- a/chrome/chrome_browser_extensions.gypi +++ b/chrome/chrome_browser_extensions.gypi @@ -449,8 +449,6 @@ 'browser/extensions/api/webview/webview_api.h', 'browser/extensions/app_host_installer_win.cc', 'browser/extensions/app_host_installer_win.h', - 'browser/extensions/app_launcher.cc', - 'browser/extensions/app_launcher.h', 'browser/extensions/app_notification.cc', 'browser/extensions/app_notification.h', 'browser/extensions/app_notification_manager.cc', @@ -552,8 +550,6 @@ 'browser/extensions/extension_install_prompt.h', 'browser/extensions/extension_install_ui.cc', 'browser/extensions/extension_install_ui.h', - 'browser/extensions/extension_install_ui_default.cc', - 'browser/extensions/extension_install_ui_default.h', 'browser/extensions/extension_keybinding_registry.cc', 'browser/extensions/extension_keybinding_registry.h', 'browser/extensions/extension_pref_store.cc', @@ -900,8 +896,6 @@ 'sources': [ 'browser/extensions/extension_error_ui_android.cc', 'browser/extensions/extension_error_ui_android.h', - 'browser/extensions/extension_install_ui_android.cc', - 'browser/extensions/extension_install_ui_android.h', 'browser/extensions/extension_tab_util_android.cc', ], 'sources!': [ @@ -909,8 +903,6 @@ 'browser/extensions/app_notify_channel_ui_impl.h', 'browser/extensions/extension_error_ui_default.cc', 'browser/extensions/extension_error_ui_default.h', - 'browser/extensions/extension_install_ui_default.cc', - 'browser/extensions/extension_install_ui_default.h', 'browser/extensions/extension_tab_util.cc', 'browser/extensions/platform_app_launcher.cc', 'browser/extensions/platform_app_launcher.h', diff --git a/chrome/chrome_browser_ui.gypi b/chrome/chrome_browser_ui.gypi index 7930fc1..95e0a86 100644 --- a/chrome/chrome_browser_ui.gypi +++ b/chrome/chrome_browser_ui.gypi @@ -74,6 +74,8 @@ 'browser/ui/android/chrome_http_auth_handler.cc', 'browser/ui/android/chrome_http_auth_handler.h', 'browser/ui/android/extensions/extension_install_dialog_android.cc', + 'browser/ui/android/extensions/extension_install_ui_android.cc', + 'browser/ui/android/extensions/extension_install_ui_android.h', 'browser/ui/android/extensions/extension_view_android.cc', 'browser/ui/android/extensions/extension_view_android.h', 'browser/ui/android/external_protocol_dialog_android.cc', @@ -842,6 +844,8 @@ 'browser/ui/crypto_module_password_dialog_openssl.cc', 'browser/ui/extensions/application_launch.cc', 'browser/ui/extensions/application_launch.h', + 'browser/ui/extensions/extension_install_ui_default.cc', + 'browser/ui/extensions/extension_install_ui_default.h', 'browser/ui/extensions/extension_enable_flow.cc', 'browser/ui/extensions/extension_enable_flow.h', 'browser/ui/extensions/extension_enable_flow_delegate.h', @@ -2556,6 +2560,8 @@ 'browser/ui/browser_tabstrip.h', 'browser/ui/chrome_pages.cc', 'browser/ui/chrome_pages.h', + 'browser/ui/extensions/extension_install_ui_default.cc', + 'browser/ui/extensions/extension_install_ui_default.h', 'browser/ui/ntp_background_util.cc', 'browser/ui/ntp_background_util.h', 'browser/ui/sad_tab_helper.cc', diff --git a/chrome/common/pref_names.cc b/chrome/common/pref_names.cc index 3598c92..2cb24e5 100644 --- a/chrome/common/pref_names.cc +++ b/chrome/common/pref_names.cc @@ -1618,10 +1618,6 @@ const char kExtensionInstallForceList[] = "extensions.install.forcelist"; const char kExtensionStorageGarbageCollect[] = "extensions.storage.garbagecollect"; -// Local state caching knowledge of whether the app launcher is installed. -const char kAppLauncherIsEnabled[] = - "extensions.app_launcher.should_show_apps_page"; - // Keeps track of which sessions are collapsed in the Other Devices menu. const char kNtpCollapsedForeignSessions[] = "ntp.collapsed_foreign_sessions"; diff --git a/chrome/common/pref_names.h b/chrome/common/pref_names.h index 4babefb..9a80028 100644 --- a/chrome/common/pref_names.h +++ b/chrome/common/pref_names.h @@ -569,8 +569,6 @@ extern const char kExtensionInstallDenyList[]; extern const char kExtensionInstallForceList[]; extern const char kExtensionStorageGarbageCollect[]; -extern const char kAppLauncherIsEnabled[]; - extern const char kNtpTipsResourceServer[]; extern const char kNtpCollapsedForeignSessions[]; -- cgit v1.1