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

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

Issue 10907104: Support an --install-from-webstore command line switch (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: updated comment Created 8 years, 3 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 | Annotate | Revision Log
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_inline_installer.h" 5 #include "chrome/browser/extensions/webstore_inline_installer.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 virtual ~SafeWebstoreResponseParser() {} 141 virtual ~SafeWebstoreResponseParser() {}
142 142
143 WebstoreInlineInstaller* client_; 143 WebstoreInlineInstaller* client_;
144 144
145 std::string webstore_data_; 145 std::string webstore_data_;
146 std::string error_; 146 std::string error_;
147 scoped_ptr<DictionaryValue> parsed_webstore_data_; 147 scoped_ptr<DictionaryValue> parsed_webstore_data_;
148 }; 148 };
149 149
150 WebstoreInlineInstaller::WebstoreInlineInstaller(WebContents* web_contents, 150 WebstoreInlineInstaller::WebstoreInlineInstaller(WebContents* web_contents,
151 int install_id,
152 int return_route_id,
153 std::string webstore_item_id, 151 std::string webstore_item_id,
152 bool require_verified_site,
154 GURL requestor_url, 153 GURL requestor_url,
155 Delegate* delegate) 154 Callback callback)
156 : content::WebContentsObserver(web_contents), 155 : content::WebContentsObserver(web_contents),
157 install_id_(install_id),
158 return_route_id_(return_route_id),
159 id_(webstore_item_id), 156 id_(webstore_item_id),
157 require_verified_site_(require_verified_site),
160 requestor_url_(requestor_url), 158 requestor_url_(requestor_url),
161 delegate_(delegate), 159 callback_(callback),
162 average_rating_(0.0), 160 average_rating_(0.0),
163 rating_count_(0) { 161 rating_count_(0) {
162 CHECK(!callback.is_null());
164 } 163 }
165 164
166 void WebstoreInlineInstaller::BeginInstall() { 165 void WebstoreInlineInstaller::BeginInstall() {
167 AddRef(); // Balanced in CompleteInstall or WebContentsDestroyed. 166 AddRef(); // Balanced in CompleteInstall or WebContentsDestroyed.
168 167
169 if (!Extension::IdIsValid(id_)) { 168 if (!Extension::IdIsValid(id_)) {
170 CompleteInstall(kInvalidWebstoreItemId); 169 CompleteInstall(kInvalidWebstoreItemId);
171 return; 170 return;
172 } 171 }
173 172
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 295
297 // Verified site is required 296 // Verified site is required
298 if (webstore_data->HasKey(kVerifiedSiteKey)) { 297 if (webstore_data->HasKey(kVerifiedSiteKey)) {
299 std::string verified_site; 298 std::string verified_site;
300 if (!webstore_data->GetString(kVerifiedSiteKey, &verified_site)) { 299 if (!webstore_data->GetString(kVerifiedSiteKey, &verified_site)) {
301 CompleteInstall(kInvalidWebstoreResponseError); 300 CompleteInstall(kInvalidWebstoreResponseError);
302 return; 301 return;
303 } 302 }
304 303
305 if (!IsRequestorURLInVerifiedSite(requestor_url_, verified_site)) { 304 if (!IsRequestorURLInVerifiedSite(requestor_url_, verified_site)) {
306 CompleteInstall(kNotFromVerifiedSiteError); 305 CompleteInstall(kNotFromVerifiedSiteError);
Mihai Parparita -not on Chrome 2012/09/07 22:01:36 Seems like you'd want to ignore this error if requ
asargent_no_longer_on_chrome 2012/09/14 23:24:35 Done.
307 return; 306 return;
308 } 307 }
309 } else { 308 } else if (require_verified_site_) {
310 CompleteInstall(kNoVerifiedSiteError); 309 CompleteInstall(kNoVerifiedSiteError);
311 return; 310 return;
312 } 311 }
313 312
314 scoped_refptr<WebstoreInstallHelper> helper = new WebstoreInstallHelper( 313 scoped_refptr<WebstoreInstallHelper> helper = new WebstoreInstallHelper(
315 this, 314 this,
316 id_, 315 id_,
317 manifest, 316 manifest,
318 "", // We don't have any icon data. 317 "", // We don't have any icon data.
319 icon_url, 318 icon_url,
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 id_, 357 id_,
359 localized_name_, 358 localized_name_,
360 localized_description_, 359 localized_description_,
361 &error); 360 &error);
362 if (!dummy_extension_) { 361 if (!dummy_extension_) {
363 OnWebstoreParseFailure(id_, WebstoreInstallHelper::Delegate::MANIFEST_ERROR, 362 OnWebstoreParseFailure(id_, WebstoreInstallHelper::Delegate::MANIFEST_ERROR,
364 kInvalidManifestError); 363 kInvalidManifestError);
365 return; 364 return;
366 } 365 }
367 366
368 install_ui_.reset( 367 install_ui_.reset(new ExtensionInstallPrompt(NULL, web_contents(), profile));
369 ExtensionInstallUI::CreateInstallPromptWithWebContents(web_contents()));
370 install_ui_->ConfirmInlineInstall(this, dummy_extension_, &icon_, prompt); 368 install_ui_->ConfirmInlineInstall(this, dummy_extension_, &icon_, prompt);
371 // Control flow finishes up in InstallUIProceed or InstallUIAbort. 369 // Control flow finishes up in InstallUIProceed or InstallUIAbort.
372 } 370 }
373 371
374 void WebstoreInlineInstaller::OnWebstoreParseFailure( 372 void WebstoreInlineInstaller::OnWebstoreParseFailure(
375 const std::string& id, 373 const std::string& id,
376 InstallHelperResultCode result_code, 374 InstallHelperResultCode result_code,
377 const std::string& error_message) { 375 const std::string& error_message) {
378 CompleteInstall(error_message); 376 CompleteInstall(error_message);
379 } 377 }
(...skipping 19 matching lines...) Expand all
399 profile, this, &(web_contents()->GetController()), id_, approval.Pass(), 397 profile, this, &(web_contents()->GetController()), id_, approval.Pass(),
400 WebstoreInstaller::FLAG_INLINE_INSTALL); 398 WebstoreInstaller::FLAG_INLINE_INSTALL);
401 installer->Start(); 399 installer->Start();
402 } 400 }
403 401
404 void WebstoreInlineInstaller::InstallUIAbort(bool user_initiated) { 402 void WebstoreInlineInstaller::InstallUIAbort(bool user_initiated) {
405 CompleteInstall(kUserCancelledError); 403 CompleteInstall(kUserCancelledError);
406 } 404 }
407 405
408 void WebstoreInlineInstaller::WebContentsDestroyed(WebContents* web_contents) { 406 void WebstoreInlineInstaller::WebContentsDestroyed(WebContents* web_contents) {
407 callback_.Reset();
409 // Abort any in-progress fetches. 408 // Abort any in-progress fetches.
410 if (webstore_data_url_fetcher_.get()) { 409 if (webstore_data_url_fetcher_.get()) {
411 webstore_data_url_fetcher_.reset(); 410 webstore_data_url_fetcher_.reset();
412 Release(); // Matches the AddRef in BeginInstall. 411 Release(); // Matches the AddRef in BeginInstall.
413 } 412 }
414 } 413 }
415 414
416 void WebstoreInlineInstaller::OnExtensionInstallSuccess(const std::string& id) { 415 void WebstoreInlineInstaller::OnExtensionInstallSuccess(const std::string& id) {
417 CHECK_EQ(id_, id); 416 CHECK_EQ(id_, id);
418 CompleteInstall(""); 417 CompleteInstall("");
419 } 418 }
420 419
421 void WebstoreInlineInstaller::OnExtensionInstallFailure( 420 void WebstoreInlineInstaller::OnExtensionInstallFailure(
422 const std::string& id, const std::string& error) { 421 const std::string& id, const std::string& error) {
423 CHECK_EQ(id_, id); 422 CHECK_EQ(id_, id);
424 CompleteInstall(error); 423 CompleteInstall(error);
425 } 424 }
426 425
427 void WebstoreInlineInstaller::CompleteInstall(const std::string& error) { 426 void WebstoreInlineInstaller::CompleteInstall(const std::string& error) {
428 // Only bother responding if there's still a tab contents to send back the 427 if (!callback_.is_null())
429 // response to. 428 callback_.Run(error.empty(), error);
430 if (web_contents()) {
431 if (error.empty()) {
432 delegate_->OnInlineInstallSuccess(install_id_, return_route_id_);
433 } else {
434 delegate_->OnInlineInstallFailure(install_id_, return_route_id_, error);
435 }
436 }
437 429
438 Release(); // Matches the AddRef in BeginInstall. 430 Release(); // Matches the AddRef in BeginInstall.
439 } 431 }
440 432
441 // static 433 // static
442 bool WebstoreInlineInstaller::IsRequestorURLInVerifiedSite( 434 bool WebstoreInlineInstaller::IsRequestorURLInVerifiedSite(
443 const GURL& requestor_url, 435 const GURL& requestor_url,
444 const std::string& verified_site) { 436 const std::string& verified_site) {
445 // Turn the verified site (which may be a bare domain, or have a port and/or a 437 // Turn the verified site (which may be a bare domain, or have a port and/or a
446 // path) into a URL that can be parsed by URLPattern. 438 // path) into a URL that can be parsed by URLPattern.
(...skipping 10 matching lines...) Expand all
457 DLOG(WARNING) << "Could not parse " << verified_site_url << 449 DLOG(WARNING) << "Could not parse " << verified_site_url <<
458 " as URL pattern " << parse_result; 450 " as URL pattern " << parse_result;
459 return false; 451 return false;
460 } 452 }
461 verified_site_pattern.SetScheme("*"); 453 verified_site_pattern.SetScheme("*");
462 454
463 return verified_site_pattern.MatchesURL(requestor_url); 455 return verified_site_pattern.MatchesURL(requestor_url);
464 } 456 }
465 457
466 } // namespace extensions 458 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698