| 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/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| 11 #include "chrome/browser/favicon/favicon_service.h" |
| 11 #include "chrome/browser/infobars/infobar_tab_helper.h" | 12 #include "chrome/browser/infobars/infobar_tab_helper.h" |
| 12 #include "chrome/browser/intents/web_intents_registry.h" | 13 #include "chrome/browser/intents/web_intents_registry.h" |
| 13 #include "chrome/browser/intents/web_intents_registry_factory.h" | 14 #include "chrome/browser/intents/web_intents_registry_factory.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 15 #include "grit/generated_resources.h" | 16 #include "grit/generated_resources.h" |
| 16 #include "ui/base/l10n/l10n_util.h" | 17 #include "ui/base/l10n/l10n_util.h" |
| 17 | 18 |
| 18 RegisterIntentHandlerInfoBarDelegate::RegisterIntentHandlerInfoBarDelegate( | 19 RegisterIntentHandlerInfoBarDelegate::RegisterIntentHandlerInfoBarDelegate( |
| 19 InfoBarTabHelper* infobar_helper, | 20 InfoBarTabHelper* infobar_helper, |
| 20 WebIntentsRegistry* registry, | 21 WebIntentsRegistry* registry, |
| 21 const webkit_glue::WebIntentServiceData& service) | 22 const webkit_glue::WebIntentServiceData& service, |
| 23 FaviconService* favicon_service, |
| 24 const GURL& origin_url) |
| 22 : ConfirmInfoBarDelegate(infobar_helper), | 25 : ConfirmInfoBarDelegate(infobar_helper), |
| 23 registry_(registry), | 26 registry_(registry), |
| 24 service_(service) { | 27 service_(service), |
| 28 favicon_service_(favicon_service), |
| 29 origin_url_(origin_url) { |
| 25 } | 30 } |
| 26 | 31 |
| 27 InfoBarDelegate::Type | 32 InfoBarDelegate::Type |
| 28 RegisterIntentHandlerInfoBarDelegate::GetInfoBarType() const { | 33 RegisterIntentHandlerInfoBarDelegate::GetInfoBarType() const { |
| 29 return PAGE_ACTION_TYPE; | 34 return PAGE_ACTION_TYPE; |
| 30 } | 35 } |
| 31 | 36 |
| 32 string16 RegisterIntentHandlerInfoBarDelegate::GetMessageText() const { | 37 string16 RegisterIntentHandlerInfoBarDelegate::GetMessageText() const { |
| 33 return l10n_util::GetStringFUTF16( | 38 return l10n_util::GetStringFUTF16( |
| 34 IDS_REGISTER_INTENT_HANDLER_CONFIRM, | 39 IDS_REGISTER_INTENT_HANDLER_CONFIRM, |
| 35 service_.title, | 40 service_.title, |
| 36 UTF8ToUTF16(service_.service_url.host())); | 41 UTF8ToUTF16(service_.service_url.host())); |
| 37 } | 42 } |
| 38 | 43 |
| 39 string16 RegisterIntentHandlerInfoBarDelegate::GetButtonLabel( | 44 string16 RegisterIntentHandlerInfoBarDelegate::GetButtonLabel( |
| 40 InfoBarButton button) const { | 45 InfoBarButton button) const { |
| 41 if (button == BUTTON_OK) { | 46 if (button == BUTTON_OK) { |
| 42 return l10n_util::GetStringFUTF16(IDS_REGISTER_INTENT_HANDLER_ACCEPT, | 47 return l10n_util::GetStringFUTF16(IDS_REGISTER_INTENT_HANDLER_ACCEPT, |
| 43 UTF8ToUTF16(service_.service_url.host())); | 48 UTF8ToUTF16(service_.service_url.host())); |
| 44 } | 49 } |
| 45 | 50 |
| 46 DCHECK(button == BUTTON_CANCEL); | 51 DCHECK(button == BUTTON_CANCEL); |
| 47 return l10n_util::GetStringUTF16(IDS_REGISTER_INTENT_HANDLER_DENY); | 52 return l10n_util::GetStringUTF16(IDS_REGISTER_INTENT_HANDLER_DENY); |
| 48 } | 53 } |
| 49 | 54 |
| 50 bool RegisterIntentHandlerInfoBarDelegate::Accept() { | 55 bool RegisterIntentHandlerInfoBarDelegate::Accept() { |
| 51 registry_->RegisterIntentProvider(service_); | 56 registry_->RegisterIntentProvider(service_); |
| 57 |
| 58 // Register a temporary FavIcon in case we never visited the provider page. |
| 59 if (favicon_service_ && origin_url_ != service_.service_url) |
| 60 favicon_service_->CloneFavicon(origin_url_, service_.service_url); |
| 61 |
| 52 return true; | 62 return true; |
| 53 } | 63 } |
| 54 | 64 |
| 55 string16 RegisterIntentHandlerInfoBarDelegate::GetLinkText() const { | 65 string16 RegisterIntentHandlerInfoBarDelegate::GetLinkText() const { |
| 56 return l10n_util::GetStringUTF16(IDS_LEARN_MORE); | 66 return l10n_util::GetStringUTF16(IDS_LEARN_MORE); |
| 57 } | 67 } |
| 58 | 68 |
| 59 bool RegisterIntentHandlerInfoBarDelegate::LinkClicked( | 69 bool RegisterIntentHandlerInfoBarDelegate::LinkClicked( |
| 60 WindowOpenDisposition disposition) { | 70 WindowOpenDisposition disposition) { |
| 61 // TODO(jhawkins): Open the Web Intents Help Center article once it is | 71 // TODO(jhawkins): Open the Web Intents Help Center article once it is |
| 62 // written. | 72 // written. |
| 63 // TODO(jhawkins): Add associated bug for the article here. | 73 // TODO(jhawkins): Add associated bug for the article here. |
| 64 return false; | 74 return false; |
| 65 } | 75 } |
| 66 | 76 |
| 67 namespace { | 77 namespace { |
| 68 | 78 |
| 69 // Helper continuation for MaybeShowIntentInfoBar. | 79 // Helper continuation for MaybeShowIntentInfoBar. |
| 70 void CheckProvider(InfoBarTabHelper* infobar_helper, | 80 void CheckProvider(InfoBarTabHelper* infobar_helper, |
| 71 WebIntentsRegistry* registry, | 81 WebIntentsRegistry* registry, |
| 72 const webkit_glue::WebIntentServiceData& service, | 82 const webkit_glue::WebIntentServiceData& service, |
| 83 FaviconService* favicon_service, |
| 84 const GURL& origin_url, |
| 73 bool provider_exists) { | 85 bool provider_exists) { |
| 74 if (!provider_exists) { | 86 if (!provider_exists) { |
| 75 infobar_helper->AddInfoBar(new RegisterIntentHandlerInfoBarDelegate( | 87 infobar_helper->AddInfoBar(new RegisterIntentHandlerInfoBarDelegate( |
| 76 infobar_helper, registry, service)); | 88 infobar_helper, registry, service, favicon_service, origin_url)); |
| 77 } | 89 } |
| 78 } | 90 } |
| 79 | 91 |
| 80 } // namespace | 92 } // namespace |
| 81 | 93 |
| 82 // static | 94 // static |
| 83 void RegisterIntentHandlerInfoBarDelegate::MaybeShowIntentInfoBar( | 95 void RegisterIntentHandlerInfoBarDelegate::MaybeShowIntentInfoBar( |
| 84 InfoBarTabHelper* infobar_helper, | 96 InfoBarTabHelper* infobar_helper, |
| 85 WebIntentsRegistry* registry, | 97 WebIntentsRegistry* registry, |
| 86 const webkit_glue::WebIntentServiceData& service) { | 98 const webkit_glue::WebIntentServiceData& service, |
| 99 FaviconService* favicon_service, |
| 100 const GURL& origin_url) { |
| 87 DCHECK(infobar_helper); | 101 DCHECK(infobar_helper); |
| 88 DCHECK(registry); | 102 DCHECK(registry); |
| 89 registry->IntentProviderExists(service, | 103 registry->IntentProviderExists(service, |
| 90 base::Bind(&CheckProvider, | 104 base::Bind(&CheckProvider, |
| 91 base::Unretained(infobar_helper), | 105 base::Unretained(infobar_helper), |
| 92 registry, | 106 registry, |
| 93 service)); | 107 service, |
| 108 favicon_service, |
| 109 origin_url)); |
| 94 } | 110 } |
| OLD | NEW |