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