Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(181)

Side by Side Diff: chrome/browser/ui/webui/ntp/app_launcher_handler.h

Issue 8637001: [NTP4] Auto-deletion of empty apps panes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: removing bits for refactor Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "chrome/browser/cancelable_request.h" 12 #include "chrome/browser/cancelable_request.h"
13 #include "chrome/browser/extensions/extension_install_ui.h" 13 #include "chrome/browser/extensions/extension_install_ui.h"
14 #include "chrome/browser/extensions/extension_uninstall_dialog.h" 14 #include "chrome/browser/extensions/extension_uninstall_dialog.h"
15 #include "chrome/browser/favicon/favicon_service.h" 15 #include "chrome/browser/favicon/favicon_service.h"
16 #include "chrome/browser/prefs/pref_change_registrar.h" 16 #include "chrome/browser/prefs/pref_change_registrar.h"
17 #include "chrome/common/extensions/extension.h" 17 #include "chrome/common/extensions/extension.h"
18 #include "chrome/common/extensions/extension_constants.h" 18 #include "chrome/common/extensions/extension_constants.h"
19 #include "chrome/common/string_ordinal.h" 19 #include "chrome/common/string_ordinal.h"
20 #include "content/public/browser/notification_observer.h" 20 #include "content/public/browser/notification_observer.h"
21 #include "content/public/browser/notification_registrar.h" 21 #include "content/public/browser/notification_registrar.h"
22 #include "content/public/browser/web_ui_message_handler.h" 22 #include "content/public/browser/web_ui_message_handler.h"
23 23
24 class AppNotification; 24 class AppNotification;
25 class ExtensionService; 25 class ExtensionService;
26 class ExtensionSet;
26 class PrefChangeRegistrar; 27 class PrefChangeRegistrar;
27 class Profile; 28 class Profile;
28 29
29 // The handler for Javascript messages related to the "apps" view. 30 // The handler for Javascript messages related to the "apps" view.
30 class AppLauncherHandler : public content::WebUIMessageHandler, 31 class AppLauncherHandler : public content::WebUIMessageHandler,
31 public ExtensionUninstallDialog::Delegate, 32 public ExtensionUninstallDialog::Delegate,
32 public ExtensionInstallUI::Delegate, 33 public ExtensionInstallUI::Delegate,
33 public content::NotificationObserver { 34 public content::NotificationObserver {
34 public: 35 public:
35 explicit AppLauncherHandler(ExtensionService* extension_service); 36 explicit AppLauncherHandler(ExtensionService* extension_service);
(...skipping 11 matching lines...) Expand all
47 base::DictionaryValue* value); 48 base::DictionaryValue* value);
48 49
49 // WebUIMessageHandler implementation. 50 // WebUIMessageHandler implementation.
50 virtual void RegisterMessages() OVERRIDE; 51 virtual void RegisterMessages() OVERRIDE;
51 52
52 // content::NotificationObserver 53 // content::NotificationObserver
53 virtual void Observe(int type, 54 virtual void Observe(int type,
54 const content::NotificationSource& source, 55 const content::NotificationSource& source,
55 const content::NotificationDetails& details) OVERRIDE; 56 const content::NotificationDetails& details) OVERRIDE;
56 57
58 // Remove ordinals or page indices from legacy profiles.
59 void RemoveNonAppExtensionOrdinals(const ExtensionSet* extensions);
60
57 // Populate the given dictionary with all installed app info. 61 // Populate the given dictionary with all installed app info.
58 void FillAppDictionary(base::DictionaryValue* value); 62 void FillAppDictionary(base::DictionaryValue* value);
59 63
60 // Create a dictionary value for the given extension. May return NULL, e.g. if 64 // 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 65 // the given extension is not an app. If non-NULL, the caller assumes
62 // ownership of the pointer. 66 // ownership of the pointer.
63 base::DictionaryValue* GetAppInfo(const Extension* extension); 67 base::DictionaryValue* GetAppInfo(const Extension* extension);
64 68
65 // Populate the given dictionary with the web store promo content. 69 // Populate the given dictionary with the web store promo content.
66 void FillPromoDictionary(base::DictionaryValue* value); 70 void FillPromoDictionary(base::DictionaryValue* value);
67 71
72 // Callback for the "deleteAppsPage" message. Takes a page index as the first
73 // and only argument.
74 void HandleDeleteEmptyAppsPage(const base::ListValue* args);
75
68 // Callback for the "getApps" message. 76 // Callback for the "getApps" message.
69 void HandleGetApps(const base::ListValue* args); 77 void HandleGetApps(const base::ListValue* args);
70 78
71 // Callback for the "launchApp" message. 79 // Callback for the "launchApp" message.
72 void HandleLaunchApp(const base::ListValue* args); 80 void HandleLaunchApp(const base::ListValue* args);
73 81
74 // Callback for the "setLaunchType" message. 82 // Callback for the "setLaunchType" message.
75 void HandleSetLaunchType(const base::ListValue* args); 83 void HandleSetLaunchType(const base::ListValue* args);
76 84
77 // Callback for the "uninstallApp" message. 85 // Callback for the "uninstallApp" message.
78 void HandleUninstallApp(const base::ListValue* args); 86 void HandleUninstallApp(const base::ListValue* args);
79 87
80 // Callback for the "hideAppPromo" message. 88 // Callback for the "hideAppPromo" message.
81 void HandleHideAppsPromo(const base::ListValue* args); 89 void HandleHideAppsPromo(const base::ListValue* args);
82 90
83 // Callback for the "createAppShortcut" message. 91 // Callback for the "createAppShortcut" message.
84 void HandleCreateAppShortcut(const base::ListValue* args); 92 void HandleCreateAppShortcut(const base::ListValue* args);
85 93
86 // Callback for the "reorderApps" message. 94 // Callback for the "reorderApps" message.
87 void HandleReorderApps(const base::ListValue* args); 95 void HandleReorderApps(const base::ListValue* args);
88 96
89 // Callback for the "setPageIndex" message. 97 // Callback for the "setPageIndex" message.
90 void HandleSetPageIndex(const base::ListValue* args); 98 void HandleSetPageIndex(const base::ListValue* args);
91 99
92 // Callback for the "promoSeen" message. 100 // Callback for the "promoSeen" message.
93 void HandlePromoSeen(const base::ListValue* args); 101 void HandlePromoSeen(const base::ListValue* args);
94 102
95 // Callback for the "saveAppPageName" message. 103 // Callback for the "saveAppsPageName" message.
96 void HandleSaveAppPageName(const base::ListValue* args); 104 void HandleSaveAppsPageName(const base::ListValue* args);
97 105
98 // Callback for the "generateAppForLink" message. 106 // Callback for the "generateAppForLink" message.
99 void HandleGenerateAppForLink(const base::ListValue* args); 107 void HandleGenerateAppForLink(const base::ListValue* args);
100 108
101 // Callback for the "recordAppLaunchByURL" message. Takes an escaped URL and a 109 // Callback for the "recordAppLaunchByURL" message. Takes an escaped URL and a
102 // launch source (integer), and if the URL represents an app, records the 110 // launch source (integer), and if the URL represents an app, records the
103 // action for UMA. 111 // action for UMA.
104 void HandleRecordAppLaunchByURL(const base::ListValue* args); 112 void HandleRecordAppLaunchByURL(const base::ListValue* args);
105 113
106 // Callback for "closeNotification" message. 114 // Callback for "closeNotification" message.
107 void HandleNotificationClose(const base::ListValue* args); 115 void HandleNotificationClose(const base::ListValue* args);
108 116
109 // Callback for "setNotificationsDisabled" message. 117 // Callback for "setNotificationsDisabled" message.
110 void HandleSetNotificationsDisabled(const base::ListValue* args); 118 void HandleSetNotificationsDisabled(const base::ListValue* args);
111 119
112 // Register app launcher preferences. 120 // Register app launcher preferences.
113 static void RegisterUserPrefs(PrefService* pref_service); 121 static void RegisterUserPrefs(PrefService* pref_service);
114 122
115 private: 123 private:
116 struct AppInstallInfo { 124 struct AppInstallInfo {
117 AppInstallInfo(); 125 AppInstallInfo();
118 ~AppInstallInfo(); 126 ~AppInstallInfo();
119 127
120 bool is_bookmark_app; 128 bool is_bookmark_app;
121 string16 title; 129 string16 title;
122 GURL app_url; 130 GURL app_url;
123 StringOrdinal page_ordinal; 131 StringOrdinal page_ordinal;
124 }; 132 };
125 133
134 // Reset some instance flags we use to track the currently uninstalling app.
135 void CleanupAfterUninstall();
136
126 // Records a web store launch in the appropriate histograms. |promo_active| 137 // Records a web store launch in the appropriate histograms. |promo_active|
127 // specifies if the web store promotion was active. 138 // specifies if the web store promotion was active.
128 static void RecordWebStoreLaunch(bool promo_active); 139 static void RecordWebStoreLaunch(bool promo_active);
129 140
130 // Records an app launch in the corresponding |bucket| of the app launch 141 // Records an app launch in the corresponding |bucket| of the app launch
131 // histogram. |promo_active| specifies if the web store promotion was active. 142 // histogram. |promo_active| specifies if the web store promotion was active.
132 static void RecordAppLaunchByID(extension_misc::AppLaunchBucket bucket); 143 static void RecordAppLaunchByID(extension_misc::AppLaunchBucket bucket);
133 144
134 // Records an app launch in the corresponding |bucket| of the app launch 145 // Records an app launch in the corresponding |bucket| of the app launch
135 // histogram if the |escaped_url| corresponds to an installed app. 146 // histogram if the |escaped_url| corresponds to an installed app.
(...skipping 20 matching lines...) Expand all
156 // needed. 167 // needed.
157 ExtensionInstallUI* GetExtensionInstallUI(); 168 ExtensionInstallUI* GetExtensionInstallUI();
158 169
159 // Helper that uninstalls all the default apps. 170 // Helper that uninstalls all the default apps.
160 void UninstallDefaultApps(); 171 void UninstallDefaultApps();
161 172
162 // Continuation for installing a bookmark app after favicon lookup. 173 // Continuation for installing a bookmark app after favicon lookup.
163 void OnFaviconForApp(FaviconService::Handle handle, 174 void OnFaviconForApp(FaviconService::Handle handle,
164 history::FaviconData data); 175 history::FaviconData data);
165 176
177 // Ask all the apps which page they're on and return a sorted, unique list.
178 std::vector<std::string>* PageOrdinalsFromApps();
179
166 // Sends |highlight_app_id_| to the js. 180 // Sends |highlight_app_id_| to the js.
167 void SetAppToBeHighlighted(); 181 void SetAppToBeHighlighted();
168 182
183 // Go over the existing preference we read from the profile and make sure
184 // every page ordinal is in it (and remove possible extras). Returns a bool
185 // telling the caller whether any values were changed in this method.
186 bool SyncPageNamesToApps(DictionaryValue* page_names);
187
169 // The apps are represented in the extensions model, which 188 // The apps are represented in the extensions model, which
170 // outlives us since it's owned by our containing profile. 189 // outlives us since it's owned by our containing profile.
171 ExtensionService* const extension_service_; 190 ExtensionService* const extension_service_;
172 191
173 // We monitor changes to the extension system so that we can reload the apps 192 // We monitor changes to the extension system so that we can reload the apps
174 // when necessary. 193 // when necessary.
175 content::NotificationRegistrar registrar_; 194 content::NotificationRegistrar registrar_;
176 195
177 // Monitor extension preference changes so that the Web UI can be notified. 196 // Monitor extension preference changes so that the Web UI can be notified.
178 PrefChangeRegistrar pref_change_registrar_; 197 PrefChangeRegistrar pref_change_registrar_;
(...skipping 16 matching lines...) Expand all
195 bool attempted_bookmark_app_install_; 214 bool attempted_bookmark_app_install_;
196 215
197 // True if we have executed HandleGetApps() at least once. 216 // True if we have executed HandleGetApps() at least once.
198 bool has_loaded_apps_; 217 bool has_loaded_apps_;
199 218
200 // 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
201 // 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
202 // 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).
203 std::string highlight_app_id_; 222 std::string highlight_app_id_;
204 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
205 // Hold state for favicon requests. 229 // Hold state for favicon requests.
206 CancelableRequestConsumerTSimple<AppInstallInfo*> favicon_consumer_; 230 CancelableRequestConsumerTSimple<AppInstallInfo*> favicon_consumer_;
207 231
208 DISALLOW_COPY_AND_ASSIGN(AppLauncherHandler); 232 DISALLOW_COPY_AND_ASSIGN(AppLauncherHandler);
209 }; 233 };
210 234
211 #endif // CHROME_BROWSER_UI_WEBUI_NTP_APP_LAUNCHER_HANDLER_H_ 235 #endif // CHROME_BROWSER_UI_WEBUI_NTP_APP_LAUNCHER_HANDLER_H_
OLDNEW
« no previous file with comments | « chrome/browser/resources/shared/js/cr/ui/card_slider.js ('k') | chrome/browser/ui/webui/ntp/app_launcher_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698