| 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 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 // a desktop. | 363 // a desktop. |
| 364 dictionary->SetBoolean("disableCreateAppShortcut", true); | 364 dictionary->SetBoolean("disableCreateAppShortcut", true); |
| 365 #endif | 365 #endif |
| 366 | 366 |
| 367 dictionary->SetBoolean( | 367 dictionary->SetBoolean( |
| 368 "showLauncher", | 368 "showLauncher", |
| 369 extension_service_->apps_promo()->ShouldShowAppLauncher( | 369 extension_service_->apps_promo()->ShouldShowAppLauncher( |
| 370 extension_service_->GetAppIds())); | 370 extension_service_->GetAppIds())); |
| 371 | 371 |
| 372 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kNewTabPage4)) { | 372 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kNewTabPage4)) { |
| 373 PrefService* prefs = web_ui_->GetProfile()->GetPrefs(); | 373 Profile* profile = |
| 374 Profile::FromBrowserContext(web_ui_->tab_contents()->browser_context()); |
| 375 PrefService* prefs = profile->GetPrefs(); |
| 374 const ListValue* app_page_names = prefs->GetList(prefs::kNTPAppPageNames); | 376 const ListValue* app_page_names = prefs->GetList(prefs::kNTPAppPageNames); |
| 375 if (app_page_names && app_page_names->GetSize()) { | 377 if (app_page_names && app_page_names->GetSize()) { |
| 376 dictionary->Set("appPageNames", | 378 dictionary->Set("appPageNames", |
| 377 static_cast<ListValue*>(app_page_names->DeepCopy())); | 379 static_cast<ListValue*>(app_page_names->DeepCopy())); |
| 378 } | 380 } |
| 379 } | 381 } |
| 380 } | 382 } |
| 381 | 383 |
| 382 DictionaryValue* AppLauncherHandler::GetAppInfo(const Extension* extension) { | 384 DictionaryValue* AppLauncherHandler::GetAppInfo(const Extension* extension) { |
| 383 AppNotificationManager* notification_manager = | 385 AppNotificationManager* notification_manager = |
| (...skipping 19 matching lines...) Expand all Loading... |
| 403 | 405 |
| 404 // Tell the client whether to show the promo for this view. We don't do this | 406 // Tell the client whether to show the promo for this view. We don't do this |
| 405 // in the case of PREF_CHANGED because: | 407 // in the case of PREF_CHANGED because: |
| 406 // | 408 // |
| 407 // a) At that point in time, depending on the pref that changed, it can look | 409 // a) At that point in time, depending on the pref that changed, it can look |
| 408 // like the set of apps installed has changed, and we will mark the promo | 410 // like the set of apps installed has changed, and we will mark the promo |
| 409 // expired. | 411 // expired. |
| 410 // b) Conceptually, it doesn't really make sense to count a | 412 // b) Conceptually, it doesn't really make sense to count a |
| 411 // prefchange-triggered refresh as a promo 'view'. | 413 // prefchange-triggered refresh as a promo 'view'. |
| 412 AppsPromo* apps_promo = extension_service_->apps_promo(); | 414 AppsPromo* apps_promo = extension_service_->apps_promo(); |
| 413 PrefService* prefs = web_ui_->GetProfile()->GetPrefs(); | 415 Profile* profile = |
| 416 Profile::FromBrowserContext(web_ui_->tab_contents()->browser_context()); |
| 417 PrefService* prefs = profile->GetPrefs(); |
| 414 bool apps_promo_just_expired = false; | 418 bool apps_promo_just_expired = false; |
| 415 if (apps_promo->ShouldShowPromo(extension_service_->GetAppIds(), | 419 if (apps_promo->ShouldShowPromo(extension_service_->GetAppIds(), |
| 416 &apps_promo_just_expired)) { | 420 &apps_promo_just_expired)) { |
| 417 apps_promo->MaximizeAppsIfNecessary(); | 421 apps_promo->MaximizeAppsIfNecessary(); |
| 418 dictionary.SetBoolean("showPromo", true); | 422 dictionary.SetBoolean("showPromo", true); |
| 419 FillPromoDictionary(&dictionary); | 423 FillPromoDictionary(&dictionary); |
| 420 promo_active_ = true; | 424 promo_active_ = true; |
| 421 } else { | 425 } else { |
| 422 dictionary.SetBoolean("showPromo", false); | 426 dictionary.SetBoolean("showPromo", false); |
| 423 promo_active_ = false; | 427 promo_active_ = false; |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 675 } | 679 } |
| 676 | 680 |
| 677 void AppLauncherHandler::HandleSaveAppPageName(const ListValue* args) { | 681 void AppLauncherHandler::HandleSaveAppPageName(const ListValue* args) { |
| 678 string16 name; | 682 string16 name; |
| 679 CHECK(args->GetString(0, &name)); | 683 CHECK(args->GetString(0, &name)); |
| 680 | 684 |
| 681 double page_index; | 685 double page_index; |
| 682 CHECK(args->GetDouble(1, &page_index)); | 686 CHECK(args->GetDouble(1, &page_index)); |
| 683 | 687 |
| 684 AutoReset<bool> auto_reset(&ignore_changes_, true); | 688 AutoReset<bool> auto_reset(&ignore_changes_, true); |
| 685 PrefService* prefs = web_ui_->GetProfile()->GetPrefs(); | 689 Profile* profile = |
| 690 Profile::FromBrowserContext(web_ui_->tab_contents()->browser_context()); |
| 691 PrefService* prefs = profile->GetPrefs(); |
| 686 ListPrefUpdate update(prefs, prefs::kNTPAppPageNames); | 692 ListPrefUpdate update(prefs, prefs::kNTPAppPageNames); |
| 687 ListValue* list = update.Get(); | 693 ListValue* list = update.Get(); |
| 688 list->Set(static_cast<size_t>(page_index), Value::CreateStringValue(name)); | 694 list->Set(static_cast<size_t>(page_index), Value::CreateStringValue(name)); |
| 689 } | 695 } |
| 690 | 696 |
| 691 void AppLauncherHandler::HandleGenerateAppForLink(const ListValue* args) { | 697 void AppLauncherHandler::HandleGenerateAppForLink(const ListValue* args) { |
| 692 std::string url; | 698 std::string url; |
| 693 CHECK(args->GetString(0, &url)); | 699 CHECK(args->GetString(0, &url)); |
| 694 | 700 |
| 695 string16 title; | 701 string16 title; |
| 696 CHECK(args->GetString(1, &title)); | 702 CHECK(args->GetString(1, &title)); |
| 697 | 703 |
| 698 GURL launch_url(url); | 704 GURL launch_url(url); |
| 699 | 705 |
| 700 scoped_ptr<WebApplicationInfo> web_app(new WebApplicationInfo); | 706 scoped_ptr<WebApplicationInfo> web_app(new WebApplicationInfo); |
| 701 web_app->is_bookmark_app = true; | 707 web_app->is_bookmark_app = true; |
| 702 web_app->title = title; | 708 web_app->title = title; |
| 703 web_app->app_url = launch_url; | 709 web_app->app_url = launch_url; |
| 704 WebApplicationInfo::IconInfo icon; | 710 WebApplicationInfo::IconInfo icon; |
| 705 icon.url = GURL(); | 711 icon.url = GURL(); |
| 706 icon.width = icon.height = 16; | 712 icon.width = icon.height = 16; |
| 707 web_app->icons.push_back(icon); | 713 web_app->icons.push_back(icon); |
| 708 | 714 |
| 709 Profile* profile = web_ui_->GetProfile(); | 715 Profile* profile = |
| 716 Profile::FromBrowserContext(web_ui_->tab_contents()->browser_context()); |
| 710 FaviconService* favicon_service = | 717 FaviconService* favicon_service = |
| 711 profile->GetFaviconService(Profile::EXPLICIT_ACCESS); | 718 profile->GetFaviconService(Profile::EXPLICIT_ACCESS); |
| 712 if (!favicon_service) { | 719 if (!favicon_service) { |
| 713 LOG(ERROR) << "No favicon service"; | 720 LOG(ERROR) << "No favicon service"; |
| 714 scoped_refptr<CrxInstaller> installer( | 721 scoped_refptr<CrxInstaller> installer( |
| 715 extension_service_->MakeCrxInstaller(NULL)); | 722 extension_service_->MakeCrxInstaller(NULL)); |
| 716 installer->InstallWebApp(*web_app); | 723 installer->InstallWebApp(*web_app); |
| 717 return; | 724 return; |
| 718 } | 725 } |
| 719 | 726 |
| 720 FaviconService::Handle h = favicon_service->GetFaviconForURL( | 727 FaviconService::Handle h = favicon_service->GetFaviconForURL( |
| 721 launch_url, history::FAVICON, &favicon_consumer_, | 728 launch_url, history::FAVICON, &favicon_consumer_, |
| 722 NewCallback(this, &AppLauncherHandler::OnFaviconForApp)); | 729 NewCallback(this, &AppLauncherHandler::OnFaviconForApp)); |
| 723 favicon_consumer_.SetClientData(favicon_service, h, web_app.release()); | 730 favicon_consumer_.SetClientData(favicon_service, h, web_app.release()); |
| 724 } | 731 } |
| 725 | 732 |
| 726 void AppLauncherHandler::HandleRecordAppLaunchByURL( | 733 void AppLauncherHandler::HandleRecordAppLaunchByURL( |
| 727 const base::ListValue* args) { | 734 const base::ListValue* args) { |
| 728 std::string url; | 735 std::string url; |
| 729 CHECK(args->GetString(0, &url)); | 736 CHECK(args->GetString(0, &url)); |
| 730 double source; | 737 double source; |
| 731 CHECK(args->GetDouble(1, &source)); | 738 CHECK(args->GetDouble(1, &source)); |
| 732 | 739 |
| 733 extension_misc::AppLaunchBucket bucket = | 740 extension_misc::AppLaunchBucket bucket = |
| 734 static_cast<extension_misc::AppLaunchBucket>(static_cast<int>(source)); | 741 static_cast<extension_misc::AppLaunchBucket>(static_cast<int>(source)); |
| 735 CHECK(source < extension_misc::APP_LAUNCH_BUCKET_BOUNDARY); | 742 CHECK(source < extension_misc::APP_LAUNCH_BUCKET_BOUNDARY); |
| 736 | 743 |
| 737 RecordAppLaunchByURL(web_ui_->GetProfile(), url, bucket); | 744 Profile* profile = |
| 745 Profile::FromBrowserContext(web_ui_->tab_contents()->browser_context()); |
| 746 RecordAppLaunchByURL(profile, url, bucket); |
| 738 } | 747 } |
| 739 | 748 |
| 740 void AppLauncherHandler::OnFaviconForApp(FaviconService::Handle handle, | 749 void AppLauncherHandler::OnFaviconForApp(FaviconService::Handle handle, |
| 741 history::FaviconData data) { | 750 history::FaviconData data) { |
| 742 scoped_ptr<WebApplicationInfo> web_app( | 751 scoped_ptr<WebApplicationInfo> web_app( |
| 743 favicon_consumer_.GetClientDataForCurrentRequest()); | 752 favicon_consumer_.GetClientDataForCurrentRequest()); |
| 744 CHECK(!web_app->icons.empty()); | 753 CHECK(!web_app->icons.empty()); |
| 745 if (data.is_valid() && gfx::PNGCodec::Decode(data.image_data->front(), | 754 if (data.is_valid() && gfx::PNGCodec::Decode(data.image_data->front(), |
| 746 data.image_data->size(), | 755 data.image_data->size(), |
| 747 &(web_app->icons[0].data))) { | 756 &(web_app->icons[0].data))) { |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 890 "Extensions.Permissions_ReEnableCancel" : | 899 "Extensions.Permissions_ReEnableCancel" : |
| 891 "Extensions.Permissions_ReEnableAbort"; | 900 "Extensions.Permissions_ReEnableAbort"; |
| 892 ExtensionService::RecordPermissionMessagesHistogram( | 901 ExtensionService::RecordPermissionMessagesHistogram( |
| 893 extension, histogram_name.c_str()); | 902 extension, histogram_name.c_str()); |
| 894 | 903 |
| 895 ExtensionDialogCanceled(); | 904 ExtensionDialogCanceled(); |
| 896 } | 905 } |
| 897 | 906 |
| 898 ExtensionUninstallDialog* AppLauncherHandler::GetExtensionUninstallDialog() { | 907 ExtensionUninstallDialog* AppLauncherHandler::GetExtensionUninstallDialog() { |
| 899 if (!extension_uninstall_dialog_.get()) { | 908 if (!extension_uninstall_dialog_.get()) { |
| 900 extension_uninstall_dialog_.reset( | 909 Profile* profile = |
| 901 new ExtensionUninstallDialog(web_ui_->GetProfile())); | 910 Profile::FromBrowserContext(web_ui_->tab_contents()->browser_context()); |
| 911 extension_uninstall_dialog_.reset(new ExtensionUninstallDialog(profile)); |
| 902 } | 912 } |
| 903 return extension_uninstall_dialog_.get(); | 913 return extension_uninstall_dialog_.get(); |
| 904 } | 914 } |
| 905 | 915 |
| 906 ExtensionInstallUI* AppLauncherHandler::GetExtensionInstallUI() { | 916 ExtensionInstallUI* AppLauncherHandler::GetExtensionInstallUI() { |
| 907 if (!extension_install_ui_.get()) { | 917 if (!extension_install_ui_.get()) { |
| 908 extension_install_ui_.reset( | 918 Profile* profile = |
| 909 new ExtensionInstallUI(web_ui_->GetProfile())); | 919 Profile::FromBrowserContext(web_ui_->tab_contents()->browser_context()); |
| 920 extension_install_ui_.reset(new ExtensionInstallUI(profile)); |
| 910 } | 921 } |
| 911 return extension_install_ui_.get(); | 922 return extension_install_ui_.get(); |
| 912 } | 923 } |
| 913 | 924 |
| 914 void AppLauncherHandler::UninstallDefaultApps() { | 925 void AppLauncherHandler::UninstallDefaultApps() { |
| 915 AppsPromo* apps_promo = extension_service_->apps_promo(); | 926 AppsPromo* apps_promo = extension_service_->apps_promo(); |
| 916 const ExtensionIdSet& app_ids = apps_promo->old_default_apps(); | 927 const ExtensionIdSet& app_ids = apps_promo->old_default_apps(); |
| 917 for (ExtensionIdSet::const_iterator iter = app_ids.begin(); | 928 for (ExtensionIdSet::const_iterator iter = app_ids.begin(); |
| 918 iter != app_ids.end(); ++iter) { | 929 iter != app_ids.end(); ++iter) { |
| 919 if (extension_service_->GetExtensionById(*iter, true)) | 930 if (extension_service_->GetExtensionById(*iter, true)) |
| 920 extension_service_->UninstallExtension(*iter, false, NULL); | 931 extension_service_->UninstallExtension(*iter, false, NULL); |
| 921 } | 932 } |
| 922 } | 933 } |
| OLD | NEW |