| 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" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 #include "content/public/browser/notification_service.h" | 46 #include "content/public/browser/notification_service.h" |
| 47 #include "content/public/browser/web_ui.h" | 47 #include "content/public/browser/web_ui.h" |
| 48 #include "googleurl/src/gurl.h" | 48 #include "googleurl/src/gurl.h" |
| 49 #include "grit/browser_resources.h" | 49 #include "grit/browser_resources.h" |
| 50 #include "grit/generated_resources.h" | 50 #include "grit/generated_resources.h" |
| 51 #include "net/base/escape.h" | 51 #include "net/base/escape.h" |
| 52 #include "ui/base/animation/animation.h" | 52 #include "ui/base/animation/animation.h" |
| 53 #include "ui/base/l10n/l10n_util.h" | 53 #include "ui/base/l10n/l10n_util.h" |
| 54 #include "ui/gfx/codec/png_codec.h" | 54 #include "ui/gfx/codec/png_codec.h" |
| 55 | 55 |
| 56 using application_launch::LaunchParams; |
| 57 using application_launch::OpenApplication; |
| 56 using content::WebContents; | 58 using content::WebContents; |
| 57 using extensions::Extension; | 59 using extensions::Extension; |
| 58 | 60 |
| 59 namespace { | 61 namespace { |
| 60 | 62 |
| 61 const net::UnescapeRule::Type kUnescapeRules = | 63 const net::UnescapeRule::Type kUnescapeRules = |
| 62 net::UnescapeRule::NORMAL | net::UnescapeRule::URL_SPECIAL_CHARS; | 64 net::UnescapeRule::NORMAL | net::UnescapeRule::URL_SPECIAL_CHARS; |
| 63 | 65 |
| 64 extension_misc::AppLaunchBucket ParseLaunchSource( | 66 extension_misc::AppLaunchBucket ParseLaunchSource( |
| 65 const std::string& launch_source) { | 67 const std::string& launch_source) { |
| (...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 526 | 528 |
| 527 WindowOpenDisposition disposition = args->GetSize() > 3 ? | 529 WindowOpenDisposition disposition = args->GetSize() > 3 ? |
| 528 web_ui_util::GetDispositionFromClick(args, 3) : CURRENT_TAB; | 530 web_ui_util::GetDispositionFromClick(args, 3) : CURRENT_TAB; |
| 529 if (extension_id != extension_misc::kWebStoreAppId) { | 531 if (extension_id != extension_misc::kWebStoreAppId) { |
| 530 RecordAppLaunchByID(launch_bucket); | 532 RecordAppLaunchByID(launch_bucket); |
| 531 extension_service_->apps_promo()->ExpireDefaultApps(); | 533 extension_service_->apps_promo()->ExpireDefaultApps(); |
| 532 } else { | 534 } else { |
| 533 RecordWebStoreLaunch(url.find("chrome-ntp-promo") != std::string::npos); | 535 RecordWebStoreLaunch(url.find("chrome-ntp-promo") != std::string::npos); |
| 534 } | 536 } |
| 535 | 537 |
| 536 if (disposition == NEW_FOREGROUND_TAB || disposition == NEW_BACKGROUND_TAB) { | 538 if (disposition == NEW_FOREGROUND_TAB || disposition == NEW_BACKGROUND_TAB || |
| 539 disposition == NEW_WINDOW) { |
| 537 // TODO(jamescook): Proper support for background tabs. | 540 // TODO(jamescook): Proper support for background tabs. |
| 538 application_launch::OpenApplication( | 541 LaunchParams params(profile, extension, |
| 539 profile, extension, extension_misc::LAUNCH_TAB, GURL(url), disposition, | 542 disposition == NEW_WINDOW ? |
| 540 NULL); | 543 extension_misc::LAUNCH_WINDOW : |
| 541 } else if (disposition == NEW_WINDOW) { | 544 extension_misc::LAUNCH_TAB, |
| 542 // Force a new window open. | 545 disposition); |
| 543 application_launch::OpenApplication( | 546 params.override_url = GURL(url); |
| 544 profile, extension, extension_misc::LAUNCH_WINDOW, GURL(url), | 547 OpenApplication(params); |
| 545 disposition, NULL); | |
| 546 } else { | 548 } else { |
| 547 // Look at preference to find the right launch container. If no preference | 549 // Look at preference to find the right launch container. If no preference |
| 548 // is set, launch as a regular tab. | 550 // is set, launch as a regular tab. |
| 549 extension_misc::LaunchContainer launch_container = | 551 extension_misc::LaunchContainer launch_container = |
| 550 extension_service_->extension_prefs()->GetLaunchContainer( | 552 extension_service_->extension_prefs()->GetLaunchContainer( |
| 551 extension, ExtensionPrefs::LAUNCH_REGULAR); | 553 extension, ExtensionPrefs::LAUNCH_REGULAR); |
| 552 | 554 |
| 553 // To give a more "launchy" experience when using the NTP launcher, we close | 555 // To give a more "launchy" experience when using the NTP launcher, we close |
| 554 // it automatically. | 556 // it automatically. |
| 555 Browser* browser = browser::FindBrowserWithWebContents( | 557 Browser* browser = browser::FindBrowserWithWebContents( |
| 556 web_ui()->GetWebContents()); | 558 web_ui()->GetWebContents()); |
| 557 WebContents* old_contents = NULL; | 559 WebContents* old_contents = NULL; |
| 558 if (browser) | 560 if (browser) |
| 559 old_contents = chrome::GetActiveWebContents(browser); | 561 old_contents = chrome::GetActiveWebContents(browser); |
| 560 | 562 |
| 561 WebContents* new_contents = application_launch::OpenApplication( | 563 LaunchParams params(profile, extension, launch_container, |
| 562 profile, extension, launch_container, GURL(url), | 564 old_contents ? CURRENT_TAB : NEW_FOREGROUND_TAB); |
| 563 old_contents ? CURRENT_TAB : NEW_FOREGROUND_TAB, NULL); | 565 params.override_url = GURL(url); |
| 566 WebContents* new_contents = OpenApplication(params); |
| 564 | 567 |
| 565 // This will also destroy the handler, so do not perform any actions after. | 568 // This will also destroy the handler, so do not perform any actions after. |
| 566 if (new_contents != old_contents && browser && browser->tab_count() > 1) | 569 if (new_contents != old_contents && browser && browser->tab_count() > 1) |
| 567 chrome::CloseWebContents(browser, old_contents); | 570 chrome::CloseWebContents(browser, old_contents); |
| 568 } | 571 } |
| 569 } | 572 } |
| 570 | 573 |
| 571 void AppLauncherHandler::HandleSetLaunchType(const ListValue* args) { | 574 void AppLauncherHandler::HandleSetLaunchType(const ListValue* args) { |
| 572 std::string extension_id; | 575 std::string extension_id; |
| 573 double launch_type; | 576 double launch_type; |
| (...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 981 | 984 |
| 982 void AppLauncherHandler::UninstallDefaultApps() { | 985 void AppLauncherHandler::UninstallDefaultApps() { |
| 983 AppsPromo* apps_promo = extension_service_->apps_promo(); | 986 AppsPromo* apps_promo = extension_service_->apps_promo(); |
| 984 const extensions::ExtensionIdSet& app_ids = apps_promo->old_default_apps(); | 987 const extensions::ExtensionIdSet& app_ids = apps_promo->old_default_apps(); |
| 985 for (extensions::ExtensionIdSet::const_iterator iter = app_ids.begin(); | 988 for (extensions::ExtensionIdSet::const_iterator iter = app_ids.begin(); |
| 986 iter != app_ids.end(); ++iter) { | 989 iter != app_ids.end(); ++iter) { |
| 987 if (extension_service_->GetExtensionById(*iter, true)) | 990 if (extension_service_->GetExtensionById(*iter, true)) |
| 988 extension_service_->UninstallExtension(*iter, false, NULL); | 991 extension_service_->UninstallExtension(*iter, false, NULL); |
| 989 } | 992 } |
| 990 } | 993 } |
| OLD | NEW |