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 <vector> | 7 #include <vector> |
8 | 8 |
9 #include "apps/metrics_names.h" | 9 #include "apps/metrics_names.h" |
10 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 #include "ui/base/webui/web_ui_util.h" | 66 #include "ui/base/webui/web_ui_util.h" |
67 #include "url/gurl.h" | 67 #include "url/gurl.h" |
68 | 68 |
69 using content::WebContents; | 69 using content::WebContents; |
70 using extensions::AppSorting; | 70 using extensions::AppSorting; |
71 using extensions::CrxInstaller; | 71 using extensions::CrxInstaller; |
72 using extensions::Extension; | 72 using extensions::Extension; |
73 using extensions::ExtensionPrefs; | 73 using extensions::ExtensionPrefs; |
74 using extensions::ExtensionRegistry; | 74 using extensions::ExtensionRegistry; |
75 using extensions::ExtensionSet; | 75 using extensions::ExtensionSet; |
| 76 using extensions::ExtensionSystem; |
76 | 77 |
77 namespace { | 78 namespace { |
78 | 79 |
79 void RecordAppLauncherPromoHistogram( | 80 void RecordAppLauncherPromoHistogram( |
80 apps::AppLauncherPromoHistogramValues value) { | 81 apps::AppLauncherPromoHistogramValues value) { |
81 DCHECK_LT(value, apps::APP_LAUNCHER_PROMO_MAX); | 82 DCHECK_LT(value, apps::APP_LAUNCHER_PROMO_MAX); |
82 UMA_HISTOGRAM_ENUMERATION( | 83 UMA_HISTOGRAM_ENUMERATION( |
83 "Apps.AppLauncherPromo", value, apps::APP_LAUNCHER_PROMO_MAX); | 84 "Apps.AppLauncherPromo", value, apps::APP_LAUNCHER_PROMO_MAX); |
84 } | 85 } |
85 | 86 |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 value->SetBoolean("icon_small_exists", icon_small_exists); | 170 value->SetBoolean("icon_small_exists", icon_small_exists); |
170 value->SetInteger("launch_container", | 171 value->SetInteger("launch_container", |
171 extensions::AppLaunchInfo::GetLaunchContainer(extension)); | 172 extensions::AppLaunchInfo::GetLaunchContainer(extension)); |
172 ExtensionPrefs* prefs = ExtensionPrefs::Get(service->profile()); | 173 ExtensionPrefs* prefs = ExtensionPrefs::Get(service->profile()); |
173 value->SetInteger("launch_type", extensions::GetLaunchType(prefs, extension)); | 174 value->SetInteger("launch_type", extensions::GetLaunchType(prefs, extension)); |
174 value->SetBoolean("is_component", | 175 value->SetBoolean("is_component", |
175 extension->location() == extensions::Manifest::COMPONENT); | 176 extension->location() == extensions::Manifest::COMPONENT); |
176 value->SetBoolean("is_webstore", | 177 value->SetBoolean("is_webstore", |
177 extension->id() == extensions::kWebStoreAppId); | 178 extension->id() == extensions::kWebStoreAppId); |
178 | 179 |
179 AppSorting* sorting = prefs->app_sorting(); | 180 AppSorting* sorting = ExtensionSystem::Get(service->profile())->app_sorting(); |
180 syncer::StringOrdinal page_ordinal = sorting->GetPageOrdinal(extension->id()); | 181 syncer::StringOrdinal page_ordinal = sorting->GetPageOrdinal(extension->id()); |
181 if (!page_ordinal.IsValid()) { | 182 if (!page_ordinal.IsValid()) { |
182 // Make sure every app has a page ordinal (some predate the page ordinal). | 183 // Make sure every app has a page ordinal (some predate the page ordinal). |
183 // The webstore app should be on the first page. | 184 // The webstore app should be on the first page. |
184 page_ordinal = extension->id() == extensions::kWebStoreAppId ? | 185 page_ordinal = extension->id() == extensions::kWebStoreAppId ? |
185 sorting->CreateFirstAppPageOrdinal() : | 186 sorting->CreateFirstAppPageOrdinal() : |
186 sorting->GetNaturalAppPageOrdinal(); | 187 sorting->GetNaturalAppPageOrdinal(); |
187 sorting->SetPageOrdinal(extension->id(), page_ordinal); | 188 sorting->SetPageOrdinal(extension->id(), page_ordinal); |
188 } | 189 } |
189 value->SetInteger("page_index", | 190 value->SetInteger("page_index", |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
432 base::Closure callback = base::Bind( | 433 base::Closure callback = base::Bind( |
433 &AppLauncherHandler::OnExtensionPreferenceChanged, | 434 &AppLauncherHandler::OnExtensionPreferenceChanged, |
434 base::Unretained(this)); | 435 base::Unretained(this)); |
435 extension_pref_change_registrar_.Init( | 436 extension_pref_change_registrar_.Init( |
436 ExtensionPrefs::Get(profile)->pref_service()); | 437 ExtensionPrefs::Get(profile)->pref_service()); |
437 extension_pref_change_registrar_.Add( | 438 extension_pref_change_registrar_.Add( |
438 extensions::pref_names::kExtensions, callback); | 439 extensions::pref_names::kExtensions, callback); |
439 extension_pref_change_registrar_.Add(prefs::kNtpAppPageNames, callback); | 440 extension_pref_change_registrar_.Add(prefs::kNtpAppPageNames, callback); |
440 | 441 |
441 ExtensionRegistry::Get(profile)->AddObserver(this); | 442 ExtensionRegistry::Get(profile)->AddObserver(this); |
442 registrar_.Add(this, | 443 registrar_.Add(this, chrome::NOTIFICATION_APP_LAUNCHER_REORDERED, |
443 chrome::NOTIFICATION_APP_LAUNCHER_REORDERED, | |
444 content::Source<AppSorting>( | 444 content::Source<AppSorting>( |
445 ExtensionPrefs::Get(profile)->app_sorting())); | 445 ExtensionSystem::Get(profile)->app_sorting())); |
446 registrar_.Add(this, | 446 registrar_.Add(this, |
447 extensions::NOTIFICATION_EXTENSION_INSTALL_ERROR, | 447 extensions::NOTIFICATION_EXTENSION_INSTALL_ERROR, |
448 content::Source<CrxInstaller>(NULL)); | 448 content::Source<CrxInstaller>(NULL)); |
449 registrar_.Add(this, | 449 registrar_.Add(this, |
450 extensions::NOTIFICATION_EXTENSION_LOAD_ERROR, | 450 extensions::NOTIFICATION_EXTENSION_LOAD_ERROR, |
451 content::Source<Profile>(profile)); | 451 content::Source<Profile>(profile)); |
452 } | 452 } |
453 | 453 |
454 has_loaded_apps_ = true; | 454 has_loaded_apps_ = true; |
455 } | 455 } |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
629 CHECK(app_order->GetString(i + 1, &successor_to_moved_ext)); | 629 CHECK(app_order->GetString(i + 1, &successor_to_moved_ext)); |
630 break; | 630 break; |
631 } | 631 } |
632 } | 632 } |
633 | 633 |
634 // Don't update the page; it already knows the apps have been reordered. | 634 // Don't update the page; it already knows the apps have been reordered. |
635 base::AutoReset<bool> auto_reset(&ignore_changes_, true); | 635 base::AutoReset<bool> auto_reset(&ignore_changes_, true); |
636 ExtensionPrefs* extension_prefs = | 636 ExtensionPrefs* extension_prefs = |
637 ExtensionPrefs::Get(extension_service_->GetBrowserContext()); | 637 ExtensionPrefs::Get(extension_service_->GetBrowserContext()); |
638 extension_prefs->SetAppDraggedByUser(dragged_app_id); | 638 extension_prefs->SetAppDraggedByUser(dragged_app_id); |
639 extension_prefs->app_sorting()->OnExtensionMoved( | 639 ExtensionSystem::Get(extension_service_->GetBrowserContext()) |
640 dragged_app_id, predecessor_to_moved_ext, successor_to_moved_ext); | 640 ->app_sorting() |
| 641 ->OnExtensionMoved(dragged_app_id, predecessor_to_moved_ext, |
| 642 successor_to_moved_ext); |
641 } | 643 } |
642 | 644 |
643 void AppLauncherHandler::HandleSetPageIndex(const base::ListValue* args) { | 645 void AppLauncherHandler::HandleSetPageIndex(const base::ListValue* args) { |
644 AppSorting* app_sorting = | 646 AppSorting* app_sorting = |
645 ExtensionPrefs::Get(extension_service_->profile())->app_sorting(); | 647 ExtensionSystem::Get(extension_service_->profile())->app_sorting(); |
646 | |
647 std::string extension_id; | 648 std::string extension_id; |
648 double page_index; | 649 double page_index; |
649 CHECK(args->GetString(0, &extension_id)); | 650 CHECK(args->GetString(0, &extension_id)); |
650 CHECK(args->GetDouble(1, &page_index)); | 651 CHECK(args->GetDouble(1, &page_index)); |
651 const syncer::StringOrdinal& page_ordinal = | 652 const syncer::StringOrdinal& page_ordinal = |
652 app_sorting->PageIntegerAsStringOrdinal(static_cast<size_t>(page_index)); | 653 app_sorting->PageIntegerAsStringOrdinal(static_cast<size_t>(page_index)); |
653 | 654 |
654 // Don't update the page; it already knows the apps have been reordered. | 655 // Don't update the page; it already knows the apps have been reordered. |
655 base::AutoReset<bool> auto_reset(&ignore_changes_, true); | 656 base::AutoReset<bool> auto_reset(&ignore_changes_, true); |
656 app_sorting->SetPageOrdinal(extension_id, page_ordinal); | 657 app_sorting->SetPageOrdinal(extension_id, page_ordinal); |
(...skipping 17 matching lines...) Expand all Loading... |
674 std::string url; | 675 std::string url; |
675 CHECK(args->GetString(0, &url)); | 676 CHECK(args->GetString(0, &url)); |
676 GURL launch_url(url); | 677 GURL launch_url(url); |
677 | 678 |
678 base::string16 title; | 679 base::string16 title; |
679 CHECK(args->GetString(1, &title)); | 680 CHECK(args->GetString(1, &title)); |
680 | 681 |
681 double page_index; | 682 double page_index; |
682 CHECK(args->GetDouble(2, &page_index)); | 683 CHECK(args->GetDouble(2, &page_index)); |
683 AppSorting* app_sorting = | 684 AppSorting* app_sorting = |
684 ExtensionPrefs::Get(extension_service_->profile())->app_sorting(); | 685 ExtensionSystem::Get(extension_service_->profile())->app_sorting(); |
685 const syncer::StringOrdinal& page_ordinal = | 686 const syncer::StringOrdinal& page_ordinal = |
686 app_sorting->PageIntegerAsStringOrdinal(static_cast<size_t>(page_index)); | 687 app_sorting->PageIntegerAsStringOrdinal(static_cast<size_t>(page_index)); |
687 | 688 |
688 Profile* profile = Profile::FromWebUI(web_ui()); | 689 Profile* profile = Profile::FromWebUI(web_ui()); |
689 favicon::FaviconService* favicon_service = | 690 favicon::FaviconService* favicon_service = |
690 FaviconServiceFactory::GetForProfile(profile, | 691 FaviconServiceFactory::GetForProfile(profile, |
691 ServiceAccessType::EXPLICIT_ACCESS); | 692 ServiceAccessType::EXPLICIT_ACCESS); |
692 if (!favicon_service) { | 693 if (!favicon_service) { |
693 LOG(ERROR) << "No favicon service"; | 694 LOG(ERROR) << "No favicon service"; |
694 return; | 695 return; |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
845 base::FundamentalValue(!extension_id_prompting_.empty())); | 846 base::FundamentalValue(!extension_id_prompting_.empty())); |
846 } | 847 } |
847 | 848 |
848 bool AppLauncherHandler::ShouldShow(const Extension* extension) const { | 849 bool AppLauncherHandler::ShouldShow(const Extension* extension) const { |
849 if (ignore_changes_ || !has_loaded_apps_ || !extension->is_app()) | 850 if (ignore_changes_ || !has_loaded_apps_ || !extension->is_app()) |
850 return false; | 851 return false; |
851 | 852 |
852 Profile* profile = Profile::FromWebUI(web_ui()); | 853 Profile* profile = Profile::FromWebUI(web_ui()); |
853 return extensions::ui_util::ShouldDisplayInNewTabPage(extension, profile); | 854 return extensions::ui_util::ShouldDisplayInNewTabPage(extension, profile); |
854 } | 855 } |
OLD | NEW |