Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/intents/register_intent_handler_infobar_delegate.h" | 5 #include "chrome/browser/intents/register_intent_handler_infobar_delegate.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "chrome/browser/infobars/infobar_tab_helper.h" | |
| 9 #include "chrome/browser/intents/web_intents_registry.h" | 10 #include "chrome/browser/intents/web_intents_registry.h" |
| 10 #include "chrome/browser/intents/web_intents_registry_factory.h" | 11 #include "chrome/browser/intents/web_intents_registry_factory.h" |
| 11 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
| 12 #include "grit/generated_resources.h" | 13 #include "grit/generated_resources.h" |
| 13 #include "ui/base/l10n/l10n_util.h" | 14 #include "ui/base/l10n/l10n_util.h" |
| 14 | 15 |
| 15 RegisterIntentHandlerInfoBarDelegate::RegisterIntentHandlerInfoBarDelegate( | 16 RegisterIntentHandlerInfoBarDelegate::RegisterIntentHandlerInfoBarDelegate( |
| 16 InfoBarTabHelper* infobar_helper, | 17 InfoBarTabHelper* infobar_helper, |
| 17 WebIntentsRegistry* registry, | 18 WebIntentsRegistry* registry, |
| 18 const WebIntentServiceData& service) | 19 const WebIntentServiceData& service) |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 53 return l10n_util::GetStringUTF16(IDS_LEARN_MORE); | 54 return l10n_util::GetStringUTF16(IDS_LEARN_MORE); |
| 54 } | 55 } |
| 55 | 56 |
| 56 bool RegisterIntentHandlerInfoBarDelegate::LinkClicked( | 57 bool RegisterIntentHandlerInfoBarDelegate::LinkClicked( |
| 57 WindowOpenDisposition disposition) { | 58 WindowOpenDisposition disposition) { |
| 58 // TODO(jhawkins): Open the Web Intents Help Center article once it is | 59 // TODO(jhawkins): Open the Web Intents Help Center article once it is |
| 59 // written. | 60 // written. |
| 60 // TODO(jhawkins): Add associated bug for the article here. | 61 // TODO(jhawkins): Add associated bug for the article here. |
| 61 return false; | 62 return false; |
| 62 } | 63 } |
| 64 | |
| 65 // A trampoline for showing the infobar if it is not already registered. | |
| 66 // Triggered by a return to a query to the WebIntentsRegistry. | |
| 67 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.
| |
| 68 public: | |
| 69 IntentCheckConsumer(InfoBarTabHelper* infobar_helper, | |
| 70 WebIntentsRegistry* registry, | |
| 71 const WebIntentServiceData& service) | |
| 72 : infobar_helper_(infobar_helper), | |
| 73 registry_(registry), | |
| 74 service_(service) {} | |
| 75 virtual ~IntentCheckConsumer() {} | |
| 76 | |
| 77 // Gets the list of all intents for a particular action. We'll check them all | |
| 78 // to see if this one is already registered. If it is, we bail out without | |
| 79 // showing the infobar. If it isn't, we show the infobar. We then delete | |
| 80 // ourselves. | |
| 81 virtual void OnIntentsQueryDone( | |
| 82 WebIntentsRegistry::QueryID id, | |
| 83 const WebIntentsRegistry::IntentList& list) OVERRIDE { | |
| 84 scoped_ptr<IntentCheckConsumer> self_deleter(this); | |
| 85 | |
| 86 for (WebIntentsRegistry::IntentList::const_iterator i = list.begin(); | |
| 87 i != list.end(); ++i) { | |
| 88 if (*i == service_) | |
| 89 return; | |
| 90 } | |
| 91 | |
| 92 infobar_helper_->AddInfoBar(new RegisterIntentHandlerInfoBarDelegate( | |
| 93 infobar_helper_, registry_, service_)); | |
| 94 } | |
| 95 | |
| 96 private: | |
| 97 InfoBarTabHelper* infobar_helper_; | |
| 98 WebIntentsRegistry* registry_; | |
| 99 WebIntentServiceData service_; | |
| 100 }; | |
| 101 | |
| 102 // static | |
| 103 void RegisterIntentHandlerInfoBarDelegate::MaybeShowIntentInfoBar( | |
| 104 InfoBarTabHelper* infobar_helper, | |
| 105 WebIntentsRegistry* registry, | |
| 106 const WebIntentServiceData& service) { | |
| 107 registry->GetIntentProviders(service.action, | |
| 108 new IntentCheckConsumer(infobar_helper, | |
| 109 registry, | |
| 110 service)); | |
| 111 } | |
| OLD | NEW |