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

Side by Side Diff: chrome/browser/ui/intents/web_intent_picker_controller.cc

Issue 10980002: Mac Web Intents Part 1: Show extension download progress (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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/ui/intents/web_intent_picker_controller.h" 5 #include "chrome/browser/ui/intents/web_intent_picker_controller.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
11 #include "base/md5.h" 11 #include "base/md5.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/time.h" 13 #include "base/time.h"
14 #include "base/utf_string_conversions.h" 14 #include "base/utf_string_conversions.h"
15 #include "chrome/browser/download/download_item_model.h"
16 #include "chrome/browser/download/download_util.h"
15 #include "chrome/browser/extensions/extension_service.h" 17 #include "chrome/browser/extensions/extension_service.h"
16 #include "chrome/browser/extensions/platform_app_launcher.h" 18 #include "chrome/browser/extensions/platform_app_launcher.h"
17 #include "chrome/browser/extensions/webstore_installer.h" 19 #include "chrome/browser/extensions/webstore_installer.h"
18 #include "chrome/browser/favicon/favicon_service.h" 20 #include "chrome/browser/favicon/favicon_service.h"
19 #include "chrome/browser/favicon/favicon_service_factory.h" 21 #include "chrome/browser/favicon/favicon_service_factory.h"
20 #include "chrome/browser/intents/cws_intents_registry_factory.h" 22 #include "chrome/browser/intents/cws_intents_registry_factory.h"
21 #include "chrome/browser/intents/default_web_intent_service.h" 23 #include "chrome/browser/intents/default_web_intent_service.h"
22 #include "chrome/browser/intents/web_intents_registry_factory.h" 24 #include "chrome/browser/intents/web_intents_registry_factory.h"
23 #include "chrome/browser/intents/web_intents_reporting.h" 25 #include "chrome/browser/intents/web_intents_reporting.h"
24 #include "chrome/browser/intents/web_intents_util.h" 26 #include "chrome/browser/intents/web_intents_util.h"
25 #include "chrome/browser/profiles/profile.h" 27 #include "chrome/browser/profiles/profile.h"
26 #include "chrome/browser/tab_contents/tab_util.h" 28 #include "chrome/browser/tab_contents/tab_util.h"
27 #include "chrome/browser/ui/browser.h" 29 #include "chrome/browser/ui/browser.h"
28 #include "chrome/browser/ui/browser_finder.h" 30 #include "chrome/browser/ui/browser_finder.h"
29 #include "chrome/browser/ui/browser_list.h" 31 #include "chrome/browser/ui/browser_list.h"
30 #include "chrome/browser/ui/browser_navigator.h" 32 #include "chrome/browser/ui/browser_navigator.h"
31 #include "chrome/browser/ui/browser_tabstrip.h" 33 #include "chrome/browser/ui/browser_tabstrip.h"
32 #include "chrome/browser/ui/browser_window.h" 34 #include "chrome/browser/ui/browser_window.h"
33 #include "chrome/browser/ui/constrained_window_tab_helper.h" 35 #include "chrome/browser/ui/constrained_window_tab_helper.h"
34 #include "chrome/browser/ui/intents/web_intent_picker.h" 36 #include "chrome/browser/ui/intents/web_intent_picker.h"
35 #include "chrome/browser/ui/intents/web_intent_picker_model.h" 37 #include "chrome/browser/ui/intents/web_intent_picker_model.h"
36 #include "chrome/browser/ui/tab_contents/tab_contents.h" 38 #include "chrome/browser/ui/tab_contents/tab_contents.h"
37 #include "chrome/browser/ui/tabs/tab_strip_model.h" 39 #include "chrome/browser/ui/tabs/tab_strip_model.h"
38 #include "chrome/browser/webdata/web_data_service.h" 40 #include "chrome/browser/webdata/web_data_service.h"
39 #include "chrome/common/chrome_notification_types.h" 41 #include "chrome/common/chrome_notification_types.h"
40 #include "chrome/common/url_constants.h" 42 #include "chrome/common/url_constants.h"
41 #include "content/public/browser/browser_thread.h" 43 #include "content/public/browser/browser_thread.h"
44 #include "content/public/browser/download_manager.h"
42 #include "content/public/browser/navigation_controller.h" 45 #include "content/public/browser/navigation_controller.h"
43 #include "content/public/browser/notification_source.h" 46 #include "content/public/browser/notification_source.h"
44 #include "content/public/browser/web_contents.h" 47 #include "content/public/browser/web_contents.h"
45 #include "content/public/browser/web_contents_observer.h" 48 #include "content/public/browser/web_contents_observer.h"
46 #include "content/public/browser/web_intents_dispatcher.h" 49 #include "content/public/browser/web_intents_dispatcher.h"
47 #include "grit/generated_resources.h" 50 #include "grit/generated_resources.h"
48 #include "ipc/ipc_message.h" 51 #include "ipc/ipc_message.h"
49 #include "net/base/load_flags.h" 52 #include "net/base/load_flags.h"
50 #include "net/url_request/url_fetcher.h" 53 #include "net/url_request/url_fetcher.h"
51 #include "net/url_request/url_fetcher_delegate.h" 54 #include "net/url_request/url_fetcher_delegate.h"
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 } 465 }
463 466
464 void WebIntentPickerController::OnInlineDispositionWebContentsCreated( 467 void WebIntentPickerController::OnInlineDispositionWebContentsCreated(
465 content::WebContents* web_contents) { 468 content::WebContents* web_contents) {
466 if (web_contents) 469 if (web_contents)
467 intents_dispatcher_->DispatchIntent(web_contents); 470 intents_dispatcher_->DispatchIntent(web_contents);
468 } 471 }
469 472
470 void WebIntentPickerController::OnExtensionInstallRequested( 473 void WebIntentPickerController::OnExtensionInstallRequested(
471 const std::string& id) { 474 const std::string& id) {
475 picker_model_->SetPendingInstallExtensionId(id);
Greg Billock 2012/09/25 07:15:46 Needed? I don't see where this is used.
Greg Billock 2012/10/02 03:02:29 Now used?
sail 2012/10/02 18:57:01 Yea, used here: http://codereview.chromium.org/110
476
472 scoped_ptr<WebstoreInstaller::Approval> approval( 477 scoped_ptr<WebstoreInstaller::Approval> approval(
473 WebstoreInstaller::Approval::CreateWithInstallPrompt( 478 WebstoreInstaller::Approval::CreateWithInstallPrompt(
474 tab_contents_->profile())); 479 tab_contents_->profile()));
475 480
476 scoped_refptr<WebstoreInstaller> installer = new WebstoreInstaller( 481 scoped_refptr<WebstoreInstaller> installer = new WebstoreInstaller(
477 tab_contents_->profile(), this, 482 tab_contents_->profile(), this,
478 &tab_contents_->web_contents()->GetController(), id, 483 &tab_contents_->web_contents()->GetController(), id,
479 approval.Pass(), WebstoreInstaller::FLAG_INLINE_INSTALL); 484 approval.Pass(), WebstoreInstaller::FLAG_INLINE_INSTALL);
480 485
481 pending_async_count_++; 486 pending_async_count_++;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
520 525
521 void WebIntentPickerController::OnChooseAnotherService() { 526 void WebIntentPickerController::OnChooseAnotherService() {
522 DCHECK(intents_dispatcher_); 527 DCHECK(intents_dispatcher_);
523 web_intents::RecordChooseAnotherService(uma_bucket_); 528 web_intents::RecordChooseAnotherService(uma_bucket_);
524 intents_dispatcher_->ResetDispatch(); 529 intents_dispatcher_->ResetDispatch();
525 } 530 }
526 531
527 void WebIntentPickerController::OnClosing() { 532 void WebIntentPickerController::OnClosing() {
528 SetDialogState(kPickerHidden); 533 SetDialogState(kPickerHidden);
529 picker_ = NULL; 534 picker_ = NULL;
535 CancelDownload();
530 #if defined(TOOLKIT_VIEWS) 536 #if defined(TOOLKIT_VIEWS)
531 if (cancelled_) 537 if (cancelled_)
532 OnUserCancelledPickerDialog(); 538 OnUserCancelledPickerDialog();
533 #endif 539 #endif
534 } 540 }
535 541
542 void WebIntentPickerController::OnExtensionDownloadStarted(
543 const std::string& id,
544 content::DownloadItem* item) {
545 download_util::SetShouldShowInShelf(item, false);
Nico 2012/09/25 03:07:18 From what I understand, this relies on this notifi
asanka 2012/09/25 16:29:30 The ordering is: 1. DownloadManager::OnDownloadCre
Steve McKay 2012/09/25 18:56:04 What if we flipped the perspective a bit and start
Greg Billock 2012/10/02 19:20:38 When we use a separate RequestHandler for intents,
546 download_id_ = item->GetGlobalId();
547 UpdateDownloadState(id, item);
548 }
549
550 void WebIntentPickerController::OnExtensionDownloadProgress(
551 const std::string& id,
552 content::DownloadItem* item) {
553 UpdateDownloadState(id, item);
554 }
555
536 void WebIntentPickerController::OnExtensionInstallSuccess( 556 void WebIntentPickerController::OnExtensionInstallSuccess(
537 const std::string& extension_id) { 557 const std::string& extension_id) {
538 // OnExtensionInstallSuccess is called via NotificationService::Notify before 558 // OnExtensionInstallSuccess is called via NotificationService::Notify before
539 // the extension is added to the ExtensionService. Dispatch via PostTask to 559 // the extension is added to the ExtensionService. Dispatch via PostTask to
540 // allow ExtensionService to update. 560 // allow ExtensionService to update.
541 MessageLoop::current()->PostTask( 561 MessageLoop::current()->PostTask(
542 FROM_HERE, 562 FROM_HERE,
543 base::Bind( 563 base::Bind(
544 &WebIntentPickerController::DispatchToInstalledExtension, 564 &WebIntentPickerController::DispatchToInstalledExtension,
545 base::Unretained(this), 565 base::Unretained(this),
546 extension_id)); 566 extension_id));
547 } 567 }
548 568
549 void WebIntentPickerController::DispatchToInstalledExtension( 569 void WebIntentPickerController::DispatchToInstalledExtension(
550 const std::string& extension_id) { 570 const std::string& extension_id) {
551 web_intents::RecordCWSExtensionInstalled(uma_bucket_); 571 web_intents::RecordCWSExtensionInstalled(uma_bucket_);
552 picker_->OnExtensionInstallSuccess(extension_id); 572
573 download_id_ = content::DownloadId();
574 picker_model_->ClearPendingInstall();
575 if (picker_)
groby-ooo-7-16 2012/09/25 22:20:56 nit: This should never be NULL. Can we just DCHECK
sail 2012/10/02 18:57:01 Unfortunately there's this function is called asyn
576 picker_->OnExtensionInstallSuccess(extension_id);
577
553 WebIntentsRegistry::IntentServiceList services; 578 WebIntentsRegistry::IntentServiceList services;
554 GetWebIntentsRegistry(tab_contents_)->GetIntentServicesForExtensionFilter( 579 GetWebIntentsRegistry(tab_contents_)->GetIntentServicesForExtensionFilter(
555 picker_model_->action(), picker_model_->type(), 580 picker_model_->action(), picker_model_->type(),
556 extension_id, 581 extension_id,
557 &services); 582 &services);
558 583
559 // Extension must be registered with registry by now. 584 // Extension must be registered with registry by now.
560 DCHECK(services.size() > 0); 585 DCHECK(services.size() > 0);
561 586
562 // TODO(binji): We're going to need to disambiguate if there are multiple 587 // TODO(binji): We're going to need to disambiguate if there are multiple
563 // services. For now, just choose the first. 588 // services. For now, just choose the first.
564 const webkit_glue::WebIntentServiceData& service_data = services[0]; 589 const webkit_glue::WebIntentServiceData& service_data = services[0];
565 590
566 picker_model_->AddInstalledService( 591 picker_model_->AddInstalledService(
567 service_data.title, service_data.service_url, 592 service_data.title, service_data.service_url,
568 service_data.disposition); 593 service_data.disposition);
569 OnServiceChosen(service_data.service_url, service_data.disposition); 594 OnServiceChosen(service_data.service_url, service_data.disposition);
570 AsyncOperationFinished(); 595 AsyncOperationFinished();
571 } 596 }
572 597
573 void WebIntentPickerController::OnExtensionInstallFailure( 598 void WebIntentPickerController::OnExtensionInstallFailure(
574 const std::string& id, 599 const std::string& id,
575 const std::string& error) { 600 const std::string& error,
576 picker_->OnExtensionInstallFailure(id); 601 bool cancelled) {
602 CancelDownload();
asanka 2012/09/25 16:29:30 Why call CancelDownload() here?
sail 2012/10/02 18:57:01 For example, if we weren't able to unpack the exte
603 // If the user cancelled the install then don't show an error message.
Nico 2012/09/25 03:07:18 nit: canceled
sail 2012/10/02 18:57:01 Weird, it looks like we use both in chrome/*: dhcp
604 if (cancelled)
605 picker_model_->ClearPendingInstall();
606 else
607 picker_model_->SetPendingInstallStatusString(UTF8ToUTF16(error));
608
609 if (picker_)
610 picker_->OnExtensionInstallFailure(id);
577 AsyncOperationFinished(); 611 AsyncOperationFinished();
578 } 612 }
579 613
580 void WebIntentPickerController::OnSendReturnMessage( 614 void WebIntentPickerController::OnSendReturnMessage(
581 webkit_glue::WebIntentReplyType reply_type) { 615 webkit_glue::WebIntentReplyType reply_type) {
582 ClosePicker(); 616 ClosePicker();
583 uma_reporter_->RecordServiceActiveDuration(reply_type); 617 uma_reporter_->RecordServiceActiveDuration(reply_type);
584 618
585 if (service_tab_ && 619 if (service_tab_ &&
586 reply_type != webkit_glue::WEB_INTENT_SERVICE_CONTENTS_CLOSED) { 620 reply_type != webkit_glue::WEB_INTENT_SERVICE_CONTENTS_CLOSED) {
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after
1055 web_intents::RecordPickerShow( 1089 web_intents::RecordPickerShow(
1056 uma_bucket_, picker_model_->GetInstalledServiceCount()); 1090 uma_bucket_, picker_model_->GetInstalledServiceCount());
1057 picker_shown_ = true; 1091 picker_shown_ = true;
1058 } 1092 }
1059 1093
1060 void WebIntentPickerController::ClosePicker() { 1094 void WebIntentPickerController::ClosePicker() {
1061 SetDialogState(kPickerHidden); 1095 SetDialogState(kPickerHidden);
1062 if (picker_) 1096 if (picker_)
1063 picker_->Close(); 1097 picker_->Close();
1064 } 1098 }
1099
1100 void WebIntentPickerController::UpdateDownloadState(
Steve McKay 2012/09/25 18:56:04 Feels like this entire method should be pushed int
sail 2012/10/02 18:57:01 Done.
1101 const std::string& id,
1102 content::DownloadItem* item) {
1103 picker_model_->SetPendingInstallDownloadPercent(item->PercentComplete());
1104 DownloadItemModel download_model(item);
1105 picker_model_->SetPendingInstallStatusString(download_model.GetStatusText());
1106 }
1107
1108 void WebIntentPickerController::CancelDownload() {
Steve McKay 2012/09/25 18:56:04 CancelExtensionDownload Does the picker model nee
sail 2012/10/02 18:57:01 Done. This used to be in the caller code. Moved to
1109 if (!download_id_.IsValid())
1110 return;
1111 content::DownloadManager* download_manager =
1112 content::BrowserContext::GetDownloadManager(tab_contents_->profile());
1113 if (!download_manager)
1114 return;
1115 content::DownloadItem* item =
1116 download_manager->GetDownload(download_id_.local());
1117 if (item)
1118 item->Cancel(true);
1119 download_id_ = content::DownloadId();
1120 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698