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

Side by Side Diff: chrome/browser/extensions/webstore_install_helper.cc

Issue 855513002: Add/resurrect support for bundles of WebStore items. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@testext_bundle
Patch Set: add CRXs Created 5 years, 8 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 unified diff | Download patch
OLDNEW
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/extensions/webstore_install_helper.h" 5 #include "chrome/browser/extensions/webstore_install_helper.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/values.h" 10 #include "base/values.h"
11 #include "chrome/browser/safe_image_fetcher.h"
11 #include "chrome/common/chrome_utility_messages.h" 12 #include "chrome/common/chrome_utility_messages.h"
12 #include "chrome/common/extensions/chrome_utility_extensions_messages.h" 13 #include "chrome/common/extensions/chrome_utility_extensions_messages.h"
13 #include "content/public/browser/browser_thread.h" 14 #include "content/public/browser/browser_thread.h"
14 #include "content/public/browser/utility_process_host.h" 15 #include "content/public/browser/utility_process_host.h"
15 #include "net/base/load_flags.h"
16 #include "net/url_request/url_fetcher.h"
17 #include "net/url_request/url_request_context_getter.h"
18 #include "net/url_request/url_request_status.h"
19 16
20 using content::BrowserThread; 17 using content::BrowserThread;
21 using content::UtilityProcessHost; 18 using content::UtilityProcessHost;
22 19
23 namespace { 20 namespace {
24 21
25 const char kImageDecodeError[] = "Image decode failed"; 22 const char kImageDecodeError[] = "Image decode failed";
26 23
27 } // namespace 24 } // namespace
28 25
29 namespace extensions { 26 namespace extensions {
30 27
31 WebstoreInstallHelper::WebstoreInstallHelper( 28 WebstoreInstallHelper::WebstoreInstallHelper(
32 Delegate* delegate, 29 Delegate* delegate,
33 const std::string& id, 30 const std::string& id,
34 const std::string& manifest, 31 const std::string& manifest,
35 const GURL& icon_url, 32 const GURL& icon_url,
36 net::URLRequestContextGetter* context_getter) 33 net::URLRequestContextGetter* context_getter)
37 : ImageRequest( 34 : delegate_(delegate),
38 content::BrowserThread::GetMessageLoopProxyForThread(
39 content::BrowserThread::IO)),
40 delegate_(delegate),
41 id_(id), 35 id_(id),
42 manifest_(manifest), 36 manifest_(manifest),
43 icon_url_(icon_url), 37 icon_url_(icon_url),
44 context_getter_(context_getter), 38 context_getter_(context_getter),
45 icon_decode_complete_(false), 39 icon_decode_complete_(false),
46 manifest_parse_complete_(false), 40 manifest_parse_complete_(false),
47 parse_error_(Delegate::UNKNOWN_ERROR) { 41 parse_error_(Delegate::UNKNOWN_ERROR) {
48 } 42 }
49 43
50 WebstoreInstallHelper::~WebstoreInstallHelper() {} 44 WebstoreInstallHelper::~WebstoreInstallHelper() {}
51 45
52 void WebstoreInstallHelper::Start() { 46 void WebstoreInstallHelper::Start() {
53 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 47 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
54 48
55 if (icon_url_.is_empty()) 49 if (icon_url_.is_empty()) {
56 icon_decode_complete_ = true; 50 icon_decode_complete_ = true;
51 } else {
52 icon_fetcher_.reset(new SafeImageFetcher(
53 icon_url_, context_getter_,
54 base::Bind(&WebstoreInstallHelper::OnIconFetched, this)));
55 }
57 56
58 BrowserThread::PostTask( 57 BrowserThread::PostTask(
59 BrowserThread::IO, 58 BrowserThread::IO,
60 FROM_HERE, 59 FROM_HERE,
61 base::Bind(&WebstoreInstallHelper::StartWorkOnIOThread, this)); 60 base::Bind(&WebstoreInstallHelper::StartWorkOnIOThread, this));
62
63 if (!icon_url_.is_empty()) {
64 CHECK(context_getter_);
65 url_fetcher_.reset(net::URLFetcher::Create(
66 icon_url_, net::URLFetcher::GET, this));
67 url_fetcher_->SetRequestContext(context_getter_);
68 url_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES |
69 net::LOAD_DO_NOT_SEND_COOKIES);
70
71 url_fetcher_->Start();
72 // We'll get called back in OnURLFetchComplete.
73 }
74 } 61 }
75 62
76 void WebstoreInstallHelper::StartWorkOnIOThread() { 63 void WebstoreInstallHelper::StartWorkOnIOThread() {
77 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 64 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
78 utility_host_ = UtilityProcessHost::Create( 65 utility_host_ = UtilityProcessHost::Create(
79 this, base::MessageLoopProxy::current().get())->AsWeakPtr(); 66 this, base::MessageLoopProxy::current().get())->AsWeakPtr();
80 utility_host_->StartBatchMode(); 67 utility_host_->StartBatchMode();
81 68
82 utility_host_->Send(new ChromeUtilityMsg_ParseJSON(manifest_)); 69 utility_host_->Send(new ChromeUtilityMsg_ParseJSON(manifest_));
83 } 70 }
84 71
85 void WebstoreInstallHelper::OnURLFetchComplete(
86 const net::URLFetcher* source) {
87 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
88 CHECK(source == url_fetcher_.get());
89 int response_code =
90 source->GetStatus().is_success() ? source->GetResponseCode() : 0;
91 if (!source->GetStatus().is_success() ||
92 response_code / 100 == 4 || response_code / 100 == 5) {
93 BrowserThread::PostTask(
94 BrowserThread::IO, FROM_HERE,
95 base::Bind(&WebstoreInstallHelper::OnDecodeImageFailed, this));
96 } else {
97 std::string response_data;
98 source->GetResponseAsString(&response_data);
99
100 ImageDecoder::Start(this, response_data);
101 }
102 url_fetcher_.reset();
103 }
104
105 bool WebstoreInstallHelper::OnMessageReceived(const IPC::Message& message) { 72 bool WebstoreInstallHelper::OnMessageReceived(const IPC::Message& message) {
106 bool handled = true; 73 bool handled = true;
107 IPC_BEGIN_MESSAGE_MAP(WebstoreInstallHelper, message) 74 IPC_BEGIN_MESSAGE_MAP(WebstoreInstallHelper, message)
108 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_ParseJSON_Succeeded, 75 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_ParseJSON_Succeeded,
109 OnJSONParseSucceeded) 76 OnJSONParseSucceeded)
110 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_ParseJSON_Failed, 77 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_ParseJSON_Failed,
111 OnJSONParseFailed) 78 OnJSONParseFailed)
112 IPC_MESSAGE_UNHANDLED(handled = false) 79 IPC_MESSAGE_UNHANDLED(handled = false)
113 IPC_END_MESSAGE_MAP() 80 IPC_END_MESSAGE_MAP()
114 return handled; 81 return handled;
115 } 82 }
116 83
117 void WebstoreInstallHelper::OnImageDecoded(const SkBitmap& decoded_image) { 84 void WebstoreInstallHelper::OnIconFetched(const SkBitmap& icon) {
118 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 85 icon_ = icon;
119 icon_ = decoded_image;
120 icon_decode_complete_ = true; 86 icon_decode_complete_ = true;
121 ReportResultsIfComplete(); 87 if (icon_.empty()) {
122 } 88 error_ = kImageDecodeError;
123 89 parse_error_ = Delegate::ICON_ERROR;
124 void WebstoreInstallHelper::OnDecodeImageFailed() { 90 }
125 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 91 BrowserThread::PostTask(
126 icon_decode_complete_ = true; 92 BrowserThread::IO,
127 error_ = kImageDecodeError; 93 FROM_HERE,
128 parse_error_ = Delegate::ICON_ERROR; 94 base::Bind(&WebstoreInstallHelper::ReportResultsIfComplete, this));
129 ReportResultsIfComplete();
130 } 95 }
131 96
132 void WebstoreInstallHelper::OnJSONParseSucceeded( 97 void WebstoreInstallHelper::OnJSONParseSucceeded(
133 const base::ListValue& wrapper) { 98 const base::ListValue& wrapper) {
134 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 99 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
135 manifest_parse_complete_ = true; 100 manifest_parse_complete_ = true;
136 const base::Value* value = NULL; 101 const base::Value* value = NULL;
137 CHECK(wrapper.Get(0, &value)); 102 CHECK(wrapper.Get(0, &value));
138 if (value->IsType(base::Value::TYPE_DICTIONARY)) { 103 if (value->IsType(base::Value::TYPE_DICTIONARY)) {
139 parsed_manifest_.reset( 104 parsed_manifest_.reset(
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 138
174 void WebstoreInstallHelper::ReportResultFromUIThread() { 139 void WebstoreInstallHelper::ReportResultFromUIThread() {
175 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 140 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
176 if (error_.empty() && parsed_manifest_) 141 if (error_.empty() && parsed_manifest_)
177 delegate_->OnWebstoreParseSuccess(id_, icon_, parsed_manifest_.release()); 142 delegate_->OnWebstoreParseSuccess(id_, icon_, parsed_manifest_.release());
178 else 143 else
179 delegate_->OnWebstoreParseFailure(id_, parse_error_, error_); 144 delegate_->OnWebstoreParseFailure(id_, parse_error_, error_);
180 } 145 }
181 146
182 } // namespace extensions 147 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698