Chromium Code Reviews| 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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 109 return false; | 109 return false; |
| 110 } | 110 } |
| 111 | 111 |
| 112 void AppLauncherHandler::CreateAppInfo(const Extension* extension, | 112 void AppLauncherHandler::CreateAppInfo(const Extension* extension, |
| 113 const AppNotification* notification, | 113 const AppNotification* notification, |
| 114 ExtensionService* service, | 114 ExtensionService* service, |
| 115 DictionaryValue* value) { | 115 DictionaryValue* value) { |
| 116 bool enabled = service->IsExtensionEnabled(extension->id()) && | 116 bool enabled = service->IsExtensionEnabled(extension->id()) && |
| 117 !service->GetTerminatedExtension(extension->id()); | 117 !service->GetTerminatedExtension(extension->id()); |
| 118 bool icon_big_exists = true; | 118 bool icon_big_exists = true; |
| 119 // Instead of setting grayscale here, we do it in the js. | |
|
Evan Stade
2011/08/30 03:34:14
probably best to check for NTP4
Yoyo Zhou
2011/08/30 17:37:10
Done.
| |
| 119 GURL icon_big = | 120 GURL icon_big = |
| 120 ExtensionIconSource::GetIconURL(extension, | 121 ExtensionIconSource::GetIconURL(extension, |
| 121 Extension::EXTENSION_ICON_LARGE, | 122 Extension::EXTENSION_ICON_LARGE, |
| 122 ExtensionIconSet::MATCH_EXACTLY, | 123 ExtensionIconSet::MATCH_EXACTLY, |
| 123 !enabled, &icon_big_exists); | 124 false, &icon_big_exists); |
| 124 bool icon_small_exists = true; | 125 bool icon_small_exists = true; |
| 125 GURL icon_small = | 126 GURL icon_small = |
| 126 ExtensionIconSource::GetIconURL(extension, | 127 ExtensionIconSource::GetIconURL(extension, |
| 127 Extension::EXTENSION_ICON_BITTY, | 128 Extension::EXTENSION_ICON_BITTY, |
| 128 ExtensionIconSet::MATCH_BIGGER, | 129 ExtensionIconSet::MATCH_BIGGER, |
| 129 !enabled, &icon_small_exists); | 130 false, &icon_small_exists); |
| 130 | 131 |
| 131 value->Clear(); | 132 value->Clear(); |
| 132 value->SetString("id", extension->id()); | 133 value->SetString("id", extension->id()); |
| 133 value->SetString("name", extension->name()); | 134 value->SetString("name", extension->name()); |
| 134 value->SetString("description", extension->description()); | 135 value->SetString("description", extension->description()); |
| 135 value->SetString("launch_url", extension->GetFullLaunchURL().spec()); | 136 value->SetString("launch_url", extension->GetFullLaunchURL().spec()); |
| 136 if (enabled) | 137 value->SetBoolean("enabled", enabled); |
| 137 value->SetString("options_url", extension->options_url().spec()); | 138 value->SetString("options_url", extension->options_url().spec()); |
| 138 value->SetBoolean("can_uninstall", | 139 value->SetBoolean("can_uninstall", |
| 139 Extension::UserMayDisable(extension->location())); | 140 Extension::UserMayDisable(extension->location())); |
| 140 value->SetString("icon_big", icon_big.spec()); | 141 value->SetString("icon_big", icon_big.spec()); |
| 141 value->SetBoolean("icon_big_exists", icon_big_exists); | 142 value->SetBoolean("icon_big_exists", icon_big_exists); |
| 142 value->SetString("icon_small", icon_small.spec()); | 143 value->SetString("icon_small", icon_small.spec()); |
| 143 value->SetBoolean("icon_small_exists", icon_small_exists); | 144 value->SetBoolean("icon_small_exists", icon_small_exists); |
| 144 value->SetInteger("launch_container", extension->launch_container()); | 145 value->SetInteger("launch_container", extension->launch_container()); |
| 145 ExtensionPrefs* prefs = service->extension_prefs(); | 146 ExtensionPrefs* prefs = service->extension_prefs(); |
| 146 value->SetInteger("launch_type", | 147 value->SetInteger("launch_type", |
| 147 prefs->GetLaunchType(extension->id(), | 148 prefs->GetLaunchType(extension->id(), |
| 148 ExtensionPrefs::LAUNCH_DEFAULT)); | 149 ExtensionPrefs::LAUNCH_DEFAULT)); |
| 150 value->SetBoolean("offline_enabled", extension->offline_enabled()); | |
| 149 value->SetBoolean("is_component", | 151 value->SetBoolean("is_component", |
| 150 extension->location() == Extension::COMPONENT); | 152 extension->location() == Extension::COMPONENT); |
| 151 value->SetBoolean("is_webstore", | 153 value->SetBoolean("is_webstore", |
| 152 extension->id() == extension_misc::kWebStoreAppId); | 154 extension->id() == extension_misc::kWebStoreAppId); |
| 153 | 155 |
| 154 if (notification) | 156 if (notification) |
| 155 value->Set("notification", SerializeNotification(*notification)); | 157 value->Set("notification", SerializeNotification(*notification)); |
| 156 | 158 |
| 157 int app_launch_index = prefs->GetAppLaunchIndex(extension->id()); | 159 int app_launch_index = prefs->GetAppLaunchIndex(extension->id()); |
| 158 if (app_launch_index == -1) { | 160 if (app_launch_index == -1) { |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 287 attempted_bookmark_app_install_)); | 289 attempted_bookmark_app_install_)); |
| 288 attempted_bookmark_app_install_ = false; | 290 attempted_bookmark_app_install_ = false; |
| 289 web_ui_->CallJavascriptFunction("ntp4.appAdded", *app_info, *highlight); | 291 web_ui_->CallJavascriptFunction("ntp4.appAdded", *app_info, *highlight); |
| 290 } | 292 } |
| 291 | 293 |
| 292 break; | 294 break; |
| 293 } | 295 } |
| 294 case chrome::NOTIFICATION_EXTENSION_UNLOADED: { | 296 case chrome::NOTIFICATION_EXTENSION_UNLOADED: { |
| 295 const Extension* extension = | 297 const Extension* extension = |
| 296 Details<UnloadedExtensionInfo>(details)->extension; | 298 Details<UnloadedExtensionInfo>(details)->extension; |
| 299 bool is_uninstall = | |
|
Evan Stade
2011/08/30 03:34:14
define this right above first use, not here
Yoyo Zhou
2011/08/30 17:37:10
Done.
| |
| 300 (Details<UnloadedExtensionInfo>(details)->reason == | |
|
Evan Stade
2011/08/30 03:34:14
don't need ()
Yoyo Zhou
2011/08/30 17:37:10
Gone.
| |
| 301 extension_misc::UNLOAD_REASON_UNINSTALL); | |
| 297 if (!extension->is_app()) | 302 if (!extension->is_app()) |
| 298 return; | 303 return; |
| 299 | 304 |
| 300 if (!NewTabUI::NTP4Enabled()) { | 305 if (!NewTabUI::NTP4Enabled()) { |
| 301 HandleGetApps(NULL); | 306 HandleGetApps(NULL); |
| 302 break; | 307 break; |
| 303 } | 308 } |
| 304 | 309 |
| 305 scoped_ptr<DictionaryValue> app_info(GetAppInfo(extension)); | 310 scoped_ptr<DictionaryValue> app_info(GetAppInfo(extension)); |
| 306 if (app_info.get()) | 311 scoped_ptr<BooleanValue> uninstall_value( |
| 307 web_ui_->CallJavascriptFunction("ntp4.appRemoved", *app_info); | 312 Value::CreateBooleanValue(is_uninstall)); |
| 308 break; | 313 if (app_info.get()) { |
| 314 web_ui_->CallJavascriptFunction( | |
| 315 "ntp4.appRemoved", *app_info, *uninstall_value); | |
| 316 } | |
|
Evan Stade
2011/08/30 03:34:14
no break?
Yoyo Zhou
2011/08/30 17:37:10
Argh, lost it in the merge. Good catch.
| |
| 309 } | 317 } |
| 310 case chrome::NOTIFICATION_EXTENSION_LAUNCHER_REORDERED: | 318 case chrome::NOTIFICATION_EXTENSION_LAUNCHER_REORDERED: |
| 311 // The promo may not load until a couple seconds after the first NTP view, | 319 // The promo may not load until a couple seconds after the first NTP view, |
| 312 // so we listen for the load notification and notify the NTP when ready. | 320 // so we listen for the load notification and notify the NTP when ready. |
| 313 case chrome::NOTIFICATION_WEB_STORE_PROMO_LOADED: | 321 case chrome::NOTIFICATION_WEB_STORE_PROMO_LOADED: |
| 314 if (web_ui_->tab_contents()) | 322 if (web_ui_->tab_contents()) |
| 315 HandleGetApps(NULL); | 323 HandleGetApps(NULL); |
| 316 break; | 324 break; |
| 317 case chrome::NOTIFICATION_PREF_CHANGED: { | 325 case chrome::NOTIFICATION_PREF_CHANGED: { |
| 318 if (!web_ui_->tab_contents()) | 326 if (!web_ui_->tab_contents()) |
| (...skipping 634 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 953 | 961 |
| 954 void AppLauncherHandler::UninstallDefaultApps() { | 962 void AppLauncherHandler::UninstallDefaultApps() { |
| 955 AppsPromo* apps_promo = extension_service_->apps_promo(); | 963 AppsPromo* apps_promo = extension_service_->apps_promo(); |
| 956 const ExtensionIdSet& app_ids = apps_promo->old_default_apps(); | 964 const ExtensionIdSet& app_ids = apps_promo->old_default_apps(); |
| 957 for (ExtensionIdSet::const_iterator iter = app_ids.begin(); | 965 for (ExtensionIdSet::const_iterator iter = app_ids.begin(); |
| 958 iter != app_ids.end(); ++iter) { | 966 iter != app_ids.end(); ++iter) { |
| 959 if (extension_service_->GetExtensionById(*iter, true)) | 967 if (extension_service_->GetExtensionById(*iter, true)) |
| 960 extension_service_->UninstallExtension(*iter, false, NULL); | 968 extension_service_->UninstallExtension(*iter, false, NULL); |
| 961 } | 969 } |
| 962 } | 970 } |
| OLD | NEW |