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

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

Issue 8785016: Add menu option for disabling app notifications (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: respond to more review feedback Created 9 years 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 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(

Powered by Google App Engine
This is Rietveld 408576698