Index: chrome/browser/ui/browser.cc |
diff --git a/chrome/browser/ui/browser.cc b/chrome/browser/ui/browser.cc |
index 8733ae882a51f8b611f8f88f45cca87e4a94bb09..4b84fd409472f15b5986ae72200357aeb50e7736 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; |
@@ -255,6 +261,122 @@ BrowserWindow* CreateBrowserWindow(Browser* browser) { |
return BrowserWindow::CreateBrowserWindow(browser); |
} |
+class PpapiBrokerPermissionInfoBarDelegate : public ConfirmInfoBarDelegate { |
markusheintz_
2012/08/13 06:09:06
nit: I wonder whether this class should live in it
Bernhard Bauer
2012/08/13 10:51:46
Yeah, I'm not sure either. I'm slightly leaning to
|
+ public: |
+ PpapiBrokerPermissionInfoBarDelegate( |
+ InfoBarTabHelper* helper, |
+ const GURL& url, |
+ const FilePath& plugin_path, |
+ const std::string& languages, |
+ HostContentSettingsMap* content_settings, |
+ const base::Callback<void(bool)>& callback); |
+ ~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 |
//////////////////////////////////////////////////////////////////////////////// |
@@ -961,8 +1083,41 @@ 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(); |
+ 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, |