Index: chrome/browser/ui/intents/web_intent_picker_controller.cc |
diff --git a/chrome/browser/ui/intents/web_intent_picker_controller.cc b/chrome/browser/ui/intents/web_intent_picker_controller.cc |
index 2f372045f44e1782c09d7b125922b10dee17f34a..04d5dfc8f3f333e0e178bd16bf8cd5436e0244dd 100644 |
--- a/chrome/browser/ui/intents/web_intent_picker_controller.cc |
+++ b/chrome/browser/ui/intents/web_intent_picker_controller.cc |
@@ -8,7 +8,7 @@ |
#include "base/bind.h" |
#include "base/bind_helpers.h" |
-#include "chrome/browser/ui/browser.h" |
+#include "chrome/browser/extensions/webstore_installer.h" |
#include "chrome/browser/favicon/favicon_service.h" |
#include "chrome/browser/intents/default_web_intent_service.h" |
#include "chrome/browser/intents/web_intents_registry_factory.h" |
@@ -16,6 +16,7 @@ |
#include "chrome/browser/profiles/profile.h" |
#include "chrome/browser/tab_contents/tab_util.h" |
#include "chrome/browser/tabs/tab_strip_model.h" |
+#include "chrome/browser/ui/browser.h" |
#include "chrome/browser/ui/browser_list.h" |
#include "chrome/browser/ui/browser_navigator.h" |
#include "chrome/browser/ui/intents/web_intent_picker.h" |
@@ -24,6 +25,7 @@ |
#include "chrome/browser/webdata/web_data_service.h" |
#include "chrome/common/chrome_notification_types.h" |
#include "content/public/browser/browser_thread.h" |
+#include "content/public/browser/navigation_controller.h" |
#include "content/public/browser/notification_source.h" |
#include "content/public/browser/web_contents.h" |
#include "content/public/browser/web_intents_dispatcher.h" |
@@ -66,25 +68,73 @@ WebIntentPickerModel::Disposition ConvertDisposition( |
} |
} |
+// WebIntentsRegistryTrampoline ----------------------------------------------- |
James Hawkins
2012/03/15 01:05:20
Kill this line, preferably via fire.
binji
2012/03/15 17:53:14
Done.
|
+ |
+class WebIntentsRegistryTrampoline : public WebIntentsRegistry::Consumer { |
James Hawkins
2012/03/15 01:05:20
Document the class.
binji
2012/03/15 17:53:14
Done.
|
+ public: |
+ typedef std::vector<webkit_glue::WebIntentServiceData> IntentServices; |
+ typedef base::Callback<void(const IntentServices&)> Callback; |
James Hawkins
2012/03/15 01:05:20
Pick a less generic name than Callback.
binji
2012/03/15 17:53:14
Done.
|
+ |
+ explicit WebIntentsRegistryTrampoline(const Callback& callback); |
James Hawkins
2012/03/15 01:05:20
|callback| must not be null?
binji
2012/03/15 17:53:14
Done.
|
+ ~WebIntentsRegistryTrampoline(); |
+ |
+ // WebIntentsRegistry::Consumer implementation. |
+ virtual void OnIntentsQueryDone( |
+ WebIntentsRegistry::QueryID, |
+ const std::vector<webkit_glue::WebIntentServiceData>& services) OVERRIDE; |
+ virtual void OnIntentsDefaultsQueryDone( |
+ WebIntentsRegistry::QueryID, |
+ const DefaultWebIntentService& default_service) OVERRIDE {} |
+ |
+ private: |
+ Callback callback_; |
James Hawkins
2012/03/15 01:05:20
Document member variable.
binji
2012/03/15 17:53:14
Done.
|
+}; |
+ |
+WebIntentsRegistryTrampoline::WebIntentsRegistryTrampoline( |
+ const Callback& callback) |
+ : callback_(callback) { |
+} |
+ |
+WebIntentsRegistryTrampoline::~WebIntentsRegistryTrampoline() { |
+} |
+ |
+void WebIntentsRegistryTrampoline::OnIntentsQueryDone( |
+ WebIntentsRegistry::QueryID, |
+ const std::vector<webkit_glue::WebIntentServiceData>& services) { |
+ callback_.Run(services); |
+ delete this; |
+} |
+ |
+// URLFetcherTrampoline ------------------------------------------------------- |
+ |
class URLFetcherTrampoline : public content::URLFetcherDelegate { |
public: |
typedef base::Callback<void(const content::URLFetcher* source)> Callback; |
- explicit URLFetcherTrampoline(const Callback& callback) |
- : callback_(callback) {} |
- ~URLFetcherTrampoline() {} |
+ explicit URLFetcherTrampoline(const Callback& callback); |
+ ~URLFetcherTrampoline(); |
// content::URLFetcherDelegate implementation. |
- virtual void OnURLFetchComplete(const content::URLFetcher* source) OVERRIDE { |
- callback_.Run(source); |
- delete source; |
- delete this; |
- } |
+ virtual void OnURLFetchComplete(const content::URLFetcher* source) OVERRIDE; |
private: |
Callback callback_; |
}; |
+URLFetcherTrampoline::URLFetcherTrampoline(const Callback& callback) |
+ : callback_(callback) { |
+} |
+ |
+URLFetcherTrampoline::~URLFetcherTrampoline() { |
+} |
+ |
+void URLFetcherTrampoline::OnURLFetchComplete( |
+ const content::URLFetcher* source) { |
+ callback_.Run(source); |
+ delete source; |
+ delete this; |
+} |
+ |
} // namespace |
WebIntentPickerController::WebIntentPickerController( |
@@ -124,6 +174,8 @@ void WebIntentPickerController::ShowDialog(Browser* browser, |
return; |
picker_model_->Clear(); |
+ picker_model_->set_action(action); |
+ picker_model_->set_mimetype(type); |
// If picker is non-NULL, it was set by a test. |
if (picker_ == NULL) { |
@@ -133,8 +185,13 @@ void WebIntentPickerController::ShowDialog(Browser* browser, |
picker_shown_ = true; |
pending_async_count_+= 2; |
- GetWebIntentsRegistry(wrapper_)->GetIntentServices(action, type, this); |
- GetCWSIntentsRegistry(wrapper_)->GetIntentServices(action, type, |
+ GetWebIntentsRegistry(wrapper_)->GetIntentServices( |
+ action, type, |
+ new WebIntentsRegistryTrampoline( |
James Hawkins
2012/03/15 01:05:20
Document ownership.
binji
2012/03/15 17:53:14
Done.
|
+ base::Bind(&WebIntentPickerController::OnWebIntentServicesAvailable, |
+ weak_ptr_factory_.GetWeakPtr()))); |
+ GetCWSIntentsRegistry(wrapper_)->GetIntentServices( |
+ action, type, |
base::Bind(&WebIntentPickerController::OnCWSIntentServicesAvailable, |
weak_ptr_factory_.GetWeakPtr())); |
} |
@@ -207,6 +264,19 @@ void WebIntentPickerController::OnInlineDispositionWebContentsCreated( |
intents_dispatcher_->DispatchIntent(web_contents); |
} |
+void WebIntentPickerController::OnExtensionInstallRequested( |
+ const std::string& id) { |
+ webstore_installer_ = new WebstoreInstaller( |
+ wrapper_->profile(), |
James Hawkins
2012/03/15 01:05:20
Save rows by collapsing these parameters.
binji
2012/03/15 17:53:14
Done.
|
+ this, |
+ &wrapper_->web_contents()->GetController(), |
+ id, |
+ WebstoreInstaller::FLAG_INLINE_INSTALL); |
+ |
+ pending_async_count_++; |
+ webstore_installer_->Start(); |
+} |
+ |
void WebIntentPickerController::OnCancelled() { |
if (!intents_dispatcher_) |
return; |
@@ -227,6 +297,28 @@ void WebIntentPickerController::OnClosing() { |
picker_ = NULL; |
} |
+void WebIntentPickerController::OnExtensionInstallSuccess( |
+ const std::string& id) { |
+ picker_->OnExtensionInstallSuccess(id); |
+ pending_async_count_++; |
+ GetWebIntentsRegistry(wrapper_)->GetIntentServicesWithExtensionId( |
+ picker_model_->action(), |
+ picker_model_->mimetype(), |
+ id, |
+ new WebIntentsRegistryTrampoline( |
+ base::Bind( |
+ &WebIntentPickerController::OnExtensionInstallServiceAvailable, |
+ weak_ptr_factory_.GetWeakPtr()))); |
+ AsyncOperationFinished(); |
+} |
+ |
+void WebIntentPickerController::OnExtensionInstallFailure( |
+ const std::string& id, |
+ const std::string& error) { |
+ picker_->OnExtensionInstallFailure(id); |
+ AsyncOperationFinished(); |
+} |
+ |
void WebIntentPickerController::OnSendReturnMessage( |
webkit_glue::WebIntentReplyType reply_type) { |
ClosePicker(); |
@@ -255,8 +347,7 @@ void WebIntentPickerController::OnSendReturnMessage( |
intents_dispatcher_ = NULL; |
} |
-void WebIntentPickerController::OnIntentsQueryDone( |
- WebIntentsRegistry::QueryID, |
+void WebIntentPickerController::OnWebIntentServicesAvailable( |
const std::vector<webkit_glue::WebIntentServiceData>& services) { |
FaviconService* favicon_service = GetFaviconService(wrapper_); |
for (size_t i = 0; i < services.size(); ++i) { |
@@ -279,11 +370,6 @@ void WebIntentPickerController::OnIntentsQueryDone( |
AsyncOperationFinished(); |
} |
-void WebIntentPickerController::OnIntentsDefaultsQueryDone( |
- WebIntentsRegistry::QueryID, |
- const DefaultWebIntentService& default_service) { |
-} |
- |
void WebIntentPickerController::OnFaviconDataAvailable( |
FaviconService::Handle handle, history::FaviconData favicon_data) { |
size_t index = favicon_consumer_.GetClientDataForCurrentRequest(); |
@@ -416,6 +502,19 @@ void WebIntentPickerController::OnExtensionIconUnavailable( |
AsyncOperationFinished(); |
} |
+void WebIntentPickerController::OnExtensionInstallServiceAvailable( |
+ const std::vector<webkit_glue::WebIntentServiceData>& services) { |
James Hawkins
2012/03/15 01:05:20
Document in the header that |services| must be a n
binji
2012/03/15 17:53:14
Done.
|
+ DCHECK(services.size() > 0); |
+ |
+ // TODO(binji): We're going to need to disambiguate if there are multiple |
+ // services. For now, just choose the first. |
+ const webkit_glue::WebIntentServiceData& service_data = services[0]; |
+ OnServiceChosen( |
+ service_data.service_url, |
+ ConvertDisposition(service_data.disposition)); |
+ AsyncOperationFinished(); |
+} |
+ |
void WebIntentPickerController::AsyncOperationFinished() { |
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
if (--pending_async_count_ == 0) { |