| 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/intents/web_intents_registry.h" | 9 #include "chrome/browser/intents/web_intents_registry.h" |
| 10 #include "chrome/browser/intents/web_intents_registry_factory.h" | 10 #include "chrome/browser/intents/web_intents_registry_factory.h" |
| 11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 12 #include "content/browser/tab_contents/tab_contents.h" | 12 #include "content/browser/tab_contents/tab_contents.h" |
| 13 #include "grit/generated_resources.h" | 13 #include "grit/generated_resources.h" |
| 14 #include "ui/base/l10n/l10n_util.h" | 14 #include "ui/base/l10n/l10n_util.h" |
| 15 | 15 |
| 16 RegisterIntentHandlerInfoBarDelegate::RegisterIntentHandlerInfoBarDelegate( | 16 RegisterIntentHandlerInfoBarDelegate::RegisterIntentHandlerInfoBarDelegate( |
| 17 TabContents* tab_contents, const WebIntentData& intent) | 17 TabContents* tab_contents, const WebIntentServiceData& service) |
| 18 : ConfirmInfoBarDelegate(tab_contents), | 18 : ConfirmInfoBarDelegate(tab_contents), |
| 19 tab_contents_(tab_contents), | 19 tab_contents_(tab_contents), |
| 20 profile_(Profile::FromBrowserContext(tab_contents->browser_context())), | 20 profile_(Profile::FromBrowserContext(tab_contents->browser_context())), |
| 21 intent_(intent) { | 21 service_(service) { |
| 22 } | 22 } |
| 23 | 23 |
| 24 InfoBarDelegate::Type | 24 InfoBarDelegate::Type |
| 25 RegisterIntentHandlerInfoBarDelegate::GetInfoBarType() const { | 25 RegisterIntentHandlerInfoBarDelegate::GetInfoBarType() const { |
| 26 return PAGE_ACTION_TYPE; | 26 return PAGE_ACTION_TYPE; |
| 27 } | 27 } |
| 28 | 28 |
| 29 string16 RegisterIntentHandlerInfoBarDelegate::GetMessageText() const { | 29 string16 RegisterIntentHandlerInfoBarDelegate::GetMessageText() const { |
| 30 return l10n_util::GetStringFUTF16( | 30 return l10n_util::GetStringFUTF16( |
| 31 IDS_REGISTER_INTENT_HANDLER_CONFIRM, | 31 IDS_REGISTER_INTENT_HANDLER_CONFIRM, |
| 32 intent_.title, | 32 service_.title, |
| 33 UTF8ToUTF16(intent_.service_url.host())); | 33 UTF8ToUTF16(service_.service_url.host())); |
| 34 } | 34 } |
| 35 | 35 |
| 36 string16 RegisterIntentHandlerInfoBarDelegate::GetButtonLabel( | 36 string16 RegisterIntentHandlerInfoBarDelegate::GetButtonLabel( |
| 37 InfoBarButton button) const { | 37 InfoBarButton button) const { |
| 38 if (button == BUTTON_OK) { | 38 if (button == BUTTON_OK) { |
| 39 return l10n_util::GetStringFUTF16(IDS_REGISTER_INTENT_HANDLER_ACCEPT, | 39 return l10n_util::GetStringFUTF16(IDS_REGISTER_INTENT_HANDLER_ACCEPT, |
| 40 UTF8ToUTF16(intent_.service_url.host())); | 40 UTF8ToUTF16(service_.service_url.host())); |
| 41 } | 41 } |
| 42 | 42 |
| 43 DCHECK(button == BUTTON_CANCEL); | 43 DCHECK(button == BUTTON_CANCEL); |
| 44 return l10n_util::GetStringUTF16(IDS_REGISTER_INTENT_HANDLER_DENY); | 44 return l10n_util::GetStringUTF16(IDS_REGISTER_INTENT_HANDLER_DENY); |
| 45 } | 45 } |
| 46 | 46 |
| 47 bool RegisterIntentHandlerInfoBarDelegate::Accept() { | 47 bool RegisterIntentHandlerInfoBarDelegate::Accept() { |
| 48 WebIntentsRegistry* registry = | 48 WebIntentsRegistry* registry = |
| 49 WebIntentsRegistryFactory::GetForProfile(profile_); | 49 WebIntentsRegistryFactory::GetForProfile(profile_); |
| 50 registry->RegisterIntentProvider(intent_); | 50 registry->RegisterIntentProvider(service_); |
| 51 return true; | 51 return true; |
| 52 } | 52 } |
| 53 | 53 |
| 54 string16 RegisterIntentHandlerInfoBarDelegate::GetLinkText() const { | 54 string16 RegisterIntentHandlerInfoBarDelegate::GetLinkText() const { |
| 55 return l10n_util::GetStringUTF16(IDS_LEARN_MORE); | 55 return l10n_util::GetStringUTF16(IDS_LEARN_MORE); |
| 56 } | 56 } |
| 57 | 57 |
| 58 bool RegisterIntentHandlerInfoBarDelegate::LinkClicked( | 58 bool RegisterIntentHandlerInfoBarDelegate::LinkClicked( |
| 59 WindowOpenDisposition disposition) { | 59 WindowOpenDisposition disposition) { |
| 60 // TODO(jhawkins): Open the Web Intents Help Center article once it is | 60 // TODO(jhawkins): Open the Web Intents Help Center article once it is |
| 61 // written. | 61 // written. |
| 62 // TODO(jhawkins): Add associated bug for the article here. | 62 // TODO(jhawkins): Add associated bug for the article here. |
| 63 return false; | 63 return false; |
| 64 } | 64 } |
| OLD | NEW |