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 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 GURL icon_small = extensions::ExtensionIconSource::GetIconURL( | 152 GURL icon_small = extensions::ExtensionIconSource::GetIconURL( |
153 extension, | 153 extension, |
154 extension_misc::EXTENSION_ICON_BITTY, | 154 extension_misc::EXTENSION_ICON_BITTY, |
155 ExtensionIconSet::MATCH_BIGGER, | 155 ExtensionIconSet::MATCH_BIGGER, |
156 false, | 156 false, |
157 &icon_small_exists); | 157 &icon_small_exists); |
158 value->SetString("icon_small", icon_small.spec()); | 158 value->SetString("icon_small", icon_small.spec()); |
159 value->SetBoolean("icon_small_exists", icon_small_exists); | 159 value->SetBoolean("icon_small_exists", icon_small_exists); |
160 value->SetInteger("launch_container", | 160 value->SetInteger("launch_container", |
161 extensions::AppLaunchInfo::GetLaunchContainer(extension)); | 161 extensions::AppLaunchInfo::GetLaunchContainer(extension)); |
162 ExtensionPrefs* prefs = service->extension_prefs(); | 162 ExtensionPrefs* prefs = ExtensionPrefs::Get(service->profile()); |
163 value->SetInteger("launch_type", extensions::GetLaunchType(prefs, extension)); | 163 value->SetInteger("launch_type", extensions::GetLaunchType(prefs, extension)); |
164 value->SetBoolean("is_component", | 164 value->SetBoolean("is_component", |
165 extension->location() == extensions::Manifest::COMPONENT); | 165 extension->location() == extensions::Manifest::COMPONENT); |
166 value->SetBoolean("is_webstore", | 166 value->SetBoolean("is_webstore", |
167 extension->id() == extension_misc::kWebStoreAppId); | 167 extension->id() == extension_misc::kWebStoreAppId); |
168 | 168 |
169 AppSorting* sorting = prefs->app_sorting(); | 169 AppSorting* sorting = prefs->app_sorting(); |
170 syncer::StringOrdinal page_ordinal = sorting->GetPageOrdinal(extension->id()); | 170 syncer::StringOrdinal page_ordinal = sorting->GetPageOrdinal(extension->id()); |
171 if (!page_ordinal.IsValid()) { | 171 if (!page_ordinal.IsValid()) { |
172 // Make sure every app has a page ordinal (some predate the page ordinal). | 172 // Make sure every app has a page ordinal (some predate the page ordinal). |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 return; | 264 return; |
265 | 265 |
266 PrefService* prefs = Profile::FromWebUI(web_ui())->GetPrefs(); | 266 PrefService* prefs = Profile::FromWebUI(web_ui())->GetPrefs(); |
267 if (!ShouldDisplayInNewTabPage(extension, prefs)) | 267 if (!ShouldDisplayInNewTabPage(extension, prefs)) |
268 return; | 268 return; |
269 | 269 |
270 scoped_ptr<base::DictionaryValue> app_info(GetAppInfo(extension)); | 270 scoped_ptr<base::DictionaryValue> app_info(GetAppInfo(extension)); |
271 if (app_info.get()) { | 271 if (app_info.get()) { |
272 visible_apps_.insert(extension->id()); | 272 visible_apps_.insert(extension->id()); |
273 | 273 |
274 ExtensionPrefs* prefs = extension_service_->extension_prefs(); | 274 ExtensionPrefs* prefs = ExtensionPrefs::Get( |
| 275 extension_service_->profile()); |
275 scoped_ptr<base::FundamentalValue> highlight( | 276 scoped_ptr<base::FundamentalValue> highlight( |
276 base::Value::CreateBooleanValue( | 277 base::Value::CreateBooleanValue( |
277 prefs->IsFromBookmark(extension->id()) && | 278 prefs->IsFromBookmark(extension->id()) && |
278 attempted_bookmark_app_install_)); | 279 attempted_bookmark_app_install_)); |
279 attempted_bookmark_app_install_ = false; | 280 attempted_bookmark_app_install_ = false; |
280 web_ui()->CallJavascriptFunction( | 281 web_ui()->CallJavascriptFunction( |
281 "ntp.appAdded", *app_info, *highlight); | 282 "ntp.appAdded", *app_info, *highlight); |
282 } | 283 } |
283 | 284 |
284 break; | 285 break; |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
457 FillAppDictionary(&dictionary); | 458 FillAppDictionary(&dictionary); |
458 web_ui()->CallJavascriptFunction("ntp.getAppsCallback", dictionary); | 459 web_ui()->CallJavascriptFunction("ntp.getAppsCallback", dictionary); |
459 | 460 |
460 // First time we get here we set up the observer so that we can tell update | 461 // First time we get here we set up the observer so that we can tell update |
461 // the apps as they change. | 462 // the apps as they change. |
462 if (!has_loaded_apps_) { | 463 if (!has_loaded_apps_) { |
463 base::Closure callback = base::Bind( | 464 base::Closure callback = base::Bind( |
464 &AppLauncherHandler::OnExtensionPreferenceChanged, | 465 &AppLauncherHandler::OnExtensionPreferenceChanged, |
465 base::Unretained(this)); | 466 base::Unretained(this)); |
466 extension_pref_change_registrar_.Init( | 467 extension_pref_change_registrar_.Init( |
467 extension_service_->extension_prefs()->pref_service()); | 468 ExtensionPrefs::Get(profile)->pref_service()); |
468 extension_pref_change_registrar_.Add( | 469 extension_pref_change_registrar_.Add( |
469 extensions::pref_names::kExtensions, callback); | 470 extensions::pref_names::kExtensions, callback); |
470 extension_pref_change_registrar_.Add(prefs::kNtpAppPageNames, callback); | 471 extension_pref_change_registrar_.Add(prefs::kNtpAppPageNames, callback); |
471 | 472 |
472 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, | 473 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, |
473 content::Source<Profile>(profile)); | 474 content::Source<Profile>(profile)); |
474 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, | 475 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, |
475 content::Source<Profile>(profile)); | 476 content::Source<Profile>(profile)); |
476 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNINSTALLED, | 477 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNINSTALLED, |
477 content::Source<Profile>(profile)); | 478 content::Source<Profile>(profile)); |
478 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LAUNCHER_REORDERED, | 479 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LAUNCHER_REORDERED, |
479 content::Source<AppSorting>( | 480 content::Source<AppSorting>( |
480 extension_service_->extension_prefs()->app_sorting())); | 481 ExtensionPrefs::Get(profile)->app_sorting())); |
481 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_INSTALL_ERROR, | 482 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_INSTALL_ERROR, |
482 content::Source<CrxInstaller>(NULL)); | 483 content::Source<CrxInstaller>(NULL)); |
483 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOAD_ERROR, | 484 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOAD_ERROR, |
484 content::Source<Profile>(profile)); | 485 content::Source<Profile>(profile)); |
485 } | 486 } |
486 | 487 |
487 has_loaded_apps_ = true; | 488 has_loaded_apps_ = true; |
488 } | 489 } |
489 | 490 |
490 void AppLauncherHandler::HandleLaunchApp(const base::ListValue* args) { | 491 void AppLauncherHandler::HandleLaunchApp(const base::ListValue* args) { |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
636 if (i > 0) | 637 if (i > 0) |
637 CHECK(app_order->GetString(i - 1, &predecessor_to_moved_ext)); | 638 CHECK(app_order->GetString(i - 1, &predecessor_to_moved_ext)); |
638 if (i + 1 < app_order->GetSize()) | 639 if (i + 1 < app_order->GetSize()) |
639 CHECK(app_order->GetString(i + 1, &successor_to_moved_ext)); | 640 CHECK(app_order->GetString(i + 1, &successor_to_moved_ext)); |
640 break; | 641 break; |
641 } | 642 } |
642 } | 643 } |
643 | 644 |
644 // Don't update the page; it already knows the apps have been reordered. | 645 // Don't update the page; it already knows the apps have been reordered. |
645 base::AutoReset<bool> auto_reset(&ignore_changes_, true); | 646 base::AutoReset<bool> auto_reset(&ignore_changes_, true); |
646 extension_service_->extension_prefs()->SetAppDraggedByUser(dragged_app_id); | 647 ExtensionPrefs::Get(extension_service_->profile())-> |
| 648 SetAppDraggedByUser(dragged_app_id); |
647 extension_service_->OnExtensionMoved(dragged_app_id, | 649 extension_service_->OnExtensionMoved(dragged_app_id, |
648 predecessor_to_moved_ext, | 650 predecessor_to_moved_ext, |
649 successor_to_moved_ext); | 651 successor_to_moved_ext); |
650 } | 652 } |
651 | 653 |
652 void AppLauncherHandler::HandleSetPageIndex(const base::ListValue* args) { | 654 void AppLauncherHandler::HandleSetPageIndex(const base::ListValue* args) { |
653 AppSorting* app_sorting = | 655 AppSorting* app_sorting = |
654 extension_service_->extension_prefs()->app_sorting(); | 656 ExtensionPrefs::Get(extension_service_->profile())->app_sorting(); |
655 | 657 |
656 std::string extension_id; | 658 std::string extension_id; |
657 double page_index; | 659 double page_index; |
658 CHECK(args->GetString(0, &extension_id)); | 660 CHECK(args->GetString(0, &extension_id)); |
659 CHECK(args->GetDouble(1, &page_index)); | 661 CHECK(args->GetDouble(1, &page_index)); |
660 const syncer::StringOrdinal& page_ordinal = | 662 const syncer::StringOrdinal& page_ordinal = |
661 app_sorting->PageIntegerAsStringOrdinal(static_cast<size_t>(page_index)); | 663 app_sorting->PageIntegerAsStringOrdinal(static_cast<size_t>(page_index)); |
662 | 664 |
663 // Don't update the page; it already knows the apps have been reordered. | 665 // Don't update the page; it already knows the apps have been reordered. |
664 base::AutoReset<bool> auto_reset(&ignore_changes_, true); | 666 base::AutoReset<bool> auto_reset(&ignore_changes_, true); |
(...skipping 18 matching lines...) Expand all Loading... |
683 std::string url; | 685 std::string url; |
684 CHECK(args->GetString(0, &url)); | 686 CHECK(args->GetString(0, &url)); |
685 GURL launch_url(url); | 687 GURL launch_url(url); |
686 | 688 |
687 base::string16 title; | 689 base::string16 title; |
688 CHECK(args->GetString(1, &title)); | 690 CHECK(args->GetString(1, &title)); |
689 | 691 |
690 double page_index; | 692 double page_index; |
691 CHECK(args->GetDouble(2, &page_index)); | 693 CHECK(args->GetDouble(2, &page_index)); |
692 AppSorting* app_sorting = | 694 AppSorting* app_sorting = |
693 extension_service_->extension_prefs()->app_sorting(); | 695 ExtensionPrefs::Get(extension_service_->profile())->app_sorting(); |
694 const syncer::StringOrdinal& page_ordinal = | 696 const syncer::StringOrdinal& page_ordinal = |
695 app_sorting->PageIntegerAsStringOrdinal(static_cast<size_t>(page_index)); | 697 app_sorting->PageIntegerAsStringOrdinal(static_cast<size_t>(page_index)); |
696 | 698 |
697 Profile* profile = Profile::FromWebUI(web_ui()); | 699 Profile* profile = Profile::FromWebUI(web_ui()); |
698 FaviconService* favicon_service = | 700 FaviconService* favicon_service = |
699 FaviconServiceFactory::GetForProfile(profile, Profile::EXPLICIT_ACCESS); | 701 FaviconServiceFactory::GetForProfile(profile, Profile::EXPLICIT_ACCESS); |
700 if (!favicon_service) { | 702 if (!favicon_service) { |
701 LOG(ERROR) << "No favicon service"; | 703 LOG(ERROR) << "No favicon service"; |
702 return; | 704 return; |
703 } | 705 } |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
845 ExtensionUninstallDialog* AppLauncherHandler::GetExtensionUninstallDialog() { | 847 ExtensionUninstallDialog* AppLauncherHandler::GetExtensionUninstallDialog() { |
846 if (!extension_uninstall_dialog_.get()) { | 848 if (!extension_uninstall_dialog_.get()) { |
847 Browser* browser = chrome::FindBrowserWithWebContents( | 849 Browser* browser = chrome::FindBrowserWithWebContents( |
848 web_ui()->GetWebContents()); | 850 web_ui()->GetWebContents()); |
849 extension_uninstall_dialog_.reset( | 851 extension_uninstall_dialog_.reset( |
850 ExtensionUninstallDialog::Create(extension_service_->profile(), | 852 ExtensionUninstallDialog::Create(extension_service_->profile(), |
851 browser, this)); | 853 browser, this)); |
852 } | 854 } |
853 return extension_uninstall_dialog_.get(); | 855 return extension_uninstall_dialog_.get(); |
854 } | 856 } |
OLD | NEW |