| Index: chrome/browser/ui/browser.cc
|
| diff --git a/chrome/browser/ui/browser.cc b/chrome/browser/ui/browser.cc
|
| index 309b743c69414332c767ff7e2631a0fd7b315b94..4c720b529a0907abda901f9d1fae3379d8ddd496 100644
|
| --- a/chrome/browser/ui/browser.cc
|
| +++ b/chrome/browser/ui/browser.cc
|
| @@ -194,6 +194,8 @@
|
| #include "webkit/glue/web_intent_service_data.h"
|
| #include "webkit/glue/webkit_glue.h"
|
| #include "webkit/glue/window_open_disposition.h"
|
| +#include "webkit/plugins/npapi/plugin_group.h"
|
| +#include "webkit/plugins/npapi/plugin_list.h"
|
| #include "webkit/plugins/webplugininfo.h"
|
|
|
| #if defined(OS_WIN)
|
| @@ -239,6 +241,10 @@ const char kBrokenPageUrl[] =
|
| // The URL for the privacy dashboard.
|
| const char kPrivacyDashboardUrl[] = "https://www.google.com/dashboard";
|
|
|
| +// The URL for the "learn more" article about the PPAPI broker.
|
| +const char kPpapiBrokerLearnMoreUrl[] =
|
| + "https://support.google.com/chrome/?p=ib_pepper_broker";
|
| +
|
| // How long we wait before updating the browser chrome while loading a page.
|
| const int kUIUpdateCoalescingTimeMS = 200;
|
|
|
| @@ -263,6 +269,122 @@ chrome::HostDesktopType kDefaultHostDesktopType =
|
| #endif
|
|
|
|
|
| +class PpapiBrokerPermissionInfoBarDelegate : public ConfirmInfoBarDelegate {
|
| + public:
|
| + PpapiBrokerPermissionInfoBarDelegate(
|
| + InfoBarTabHelper* helper,
|
| + const GURL& url,
|
| + const FilePath& plugin_path,
|
| + const std::string& languages,
|
| + HostContentSettingsMap* content_settings,
|
| + const base::Callback<void(bool)>& callback);
|
| + virtual ~PpapiBrokerPermissionInfoBarDelegate();
|
| +
|
| + // ConfirmInfoBarDelegate:
|
| + virtual string16 GetMessageText() const OVERRIDE;
|
| + virtual int GetButtons() const OVERRIDE;
|
| + virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE;
|
| + virtual bool Accept() OVERRIDE;
|
| + virtual bool Cancel() OVERRIDE;
|
| + virtual string16 GetLinkText() const OVERRIDE;
|
| + virtual bool LinkClicked(WindowOpenDisposition disposition) OVERRIDE;
|
| + virtual gfx::Image* GetIcon() const OVERRIDE;
|
| +
|
| + private:
|
| + GURL url_;
|
| + FilePath plugin_path_;
|
| + std::string languages_;
|
| + HostContentSettingsMap* content_settings_;
|
| + base::Callback<void(bool)> callback_;
|
| +};
|
| +
|
| +PpapiBrokerPermissionInfoBarDelegate::PpapiBrokerPermissionInfoBarDelegate(
|
| + InfoBarTabHelper* helper,
|
| + const GURL& url,
|
| + const FilePath& plugin_path,
|
| + const std::string& languages,
|
| + HostContentSettingsMap* content_settings,
|
| + const base::Callback<void(bool)>& callback)
|
| + : ConfirmInfoBarDelegate(helper),
|
| + url_(url),
|
| + plugin_path_(plugin_path),
|
| + languages_(languages),
|
| + content_settings_(content_settings),
|
| + callback_(callback) {
|
| +}
|
| +
|
| +PpapiBrokerPermissionInfoBarDelegate::~PpapiBrokerPermissionInfoBarDelegate() {
|
| + if (!callback_.is_null())
|
| + callback_.Run(false);
|
| +}
|
| +
|
| +string16 PpapiBrokerPermissionInfoBarDelegate::GetMessageText() const {
|
| + content::PluginService* plugin_service =
|
| + content::PluginService::GetInstance();
|
| + webkit::WebPluginInfo plugin;
|
| + bool success = plugin_service->GetPluginInfoByPath(plugin_path_, &plugin);
|
| + DCHECK(success);
|
| + scoped_ptr<webkit::npapi::PluginGroup> plugin_group(
|
| + plugin_service->GetPluginList()->GetPluginGroup(plugin));
|
| + return l10n_util::GetStringFUTF16(IDS_PPAPI_BROKER_INFOBAR_QUESTION,
|
| + plugin_group->GetGroupName(),
|
| + net::FormatUrl(url_, languages_));
|
| +}
|
| +
|
| +int PpapiBrokerPermissionInfoBarDelegate::GetButtons() const {
|
| + return BUTTON_OK | BUTTON_CANCEL;
|
| +}
|
| +
|
| +string16 PpapiBrokerPermissionInfoBarDelegate::GetButtonLabel(
|
| + InfoBarButton button) const {
|
| + switch (button) {
|
| + case BUTTON_OK:
|
| + return l10n_util::GetStringUTF16(IDS_PPAPI_BROKER_ALLOW_BUTTON);
|
| + case BUTTON_CANCEL:
|
| + return l10n_util::GetStringUTF16(IDS_PPAPI_BROKER_DENY_BUTTON);
|
| + default:
|
| + NOTREACHED();
|
| + return string16();
|
| + }
|
| +}
|
| +
|
| +bool PpapiBrokerPermissionInfoBarDelegate::Accept() {
|
| + callback_.Run(true);
|
| + callback_ = base::Callback<void(bool)>();
|
| + content_settings_->SetContentSetting(
|
| + ContentSettingsPattern::FromURLNoWildcard(url_),
|
| + ContentSettingsPattern::Wildcard(),
|
| + CONTENT_SETTINGS_TYPE_PPAPI_BROKER,
|
| + std::string(), CONTENT_SETTING_ALLOW);
|
| + return true;
|
| +}
|
| +
|
| +bool PpapiBrokerPermissionInfoBarDelegate::Cancel() {
|
| + callback_.Run(false);
|
| + callback_ = base::Callback<void(bool)>();
|
| + return true;
|
| +}
|
| +
|
| +string16 PpapiBrokerPermissionInfoBarDelegate::GetLinkText() const {
|
| + return l10n_util::GetStringUTF16(IDS_LEARN_MORE);
|
| +}
|
| +
|
| +bool PpapiBrokerPermissionInfoBarDelegate::LinkClicked(
|
| + WindowOpenDisposition disposition) {
|
| + OpenURLParams params(
|
| + GURL(kPpapiBrokerLearnMoreUrl), Referrer(),
|
| + (disposition == CURRENT_TAB) ? NEW_FOREGROUND_TAB : disposition,
|
| + content::PAGE_TRANSITION_LINK,
|
| + false);
|
| + owner()->web_contents()->OpenURL(params);
|
| + return false;
|
| +}
|
| +
|
| +gfx::Image* PpapiBrokerPermissionInfoBarDelegate::GetIcon() const {
|
| + return &ResourceBundle::GetSharedInstance().GetNativeImageNamed(
|
| + IDR_INFOBAR_PLUGIN_INSTALL);
|
| +}
|
| +
|
| } // namespace
|
|
|
| ////////////////////////////////////////////////////////////////////////////////
|
| @@ -985,8 +1107,47 @@ void Browser::RequestPpapiBrokerPermissionHelper(
|
| const GURL& url,
|
| const FilePath& plugin_path,
|
| const base::Callback<void(bool)>& callback) {
|
| - // TODO(bauerb): Request permission.
|
| - callback.Run(true);
|
| + TabContents* tab = TabContents::FromWebContents(web_contents);
|
| + if (!tab) {
|
| + callback.Run(false);
|
| + return;
|
| + }
|
| +
|
| + Profile* profile = tab->profile();
|
| + // Disallow broker access in incognito mode.
|
| + if (profile->IsOffTheRecord() || Profile::IsGuestSession()) {
|
| + callback.Run(false);
|
| + return;
|
| + }
|
| +
|
| + HostContentSettingsMap* content_settings =
|
| + profile->GetHostContentSettingsMap();
|
| + ContentSetting setting =
|
| + content_settings->GetContentSetting(url, url,
|
| + CONTENT_SETTINGS_TYPE_PPAPI_BROKER,
|
| + std::string());
|
| + switch (setting) {
|
| + case CONTENT_SETTING_ALLOW: {
|
| + callback.Run(true);
|
| + break;
|
| + }
|
| + case CONTENT_SETTING_BLOCK: {
|
| + callback.Run(false);
|
| + break;
|
| + }
|
| + case CONTENT_SETTING_ASK: {
|
| + InfoBarTabHelper* infobar_helper = tab->infobar_tab_helper();
|
| + std::string languages =
|
| + profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
|
| + infobar_helper->AddInfoBar(
|
| + new PpapiBrokerPermissionInfoBarDelegate(
|
| + infobar_helper, url, plugin_path, languages, content_settings,
|
| + callback));
|
| + break;
|
| + }
|
| + default:
|
| + NOTREACHED();
|
| + }
|
| }
|
|
|
| void Browser::UpdateUIForNavigationInTab(TabContents* contents,
|
|
|