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 d0b075db106d60b779bef20b5b5e4abacb3bfc34..f62305bd6fbfa0278d7c277696dbbf670d34542f 100644 |
--- a/chrome/browser/ui/webui/ntp/app_launcher_handler.cc |
+++ b/chrome/browser/ui/webui/ntp/app_launcher_handler.cc |
@@ -150,6 +150,12 @@ void AppLauncherHandler::CreateAppInfo(const Extension* extension, |
value->SetBoolean("is_webstore", |
extension->id() == extension_misc::kWebStoreAppId); |
+ if (extension->HasAPIPermission(ExtensionAPIPermission::kAppNotifications)) { |
+ ExtensionPrefs* prefs = service->extension_prefs(); |
+ value->SetBoolean("notifications_disabled", |
+ prefs->IsAppNotificationDisabled(extension->id())); |
+ } |
+ |
if (notification) |
value->Set("notification", SerializeNotification(*notification)); |
@@ -222,6 +228,9 @@ void AppLauncherHandler::RegisterMessages() { |
web_ui_->RegisterMessageCallback("closeNotification", |
base::Bind(&AppLauncherHandler::HandleNotificationClose, |
base::Unretained(this))); |
+ web_ui_->RegisterMessageCallback("setNotificationsDisabled", |
+ base::Bind(&AppLauncherHandler::HandleSetNotificationsDisabled, |
+ base::Unretained(this))); |
} |
void AppLauncherHandler::Observe(int type, |
@@ -239,10 +248,6 @@ void AppLauncherHandler::Observe(int type, |
switch (type) { |
case chrome::NOTIFICATION_APP_NOTIFICATION_STATE_CHANGED: { |
- Profile* profile = content::Source<Profile>(source).ptr(); |
- if (!Profile::FromWebUI(web_ui_)->IsSameProfile(profile)) |
- return; |
- |
const std::string& id = |
*content::Details<const std::string>(details).ptr(); |
const AppNotification* notification = |
@@ -469,7 +474,7 @@ void AppLauncherHandler::HandleGetApps(const ListValue* args) { |
pref_change_registrar_.Add(prefs::kNTPAppPageNames, this); |
registrar_.Add(this, chrome::NOTIFICATION_APP_NOTIFICATION_STATE_CHANGED, |
- content::NotificationService::AllSources()); |
+ content::Source<Profile>(profile)); |
registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, |
content::Source<Profile>(profile)); |
registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, |
@@ -760,6 +765,20 @@ void AppLauncherHandler::HandleNotificationClose(const ListValue* args) { |
notification_manager->ClearAll(extension_id); |
} |
+void AppLauncherHandler::HandleSetNotificationsDisabled( |
+ const ListValue* args) { |
+ std::string extension_id; |
+ bool disabled = false; |
+ CHECK(args->GetString(0, &extension_id)); |
+ CHECK(args->GetBoolean(1, &disabled)); |
+ |
+ const Extension* extension = extension_service_->GetExtensionById( |
+ extension_id, true); |
+ if (!extension) |
+ return; |
+ extension_service_->SetAppNotificationDisabled(extension_id, disabled); |
+} |
+ |
void AppLauncherHandler::OnFaviconForApp(FaviconService::Handle handle, |
history::FaviconData data) { |
scoped_ptr<AppInstallInfo> install_info( |