| 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_observer.h" | 5 #include "chrome/browser/pepper_broker_infobar_delegate.h" |
| 6 | 6 |
| 7 #include "base/memory/scoped_ptr.h" | |
| 8 #include "chrome/browser/api/infobars/confirm_infobar_delegate.h" | |
| 9 #include "chrome/browser/content_settings/host_content_settings_map.h" | 7 #include "chrome/browser/content_settings/host_content_settings_map.h" |
| 10 #include "chrome/browser/infobars/infobar_tab_helper.h" | 8 #include "chrome/browser/infobars/infobar_tab_helper.h" |
| 11 #include "chrome/browser/plugins/plugin_finder.h" | 9 #include "chrome/browser/plugins/plugin_finder.h" |
| 12 #include "chrome/browser/plugins/plugin_metadata.h" | 10 #include "chrome/browser/plugins/plugin_metadata.h" |
| 13 #include "chrome/browser/prefs/pref_service.h" | 11 #include "chrome/browser/prefs/pref_service.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/common/pref_names.h" | 13 #include "chrome/common/pref_names.h" |
| 16 #include "content/public/browser/page_navigator.h" | 14 #include "content/public/browser/page_navigator.h" |
| 17 #include "content/public/browser/plugin_service.h" | 15 #include "content/public/browser/plugin_service.h" |
| 18 #include "content/public/browser/user_metrics.h" | 16 #include "content/public/browser/user_metrics.h" |
| 19 #include "content/public/browser/web_contents.h" | 17 #include "content/public/browser/web_contents.h" |
| 20 #include "content/public/common/referrer.h" | 18 #include "content/public/common/referrer.h" |
| 21 #include "grit/generated_resources.h" | 19 #include "grit/generated_resources.h" |
| 22 #include "grit/theme_resources.h" | 20 #include "grit/theme_resources.h" |
| 23 #include "net/base/net_util.h" | 21 #include "net/base/net_util.h" |
| 24 #include "ui/base/l10n/l10n_util.h" | 22 #include "ui/base/l10n/l10n_util.h" |
| 25 #include "ui/base/resource/resource_bundle.h" | 23 #include "ui/base/resource/resource_bundle.h" |
| 26 #include "webkit/plugins/npapi/plugin_list.h" | |
| 27 #include "webkit/plugins/webplugininfo.h" | 24 #include "webkit/plugins/webplugininfo.h" |
| 28 | 25 |
| 26 // The URL for the "learn more" article about the PPAPI broker. |
| 27 const char kPpapiBrokerLearnMoreUrl[] = |
| 28 "https://support.google.com/chrome/?p=ib_pepper_broker"; |
| 29 |
| 29 using content::OpenURLParams; | 30 using content::OpenURLParams; |
| 30 using content::Referrer; | 31 using content::Referrer; |
| 31 using content::WebContents; | 32 using content::WebContents; |
| 32 | 33 |
| 33 DEFINE_WEB_CONTENTS_USER_DATA_KEY(PepperBrokerObserver) | 34 // static |
| 35 void PepperBrokerInfoBarDelegate::Show( |
| 36 WebContents* web_contents, |
| 37 const GURL& url, |
| 38 const FilePath& plugin_path, |
| 39 const base::Callback<void(bool)>& callback) { |
| 40 // TODO(wad): Add ephemeral device ID support for broker in guest mode. |
| 41 if (Profile::IsGuestSession()) { |
| 42 callback.Run(false); |
| 43 return; |
| 44 } |
| 34 | 45 |
| 35 namespace { | 46 Profile* profile = |
| 47 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| 48 HostContentSettingsMap* content_settings = |
| 49 profile->GetHostContentSettingsMap(); |
| 50 ContentSetting setting = |
| 51 content_settings->GetContentSetting(url, url, |
| 52 CONTENT_SETTINGS_TYPE_PPAPI_BROKER, |
| 53 std::string()); |
| 54 switch (setting) { |
| 55 case CONTENT_SETTING_ALLOW: { |
| 56 content::RecordAction( |
| 57 content::UserMetricsAction("PPAPI.BrokerSettingAllow")); |
| 58 callback.Run(true); |
| 59 break; |
| 60 } |
| 61 case CONTENT_SETTING_BLOCK: { |
| 62 content::RecordAction( |
| 63 content::UserMetricsAction("PPAPI.BrokerSettingDeny")); |
| 64 callback.Run(false); |
| 65 break; |
| 66 } |
| 67 case CONTENT_SETTING_ASK: { |
| 68 content::RecordAction( |
| 69 content::UserMetricsAction("PPAPI.BrokerInfobarDisplayed")); |
| 36 | 70 |
| 37 // The URL for the "learn more" article about the PPAPI broker. | 71 InfoBarTabHelper* infobar_helper = |
| 38 const char kPpapiBrokerLearnMoreUrl[] = | 72 InfoBarTabHelper::FromWebContents(web_contents); |
| 39 "https://support.google.com/chrome/?p=ib_pepper_broker"; | 73 std::string languages = |
| 40 | 74 profile->GetPrefs()->GetString(prefs::kAcceptLanguages); |
| 41 class PepperBrokerInfoBarDelegate : public ConfirmInfoBarDelegate { | 75 infobar_helper->AddInfoBar( |
| 42 public: | 76 new PepperBrokerInfoBarDelegate( |
| 43 static void Show( | 77 infobar_helper, url, plugin_path, languages, content_settings, |
| 44 content::WebContents* web_contents, | 78 callback)); |
| 45 const GURL& url, | 79 break; |
| 46 const FilePath& plugin_path, | 80 } |
| 47 const base::Callback<void(bool)>& callback); | 81 default: |
| 48 | 82 NOTREACHED(); |
| 49 PepperBrokerInfoBarDelegate( | 83 } |
| 50 InfoBarTabHelper* helper, | 84 } |
| 51 const GURL& url, | |
| 52 const FilePath& plugin_path, | |
| 53 const std::string& languages, | |
| 54 HostContentSettingsMap* content_settings, | |
| 55 const base::Callback<void(bool)>& callback); | |
| 56 virtual ~PepperBrokerInfoBarDelegate(); | |
| 57 | |
| 58 // ConfirmInfoBarDelegate: | |
| 59 virtual string16 GetMessageText() const OVERRIDE; | |
| 60 virtual int GetButtons() const OVERRIDE; | |
| 61 virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; | |
| 62 virtual bool Accept() OVERRIDE; | |
| 63 virtual bool Cancel() OVERRIDE; | |
| 64 virtual string16 GetLinkText() const OVERRIDE; | |
| 65 virtual bool LinkClicked(WindowOpenDisposition disposition) OVERRIDE; | |
| 66 virtual gfx::Image* GetIcon() const OVERRIDE; | |
| 67 | |
| 68 private: | |
| 69 void DispatchCallback(bool result); | |
| 70 | |
| 71 const GURL url_; | |
| 72 const FilePath plugin_path_; | |
| 73 const std::string languages_; | |
| 74 HostContentSettingsMap* content_settings_; | |
| 75 base::Callback<void(bool)> callback_; | |
| 76 | |
| 77 DISALLOW_COPY_AND_ASSIGN(PepperBrokerInfoBarDelegate); | |
| 78 }; | |
| 79 | 85 |
| 80 PepperBrokerInfoBarDelegate::PepperBrokerInfoBarDelegate( | 86 PepperBrokerInfoBarDelegate::PepperBrokerInfoBarDelegate( |
| 81 InfoBarTabHelper* helper, | 87 InfoBarTabHelper* helper, |
| 82 const GURL& url, | 88 const GURL& url, |
| 83 const FilePath& plugin_path, | 89 const FilePath& plugin_path, |
| 84 const std::string& languages, | 90 const std::string& languages, |
| 85 HostContentSettingsMap* content_settings, | 91 HostContentSettingsMap* content_settings, |
| 86 const base::Callback<void(bool)>& callback) | 92 const base::Callback<void(bool)>& callback) |
| 87 : ConfirmInfoBarDelegate(helper), | 93 : ConfirmInfoBarDelegate(helper), |
| 88 url_(url), | 94 url_(url), |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 content::UserMetricsAction("PPAPI.BrokerInfobarClickedAllow") : | 169 content::UserMetricsAction("PPAPI.BrokerInfobarClickedAllow") : |
| 164 content::UserMetricsAction("PPAPI.BrokerInfobarClickedDeny")); | 170 content::UserMetricsAction("PPAPI.BrokerInfobarClickedDeny")); |
| 165 callback_.Run(result); | 171 callback_.Run(result); |
| 166 callback_ = base::Callback<void(bool)>(); | 172 callback_ = base::Callback<void(bool)>(); |
| 167 content_settings_->SetContentSetting( | 173 content_settings_->SetContentSetting( |
| 168 ContentSettingsPattern::FromURLNoWildcard(url_), | 174 ContentSettingsPattern::FromURLNoWildcard(url_), |
| 169 ContentSettingsPattern::Wildcard(), | 175 ContentSettingsPattern::Wildcard(), |
| 170 CONTENT_SETTINGS_TYPE_PPAPI_BROKER, | 176 CONTENT_SETTINGS_TYPE_PPAPI_BROKER, |
| 171 std::string(), result ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK); | 177 std::string(), result ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK); |
| 172 } | 178 } |
| 173 | |
| 174 } // namespace | |
| 175 | |
| 176 PepperBrokerObserver::PepperBrokerObserver(WebContents* web_contents) | |
| 177 : WebContentsObserver(web_contents) {} | |
| 178 | |
| 179 PepperBrokerObserver::~PepperBrokerObserver() {} | |
| 180 | |
| 181 bool PepperBrokerObserver::RequestPpapiBrokerPermission( | |
| 182 WebContents* web_contents, | |
| 183 const GURL& url, | |
| 184 const FilePath& plugin_path, | |
| 185 const base::Callback<void(bool)>& callback) { | |
| 186 Profile* profile = | |
| 187 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | |
| 188 // TODO(wad): Add ephemeral device ID support for broker in guest mode. | |
| 189 if (Profile::IsGuestSession()) { | |
| 190 callback.Run(false); | |
| 191 return true; | |
| 192 } | |
| 193 | |
| 194 HostContentSettingsMap* content_settings = | |
| 195 profile->GetHostContentSettingsMap(); | |
| 196 ContentSetting setting = | |
| 197 content_settings->GetContentSetting(url, url, | |
| 198 CONTENT_SETTINGS_TYPE_PPAPI_BROKER, | |
| 199 std::string()); | |
| 200 switch (setting) { | |
| 201 case CONTENT_SETTING_ALLOW: { | |
| 202 content::RecordAction( | |
| 203 content::UserMetricsAction("PPAPI.BrokerSettingAllow")); | |
| 204 callback.Run(true); | |
| 205 break; | |
| 206 } | |
| 207 case CONTENT_SETTING_BLOCK: { | |
| 208 content::RecordAction( | |
| 209 content::UserMetricsAction("PPAPI.BrokerSettingDeny")); | |
| 210 callback.Run(false); | |
| 211 break; | |
| 212 } | |
| 213 case CONTENT_SETTING_ASK: { | |
| 214 content::RecordAction( | |
| 215 content::UserMetricsAction("PPAPI.BrokerInfobarDisplayed")); | |
| 216 | |
| 217 InfoBarTabHelper* infobar_helper = | |
| 218 InfoBarTabHelper::FromWebContents(web_contents); | |
| 219 std::string languages = | |
| 220 profile->GetPrefs()->GetString(prefs::kAcceptLanguages); | |
| 221 infobar_helper->AddInfoBar( | |
| 222 new PepperBrokerInfoBarDelegate( | |
| 223 infobar_helper, url, plugin_path, languages, content_settings, | |
| 224 callback)); | |
| 225 break; | |
| 226 } | |
| 227 default: | |
| 228 NOTREACHED(); | |
| 229 } | |
| 230 | |
| 231 return true; | |
| 232 } | |
| OLD | NEW |