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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 } | 92 } |
93 return dictionary; | 93 return dictionary; |
94 } | 94 } |
95 | 95 |
96 // static | 96 // static |
97 bool AppLauncherHandler::IsAppExcludedFromList(const Extension* extension) { | 97 bool AppLauncherHandler::IsAppExcludedFromList(const Extension* extension) { |
98 // Don't include the WebStore and the Cloud Print app. | 98 // Don't include the WebStore and the Cloud Print app. |
99 // The WebStore launcher gets special treatment in ntp/apps.js. | 99 // The WebStore launcher gets special treatment in ntp/apps.js. |
100 // The Cloud Print app should never be displayed in the NTP. | 100 // The Cloud Print app should never be displayed in the NTP. |
101 bool ntp3 = | 101 bool ntp3 = |
102 !NewTabUI::Ntp4Enabled(); | 102 !NewTabUI::NTP4Enabled(); |
103 if (!extension->is_app() || | 103 if (!extension->is_app() || |
104 (ntp3 && extension->id() == extension_misc::kWebStoreAppId) || | 104 (ntp3 && extension->id() == extension_misc::kWebStoreAppId) || |
105 (extension->id() == extension_misc::kCloudPrintAppId)) { | 105 (extension->id() == extension_misc::kCloudPrintAppId)) { |
106 return true; | 106 return true; |
107 } | 107 } |
108 return false; | 108 return false; |
109 } | 109 } |
110 | 110 |
111 void AppLauncherHandler::CreateAppInfo(const Extension* extension, | 111 void AppLauncherHandler::CreateAppInfo(const Extension* extension, |
112 const AppNotification* notification, | 112 const AppNotification* notification, |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 } | 262 } |
263 case chrome::NOTIFICATION_EXTENSION_LOADED: | 263 case chrome::NOTIFICATION_EXTENSION_LOADED: |
264 case chrome::NOTIFICATION_EXTENSION_UNLOADED: { | 264 case chrome::NOTIFICATION_EXTENSION_UNLOADED: { |
265 const Extension* extension = | 265 const Extension* extension = |
266 type == chrome::NOTIFICATION_EXTENSION_LOADED ? | 266 type == chrome::NOTIFICATION_EXTENSION_LOADED ? |
267 Details<const Extension>(details).ptr() : | 267 Details<const Extension>(details).ptr() : |
268 Details<UnloadedExtensionInfo>(details)->extension; | 268 Details<UnloadedExtensionInfo>(details)->extension; |
269 if (!extension->is_app()) | 269 if (!extension->is_app()) |
270 break; | 270 break; |
271 | 271 |
272 if (NewTabUI::Ntp4Enabled()) { | 272 if (NewTabUI::NTP4Enabled()) { |
273 scoped_ptr<DictionaryValue> app_info(GetAppInfo(extension)); | 273 scoped_ptr<DictionaryValue> app_info(GetAppInfo(extension)); |
274 if (app_info.get()) { | 274 if (app_info.get()) { |
275 std::string function = | 275 std::string function = |
276 type == chrome::NOTIFICATION_EXTENSION_LOADED ? | 276 type == chrome::NOTIFICATION_EXTENSION_LOADED ? |
277 "ntp4.appAdded" : "ntp4.appRemoved"; | 277 "ntp4.appAdded" : "ntp4.appRemoved"; |
278 web_ui_->CallJavascriptFunction(function, *app_info); | 278 web_ui_->CallJavascriptFunction(function, *app_info); |
279 } | 279 } |
280 } else if (web_ui_->tab_contents()) { | 280 } else if (web_ui_->tab_contents()) { |
281 HandleGetApps(NULL); | 281 HandleGetApps(NULL); |
282 } | 282 } |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
360 // Making shortcut does not make sense on ChromeOS because it does not have | 360 // Making shortcut does not make sense on ChromeOS because it does not have |
361 // a desktop. | 361 // a desktop. |
362 dictionary->SetBoolean("disableCreateAppShortcut", true); | 362 dictionary->SetBoolean("disableCreateAppShortcut", true); |
363 #endif | 363 #endif |
364 | 364 |
365 dictionary->SetBoolean( | 365 dictionary->SetBoolean( |
366 "showLauncher", | 366 "showLauncher", |
367 extension_service_->apps_promo()->ShouldShowAppLauncher( | 367 extension_service_->apps_promo()->ShouldShowAppLauncher( |
368 extension_service_->GetAppIds())); | 368 extension_service_->GetAppIds())); |
369 | 369 |
370 if (NewTabUI::Ntp4Enabled()) { | 370 if (NewTabUI::NTP4Enabled()) { |
371 PrefService* prefs = Profile::FromWebUI(web_ui_)->GetPrefs(); | 371 PrefService* prefs = Profile::FromWebUI(web_ui_)->GetPrefs(); |
372 const ListValue* app_page_names = prefs->GetList(prefs::kNTPAppPageNames); | 372 const ListValue* app_page_names = prefs->GetList(prefs::kNTPAppPageNames); |
373 if (app_page_names && app_page_names->GetSize()) { | 373 if (app_page_names && app_page_names->GetSize()) { |
374 dictionary->Set("appPageNames", | 374 dictionary->Set("appPageNames", |
375 static_cast<ListValue*>(app_page_names->DeepCopy())); | 375 static_cast<ListValue*>(app_page_names->DeepCopy())); |
376 } | 376 } |
377 } | 377 } |
378 } | 378 } |
379 | 379 |
380 DictionaryValue* AppLauncherHandler::GetAppInfo(const Extension* extension) { | 380 DictionaryValue* AppLauncherHandler::GetAppInfo(const Extension* extension) { |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
494 // If the user pressed special keys when clicking, override the saved | 494 // If the user pressed special keys when clicking, override the saved |
495 // preference for launch container. | 495 // preference for launch container. |
496 bool middle_button = (button == 1.0); | 496 bool middle_button = (button == 1.0); |
497 WindowOpenDisposition disposition = | 497 WindowOpenDisposition disposition = |
498 disposition_utils::DispositionFromClick(middle_button, alt_key, | 498 disposition_utils::DispositionFromClick(middle_button, alt_key, |
499 ctrl_key, meta_key, shift_key); | 499 ctrl_key, meta_key, shift_key); |
500 | 500 |
501 if (extension_id != extension_misc::kWebStoreAppId) { | 501 if (extension_id != extension_misc::kWebStoreAppId) { |
502 RecordAppLaunchByID(promo_active_, launch_bucket); | 502 RecordAppLaunchByID(promo_active_, launch_bucket); |
503 extension_service_->apps_promo()->ExpireDefaultApps(); | 503 extension_service_->apps_promo()->ExpireDefaultApps(); |
504 } else if (NewTabUI::Ntp4Enabled()) { | 504 } else if (NewTabUI::NTP4Enabled()) { |
505 RecordWebStoreLaunch(promo_active_); | 505 RecordWebStoreLaunch(promo_active_); |
506 } | 506 } |
507 | 507 |
508 if (disposition == NEW_FOREGROUND_TAB || disposition == NEW_BACKGROUND_TAB) { | 508 if (disposition == NEW_FOREGROUND_TAB || disposition == NEW_BACKGROUND_TAB) { |
509 // TODO(jamescook): Proper support for background tabs. | 509 // TODO(jamescook): Proper support for background tabs. |
510 Browser::OpenApplication( | 510 Browser::OpenApplication( |
511 profile, extension, extension_misc::LAUNCH_TAB, disposition); | 511 profile, extension, extension_misc::LAUNCH_TAB, disposition); |
512 } else if (disposition == NEW_WINDOW) { | 512 } else if (disposition == NEW_WINDOW) { |
513 // Force a new window open. | 513 // Force a new window open. |
514 Browser::OpenApplication( | 514 Browser::OpenApplication( |
(...skipping 27 matching lines...) Expand all Loading... |
542 double launch_type; | 542 double launch_type; |
543 CHECK(args->GetString(0, &extension_id)); | 543 CHECK(args->GetString(0, &extension_id)); |
544 CHECK(args->GetDouble(1, &launch_type)); | 544 CHECK(args->GetDouble(1, &launch_type)); |
545 | 545 |
546 const Extension* extension = | 546 const Extension* extension = |
547 extension_service_->GetExtensionById(extension_id, true); | 547 extension_service_->GetExtensionById(extension_id, true); |
548 CHECK(extension); | 548 CHECK(extension); |
549 | 549 |
550 // Don't update the page; it already knows about the launch type change. | 550 // Don't update the page; it already knows about the launch type change. |
551 scoped_ptr<AutoReset<bool> > auto_reset; | 551 scoped_ptr<AutoReset<bool> > auto_reset; |
552 if (NewTabUI::Ntp4Enabled()) | 552 if (NewTabUI::NTP4Enabled()) |
553 auto_reset.reset(new AutoReset<bool>(&ignore_changes_, true)); | 553 auto_reset.reset(new AutoReset<bool>(&ignore_changes_, true)); |
554 | 554 |
555 extension_service_->extension_prefs()->SetLaunchType( | 555 extension_service_->extension_prefs()->SetLaunchType( |
556 extension_id, | 556 extension_id, |
557 static_cast<ExtensionPrefs::LaunchType>( | 557 static_cast<ExtensionPrefs::LaunchType>( |
558 static_cast<int>(launch_type))); | 558 static_cast<int>(launch_type))); |
559 } | 559 } |
560 | 560 |
561 void AppLauncherHandler::HandleUninstallApp(const ListValue* args) { | 561 void AppLauncherHandler::HandleUninstallApp(const ListValue* args) { |
562 std::string extension_id; | 562 std::string extension_id; |
(...skipping 10 matching lines...) Expand all Loading... |
573 return; | 573 return; |
574 } | 574 } |
575 if (!extension_id_prompting_.empty()) | 575 if (!extension_id_prompting_.empty()) |
576 return; // Only one prompt at a time. | 576 return; // Only one prompt at a time. |
577 | 577 |
578 extension_id_prompting_ = extension_id; | 578 extension_id_prompting_ = extension_id; |
579 | 579 |
580 bool dont_confirm = false; | 580 bool dont_confirm = false; |
581 if (args->GetBoolean(1, &dont_confirm) && dont_confirm) { | 581 if (args->GetBoolean(1, &dont_confirm) && dont_confirm) { |
582 scoped_ptr<AutoReset<bool> > auto_reset; | 582 scoped_ptr<AutoReset<bool> > auto_reset; |
583 if (NewTabUI::Ntp4Enabled()) | 583 if (NewTabUI::NTP4Enabled()) |
584 auto_reset.reset(new AutoReset<bool>(&ignore_changes_, true)); | 584 auto_reset.reset(new AutoReset<bool>(&ignore_changes_, true)); |
585 ExtensionDialogAccepted(); | 585 ExtensionDialogAccepted(); |
586 } else { | 586 } else { |
587 GetExtensionUninstallDialog()->ConfirmUninstall(this, extension); | 587 GetExtensionUninstallDialog()->ConfirmUninstall(this, extension); |
588 } | 588 } |
589 } | 589 } |
590 | 590 |
591 void AppLauncherHandler::HandleHideAppsPromo(const ListValue* args) { | 591 void AppLauncherHandler::HandleHideAppsPromo(const ListValue* args) { |
592 // If the user has intentionally hidden the promotion, we'll uninstall all the | 592 // If the user has intentionally hidden the promotion, we'll uninstall all the |
593 // default apps (we know the user hasn't installed any apps on their own at | 593 // default apps (we know the user hasn't installed any apps on their own at |
594 // this point, or the promotion wouldn't have been shown). | 594 // this point, or the promotion wouldn't have been shown). |
595 if (NewTabUI::Ntp4Enabled()) { | 595 if (NewTabUI::NTP4Enabled()) { |
596 UninstallDefaultApps(); | 596 UninstallDefaultApps(); |
597 extension_service_->apps_promo()->HidePromo(); | 597 extension_service_->apps_promo()->HidePromo(); |
598 } else { | 598 } else { |
599 // TODO(estade): remove all this. NTP3 uninstalled all the default apps then | 599 // TODO(estade): remove all this. NTP3 uninstalled all the default apps then |
600 // refreshed the entire NTP, we don't have to jump through these hoops for | 600 // refreshed the entire NTP, we don't have to jump through these hoops for |
601 // NTP4 because each app uninstall is handled separately without reloading | 601 // NTP4 because each app uninstall is handled separately without reloading |
602 // the entire page. | 602 // the entire page. |
603 ignore_changes_ = true; | 603 ignore_changes_ = true; |
604 UninstallDefaultApps(); | 604 UninstallDefaultApps(); |
605 extension_service_->apps_promo()->HidePromo(); | 605 extension_service_->apps_promo()->HidePromo(); |
(...skipping 30 matching lines...) Expand all Loading... |
636 | 636 |
637 std::vector<std::string> extension_ids; | 637 std::vector<std::string> extension_ids; |
638 for (size_t i = 0; i < app_order->GetSize(); ++i) { | 638 for (size_t i = 0; i < app_order->GetSize(); ++i) { |
639 std::string value; | 639 std::string value; |
640 if (app_order->GetString(i, &value)) | 640 if (app_order->GetString(i, &value)) |
641 extension_ids.push_back(value); | 641 extension_ids.push_back(value); |
642 } | 642 } |
643 | 643 |
644 // Don't update the page; it already knows the apps have been reordered. | 644 // Don't update the page; it already knows the apps have been reordered. |
645 scoped_ptr<AutoReset<bool> > auto_reset; | 645 scoped_ptr<AutoReset<bool> > auto_reset; |
646 if (NewTabUI::Ntp4Enabled()) | 646 if (NewTabUI::NTP4Enabled()) |
647 auto_reset.reset(new AutoReset<bool>(&ignore_changes_, true)); | 647 auto_reset.reset(new AutoReset<bool>(&ignore_changes_, true)); |
648 | 648 |
649 extension_service_->extension_prefs()->SetAppDraggedByUser(dragged_app_id); | 649 extension_service_->extension_prefs()->SetAppDraggedByUser(dragged_app_id); |
650 extension_service_->extension_prefs()->SetAppLauncherOrder(extension_ids); | 650 extension_service_->extension_prefs()->SetAppLauncherOrder(extension_ids); |
651 } | 651 } |
652 | 652 |
653 void AppLauncherHandler::HandleSetPageIndex(const ListValue* args) { | 653 void AppLauncherHandler::HandleSetPageIndex(const ListValue* args) { |
654 std::string extension_id; | 654 std::string extension_id; |
655 double page_index; | 655 double page_index; |
656 CHECK(args->GetString(0, &extension_id)); | 656 CHECK(args->GetString(0, &extension_id)); |
657 CHECK(args->GetDouble(1, &page_index)); | 657 CHECK(args->GetDouble(1, &page_index)); |
658 | 658 |
659 // Don't update the page; it already knows the apps have been reordered. | 659 // Don't update the page; it already knows the apps have been reordered. |
660 scoped_ptr<AutoReset<bool> > auto_reset; | 660 scoped_ptr<AutoReset<bool> > auto_reset; |
661 if (NewTabUI::Ntp4Enabled()) | 661 if (NewTabUI::NTP4Enabled()) |
662 auto_reset.reset(new AutoReset<bool>(&ignore_changes_, true)); | 662 auto_reset.reset(new AutoReset<bool>(&ignore_changes_, true)); |
663 | 663 |
664 extension_service_->extension_prefs()->SetPageIndex(extension_id, | 664 extension_service_->extension_prefs()->SetPageIndex(extension_id, |
665 static_cast<int>(page_index)); | 665 static_cast<int>(page_index)); |
666 } | 666 } |
667 | 667 |
668 void AppLauncherHandler::HandlePromoSeen(const ListValue* args) { | 668 void AppLauncherHandler::HandlePromoSeen(const ListValue* args) { |
669 UMA_HISTOGRAM_ENUMERATION(extension_misc::kAppsPromoHistogram, | 669 UMA_HISTOGRAM_ENUMERATION(extension_misc::kAppsPromoHistogram, |
670 extension_misc::PROMO_SEEN, | 670 extension_misc::PROMO_SEEN, |
671 extension_misc::PROMO_BUCKET_BOUNDARY); | 671 extension_misc::PROMO_BUCKET_BOUNDARY); |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
909 | 909 |
910 void AppLauncherHandler::UninstallDefaultApps() { | 910 void AppLauncherHandler::UninstallDefaultApps() { |
911 AppsPromo* apps_promo = extension_service_->apps_promo(); | 911 AppsPromo* apps_promo = extension_service_->apps_promo(); |
912 const ExtensionIdSet& app_ids = apps_promo->old_default_apps(); | 912 const ExtensionIdSet& app_ids = apps_promo->old_default_apps(); |
913 for (ExtensionIdSet::const_iterator iter = app_ids.begin(); | 913 for (ExtensionIdSet::const_iterator iter = app_ids.begin(); |
914 iter != app_ids.end(); ++iter) { | 914 iter != app_ids.end(); ++iter) { |
915 if (extension_service_->GetExtensionById(*iter, true)) | 915 if (extension_service_->GetExtensionById(*iter, true)) |
916 extension_service_->UninstallExtension(*iter, false, NULL); | 916 extension_service_->UninstallExtension(*iter, false, NULL); |
917 } | 917 } |
918 } | 918 } |
OLD | NEW |