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 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 base::Unretained(this))); | 270 base::Unretained(this))); |
271 web_ui_->RegisterMessageCallback("saveAppPageName", | 271 web_ui_->RegisterMessageCallback("saveAppPageName", |
272 base::Bind(&AppLauncherHandler::HandleSaveAppPageName, | 272 base::Bind(&AppLauncherHandler::HandleSaveAppPageName, |
273 base::Unretained(this))); | 273 base::Unretained(this))); |
274 web_ui_->RegisterMessageCallback("generateAppForLink", | 274 web_ui_->RegisterMessageCallback("generateAppForLink", |
275 base::Bind(&AppLauncherHandler::HandleGenerateAppForLink, | 275 base::Bind(&AppLauncherHandler::HandleGenerateAppForLink, |
276 base::Unretained(this))); | 276 base::Unretained(this))); |
277 web_ui_->RegisterMessageCallback("recordAppLaunchByURL", | 277 web_ui_->RegisterMessageCallback("recordAppLaunchByURL", |
278 base::Bind(&AppLauncherHandler::HandleRecordAppLaunchByURL, | 278 base::Bind(&AppLauncherHandler::HandleRecordAppLaunchByURL, |
279 base::Unretained(this))); | 279 base::Unretained(this))); |
| 280 web_ui_->RegisterMessageCallback("closeNotification", |
| 281 base::Bind(&AppLauncherHandler::HandleNotificationClose, |
| 282 base::Unretained(this))); |
280 } | 283 } |
281 | 284 |
282 void AppLauncherHandler::Observe(int type, | 285 void AppLauncherHandler::Observe(int type, |
283 const content::NotificationSource& source, | 286 const content::NotificationSource& source, |
284 const content::NotificationDetails& details) { | 287 const content::NotificationDetails& details) { |
285 if (type == chrome::NOTIFICATION_APP_INSTALLED_TO_NTP && | 288 if (type == chrome::NOTIFICATION_APP_INSTALLED_TO_NTP && |
286 NewTabUI::NTP4Enabled()) { | 289 NewTabUI::NTP4Enabled()) { |
287 highlight_app_id_ = *content::Details<const std::string>(details).ptr(); | 290 highlight_app_id_ = *content::Details<const std::string>(details).ptr(); |
288 if (has_loaded_apps_) | 291 if (has_loaded_apps_) |
289 SetAppToBeHighlighted(); | 292 SetAppToBeHighlighted(); |
(...skipping 540 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
830 double source; | 833 double source; |
831 CHECK(args->GetDouble(1, &source)); | 834 CHECK(args->GetDouble(1, &source)); |
832 | 835 |
833 extension_misc::AppLaunchBucket bucket = | 836 extension_misc::AppLaunchBucket bucket = |
834 static_cast<extension_misc::AppLaunchBucket>(static_cast<int>(source)); | 837 static_cast<extension_misc::AppLaunchBucket>(static_cast<int>(source)); |
835 CHECK(source < extension_misc::APP_LAUNCH_BUCKET_BOUNDARY); | 838 CHECK(source < extension_misc::APP_LAUNCH_BUCKET_BOUNDARY); |
836 | 839 |
837 RecordAppLaunchByURL(Profile::FromWebUI(web_ui_), url, bucket); | 840 RecordAppLaunchByURL(Profile::FromWebUI(web_ui_), url, bucket); |
838 } | 841 } |
839 | 842 |
| 843 void AppLauncherHandler::HandleNotificationClose(const ListValue* args) { |
| 844 std::string extension_id; |
| 845 CHECK(args->GetString(0, &extension_id)); |
| 846 |
| 847 const Extension* extension = extension_service_->GetExtensionById( |
| 848 extension_id, true); |
| 849 if (!extension) |
| 850 return; |
| 851 |
| 852 AppNotificationManager* notification_manager = |
| 853 extension_service_->app_notification_manager(); |
| 854 notification_manager->ClearAll(extension_id); |
| 855 } |
| 856 |
840 void AppLauncherHandler::OnFaviconForApp(FaviconService::Handle handle, | 857 void AppLauncherHandler::OnFaviconForApp(FaviconService::Handle handle, |
841 history::FaviconData data) { | 858 history::FaviconData data) { |
842 scoped_ptr<AppInstallInfo> install_info( | 859 scoped_ptr<AppInstallInfo> install_info( |
843 favicon_consumer_.GetClientDataForCurrentRequest()); | 860 favicon_consumer_.GetClientDataForCurrentRequest()); |
844 scoped_ptr<WebApplicationInfo> web_app(new WebApplicationInfo()); | 861 scoped_ptr<WebApplicationInfo> web_app(new WebApplicationInfo()); |
845 web_app->is_bookmark_app = install_info->is_bookmark_app; | 862 web_app->is_bookmark_app = install_info->is_bookmark_app; |
846 web_app->title = install_info->title; | 863 web_app->title = install_info->title; |
847 web_app->app_url = install_info->app_url; | 864 web_app->app_url = install_info->app_url; |
848 web_app->urls.push_back(install_info->app_url); | 865 web_app->urls.push_back(install_info->app_url); |
849 | 866 |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1036 | 1053 |
1037 void AppLauncherHandler::UninstallDefaultApps() { | 1054 void AppLauncherHandler::UninstallDefaultApps() { |
1038 AppsPromo* apps_promo = extension_service_->apps_promo(); | 1055 AppsPromo* apps_promo = extension_service_->apps_promo(); |
1039 const ExtensionIdSet& app_ids = apps_promo->old_default_apps(); | 1056 const ExtensionIdSet& app_ids = apps_promo->old_default_apps(); |
1040 for (ExtensionIdSet::const_iterator iter = app_ids.begin(); | 1057 for (ExtensionIdSet::const_iterator iter = app_ids.begin(); |
1041 iter != app_ids.end(); ++iter) { | 1058 iter != app_ids.end(); ++iter) { |
1042 if (extension_service_->GetExtensionById(*iter, true)) | 1059 if (extension_service_->GetExtensionById(*iter, true)) |
1043 extension_service_->UninstallExtension(*iter, false, NULL); | 1060 extension_service_->UninstallExtension(*iter, false, NULL); |
1044 } | 1061 } |
1045 } | 1062 } |
OLD | NEW |