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 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
410 | 410 |
411 intents_dispatcher_->ResetDispatch(); | 411 intents_dispatcher_->ResetDispatch(); |
412 } | 412 } |
413 | 413 |
414 void WebIntentPickerController::OnClosing() { | 414 void WebIntentPickerController::OnClosing() { |
415 picker_shown_ = false; | 415 picker_shown_ = false; |
416 picker_ = NULL; | 416 picker_ = NULL; |
417 } | 417 } |
418 | 418 |
419 void WebIntentPickerController::OnExtensionInstallSuccess( | 419 void WebIntentPickerController::OnExtensionInstallSuccess( |
420 const std::string& id) { | 420 const std::string& extension_id) { |
421 picker_->OnExtensionInstallSuccess(id); | 421 // OnExtensionInstallSuccess is called via NotificationService::Notify before |
422 pending_async_count_++; | 422 // the extension is added to the ExtensionService. Dispatch via PostTask to |
| 423 // allow ExtensionService to update. |
| 424 MessageLoop::current()->PostTask( |
| 425 FROM_HERE, |
| 426 base::Bind( |
| 427 &WebIntentPickerController::DispatchToInstalledExtension, |
| 428 base::Unretained(this), |
| 429 extension_id)); |
| 430 } |
| 431 |
| 432 void WebIntentPickerController::DispatchToInstalledExtension( |
| 433 const std::string& extension_id) { |
| 434 picker_->OnExtensionInstallSuccess(extension_id); |
| 435 WebIntentsRegistry::IntentServiceList services; |
423 GetWebIntentsRegistry(tab_contents_)->GetIntentServicesForExtensionFilter( | 436 GetWebIntentsRegistry(tab_contents_)->GetIntentServicesForExtensionFilter( |
424 picker_model_->action(), | 437 picker_model_->action(), picker_model_->mimetype(), |
425 picker_model_->mimetype(), | 438 extension_id, |
426 id, | 439 &services); |
427 base::Bind( | 440 |
428 &WebIntentPickerController::OnExtensionInstallServiceAvailable, | 441 // Extension must be registered with registry by now. |
429 weak_ptr_factory_.GetWeakPtr())); | 442 DCHECK(services.size() > 0); |
| 443 |
| 444 // TODO(binji): We're going to need to disambiguate if there are multiple |
| 445 // services. For now, just choose the first. |
| 446 const webkit_glue::WebIntentServiceData& service_data = services[0]; |
| 447 |
| 448 picker_model_->AddInstalledService( |
| 449 service_data.title, service_data.service_url, |
| 450 ConvertDisposition(service_data.disposition)); |
| 451 OnServiceChosen( |
| 452 service_data.service_url, |
| 453 ConvertDisposition(service_data.disposition)); |
430 AsyncOperationFinished(); | 454 AsyncOperationFinished(); |
431 } | 455 } |
432 | 456 |
433 void WebIntentPickerController::OnExtensionInstallFailure( | 457 void WebIntentPickerController::OnExtensionInstallFailure( |
434 const std::string& id, | 458 const std::string& id, |
435 const std::string& error) { | 459 const std::string& error) { |
436 picker_->OnExtensionInstallFailure(id); | 460 picker_->OnExtensionInstallFailure(id); |
437 AsyncOperationFinished(); | 461 AsyncOperationFinished(); |
438 } | 462 } |
439 | 463 |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
723 | 747 |
724 void WebIntentPickerController::SourceDispatcherReplied( | 748 void WebIntentPickerController::SourceDispatcherReplied( |
725 webkit_glue::WebIntentReplyType reply_type) { | 749 webkit_glue::WebIntentReplyType reply_type) { |
726 source_intents_dispatcher_ = NULL; | 750 source_intents_dispatcher_ = NULL; |
727 } | 751 } |
728 | 752 |
729 bool WebIntentPickerController::ShowLocationBarPickerTool() { | 753 bool WebIntentPickerController::ShowLocationBarPickerTool() { |
730 return window_disposition_source_ || source_intents_dispatcher_; | 754 return window_disposition_source_ || source_intents_dispatcher_; |
731 } | 755 } |
732 | 756 |
733 void WebIntentPickerController::OnExtensionInstallServiceAvailable( | |
734 const std::vector<webkit_glue::WebIntentServiceData>& services) { | |
735 DCHECK(services.size() > 0); | |
736 | |
737 // TODO(binji): We're going to need to disambiguate if there are multiple | |
738 // services. For now, just choose the first. | |
739 const webkit_glue::WebIntentServiceData& service_data = services[0]; | |
740 picker_model_->AddInstalledService( | |
741 service_data.title, service_data.service_url, | |
742 ConvertDisposition(service_data.disposition)); | |
743 OnServiceChosen( | |
744 service_data.service_url, | |
745 ConvertDisposition(service_data.disposition)); | |
746 AsyncOperationFinished(); | |
747 } | |
748 | |
749 void WebIntentPickerController::AsyncOperationFinished() { | 757 void WebIntentPickerController::AsyncOperationFinished() { |
750 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 758 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
751 if (--pending_async_count_ == 0) { | 759 if (--pending_async_count_ == 0) { |
752 if (picker_) | 760 if (picker_) |
753 picker_->OnPendingAsyncCompleted(); | 761 picker_->OnPendingAsyncCompleted(); |
754 } | 762 } |
755 } | 763 } |
756 | 764 |
757 void WebIntentPickerController::CreatePicker() { | 765 void WebIntentPickerController::CreatePicker() { |
758 // If picker is non-NULL, it was set by a test. | 766 // If picker is non-NULL, it was set by a test. |
759 if (picker_ == NULL) | 767 if (picker_ == NULL) |
760 picker_ = WebIntentPicker::Create(tab_contents_, this, picker_model_.get()); | 768 picker_ = WebIntentPicker::Create(tab_contents_, this, picker_model_.get()); |
761 picker_shown_ = true; | 769 picker_shown_ = true; |
762 } | 770 } |
763 | 771 |
764 void WebIntentPickerController::ClosePicker() { | 772 void WebIntentPickerController::ClosePicker() { |
765 if (picker_) | 773 if (picker_) |
766 picker_->Close(); | 774 picker_->Close(); |
767 } | 775 } |
OLD | NEW |