OLD | NEW |
| (Empty) |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/intents/register_intent_handler_infobar_delegate.h" | |
6 | |
7 #include "base/bind.h" | |
8 #include "base/bind_helpers.h" | |
9 #include "base/logging.h" | |
10 #include "base/utf_string_conversions.h" | |
11 #include "chrome/browser/api/infobars/infobar_service.h" | |
12 #include "chrome/browser/favicon/favicon_service.h" | |
13 #include "chrome/browser/favicon/favicon_service_factory.h" | |
14 #include "chrome/browser/intents/web_intents_registry.h" | |
15 #include "chrome/browser/intents/web_intents_registry_factory.h" | |
16 #include "chrome/browser/intents/web_intents_util.h" | |
17 #include "chrome/browser/profiles/profile.h" | |
18 #include "content/public/browser/web_contents.h" | |
19 #include "grit/generated_resources.h" | |
20 #include "ui/base/l10n/l10n_util.h" | |
21 | |
22 | |
23 // static | |
24 void RegisterIntentHandlerInfoBarDelegate::Create( | |
25 content::WebContents* web_contents, | |
26 const webkit_glue::WebIntentServiceData& data) { | |
27 Profile* profile = | |
28 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | |
29 if (profile->IsOffTheRecord()) | |
30 return; | |
31 | |
32 if (!web_intents::IsWebIntentsEnabledForProfile(profile)) | |
33 return; | |
34 | |
35 FaviconService* favicon_service = FaviconServiceFactory::GetForProfile( | |
36 profile, Profile::EXPLICIT_ACCESS); | |
37 | |
38 WebIntentsRegistry* registry = | |
39 WebIntentsRegistryFactory::GetForProfile(profile); | |
40 registry->IntentServiceExists( | |
41 data, base::Bind( | |
42 &CreateContinuation, | |
43 base::Unretained(InfoBarService::FromWebContents(web_contents)), | |
44 registry, | |
45 data, | |
46 favicon_service, | |
47 web_contents->GetURL())); | |
48 } | |
49 | |
50 InfoBarDelegate::Type | |
51 RegisterIntentHandlerInfoBarDelegate::GetInfoBarType() const { | |
52 return PAGE_ACTION_TYPE; | |
53 } | |
54 | |
55 string16 RegisterIntentHandlerInfoBarDelegate::GetMessageText() const { | |
56 return l10n_util::GetStringFUTF16( | |
57 IDS_REGISTER_INTENT_HANDLER_CONFIRM, | |
58 service_.title, | |
59 UTF8ToUTF16(service_.service_url.host())); | |
60 } | |
61 | |
62 string16 RegisterIntentHandlerInfoBarDelegate::GetButtonLabel( | |
63 InfoBarButton button) const { | |
64 if (button == BUTTON_OK) { | |
65 return l10n_util::GetStringFUTF16(IDS_REGISTER_INTENT_HANDLER_ACCEPT, | |
66 UTF8ToUTF16(service_.service_url.host())); | |
67 } | |
68 | |
69 DCHECK(button == BUTTON_CANCEL); | |
70 return l10n_util::GetStringUTF16(IDS_REGISTER_INTENT_HANDLER_DENY); | |
71 } | |
72 | |
73 bool RegisterIntentHandlerInfoBarDelegate::Accept() { | |
74 registry_->RegisterIntentService(service_); | |
75 | |
76 // Register a temporary FavIcon in case we never visited the provider page. | |
77 if (favicon_service_ && origin_url_ != service_.service_url) | |
78 favicon_service_->CloneFavicon(origin_url_, service_.service_url); | |
79 | |
80 return true; | |
81 } | |
82 | |
83 string16 RegisterIntentHandlerInfoBarDelegate::GetLinkText() const { | |
84 return l10n_util::GetStringUTF16(IDS_LEARN_MORE); | |
85 } | |
86 | |
87 bool RegisterIntentHandlerInfoBarDelegate::LinkClicked( | |
88 WindowOpenDisposition disposition) { | |
89 // TODO(jhawkins): Open the Web Intents Help Center article once it is | |
90 // written. | |
91 // TODO(jhawkins): Add associated bug for the article here. | |
92 return false; | |
93 } | |
94 | |
95 RegisterIntentHandlerInfoBarDelegate::RegisterIntentHandlerInfoBarDelegate( | |
96 InfoBarService* infobar_service, | |
97 WebIntentsRegistry* registry, | |
98 const webkit_glue::WebIntentServiceData& service, | |
99 FaviconService* favicon_service, | |
100 const GURL& origin_url) | |
101 : ConfirmInfoBarDelegate(infobar_service), | |
102 registry_(registry), | |
103 service_(service), | |
104 favicon_service_(favicon_service), | |
105 origin_url_(origin_url) { | |
106 } | |
107 | |
108 // static | |
109 void RegisterIntentHandlerInfoBarDelegate::CreateContinuation( | |
110 InfoBarService* infobar_service, | |
111 WebIntentsRegistry* registry, | |
112 const webkit_glue::WebIntentServiceData& service, | |
113 FaviconService* favicon_service, | |
114 const GURL& origin_url, | |
115 bool provider_exists) { | |
116 if (!provider_exists) { | |
117 infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>( | |
118 new RegisterIntentHandlerInfoBarDelegate( | |
119 infobar_service, registry, service, favicon_service, origin_url))); | |
120 } | |
121 } | |
OLD | NEW |