| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 void FillAppDictionary(base::DictionaryValue* value); | 58 void FillAppDictionary(base::DictionaryValue* value); |
| 59 | 59 |
| 60 // Create a dictionary value for the given extension. May return NULL, e.g. if | 60 // Create a dictionary value for the given extension. May return NULL, e.g. if |
| 61 // the given extension is not an app. If non-NULL, the caller assumes | 61 // the given extension is not an app. If non-NULL, the caller assumes |
| 62 // ownership of the pointer. | 62 // ownership of the pointer. |
| 63 base::DictionaryValue* GetAppInfo(const Extension* extension); | 63 base::DictionaryValue* GetAppInfo(const Extension* extension); |
| 64 | 64 |
| 65 // Populate the given dictionary with the web store promo content. | 65 // Populate the given dictionary with the web store promo content. |
| 66 void FillPromoDictionary(base::DictionaryValue* value); | 66 void FillPromoDictionary(base::DictionaryValue* value); |
| 67 | 67 |
| 68 // Callback for the "deleteAppsPage" message. Takes a page index as the first |
| 69 // and only argument. |
| 70 void HandleDeleteAppsPage(const base::ListValue* args); |
| 71 |
| 68 // Callback for the "getApps" message. | 72 // Callback for the "getApps" message. |
| 69 void HandleGetApps(const base::ListValue* args); | 73 void HandleGetApps(const base::ListValue* args); |
| 70 | 74 |
| 71 // Callback for the "launchApp" message. | 75 // Callback for the "launchApp" message. |
| 72 void HandleLaunchApp(const base::ListValue* args); | 76 void HandleLaunchApp(const base::ListValue* args); |
| 73 | 77 |
| 74 // Callback for the "setLaunchType" message. | 78 // Callback for the "setLaunchType" message. |
| 75 void HandleSetLaunchType(const base::ListValue* args); | 79 void HandleSetLaunchType(const base::ListValue* args); |
| 76 | 80 |
| 77 // Callback for the "uninstallApp" message. | 81 // Callback for the "uninstallApp" message. |
| 78 void HandleUninstallApp(const base::ListValue* args); | 82 void HandleUninstallApp(const base::ListValue* args); |
| 79 | 83 |
| 80 // Callback for the "hideAppPromo" message. | 84 // Callback for the "hideAppPromo" message. |
| 81 void HandleHideAppsPromo(const base::ListValue* args); | 85 void HandleHideAppsPromo(const base::ListValue* args); |
| 82 | 86 |
| 83 // Callback for the "createAppShortcut" message. | 87 // Callback for the "createAppShortcut" message. |
| 84 void HandleCreateAppShortcut(const base::ListValue* args); | 88 void HandleCreateAppShortcut(const base::ListValue* args); |
| 85 | 89 |
| 86 // Callback for the "reorderApps" message. | 90 // Callback for the "reorderApps" message. |
| 87 void HandleReorderApps(const base::ListValue* args); | 91 void HandleReorderApps(const base::ListValue* args); |
| 88 | 92 |
| 89 // Callback for the "setPageIndex" message. | 93 // Callback for the "setPageIndex" message. |
| 90 void HandleSetPageIndex(const base::ListValue* args); | 94 void HandleSetPageIndex(const base::ListValue* args); |
| 91 | 95 |
| 92 // Callback for the "promoSeen" message. | 96 // Callback for the "promoSeen" message. |
| 93 void HandlePromoSeen(const base::ListValue* args); | 97 void HandlePromoSeen(const base::ListValue* args); |
| 94 | 98 |
| 95 // Callback for the "saveAppPageName" message. | 99 // Callback for the "saveAppsPageName" message. |
| 96 void HandleSaveAppPageName(const base::ListValue* args); | 100 void HandleSaveAppsPageName(const base::ListValue* args); |
| 97 | 101 |
| 98 // Callback for the "generateAppForLink" message. | 102 // Callback for the "generateAppForLink" message. |
| 99 void HandleGenerateAppForLink(const base::ListValue* args); | 103 void HandleGenerateAppForLink(const base::ListValue* args); |
| 100 | 104 |
| 101 // Callback for the "recordAppLaunchByURL" message. Takes an escaped URL and a | 105 // Callback for the "recordAppLaunchByURL" message. Takes an escaped URL and a |
| 102 // launch source (integer), and if the URL represents an app, records the | 106 // launch source (integer), and if the URL represents an app, records the |
| 103 // action for UMA. | 107 // action for UMA. |
| 104 void HandleRecordAppLaunchByURL(const base::ListValue* args); | 108 void HandleRecordAppLaunchByURL(const base::ListValue* args); |
| 105 | 109 |
| 106 // Callback for "closeNotification" message. | 110 // Callback for "closeNotification" message. |
| 107 void HandleNotificationClose(const base::ListValue* args); | 111 void HandleNotificationClose(const base::ListValue* args); |
| 108 | 112 |
| 109 // Callback for "setNotificationsDisabled" message. | 113 // Callback for "setNotificationsDisabled" message. |
| 110 void HandleSetNotificationsDisabled(const base::ListValue* args); | 114 void HandleSetNotificationsDisabled(const base::ListValue* args); |
| 111 | 115 |
| 112 // Register app launcher preferences. | 116 // Register app launcher preferences. |
| 113 static void RegisterUserPrefs(PrefService* pref_service); | 117 static void RegisterUserPrefs(PrefService* pref_service); |
| 114 | 118 |
| 115 private: | 119 private: |
| 116 struct AppInstallInfo { | 120 struct AppInstallInfo { |
| 117 bool is_bookmark_app; | 121 bool is_bookmark_app; |
| 118 string16 title; | 122 string16 title; |
| 119 GURL app_url; | 123 GURL app_url; |
| 120 int page_index; | 124 int page_index; |
| 121 }; | 125 }; |
| 122 | 126 |
| 127 // Reset some instance flags we use to track the currently uninstalling app. |
| 128 void CleanupAfterUninstall(); |
| 129 |
| 130 // Removes pages with no apps when loading from saved preferences. Does its |
| 131 // best to avoid messing up save apps page names in the process. |
| 132 void CondenseAppsPages(); |
| 133 |
| 134 // Deletes a range of empty apps pages. |
| 135 void DeleteAppsPageRange(const size_t index, const size_t howmany); |
| 136 |
| 137 // Make sure that the app has a valid page index before we do anything with |
| 138 // this data. |
| 139 static void EnsureAppHasPageIndex(ExtensionService* service, |
| 140 const std::string& id); |
| 141 |
| 142 // Return the number apps that have the given |page_index|. |
| 143 int GetNumberOfAppsOnPage(const int page_index) const; |
| 144 |
| 123 // Records a web store launch in the appropriate histograms. |promo_active| | 145 // Records a web store launch in the appropriate histograms. |promo_active| |
| 124 // specifies if the web store promotion was active. | 146 // specifies if the web store promotion was active. |
| 125 static void RecordWebStoreLaunch(bool promo_active); | 147 static void RecordWebStoreLaunch(bool promo_active); |
| 126 | 148 |
| 127 // Records an app launch in the corresponding |bucket| of the app launch | 149 // Records an app launch in the corresponding |bucket| of the app launch |
| 128 // histogram. |promo_active| specifies if the web store promotion was active. | 150 // histogram. |promo_active| specifies if the web store promotion was active. |
| 129 static void RecordAppLaunchByID(extension_misc::AppLaunchBucket bucket); | 151 static void RecordAppLaunchByID(extension_misc::AppLaunchBucket bucket); |
| 130 | 152 |
| 131 // Records an app launch in the corresponding |bucket| of the app launch | 153 // Records an app launch in the corresponding |bucket| of the app launch |
| 132 // histogram if the |escaped_url| corresponds to an installed app. | 154 // histogram if the |escaped_url| corresponds to an installed app. |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 bool attempted_bookmark_app_install_; | 214 bool attempted_bookmark_app_install_; |
| 193 | 215 |
| 194 // True if we have executed HandleGetApps() at least once. | 216 // True if we have executed HandleGetApps() at least once. |
| 195 bool has_loaded_apps_; | 217 bool has_loaded_apps_; |
| 196 | 218 |
| 197 // The ID of the app to be highlighted on the NTP (i.e. shown on the page | 219 // The ID of the app to be highlighted on the NTP (i.e. shown on the page |
| 198 // and pulsed). This is done for new installs. The actual higlighting occurs | 220 // and pulsed). This is done for new installs. The actual higlighting occurs |
| 199 // when the app is added to the page (via getAppsCallback or appAdded). | 221 // when the app is added to the page (via getAppsCallback or appAdded). |
| 200 std::string highlight_app_id_; | 222 std::string highlight_app_id_; |
| 201 | 223 |
| 224 // Used to determine if the current instance of AppLauncherHandler called |
| 225 // ExtensionUninstallAccepted(). If the current one was the one that called |
| 226 // this, we use this value to animate the removal on the attached NTP. |
| 227 bool uninstall_from_page_; |
| 228 |
| 202 // Hold state for favicon requests. | 229 // Hold state for favicon requests. |
| 203 CancelableRequestConsumerTSimple<AppInstallInfo*> favicon_consumer_; | 230 CancelableRequestConsumerTSimple<AppInstallInfo*> favicon_consumer_; |
| 204 | 231 |
| 205 DISALLOW_COPY_AND_ASSIGN(AppLauncherHandler); | 232 DISALLOW_COPY_AND_ASSIGN(AppLauncherHandler); |
| 206 }; | 233 }; |
| 207 | 234 |
| 208 #endif // CHROME_BROWSER_UI_WEBUI_NTP_APP_LAUNCHER_HANDLER_H_ | 235 #endif // CHROME_BROWSER_UI_WEBUI_NTP_APP_LAUNCHER_HANDLER_H_ |
| OLD | NEW |