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

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

Issue 7327007: Moving notification types which are chrome specific to a new header file chrome_notification_type... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 5 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 #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/profiles/profile.h" 22 #include "chrome/browser/profiles/profile.h"
23 #include "chrome/browser/ui/browser.h" 23 #include "chrome/browser/ui/browser.h"
24 #include "chrome/browser/ui/browser_list.h" 24 #include "chrome/browser/ui/browser_list.h"
25 #include "chrome/browser/ui/browser_window.h" 25 #include "chrome/browser/ui/browser_window.h"
26 #include "chrome/browser/ui/webui/extension_icon_source.h" 26 #include "chrome/browser/ui/webui/extension_icon_source.h"
27 #include "chrome/browser/ui/webui/ntp/shown_sections_handler.h" 27 #include "chrome/browser/ui/webui/ntp/shown_sections_handler.h"
28 #include "chrome/common/chrome_notification_types.h"
28 #include "chrome/common/chrome_switches.h" 29 #include "chrome/common/chrome_switches.h"
29 #include "chrome/common/extensions/extension.h" 30 #include "chrome/common/extensions/extension.h"
30 #include "chrome/common/extensions/extension_constants.h" 31 #include "chrome/common/extensions/extension_constants.h"
31 #include "chrome/common/extensions/extension_icon_set.h" 32 #include "chrome/common/extensions/extension_icon_set.h"
32 #include "chrome/common/extensions/extension_resource.h" 33 #include "chrome/common/extensions/extension_resource.h"
33 #include "chrome/common/url_constants.h" 34 #include "chrome/common/url_constants.h"
34 #include "content/browser/disposition_utils.h" 35 #include "content/browser/disposition_utils.h"
35 #include "content/browser/tab_contents/tab_contents.h" 36 #include "content/browser/tab_contents/tab_contents.h"
36 #include "content/common/notification_service.h" 37 #include "content/common/notification_service.h"
37 #include "content/common/notification_type.h"
38 #include "googleurl/src/gurl.h" 38 #include "googleurl/src/gurl.h"
39 #include "grit/browser_resources.h" 39 #include "grit/browser_resources.h"
40 #include "grit/generated_resources.h" 40 #include "grit/generated_resources.h"
41 #include "net/base/escape.h" 41 #include "net/base/escape.h"
42 #include "ui/base/animation/animation.h" 42 #include "ui/base/animation/animation.h"
43 #include "webkit/glue/window_open_disposition.h" 43 #include "webkit/glue/window_open_disposition.h"
44 44
45 namespace { 45 namespace {
46 46
47 // The URL prefixes used by the NTP to signal when the web store or an app 47 // The URL prefixes used by the NTP to signal when the web store or an app
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 web_ui_->RegisterMessageCallback("createAppShortcut", 202 web_ui_->RegisterMessageCallback("createAppShortcut",
203 NewCallback(this, &AppLauncherHandler::HandleCreateAppShortcut)); 203 NewCallback(this, &AppLauncherHandler::HandleCreateAppShortcut));
204 web_ui_->RegisterMessageCallback("reorderApps", 204 web_ui_->RegisterMessageCallback("reorderApps",
205 NewCallback(this, &AppLauncherHandler::HandleReorderApps)); 205 NewCallback(this, &AppLauncherHandler::HandleReorderApps));
206 web_ui_->RegisterMessageCallback("setPageIndex", 206 web_ui_->RegisterMessageCallback("setPageIndex",
207 NewCallback(this, &AppLauncherHandler::HandleSetPageIndex)); 207 NewCallback(this, &AppLauncherHandler::HandleSetPageIndex));
208 web_ui_->RegisterMessageCallback("promoSeen", 208 web_ui_->RegisterMessageCallback("promoSeen",
209 NewCallback(this, &AppLauncherHandler::HandlePromoSeen)); 209 NewCallback(this, &AppLauncherHandler::HandlePromoSeen));
210 } 210 }
211 211
212 void AppLauncherHandler::Observe(NotificationType type, 212 void AppLauncherHandler::Observe(int type,
213 const NotificationSource& source, 213 const NotificationSource& source,
214 const NotificationDetails& details) { 214 const NotificationDetails& details) {
215 if (ignore_changes_) 215 if (ignore_changes_)
216 return; 216 return;
217 217
218 switch (type.value) { 218 switch (type) {
219 case NotificationType::APP_NOTIFICATION_STATE_CHANGED: { 219 case chrome::NOTIFICATION_APP_NOTIFICATION_STATE_CHANGED: {
220 const std::string& id = *Details<const std::string>(details).ptr(); 220 const std::string& id = *Details<const std::string>(details).ptr();
221 const AppNotification* notification = 221 const AppNotification* notification =
222 extensions_service_->app_notification_manager()->GetLast(id); 222 extensions_service_->app_notification_manager()->GetLast(id);
223 ListValue args; 223 ListValue args;
224 args.Append(new StringValue(id)); 224 args.Append(new StringValue(id));
225 if (notification) 225 if (notification)
226 args.Append(SerializeNotification(*notification)); 226 args.Append(SerializeNotification(*notification));
227 web_ui_->CallJavascriptFunction("appNotificationChanged", args); 227 web_ui_->CallJavascriptFunction("appNotificationChanged", args);
228 break; 228 break;
229 } 229 }
230 case NotificationType::EXTENSION_LOADED: 230 case chrome::NOTIFICATION_EXTENSION_LOADED:
231 case NotificationType::EXTENSION_UNLOADED: { 231 case chrome::NOTIFICATION_EXTENSION_UNLOADED: {
232 const Extension* extension = 232 const Extension* extension =
233 type == NotificationType::EXTENSION_LOADED ? 233 type == chrome::NOTIFICATION_EXTENSION_LOADED ?
234 Details<const Extension>(details).ptr() : 234 Details<const Extension>(details).ptr() :
235 Details<UnloadedExtensionInfo>(details)->extension; 235 Details<UnloadedExtensionInfo>(details)->extension;
236 if (!extension->is_app()) 236 if (!extension->is_app())
237 break; 237 break;
238 238
239 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kNewTabPage4)) { 239 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kNewTabPage4)) {
240 scoped_ptr<DictionaryValue> app_info(GetAppInfo(extension)); 240 scoped_ptr<DictionaryValue> app_info(GetAppInfo(extension));
241 std::string function = 241 std::string function =
242 type.value == NotificationType::EXTENSION_LOADED ? 242 type == chrome::NOTIFICATION_EXTENSION_LOADED ?
243 "ntp4.appAdded" : "ntp4.appRemoved"; 243 "ntp4.appAdded" : "ntp4.appRemoved";
244 web_ui_->CallJavascriptFunction(function, *app_info); 244 web_ui_->CallJavascriptFunction(function, *app_info);
245 } else if (web_ui_->tab_contents()) { 245 } else if (web_ui_->tab_contents()) {
246 HandleGetApps(NULL); 246 HandleGetApps(NULL);
247 } 247 }
248 248
249 break; 249 break;
250 } 250 }
251 case NotificationType::EXTENSION_LAUNCHER_REORDERED: 251 case chrome::NOTIFICATION_EXTENSION_LAUNCHER_REORDERED:
252 // The promo may not load until a couple seconds after the first NTP view, 252 // The promo may not load until a couple seconds after the first NTP view,
253 // so we listen for the load notification and notify the NTP when ready. 253 // so we listen for the load notification and notify the NTP when ready.
254 case NotificationType::WEB_STORE_PROMO_LOADED: 254 case chrome::NOTIFICATION_WEB_STORE_PROMO_LOADED:
255 if (web_ui_->tab_contents()) 255 if (web_ui_->tab_contents())
256 HandleGetApps(NULL); 256 HandleGetApps(NULL);
257 break; 257 break;
258 case NotificationType::PREF_CHANGED: { 258 case chrome::NOTIFICATION_PREF_CHANGED: {
259 if (!web_ui_->tab_contents()) 259 if (!web_ui_->tab_contents())
260 break; 260 break;
261 261
262 DictionaryValue dictionary; 262 DictionaryValue dictionary;
263 FillAppDictionary(&dictionary); 263 FillAppDictionary(&dictionary);
264 web_ui_->CallJavascriptFunction("appsPrefChangeCallback", dictionary); 264 web_ui_->CallJavascriptFunction("appsPrefChangeCallback", dictionary);
265 break; 265 break;
266 } 266 }
267 default: 267 default:
268 NOTREACHED(); 268 NOTREACHED();
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 ignore_changes_ = false; 374 ignore_changes_ = false;
375 ShownSectionsHandler::SetShownSection(prefs, THUMB); 375 ShownSectionsHandler::SetShownSection(prefs, THUMB);
376 } 376 }
377 377
378 FillAppDictionary(&dictionary); 378 FillAppDictionary(&dictionary);
379 web_ui_->CallJavascriptFunction("getAppsCallback", dictionary); 379 web_ui_->CallJavascriptFunction("getAppsCallback", dictionary);
380 380
381 // First time we get here we set up the observer so that we can tell update 381 // First time we get here we set up the observer so that we can tell update
382 // the apps as they change. 382 // the apps as they change.
383 if (registrar_.IsEmpty()) { 383 if (registrar_.IsEmpty()) {
384 registrar_.Add(this, NotificationType::APP_NOTIFICATION_STATE_CHANGED, 384 registrar_.Add(this, chrome::NOTIFICATION_APP_NOTIFICATION_STATE_CHANGED,
385 NotificationService::AllSources()); 385 NotificationService::AllSources());
386 registrar_.Add(this, NotificationType::EXTENSION_LOADED, 386 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED,
387 NotificationService::AllSources()); 387 NotificationService::AllSources());
388 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED, 388 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED,
389 NotificationService::AllSources()); 389 NotificationService::AllSources());
390 registrar_.Add(this, NotificationType::EXTENSION_LAUNCHER_REORDERED, 390 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LAUNCHER_REORDERED,
391 NotificationService::AllSources()); 391 NotificationService::AllSources());
392 registrar_.Add(this, NotificationType::WEB_STORE_PROMO_LOADED, 392 registrar_.Add(this, chrome::NOTIFICATION_WEB_STORE_PROMO_LOADED,
393 NotificationService::AllSources()); 393 NotificationService::AllSources());
394 } 394 }
395 if (pref_change_registrar_.IsEmpty()) { 395 if (pref_change_registrar_.IsEmpty()) {
396 pref_change_registrar_.Init( 396 pref_change_registrar_.Init(
397 extensions_service_->extension_prefs()->pref_service()); 397 extensions_service_->extension_prefs()->pref_service());
398 pref_change_registrar_.Add(ExtensionPrefs::kExtensionsPref, this); 398 pref_change_registrar_.Add(ExtensionPrefs::kExtensionsPref, this);
399 } 399 }
400 } 400 }
401 401
402 void AppLauncherHandler::HandleLaunchApp(const ListValue* args) { 402 void AppLauncherHandler::HandleLaunchApp(const ListValue* args) {
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
731 731
732 void AppLauncherHandler::UninstallDefaultApps() { 732 void AppLauncherHandler::UninstallDefaultApps() {
733 AppsPromo* apps_promo = extensions_service_->apps_promo(); 733 AppsPromo* apps_promo = extensions_service_->apps_promo();
734 const ExtensionIdSet& app_ids = apps_promo->old_default_apps(); 734 const ExtensionIdSet& app_ids = apps_promo->old_default_apps();
735 for (ExtensionIdSet::const_iterator iter = app_ids.begin(); 735 for (ExtensionIdSet::const_iterator iter = app_ids.begin();
736 iter != app_ids.end(); ++iter) { 736 iter != app_ids.end(); ++iter) {
737 if (extensions_service_->GetExtensionById(*iter, true)) 737 if (extensions_service_->GetExtensionById(*iter, true))
738 extensions_service_->UninstallExtension(*iter, false, NULL); 738 extensions_service_->UninstallExtension(*iter, false, NULL);
739 } 739 }
740 } 740 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698