| 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" |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 ExtensionPrefs* prefs = service->extension_prefs(); | 142 ExtensionPrefs* prefs = service->extension_prefs(); |
| 143 value->SetInteger("launch_type", | 143 value->SetInteger("launch_type", |
| 144 prefs->GetLaunchType(extension->id(), | 144 prefs->GetLaunchType(extension->id(), |
| 145 ExtensionPrefs::LAUNCH_DEFAULT)); | 145 ExtensionPrefs::LAUNCH_DEFAULT)); |
| 146 value->SetBoolean("offline_enabled", extension->offline_enabled()); | 146 value->SetBoolean("offline_enabled", extension->offline_enabled()); |
| 147 value->SetBoolean("is_component", | 147 value->SetBoolean("is_component", |
| 148 extension->location() == Extension::COMPONENT); | 148 extension->location() == Extension::COMPONENT); |
| 149 value->SetBoolean("is_webstore", | 149 value->SetBoolean("is_webstore", |
| 150 extension->id() == extension_misc::kWebStoreAppId); | 150 extension->id() == extension_misc::kWebStoreAppId); |
| 151 | 151 |
| 152 if (extension->HasAPIPermission(ExtensionAPIPermission::kAppNotifications)) { |
| 153 ExtensionPrefs* prefs = service->extension_prefs(); |
| 154 value->SetBoolean("notifications_disabled", |
| 155 prefs->IsAppNotificationDisabled(extension->id())); |
| 156 } |
| 157 |
| 152 if (notification) | 158 if (notification) |
| 153 value->Set("notification", SerializeNotification(*notification)); | 159 value->Set("notification", SerializeNotification(*notification)); |
| 154 | 160 |
| 155 int app_launch_index = prefs->GetAppLaunchIndex(extension->id()); | 161 int app_launch_index = prefs->GetAppLaunchIndex(extension->id()); |
| 156 if (app_launch_index == -1) { | 162 if (app_launch_index == -1) { |
| 157 // Make sure every app has a launch index (some predate the launch index). | 163 // Make sure every app has a launch index (some predate the launch index). |
| 158 // The webstore's app launch index is set to -2 to make sure it's first. | 164 // The webstore's app launch index is set to -2 to make sure it's first. |
| 159 // The next time the user drags (any) app this will be set to something | 165 // The next time the user drags (any) app this will be set to something |
| 160 // sane (i.e. >= 0). | 166 // sane (i.e. >= 0). |
| 161 app_launch_index = extension->id() == extension_misc::kWebStoreAppId ? | 167 app_launch_index = extension->id() == extension_misc::kWebStoreAppId ? |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 base::Unretained(this))); | 220 base::Unretained(this))); |
| 215 web_ui_->RegisterMessageCallback("generateAppForLink", | 221 web_ui_->RegisterMessageCallback("generateAppForLink", |
| 216 base::Bind(&AppLauncherHandler::HandleGenerateAppForLink, | 222 base::Bind(&AppLauncherHandler::HandleGenerateAppForLink, |
| 217 base::Unretained(this))); | 223 base::Unretained(this))); |
| 218 web_ui_->RegisterMessageCallback("recordAppLaunchByURL", | 224 web_ui_->RegisterMessageCallback("recordAppLaunchByURL", |
| 219 base::Bind(&AppLauncherHandler::HandleRecordAppLaunchByURL, | 225 base::Bind(&AppLauncherHandler::HandleRecordAppLaunchByURL, |
| 220 base::Unretained(this))); | 226 base::Unretained(this))); |
| 221 web_ui_->RegisterMessageCallback("closeNotification", | 227 web_ui_->RegisterMessageCallback("closeNotification", |
| 222 base::Bind(&AppLauncherHandler::HandleNotificationClose, | 228 base::Bind(&AppLauncherHandler::HandleNotificationClose, |
| 223 base::Unretained(this))); | 229 base::Unretained(this))); |
| 230 web_ui_->RegisterMessageCallback("setNotificationsDisabled", |
| 231 base::Bind(&AppLauncherHandler::HandleSetNotificationsDisabled, |
| 232 base::Unretained(this))); |
| 224 } | 233 } |
| 225 | 234 |
| 226 void AppLauncherHandler::Observe(int type, | 235 void AppLauncherHandler::Observe(int type, |
| 227 const content::NotificationSource& source, | 236 const content::NotificationSource& source, |
| 228 const content::NotificationDetails& details) { | 237 const content::NotificationDetails& details) { |
| 229 if (type == chrome::NOTIFICATION_APP_INSTALLED_TO_NTP) { | 238 if (type == chrome::NOTIFICATION_APP_INSTALLED_TO_NTP) { |
| 230 highlight_app_id_ = *content::Details<const std::string>(details).ptr(); | 239 highlight_app_id_ = *content::Details<const std::string>(details).ptr(); |
| 231 if (has_loaded_apps_) | 240 if (has_loaded_apps_) |
| 232 SetAppToBeHighlighted(); | 241 SetAppToBeHighlighted(); |
| 233 return; | 242 return; |
| 234 } | 243 } |
| 235 | 244 |
| 236 if (ignore_changes_ || !has_loaded_apps_) | 245 if (ignore_changes_ || !has_loaded_apps_) |
| 237 return; | 246 return; |
| 238 | 247 |
| 239 switch (type) { | 248 switch (type) { |
| 240 case chrome::NOTIFICATION_APP_NOTIFICATION_STATE_CHANGED: { | 249 case chrome::NOTIFICATION_APP_NOTIFICATION_STATE_CHANGED: { |
| 241 Profile* profile = content::Source<Profile>(source).ptr(); | |
| 242 if (!Profile::FromWebUI(web_ui_)->IsSameProfile(profile)) | |
| 243 return; | |
| 244 | |
| 245 const std::string& id = | 250 const std::string& id = |
| 246 *content::Details<const std::string>(details).ptr(); | 251 *content::Details<const std::string>(details).ptr(); |
| 247 const AppNotification* notification = | 252 const AppNotification* notification = |
| 248 extension_service_->app_notification_manager()->GetLast(id); | 253 extension_service_->app_notification_manager()->GetLast(id); |
| 249 base::StringValue id_value(id); | 254 base::StringValue id_value(id); |
| 250 if (notification) { | 255 if (notification) { |
| 251 scoped_ptr<DictionaryValue> notification_value( | 256 scoped_ptr<DictionaryValue> notification_value( |
| 252 SerializeNotification(*notification)); | 257 SerializeNotification(*notification)); |
| 253 web_ui_->CallJavascriptFunction("appNotificationChanged", | 258 web_ui_->CallJavascriptFunction("appNotificationChanged", |
| 254 id_value, *notification_value.get()); | 259 id_value, *notification_value.get()); |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 461 | 466 |
| 462 // First time we get here we set up the observer so that we can tell update | 467 // First time we get here we set up the observer so that we can tell update |
| 463 // the apps as they change. | 468 // the apps as they change. |
| 464 if (!has_loaded_apps_) { | 469 if (!has_loaded_apps_) { |
| 465 pref_change_registrar_.Init( | 470 pref_change_registrar_.Init( |
| 466 extension_service_->extension_prefs()->pref_service()); | 471 extension_service_->extension_prefs()->pref_service()); |
| 467 pref_change_registrar_.Add(ExtensionPrefs::kExtensionsPref, this); | 472 pref_change_registrar_.Add(ExtensionPrefs::kExtensionsPref, this); |
| 468 pref_change_registrar_.Add(prefs::kNTPAppPageNames, this); | 473 pref_change_registrar_.Add(prefs::kNTPAppPageNames, this); |
| 469 | 474 |
| 470 registrar_.Add(this, chrome::NOTIFICATION_APP_NOTIFICATION_STATE_CHANGED, | 475 registrar_.Add(this, chrome::NOTIFICATION_APP_NOTIFICATION_STATE_CHANGED, |
| 471 content::NotificationService::AllSources()); | 476 content::Source<Profile>(profile)); |
| 472 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, | 477 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, |
| 473 content::Source<Profile>(profile)); | 478 content::Source<Profile>(profile)); |
| 474 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, | 479 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, |
| 475 content::Source<Profile>(profile)); | 480 content::Source<Profile>(profile)); |
| 476 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LAUNCHER_REORDERED, | 481 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LAUNCHER_REORDERED, |
| 477 content::Source<ExtensionPrefs>(extension_service_->extension_prefs())); | 482 content::Source<ExtensionPrefs>(extension_service_->extension_prefs())); |
| 478 registrar_.Add(this, chrome::NOTIFICATION_WEB_STORE_PROMO_LOADED, | 483 registrar_.Add(this, chrome::NOTIFICATION_WEB_STORE_PROMO_LOADED, |
| 479 content::Source<Profile>(profile)); | 484 content::Source<Profile>(profile)); |
| 480 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_INSTALL_ERROR, | 485 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_INSTALL_ERROR, |
| 481 content::Source<CrxInstaller>(NULL)); | 486 content::Source<CrxInstaller>(NULL)); |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 734 const Extension* extension = extension_service_->GetExtensionById( | 739 const Extension* extension = extension_service_->GetExtensionById( |
| 735 extension_id, true); | 740 extension_id, true); |
| 736 if (!extension) | 741 if (!extension) |
| 737 return; | 742 return; |
| 738 | 743 |
| 739 AppNotificationManager* notification_manager = | 744 AppNotificationManager* notification_manager = |
| 740 extension_service_->app_notification_manager(); | 745 extension_service_->app_notification_manager(); |
| 741 notification_manager->ClearAll(extension_id); | 746 notification_manager->ClearAll(extension_id); |
| 742 } | 747 } |
| 743 | 748 |
| 749 void AppLauncherHandler::HandleSetNotificationsDisabled( |
| 750 const ListValue* args) { |
| 751 std::string extension_id; |
| 752 bool disabled = false; |
| 753 CHECK(args->GetString(0, &extension_id)); |
| 754 CHECK(args->GetBoolean(1, &disabled)); |
| 755 |
| 756 const Extension* extension = extension_service_->GetExtensionById( |
| 757 extension_id, true); |
| 758 if (!extension) |
| 759 return; |
| 760 extension_service_->SetAppNotificationDisabled(extension_id, disabled); |
| 761 } |
| 762 |
| 744 void AppLauncherHandler::OnFaviconForApp(FaviconService::Handle handle, | 763 void AppLauncherHandler::OnFaviconForApp(FaviconService::Handle handle, |
| 745 history::FaviconData data) { | 764 history::FaviconData data) { |
| 746 scoped_ptr<AppInstallInfo> install_info( | 765 scoped_ptr<AppInstallInfo> install_info( |
| 747 favicon_consumer_.GetClientDataForCurrentRequest()); | 766 favicon_consumer_.GetClientDataForCurrentRequest()); |
| 748 scoped_ptr<WebApplicationInfo> web_app(new WebApplicationInfo()); | 767 scoped_ptr<WebApplicationInfo> web_app(new WebApplicationInfo()); |
| 749 web_app->is_bookmark_app = install_info->is_bookmark_app; | 768 web_app->is_bookmark_app = install_info->is_bookmark_app; |
| 750 web_app->title = install_info->title; | 769 web_app->title = install_info->title; |
| 751 web_app->app_url = install_info->app_url; | 770 web_app->app_url = install_info->app_url; |
| 752 web_app->urls.push_back(install_info->app_url); | 771 web_app->urls.push_back(install_info->app_url); |
| 753 | 772 |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 934 | 953 |
| 935 void AppLauncherHandler::UninstallDefaultApps() { | 954 void AppLauncherHandler::UninstallDefaultApps() { |
| 936 AppsPromo* apps_promo = extension_service_->apps_promo(); | 955 AppsPromo* apps_promo = extension_service_->apps_promo(); |
| 937 const ExtensionIdSet& app_ids = apps_promo->old_default_apps(); | 956 const ExtensionIdSet& app_ids = apps_promo->old_default_apps(); |
| 938 for (ExtensionIdSet::const_iterator iter = app_ids.begin(); | 957 for (ExtensionIdSet::const_iterator iter = app_ids.begin(); |
| 939 iter != app_ids.end(); ++iter) { | 958 iter != app_ids.end(); ++iter) { |
| 940 if (extension_service_->GetExtensionById(*iter, true)) | 959 if (extension_service_->GetExtensionById(*iter, true)) |
| 941 extension_service_->UninstallExtension(*iter, false, NULL); | 960 extension_service_->UninstallExtension(*iter, false, NULL); |
| 942 } | 961 } |
| 943 } | 962 } |
| OLD | NEW |