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 #include "chrome/browser/ui/webui/ntp/app_launcher_handler.h" | 5 #include "chrome/browser/ui/webui/ntp/app_launcher_handler.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
13 #include "base/string_number_conversions.h" | 13 #include "base/string_number_conversions.h" |
14 #include "base/string_split.h" | 14 #include "base/string_split.h" |
15 #include "base/string_util.h" | 15 #include "base/string_util.h" |
16 #include "base/utf_string_conversions.h" | 16 #include "base/utf_string_conversions.h" |
17 #include "base/values.h" | 17 #include "base/values.h" |
18 #include "chrome/browser/extensions/apps_promo.h" | 18 #include "chrome/browser/extensions/apps_promo.h" |
19 #include "chrome/browser/extensions/extension_prefs.h" | 19 #include "chrome/browser/extensions/extension_prefs.h" |
20 #include "chrome/browser/extensions/extension_service.h" | 20 #include "chrome/browser/extensions/extension_service.h" |
21 #include "chrome/browser/platform_util.h" | 21 #include "chrome/browser/platform_util.h" |
22 #include "chrome/browser/prefs/pref_service.h" | 22 #include "chrome/browser/prefs/pref_service.h" |
23 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 23 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
24 #include "chrome/browser/profiles/profile.h" | 24 #include "chrome/browser/profiles/profile.h" |
25 #include "chrome/browser/ui/browser.h" | 25 #include "chrome/browser/ui/browser.h" |
26 #include "chrome/browser/ui/browser_list.h" | 26 #include "chrome/browser/ui/browser_list.h" |
27 #include "chrome/browser/ui/browser_window.h" | 27 #include "chrome/browser/ui/browser_window.h" |
28 #include "chrome/browser/ui/webui/extension_icon_source.h" | 28 #include "chrome/browser/ui/webui/extension_icon_source.h" |
29 #include "chrome/browser/ui/webui/ntp/shown_sections_handler.h" | 29 #include "chrome/browser/ui/webui/ntp/shown_sections_handler.h" |
| 30 #include "chrome/common/chrome_notification_types.h" |
30 #include "chrome/common/chrome_switches.h" | 31 #include "chrome/common/chrome_switches.h" |
31 #include "chrome/common/extensions/extension.h" | 32 #include "chrome/common/extensions/extension.h" |
32 #include "chrome/common/extensions/extension_constants.h" | 33 #include "chrome/common/extensions/extension_constants.h" |
33 #include "chrome/common/extensions/extension_icon_set.h" | 34 #include "chrome/common/extensions/extension_icon_set.h" |
34 #include "chrome/common/extensions/extension_resource.h" | 35 #include "chrome/common/extensions/extension_resource.h" |
35 #include "chrome/common/pref_names.h" | 36 #include "chrome/common/pref_names.h" |
36 #include "chrome/common/url_constants.h" | 37 #include "chrome/common/url_constants.h" |
37 #include "content/browser/disposition_utils.h" | 38 #include "content/browser/disposition_utils.h" |
38 #include "content/browser/tab_contents/tab_contents.h" | 39 #include "content/browser/tab_contents/tab_contents.h" |
39 #include "content/common/notification_service.h" | 40 #include "content/common/notification_service.h" |
40 #include "content/common/notification_type.h" | |
41 #include "googleurl/src/gurl.h" | 41 #include "googleurl/src/gurl.h" |
42 #include "grit/browser_resources.h" | 42 #include "grit/browser_resources.h" |
43 #include "grit/generated_resources.h" | 43 #include "grit/generated_resources.h" |
44 #include "net/base/escape.h" | 44 #include "net/base/escape.h" |
45 #include "ui/base/animation/animation.h" | 45 #include "ui/base/animation/animation.h" |
46 #include "webkit/glue/window_open_disposition.h" | 46 #include "webkit/glue/window_open_disposition.h" |
47 | 47 |
48 namespace { | 48 namespace { |
49 | 49 |
50 // The URL prefixes used by the NTP to signal when the web store or an app | 50 // The URL prefixes used by the NTP to signal when the web store or an app |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 web_ui_->RegisterMessageCallback("reorderApps", | 207 web_ui_->RegisterMessageCallback("reorderApps", |
208 NewCallback(this, &AppLauncherHandler::HandleReorderApps)); | 208 NewCallback(this, &AppLauncherHandler::HandleReorderApps)); |
209 web_ui_->RegisterMessageCallback("setPageIndex", | 209 web_ui_->RegisterMessageCallback("setPageIndex", |
210 NewCallback(this, &AppLauncherHandler::HandleSetPageIndex)); | 210 NewCallback(this, &AppLauncherHandler::HandleSetPageIndex)); |
211 web_ui_->RegisterMessageCallback("promoSeen", | 211 web_ui_->RegisterMessageCallback("promoSeen", |
212 NewCallback(this, &AppLauncherHandler::HandlePromoSeen)); | 212 NewCallback(this, &AppLauncherHandler::HandlePromoSeen)); |
213 web_ui_->RegisterMessageCallback("saveAppPageName", | 213 web_ui_->RegisterMessageCallback("saveAppPageName", |
214 NewCallback(this, &AppLauncherHandler::HandleSaveAppPageName)); | 214 NewCallback(this, &AppLauncherHandler::HandleSaveAppPageName)); |
215 } | 215 } |
216 | 216 |
217 void AppLauncherHandler::Observe(NotificationType type, | 217 void AppLauncherHandler::Observe(int type, |
218 const NotificationSource& source, | 218 const NotificationSource& source, |
219 const NotificationDetails& details) { | 219 const NotificationDetails& details) { |
220 if (ignore_changes_) | 220 if (ignore_changes_) |
221 return; | 221 return; |
222 | 222 |
223 switch (type.value) { | 223 switch (type) { |
224 case NotificationType::APP_NOTIFICATION_STATE_CHANGED: { | 224 case chrome::NOTIFICATION_APP_NOTIFICATION_STATE_CHANGED: { |
225 const std::string& id = *Details<const std::string>(details).ptr(); | 225 const std::string& id = *Details<const std::string>(details).ptr(); |
226 const AppNotification* notification = | 226 const AppNotification* notification = |
227 extensions_service_->app_notification_manager()->GetLast(id); | 227 extensions_service_->app_notification_manager()->GetLast(id); |
228 ListValue args; | 228 ListValue args; |
229 args.Append(new StringValue(id)); | 229 args.Append(new StringValue(id)); |
230 if (notification) | 230 if (notification) |
231 args.Append(SerializeNotification(*notification)); | 231 args.Append(SerializeNotification(*notification)); |
232 web_ui_->CallJavascriptFunction("appNotificationChanged", args); | 232 web_ui_->CallJavascriptFunction("appNotificationChanged", args); |
233 break; | 233 break; |
234 } | 234 } |
235 case NotificationType::EXTENSION_LOADED: | 235 case chrome::NOTIFICATION_EXTENSION_LOADED: |
236 case NotificationType::EXTENSION_UNLOADED: { | 236 case chrome::NOTIFICATION_EXTENSION_UNLOADED: { |
237 const Extension* extension = | 237 const Extension* extension = |
238 type == NotificationType::EXTENSION_LOADED ? | 238 type == chrome::NOTIFICATION_EXTENSION_LOADED ? |
239 Details<const Extension>(details).ptr() : | 239 Details<const Extension>(details).ptr() : |
240 Details<UnloadedExtensionInfo>(details)->extension; | 240 Details<UnloadedExtensionInfo>(details)->extension; |
241 if (!extension->is_app()) | 241 if (!extension->is_app()) |
242 break; | 242 break; |
243 | 243 |
244 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kNewTabPage4)) { | 244 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kNewTabPage4)) { |
245 scoped_ptr<DictionaryValue> app_info(GetAppInfo(extension)); | 245 scoped_ptr<DictionaryValue> app_info(GetAppInfo(extension)); |
246 std::string function = | 246 std::string function = |
247 type.value == NotificationType::EXTENSION_LOADED ? | 247 type == chrome::NOTIFICATION_EXTENSION_LOADED ? |
248 "ntp4.appAdded" : "ntp4.appRemoved"; | 248 "ntp4.appAdded" : "ntp4.appRemoved"; |
249 web_ui_->CallJavascriptFunction(function, *app_info); | 249 web_ui_->CallJavascriptFunction(function, *app_info); |
250 } else if (web_ui_->tab_contents()) { | 250 } else if (web_ui_->tab_contents()) { |
251 HandleGetApps(NULL); | 251 HandleGetApps(NULL); |
252 } | 252 } |
253 | 253 |
254 break; | 254 break; |
255 } | 255 } |
256 case NotificationType::EXTENSION_LAUNCHER_REORDERED: | 256 case chrome::NOTIFICATION_EXTENSION_LAUNCHER_REORDERED: |
257 // The promo may not load until a couple seconds after the first NTP view, | 257 // The promo may not load until a couple seconds after the first NTP view, |
258 // so we listen for the load notification and notify the NTP when ready. | 258 // so we listen for the load notification and notify the NTP when ready. |
259 case NotificationType::WEB_STORE_PROMO_LOADED: | 259 case chrome::NOTIFICATION_WEB_STORE_PROMO_LOADED: |
260 if (web_ui_->tab_contents()) | 260 if (web_ui_->tab_contents()) |
261 HandleGetApps(NULL); | 261 HandleGetApps(NULL); |
262 break; | 262 break; |
263 case NotificationType::PREF_CHANGED: { | 263 case chrome::NOTIFICATION_PREF_CHANGED: { |
264 if (!web_ui_->tab_contents()) | 264 if (!web_ui_->tab_contents()) |
265 break; | 265 break; |
266 // Handle app page renames. | 266 // Handle app page renames. |
267 std::string* pref_name = Details<std::string>(details).ptr(); | 267 std::string* pref_name = Details<std::string>(details).ptr(); |
268 if (*pref_name == prefs::kNTPAppPageNames) { | 268 if (*pref_name == prefs::kNTPAppPageNames) { |
269 HandleGetApps(NULL); | 269 HandleGetApps(NULL); |
270 } else { | 270 } else { |
271 // Default prefs change handling. | 271 // Default prefs change handling. |
272 DictionaryValue dictionary; | 272 DictionaryValue dictionary; |
273 FillAppDictionary(&dictionary); | 273 FillAppDictionary(&dictionary); |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
392 ignore_changes_ = false; | 392 ignore_changes_ = false; |
393 ShownSectionsHandler::SetShownSection(prefs, THUMB); | 393 ShownSectionsHandler::SetShownSection(prefs, THUMB); |
394 } | 394 } |
395 | 395 |
396 FillAppDictionary(&dictionary); | 396 FillAppDictionary(&dictionary); |
397 web_ui_->CallJavascriptFunction("getAppsCallback", dictionary); | 397 web_ui_->CallJavascriptFunction("getAppsCallback", dictionary); |
398 | 398 |
399 // First time we get here we set up the observer so that we can tell update | 399 // First time we get here we set up the observer so that we can tell update |
400 // the apps as they change. | 400 // the apps as they change. |
401 if (registrar_.IsEmpty()) { | 401 if (registrar_.IsEmpty()) { |
402 registrar_.Add(this, NotificationType::APP_NOTIFICATION_STATE_CHANGED, | 402 registrar_.Add(this, chrome::NOTIFICATION_APP_NOTIFICATION_STATE_CHANGED, |
403 NotificationService::AllSources()); | 403 NotificationService::AllSources()); |
404 registrar_.Add(this, NotificationType::EXTENSION_LOADED, | 404 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, |
405 NotificationService::AllSources()); | 405 NotificationService::AllSources()); |
406 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED, | 406 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, |
407 NotificationService::AllSources()); | 407 NotificationService::AllSources()); |
408 registrar_.Add(this, NotificationType::EXTENSION_LAUNCHER_REORDERED, | 408 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LAUNCHER_REORDERED, |
409 NotificationService::AllSources()); | 409 NotificationService::AllSources()); |
410 registrar_.Add(this, NotificationType::WEB_STORE_PROMO_LOADED, | 410 registrar_.Add(this, chrome::NOTIFICATION_WEB_STORE_PROMO_LOADED, |
411 NotificationService::AllSources()); | 411 NotificationService::AllSources()); |
412 } | 412 } |
413 if (pref_change_registrar_.IsEmpty()) { | 413 if (pref_change_registrar_.IsEmpty()) { |
414 pref_change_registrar_.Init( | 414 pref_change_registrar_.Init( |
415 extensions_service_->extension_prefs()->pref_service()); | 415 extensions_service_->extension_prefs()->pref_service()); |
416 pref_change_registrar_.Add(ExtensionPrefs::kExtensionsPref, this); | 416 pref_change_registrar_.Add(ExtensionPrefs::kExtensionsPref, this); |
417 pref_change_registrar_.Add(prefs::kNTPAppPageNames, this); | 417 pref_change_registrar_.Add(prefs::kNTPAppPageNames, this); |
418 } | 418 } |
419 } | 419 } |
420 | 420 |
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
771 | 771 |
772 void AppLauncherHandler::UninstallDefaultApps() { | 772 void AppLauncherHandler::UninstallDefaultApps() { |
773 AppsPromo* apps_promo = extensions_service_->apps_promo(); | 773 AppsPromo* apps_promo = extensions_service_->apps_promo(); |
774 const ExtensionIdSet& app_ids = apps_promo->old_default_apps(); | 774 const ExtensionIdSet& app_ids = apps_promo->old_default_apps(); |
775 for (ExtensionIdSet::const_iterator iter = app_ids.begin(); | 775 for (ExtensionIdSet::const_iterator iter = app_ids.begin(); |
776 iter != app_ids.end(); ++iter) { | 776 iter != app_ids.end(); ++iter) { |
777 if (extensions_service_->GetExtensionById(*iter, true)) | 777 if (extensions_service_->GetExtensionById(*iter, true)) |
778 extensions_service_->UninstallExtension(*iter, false, NULL); | 778 extensions_service_->UninstallExtension(*iter, false, NULL); |
779 } | 779 } |
780 } | 780 } |
OLD | NEW |