Refactoring : Move AuthAttempt and Authenticators to chromeos/login
[chromium-blink-merge.git] / chrome / browser / pepper_broker_infobar_delegate.cc
blob4a0bcd4990732423ca617c62036a0288ac60f7b9
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.
5 #include "chrome/browser/pepper_broker_infobar_delegate.h"
7 #include "base/prefs/pref_service.h"
8 #include "chrome/browser/content_settings/host_content_settings_map.h"
9 #include "chrome/browser/content_settings/tab_specific_content_settings.h"
10 #include "chrome/browser/infobars/infobar_service.h"
11 #include "chrome/browser/plugins/plugin_finder.h"
12 #include "chrome/browser/plugins/plugin_metadata.h"
13 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/common/pref_names.h"
15 #include "components/infobars/core/infobar.h"
16 #include "content/public/browser/page_navigator.h"
17 #include "content/public/browser/plugin_service.h"
18 #include "content/public/browser/user_metrics.h"
19 #include "content/public/browser/web_contents.h"
20 #include "content/public/common/referrer.h"
21 #include "content/public/common/webplugininfo.h"
22 #include "grit/generated_resources.h"
23 #include "grit/theme_resources.h"
24 #include "net/base/net_util.h"
25 #include "ui/base/l10n/l10n_util.h"
28 // static
29 void PepperBrokerInfoBarDelegate::Create(
30 content::WebContents* web_contents,
31 const GURL& url,
32 const base::FilePath& plugin_path,
33 const base::Callback<void(bool)>& callback) {
34 Profile* profile =
35 Profile::FromBrowserContext(web_contents->GetBrowserContext());
36 // TODO(wad): Add ephemeral device ID support for broker in guest mode.
37 if (profile->IsGuestSession()) {
38 callback.Run(false);
39 return;
42 TabSpecificContentSettings* tab_content_settings =
43 TabSpecificContentSettings::FromWebContents(web_contents);
45 HostContentSettingsMap* content_settings =
46 profile->GetHostContentSettingsMap();
47 ContentSetting setting =
48 content_settings->GetContentSetting(url, url,
49 CONTENT_SETTINGS_TYPE_PPAPI_BROKER,
50 std::string());
52 if (setting == CONTENT_SETTING_ASK) {
53 content::RecordAction(
54 base::UserMetricsAction("PPAPI.BrokerInfobarDisplayed"));
55 InfoBarService* infobar_service =
56 InfoBarService::FromWebContents(web_contents);
57 infobar_service->AddInfoBar(ConfirmInfoBarDelegate::CreateInfoBar(
58 scoped_ptr<ConfirmInfoBarDelegate>(new PepperBrokerInfoBarDelegate(
59 url, plugin_path,
60 profile->GetPrefs()->GetString(prefs::kAcceptLanguages),
61 content_settings, tab_content_settings, callback))));
62 return;
65 bool allowed = (setting == CONTENT_SETTING_ALLOW);
66 content::RecordAction(allowed ?
67 base::UserMetricsAction("PPAPI.BrokerSettingAllow") :
68 base::UserMetricsAction("PPAPI.BrokerSettingDeny"));
69 tab_content_settings->SetPepperBrokerAllowed(allowed);
70 callback.Run(allowed);
73 PepperBrokerInfoBarDelegate::PepperBrokerInfoBarDelegate(
74 const GURL& url,
75 const base::FilePath& plugin_path,
76 const std::string& languages,
77 HostContentSettingsMap* content_settings,
78 TabSpecificContentSettings* tab_content_settings,
79 const base::Callback<void(bool)>& callback)
80 : ConfirmInfoBarDelegate(),
81 url_(url),
82 plugin_path_(plugin_path),
83 languages_(languages),
84 content_settings_(content_settings),
85 tab_content_settings_(tab_content_settings),
86 callback_(callback) {
89 PepperBrokerInfoBarDelegate::~PepperBrokerInfoBarDelegate() {
90 if (!callback_.is_null())
91 callback_.Run(false);
94 int PepperBrokerInfoBarDelegate::GetIconID() const {
95 return IDR_INFOBAR_PLUGIN_INSTALL;
98 base::string16 PepperBrokerInfoBarDelegate::GetMessageText() const {
99 content::PluginService* plugin_service =
100 content::PluginService::GetInstance();
101 content::WebPluginInfo plugin;
102 bool success = plugin_service->GetPluginInfoByPath(plugin_path_, &plugin);
103 DCHECK(success);
104 scoped_ptr<PluginMetadata> plugin_metadata(
105 PluginFinder::GetInstance()->GetPluginMetadata(plugin));
106 return l10n_util::GetStringFUTF16(IDS_PEPPER_BROKER_MESSAGE,
107 plugin_metadata->name(),
108 net::FormatUrl(url_.GetOrigin(),
109 languages_));
112 base::string16 PepperBrokerInfoBarDelegate::GetButtonLabel(
113 InfoBarButton button) const {
114 return l10n_util::GetStringUTF16((button == BUTTON_OK) ?
115 IDS_PEPPER_BROKER_ALLOW_BUTTON : IDS_PEPPER_BROKER_DENY_BUTTON);
118 bool PepperBrokerInfoBarDelegate::Accept() {
119 DispatchCallback(true);
120 return true;
123 bool PepperBrokerInfoBarDelegate::Cancel() {
124 DispatchCallback(false);
125 return true;
128 base::string16 PepperBrokerInfoBarDelegate::GetLinkText() const {
129 return l10n_util::GetStringUTF16(IDS_LEARN_MORE);
132 bool PepperBrokerInfoBarDelegate::LinkClicked(
133 WindowOpenDisposition disposition) {
134 GURL learn_more_url("https://support.google.com/chrome/?p=ib_pepper_broker");
135 InfoBarService::WebContentsFromInfoBar(infobar())->OpenURL(
136 content::OpenURLParams(
137 learn_more_url, content::Referrer(),
138 (disposition == CURRENT_TAB) ? NEW_FOREGROUND_TAB : disposition,
139 content::PAGE_TRANSITION_LINK, false));
140 return false;
143 void PepperBrokerInfoBarDelegate::DispatchCallback(bool result) {
144 content::RecordAction(result ?
145 base::UserMetricsAction("PPAPI.BrokerInfobarClickedAllow") :
146 base::UserMetricsAction("PPAPI.BrokerInfobarClickedDeny"));
147 callback_.Run(result);
148 callback_ = base::Callback<void(bool)>();
149 content_settings_->SetContentSetting(
150 ContentSettingsPattern::FromURLNoWildcard(url_),
151 ContentSettingsPattern::Wildcard(),
152 CONTENT_SETTINGS_TYPE_PPAPI_BROKER,
153 std::string(), result ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK);
154 tab_content_settings_->SetPepperBrokerAllowed(result);