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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 return false; | 110 return false; |
111 } | 111 } |
112 | 112 |
113 void AppLauncherHandler::CreateAppInfo(const Extension* extension, | 113 void AppLauncherHandler::CreateAppInfo(const Extension* extension, |
114 const AppNotification* notification, | 114 const AppNotification* notification, |
115 ExtensionService* service, | 115 ExtensionService* service, |
116 DictionaryValue* value) { | 116 DictionaryValue* value) { |
117 bool enabled = service->IsExtensionEnabled(extension->id()) && | 117 bool enabled = service->IsExtensionEnabled(extension->id()) && |
118 !service->GetTerminatedExtension(extension->id()); | 118 !service->GetTerminatedExtension(extension->id()); |
119 bool icon_big_exists = true; | 119 bool icon_big_exists = true; |
| 120 // Instead of setting grayscale here, we do it in apps_page.js in NTP4. |
| 121 bool grayscale = NewTabUI::NTP4Enabled() ? false : !enabled; |
120 GURL icon_big = | 122 GURL icon_big = |
121 ExtensionIconSource::GetIconURL(extension, | 123 ExtensionIconSource::GetIconURL(extension, |
122 Extension::EXTENSION_ICON_LARGE, | 124 Extension::EXTENSION_ICON_LARGE, |
123 ExtensionIconSet::MATCH_EXACTLY, | 125 ExtensionIconSet::MATCH_EXACTLY, |
124 !enabled, &icon_big_exists); | 126 grayscale, &icon_big_exists); |
125 bool icon_small_exists = true; | 127 bool icon_small_exists = true; |
126 GURL icon_small = | 128 GURL icon_small = |
127 ExtensionIconSource::GetIconURL(extension, | 129 ExtensionIconSource::GetIconURL(extension, |
128 Extension::EXTENSION_ICON_BITTY, | 130 Extension::EXTENSION_ICON_BITTY, |
129 ExtensionIconSet::MATCH_BIGGER, | 131 ExtensionIconSet::MATCH_BIGGER, |
130 !enabled, &icon_small_exists); | 132 grayscale, &icon_small_exists); |
131 | 133 |
132 value->Clear(); | 134 value->Clear(); |
133 value->SetString("id", extension->id()); | 135 value->SetString("id", extension->id()); |
134 value->SetString("name", extension->name()); | 136 value->SetString("name", extension->name()); |
135 value->SetString("description", extension->description()); | 137 value->SetString("description", extension->description()); |
136 value->SetString("launch_url", extension->GetFullLaunchURL().spec()); | 138 value->SetString("launch_url", extension->GetFullLaunchURL().spec()); |
137 if (enabled) | 139 value->SetBoolean("enabled", enabled); |
| 140 if (NewTabUI::NTP4Enabled() || enabled) |
138 value->SetString("options_url", extension->options_url().spec()); | 141 value->SetString("options_url", extension->options_url().spec()); |
139 value->SetBoolean("can_uninstall", | 142 value->SetBoolean("can_uninstall", |
140 Extension::UserMayDisable(extension->location())); | 143 Extension::UserMayDisable(extension->location())); |
141 value->SetString("icon_big", icon_big.spec()); | 144 value->SetString("icon_big", icon_big.spec()); |
142 value->SetBoolean("icon_big_exists", icon_big_exists); | 145 value->SetBoolean("icon_big_exists", icon_big_exists); |
143 value->SetString("icon_small", icon_small.spec()); | 146 value->SetString("icon_small", icon_small.spec()); |
144 value->SetBoolean("icon_small_exists", icon_small_exists); | 147 value->SetBoolean("icon_small_exists", icon_small_exists); |
145 value->SetInteger("launch_container", extension->launch_container()); | 148 value->SetInteger("launch_container", extension->launch_container()); |
146 ExtensionPrefs* prefs = service->extension_prefs(); | 149 ExtensionPrefs* prefs = service->extension_prefs(); |
147 value->SetInteger("launch_type", | 150 value->SetInteger("launch_type", |
148 prefs->GetLaunchType(extension->id(), | 151 prefs->GetLaunchType(extension->id(), |
149 ExtensionPrefs::LAUNCH_DEFAULT)); | 152 ExtensionPrefs::LAUNCH_DEFAULT)); |
| 153 value->SetBoolean("offline_enabled", extension->offline_enabled()); |
150 value->SetBoolean("is_component", | 154 value->SetBoolean("is_component", |
151 extension->location() == Extension::COMPONENT); | 155 extension->location() == Extension::COMPONENT); |
152 value->SetBoolean("is_webstore", | 156 value->SetBoolean("is_webstore", |
153 extension->id() == extension_misc::kWebStoreAppId); | 157 extension->id() == extension_misc::kWebStoreAppId); |
154 | 158 |
155 if (notification) | 159 if (notification) |
156 value->Set("notification", SerializeNotification(*notification)); | 160 value->Set("notification", SerializeNotification(*notification)); |
157 | 161 |
158 int app_launch_index = prefs->GetAppLaunchIndex(extension->id()); | 162 int app_launch_index = prefs->GetAppLaunchIndex(extension->id()); |
159 if (app_launch_index == -1) { | 163 if (app_launch_index == -1) { |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 Details<UnloadedExtensionInfo>(details)->extension; | 316 Details<UnloadedExtensionInfo>(details)->extension; |
313 if (!extension->is_app()) | 317 if (!extension->is_app()) |
314 return; | 318 return; |
315 | 319 |
316 if (!NewTabUI::NTP4Enabled()) { | 320 if (!NewTabUI::NTP4Enabled()) { |
317 HandleGetApps(NULL); | 321 HandleGetApps(NULL); |
318 break; | 322 break; |
319 } | 323 } |
320 | 324 |
321 scoped_ptr<DictionaryValue> app_info(GetAppInfo(extension)); | 325 scoped_ptr<DictionaryValue> app_info(GetAppInfo(extension)); |
322 if (app_info.get()) | 326 scoped_ptr<base::FundamentalValue> uninstall_value( |
323 web_ui_->CallJavascriptFunction("ntp4.appRemoved", *app_info); | 327 Value::CreateBooleanValue( |
| 328 Details<UnloadedExtensionInfo>(details)->reason == |
| 329 extension_misc::UNLOAD_REASON_UNINSTALL)); |
| 330 if (app_info.get()) { |
| 331 web_ui_->CallJavascriptFunction( |
| 332 "ntp4.appRemoved", *app_info, *uninstall_value); |
| 333 } |
324 break; | 334 break; |
325 } | 335 } |
326 case chrome::NOTIFICATION_EXTENSION_LAUNCHER_REORDERED: | 336 case chrome::NOTIFICATION_EXTENSION_LAUNCHER_REORDERED: |
327 // The promo may not load until a couple seconds after the first NTP view, | 337 // The promo may not load until a couple seconds after the first NTP view, |
328 // so we listen for the load notification and notify the NTP when ready. | 338 // so we listen for the load notification and notify the NTP when ready. |
329 case chrome::NOTIFICATION_WEB_STORE_PROMO_LOADED: | 339 case chrome::NOTIFICATION_WEB_STORE_PROMO_LOADED: |
330 if (web_ui_->tab_contents()) | 340 if (web_ui_->tab_contents()) |
331 HandleGetApps(NULL); | 341 HandleGetApps(NULL); |
332 break; | 342 break; |
333 case chrome::NOTIFICATION_PREF_CHANGED: { | 343 case chrome::NOTIFICATION_PREF_CHANGED: { |
(...skipping 647 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
981 | 991 |
982 void AppLauncherHandler::UninstallDefaultApps() { | 992 void AppLauncherHandler::UninstallDefaultApps() { |
983 AppsPromo* apps_promo = extension_service_->apps_promo(); | 993 AppsPromo* apps_promo = extension_service_->apps_promo(); |
984 const ExtensionIdSet& app_ids = apps_promo->old_default_apps(); | 994 const ExtensionIdSet& app_ids = apps_promo->old_default_apps(); |
985 for (ExtensionIdSet::const_iterator iter = app_ids.begin(); | 995 for (ExtensionIdSet::const_iterator iter = app_ids.begin(); |
986 iter != app_ids.end(); ++iter) { | 996 iter != app_ids.end(); ++iter) { |
987 if (extension_service_->GetExtensionById(*iter, true)) | 997 if (extension_service_->GetExtensionById(*iter, true)) |
988 extension_service_->UninstallExtension(*iter, false, NULL); | 998 extension_service_->UninstallExtension(*iter, false, NULL); |
989 } | 999 } |
990 } | 1000 } |
OLD | NEW |