| 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 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 extension->location() == Extension::COMPONENT); | 149 extension->location() == Extension::COMPONENT); |
| 150 value->SetBoolean("is_webstore", | 150 value->SetBoolean("is_webstore", |
| 151 extension->id() == extension_misc::kWebStoreAppId); | 151 extension->id() == extension_misc::kWebStoreAppId); |
| 152 | 152 |
| 153 if (notification) | 153 if (notification) |
| 154 value->Set("notification", SerializeNotification(*notification)); | 154 value->Set("notification", SerializeNotification(*notification)); |
| 155 | 155 |
| 156 int app_launch_index = prefs->GetAppLaunchIndex(extension->id()); | 156 int app_launch_index = prefs->GetAppLaunchIndex(extension->id()); |
| 157 if (app_launch_index == -1) { | 157 if (app_launch_index == -1) { |
| 158 // Make sure every app has a launch index (some predate the launch index). | 158 // Make sure every app has a launch index (some predate the launch index). |
| 159 app_launch_index = prefs->GetNextAppLaunchIndex(); | 159 app_launch_index = prefs->GetNextAppLaunchIndex(0); |
| 160 prefs->SetAppLaunchIndex(extension->id(), app_launch_index); | 160 prefs->SetAppLaunchIndex(extension->id(), app_launch_index); |
| 161 } | 161 } |
| 162 value->SetInteger("app_launch_index", app_launch_index); | 162 value->SetInteger("app_launch_index", app_launch_index); |
| 163 | 163 |
| 164 int page_index = prefs->GetPageIndex(extension->id()); | 164 int page_index = prefs->GetPageIndex(extension->id()); |
| 165 if (page_index >= 0) { | 165 if (page_index >= 0) { |
| 166 // Only provide a value if one is stored | 166 // Only provide a value if one is stored |
| 167 value->SetInteger("page_index", page_index); | 167 value->SetInteger("page_index", page_index); |
| 168 } | 168 } |
| 169 } | 169 } |
| (...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 683 AutoReset<bool> auto_reset(&ignore_changes_, true); | 683 AutoReset<bool> auto_reset(&ignore_changes_, true); |
| 684 PrefService* prefs = Profile::FromWebUI(web_ui_)->GetPrefs(); | 684 PrefService* prefs = Profile::FromWebUI(web_ui_)->GetPrefs(); |
| 685 ListPrefUpdate update(prefs, prefs::kNTPAppPageNames); | 685 ListPrefUpdate update(prefs, prefs::kNTPAppPageNames); |
| 686 ListValue* list = update.Get(); | 686 ListValue* list = update.Get(); |
| 687 list->Set(static_cast<size_t>(page_index), Value::CreateStringValue(name)); | 687 list->Set(static_cast<size_t>(page_index), Value::CreateStringValue(name)); |
| 688 } | 688 } |
| 689 | 689 |
| 690 void AppLauncherHandler::HandleGenerateAppForLink(const ListValue* args) { | 690 void AppLauncherHandler::HandleGenerateAppForLink(const ListValue* args) { |
| 691 std::string url; | 691 std::string url; |
| 692 CHECK(args->GetString(0, &url)); | 692 CHECK(args->GetString(0, &url)); |
| 693 GURL launch_url(url); |
| 693 | 694 |
| 694 string16 title; | 695 string16 title; |
| 695 CHECK(args->GetString(1, &title)); | 696 CHECK(args->GetString(1, &title)); |
| 696 | 697 |
| 697 GURL launch_url(url); | 698 double page_index; |
| 698 | 699 CHECK(args->GetDouble(2, &page_index)); |
| 699 scoped_ptr<WebApplicationInfo> web_app(new WebApplicationInfo); | |
| 700 web_app->is_bookmark_app = true; | |
| 701 web_app->title = title; | |
| 702 web_app->app_url = launch_url; | |
| 703 | 700 |
| 704 Profile* profile = Profile::FromWebUI(web_ui_); | 701 Profile* profile = Profile::FromWebUI(web_ui_); |
| 705 FaviconService* favicon_service = | 702 FaviconService* favicon_service = |
| 706 profile->GetFaviconService(Profile::EXPLICIT_ACCESS); | 703 profile->GetFaviconService(Profile::EXPLICIT_ACCESS); |
| 707 if (!favicon_service) { | 704 if (!favicon_service) { |
| 708 LOG(ERROR) << "No favicon service"; | 705 LOG(ERROR) << "No favicon service"; |
| 709 scoped_refptr<CrxInstaller> installer( | |
| 710 extension_service_->MakeCrxInstaller(NULL)); | |
| 711 installer->InstallWebApp(*web_app); | |
| 712 return; | 706 return; |
| 713 } | 707 } |
| 714 | 708 |
| 709 scoped_ptr<AppInstallInfo> install_info(new AppInstallInfo()); |
| 710 install_info->is_bookmark_app = true; |
| 711 install_info->title = title; |
| 712 install_info->app_url = launch_url; |
| 713 install_info->page_index = static_cast<int>(page_index); |
| 714 |
| 715 FaviconService::Handle h = favicon_service->GetFaviconForURL( | 715 FaviconService::Handle h = favicon_service->GetFaviconForURL( |
| 716 launch_url, history::FAVICON, &favicon_consumer_, | 716 launch_url, history::FAVICON, &favicon_consumer_, |
| 717 NewCallback(this, &AppLauncherHandler::OnFaviconForApp)); | 717 NewCallback(this, &AppLauncherHandler::OnFaviconForApp)); |
| 718 favicon_consumer_.SetClientData(favicon_service, h, web_app.release()); | 718 favicon_consumer_.SetClientData(favicon_service, h, install_info.release()); |
| 719 } | 719 } |
| 720 | 720 |
| 721 void AppLauncherHandler::HandleRecordAppLaunchByURL( | 721 void AppLauncherHandler::HandleRecordAppLaunchByURL( |
| 722 const base::ListValue* args) { | 722 const base::ListValue* args) { |
| 723 std::string url; | 723 std::string url; |
| 724 CHECK(args->GetString(0, &url)); | 724 CHECK(args->GetString(0, &url)); |
| 725 double source; | 725 double source; |
| 726 CHECK(args->GetDouble(1, &source)); | 726 CHECK(args->GetDouble(1, &source)); |
| 727 | 727 |
| 728 extension_misc::AppLaunchBucket bucket = | 728 extension_misc::AppLaunchBucket bucket = |
| 729 static_cast<extension_misc::AppLaunchBucket>(static_cast<int>(source)); | 729 static_cast<extension_misc::AppLaunchBucket>(static_cast<int>(source)); |
| 730 CHECK(source < extension_misc::APP_LAUNCH_BUCKET_BOUNDARY); | 730 CHECK(source < extension_misc::APP_LAUNCH_BUCKET_BOUNDARY); |
| 731 | 731 |
| 732 RecordAppLaunchByURL(Profile::FromWebUI(web_ui_), url, bucket); | 732 RecordAppLaunchByURL(Profile::FromWebUI(web_ui_), url, bucket); |
| 733 } | 733 } |
| 734 | 734 |
| 735 void AppLauncherHandler::OnFaviconForApp(FaviconService::Handle handle, | 735 void AppLauncherHandler::OnFaviconForApp(FaviconService::Handle handle, |
| 736 history::FaviconData data) { | 736 history::FaviconData data) { |
| 737 scoped_ptr<WebApplicationInfo> web_app( | 737 scoped_ptr<AppInstallInfo> install_info( |
| 738 favicon_consumer_.GetClientDataForCurrentRequest()); | 738 favicon_consumer_.GetClientDataForCurrentRequest()); |
| 739 scoped_ptr<WebApplicationInfo> web_app(new WebApplicationInfo()); |
| 740 web_app->is_bookmark_app = install_info->is_bookmark_app; |
| 741 web_app->title = install_info->title; |
| 742 web_app->app_url = install_info->app_url; |
| 743 |
| 739 WebApplicationInfo::IconInfo icon; | 744 WebApplicationInfo::IconInfo icon; |
| 740 web_app->icons.push_back(icon); | 745 web_app->icons.push_back(icon); |
| 741 if (data.is_valid() && gfx::PNGCodec::Decode(data.image_data->front(), | 746 if (data.is_valid() && gfx::PNGCodec::Decode(data.image_data->front(), |
| 742 data.image_data->size(), | 747 data.image_data->size(), |
| 743 &(web_app->icons[0].data))) { | 748 &(web_app->icons[0].data))) { |
| 744 web_app->icons[0].url = GURL(); | 749 web_app->icons[0].url = GURL(); |
| 745 web_app->icons[0].width = web_app->icons[0].data.width(); | 750 web_app->icons[0].width = web_app->icons[0].data.width(); |
| 746 web_app->icons[0].height = web_app->icons[0].data.height(); | 751 web_app->icons[0].height = web_app->icons[0].data.height(); |
| 747 } else { | 752 } else { |
| 748 web_app->icons.clear(); | 753 web_app->icons.clear(); |
| 749 } | 754 } |
| 750 | 755 |
| 751 scoped_refptr<CrxInstaller> installer( | 756 scoped_refptr<CrxInstaller> installer( |
| 752 extension_service_->MakeCrxInstaller(NULL)); | 757 extension_service_->MakeCrxInstaller(NULL)); |
| 758 installer->set_page_index(install_info->page_index); |
| 753 installer->InstallWebApp(*web_app); | 759 installer->InstallWebApp(*web_app); |
| 754 } | 760 } |
| 755 | 761 |
| 756 // static | 762 // static |
| 757 void AppLauncherHandler::RegisterUserPrefs(PrefService* pref_service) { | 763 void AppLauncherHandler::RegisterUserPrefs(PrefService* pref_service) { |
| 758 // TODO(csilv): We will want this to be a syncable preference instead. | 764 // TODO(csilv): We will want this to be a syncable preference instead. |
| 759 pref_service->RegisterListPref(prefs::kNTPAppPageNames, | 765 pref_service->RegisterListPref(prefs::kNTPAppPageNames, |
| 760 PrefService::UNSYNCABLE_PREF); | 766 PrefService::UNSYNCABLE_PREF); |
| 761 } | 767 } |
| 762 | 768 |
| 763 // static | 769 // statiic |
| 764 void AppLauncherHandler::RecordWebStoreLaunch(bool promo_active) { | 770 void AppLauncherHandler::RecordWebStoreLaunch(bool promo_active) { |
| 765 UMA_HISTOGRAM_ENUMERATION(extension_misc::kAppLaunchHistogram, | 771 UMA_HISTOGRAM_ENUMERATION(extension_misc::kAppLaunchHistogram, |
| 766 extension_misc::APP_LAUNCH_NTP_WEBSTORE, | 772 extension_misc::APP_LAUNCH_NTP_WEBSTORE, |
| 767 extension_misc::APP_LAUNCH_BUCKET_BOUNDARY); | 773 extension_misc::APP_LAUNCH_BUCKET_BOUNDARY); |
| 768 | 774 |
| 769 if (!promo_active) return; | 775 if (!promo_active) return; |
| 770 | 776 |
| 771 UMA_HISTOGRAM_ENUMERATION(extension_misc::kAppsPromoHistogram, | 777 UMA_HISTOGRAM_ENUMERATION(extension_misc::kAppsPromoHistogram, |
| 772 extension_misc::PROMO_LAUNCH_WEB_STORE, | 778 extension_misc::PROMO_LAUNCH_WEB_STORE, |
| 773 extension_misc::PROMO_BUCKET_BOUNDARY); | 779 extension_misc::PROMO_BUCKET_BOUNDARY); |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 911 | 917 |
| 912 void AppLauncherHandler::UninstallDefaultApps() { | 918 void AppLauncherHandler::UninstallDefaultApps() { |
| 913 AppsPromo* apps_promo = extension_service_->apps_promo(); | 919 AppsPromo* apps_promo = extension_service_->apps_promo(); |
| 914 const ExtensionIdSet& app_ids = apps_promo->old_default_apps(); | 920 const ExtensionIdSet& app_ids = apps_promo->old_default_apps(); |
| 915 for (ExtensionIdSet::const_iterator iter = app_ids.begin(); | 921 for (ExtensionIdSet::const_iterator iter = app_ids.begin(); |
| 916 iter != app_ids.end(); ++iter) { | 922 iter != app_ids.end(); ++iter) { |
| 917 if (extension_service_->GetExtensionById(*iter, true)) | 923 if (extension_service_->GetExtensionById(*iter, true)) |
| 918 extension_service_->UninstallExtension(*iter, false, NULL); | 924 extension_service_->UninstallExtension(*iter, false, NULL); |
| 919 } | 925 } |
| 920 } | 926 } |
| OLD | NEW |