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