diff options
author | tmdiep@chromium.org <tmdiep@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-11-06 23:44:31 +0000 |
---|---|---|
committer | tmdiep@chromium.org <tmdiep@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-11-06 23:44:31 +0000 |
commit | 4b2dee32040ac1a74a60a73d12cd73917d2f548f (patch) | |
tree | 2bb59b5cd9c0700e1e3465488b4c62c72b37d1a4 /chrome/browser/extensions | |
parent | bf10864da44f34d435bff3a264458ae18bdba215 (diff) | |
download | chromium_src-4b2dee32040ac1a74a60a73d12cd73917d2f548f.zip chromium_src-4b2dee32040ac1a74a60a73d12cd73917d2f548f.tar.gz chromium_src-4b2dee32040ac1a74a60a73d12cd73917d2f548f.tar.bz2 |
Launch ephemeral app for webstore detail links
Added EphemeralAppThrottle, which will launch ephemeral apps for
links to Chrome Web Store detail pages instead of opening the page in
the browser. This will only occur if the enable-ephemeral-apps switch
is enabled.
For experimental purposes only. The extension will currently be
installed in Chrome.
BUG=312460
Review URL: https://codereview.chromium.org/51943003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@233419 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions')
-rw-r--r-- | chrome/browser/extensions/webstore_ephemeral_installer.cc | 69 | ||||
-rw-r--r-- | chrome/browser/extensions/webstore_ephemeral_installer.h | 15 |
2 files changed, 74 insertions, 10 deletions
diff --git a/chrome/browser/extensions/webstore_ephemeral_installer.cc b/chrome/browser/extensions/webstore_ephemeral_installer.cc index 1d1e2d5..31f7a04 100644 --- a/chrome/browser/extensions/webstore_ephemeral_installer.cc +++ b/chrome/browser/extensions/webstore_ephemeral_installer.cc @@ -12,6 +12,7 @@ #include "chrome/common/extensions/permissions/permissions_data.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/web_contents.h" +#include "content/public/browser/web_contents_view.h" using content::WebContents; @@ -22,13 +23,14 @@ namespace { // TODO(tmdiep): Launching the app will be moved downstream when an ephemeral // app service/manager is implemented. void LaunchApp(Profile* profile, const std::string& id) { - ExtensionService* service = extensions::ExtensionSystem::Get(profile)-> - extension_service(); + ExtensionService* service = + ExtensionSystem::Get(profile)->extension_service(); DCHECK(service); - const extensions::Extension* extension = service->GetExtensionById(id, false); + const Extension* extension = service->GetExtensionById(id, false); if (extension) { + // TODO(tmdiep): Sort out params.desktop_type when launching is moved + // to the correct location. AppLaunchParams params(profile, extension, NEW_FOREGROUND_TAB); - params.desktop_type = chrome::HOST_DESKTOP_TYPE_NATIVE; OpenApplication(params); } } @@ -45,7 +47,22 @@ void OnInstallDone(Profile* profile, base::Bind(&LaunchApp, profile, id), base::TimeDelta()); - callback.Run(success, error); + if (!callback.is_null()) + callback.Run(success, error); +} + +Profile* ProfileForWebContents(content::WebContents* contents) { + if (!contents) + return NULL; + + return Profile::FromBrowserContext(contents->GetBrowserContext()); +} + +gfx::NativeWindow NativeWindowForWebContents(content::WebContents* contents) { + if (!contents) + return NULL; + + return contents->GetView()->GetTopLevelNativeWindow(); } } // namespace @@ -62,8 +79,20 @@ WebstoreEphemeralInstaller::CreateForLauncher( profile, parent_window, callback); - installer->set_install_source( - extensions::WebstoreInstaller::INSTALL_SOURCE_APP_LAUNCHER); + installer->set_install_source(WebstoreInstaller::INSTALL_SOURCE_APP_LAUNCHER); + return installer; +} + +// static +scoped_refptr<WebstoreEphemeralInstaller> +WebstoreEphemeralInstaller::CreateForLink( + const std::string& webstore_item_id, + content::WebContents* web_contents) { + scoped_refptr<WebstoreEphemeralInstaller> installer = + new WebstoreEphemeralInstaller(webstore_item_id, + web_contents, + Callback()); + installer->set_install_source(WebstoreInstaller::INSTALL_SOURCE_OTHER); return installer; } @@ -80,10 +109,24 @@ WebstoreEphemeralInstaller::WebstoreEphemeralInstaller( dummy_web_contents_( WebContents::Create(WebContents::CreateParams(profile))) {} +WebstoreEphemeralInstaller::WebstoreEphemeralInstaller( + const std::string& webstore_item_id, + content::WebContents* web_contents, + const Callback& callback) + : WebstoreStandaloneInstaller( + webstore_item_id, + ProfileForWebContents(web_contents), + base::Bind(OnInstallDone, + ProfileForWebContents(web_contents), + webstore_item_id, + callback)), + content::WebContentsObserver(web_contents), + parent_window_(NativeWindowForWebContents(web_contents)) {} + WebstoreEphemeralInstaller::~WebstoreEphemeralInstaller() {} bool WebstoreEphemeralInstaller::CheckRequestorAlive() const { - return true; + return dummy_web_contents_.get() != NULL || web_contents() != NULL; } const GURL& WebstoreEphemeralInstaller::GetRequestorURL() const { @@ -99,7 +142,7 @@ bool WebstoreEphemeralInstaller::ShouldShowAppInstalledBubble() const { } WebContents* WebstoreEphemeralInstaller::GetWebContents() const { - return dummy_web_contents_.get(); + return web_contents() ? web_contents() : dummy_web_contents_.get(); } scoped_ptr<ExtensionInstallPrompt::Prompt> @@ -147,8 +190,16 @@ bool WebstoreEphemeralInstaller::CheckRequestorPermitted( scoped_ptr<ExtensionInstallPrompt> WebstoreEphemeralInstaller::CreateInstallUI() { + if (web_contents()) + return make_scoped_ptr(new ExtensionInstallPrompt(web_contents())); + return make_scoped_ptr( new ExtensionInstallPrompt(profile(), parent_window_, NULL)); } +void WebstoreEphemeralInstaller::WebContentsDestroyed( + content::WebContents* web_contents) { + AbortInstall(); +} + } // namespace extensions diff --git a/chrome/browser/extensions/webstore_ephemeral_installer.h b/chrome/browser/extensions/webstore_ephemeral_installer.h index 895976b7..5623b30 100644 --- a/chrome/browser/extensions/webstore_ephemeral_installer.h +++ b/chrome/browser/extensions/webstore_ephemeral_installer.h @@ -9,6 +9,7 @@ #include "base/basictypes.h" #include "chrome/browser/extensions/webstore_standalone_installer.h" +#include "content/public/browser/web_contents_observer.h" class Profile; @@ -20,7 +21,8 @@ namespace extensions { // WebstoreEphemeralInstaller handles the installation of ephemeral apps. class WebstoreEphemeralInstaller - : public extensions::WebstoreStandaloneInstaller { + : public extensions::WebstoreStandaloneInstaller, + public content::WebContentsObserver { public: typedef WebstoreStandaloneInstaller::Callback Callback; @@ -29,6 +31,9 @@ class WebstoreEphemeralInstaller Profile* profile, gfx::NativeWindow parent_window, const Callback& callback); + static scoped_refptr<WebstoreEphemeralInstaller> CreateForLink( + const std::string& webstore_item_id, + content::WebContents* web_contents); private: friend class base::RefCountedThreadSafe<WebstoreEphemeralInstaller>; @@ -38,6 +43,10 @@ class WebstoreEphemeralInstaller gfx::NativeWindow parent_window, const Callback& callback); + WebstoreEphemeralInstaller(const std::string& webstore_item_id, + content::WebContents* web_contents, + const Callback& callback); + virtual ~WebstoreEphemeralInstaller(); // WebstoreStandaloneInstaller implementation. @@ -56,6 +65,10 @@ class WebstoreEphemeralInstaller std::string* error) const OVERRIDE; virtual scoped_ptr<ExtensionInstallPrompt> CreateInstallUI() OVERRIDE; + // content::WebContentsObserver implementation. + virtual void WebContentsDestroyed( + content::WebContents* web_contents) OVERRIDE; + gfx::NativeWindow parent_window_; scoped_ptr<content::WebContents> dummy_web_contents_; |