| Index: chrome/browser/ui/extensions/application_launch_web_app.cc
|
| diff --git a/chrome/browser/ui/extensions/application_launch_web_app.cc b/chrome/browser/ui/extensions/application_launch_web_app.cc
|
| index 74ce425b27a4c7a6b53dae6f9dbbeb69348873bd..1f8fa3a21022d7ffc95babbd3f62c24c5565db5c 100644
|
| --- a/chrome/browser/ui/extensions/application_launch_web_app.cc
|
| +++ b/chrome/browser/ui/extensions/application_launch_web_app.cc
|
| @@ -2,45 +2,30 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -#include "chrome/browser/ui/extensions/application_launch.h"
|
| +#include "chrome/browser/ui/extensions/application_launch_web_app.h"
|
|
|
| #include <string>
|
|
|
| #include "apps/launcher.h"
|
| -#include "base/command_line.h"
|
| #include "base/metrics/histogram.h"
|
| -#include "base/strings/utf_string_conversions.h"
|
| #include "chrome/browser/app_mode/app_mode_utils.h"
|
| -#include "chrome/browser/apps/per_app_settings_service.h"
|
| -#include "chrome/browser/apps/per_app_settings_service_factory.h"
|
| -#include "chrome/browser/extensions/extension_service.h"
|
| #include "chrome/browser/extensions/launch_util.h"
|
| -#include "chrome/browser/extensions/tab_helper.h"
|
| #include "chrome/browser/profiles/profile.h"
|
| -#include "chrome/browser/ui/app_list/app_list_service.h"
|
| #include "chrome/browser/ui/browser.h"
|
| #include "chrome/browser/ui/browser_commands.h"
|
| #include "chrome/browser/ui/browser_finder.h"
|
| #include "chrome/browser/ui/browser_tabstrip.h"
|
| #include "chrome/browser/ui/browser_window.h"
|
| -#include "chrome/browser/ui/extensions/extension_enable_flow.h"
|
| -#include "chrome/browser/ui/extensions/extension_enable_flow_delegate.h"
|
| +#include "chrome/browser/ui/extensions/app_launch_params.h"
|
| #include "chrome/browser/ui/tabs/tab_strip_model.h"
|
| #include "chrome/browser/web_applications/web_app.h"
|
| -#include "chrome/common/chrome_switches.h"
|
| #include "chrome/common/extensions/manifest_handlers/app_launch_info.h"
|
| -#include "chrome/common/url_constants.h"
|
| #include "content/public/browser/render_view_host.h"
|
| #include "content/public/browser/web_contents.h"
|
| #include "content/public/common/renderer_preferences.h"
|
| #include "extensions/browser/extension_prefs.h"
|
| #include "extensions/browser/extension_registry.h"
|
| -#include "extensions/browser/extension_system.h"
|
| -#include "extensions/common/constants.h"
|
| #include "extensions/common/extension.h"
|
| -#include "extensions/common/features/feature.h"
|
| -#include "extensions/common/features/feature_provider.h"
|
| -#include "extensions/common/manifest_handlers/options_page_info.h"
|
| #include "ui/base/window_open_disposition.h"
|
| #include "ui/gfx/rect.h"
|
|
|
| @@ -55,64 +40,6 @@ using extensions::ExtensionRegistry;
|
|
|
| namespace {
|
|
|
| -// Attempts to launch a packaged app, prompting the user to enable it if
|
| -// necessary. If a prompt is required it will be shown inside the AppList.
|
| -// This class manages its own lifetime.
|
| -class EnableViaAppListFlow : public ExtensionEnableFlowDelegate {
|
| - public:
|
| - EnableViaAppListFlow(ExtensionService* service,
|
| - Profile* profile,
|
| - chrome::HostDesktopType desktop_type,
|
| - const std::string& extension_id,
|
| - const base::Closure& callback)
|
| - : service_(service),
|
| - profile_(profile),
|
| - desktop_type_(desktop_type),
|
| - extension_id_(extension_id),
|
| - callback_(callback) {
|
| - }
|
| -
|
| - virtual ~EnableViaAppListFlow() {
|
| - }
|
| -
|
| - void Run() {
|
| - DCHECK(!service_->IsExtensionEnabled(extension_id_));
|
| - flow_.reset(new ExtensionEnableFlow(profile_, extension_id_, this));
|
| - flow_->StartForCurrentlyNonexistentWindow(
|
| - base::Bind(&EnableViaAppListFlow::ShowAppList, base::Unretained(this)));
|
| - }
|
| -
|
| - private:
|
| - gfx::NativeWindow ShowAppList() {
|
| - AppListService* app_list_service = AppListService::Get(desktop_type_);
|
| - app_list_service->Show();
|
| - return app_list_service->GetAppListWindow();
|
| - }
|
| -
|
| - // ExtensionEnableFlowDelegate overrides.
|
| - virtual void ExtensionEnableFlowFinished() override {
|
| - const Extension* extension =
|
| - service_->GetExtensionById(extension_id_, false);
|
| - if (!extension)
|
| - return;
|
| - callback_.Run();
|
| - delete this;
|
| - }
|
| -
|
| - virtual void ExtensionEnableFlowAborted(bool user_initiated) override {
|
| - delete this;
|
| - }
|
| -
|
| - ExtensionService* service_;
|
| - Profile* profile_;
|
| - chrome::HostDesktopType desktop_type_;
|
| - std::string extension_id_;
|
| - base::Closure callback_;
|
| - scoped_ptr<ExtensionEnableFlow> flow_;
|
| -
|
| - DISALLOW_COPY_AND_ASSIGN(EnableViaAppListFlow);
|
| -};
|
| -
|
| const Extension* GetExtension(const AppLaunchParams& params) {
|
| if (params.extension_id.empty())
|
| return NULL;
|
| @@ -147,13 +74,12 @@ ui::WindowShowState DetermineWindowShowState(
|
| return ui::SHOW_STATE_DEFAULT;
|
| }
|
|
|
| -WebContents* OpenApplicationWindow(const AppLaunchParams& params) {
|
| +} // namespace
|
| +
|
| +WebContents* OpenWebAppWindow(const AppLaunchParams& params, const GURL& url) {
|
| Profile* const profile = params.profile;
|
| const Extension* const extension = GetExtension(params);
|
| - const GURL url_input = params.override_url;
|
|
|
| - DCHECK(!url_input.is_empty() || extension);
|
| - GURL url = UrlForExtension(extension, url_input);
|
| std::string app_name = extension ?
|
| web_app::GenerateApplicationNameFromExtensionId(extension->id()) :
|
| web_app::GenerateApplicationNameFromURL(url);
|
| @@ -194,7 +120,8 @@ WebContents* OpenApplicationWindow(const AppLaunchParams& params) {
|
| return web_contents;
|
| }
|
|
|
| -WebContents* OpenApplicationTab(const AppLaunchParams& launch_params) {
|
| +WebContents* OpenWebAppTab(const AppLaunchParams& launch_params,
|
| + const GURL& url) {
|
| const Extension* extension = GetExtension(launch_params);
|
| CHECK(extension);
|
| Profile* const profile = launch_params.profile;
|
| @@ -226,8 +153,7 @@ WebContents* OpenApplicationTab(const AppLaunchParams& launch_params) {
|
| if (launch_type == extensions::LAUNCH_TYPE_PINNED)
|
| add_type |= TabStripModel::ADD_PINNED;
|
|
|
| - GURL extension_url = UrlForExtension(extension, launch_params.override_url);
|
| - chrome::NavigateParams params(browser, extension_url,
|
| + chrome::NavigateParams params(browser, url,
|
| ui::PAGE_TRANSITION_AUTO_TOPLEVEL);
|
| params.tabstrip_add_types = add_type;
|
| params.disposition = disposition;
|
| @@ -239,7 +165,7 @@ WebContents* OpenApplicationTab(const AppLaunchParams& launch_params) {
|
| int tab_index = model->GetIndexOfWebContents(existing_tab);
|
|
|
| existing_tab->OpenURL(content::OpenURLParams(
|
| - extension_url,
|
| + url,
|
| content::Referrer(existing_tab->GetURL(),
|
| blink::WebReferrerPolicyDefault),
|
| disposition, ui::PAGE_TRANSITION_LINK, false));
|
| @@ -282,184 +208,3 @@ WebContents* OpenApplicationTab(const AppLaunchParams& launch_params) {
|
| }
|
| return contents;
|
| }
|
| -
|
| -WebContents* OpenEnabledApplication(const AppLaunchParams& params) {
|
| - const Extension* extension = GetExtension(params);
|
| - if (!extension)
|
| - return NULL;
|
| - Profile* profile = params.profile;
|
| -
|
| - WebContents* tab = NULL;
|
| - ExtensionPrefs* prefs = ExtensionPrefs::Get(profile);
|
| - prefs->SetActiveBit(extension->id(), true);
|
| -
|
| - UMA_HISTOGRAM_ENUMERATION(
|
| - "Extensions.AppLaunchContainer", params.container, 100);
|
| -
|
| - if (CanLaunchViaEvent(extension)) {
|
| - // Remember what desktop the launch happened on so that when the app opens a
|
| - // window we can open them on the right desktop.
|
| - PerAppSettingsServiceFactory::GetForBrowserContext(profile)->
|
| - SetDesktopLastLaunchedFrom(extension->id(), params.desktop_type);
|
| -
|
| - apps::LaunchPlatformAppWithCommandLine(
|
| - profile, extension, params.command_line, params.current_directory);
|
| - return NULL;
|
| - }
|
| -
|
| - // Record v1 app launch. Platform app launch is recorded when dispatching
|
| - // the onLaunched event.
|
| - prefs->SetLastLaunchTime(extension->id(), base::Time::Now());
|
| -
|
| - switch (params.container) {
|
| - case extensions::LAUNCH_CONTAINER_NONE: {
|
| - NOTREACHED();
|
| - break;
|
| - }
|
| - case extensions::LAUNCH_CONTAINER_PANEL:
|
| - case extensions::LAUNCH_CONTAINER_WINDOW:
|
| - tab = OpenApplicationWindow(params);
|
| - break;
|
| - case extensions::LAUNCH_CONTAINER_TAB: {
|
| - tab = OpenApplicationTab(params);
|
| - break;
|
| - }
|
| - default:
|
| - NOTREACHED();
|
| - break;
|
| - }
|
| - return tab;
|
| -}
|
| -
|
| -} // namespace
|
| -
|
| -AppLaunchParams::AppLaunchParams(Profile* profile,
|
| - const extensions::Extension* extension,
|
| - extensions::LaunchContainer container,
|
| - WindowOpenDisposition disposition)
|
| - : profile(profile),
|
| - extension_id(extension ? extension->id() : std::string()),
|
| - container(container),
|
| - disposition(disposition),
|
| - desktop_type(chrome::GetActiveDesktop()),
|
| - override_url(),
|
| - override_bounds(),
|
| - command_line(CommandLine::NO_PROGRAM) {}
|
| -
|
| -AppLaunchParams::AppLaunchParams(Profile* profile,
|
| - const extensions::Extension* extension,
|
| - WindowOpenDisposition disposition)
|
| - : profile(profile),
|
| - extension_id(extension ? extension->id() : std::string()),
|
| - container(extensions::LAUNCH_CONTAINER_NONE),
|
| - disposition(disposition),
|
| - desktop_type(chrome::GetActiveDesktop()),
|
| - override_url(),
|
| - override_bounds(),
|
| - command_line(CommandLine::NO_PROGRAM) {
|
| - // Look up the app preference to find out the right launch container. Default
|
| - // is to launch as a regular tab.
|
| - container =
|
| - extensions::GetLaunchContainer(ExtensionPrefs::Get(profile), extension);
|
| -}
|
| -
|
| -AppLaunchParams::AppLaunchParams(Profile* profile,
|
| - const extensions::Extension* extension,
|
| - int event_flags,
|
| - chrome::HostDesktopType desktop_type)
|
| - : profile(profile),
|
| - extension_id(extension ? extension->id() : std::string()),
|
| - container(extensions::LAUNCH_CONTAINER_NONE),
|
| - disposition(ui::DispositionFromEventFlags(event_flags)),
|
| - desktop_type(desktop_type),
|
| - override_url(),
|
| - override_bounds(),
|
| - command_line(CommandLine::NO_PROGRAM) {
|
| - if (disposition == NEW_FOREGROUND_TAB || disposition == NEW_BACKGROUND_TAB) {
|
| - container = extensions::LAUNCH_CONTAINER_TAB;
|
| - } else if (disposition == NEW_WINDOW) {
|
| - container = extensions::LAUNCH_CONTAINER_WINDOW;
|
| - } else {
|
| - // Look at preference to find the right launch container. If no preference
|
| - // is set, launch as a regular tab.
|
| - container =
|
| - extensions::GetLaunchContainer(ExtensionPrefs::Get(profile), extension);
|
| - disposition = NEW_FOREGROUND_TAB;
|
| - }
|
| -}
|
| -
|
| -AppLaunchParams::~AppLaunchParams() {
|
| -}
|
| -
|
| -WebContents* OpenApplication(const AppLaunchParams& params) {
|
| - return OpenEnabledApplication(params);
|
| -}
|
| -
|
| -void OpenApplicationWithReenablePrompt(const AppLaunchParams& params) {
|
| - const Extension* extension = GetExtension(params);
|
| - if (!extension)
|
| - return;
|
| - Profile* profile = params.profile;
|
| -
|
| - ExtensionService* service =
|
| - extensions::ExtensionSystem::Get(profile)->extension_service();
|
| - if (!service->IsExtensionEnabled(extension->id()) ||
|
| - extensions::ExtensionRegistry::Get(profile)->GetExtensionById(
|
| - extension->id(), extensions::ExtensionRegistry::TERMINATED)) {
|
| - (new EnableViaAppListFlow(
|
| - service, profile, params.desktop_type, extension->id(),
|
| - base::Bind(base::IgnoreResult(OpenEnabledApplication), params)))->Run();
|
| - return;
|
| - }
|
| -
|
| - OpenEnabledApplication(params);
|
| -}
|
| -
|
| -WebContents* OpenAppShortcutWindow(Profile* profile,
|
| - const GURL& url) {
|
| - AppLaunchParams launch_params(
|
| - profile,
|
| - NULL, // this is a URL app. No extension.
|
| - extensions::LAUNCH_CONTAINER_WINDOW,
|
| - NEW_WINDOW);
|
| - launch_params.override_url = url;
|
| -
|
| - WebContents* tab = OpenApplicationWindow(launch_params);
|
| -
|
| - if (!tab)
|
| - return NULL;
|
| -
|
| - extensions::TabHelper::FromWebContents(tab)->UpdateShortcutOnLoadComplete();
|
| -
|
| - return tab;
|
| -}
|
| -
|
| -bool CanLaunchViaEvent(const extensions::Extension* extension) {
|
| - const extensions::FeatureProvider* feature_provider =
|
| - extensions::FeatureProvider::GetAPIFeatures();
|
| - extensions::Feature* feature = feature_provider->GetFeature("app.runtime");
|
| - return feature->IsAvailableToExtension(extension).is_available();
|
| -}
|
| -
|
| -GURL UrlForExtension(const Extension* extension, const GURL& override_url) {
|
| - if (!extension)
|
| - return override_url;
|
| -
|
| - GURL url;
|
| - if (!override_url.is_empty()) {
|
| - DCHECK(extension->web_extent().MatchesURL(override_url) ||
|
| - override_url.GetOrigin() == extension->url());
|
| - url = override_url;
|
| - } else {
|
| - url = extensions::AppLaunchInfo::GetFullLaunchURL(extension);
|
| - }
|
| -
|
| - // For extensions lacking launch urls, determine a reasonable fallback.
|
| - if (!url.is_valid()) {
|
| - url = extensions::OptionsPageInfo::GetOptionsPage(extension);
|
| - if (!url.is_valid())
|
| - url = GURL(chrome::kChromeUIExtensionsURL);
|
| - }
|
| -
|
| - return url;
|
| -}
|
|
|