| 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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 DictionaryValue* dictionary = new DictionaryValue(); | 90 DictionaryValue* dictionary = new DictionaryValue(); |
| 91 dictionary->SetString("title", notification.title()); | 91 dictionary->SetString("title", notification.title()); |
| 92 dictionary->SetString("body", notification.body()); | 92 dictionary->SetString("body", notification.body()); |
| 93 if (!notification.link_url().is_empty()) { | 93 if (!notification.link_url().is_empty()) { |
| 94 dictionary->SetString("linkUrl", notification.link_url().spec()); | 94 dictionary->SetString("linkUrl", notification.link_url().spec()); |
| 95 dictionary->SetString("linkText", notification.link_text()); | 95 dictionary->SetString("linkText", notification.link_text()); |
| 96 } | 96 } |
| 97 return dictionary; | 97 return dictionary; |
| 98 } | 98 } |
| 99 | 99 |
| 100 // static | |
| 101 bool AppLauncherHandler::IsAppExcludedFromList(const Extension* extension) { | |
| 102 // The Cloud Print app should never be displayed in the NTP. | |
| 103 if (!extension->is_app() || | |
| 104 (extension->id() == extension_misc::kCloudPrintAppId)) { | |
| 105 return true; | |
| 106 } | |
| 107 return false; | |
| 108 } | |
| 109 | |
| 110 void AppLauncherHandler::CreateAppInfo(const Extension* extension, | 100 void AppLauncherHandler::CreateAppInfo(const Extension* extension, |
| 111 const AppNotification* notification, | 101 const AppNotification* notification, |
| 112 ExtensionService* service, | 102 ExtensionService* service, |
| 113 DictionaryValue* value) { | 103 DictionaryValue* value) { |
| 114 bool enabled = service->IsExtensionEnabled(extension->id()) && | 104 bool enabled = service->IsExtensionEnabled(extension->id()) && |
| 115 !service->GetTerminatedExtension(extension->id()); | 105 !service->GetTerminatedExtension(extension->id()); |
| 116 bool icon_big_exists = true; | 106 bool icon_big_exists = true; |
| 117 // Instead of setting grayscale here, we do it in apps_page.js. | 107 // Instead of setting grayscale here, we do it in apps_page.js. |
| 118 GURL icon_big = | 108 GURL icon_big = |
| 119 ExtensionIconSource::GetIconURL(extension, | 109 ExtensionIconSource::GetIconURL(extension, |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 344 | 334 |
| 345 void AppLauncherHandler::FillAppDictionary(DictionaryValue* dictionary) { | 335 void AppLauncherHandler::FillAppDictionary(DictionaryValue* dictionary) { |
| 346 // CreateAppInfo and ClearOrdinals can change the extension prefs. | 336 // CreateAppInfo and ClearOrdinals can change the extension prefs. |
| 347 AutoReset<bool> auto_reset(&ignore_changes_, true); | 337 AutoReset<bool> auto_reset(&ignore_changes_, true); |
| 348 | 338 |
| 349 ListValue* list = new ListValue(); | 339 ListValue* list = new ListValue(); |
| 350 const ExtensionSet* extensions = extension_service_->extensions(); | 340 const ExtensionSet* extensions = extension_service_->extensions(); |
| 351 ExtensionSet::const_iterator it; | 341 ExtensionSet::const_iterator it; |
| 352 for (it = extensions->begin(); it != extensions->end(); ++it) { | 342 for (it = extensions->begin(); it != extensions->end(); ++it) { |
| 353 const Extension* extension = *it; | 343 const Extension* extension = *it; |
| 354 if (!IsAppExcludedFromList(extension)) { | 344 if (extension->ShouldDisplayInLauncher()) { |
| 355 DictionaryValue* app_info = GetAppInfo(extension); | 345 DictionaryValue* app_info = GetAppInfo(extension); |
| 356 list->Append(app_info); | 346 list->Append(app_info); |
| 357 } else { | 347 } else { |
| 358 // This is necessary because in some previous versions of chrome, we set a | 348 // This is necessary because in some previous versions of chrome, we set a |
| 359 // page index for non-app extensions. Old profiles can persist this error, | 349 // page index for non-app extensions. Old profiles can persist this error, |
| 360 // and this fixes it. This caused GetNaturalAppPageIndex() to break | 350 // and this fixes it. This caused GetNaturalAppPageIndex() to break |
| 361 // (see http://crbug.com/98325) before it was an ordinal value. | 351 // (see http://crbug.com/98325) before it was an ordinal value. |
| 362 ExtensionSorting* sortings = | 352 ExtensionSorting* sortings = |
| 363 extension_service_->extension_prefs()->extension_sorting(); | 353 extension_service_->extension_prefs()->extension_sorting(); |
| 364 if (sortings->GetPageOrdinal(extension->id()).IsValid()) | 354 if (sortings->GetPageOrdinal(extension->id()).IsValid()) |
| 365 sortings->ClearOrdinals(extension->id()); | 355 sortings->ClearOrdinals(extension->id()); |
| 366 } | 356 } |
| 367 } | 357 } |
| 368 | 358 |
| 369 extensions = extension_service_->disabled_extensions(); | 359 extensions = extension_service_->disabled_extensions(); |
| 370 for (it = extensions->begin(); it != extensions->end(); ++it) { | 360 for (it = extensions->begin(); it != extensions->end(); ++it) { |
| 371 if (!IsAppExcludedFromList(*it)) { | 361 if ((*it)->ShouldDisplayInLauncher()) { |
| 372 DictionaryValue* app_info = new DictionaryValue(); | 362 DictionaryValue* app_info = new DictionaryValue(); |
| 373 CreateAppInfo(*it, | 363 CreateAppInfo(*it, |
| 374 NULL, | 364 NULL, |
| 375 extension_service_, | 365 extension_service_, |
| 376 app_info); | 366 app_info); |
| 377 list->Append(app_info); | 367 list->Append(app_info); |
| 378 } | 368 } |
| 379 } | 369 } |
| 380 | 370 |
| 381 extensions = extension_service_->terminated_extensions(); | 371 extensions = extension_service_->terminated_extensions(); |
| 382 for (it = extensions->begin(); it != extensions->end(); ++it) { | 372 for (it = extensions->begin(); it != extensions->end(); ++it) { |
| 383 if (!IsAppExcludedFromList(*it)) { | 373 if ((*it)->ShouldDisplayInLauncher()) { |
| 384 DictionaryValue* app_info = new DictionaryValue(); | 374 DictionaryValue* app_info = new DictionaryValue(); |
| 385 CreateAppInfo(*it, | 375 CreateAppInfo(*it, |
| 386 NULL, | 376 NULL, |
| 387 extension_service_, | 377 extension_service_, |
| 388 app_info); | 378 app_info); |
| 389 list->Append(app_info); | 379 list->Append(app_info); |
| 390 } | 380 } |
| 391 } | 381 } |
| 392 | 382 |
| 393 dictionary->Set("apps", list); | 383 dictionary->Set("apps", list); |
| (...skipping 600 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 994 | 984 |
| 995 void AppLauncherHandler::UninstallDefaultApps() { | 985 void AppLauncherHandler::UninstallDefaultApps() { |
| 996 AppsPromo* apps_promo = extension_service_->apps_promo(); | 986 AppsPromo* apps_promo = extension_service_->apps_promo(); |
| 997 const ExtensionIdSet& app_ids = apps_promo->old_default_apps(); | 987 const ExtensionIdSet& app_ids = apps_promo->old_default_apps(); |
| 998 for (ExtensionIdSet::const_iterator iter = app_ids.begin(); | 988 for (ExtensionIdSet::const_iterator iter = app_ids.begin(); |
| 999 iter != app_ids.end(); ++iter) { | 989 iter != app_ids.end(); ++iter) { |
| 1000 if (extension_service_->GetExtensionById(*iter, true)) | 990 if (extension_service_->GetExtensionById(*iter, true)) |
| 1001 extension_service_->UninstallExtension(*iter, false, NULL); | 991 extension_service_->UninstallExtension(*iter, false, NULL); |
| 1002 } | 992 } |
| 1003 } | 993 } |
| OLD | NEW |