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 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 const std::string& id = *Details<const std::string>(details).ptr(); | 262 const std::string& id = *Details<const std::string>(details).ptr(); |
263 const AppNotification* notification = | 263 const AppNotification* notification = |
264 extension_service_->app_notification_manager()->GetLast(id); | 264 extension_service_->app_notification_manager()->GetLast(id); |
265 ListValue args; | 265 ListValue args; |
266 args.Append(new StringValue(id)); | 266 args.Append(new StringValue(id)); |
267 if (notification) | 267 if (notification) |
268 args.Append(SerializeNotification(*notification)); | 268 args.Append(SerializeNotification(*notification)); |
269 web_ui_->CallJavascriptFunction("appNotificationChanged", args); | 269 web_ui_->CallJavascriptFunction("appNotificationChanged", args); |
270 break; | 270 break; |
271 } | 271 } |
| 272 case chrome::NOTIFICATION_APP_INSTALLED_TO_NTP: { |
| 273 const std::string* extension_id = |
| 274 Details<const std::string>(details).ptr(); |
| 275 |
| 276 if (!NewTabUI::NTP4Enabled()) |
| 277 break; |
| 278 |
| 279 scoped_ptr<StringValue> app_id(Value::CreateStringValue(*extension_id)); |
| 280 web_ui_->CallJavascriptFunction("ntp4.setAppToBeHighlighted", *app_id); |
| 281 break; |
| 282 } |
272 case chrome::NOTIFICATION_EXTENSION_LOADED: { | 283 case chrome::NOTIFICATION_EXTENSION_LOADED: { |
273 const Extension* extension = Details<const Extension>(details).ptr(); | 284 const Extension* extension = Details<const Extension>(details).ptr(); |
274 if (!extension->is_app()) | 285 if (!extension->is_app()) |
275 return; | 286 return; |
276 | 287 |
277 if (!NewTabUI::NTP4Enabled()) { | 288 if (!NewTabUI::NTP4Enabled()) { |
278 HandleGetApps(NULL); | 289 HandleGetApps(NULL); |
279 break; | 290 break; |
280 } | 291 } |
281 | 292 |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
464 } | 475 } |
465 | 476 |
466 FillAppDictionary(&dictionary); | 477 FillAppDictionary(&dictionary); |
467 web_ui_->CallJavascriptFunction("getAppsCallback", dictionary); | 478 web_ui_->CallJavascriptFunction("getAppsCallback", dictionary); |
468 | 479 |
469 // First time we get here we set up the observer so that we can tell update | 480 // First time we get here we set up the observer so that we can tell update |
470 // the apps as they change. | 481 // the apps as they change. |
471 if (registrar_.IsEmpty()) { | 482 if (registrar_.IsEmpty()) { |
472 registrar_.Add(this, chrome::NOTIFICATION_APP_NOTIFICATION_STATE_CHANGED, | 483 registrar_.Add(this, chrome::NOTIFICATION_APP_NOTIFICATION_STATE_CHANGED, |
473 NotificationService::AllSources()); | 484 NotificationService::AllSources()); |
| 485 registrar_.Add(this, chrome::NOTIFICATION_APP_INSTALLED_TO_NTP, |
| 486 Source<TabContents>(web_ui_->tab_contents())); |
474 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, | 487 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, |
475 NotificationService::AllSources()); | 488 NotificationService::AllSources()); |
476 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, | 489 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, |
477 NotificationService::AllSources()); | 490 NotificationService::AllSources()); |
478 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LAUNCHER_REORDERED, | 491 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LAUNCHER_REORDERED, |
479 NotificationService::AllSources()); | 492 NotificationService::AllSources()); |
480 registrar_.Add(this, chrome::NOTIFICATION_WEB_STORE_PROMO_LOADED, | 493 registrar_.Add(this, chrome::NOTIFICATION_WEB_STORE_PROMO_LOADED, |
481 NotificationService::AllSources()); | 494 NotificationService::AllSources()); |
482 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_INSTALL_ERROR, | 495 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_INSTALL_ERROR, |
483 NotificationService::AllSources()); | 496 NotificationService::AllSources()); |
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
858 extension = extension_service_->GetExtensionById(extension_id, true); | 871 extension = extension_service_->GetExtensionById(extension_id, true); |
859 } | 872 } |
860 | 873 |
861 ExtensionPrefs* extension_prefs = extension_service_->extension_prefs(); | 874 ExtensionPrefs* extension_prefs = extension_service_->extension_prefs(); |
862 if (!extension_prefs->DidExtensionEscalatePermissions(extension_id)) { | 875 if (!extension_prefs->DidExtensionEscalatePermissions(extension_id)) { |
863 // Enable the extension immediately if its privileges weren't escalated. | 876 // Enable the extension immediately if its privileges weren't escalated. |
864 // This is a no-op if the extension was previously terminated. | 877 // This is a no-op if the extension was previously terminated. |
865 extension_service_->EnableExtension(extension_id); | 878 extension_service_->EnableExtension(extension_id); |
866 | 879 |
867 // Launch app asynchronously so the image will update. | 880 // Launch app asynchronously so the image will update. |
868 StringValue* app_id = Value::CreateStringValue(extension_id); | 881 scoped_ptr<StringValue> app_id(Value::CreateStringValue(extension_id)); |
869 web_ui_->CallJavascriptFunction("launchAppAfterEnable", *app_id); | 882 web_ui_->CallJavascriptFunction("launchAppAfterEnable", *app_id); |
870 return; | 883 return; |
871 } | 884 } |
872 | 885 |
873 if (!extension_id_prompting_.empty()) | 886 if (!extension_id_prompting_.empty()) |
874 return; // Only one prompt at a time. | 887 return; // Only one prompt at a time. |
875 | 888 |
876 extension_id_prompting_ = extension_id; | 889 extension_id_prompting_ = extension_id; |
877 GetExtensionInstallUI()->ConfirmReEnable(this, extension); | 890 GetExtensionInstallUI()->ConfirmReEnable(this, extension); |
878 } | 891 } |
(...skipping 29 matching lines...) Expand all Loading... |
908 extension_service_->GetExtensionById(extension_id_prompting_, true); | 921 extension_service_->GetExtensionById(extension_id_prompting_, true); |
909 if (!extension) | 922 if (!extension) |
910 return; | 923 return; |
911 | 924 |
912 extension_service_->GrantPermissionsAndEnableExtension(extension); | 925 extension_service_->GrantPermissionsAndEnableExtension(extension); |
913 | 926 |
914 // We bounce this off the NTP so the browser can update the apps icon. | 927 // We bounce this off the NTP so the browser can update the apps icon. |
915 // If we don't launch the app asynchronously, then the app's disabled | 928 // If we don't launch the app asynchronously, then the app's disabled |
916 // icon disappears but isn't replaced by the enabled icon, making a poor | 929 // icon disappears but isn't replaced by the enabled icon, making a poor |
917 // visual experience. | 930 // visual experience. |
918 StringValue* app_id = Value::CreateStringValue(extension->id()); | 931 scoped_ptr<StringValue> app_id(Value::CreateStringValue(extension->id())); |
919 web_ui_->CallJavascriptFunction("launchAppAfterEnable", *app_id); | 932 web_ui_->CallJavascriptFunction("launchAppAfterEnable", *app_id); |
920 | 933 |
921 extension_id_prompting_ = ""; | 934 extension_id_prompting_ = ""; |
922 } | 935 } |
923 | 936 |
924 void AppLauncherHandler::InstallUIAbort(bool user_initiated) { | 937 void AppLauncherHandler::InstallUIAbort(bool user_initiated) { |
925 // We record the histograms here because ExtensionDialogCanceled is also | 938 // We record the histograms here because ExtensionDialogCanceled is also |
926 // called when the extension uninstall dialog is canceled. | 939 // called when the extension uninstall dialog is canceled. |
927 const Extension* extension = | 940 const Extension* extension = |
928 extension_service_->GetExtensionById(extension_id_prompting_, true); | 941 extension_service_->GetExtensionById(extension_id_prompting_, true); |
(...skipping 24 matching lines...) Expand all Loading... |
953 | 966 |
954 void AppLauncherHandler::UninstallDefaultApps() { | 967 void AppLauncherHandler::UninstallDefaultApps() { |
955 AppsPromo* apps_promo = extension_service_->apps_promo(); | 968 AppsPromo* apps_promo = extension_service_->apps_promo(); |
956 const ExtensionIdSet& app_ids = apps_promo->old_default_apps(); | 969 const ExtensionIdSet& app_ids = apps_promo->old_default_apps(); |
957 for (ExtensionIdSet::const_iterator iter = app_ids.begin(); | 970 for (ExtensionIdSet::const_iterator iter = app_ids.begin(); |
958 iter != app_ids.end(); ++iter) { | 971 iter != app_ids.end(); ++iter) { |
959 if (extension_service_->GetExtensionById(*iter, true)) | 972 if (extension_service_->GetExtensionById(*iter, true)) |
960 extension_service_->UninstallExtension(*iter, false, NULL); | 973 extension_service_->UninstallExtension(*iter, false, NULL); |
961 } | 974 } |
962 } | 975 } |
OLD | NEW |