Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(910)

Side by Side Diff: chrome/browser/intents/register_intent_handler_infobar_delegate.cc

Issue 11644059: Change infobar creation to use a public static Create() method on the infobar delegate classes. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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/api/infobars/infobar_service.h" 11 #include "chrome/browser/api/infobars/infobar_service.h"
12 #include "chrome/browser/favicon/favicon_service.h" 12 #include "chrome/browser/favicon/favicon_service.h"
13 #include "chrome/browser/favicon/favicon_service_factory.h"
13 #include "chrome/browser/intents/web_intents_registry.h" 14 #include "chrome/browser/intents/web_intents_registry.h"
14 #include "chrome/browser/intents/web_intents_registry_factory.h" 15 #include "chrome/browser/intents/web_intents_registry_factory.h"
16 #include "chrome/browser/intents/web_intents_util.h"
15 #include "chrome/browser/profiles/profile.h" 17 #include "chrome/browser/profiles/profile.h"
18 #include "content/public/browser/web_contents.h"
16 #include "grit/generated_resources.h" 19 #include "grit/generated_resources.h"
17 #include "ui/base/l10n/l10n_util.h" 20 #include "ui/base/l10n/l10n_util.h"
18 21
19 RegisterIntentHandlerInfoBarDelegate::RegisterIntentHandlerInfoBarDelegate( 22
20 InfoBarService* infobar_service, 23 // static
21 WebIntentsRegistry* registry, 24 void RegisterIntentHandlerInfoBarDelegate::Create(
22 const webkit_glue::WebIntentServiceData& service, 25 content::WebContents* web_contents,
23 FaviconService* favicon_service, 26 const webkit_glue::WebIntentServiceData& data) {
24 const GURL& origin_url) 27 Profile* profile =
25 : ConfirmInfoBarDelegate(infobar_service), 28 Profile::FromBrowserContext(web_contents->GetBrowserContext());
26 registry_(registry), 29 if (profile->IsOffTheRecord())
27 service_(service), 30 return;
28 favicon_service_(favicon_service), 31
29 origin_url_(origin_url) { 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()));
30 } 48 }
31 49
32 InfoBarDelegate::Type 50 InfoBarDelegate::Type
33 RegisterIntentHandlerInfoBarDelegate::GetInfoBarType() const { 51 RegisterIntentHandlerInfoBarDelegate::GetInfoBarType() const {
34 return PAGE_ACTION_TYPE; 52 return PAGE_ACTION_TYPE;
35 } 53 }
36 54
37 string16 RegisterIntentHandlerInfoBarDelegate::GetMessageText() const { 55 string16 RegisterIntentHandlerInfoBarDelegate::GetMessageText() const {
38 return l10n_util::GetStringFUTF16( 56 return l10n_util::GetStringFUTF16(
39 IDS_REGISTER_INTENT_HANDLER_CONFIRM, 57 IDS_REGISTER_INTENT_HANDLER_CONFIRM,
(...skipping 27 matching lines...) Expand all
67 } 85 }
68 86
69 bool RegisterIntentHandlerInfoBarDelegate::LinkClicked( 87 bool RegisterIntentHandlerInfoBarDelegate::LinkClicked(
70 WindowOpenDisposition disposition) { 88 WindowOpenDisposition disposition) {
71 // TODO(jhawkins): Open the Web Intents Help Center article once it is 89 // TODO(jhawkins): Open the Web Intents Help Center article once it is
72 // written. 90 // written.
73 // TODO(jhawkins): Add associated bug for the article here. 91 // TODO(jhawkins): Add associated bug for the article here.
74 return false; 92 return false;
75 } 93 }
76 94
77 namespace { 95 RegisterIntentHandlerInfoBarDelegate::RegisterIntentHandlerInfoBarDelegate(
78
79 // Helper continuation for MaybeShowIntentInfoBar.
80 void CheckProvider(InfoBarService* infobar_service,
81 WebIntentsRegistry* registry,
82 const webkit_glue::WebIntentServiceData& service,
83 FaviconService* favicon_service,
84 const GURL& origin_url,
85 bool provider_exists) {
86 if (!provider_exists) {
87 infobar_service->AddInfoBar(new RegisterIntentHandlerInfoBarDelegate(
88 infobar_service, registry, service, favicon_service, origin_url));
89 }
90 }
91
92 } // namespace
93
94 // static
95 void RegisterIntentHandlerInfoBarDelegate::MaybeShowIntentInfoBar(
96 InfoBarService* infobar_service, 96 InfoBarService* infobar_service,
97 WebIntentsRegistry* registry, 97 WebIntentsRegistry* registry,
98 const webkit_glue::WebIntentServiceData& service, 98 const webkit_glue::WebIntentServiceData& service,
99 FaviconService* favicon_service, 99 FaviconService* favicon_service,
100 const GURL& origin_url) { 100 const GURL& origin_url)
101 DCHECK(infobar_service); 101 : ConfirmInfoBarDelegate(infobar_service),
102 DCHECK(registry); 102 registry_(registry),
103 registry->IntentServiceExists(service, 103 service_(service),
104 base::Bind(&CheckProvider, 104 favicon_service_(favicon_service),
105 base::Unretained(infobar_service), 105 origin_url_(origin_url) {
106 registry,
107 service,
108 favicon_service,
109 origin_url));
110 } 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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698