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 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 extension->location() == Extension::COMPONENT); | 149 extension->location() == Extension::COMPONENT); |
150 value->SetBoolean("is_webstore", | 150 value->SetBoolean("is_webstore", |
151 extension->id() == extension_misc::kWebStoreAppId); | 151 extension->id() == extension_misc::kWebStoreAppId); |
152 | 152 |
153 if (notification) | 153 if (notification) |
154 value->Set("notification", SerializeNotification(*notification)); | 154 value->Set("notification", SerializeNotification(*notification)); |
155 | 155 |
156 int app_launch_index = prefs->GetAppLaunchIndex(extension->id()); | 156 int app_launch_index = prefs->GetAppLaunchIndex(extension->id()); |
157 if (app_launch_index == -1) { | 157 if (app_launch_index == -1) { |
158 // Make sure every app has a launch index (some predate the launch index). | 158 // Make sure every app has a launch index (some predate the launch index). |
159 app_launch_index = prefs->GetNextAppLaunchIndex(0); | 159 // The webstore's app launch index is set to -2 to make sure it's first. |
| 160 // The next time the user drags (any) app this will be set to something |
| 161 // sane (i.e. >= 0). |
| 162 app_launch_index = extension->id() == extension_misc::kWebStoreAppId ? |
| 163 -2 : prefs->GetNextAppLaunchIndex(0); |
160 prefs->SetAppLaunchIndex(extension->id(), app_launch_index); | 164 prefs->SetAppLaunchIndex(extension->id(), app_launch_index); |
161 } | 165 } |
162 value->SetInteger("app_launch_index", app_launch_index); | 166 value->SetInteger("app_launch_index", app_launch_index); |
163 | 167 |
164 int page_index = prefs->GetPageIndex(extension->id()); | 168 int page_index = prefs->GetPageIndex(extension->id()); |
165 if (page_index >= 0) { | 169 if (page_index >= 0) { |
166 // Only provide a value if one is stored | 170 // Only provide a value if one is stored |
167 value->SetInteger("page_index", page_index); | 171 value->SetInteger("page_index", page_index); |
168 } | 172 } |
169 } | 173 } |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 ListValue* list = new ListValue(); | 319 ListValue* list = new ListValue(); |
316 const ExtensionList* extensions = extension_service_->extensions(); | 320 const ExtensionList* extensions = extension_service_->extensions(); |
317 ExtensionList::const_iterator it; | 321 ExtensionList::const_iterator it; |
318 for (it = extensions->begin(); it != extensions->end(); ++it) { | 322 for (it = extensions->begin(); it != extensions->end(); ++it) { |
319 if (!IsAppExcludedFromList(*it)) { | 323 if (!IsAppExcludedFromList(*it)) { |
320 DictionaryValue* app_info = GetAppInfo(*it); | 324 DictionaryValue* app_info = GetAppInfo(*it); |
321 list->Append(app_info); | 325 list->Append(app_info); |
322 } | 326 } |
323 } | 327 } |
324 | 328 |
| 329 // CreateAppInfo can change the extension prefs. |
| 330 AutoReset<bool> auto_reset(&ignore_changes_, true); |
| 331 |
325 extensions = extension_service_->disabled_extensions(); | 332 extensions = extension_service_->disabled_extensions(); |
326 for (it = extensions->begin(); it != extensions->end(); ++it) { | 333 for (it = extensions->begin(); it != extensions->end(); ++it) { |
327 if (!IsAppExcludedFromList(*it)) { | 334 if (!IsAppExcludedFromList(*it)) { |
328 DictionaryValue* app_info = new DictionaryValue(); | 335 DictionaryValue* app_info = new DictionaryValue(); |
329 CreateAppInfo(*it, | 336 CreateAppInfo(*it, |
330 NULL, | 337 NULL, |
331 extension_service_, | 338 extension_service_, |
332 app_info); | 339 app_info); |
333 list->Append(app_info); | 340 list->Append(app_info); |
334 } | 341 } |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
374 dictionary->Set("appPageNames", | 381 dictionary->Set("appPageNames", |
375 static_cast<ListValue*>(app_page_names->DeepCopy())); | 382 static_cast<ListValue*>(app_page_names->DeepCopy())); |
376 } | 383 } |
377 } | 384 } |
378 } | 385 } |
379 | 386 |
380 DictionaryValue* AppLauncherHandler::GetAppInfo(const Extension* extension) { | 387 DictionaryValue* AppLauncherHandler::GetAppInfo(const Extension* extension) { |
381 AppNotificationManager* notification_manager = | 388 AppNotificationManager* notification_manager = |
382 extension_service_->app_notification_manager(); | 389 extension_service_->app_notification_manager(); |
383 DictionaryValue* app_info = new DictionaryValue(); | 390 DictionaryValue* app_info = new DictionaryValue(); |
| 391 // CreateAppInfo can change the extension prefs. |
| 392 AutoReset<bool> auto_reset(&ignore_changes_, true); |
384 CreateAppInfo(extension, | 393 CreateAppInfo(extension, |
385 notification_manager->GetLast(extension->id()), | 394 notification_manager->GetLast(extension->id()), |
386 extension_service_, | 395 extension_service_, |
387 app_info); | 396 app_info); |
388 return app_info; | 397 return app_info; |
389 } | 398 } |
390 | 399 |
391 void AppLauncherHandler::FillPromoDictionary(DictionaryValue* dictionary) { | 400 void AppLauncherHandler::FillPromoDictionary(DictionaryValue* dictionary) { |
392 dictionary->SetString("promoHeader", AppsPromo::GetPromoHeaderText()); | 401 dictionary->SetString("promoHeader", AppsPromo::GetPromoHeaderText()); |
393 dictionary->SetString("promoButton", AppsPromo::GetPromoButtonText()); | 402 dictionary->SetString("promoButton", AppsPromo::GetPromoButtonText()); |
(...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
917 | 926 |
918 void AppLauncherHandler::UninstallDefaultApps() { | 927 void AppLauncherHandler::UninstallDefaultApps() { |
919 AppsPromo* apps_promo = extension_service_->apps_promo(); | 928 AppsPromo* apps_promo = extension_service_->apps_promo(); |
920 const ExtensionIdSet& app_ids = apps_promo->old_default_apps(); | 929 const ExtensionIdSet& app_ids = apps_promo->old_default_apps(); |
921 for (ExtensionIdSet::const_iterator iter = app_ids.begin(); | 930 for (ExtensionIdSet::const_iterator iter = app_ids.begin(); |
922 iter != app_ids.end(); ++iter) { | 931 iter != app_ids.end(); ++iter) { |
923 if (extension_service_->GetExtensionById(*iter, true)) | 932 if (extension_service_->GetExtensionById(*iter, true)) |
924 extension_service_->UninstallExtension(*iter, false, NULL); | 933 extension_service_->UninstallExtension(*iter, false, NULL); |
925 } | 934 } |
926 } | 935 } |
OLD | NEW |