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 20 matching lines...) Expand all Loading... | |
184 | 186 |
185 if (is_web_store_ping) { | 187 if (is_web_store_ping) { |
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 |
Rick Byers
2011/08/03 14:41:11
Remove extra blank line
Evan Stade
2011/08/03 22:11:22
Done.
| |
197 | |
195 WebUIMessageHandler* AppLauncherHandler::Attach(WebUI* web_ui) { | 198 WebUIMessageHandler* AppLauncherHandler::Attach(WebUI* web_ui) { |
196 // TODO(arv): Add initialization code to the Apps store etc. | 199 // TODO(arv): Add initialization code to the Apps store etc. |
197 return WebUIMessageHandler::Attach(web_ui); | 200 return WebUIMessageHandler::Attach(web_ui); |
198 } | 201 } |
199 | 202 |
200 void AppLauncherHandler::RegisterMessages() { | 203 void AppLauncherHandler::RegisterMessages() { |
201 web_ui_->RegisterMessageCallback("getApps", | 204 web_ui_->RegisterMessageCallback("getApps", |
202 NewCallback(this, &AppLauncherHandler::HandleGetApps)); | 205 NewCallback(this, &AppLauncherHandler::HandleGetApps)); |
203 web_ui_->RegisterMessageCallback("launchApp", | 206 web_ui_->RegisterMessageCallback("launchApp", |
204 NewCallback(this, &AppLauncherHandler::HandleLaunchApp)); | 207 NewCallback(this, &AppLauncherHandler::HandleLaunchApp)); |
205 web_ui_->RegisterMessageCallback("setLaunchType", | 208 web_ui_->RegisterMessageCallback("setLaunchType", |
206 NewCallback(this, &AppLauncherHandler::HandleSetLaunchType)); | 209 NewCallback(this, &AppLauncherHandler::HandleSetLaunchType)); |
207 web_ui_->RegisterMessageCallback("uninstallApp", | 210 web_ui_->RegisterMessageCallback("uninstallApp", |
208 NewCallback(this, &AppLauncherHandler::HandleUninstallApp)); | 211 NewCallback(this, &AppLauncherHandler::HandleUninstallApp)); |
209 web_ui_->RegisterMessageCallback("hideAppsPromo", | 212 web_ui_->RegisterMessageCallback("hideAppsPromo", |
210 NewCallback(this, &AppLauncherHandler::HandleHideAppsPromo)); | 213 NewCallback(this, &AppLauncherHandler::HandleHideAppsPromo)); |
211 web_ui_->RegisterMessageCallback("createAppShortcut", | 214 web_ui_->RegisterMessageCallback("createAppShortcut", |
212 NewCallback(this, &AppLauncherHandler::HandleCreateAppShortcut)); | 215 NewCallback(this, &AppLauncherHandler::HandleCreateAppShortcut)); |
213 web_ui_->RegisterMessageCallback("reorderApps", | 216 web_ui_->RegisterMessageCallback("reorderApps", |
214 NewCallback(this, &AppLauncherHandler::HandleReorderApps)); | 217 NewCallback(this, &AppLauncherHandler::HandleReorderApps)); |
215 web_ui_->RegisterMessageCallback("setPageIndex", | 218 web_ui_->RegisterMessageCallback("setPageIndex", |
216 NewCallback(this, &AppLauncherHandler::HandleSetPageIndex)); | 219 NewCallback(this, &AppLauncherHandler::HandleSetPageIndex)); |
217 web_ui_->RegisterMessageCallback("promoSeen", | 220 web_ui_->RegisterMessageCallback("promoSeen", |
218 NewCallback(this, &AppLauncherHandler::HandlePromoSeen)); | 221 NewCallback(this, &AppLauncherHandler::HandlePromoSeen)); |
219 web_ui_->RegisterMessageCallback("saveAppPageName", | 222 web_ui_->RegisterMessageCallback("saveAppPageName", |
220 NewCallback(this, &AppLauncherHandler::HandleSaveAppPageName)); | 223 NewCallback(this, &AppLauncherHandler::HandleSaveAppPageName)); |
221 web_ui_->RegisterMessageCallback("generateAppForLink", | 224 web_ui_->RegisterMessageCallback("generateAppForLink", |
222 NewCallback(this, &AppLauncherHandler::HandleGenerateAppForLink)); | 225 NewCallback(this, &AppLauncherHandler::HandleGenerateAppForLink)); |
226 web_ui_->RegisterMessageCallback("recordAppLaunchByURL", | |
227 NewCallback(this, &AppLauncherHandler::HandleRecordAppLaunchByURL)); | |
223 } | 228 } |
224 | 229 |
225 void AppLauncherHandler::Observe(int type, | 230 void AppLauncherHandler::Observe(int type, |
226 const NotificationSource& source, | 231 const NotificationSource& source, |
227 const NotificationDetails& details) { | 232 const NotificationDetails& details) { |
228 if (ignore_changes_) | 233 if (ignore_changes_) |
229 return; | 234 return; |
230 | 235 |
231 switch (type) { | 236 switch (type) { |
232 case chrome::NOTIFICATION_APP_NOTIFICATION_STATE_CHANGED: { | 237 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 | 482 // If the user pressed special keys when clicking, override the saved |
478 // preference for launch container. | 483 // preference for launch container. |
479 bool middle_button = (button == 1.0); | 484 bool middle_button = (button == 1.0); |
480 WindowOpenDisposition disposition = | 485 WindowOpenDisposition disposition = |
481 disposition_utils::DispositionFromClick(middle_button, alt_key, | 486 disposition_utils::DispositionFromClick(middle_button, alt_key, |
482 ctrl_key, meta_key, shift_key); | 487 ctrl_key, meta_key, shift_key); |
483 | 488 |
484 if (extension_id != extension_misc::kWebStoreAppId) { | 489 if (extension_id != extension_misc::kWebStoreAppId) { |
485 RecordAppLaunchByID(promo_active_, launch_bucket); | 490 RecordAppLaunchByID(promo_active_, launch_bucket); |
486 extensions_service_->apps_promo()->ExpireDefaultApps(); | 491 extensions_service_->apps_promo()->ExpireDefaultApps(); |
492 } else if (CommandLine::ForCurrentProcess()->HasSwitch( | |
493 switches::kNewTabPage4)) { | |
494 RecordWebStoreLaunch(promo_active_); | |
487 } | 495 } |
488 | 496 |
489 if (disposition == NEW_FOREGROUND_TAB || disposition == NEW_BACKGROUND_TAB) { | 497 if (disposition == NEW_FOREGROUND_TAB || disposition == NEW_BACKGROUND_TAB) { |
490 // TODO(jamescook): Proper support for background tabs. | 498 // TODO(jamescook): Proper support for background tabs. |
491 Browser::OpenApplication( | 499 Browser::OpenApplication( |
492 profile, extension, extension_misc::LAUNCH_TAB, disposition); | 500 profile, extension, extension_misc::LAUNCH_TAB, disposition); |
493 } else if (disposition == NEW_WINDOW) { | 501 } else if (disposition == NEW_WINDOW) { |
494 // Force a new window open. | 502 // Force a new window open. |
495 Browser::OpenApplication( | 503 Browser::OpenApplication( |
496 profile, extension, extension_misc::LAUNCH_WINDOW, disposition); | 504 profile, extension, extension_misc::LAUNCH_WINDOW, disposition); |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
686 return; | 694 return; |
687 } | 695 } |
688 | 696 |
689 // TODO(gbillock): get page thumb from thumbnail db/history svc? | 697 // TODO(gbillock): get page thumb from thumbnail db/history svc? |
690 FaviconService::Handle h = favicon_service->GetFaviconForURL( | 698 FaviconService::Handle h = favicon_service->GetFaviconForURL( |
691 launch_url, history::FAVICON, &favicon_consumer_, | 699 launch_url, history::FAVICON, &favicon_consumer_, |
692 NewCallback(this, &AppLauncherHandler::OnFaviconForApp)); | 700 NewCallback(this, &AppLauncherHandler::OnFaviconForApp)); |
693 favicon_consumer_.SetClientData(favicon_service, h, web_app.release()); | 701 favicon_consumer_.SetClientData(favicon_service, h, web_app.release()); |
694 } | 702 } |
695 | 703 |
704 void AppLauncherHandler::HandleRecordAppLaunchByURL( | |
705 const base::ListValue* args) { | |
706 std::string url; | |
707 CHECK(args->GetString(0, &url)); | |
708 std::string source; | |
709 CHECK(args->GetString(1, &source)); | |
Rick Byers
2011/08/03 14:41:11
Curious why you're taking a string argument here a
Evan Stade
2011/08/03 22:11:22
Done.
| |
710 | |
711 RecordAppLaunchByURL( | |
712 web_ui_->GetProfile(), url, ParseLaunchSource(source)); | |
713 } | |
714 | |
696 void AppLauncherHandler::OnFaviconForApp(FaviconService::Handle handle, | 715 void AppLauncherHandler::OnFaviconForApp(FaviconService::Handle handle, |
697 history::FaviconData data) { | 716 history::FaviconData data) { |
698 scoped_ptr<WebApplicationInfo> web_app( | 717 scoped_ptr<WebApplicationInfo> web_app( |
699 favicon_consumer_.GetClientDataForCurrentRequest()); | 718 favicon_consumer_.GetClientDataForCurrentRequest()); |
700 CHECK(!web_app->icons.empty()); | 719 CHECK(!web_app->icons.empty()); |
701 if (data.is_valid() && gfx::PNGCodec::Decode(data.image_data->front(), | 720 if (data.is_valid() && gfx::PNGCodec::Decode(data.image_data->front(), |
702 data.image_data->size(), | 721 data.image_data->size(), |
703 &(web_app->icons[0].data))) { | 722 &(web_app->icons[0].data))) { |
704 web_app->icons[0].url = GURL(); | 723 web_app->icons[0].url = GURL(); |
705 web_app->icons[0].width = web_app->icons[0].data.width(); | 724 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 | 880 |
862 void AppLauncherHandler::UninstallDefaultApps() { | 881 void AppLauncherHandler::UninstallDefaultApps() { |
863 AppsPromo* apps_promo = extensions_service_->apps_promo(); | 882 AppsPromo* apps_promo = extensions_service_->apps_promo(); |
864 const ExtensionIdSet& app_ids = apps_promo->old_default_apps(); | 883 const ExtensionIdSet& app_ids = apps_promo->old_default_apps(); |
865 for (ExtensionIdSet::const_iterator iter = app_ids.begin(); | 884 for (ExtensionIdSet::const_iterator iter = app_ids.begin(); |
866 iter != app_ids.end(); ++iter) { | 885 iter != app_ids.end(); ++iter) { |
867 if (extensions_service_->GetExtensionById(*iter, true)) | 886 if (extensions_service_->GetExtensionById(*iter, true)) |
868 extensions_service_->UninstallExtension(*iter, false, NULL); | 887 extensions_service_->UninstallExtension(*iter, false, NULL); |
869 } | 888 } |
870 } | 889 } |
OLD | NEW |