Chromium Code Reviews| Index: chrome/browser/intents/register_intent_handler_infobar_delegate.cc |
| diff --git a/chrome/browser/intents/register_intent_handler_infobar_delegate.cc b/chrome/browser/intents/register_intent_handler_infobar_delegate.cc |
| index 4c711e4c95e4a25b67708cf772a0bb007062dca7..2727cfc9e4cbc33df2c67af596454660bdcb9c97 100644 |
| --- a/chrome/browser/intents/register_intent_handler_infobar_delegate.cc |
| +++ b/chrome/browser/intents/register_intent_handler_infobar_delegate.cc |
| @@ -6,6 +6,7 @@ |
| #include "base/logging.h" |
| #include "base/utf_string_conversions.h" |
| +#include "chrome/browser/infobars/infobar_tab_helper.h" |
| #include "chrome/browser/intents/web_intents_registry.h" |
| #include "chrome/browser/intents/web_intents_registry_factory.h" |
| #include "chrome/browser/profiles/profile.h" |
| @@ -60,3 +61,51 @@ bool RegisterIntentHandlerInfoBarDelegate::LinkClicked( |
| // TODO(jhawkins): Add associated bug for the article here. |
| return false; |
| } |
| + |
| +// A trampoline for showing the infobar if it is not already registered. |
| +// Triggered by a return to a query to the WebIntentsRegistry. |
| +class IntentCheckConsumer : public WebIntentsRegistry::Consumer { |
|
James Hawkins
2011/10/05 18:37:12
Add a method to WebIntentsRegistry to check for th
Greg Billock
2011/10/05 22:19:02
Done.
|
| + public: |
| + IntentCheckConsumer(InfoBarTabHelper* infobar_helper, |
| + WebIntentsRegistry* registry, |
| + const WebIntentServiceData& service) |
| + : infobar_helper_(infobar_helper), |
| + registry_(registry), |
| + service_(service) {} |
| + virtual ~IntentCheckConsumer() {} |
| + |
| + // Gets the list of all intents for a particular action. We'll check them all |
| + // to see if this one is already registered. If it is, we bail out without |
| + // showing the infobar. If it isn't, we show the infobar. We then delete |
| + // ourselves. |
| + virtual void OnIntentsQueryDone( |
| + WebIntentsRegistry::QueryID id, |
| + const WebIntentsRegistry::IntentList& list) OVERRIDE { |
| + scoped_ptr<IntentCheckConsumer> self_deleter(this); |
| + |
| + for (WebIntentsRegistry::IntentList::const_iterator i = list.begin(); |
| + i != list.end(); ++i) { |
| + if (*i == service_) |
| + return; |
| + } |
| + |
| + infobar_helper_->AddInfoBar(new RegisterIntentHandlerInfoBarDelegate( |
| + infobar_helper_, registry_, service_)); |
| + } |
| + |
| + private: |
| + InfoBarTabHelper* infobar_helper_; |
| + WebIntentsRegistry* registry_; |
| + WebIntentServiceData service_; |
| +}; |
| + |
| +// static |
| +void RegisterIntentHandlerInfoBarDelegate::MaybeShowIntentInfoBar( |
| + InfoBarTabHelper* infobar_helper, |
| + WebIntentsRegistry* registry, |
| + const WebIntentServiceData& service) { |
| + registry->GetIntentProviders(service.action, |
| + new IntentCheckConsumer(infobar_helper, |
| + registry, |
| + service)); |
| +} |