Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(45)

Unified Diff: chrome/browser/apps/install_chrome_app.cc

Issue 412043003: Make --install-chrome-app use extensions::WebstoreInstallWithPrompt. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Redo this with only changes to install_chrome_app. Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/apps/install_chrome_app.cc
diff --git a/chrome/browser/apps/install_chrome_app.cc b/chrome/browser/apps/install_chrome_app.cc
index 57965bfd99732686b1a57b86ba54fb07adf99514..a11797dc5a5f3e61c4ae80b38e78cd195813bb00 100644
--- a/chrome/browser/apps/install_chrome_app.cc
+++ b/chrome/browser/apps/install_chrome_app.cc
@@ -8,79 +8,28 @@
#include "base/command_line.h"
#include "base/strings/stringprintf.h"
#include "chrome/browser/browser_process.h"
+#include "chrome/browser/extensions/webstore_startup_installer.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_list.h"
-#include "chrome/browser/ui/browser_navigator.h"
+#include "chrome/common/extensions/webstore_install_result.h"
+#include "extensions/browser/extension_registry.h"
#include "extensions/common/extension.h"
-#include "google_apis/gaia/gaia_urls.h"
-#include "net/url_request/url_fetcher.h"
-#include "net/url_request/url_fetcher_delegate.h"
namespace {
-// The URL to the webstore page for a specific app. "_asi=1" instructs webstore
-// to immediately try to install the app if the referrer is the sign in page.
-// This is actually the short form of the URL which just redirects to the full
-// URL. Since "_asi=1" only works on the full url, we need to resolve it first
-// before navigating the user to it.
+// The URL to the webstore page for a specific app.
const char kWebstoreUrlFormat[] =
- "https://chrome.google.com/webstore/detail/%s?_asi=1";
-
-// The URL for the sign in page, set as the referrer to webstore.
-const char kAccountsUrl[] = "https://accounts.google.com/ServiceLogin";
+ "https://chrome.google.com/webstore/detail/%s";
// Returns the webstore URL for an app.
GURL GetAppInstallUrl(const std::string& app_id) {
return GURL(base::StringPrintf(kWebstoreUrlFormat, app_id.c_str()));
}
-void NavigateToUrlWithAccountsReferrer(const GURL& url) {
- Browser* browser =
- BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_NATIVE)->get(0);
- if (!browser)
- return;
-
- chrome::NavigateParams params(
- browser, url, content::PAGE_TRANSITION_AUTO_TOPLEVEL);
- params.disposition = NEW_FOREGROUND_TAB;
- params.window_action = chrome::NavigateParams::SHOW_WINDOW;
- params.referrer = content::Referrer();
- params.referrer.url = GURL(kAccountsUrl);
- chrome::Navigate(&params);
-}
-
-class AppURLFetcher : net::URLFetcherDelegate {
- public:
- explicit AppURLFetcher(const std::string& app_id);
-
- // net::URLFetcherDelegate OVERRIDES:
- virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE;
-
- private:
- virtual ~AppURLFetcher();
-
- scoped_ptr<net::URLFetcher> url_fetcher_;
-
- DISALLOW_COPY_AND_ASSIGN(AppURLFetcher);
-};
-
-AppURLFetcher::AppURLFetcher(const std::string& app_id) {
- url_fetcher_.reset(net::URLFetcher::Create(
- GetAppInstallUrl(app_id), net::URLFetcher::GET, this));
- url_fetcher_->SetRequestContext(g_browser_process->system_request_context());
- url_fetcher_->SetStopOnRedirect(true);
- url_fetcher_->Start();
-}
-
-AppURLFetcher::~AppURLFetcher() {
-}
-
-void AppURLFetcher::OnURLFetchComplete(const net::URLFetcher* source) {
- if (source->GetResponseCode() == 301) {
- // Moved permanently.
- NavigateToUrlWithAccountsReferrer(source->GetURL());
- }
-
- delete this;
+void DoNothingCallback(bool success,
+ const std::string& error,
+ extensions::webstore_install::Result result) {
}
} // namespace
@@ -91,7 +40,31 @@ void InstallChromeApp(const std::string& app_id) {
if (!extensions::Extension::IdIsValid(app_id))
return;
- new AppURLFetcher(app_id);
+ Browser* browser =
+ BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_NATIVE)->get(0);
tapted 2014/07/28 03:41:04 I don't think BrowserList::get() can ever return N
jackhou1 2014/07/28 04:18:53 At the moment it's not an issue, but that might ch
+ if (!browser)
+ return;
+
+ content::OpenURLParams params(GetAppInstallUrl(app_id),
+ content::Referrer(),
+ NEW_FOREGROUND_TAB,
+ content::PAGE_TRANSITION_AUTO_TOPLEVEL,
+ false);
+ browser->OpenURL(params);
+
+ extensions::ExtensionRegistry* registry =
tapted 2014/07/28 03:41:04 nit: maybe `using extensions::ExtensionRegistry`?
jackhou1 2014/07/28 04:18:53 Done.
+ extensions::ExtensionRegistry::Get(browser->profile());
+ const extensions::Extension* installed_extension = registry->GetExtensionById(
+ app_id,
+ extensions::ExtensionRegistry::ENABLED |
+ extensions::ExtensionRegistry::BLACKLISTED);
tapted 2014/07/28 03:41:04 This probably needs a comment to explain this flag
jackhou1 2014/07/28 04:18:53 Done.
+ if (installed_extension)
+ return;
tapted 2014/07/28 03:41:04 Maybe a TODO(..) determine UX for an installed ext
jackhou1 2014/07/28 04:18:53 Done.
+
+ extensions::WebstoreStartupInstaller* installer =
+ new extensions::WebstoreStartupInstaller(
+ app_id, browser->profile(), true, base::Bind(&DoNothingCallback));
+ installer->BeginInstall();
}
} // namespace install_chrome_app
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698