| OLD | NEW |
| 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" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 #include "chrome/browser/ui/browser_window.h" | 32 #include "chrome/browser/ui/browser_window.h" |
| 33 #include "chrome/browser/ui/constrained_window_tab_helper.h" | 33 #include "chrome/browser/ui/constrained_window_tab_helper.h" |
| 34 #include "chrome/browser/ui/intents/web_intent_picker.h" | 34 #include "chrome/browser/ui/intents/web_intent_picker.h" |
| 35 #include "chrome/browser/ui/intents/web_intent_picker_model.h" | 35 #include "chrome/browser/ui/intents/web_intent_picker_model.h" |
| 36 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 36 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| 37 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 37 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 38 #include "chrome/browser/webdata/web_data_service.h" | 38 #include "chrome/browser/webdata/web_data_service.h" |
| 39 #include "chrome/common/chrome_notification_types.h" | 39 #include "chrome/common/chrome_notification_types.h" |
| 40 #include "chrome/common/url_constants.h" | 40 #include "chrome/common/url_constants.h" |
| 41 #include "content/public/browser/browser_thread.h" | 41 #include "content/public/browser/browser_thread.h" |
| 42 #include "content/public/browser/download_manager.h" |
| 42 #include "content/public/browser/navigation_controller.h" | 43 #include "content/public/browser/navigation_controller.h" |
| 43 #include "content/public/browser/notification_source.h" | 44 #include "content/public/browser/notification_source.h" |
| 44 #include "content/public/browser/web_contents.h" | 45 #include "content/public/browser/web_contents.h" |
| 45 #include "content/public/browser/web_contents_observer.h" | 46 #include "content/public/browser/web_contents_observer.h" |
| 46 #include "content/public/browser/web_intents_dispatcher.h" | 47 #include "content/public/browser/web_intents_dispatcher.h" |
| 47 #include "grit/generated_resources.h" | 48 #include "grit/generated_resources.h" |
| 48 #include "ipc/ipc_message.h" | 49 #include "ipc/ipc_message.h" |
| 49 #include "net/base/load_flags.h" | 50 #include "net/base/load_flags.h" |
| 50 #include "net/url_request/url_fetcher.h" | 51 #include "net/url_request/url_fetcher.h" |
| 51 #include "net/url_request/url_fetcher_delegate.h" | 52 #include "net/url_request/url_fetcher_delegate.h" |
| (...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 464 } | 465 } |
| 465 | 466 |
| 466 void WebIntentPickerController::OnInlineDispositionWebContentsCreated( | 467 void WebIntentPickerController::OnInlineDispositionWebContentsCreated( |
| 467 content::WebContents* web_contents) { | 468 content::WebContents* web_contents) { |
| 468 if (web_contents) | 469 if (web_contents) |
| 469 intents_dispatcher_->DispatchIntent(web_contents); | 470 intents_dispatcher_->DispatchIntent(web_contents); |
| 470 } | 471 } |
| 471 | 472 |
| 472 void WebIntentPickerController::OnExtensionInstallRequested( | 473 void WebIntentPickerController::OnExtensionInstallRequested( |
| 473 const std::string& id) { | 474 const std::string& id) { |
| 475 picker_model_->SetPendingExtensionInstallId(id); |
| 476 |
| 474 scoped_ptr<WebstoreInstaller::Approval> approval( | 477 scoped_ptr<WebstoreInstaller::Approval> approval( |
| 475 WebstoreInstaller::Approval::CreateWithInstallPrompt(profile_)); | 478 WebstoreInstaller::Approval::CreateWithInstallPrompt(profile_)); |
| 476 | 479 |
| 477 scoped_refptr<WebstoreInstaller> installer = new WebstoreInstaller( | 480 scoped_refptr<WebstoreInstaller> installer = new WebstoreInstaller( |
| 478 profile_, this, | 481 profile_, this, |
| 479 &web_contents_->GetController(), id, | 482 &web_contents_->GetController(), id, |
| 480 approval.Pass(), WebstoreInstaller::FLAG_INLINE_INSTALL); | 483 approval.Pass(), WebstoreInstaller::FLAG_INLINE_INSTALL); |
| 481 | 484 |
| 482 pending_async_count_++; | 485 pending_async_count_++; |
| 483 installer->Start(); | 486 installer->Start(); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 521 | 524 |
| 522 void WebIntentPickerController::OnChooseAnotherService() { | 525 void WebIntentPickerController::OnChooseAnotherService() { |
| 523 DCHECK(intents_dispatcher_); | 526 DCHECK(intents_dispatcher_); |
| 524 web_intents::RecordChooseAnotherService(uma_bucket_); | 527 web_intents::RecordChooseAnotherService(uma_bucket_); |
| 525 intents_dispatcher_->ResetDispatch(); | 528 intents_dispatcher_->ResetDispatch(); |
| 526 } | 529 } |
| 527 | 530 |
| 528 void WebIntentPickerController::OnClosing() { | 531 void WebIntentPickerController::OnClosing() { |
| 529 SetDialogState(kPickerHidden); | 532 SetDialogState(kPickerHidden); |
| 530 picker_ = NULL; | 533 picker_ = NULL; |
| 534 picker_model_->ClearPendingExtensionInstall(); |
| 535 CancelDownload(); |
| 531 #if defined(TOOLKIT_VIEWS) | 536 #if defined(TOOLKIT_VIEWS) |
| 532 if (cancelled_) | 537 if (cancelled_) |
| 533 OnUserCancelledPickerDialog(); | 538 OnUserCancelledPickerDialog(); |
| 534 #endif | 539 #endif |
| 535 } | 540 } |
| 536 | 541 |
| 542 void WebIntentPickerController::OnExtensionDownloadStarted( |
| 543 const std::string& id, |
| 544 content::DownloadItem* item) { |
| 545 download_id_ = item->GetGlobalId(); |
| 546 picker_model_->UpdateExtensionDownloadState(item); |
| 547 } |
| 548 |
| 549 void WebIntentPickerController::OnExtensionDownloadProgress( |
| 550 const std::string& id, |
| 551 content::DownloadItem* item) { |
| 552 picker_model_->UpdateExtensionDownloadState(item); |
| 553 } |
| 554 |
| 537 void WebIntentPickerController::OnExtensionInstallSuccess( | 555 void WebIntentPickerController::OnExtensionInstallSuccess( |
| 538 const std::string& extension_id) { | 556 const std::string& extension_id) { |
| 539 // OnExtensionInstallSuccess is called via NotificationService::Notify before | 557 // OnExtensionInstallSuccess is called via NotificationService::Notify before |
| 540 // the extension is added to the ExtensionService. Dispatch via PostTask to | 558 // the extension is added to the ExtensionService. Dispatch via PostTask to |
| 541 // allow ExtensionService to update. | 559 // allow ExtensionService to update. |
| 542 MessageLoop::current()->PostTask( | 560 MessageLoop::current()->PostTask( |
| 543 FROM_HERE, | 561 FROM_HERE, |
| 544 base::Bind( | 562 base::Bind( |
| 545 &WebIntentPickerController::DispatchToInstalledExtension, | 563 &WebIntentPickerController::DispatchToInstalledExtension, |
| 546 base::Unretained(this), | 564 base::Unretained(this), |
| 547 extension_id)); | 565 extension_id)); |
| 548 } | 566 } |
| 549 | 567 |
| 550 void WebIntentPickerController::DispatchToInstalledExtension( | 568 void WebIntentPickerController::DispatchToInstalledExtension( |
| 551 const std::string& extension_id) { | 569 const std::string& extension_id) { |
| 552 web_intents::RecordCWSExtensionInstalled(uma_bucket_); | 570 web_intents::RecordCWSExtensionInstalled(uma_bucket_); |
| 553 picker_->OnExtensionInstallSuccess(extension_id); | 571 |
| 572 download_id_ = content::DownloadId(); |
| 573 picker_model_->ClearPendingExtensionInstall(); |
| 574 if (picker_) |
| 575 picker_->OnExtensionInstallSuccess(extension_id); |
| 576 |
| 554 WebIntentsRegistry::IntentServiceList services; | 577 WebIntentsRegistry::IntentServiceList services; |
| 555 GetWebIntentsRegistry(profile_)->GetIntentServicesForExtensionFilter( | 578 GetWebIntentsRegistry(profile_)->GetIntentServicesForExtensionFilter( |
| 556 picker_model_->action(), picker_model_->type(), | 579 picker_model_->action(), picker_model_->type(), |
| 557 extension_id, | 580 extension_id, |
| 558 &services); | 581 &services); |
| 559 | 582 |
| 560 // Extension must be registered with registry by now. | 583 // Extension must be registered with registry by now. |
| 561 DCHECK(services.size() > 0); | 584 DCHECK(services.size() > 0); |
| 562 | 585 |
| 563 // TODO(binji): We're going to need to disambiguate if there are multiple | 586 // TODO(binji): We're going to need to disambiguate if there are multiple |
| 564 // services. For now, just choose the first. | 587 // services. For now, just choose the first. |
| 565 const webkit_glue::WebIntentServiceData& service_data = services[0]; | 588 const webkit_glue::WebIntentServiceData& service_data = services[0]; |
| 566 | 589 |
| 567 picker_model_->AddInstalledService( | 590 picker_model_->AddInstalledService( |
| 568 service_data.title, service_data.service_url, | 591 service_data.title, service_data.service_url, |
| 569 service_data.disposition); | 592 service_data.disposition); |
| 570 OnServiceChosen(service_data.service_url, service_data.disposition); | 593 OnServiceChosen(service_data.service_url, service_data.disposition); |
| 571 AsyncOperationFinished(); | 594 AsyncOperationFinished(); |
| 572 } | 595 } |
| 573 | 596 |
| 574 void WebIntentPickerController::OnExtensionInstallFailure( | 597 void WebIntentPickerController::OnExtensionInstallFailure( |
| 575 const std::string& id, | 598 const std::string& id, |
| 576 const std::string& error) { | 599 const std::string& error, |
| 577 picker_->OnExtensionInstallFailure(id); | 600 WebstoreInstaller::FailureReason reason) { |
| 601 // If the user cancelled the install then don't show an error message. |
| 602 if (reason == WebstoreInstaller::FAILURE_REASON_CANCELLED) |
| 603 picker_model_->ClearPendingExtensionInstall(); |
| 604 else |
| 605 picker_model_->SetPendingExtensionInstallStatusString(UTF8ToUTF16(error)); |
| 606 |
| 607 if (picker_) |
| 608 picker_->OnExtensionInstallFailure(id); |
| 578 AsyncOperationFinished(); | 609 AsyncOperationFinished(); |
| 579 } | 610 } |
| 580 | 611 |
| 581 void WebIntentPickerController::OnSendReturnMessage( | 612 void WebIntentPickerController::OnSendReturnMessage( |
| 582 webkit_glue::WebIntentReplyType reply_type) { | 613 webkit_glue::WebIntentReplyType reply_type) { |
| 583 ClosePicker(); | 614 ClosePicker(); |
| 584 uma_reporter_->RecordServiceActiveDuration(reply_type); | 615 uma_reporter_->RecordServiceActiveDuration(reply_type); |
| 585 | 616 |
| 586 if (service_tab_ && | 617 if (service_tab_ && |
| 587 reply_type != webkit_glue::WEB_INTENT_SERVICE_CONTENTS_CLOSED) { | 618 reply_type != webkit_glue::WEB_INTENT_SERVICE_CONTENTS_CLOSED) { |
| (...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1057 web_intents::RecordPickerShow( | 1088 web_intents::RecordPickerShow( |
| 1058 uma_bucket_, picker_model_->GetInstalledServiceCount()); | 1089 uma_bucket_, picker_model_->GetInstalledServiceCount()); |
| 1059 picker_shown_ = true; | 1090 picker_shown_ = true; |
| 1060 } | 1091 } |
| 1061 | 1092 |
| 1062 void WebIntentPickerController::ClosePicker() { | 1093 void WebIntentPickerController::ClosePicker() { |
| 1063 SetDialogState(kPickerHidden); | 1094 SetDialogState(kPickerHidden); |
| 1064 if (picker_) | 1095 if (picker_) |
| 1065 picker_->Close(); | 1096 picker_->Close(); |
| 1066 } | 1097 } |
| 1098 |
| 1099 void WebIntentPickerController::CancelDownload() { |
| 1100 if (!download_id_.IsValid()) |
| 1101 return; |
| 1102 Profile* profile = |
| 1103 Profile::FromBrowserContext(web_contents_->GetBrowserContext()); |
| 1104 content::DownloadManager* download_manager = |
| 1105 content::BrowserContext::GetDownloadManager(profile); |
| 1106 if (!download_manager) |
| 1107 return; |
| 1108 content::DownloadItem* item = |
| 1109 download_manager->GetDownload(download_id_.local()); |
| 1110 if (item) |
| 1111 item->Cancel(true); |
| 1112 download_id_ = content::DownloadId(); |
| 1113 } |
| OLD | NEW |