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

Unified Diff: chrome/browser/ui/webui/ntp/app_launcher_handler.cc

Issue 7187023: Adding an experimental app notification API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/webui/ntp/app_launcher_handler.cc
diff --git a/chrome/browser/ui/webui/ntp/app_launcher_handler.cc b/chrome/browser/ui/webui/ntp/app_launcher_handler.cc
index 633faf7d6ca8aff3c54b44a91aa41b7f0e8b84fe..98b0704e37d867ea847fb056ad62ba3883cd4c3a 100644
--- a/chrome/browser/ui/webui/ntp/app_launcher_handler.cc
+++ b/chrome/browser/ui/webui/ntp/app_launcher_handler.cc
@@ -75,6 +75,7 @@ AppLauncherHandler::~AppLauncherHandler() {}
// static
void AppLauncherHandler::CreateAppInfo(const Extension* extension,
+ const AppNotificationList* notifications,
ExtensionPrefs* prefs,
DictionaryValue* value) {
bool enabled =
@@ -109,6 +110,18 @@ void AppLauncherHandler::CreateAppInfo(const Extension* extension,
value->SetBoolean("is_component",
extension->location() == Extension::COMPONENT);
+ if (notifications && !notifications->empty()) {
+ AppNotification* n = (*notifications->rbegin()).get();
+ DictionaryValue* info = new DictionaryValue();
+ info->SetString("title", n->title);
+ info->SetString("body", n->body);
+ if (!n->linkUrl.is_empty()) {
+ info->SetString("linkUrl", n->linkUrl.spec());
+ info->SetString("linkText", n->linkText);
+ }
+ value->Set("notification", info);
+ }
+
int app_launch_index = prefs->GetAppLaunchIndex(extension->id());
if (app_launch_index == -1) {
// Make sure every app has a launch index (some predate the launch index).
@@ -198,6 +211,7 @@ void AppLauncherHandler::Observe(NotificationType type,
return;
switch (type.value) {
+ case NotificationType::APP_NOTIFICATION_STATE_CHANGED:
case NotificationType::EXTENSION_LOADED:
case NotificationType::EXTENSION_UNLOADED:
case NotificationType::EXTENSION_LAUNCHER_REORDERED:
@@ -228,10 +242,16 @@ void AppLauncherHandler::FillAppDictionary(DictionaryValue* dictionary) {
for (it = extensions->begin(); it != extensions->end(); ++it) {
// Don't include the WebStore.
// The WebStore launcher gets special treatment in ntp/apps.js.
- if ((*it)->is_app() &&
- (*it)->id() != extension_misc::kWebStoreAppId) {
+ const Extension* extension = *it;
+ if (extension->is_app() &&
+ extension->id() != extension_misc::kWebStoreAppId) {
DictionaryValue* app_info = new DictionaryValue();
- CreateAppInfo(*it, extensions_service_->extension_prefs(), app_info);
+ AppNotificationManager* notification_manager =
+ extensions_service_->app_notification_manager();
+ CreateAppInfo(extension,
+ notification_manager->GetAll(extension->id()),
+ extensions_service_->extension_prefs(),
+ app_info);
list->Append(app_info);
}
}
@@ -241,7 +261,12 @@ void AppLauncherHandler::FillAppDictionary(DictionaryValue* dictionary) {
if ((*it)->is_app() &&
(*it)->id() != extension_misc::kWebStoreAppId) {
DictionaryValue* app_info = new DictionaryValue();
- CreateAppInfo(*it, extensions_service_->extension_prefs(), app_info);
+ const AppNotificationList* notifications =
+ extensions_service_->app_notification_manager()->GetAll((*it)->id());
+ CreateAppInfo(*it,
+ notifications,
+ extensions_service_->extension_prefs(),
+ app_info);
Finnur 2011/06/20 12:21:46 Should we be showing notifications for disabled ap
asargent_no_longer_on_chrome 2011/06/21 18:10:11 No, we should not. Good catch.
list->Append(app_info);
}
}
@@ -314,6 +339,8 @@ void AppLauncherHandler::HandleGetApps(const ListValue* args) {
// First time we get here we set up the observer so that we can tell update
// the apps as they change.
if (registrar_.IsEmpty()) {
+ registrar_.Add(this, NotificationType::APP_NOTIFICATION_STATE_CHANGED,
+ NotificationService::AllSources());
registrar_.Add(this, NotificationType::EXTENSION_LOADED,
NotificationService::AllSources());
registrar_.Add(this, NotificationType::EXTENSION_UNLOADED,

Powered by Google App Engine
This is Rietveld 408576698