OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 (extension->id() == extension_misc::kCloudPrintAppId)) { | 104 (extension->id() == extension_misc::kCloudPrintAppId)) { |
105 return true; | 105 return true; |
106 } | 106 } |
107 return false; | 107 return false; |
108 } | 108 } |
109 | 109 |
110 void AppLauncherHandler::CreateAppInfo(const Extension* extension, | 110 void AppLauncherHandler::CreateAppInfo(const Extension* extension, |
111 const AppNotification* notification, | 111 const AppNotification* notification, |
112 ExtensionService* service, | 112 ExtensionService* service, |
113 DictionaryValue* value) { | 113 DictionaryValue* value) { |
114 bool enabled = service->IsExtensionEnabled(extension->id()) && | 114 bool enabled = service->IsExtensionEnabled(extension->id()); |
115 !service->GetTerminatedExtension(extension->id()); | |
116 bool icon_big_exists = true; | 115 bool icon_big_exists = true; |
117 // Instead of setting grayscale here, we do it in apps_page.js. | 116 // Instead of setting grayscale here, we do it in apps_page.js. |
118 GURL icon_big = | 117 GURL icon_big = |
119 ExtensionIconSource::GetIconURL(extension, | 118 ExtensionIconSource::GetIconURL(extension, |
120 Extension::EXTENSION_ICON_LARGE, | 119 Extension::EXTENSION_ICON_LARGE, |
121 ExtensionIconSet::MATCH_EXACTLY, | 120 ExtensionIconSet::MATCH_EXACTLY, |
122 false, &icon_big_exists); | 121 false, &icon_big_exists); |
123 bool icon_small_exists = true; | 122 bool icon_small_exists = true; |
124 GURL icon_small = | 123 GURL icon_small = |
125 ExtensionIconSource::GetIconURL(extension, | 124 ExtensionIconSource::GetIconURL(extension, |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 if (!IsAppExcludedFromList(*it)) { | 370 if (!IsAppExcludedFromList(*it)) { |
372 DictionaryValue* app_info = new DictionaryValue(); | 371 DictionaryValue* app_info = new DictionaryValue(); |
373 CreateAppInfo(*it, | 372 CreateAppInfo(*it, |
374 NULL, | 373 NULL, |
375 extension_service_, | 374 extension_service_, |
376 app_info); | 375 app_info); |
377 list->Append(app_info); | 376 list->Append(app_info); |
378 } | 377 } |
379 } | 378 } |
380 | 379 |
381 extensions = extension_service_->terminated_extensions(); | |
382 for (it = extensions->begin(); it != extensions->end(); ++it) { | |
383 if (!IsAppExcludedFromList(*it)) { | |
384 DictionaryValue* app_info = new DictionaryValue(); | |
385 CreateAppInfo(*it, | |
386 NULL, | |
387 extension_service_, | |
388 app_info); | |
389 list->Append(app_info); | |
390 } | |
391 } | |
392 | |
393 dictionary->Set("apps", list); | 380 dictionary->Set("apps", list); |
394 | 381 |
395 // TODO(estade): remove these settings when the old NTP is removed. The new | 382 // TODO(estade): remove these settings when the old NTP is removed. The new |
396 // NTP does it in js. | 383 // NTP does it in js. |
397 #if defined(OS_MACOSX) | 384 #if defined(OS_MACOSX) |
398 // App windows are not yet implemented on mac. | 385 // App windows are not yet implemented on mac. |
399 dictionary->SetBoolean("disableAppWindowLaunch", true); | 386 dictionary->SetBoolean("disableAppWindowLaunch", true); |
400 dictionary->SetBoolean("disableCreateAppShortcut", true); | 387 dictionary->SetBoolean("disableCreateAppShortcut", true); |
401 #endif | 388 #endif |
402 | 389 |
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
881 if (!profile->GetExtensionService()->IsInstalledApp(url)) | 868 if (!profile->GetExtensionService()->IsInstalledApp(url)) |
882 return; | 869 return; |
883 | 870 |
884 UMA_HISTOGRAM_ENUMERATION(extension_misc::kAppLaunchHistogram, bucket, | 871 UMA_HISTOGRAM_ENUMERATION(extension_misc::kAppLaunchHistogram, bucket, |
885 extension_misc::APP_LAUNCH_BUCKET_BOUNDARY); | 872 extension_misc::APP_LAUNCH_BUCKET_BOUNDARY); |
886 } | 873 } |
887 | 874 |
888 void AppLauncherHandler::PromptToEnableApp(const std::string& extension_id) { | 875 void AppLauncherHandler::PromptToEnableApp(const std::string& extension_id) { |
889 const Extension* extension = | 876 const Extension* extension = |
890 extension_service_->GetExtensionById(extension_id, true); | 877 extension_service_->GetExtensionById(extension_id, true); |
891 if (!extension) { | 878 // It's possible (though unlikely) the app could have been uninstalled since |
892 extension = extension_service_->GetTerminatedExtension(extension_id); | 879 // the user clicked on it. |
893 // It's possible (though unlikely) the app could have been uninstalled since | 880 if (!extension) |
894 // the user clicked on it. | 881 return; |
895 if (!extension) | |
896 return; | |
897 // If the app was terminated, reload it first. (This reallocates the | |
898 // Extension object.) | |
899 extension_service_->ReloadExtension(extension_id); | |
900 extension = extension_service_->GetExtensionById(extension_id, true); | |
901 } | |
902 | 882 |
903 ExtensionPrefs* extension_prefs = extension_service_->extension_prefs(); | 883 ExtensionPrefs* extension_prefs = extension_service_->extension_prefs(); |
904 if (!extension_prefs->DidExtensionEscalatePermissions(extension_id)) { | 884 if (!extension_prefs->DidExtensionEscalatePermissions(extension_id)) { |
905 // Enable the extension immediately if its privileges weren't escalated. | 885 // Enable the extension immediately if its privileges weren't escalated. |
906 // This is a no-op if the extension was previously terminated. | |
907 extension_service_->EnableExtension(extension_id); | 886 extension_service_->EnableExtension(extension_id); |
908 | 887 |
909 // Launch app asynchronously so the image will update. | 888 // Launch app asynchronously so the image will update. |
910 StringValue app_id(extension_id); | 889 StringValue app_id(extension_id); |
911 web_ui()->CallJavascriptFunction("launchAppAfterEnable", app_id); | 890 web_ui()->CallJavascriptFunction("launchAppAfterEnable", app_id); |
912 return; | 891 return; |
913 } | 892 } |
914 | 893 |
915 if (!extension_id_prompting_.empty()) | 894 if (!extension_id_prompting_.empty()) |
916 return; // Only one prompt at a time. | 895 return; // Only one prompt at a time. |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
994 | 973 |
995 void AppLauncherHandler::UninstallDefaultApps() { | 974 void AppLauncherHandler::UninstallDefaultApps() { |
996 AppsPromo* apps_promo = extension_service_->apps_promo(); | 975 AppsPromo* apps_promo = extension_service_->apps_promo(); |
997 const ExtensionIdSet& app_ids = apps_promo->old_default_apps(); | 976 const ExtensionIdSet& app_ids = apps_promo->old_default_apps(); |
998 for (ExtensionIdSet::const_iterator iter = app_ids.begin(); | 977 for (ExtensionIdSet::const_iterator iter = app_ids.begin(); |
999 iter != app_ids.end(); ++iter) { | 978 iter != app_ids.end(); ++iter) { |
1000 if (extension_service_->GetExtensionById(*iter, true)) | 979 if (extension_service_->GetExtensionById(*iter, true)) |
1001 extension_service_->UninstallExtension(*iter, false, NULL); | 980 extension_service_->UninstallExtension(*iter, false, NULL); |
1002 } | 981 } |
1003 } | 982 } |
OLD | NEW |