| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_UI_WEBUI_NTP_APP_LAUNCHER_HANDLER_H_ | 5 #ifndef CHROME_BROWSER_UI_WEBUI_NTP_APP_LAUNCHER_HANDLER_H_ |
| 6 #define CHROME_BROWSER_UI_WEBUI_NTP_APP_LAUNCHER_HANDLER_H_ | 6 #define CHROME_BROWSER_UI_WEBUI_NTP_APP_LAUNCHER_HANDLER_H_ |
| 7 | 7 |
| 8 #include <set> |
| 8 #include <string> | 9 #include <string> |
| 9 | 10 |
| 10 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/prefs/public/pref_change_registrar.h" | 12 #include "base/prefs/public/pref_change_registrar.h" |
| 12 #include "chrome/browser/extensions/extension_install_prompt.h" | 13 #include "chrome/browser/extensions/extension_install_prompt.h" |
| 13 #include "chrome/browser/extensions/extension_uninstall_dialog.h" | 14 #include "chrome/browser/extensions/extension_uninstall_dialog.h" |
| 14 #include "chrome/browser/favicon/favicon_service.h" | 15 #include "chrome/browser/favicon/favicon_service.h" |
| 16 #include "chrome/browser/ui/extensions/extension_enable_flow_delegate.h" |
| 15 #include "chrome/common/cancelable_task_tracker.h" | 17 #include "chrome/common/cancelable_task_tracker.h" |
| 16 #include "chrome/common/extensions/extension.h" | 18 #include "chrome/common/extensions/extension.h" |
| 17 #include "chrome/common/extensions/extension_constants.h" | 19 #include "chrome/common/extensions/extension_constants.h" |
| 18 #include "content/public/browser/notification_observer.h" | 20 #include "content/public/browser/notification_observer.h" |
| 19 #include "content/public/browser/notification_registrar.h" | 21 #include "content/public/browser/notification_registrar.h" |
| 20 #include "content/public/browser/web_ui_message_handler.h" | 22 #include "content/public/browser/web_ui_message_handler.h" |
| 21 #include "sync/api/string_ordinal.h" | 23 #include "sync/api/string_ordinal.h" |
| 22 | 24 |
| 25 class ExtensionEnableFlow; |
| 23 class ExtensionService; | 26 class ExtensionService; |
| 24 class PrefChangeRegistrar; | 27 class PrefChangeRegistrar; |
| 25 class PrefServiceSyncable; | 28 class PrefServiceSyncable; |
| 26 class Profile; | 29 class Profile; |
| 27 | 30 |
| 28 namespace extensions { | 31 namespace extensions { |
| 29 class AppNotification; | 32 class AppNotification; |
| 30 } | 33 } |
| 31 | 34 |
| 32 // The handler for Javascript messages related to the "apps" view. | 35 // The handler for Javascript messages related to the "apps" view. |
| 33 class AppLauncherHandler : public content::WebUIMessageHandler, | 36 class AppLauncherHandler : public content::WebUIMessageHandler, |
| 34 public ExtensionUninstallDialog::Delegate, | 37 public ExtensionUninstallDialog::Delegate, |
| 35 public ExtensionInstallPrompt::Delegate, | 38 public ExtensionEnableFlowDelegate, |
| 36 public content::NotificationObserver { | 39 public content::NotificationObserver { |
| 37 public: | 40 public: |
| 38 explicit AppLauncherHandler(ExtensionService* extension_service); | 41 explicit AppLauncherHandler(ExtensionService* extension_service); |
| 39 virtual ~AppLauncherHandler(); | 42 virtual ~AppLauncherHandler(); |
| 40 | 43 |
| 41 // Populate a dictionary with the information from an extension. | 44 // Populate a dictionary with the information from an extension. |
| 42 static void CreateAppInfo( | 45 static void CreateAppInfo( |
| 43 const extensions::Extension* extension, | 46 const extensions::Extension* extension, |
| 44 const extensions::AppNotification* notification, | 47 const extensions::AppNotification* notification, |
| 45 ExtensionService* service, | 48 ExtensionService* service, |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 std::string escaped_url, | 138 std::string escaped_url, |
| 136 extension_misc::AppLaunchBucket bucket); | 139 extension_misc::AppLaunchBucket bucket); |
| 137 | 140 |
| 138 // Prompts the user to re-enable the app for |extension_id|. | 141 // Prompts the user to re-enable the app for |extension_id|. |
| 139 void PromptToEnableApp(const std::string& extension_id); | 142 void PromptToEnableApp(const std::string& extension_id); |
| 140 | 143 |
| 141 // ExtensionUninstallDialog::Delegate: | 144 // ExtensionUninstallDialog::Delegate: |
| 142 virtual void ExtensionUninstallAccepted() OVERRIDE; | 145 virtual void ExtensionUninstallAccepted() OVERRIDE; |
| 143 virtual void ExtensionUninstallCanceled() OVERRIDE; | 146 virtual void ExtensionUninstallCanceled() OVERRIDE; |
| 144 | 147 |
| 145 // ExtensionInstallPrompt::Delegate: | 148 // ExtensionEnableFlowDelegate: |
| 146 virtual void InstallUIProceed() OVERRIDE; | 149 virtual ExtensionInstallPrompt* CreateExtensionInstallPrompt() OVERRIDE; |
| 147 virtual void InstallUIAbort(bool user_initiated) OVERRIDE; | 150 virtual void ExtensionEnableFlowFinished() OVERRIDE; |
| 151 virtual void ExtensionEnableFlowAborted(bool user_initiated) OVERRIDE; |
| 148 | 152 |
| 149 // Returns the ExtensionUninstallDialog object for this class, creating it if | 153 // Returns the ExtensionUninstallDialog object for this class, creating it if |
| 150 // needed. | 154 // needed. |
| 151 ExtensionUninstallDialog* GetExtensionUninstallDialog(); | 155 ExtensionUninstallDialog* GetExtensionUninstallDialog(); |
| 152 | 156 |
| 153 // Returns the ExtensionInstallPrompt object for this class, creating it if | |
| 154 // needed. | |
| 155 ExtensionInstallPrompt* GetExtensionInstallPrompt(); | |
| 156 | |
| 157 // Continuation for installing a bookmark app after favicon lookup. | 157 // Continuation for installing a bookmark app after favicon lookup. |
| 158 void OnFaviconForApp(scoped_ptr<AppInstallInfo> install_info, | 158 void OnFaviconForApp(scoped_ptr<AppInstallInfo> install_info, |
| 159 const history::FaviconImageResult& image_result); | 159 const history::FaviconImageResult& image_result); |
| 160 | 160 |
| 161 // Sends |highlight_app_id_| to the js. | 161 // Sends |highlight_app_id_| to the js. |
| 162 void SetAppToBeHighlighted(); | 162 void SetAppToBeHighlighted(); |
| 163 | 163 |
| 164 void OnPreferenceChanged(); | 164 void OnPreferenceChanged(); |
| 165 | 165 |
| 166 // The apps are represented in the extensions model, which | 166 // The apps are represented in the extensions model, which |
| 167 // outlives us since it's owned by our containing profile. | 167 // outlives us since it's owned by our containing profile. |
| 168 ExtensionService* const extension_service_; | 168 ExtensionService* const extension_service_; |
| 169 | 169 |
| 170 // We monitor changes to the extension system so that we can reload the apps | 170 // We monitor changes to the extension system so that we can reload the apps |
| 171 // when necessary. | 171 // when necessary. |
| 172 content::NotificationRegistrar registrar_; | 172 content::NotificationRegistrar registrar_; |
| 173 | 173 |
| 174 // Monitor extension preference changes so that the Web UI can be notified. | 174 // Monitor extension preference changes so that the Web UI can be notified. |
| 175 PrefChangeRegistrar pref_change_registrar_; | 175 PrefChangeRegistrar pref_change_registrar_; |
| 176 | 176 |
| 177 // Used to show confirmation UI for uninstalling extensions in incognito mode. | 177 // Used to show confirmation UI for uninstalling extensions in incognito mode. |
| 178 scoped_ptr<ExtensionUninstallDialog> extension_uninstall_dialog_; | 178 scoped_ptr<ExtensionUninstallDialog> extension_uninstall_dialog_; |
| 179 | 179 |
| 180 // Used to show confirmation UI for enabling extensions in incognito mode. | 180 // Used to show confirmation UI for enabling extensions. |
| 181 scoped_ptr<ExtensionInstallPrompt> extension_install_ui_; | 181 scoped_ptr<ExtensionEnableFlow> extension_enable_flow_; |
| 182 | 182 |
| 183 // The ids of apps to show on the NTP. | 183 // The ids of apps to show on the NTP. |
| 184 std::set<std::string> visible_apps_; | 184 std::set<std::string> visible_apps_; |
| 185 | 185 |
| 186 // The id of the extension we are prompting the user about. | 186 // The id of the extension we are prompting the user about (either enable or |
| 187 // uninstall). |
| 187 std::string extension_id_prompting_; | 188 std::string extension_id_prompting_; |
| 188 | 189 |
| 189 // When true, we ignore changes to the underlying data rather than immediately | 190 // When true, we ignore changes to the underlying data rather than immediately |
| 190 // refreshing. This is useful when making many batch updates to avoid flicker. | 191 // refreshing. This is useful when making many batch updates to avoid flicker. |
| 191 bool ignore_changes_; | 192 bool ignore_changes_; |
| 192 | 193 |
| 193 // When true, we have attempted to install a bookmark app, and are still | 194 // When true, we have attempted to install a bookmark app, and are still |
| 194 // waiting to hear about success or failure from the extensions system. | 195 // waiting to hear about success or failure from the extensions system. |
| 195 bool attempted_bookmark_app_install_; | 196 bool attempted_bookmark_app_install_; |
| 196 | 197 |
| 197 // True if we have executed HandleGetApps() at least once. | 198 // True if we have executed HandleGetApps() at least once. |
| 198 bool has_loaded_apps_; | 199 bool has_loaded_apps_; |
| 199 | 200 |
| 200 // The ID of the app to be highlighted on the NTP (i.e. shown on the page | 201 // The ID of the app to be highlighted on the NTP (i.e. shown on the page |
| 201 // and pulsed). This is done for new installs. The actual higlighting occurs | 202 // and pulsed). This is done for new installs. The actual higlighting occurs |
| 202 // when the app is added to the page (via getAppsCallback or appAdded). | 203 // when the app is added to the page (via getAppsCallback or appAdded). |
| 203 std::string highlight_app_id_; | 204 std::string highlight_app_id_; |
| 204 | 205 |
| 205 // Used for favicon loading tasks. | 206 // Used for favicon loading tasks. |
| 206 CancelableTaskTracker cancelable_task_tracker_; | 207 CancelableTaskTracker cancelable_task_tracker_; |
| 207 | 208 |
| 208 DISALLOW_COPY_AND_ASSIGN(AppLauncherHandler); | 209 DISALLOW_COPY_AND_ASSIGN(AppLauncherHandler); |
| 209 }; | 210 }; |
| 210 | 211 |
| 211 #endif // CHROME_BROWSER_UI_WEBUI_NTP_APP_LAUNCHER_HANDLER_H_ | 212 #endif // CHROME_BROWSER_UI_WEBUI_NTP_APP_LAUNCHER_HANDLER_H_ |
| OLD | NEW |