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