| 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 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 } | 144 } |
| 145 value->SetInteger("app_launch_index", app_launch_index); | 145 value->SetInteger("app_launch_index", app_launch_index); |
| 146 | 146 |
| 147 int page_index = prefs->GetPageIndex(extension->id()); | 147 int page_index = prefs->GetPageIndex(extension->id()); |
| 148 if (page_index >= 0) { | 148 if (page_index >= 0) { |
| 149 // Only provide a value if one is stored | 149 // Only provide a value if one is stored |
| 150 value->SetInteger("page_index", page_index); | 150 value->SetInteger("page_index", page_index); |
| 151 } | 151 } |
| 152 } | 152 } |
| 153 | 153 |
| 154 // TODO(estade): remove this. We record app launches via js calls rather than |
| 155 // pings for ntp4. |
| 154 // static | 156 // static |
| 155 bool AppLauncherHandler::HandlePing(Profile* profile, const std::string& path) { | 157 bool AppLauncherHandler::HandlePing(Profile* profile, const std::string& path) { |
| 156 std::vector<std::string> params; | 158 std::vector<std::string> params; |
| 157 base::SplitString(path, '+', ¶ms); | 159 base::SplitString(path, '+', ¶ms); |
| 158 | 160 |
| 159 // Check if the user launched an app from the most visited or recently | 161 // Check if the user launched an app from the most visited or recently |
| 160 // closed sections. | 162 // closed sections. |
| 161 if (kPingLaunchAppByURL == params.at(0)) { | 163 if (kPingLaunchAppByURL == params.at(0)) { |
| 162 CHECK(params.size() == 3); | 164 CHECK(params.size() == 3); |
| 163 RecordAppLaunchByURL( | 165 RecordAppLaunchByURL( |
| (...skipping 22 matching lines...) Expand all Loading... |
| 186 RecordWebStoreLaunch(is_promo_active); | 188 RecordWebStoreLaunch(is_promo_active); |
| 187 } else { | 189 } else { |
| 188 CHECK(params.size() == 3); | 190 CHECK(params.size() == 3); |
| 189 RecordAppLaunchByID(is_promo_active, ParseLaunchSource(params.at(2))); | 191 RecordAppLaunchByID(is_promo_active, ParseLaunchSource(params.at(2))); |
| 190 } | 192 } |
| 191 | 193 |
| 192 return true; | 194 return true; |
| 193 } | 195 } |
| 194 | 196 |
| 195 WebUIMessageHandler* AppLauncherHandler::Attach(WebUI* web_ui) { | 197 WebUIMessageHandler* AppLauncherHandler::Attach(WebUI* web_ui) { |
| 196 // TODO(arv): Add initialization code to the Apps store etc. | |
| 197 return WebUIMessageHandler::Attach(web_ui); | 198 return WebUIMessageHandler::Attach(web_ui); |
| 198 } | 199 } |
| 199 | 200 |
| 200 void AppLauncherHandler::RegisterMessages() { | 201 void AppLauncherHandler::RegisterMessages() { |
| 201 web_ui_->RegisterMessageCallback("getApps", | 202 web_ui_->RegisterMessageCallback("getApps", |
| 202 NewCallback(this, &AppLauncherHandler::HandleGetApps)); | 203 NewCallback(this, &AppLauncherHandler::HandleGetApps)); |
| 203 web_ui_->RegisterMessageCallback("launchApp", | 204 web_ui_->RegisterMessageCallback("launchApp", |
| 204 NewCallback(this, &AppLauncherHandler::HandleLaunchApp)); | 205 NewCallback(this, &AppLauncherHandler::HandleLaunchApp)); |
| 205 web_ui_->RegisterMessageCallback("setLaunchType", | 206 web_ui_->RegisterMessageCallback("setLaunchType", |
| 206 NewCallback(this, &AppLauncherHandler::HandleSetLaunchType)); | 207 NewCallback(this, &AppLauncherHandler::HandleSetLaunchType)); |
| 207 web_ui_->RegisterMessageCallback("uninstallApp", | 208 web_ui_->RegisterMessageCallback("uninstallApp", |
| 208 NewCallback(this, &AppLauncherHandler::HandleUninstallApp)); | 209 NewCallback(this, &AppLauncherHandler::HandleUninstallApp)); |
| 209 web_ui_->RegisterMessageCallback("hideAppsPromo", | 210 web_ui_->RegisterMessageCallback("hideAppsPromo", |
| 210 NewCallback(this, &AppLauncherHandler::HandleHideAppsPromo)); | 211 NewCallback(this, &AppLauncherHandler::HandleHideAppsPromo)); |
| 211 web_ui_->RegisterMessageCallback("createAppShortcut", | 212 web_ui_->RegisterMessageCallback("createAppShortcut", |
| 212 NewCallback(this, &AppLauncherHandler::HandleCreateAppShortcut)); | 213 NewCallback(this, &AppLauncherHandler::HandleCreateAppShortcut)); |
| 213 web_ui_->RegisterMessageCallback("reorderApps", | 214 web_ui_->RegisterMessageCallback("reorderApps", |
| 214 NewCallback(this, &AppLauncherHandler::HandleReorderApps)); | 215 NewCallback(this, &AppLauncherHandler::HandleReorderApps)); |
| 215 web_ui_->RegisterMessageCallback("setPageIndex", | 216 web_ui_->RegisterMessageCallback("setPageIndex", |
| 216 NewCallback(this, &AppLauncherHandler::HandleSetPageIndex)); | 217 NewCallback(this, &AppLauncherHandler::HandleSetPageIndex)); |
| 217 web_ui_->RegisterMessageCallback("promoSeen", | 218 web_ui_->RegisterMessageCallback("promoSeen", |
| 218 NewCallback(this, &AppLauncherHandler::HandlePromoSeen)); | 219 NewCallback(this, &AppLauncherHandler::HandlePromoSeen)); |
| 219 web_ui_->RegisterMessageCallback("saveAppPageName", | 220 web_ui_->RegisterMessageCallback("saveAppPageName", |
| 220 NewCallback(this, &AppLauncherHandler::HandleSaveAppPageName)); | 221 NewCallback(this, &AppLauncherHandler::HandleSaveAppPageName)); |
| 221 web_ui_->RegisterMessageCallback("generateAppForLink", | 222 web_ui_->RegisterMessageCallback("generateAppForLink", |
| 222 NewCallback(this, &AppLauncherHandler::HandleGenerateAppForLink)); | 223 NewCallback(this, &AppLauncherHandler::HandleGenerateAppForLink)); |
| 224 web_ui_->RegisterMessageCallback("recordAppLaunchByURL", |
| 225 NewCallback(this, &AppLauncherHandler::HandleRecordAppLaunchByURL)); |
| 223 } | 226 } |
| 224 | 227 |
| 225 void AppLauncherHandler::Observe(int type, | 228 void AppLauncherHandler::Observe(int type, |
| 226 const NotificationSource& source, | 229 const NotificationSource& source, |
| 227 const NotificationDetails& details) { | 230 const NotificationDetails& details) { |
| 228 if (ignore_changes_) | 231 if (ignore_changes_) |
| 229 return; | 232 return; |
| 230 | 233 |
| 231 switch (type) { | 234 switch (type) { |
| 232 case chrome::NOTIFICATION_APP_NOTIFICATION_STATE_CHANGED: { | 235 case chrome::NOTIFICATION_APP_NOTIFICATION_STATE_CHANGED: { |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 477 // If the user pressed special keys when clicking, override the saved | 480 // If the user pressed special keys when clicking, override the saved |
| 478 // preference for launch container. | 481 // preference for launch container. |
| 479 bool middle_button = (button == 1.0); | 482 bool middle_button = (button == 1.0); |
| 480 WindowOpenDisposition disposition = | 483 WindowOpenDisposition disposition = |
| 481 disposition_utils::DispositionFromClick(middle_button, alt_key, | 484 disposition_utils::DispositionFromClick(middle_button, alt_key, |
| 482 ctrl_key, meta_key, shift_key); | 485 ctrl_key, meta_key, shift_key); |
| 483 | 486 |
| 484 if (extension_id != extension_misc::kWebStoreAppId) { | 487 if (extension_id != extension_misc::kWebStoreAppId) { |
| 485 RecordAppLaunchByID(promo_active_, launch_bucket); | 488 RecordAppLaunchByID(promo_active_, launch_bucket); |
| 486 extensions_service_->apps_promo()->ExpireDefaultApps(); | 489 extensions_service_->apps_promo()->ExpireDefaultApps(); |
| 490 } else if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 491 switches::kNewTabPage4)) { |
| 492 RecordWebStoreLaunch(promo_active_); |
| 487 } | 493 } |
| 488 | 494 |
| 489 if (disposition == NEW_FOREGROUND_TAB || disposition == NEW_BACKGROUND_TAB) { | 495 if (disposition == NEW_FOREGROUND_TAB || disposition == NEW_BACKGROUND_TAB) { |
| 490 // TODO(jamescook): Proper support for background tabs. | 496 // TODO(jamescook): Proper support for background tabs. |
| 491 Browser::OpenApplication( | 497 Browser::OpenApplication( |
| 492 profile, extension, extension_misc::LAUNCH_TAB, disposition); | 498 profile, extension, extension_misc::LAUNCH_TAB, disposition); |
| 493 } else if (disposition == NEW_WINDOW) { | 499 } else if (disposition == NEW_WINDOW) { |
| 494 // Force a new window open. | 500 // Force a new window open. |
| 495 Browser::OpenApplication( | 501 Browser::OpenApplication( |
| 496 profile, extension, extension_misc::LAUNCH_WINDOW, disposition); | 502 profile, extension, extension_misc::LAUNCH_WINDOW, disposition); |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 686 return; | 692 return; |
| 687 } | 693 } |
| 688 | 694 |
| 689 // TODO(gbillock): get page thumb from thumbnail db/history svc? | 695 // TODO(gbillock): get page thumb from thumbnail db/history svc? |
| 690 FaviconService::Handle h = favicon_service->GetFaviconForURL( | 696 FaviconService::Handle h = favicon_service->GetFaviconForURL( |
| 691 launch_url, history::FAVICON, &favicon_consumer_, | 697 launch_url, history::FAVICON, &favicon_consumer_, |
| 692 NewCallback(this, &AppLauncherHandler::OnFaviconForApp)); | 698 NewCallback(this, &AppLauncherHandler::OnFaviconForApp)); |
| 693 favicon_consumer_.SetClientData(favicon_service, h, web_app.release()); | 699 favicon_consumer_.SetClientData(favicon_service, h, web_app.release()); |
| 694 } | 700 } |
| 695 | 701 |
| 702 void AppLauncherHandler::HandleRecordAppLaunchByURL( |
| 703 const base::ListValue* args) { |
| 704 std::string url; |
| 705 CHECK(args->GetString(0, &url)); |
| 706 double source; |
| 707 CHECK(args->GetDouble(1, &source)); |
| 708 |
| 709 extension_misc::AppLaunchBucket bucket = |
| 710 static_cast<extension_misc::AppLaunchBucket>(source); |
| 711 CHECK(source < extension_misc::APP_LAUNCH_BUCKET_BOUNDARY); |
| 712 |
| 713 RecordAppLaunchByURL(web_ui_->GetProfile(), url, bucket); |
| 714 } |
| 715 |
| 696 void AppLauncherHandler::OnFaviconForApp(FaviconService::Handle handle, | 716 void AppLauncherHandler::OnFaviconForApp(FaviconService::Handle handle, |
| 697 history::FaviconData data) { | 717 history::FaviconData data) { |
| 698 scoped_ptr<WebApplicationInfo> web_app( | 718 scoped_ptr<WebApplicationInfo> web_app( |
| 699 favicon_consumer_.GetClientDataForCurrentRequest()); | 719 favicon_consumer_.GetClientDataForCurrentRequest()); |
| 700 CHECK(!web_app->icons.empty()); | 720 CHECK(!web_app->icons.empty()); |
| 701 if (data.is_valid() && gfx::PNGCodec::Decode(data.image_data->front(), | 721 if (data.is_valid() && gfx::PNGCodec::Decode(data.image_data->front(), |
| 702 data.image_data->size(), | 722 data.image_data->size(), |
| 703 &(web_app->icons[0].data))) { | 723 &(web_app->icons[0].data))) { |
| 704 web_app->icons[0].url = GURL(); | 724 web_app->icons[0].url = GURL(); |
| 705 web_app->icons[0].width = web_app->icons[0].data.width(); | 725 web_app->icons[0].width = web_app->icons[0].data.width(); |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 861 | 881 |
| 862 void AppLauncherHandler::UninstallDefaultApps() { | 882 void AppLauncherHandler::UninstallDefaultApps() { |
| 863 AppsPromo* apps_promo = extensions_service_->apps_promo(); | 883 AppsPromo* apps_promo = extensions_service_->apps_promo(); |
| 864 const ExtensionIdSet& app_ids = apps_promo->old_default_apps(); | 884 const ExtensionIdSet& app_ids = apps_promo->old_default_apps(); |
| 865 for (ExtensionIdSet::const_iterator iter = app_ids.begin(); | 885 for (ExtensionIdSet::const_iterator iter = app_ids.begin(); |
| 866 iter != app_ids.end(); ++iter) { | 886 iter != app_ids.end(); ++iter) { |
| 867 if (extensions_service_->GetExtensionById(*iter, true)) | 887 if (extensions_service_->GetExtensionById(*iter, true)) |
| 868 extensions_service_->UninstallExtension(*iter, false, NULL); | 888 extensions_service_->UninstallExtension(*iter, false, NULL); |
| 869 } | 889 } |
| 870 } | 890 } |
| OLD | NEW |