| 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 587 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 598 } | 598 } |
| 599 } | 599 } |
| 600 | 600 |
| 601 AsyncOperationFinished(); | 601 AsyncOperationFinished(); |
| 602 } | 602 } |
| 603 | 603 |
| 604 void WebIntentPickerController::OnCWSIntentServicesAvailable( | 604 void WebIntentPickerController::OnCWSIntentServicesAvailable( |
| 605 const CWSIntentsRegistry::IntentExtensionList& extensions) { | 605 const CWSIntentsRegistry::IntentExtensionList& extensions) { |
| 606 ExtensionServiceInterface* extension_service = | 606 ExtensionServiceInterface* extension_service = |
| 607 tab_contents_->profile()->GetExtensionService(); | 607 tab_contents_->profile()->GetExtensionService(); |
| 608 |
| 609 std::vector<WebIntentPickerModel::SuggestedExtension> suggestions; |
| 608 for (size_t i = 0; i < extensions.size(); ++i) { | 610 for (size_t i = 0; i < extensions.size(); ++i) { |
| 609 const CWSIntentsRegistry::IntentExtensionInfo& info = extensions[i]; | 611 const CWSIntentsRegistry::IntentExtensionInfo& info = extensions[i]; |
| 612 |
| 613 // Do not include suggestions for already installed extensions. |
| 610 if (extension_service->GetExtensionById(UTF16ToUTF8(info.id), | 614 if (extension_service->GetExtensionById(UTF16ToUTF8(info.id), |
| 611 true)) { // Include disabled. | 615 true)) { |
| 612 continue; | 616 continue; |
| 613 } | 617 } |
| 614 | 618 |
| 615 picker_model_->AddSuggestedExtension( | 619 suggestions.push_back(WebIntentPickerModel::SuggestedExtension( |
| 616 info.name, | 620 info.name, info.id, info.average_rating)); |
| 617 info.id, | |
| 618 info.average_rating); | |
| 619 | 621 |
| 620 pending_async_count_++; | 622 pending_async_count_++; |
| 621 net::URLFetcher* icon_url_fetcher = net::URLFetcher::Create( | 623 net::URLFetcher* icon_url_fetcher = net::URLFetcher::Create( |
| 622 0, | 624 0, |
| 623 info.icon_url, | 625 info.icon_url, |
| 624 net::URLFetcher::GET, | 626 net::URLFetcher::GET, |
| 625 new URLFetcherTrampoline( | 627 new URLFetcherTrampoline( |
| 626 base::Bind( | 628 base::Bind( |
| 627 &WebIntentPickerController::OnExtensionIconURLFetchComplete, | 629 &WebIntentPickerController::OnExtensionIconURLFetchComplete, |
| 628 weak_ptr_factory_.GetWeakPtr(), info.id))); | 630 weak_ptr_factory_.GetWeakPtr(), info.id))); |
| 629 | 631 |
| 630 icon_url_fetcher->SetLoadFlags( | 632 icon_url_fetcher->SetLoadFlags( |
| 631 net::LOAD_DO_NOT_SEND_COOKIES | net::LOAD_DO_NOT_SAVE_COOKIES); | 633 net::LOAD_DO_NOT_SEND_COOKIES | net::LOAD_DO_NOT_SAVE_COOKIES); |
| 632 icon_url_fetcher->SetRequestContext( | 634 icon_url_fetcher->SetRequestContext( |
| 633 tab_contents_->profile()->GetRequestContext()); | 635 tab_contents_->profile()->GetRequestContext()); |
| 634 icon_url_fetcher->Start(); | 636 icon_url_fetcher->Start(); |
| 635 } | 637 } |
| 636 | 638 |
| 639 picker_model_->AddSuggestedExtensions(suggestions); |
| 640 |
| 637 AsyncOperationFinished(); | 641 AsyncOperationFinished(); |
| 638 } | 642 } |
| 639 | 643 |
| 640 void WebIntentPickerController::OnExtensionIconURLFetchComplete( | 644 void WebIntentPickerController::OnExtensionIconURLFetchComplete( |
| 641 const string16& extension_id, const net::URLFetcher* source) { | 645 const string16& extension_id, const net::URLFetcher* source) { |
| 642 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 646 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 643 if (source->GetResponseCode() != 200) { | 647 if (source->GetResponseCode() != 200) { |
| 644 AsyncOperationFinished(); | 648 AsyncOperationFinished(); |
| 645 return; | 649 return; |
| 646 } | 650 } |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 766 // If picker is non-NULL, it was set by a test. | 770 // If picker is non-NULL, it was set by a test. |
| 767 if (picker_ == NULL) | 771 if (picker_ == NULL) |
| 768 picker_ = WebIntentPicker::Create(tab_contents_, this, picker_model_.get()); | 772 picker_ = WebIntentPicker::Create(tab_contents_, this, picker_model_.get()); |
| 769 picker_shown_ = true; | 773 picker_shown_ = true; |
| 770 } | 774 } |
| 771 | 775 |
| 772 void WebIntentPickerController::ClosePicker() { | 776 void WebIntentPickerController::ClosePicker() { |
| 773 if (picker_) | 777 if (picker_) |
| 774 picker_->Close(); | 778 picker_->Close(); |
| 775 } | 779 } |
| OLD | NEW |