| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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" |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
| 13 #include "base/i18n/rtl.h" | 13 #include "base/i18n/rtl.h" |
| 14 #include "base/metrics/field_trial.h" | 14 #include "base/metrics/field_trial.h" |
| 15 #include "base/metrics/histogram.h" | 15 #include "base/metrics/histogram.h" |
| 16 #include "base/string_number_conversions.h" | 16 #include "base/string_number_conversions.h" |
| 17 #include "base/string_split.h" | 17 #include "base/string_split.h" |
| 18 #include "base/string_util.h" | 18 #include "base/string_util.h" |
| 19 #include "base/utf_string_conversions.h" | 19 #include "base/utf_string_conversions.h" |
| 20 #include "base/values.h" | 20 #include "base/values.h" |
| 21 #include "chrome/browser/extensions/app_notification_manager.h" | 21 #include "chrome/browser/extensions/app_notification_manager.h" |
| 22 #include "chrome/browser/extensions/apps_promo.h" | 22 #include "chrome/browser/extensions/apps_promo.h" |
| 23 #include "chrome/browser/extensions/crx_installer.h" | 23 #include "chrome/browser/extensions/crx_installer.h" |
| 24 #include "chrome/browser/extensions/extension_prefs.h" | 24 #include "chrome/browser/extensions/extension_prefs.h" |
| 25 #include "chrome/browser/extensions/extension_service.h" | 25 #include "chrome/browser/extensions/extension_service.h" |
| 26 #include "chrome/browser/extensions/extension_sorting.h" | 26 #include "chrome/browser/extensions/extension_sorting.h" |
| 27 #include "chrome/browser/prefs/pref_service.h" | 27 #include "chrome/browser/prefs/pref_service.h" |
| 28 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 28 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
| 29 #include "chrome/browser/profiles/profile.h" | 29 #include "chrome/browser/profiles/profile.h" |
| 30 #include "chrome/browser/ui/browser.h" | |
| 31 #include "chrome/browser/ui/browser_finder.h" | 30 #include "chrome/browser/ui/browser_finder.h" |
| 32 #include "chrome/browser/ui/browser_window.h" | 31 #include "chrome/browser/ui/browser_window.h" |
| 32 #include "chrome/browser/ui/extensions/application_launch.h" |
| 33 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" | 33 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" |
| 34 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" | 34 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" |
| 35 #include "chrome/browser/ui/webui/web_ui_util.h" | 35 #include "chrome/browser/ui/webui/web_ui_util.h" |
| 36 #include "chrome/common/chrome_notification_types.h" | 36 #include "chrome/common/chrome_notification_types.h" |
| 37 #include "chrome/common/extensions/extension.h" | 37 #include "chrome/common/extensions/extension.h" |
| 38 #include "chrome/common/extensions/extension_icon_set.h" | 38 #include "chrome/common/extensions/extension_icon_set.h" |
| 39 #include "chrome/common/extensions/extension_resource.h" | 39 #include "chrome/common/extensions/extension_resource.h" |
| 40 #include "chrome/common/favicon_url.h" | 40 #include "chrome/common/favicon_url.h" |
| 41 #include "chrome/common/pref_names.h" | 41 #include "chrome/common/pref_names.h" |
| 42 #include "chrome/common/url_constants.h" | 42 #include "chrome/common/url_constants.h" |
| (...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 537 web_ui_util::GetDispositionFromClick(args, 3) : CURRENT_TAB; | 537 web_ui_util::GetDispositionFromClick(args, 3) : CURRENT_TAB; |
| 538 if (extension_id != extension_misc::kWebStoreAppId) { | 538 if (extension_id != extension_misc::kWebStoreAppId) { |
| 539 RecordAppLaunchByID(launch_bucket); | 539 RecordAppLaunchByID(launch_bucket); |
| 540 extension_service_->apps_promo()->ExpireDefaultApps(); | 540 extension_service_->apps_promo()->ExpireDefaultApps(); |
| 541 } else { | 541 } else { |
| 542 RecordWebStoreLaunch(url.find("chrome-ntp-promo") != std::string::npos); | 542 RecordWebStoreLaunch(url.find("chrome-ntp-promo") != std::string::npos); |
| 543 } | 543 } |
| 544 | 544 |
| 545 if (disposition == NEW_FOREGROUND_TAB || disposition == NEW_BACKGROUND_TAB) { | 545 if (disposition == NEW_FOREGROUND_TAB || disposition == NEW_BACKGROUND_TAB) { |
| 546 // TODO(jamescook): Proper support for background tabs. | 546 // TODO(jamescook): Proper support for background tabs. |
| 547 Browser::OpenApplication( | 547 application_launch::OpenApplication( |
| 548 profile, extension, extension_misc::LAUNCH_TAB, GURL(url), disposition); | 548 profile, extension, extension_misc::LAUNCH_TAB, GURL(url), disposition); |
| 549 } else if (disposition == NEW_WINDOW) { | 549 } else if (disposition == NEW_WINDOW) { |
| 550 // Force a new window open. | 550 // Force a new window open. |
| 551 Browser::OpenApplication( | 551 application_launch::OpenApplication( |
| 552 profile, extension, extension_misc::LAUNCH_WINDOW, GURL(url), | 552 profile, extension, extension_misc::LAUNCH_WINDOW, GURL(url), |
| 553 disposition); | 553 disposition); |
| 554 } else { | 554 } else { |
| 555 // Look at preference to find the right launch container. If no preference | 555 // Look at preference to find the right launch container. If no preference |
| 556 // is set, launch as a regular tab. | 556 // is set, launch as a regular tab. |
| 557 extension_misc::LaunchContainer launch_container = | 557 extension_misc::LaunchContainer launch_container = |
| 558 extension_service_->extension_prefs()->GetLaunchContainer( | 558 extension_service_->extension_prefs()->GetLaunchContainer( |
| 559 extension, ExtensionPrefs::LAUNCH_REGULAR); | 559 extension, ExtensionPrefs::LAUNCH_REGULAR); |
| 560 | 560 |
| 561 // To give a more "launchy" experience when using the NTP launcher, we close | 561 // To give a more "launchy" experience when using the NTP launcher, we close |
| 562 // it automatically. | 562 // it automatically. |
| 563 Browser* browser = browser::FindLastActiveWithProfile(profile); | 563 Browser* browser = browser::FindLastActiveWithProfile(profile); |
| 564 WebContents* old_contents = NULL; | 564 WebContents* old_contents = NULL; |
| 565 if (browser) | 565 if (browser) |
| 566 old_contents = browser->GetSelectedWebContents(); | 566 old_contents = browser->GetSelectedWebContents(); |
| 567 | 567 |
| 568 WebContents* new_contents = Browser::OpenApplication( | 568 WebContents* new_contents = application_launch::OpenApplication( |
| 569 profile, extension, launch_container, GURL(url), | 569 profile, extension, launch_container, GURL(url), |
| 570 old_contents ? CURRENT_TAB : NEW_FOREGROUND_TAB); | 570 old_contents ? CURRENT_TAB : NEW_FOREGROUND_TAB); |
| 571 | 571 |
| 572 // This will also destroy the handler, so do not perform any actions after. | 572 // This will also destroy the handler, so do not perform any actions after. |
| 573 if (new_contents != old_contents && browser && browser->tab_count() > 1) | 573 if (new_contents != old_contents && browser && browser->tab_count() > 1) |
| 574 browser->CloseTabContents(old_contents); | 574 browser->CloseTabContents(old_contents); |
| 575 } | 575 } |
| 576 } | 576 } |
| 577 | 577 |
| 578 void AppLauncherHandler::HandleSetLaunchType(const ListValue* args) { | 578 void AppLauncherHandler::HandleSetLaunchType(const ListValue* args) { |
| (...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 984 | 984 |
| 985 void AppLauncherHandler::UninstallDefaultApps() { | 985 void AppLauncherHandler::UninstallDefaultApps() { |
| 986 AppsPromo* apps_promo = extension_service_->apps_promo(); | 986 AppsPromo* apps_promo = extension_service_->apps_promo(); |
| 987 const extensions::ExtensionIdSet& app_ids = apps_promo->old_default_apps(); | 987 const extensions::ExtensionIdSet& app_ids = apps_promo->old_default_apps(); |
| 988 for (extensions::ExtensionIdSet::const_iterator iter = app_ids.begin(); | 988 for (extensions::ExtensionIdSet::const_iterator iter = app_ids.begin(); |
| 989 iter != app_ids.end(); ++iter) { | 989 iter != app_ids.end(); ++iter) { |
| 990 if (extension_service_->GetExtensionById(*iter, true)) | 990 if (extension_service_->GetExtensionById(*iter, true)) |
| 991 extension_service_->UninstallExtension(*iter, false, NULL); | 991 extension_service_->UninstallExtension(*iter, false, NULL); |
| 992 } | 992 } |
| 993 } | 993 } |
| OLD | NEW |