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 } | 373 } |
374 | 374 |
375 dictionary->Set("apps", list); | 375 dictionary->Set("apps", list); |
376 | 376 |
377 const base::ListValue* app_page_names = | 377 const base::ListValue* app_page_names = |
378 prefs->GetList(prefs::kNtpAppPageNames); | 378 prefs->GetList(prefs::kNtpAppPageNames); |
379 if (!app_page_names || !app_page_names->GetSize()) { | 379 if (!app_page_names || !app_page_names->GetSize()) { |
380 ListPrefUpdate update(prefs, prefs::kNtpAppPageNames); | 380 ListPrefUpdate update(prefs, prefs::kNtpAppPageNames); |
381 base::ListValue* list = update.Get(); | 381 base::ListValue* list = update.Get(); |
382 list->Set(0, new base::StringValue( | 382 list->Set(0, new base::Value( |
383 l10n_util::GetStringUTF16(IDS_APP_DEFAULT_PAGE_NAME))); | 383 l10n_util::GetStringUTF16(IDS_APP_DEFAULT_PAGE_NAME))); |
384 dictionary->Set("appPageNames", | 384 dictionary->Set("appPageNames", |
385 static_cast<base::ListValue*>(list->DeepCopy())); | 385 static_cast<base::ListValue*>(list->DeepCopy())); |
386 } else { | 386 } else { |
387 dictionary->Set("appPageNames", | 387 dictionary->Set("appPageNames", |
388 static_cast<base::ListValue*>(app_page_names->DeepCopy())); | 388 static_cast<base::ListValue*>(app_page_names->DeepCopy())); |
389 } | 389 } |
390 } | 390 } |
391 | 391 |
392 std::unique_ptr<base::DictionaryValue> AppLauncherHandler::GetAppInfo( | 392 std::unique_ptr<base::DictionaryValue> AppLauncherHandler::GetAppInfo( |
393 const Extension* extension) { | 393 const Extension* extension) { |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
684 base::string16 name; | 684 base::string16 name; |
685 CHECK(args->GetString(0, &name)); | 685 CHECK(args->GetString(0, &name)); |
686 | 686 |
687 double page_index; | 687 double page_index; |
688 CHECK(args->GetDouble(1, &page_index)); | 688 CHECK(args->GetDouble(1, &page_index)); |
689 | 689 |
690 base::AutoReset<bool> auto_reset(&ignore_changes_, true); | 690 base::AutoReset<bool> auto_reset(&ignore_changes_, true); |
691 PrefService* prefs = Profile::FromWebUI(web_ui())->GetPrefs(); | 691 PrefService* prefs = Profile::FromWebUI(web_ui())->GetPrefs(); |
692 ListPrefUpdate update(prefs, prefs::kNtpAppPageNames); | 692 ListPrefUpdate update(prefs, prefs::kNtpAppPageNames); |
693 base::ListValue* list = update.Get(); | 693 base::ListValue* list = update.Get(); |
694 list->Set(static_cast<size_t>(page_index), new base::StringValue(name)); | 694 list->Set(static_cast<size_t>(page_index), new base::Value(name)); |
695 } | 695 } |
696 | 696 |
697 void AppLauncherHandler::HandleGenerateAppForLink(const base::ListValue* args) { | 697 void AppLauncherHandler::HandleGenerateAppForLink(const base::ListValue* args) { |
698 std::string url; | 698 std::string url; |
699 CHECK(args->GetString(0, &url)); | 699 CHECK(args->GetString(0, &url)); |
700 GURL launch_url(url); | 700 GURL launch_url(url); |
701 | 701 |
702 base::string16 title; | 702 base::string16 title; |
703 CHECK(args->GetString(1, &title)); | 703 CHECK(args->GetString(1, &title)); |
704 | 704 |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
774 installer->set_error_on_unsupported_requirements(true); | 774 installer->set_error_on_unsupported_requirements(true); |
775 installer->set_page_ordinal(install_info->page_ordinal); | 775 installer->set_page_ordinal(install_info->page_ordinal); |
776 installer->InstallWebApp(*web_app); | 776 installer->InstallWebApp(*web_app); |
777 attempted_bookmark_app_install_ = true; | 777 attempted_bookmark_app_install_ = true; |
778 } | 778 } |
779 | 779 |
780 void AppLauncherHandler::SetAppToBeHighlighted() { | 780 void AppLauncherHandler::SetAppToBeHighlighted() { |
781 if (highlight_app_id_.empty()) | 781 if (highlight_app_id_.empty()) |
782 return; | 782 return; |
783 | 783 |
784 base::StringValue app_id(highlight_app_id_); | 784 base::Value app_id(highlight_app_id_); |
785 web_ui()->CallJavascriptFunctionUnsafe("ntp.setAppToBeHighlighted", app_id); | 785 web_ui()->CallJavascriptFunctionUnsafe("ntp.setAppToBeHighlighted", app_id); |
786 highlight_app_id_.clear(); | 786 highlight_app_id_.clear(); |
787 } | 787 } |
788 | 788 |
789 void AppLauncherHandler::OnExtensionPreferenceChanged() { | 789 void AppLauncherHandler::OnExtensionPreferenceChanged() { |
790 base::DictionaryValue dictionary; | 790 base::DictionaryValue dictionary; |
791 FillAppDictionary(&dictionary); | 791 FillAppDictionary(&dictionary); |
792 web_ui()->CallJavascriptFunctionUnsafe("ntp.appsPrefChangeCallback", | 792 web_ui()->CallJavascriptFunctionUnsafe("ntp.appsPrefChangeCallback", |
793 dictionary); | 793 dictionary); |
794 } | 794 } |
(...skipping 27 matching lines...) Expand all Loading... |
822 CleanupAfterUninstall(); | 822 CleanupAfterUninstall(); |
823 } | 823 } |
824 | 824 |
825 void AppLauncherHandler::ExtensionEnableFlowFinished() { | 825 void AppLauncherHandler::ExtensionEnableFlowFinished() { |
826 DCHECK_EQ(extension_id_prompting_, extension_enable_flow_->extension_id()); | 826 DCHECK_EQ(extension_id_prompting_, extension_enable_flow_->extension_id()); |
827 | 827 |
828 // We bounce this off the NTP so the browser can update the apps icon. | 828 // We bounce this off the NTP so the browser can update the apps icon. |
829 // If we don't launch the app asynchronously, then the app's disabled | 829 // If we don't launch the app asynchronously, then the app's disabled |
830 // icon disappears but isn't replaced by the enabled icon, making a poor | 830 // icon disappears but isn't replaced by the enabled icon, making a poor |
831 // visual experience. | 831 // visual experience. |
832 base::StringValue app_id(extension_id_prompting_); | 832 base::Value app_id(extension_id_prompting_); |
833 web_ui()->CallJavascriptFunctionUnsafe("ntp.launchAppAfterEnable", app_id); | 833 web_ui()->CallJavascriptFunctionUnsafe("ntp.launchAppAfterEnable", app_id); |
834 | 834 |
835 extension_enable_flow_.reset(); | 835 extension_enable_flow_.reset(); |
836 extension_id_prompting_ = ""; | 836 extension_id_prompting_ = ""; |
837 } | 837 } |
838 | 838 |
839 void AppLauncherHandler::ExtensionEnableFlowAborted(bool user_initiated) { | 839 void AppLauncherHandler::ExtensionEnableFlowAborted(bool user_initiated) { |
840 DCHECK_EQ(extension_id_prompting_, extension_enable_flow_->extension_id()); | 840 DCHECK_EQ(extension_id_prompting_, extension_enable_flow_->extension_id()); |
841 | 841 |
842 // We record the histograms here because ExtensionUninstallCanceled is also | 842 // We record the histograms here because ExtensionUninstallCanceled is also |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
880 base::Value(!extension_id_prompting_.empty())); | 880 base::Value(!extension_id_prompting_.empty())); |
881 } | 881 } |
882 | 882 |
883 bool AppLauncherHandler::ShouldShow(const Extension* extension) const { | 883 bool AppLauncherHandler::ShouldShow(const Extension* extension) const { |
884 if (ignore_changes_ || !has_loaded_apps_ || !extension->is_app()) | 884 if (ignore_changes_ || !has_loaded_apps_ || !extension->is_app()) |
885 return false; | 885 return false; |
886 | 886 |
887 Profile* profile = Profile::FromWebUI(web_ui()); | 887 Profile* profile = Profile::FromWebUI(web_ui()); |
888 return extensions::ui_util::ShouldDisplayInNewTabPage(extension, profile); | 888 return extensions::ui_util::ShouldDisplayInNewTabPage(extension, profile); |
889 } | 889 } |
OLD | NEW |