| Index: chrome/browser/extensions/webstore_standalone_installer.cc
|
| diff --git a/chrome/browser/extensions/webstore_standalone_installer.cc b/chrome/browser/extensions/webstore_standalone_installer.cc
|
| index 7cf28a373b07b039e2d8d3935f0b91953a8d53bd..792be92be4b4c0135879775c77c0c38e53a87b97 100644
|
| --- a/chrome/browser/extensions/webstore_standalone_installer.cc
|
| +++ b/chrome/browser/extensions/webstore_standalone_installer.cc
|
| @@ -6,32 +6,19 @@
|
|
|
| #include <vector>
|
|
|
| -#include "base/bind.h"
|
| -#include "base/string_util.h"
|
| +#include "base/stringprintf.h"
|
| #include "base/values.h"
|
| -#include "chrome/browser/browser_process.h"
|
| #include "chrome/browser/extensions/crx_installer.h"
|
| #include "chrome/browser/extensions/extension_install_ui.h"
|
| #include "chrome/browser/extensions/extension_service.h"
|
| +#include "chrome/browser/extensions/webstore_data_fetcher.h"
|
| #include "chrome/browser/profiles/profile.h"
|
| -#include "chrome/common/chrome_utility_messages.h"
|
| #include "chrome/common/extensions/extension.h"
|
| -#include "chrome/common/extensions/extension_constants.h"
|
| -#include "chrome/common/url_constants.h"
|
| -#include "content/public/browser/utility_process_host.h"
|
| -#include "content/public/browser/utility_process_host_client.h"
|
| #include "content/public/browser/web_contents.h"
|
| #include "content/public/browser/web_contents_view.h"
|
| -#include "extensions/common/url_pattern.h"
|
| -#include "net/base/escape.h"
|
| -#include "net/base/load_flags.h"
|
| -#include "net/url_request/url_fetcher.h"
|
| -#include "net/url_request/url_request_status.h"
|
|
|
| using content::BrowserThread;
|
| using content::OpenURLParams;
|
| -using content::UtilityProcessHost;
|
| -using content::UtilityProcessHostClient;
|
| using content::WebContents;
|
|
|
| namespace extensions {
|
| @@ -63,91 +50,6 @@ const char kInlineInstallSupportedError[] =
|
| "Inline installation is not supported for this item. The user will be "
|
| "redirected to the Chrome Web Store.";
|
|
|
| -class SafeWebstoreResponseParser : public UtilityProcessHostClient {
|
| - public:
|
| - SafeWebstoreResponseParser(WebstoreStandaloneInstaller *client,
|
| - const std::string& webstore_data)
|
| - : client_(client),
|
| - webstore_data_(webstore_data) {}
|
| -
|
| - void Start() {
|
| - CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| - BrowserThread::PostTask(
|
| - BrowserThread::IO,
|
| - FROM_HERE,
|
| - base::Bind(&SafeWebstoreResponseParser::StartWorkOnIOThread, this));
|
| - }
|
| -
|
| - void StartWorkOnIOThread() {
|
| - CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
|
| - UtilityProcessHost* host =
|
| - UtilityProcessHost::Create(
|
| - this, base::MessageLoopProxy::current());
|
| - host->EnableZygote();
|
| - host->Send(new ChromeUtilityMsg_ParseJSON(webstore_data_));
|
| - }
|
| -
|
| - // Implementing pieces of the UtilityProcessHostClient interface.
|
| - virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE {
|
| - bool handled = true;
|
| - IPC_BEGIN_MESSAGE_MAP(SafeWebstoreResponseParser, message)
|
| - IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_ParseJSON_Succeeded,
|
| - OnJSONParseSucceeded)
|
| - IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_ParseJSON_Failed,
|
| - OnJSONParseFailed)
|
| - IPC_MESSAGE_UNHANDLED(handled = false)
|
| - IPC_END_MESSAGE_MAP()
|
| - return handled;
|
| - }
|
| -
|
| - void OnJSONParseSucceeded(const ListValue& wrapper) {
|
| - CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
|
| - const Value* value = NULL;
|
| - CHECK(wrapper.Get(0, &value));
|
| - if (value->IsType(Value::TYPE_DICTIONARY)) {
|
| - parsed_webstore_data_.reset(
|
| - static_cast<const DictionaryValue*>(value)->DeepCopy());
|
| - } else {
|
| - error_ = kInvalidWebstoreResponseError;
|
| - }
|
| -
|
| - ReportResults();
|
| - }
|
| -
|
| - virtual void OnJSONParseFailed(const std::string& error_message) {
|
| - CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
|
| - error_ = error_message;
|
| - ReportResults();
|
| - }
|
| -
|
| - void ReportResults() {
|
| - CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
|
| -
|
| - BrowserThread::PostTask(
|
| - BrowserThread::UI,
|
| - FROM_HERE,
|
| - base::Bind(&SafeWebstoreResponseParser::ReportResultOnUIThread, this));
|
| - }
|
| -
|
| - void ReportResultOnUIThread() {
|
| - CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| - if (error_.empty() && parsed_webstore_data_.get()) {
|
| - client_->OnWebstoreResponseParseSuccess(parsed_webstore_data_.release());
|
| - } else {
|
| - client_->OnWebstoreResponseParseFailure(error_);
|
| - }
|
| - }
|
| -
|
| - private:
|
| - virtual ~SafeWebstoreResponseParser() {}
|
| -
|
| - WebstoreStandaloneInstaller* client_;
|
| -
|
| - std::string webstore_data_;
|
| - std::string error_;
|
| - scoped_ptr<DictionaryValue> parsed_webstore_data_;
|
| -};
|
| -
|
| WebstoreStandaloneInstaller::WebstoreStandaloneInstaller(
|
| WebContents* web_contents,
|
| std::string webstore_item_id,
|
| @@ -175,47 +77,23 @@ void WebstoreStandaloneInstaller::BeginInstall() {
|
| return;
|
| }
|
|
|
| - GURL webstore_data_url(extension_urls::GetWebstoreItemJsonDataURL(id_));
|
| -
|
| - webstore_data_url_fetcher_.reset(net::URLFetcher::Create(
|
| - webstore_data_url, net::URLFetcher::GET, this));
|
| Profile* profile = Profile::FromBrowserContext(
|
| web_contents()->GetBrowserContext());
|
| - webstore_data_url_fetcher_->SetRequestContext(
|
| - profile->GetRequestContext());
|
| // Use the requesting page as the referrer both since that is more correct
|
| // (it is the page that caused this request to happen) and so that we can
|
| // track top sites that trigger inline install requests.
|
| - webstore_data_url_fetcher_->SetReferrer(requestor_url_.spec());
|
| - webstore_data_url_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES |
|
| - net::LOAD_DISABLE_CACHE);
|
| - webstore_data_url_fetcher_->Start();
|
| + webstore_data_fetcher_.reset(new WebstoreDataFetcher(
|
| + this,
|
| + profile->GetRequestContext(),
|
| + requestor_url_,
|
| + id_));
|
| + webstore_data_fetcher_->Start();
|
| }
|
|
|
| WebstoreStandaloneInstaller::~WebstoreStandaloneInstaller() {}
|
|
|
| -void WebstoreStandaloneInstaller::OnURLFetchComplete(
|
| - const net::URLFetcher* source) {
|
| - CHECK_EQ(webstore_data_url_fetcher_.get(), source);
|
| - // We shouldn't be getting UrlFetcher callbacks if the WebContents has gone
|
| - // away; we stop any in in-progress fetches in WebContentsDestroyed.
|
| - CHECK(web_contents());
|
| -
|
| - if (!webstore_data_url_fetcher_->GetStatus().is_success() ||
|
| - webstore_data_url_fetcher_->GetResponseCode() != 200) {
|
| - CompleteInstall(kWebstoreRequestError);
|
| - return;
|
| - }
|
| -
|
| - std::string webstore_json_data;
|
| - webstore_data_url_fetcher_->GetResponseAsString(&webstore_json_data);
|
| - webstore_data_url_fetcher_.reset();
|
| -
|
| - scoped_refptr<SafeWebstoreResponseParser> parser =
|
| - new SafeWebstoreResponseParser(this, webstore_json_data);
|
| - // The parser will call us back via OnWebstoreResponseParseSucces or
|
| - // OnWebstoreResponseParseFailure.
|
| - parser->Start();
|
| +void WebstoreStandaloneInstaller::OnWebstoreRequestFailure() {
|
| + CompleteInstall(kWebstoreRequestError);
|
| }
|
|
|
| void WebstoreStandaloneInstaller::OnWebstoreResponseParseSuccess(
|
| @@ -425,8 +303,8 @@ void WebstoreStandaloneInstaller::WebContentsDestroyed(
|
| WebContents* web_contents) {
|
| callback_.Reset();
|
| // Abort any in-progress fetches.
|
| - if (webstore_data_url_fetcher_.get()) {
|
| - webstore_data_url_fetcher_.reset();
|
| + if (webstore_data_fetcher_.get()) {
|
| + webstore_data_fetcher_.reset();
|
| Release(); // Matches the AddRef in BeginInstall.
|
| }
|
| }
|
|
|