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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
372 | 372 |
373 base::ListValue* list = new base::ListValue(); | 373 base::ListValue* list = new base::ListValue(); |
374 Profile* profile = Profile::FromWebUI(web_ui()); | 374 Profile* profile = Profile::FromWebUI(web_ui()); |
375 PrefService* prefs = profile->GetPrefs(); | 375 PrefService* prefs = profile->GetPrefs(); |
376 | 376 |
377 for (std::set<std::string>::iterator it = visible_apps_.begin(); | 377 for (std::set<std::string>::iterator it = visible_apps_.begin(); |
378 it != visible_apps_.end(); ++it) { | 378 it != visible_apps_.end(); ++it) { |
379 const Extension* extension = extension_service_->GetInstalledExtension(*it); | 379 const Extension* extension = extension_service_->GetInstalledExtension(*it); |
380 if (extension && extensions::ui_util::ShouldDisplayInNewTabPage( | 380 if (extension && extensions::ui_util::ShouldDisplayInNewTabPage( |
381 extension, profile)) { | 381 extension, profile)) { |
382 base::DictionaryValue* app_info = GetAppInfo(extension); | 382 list->Append(GetAppInfo(extension)); |
383 list->Append(app_info); | |
384 } | 383 } |
385 } | 384 } |
386 | 385 |
387 dictionary->Set("apps", list); | 386 dictionary->Set("apps", list); |
388 | 387 |
389 const base::ListValue* app_page_names = | 388 const base::ListValue* app_page_names = |
390 prefs->GetList(prefs::kNtpAppPageNames); | 389 prefs->GetList(prefs::kNtpAppPageNames); |
391 if (!app_page_names || !app_page_names->GetSize()) { | 390 if (!app_page_names || !app_page_names->GetSize()) { |
392 ListPrefUpdate update(prefs, prefs::kNtpAppPageNames); | 391 ListPrefUpdate update(prefs, prefs::kNtpAppPageNames); |
393 base::ListValue* list = update.Get(); | 392 base::ListValue* list = update.Get(); |
394 list->Set(0, new base::StringValue( | 393 list->Set(0, new base::StringValue( |
395 l10n_util::GetStringUTF16(IDS_APP_DEFAULT_PAGE_NAME))); | 394 l10n_util::GetStringUTF16(IDS_APP_DEFAULT_PAGE_NAME))); |
396 dictionary->Set("appPageNames", | 395 dictionary->Set("appPageNames", |
397 static_cast<base::ListValue*>(list->DeepCopy())); | 396 static_cast<base::ListValue*>(list->DeepCopy())); |
398 } else { | 397 } else { |
399 dictionary->Set("appPageNames", | 398 dictionary->Set("appPageNames", |
400 static_cast<base::ListValue*>(app_page_names->DeepCopy())); | 399 static_cast<base::ListValue*>(app_page_names->DeepCopy())); |
401 } | 400 } |
402 } | 401 } |
403 | 402 |
404 base::DictionaryValue* AppLauncherHandler::GetAppInfo( | 403 std::unique_ptr<base::DictionaryValue> AppLauncherHandler::GetAppInfo( |
405 const Extension* extension) { | 404 const Extension* extension) { |
406 base::DictionaryValue* app_info = new base::DictionaryValue(); | 405 std::unique_ptr<base::DictionaryValue> app_info(new base::DictionaryValue()); |
407 // CreateAppInfo can change the extension prefs. | 406 // CreateAppInfo can change the extension prefs. |
408 base::AutoReset<bool> auto_reset(&ignore_changes_, true); | 407 base::AutoReset<bool> auto_reset(&ignore_changes_, true); |
409 CreateAppInfo(extension, | 408 CreateAppInfo(extension, extension_service_, app_info.get()); |
410 extension_service_, | |
411 app_info); | |
412 return app_info; | 409 return app_info; |
413 } | 410 } |
414 | 411 |
415 void AppLauncherHandler::HandleGetApps(const base::ListValue* args) { | 412 void AppLauncherHandler::HandleGetApps(const base::ListValue* args) { |
416 base::DictionaryValue dictionary; | 413 base::DictionaryValue dictionary; |
417 | 414 |
418 // Tell the client whether to show the promo for this view. We don't do this | 415 // Tell the client whether to show the promo for this view. We don't do this |
419 // in the case of PREF_CHANGED because: | 416 // in the case of PREF_CHANGED because: |
420 // | 417 // |
421 // a) At that point in time, depending on the pref that changed, it can look | 418 // a) At that point in time, depending on the pref that changed, it can look |
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
882 base::FundamentalValue(!extension_id_prompting_.empty())); | 879 base::FundamentalValue(!extension_id_prompting_.empty())); |
883 } | 880 } |
884 | 881 |
885 bool AppLauncherHandler::ShouldShow(const Extension* extension) const { | 882 bool AppLauncherHandler::ShouldShow(const Extension* extension) const { |
886 if (ignore_changes_ || !has_loaded_apps_ || !extension->is_app()) | 883 if (ignore_changes_ || !has_loaded_apps_ || !extension->is_app()) |
887 return false; | 884 return false; |
888 | 885 |
889 Profile* profile = Profile::FromWebUI(web_ui()); | 886 Profile* profile = Profile::FromWebUI(web_ui()); |
890 return extensions::ui_util::ShouldDisplayInNewTabPage(extension, profile); | 887 return extensions::ui_util::ShouldDisplayInNewTabPage(extension, profile); |
891 } | 888 } |
OLD | NEW |