| OLD | NEW |
| 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/pepper_broker_infobar_delegate.h" | 5 #include "chrome/browser/pepper_broker_infobar_delegate.h" |
| 6 | 6 |
| 7 #include "chrome/browser/api/infobars/infobar_service.h" | 7 #include "chrome/browser/api/infobars/infobar_service.h" |
| 8 #include "chrome/browser/content_settings/host_content_settings_map.h" | 8 #include "chrome/browser/content_settings/host_content_settings_map.h" |
| 9 #include "chrome/browser/plugins/plugin_finder.h" | 9 #include "chrome/browser/plugins/plugin_finder.h" |
| 10 #include "chrome/browser/plugins/plugin_metadata.h" | 10 #include "chrome/browser/plugins/plugin_metadata.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 | 25 |
| 26 // The URL for the "learn more" article about the PPAPI broker. | 26 // The URL for the "learn more" article about the PPAPI broker. |
| 27 const char kPpapiBrokerLearnMoreUrl[] = | 27 const char kPpapiBrokerLearnMoreUrl[] = |
| 28 "https://support.google.com/chrome/?p=ib_pepper_broker"; | 28 "https://support.google.com/chrome/?p=ib_pepper_broker"; |
| 29 | 29 |
| 30 using content::OpenURLParams; | 30 using content::OpenURLParams; |
| 31 using content::Referrer; | 31 using content::Referrer; |
| 32 using content::WebContents; | 32 using content::WebContents; |
| 33 | 33 |
| 34 // static | 34 // static |
| 35 void PepperBrokerInfoBarDelegate::Show( | 35 void PepperBrokerInfoBarDelegate::Create( |
| 36 WebContents* web_contents, | 36 WebContents* web_contents, |
| 37 const GURL& url, | 37 const GURL& url, |
| 38 const FilePath& plugin_path, | 38 const FilePath& plugin_path, |
| 39 const base::Callback<void(bool)>& callback) { | 39 const base::Callback<void(bool)>& callback) { |
| 40 Profile* profile = | 40 Profile* profile = |
| 41 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | 41 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| 42 // TODO(wad): Add ephemeral device ID support for broker in guest mode. | 42 // TODO(wad): Add ephemeral device ID support for broker in guest mode. |
| 43 if (profile->IsGuestSession()) { | 43 if (profile->IsGuestSession()) { |
| 44 callback.Run(false); | 44 callback.Run(false); |
| 45 return; | 45 return; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 65 break; | 65 break; |
| 66 } | 66 } |
| 67 case CONTENT_SETTING_ASK: { | 67 case CONTENT_SETTING_ASK: { |
| 68 content::RecordAction( | 68 content::RecordAction( |
| 69 content::UserMetricsAction("PPAPI.BrokerInfobarDisplayed")); | 69 content::UserMetricsAction("PPAPI.BrokerInfobarDisplayed")); |
| 70 | 70 |
| 71 InfoBarService* infobar_service = | 71 InfoBarService* infobar_service = |
| 72 InfoBarService::FromWebContents(web_contents); | 72 InfoBarService::FromWebContents(web_contents); |
| 73 std::string languages = | 73 std::string languages = |
| 74 profile->GetPrefs()->GetString(prefs::kAcceptLanguages); | 74 profile->GetPrefs()->GetString(prefs::kAcceptLanguages); |
| 75 infobar_service->AddInfoBar( | 75 infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>( |
| 76 new PepperBrokerInfoBarDelegate( | 76 new PepperBrokerInfoBarDelegate( |
| 77 infobar_service, url, plugin_path, languages, content_settings, | 77 infobar_service, url, plugin_path, languages, content_settings, |
| 78 callback)); | 78 callback))); |
| 79 break; | 79 break; |
| 80 } | 80 } |
| 81 default: | 81 default: |
| 82 NOTREACHED(); | 82 NOTREACHED(); |
| 83 } | 83 } |
| 84 } | 84 } |
| 85 | 85 |
| 86 PepperBrokerInfoBarDelegate::PepperBrokerInfoBarDelegate( | |
| 87 InfoBarService* infobar_service, | |
| 88 const GURL& url, | |
| 89 const FilePath& plugin_path, | |
| 90 const std::string& languages, | |
| 91 HostContentSettingsMap* content_settings, | |
| 92 const base::Callback<void(bool)>& callback) | |
| 93 : ConfirmInfoBarDelegate(infobar_service), | |
| 94 url_(url), | |
| 95 plugin_path_(plugin_path), | |
| 96 languages_(languages), | |
| 97 content_settings_(content_settings), | |
| 98 callback_(callback) { | |
| 99 } | |
| 100 | |
| 101 PepperBrokerInfoBarDelegate::~PepperBrokerInfoBarDelegate() { | |
| 102 if (!callback_.is_null()) | |
| 103 callback_.Run(false); | |
| 104 } | |
| 105 | |
| 106 string16 PepperBrokerInfoBarDelegate::GetMessageText() const { | 86 string16 PepperBrokerInfoBarDelegate::GetMessageText() const { |
| 107 content::PluginService* plugin_service = | 87 content::PluginService* plugin_service = |
| 108 content::PluginService::GetInstance(); | 88 content::PluginService::GetInstance(); |
| 109 webkit::WebPluginInfo plugin; | 89 webkit::WebPluginInfo plugin; |
| 110 bool success = plugin_service->GetPluginInfoByPath(plugin_path_, &plugin); | 90 bool success = plugin_service->GetPluginInfoByPath(plugin_path_, &plugin); |
| 111 DCHECK(success); | 91 DCHECK(success); |
| 112 scoped_ptr<PluginMetadata> plugin_metadata( | 92 scoped_ptr<PluginMetadata> plugin_metadata( |
| 113 PluginFinder::GetInstance()->GetPluginMetadata(plugin)); | 93 PluginFinder::GetInstance()->GetPluginMetadata(plugin)); |
| 114 return l10n_util::GetStringFUTF16(IDS_PEPPER_BROKER_MESSAGE, | 94 return l10n_util::GetStringFUTF16(IDS_PEPPER_BROKER_MESSAGE, |
| 115 plugin_metadata->name(), | 95 plugin_metadata->name(), |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 false); | 137 false); |
| 158 owner()->GetWebContents()->OpenURL(params); | 138 owner()->GetWebContents()->OpenURL(params); |
| 159 return false; | 139 return false; |
| 160 } | 140 } |
| 161 | 141 |
| 162 gfx::Image* PepperBrokerInfoBarDelegate::GetIcon() const { | 142 gfx::Image* PepperBrokerInfoBarDelegate::GetIcon() const { |
| 163 return &ResourceBundle::GetSharedInstance().GetNativeImageNamed( | 143 return &ResourceBundle::GetSharedInstance().GetNativeImageNamed( |
| 164 IDR_INFOBAR_PLUGIN_INSTALL); | 144 IDR_INFOBAR_PLUGIN_INSTALL); |
| 165 } | 145 } |
| 166 | 146 |
| 147 PepperBrokerInfoBarDelegate::PepperBrokerInfoBarDelegate( |
| 148 InfoBarService* infobar_service, |
| 149 const GURL& url, |
| 150 const FilePath& plugin_path, |
| 151 const std::string& languages, |
| 152 HostContentSettingsMap* content_settings, |
| 153 const base::Callback<void(bool)>& callback) |
| 154 : ConfirmInfoBarDelegate(infobar_service), |
| 155 url_(url), |
| 156 plugin_path_(plugin_path), |
| 157 languages_(languages), |
| 158 content_settings_(content_settings), |
| 159 callback_(callback) { |
| 160 } |
| 161 |
| 162 PepperBrokerInfoBarDelegate::~PepperBrokerInfoBarDelegate() { |
| 163 if (!callback_.is_null()) |
| 164 callback_.Run(false); |
| 165 } |
| 166 |
| 167 void PepperBrokerInfoBarDelegate::DispatchCallback(bool result) { | 167 void PepperBrokerInfoBarDelegate::DispatchCallback(bool result) { |
| 168 content::RecordAction(result ? | 168 content::RecordAction(result ? |
| 169 content::UserMetricsAction("PPAPI.BrokerInfobarClickedAllow") : | 169 content::UserMetricsAction("PPAPI.BrokerInfobarClickedAllow") : |
| 170 content::UserMetricsAction("PPAPI.BrokerInfobarClickedDeny")); | 170 content::UserMetricsAction("PPAPI.BrokerInfobarClickedDeny")); |
| 171 callback_.Run(result); | 171 callback_.Run(result); |
| 172 callback_ = base::Callback<void(bool)>(); | 172 callback_ = base::Callback<void(bool)>(); |
| 173 content_settings_->SetContentSetting( | 173 content_settings_->SetContentSetting( |
| 174 ContentSettingsPattern::FromURLNoWildcard(url_), | 174 ContentSettingsPattern::FromURLNoWildcard(url_), |
| 175 ContentSettingsPattern::Wildcard(), | 175 ContentSettingsPattern::Wildcard(), |
| 176 CONTENT_SETTINGS_TYPE_PPAPI_BROKER, | 176 CONTENT_SETTINGS_TYPE_PPAPI_BROKER, |
| 177 std::string(), result ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK); | 177 std::string(), result ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK); |
| 178 } | 178 } |
| OLD | NEW |