diff options
-rw-r--r-- | android_webview/browser/renderer_host/aw_render_view_host_ext.h | 1 | ||||
-rw-r--r-- | chrome/browser/pepper_broker_infobar_delegate.cc (renamed from chrome/browser/pepper_broker_observer.cc) | 162 | ||||
-rw-r--r-- | chrome/browser/pepper_broker_infobar_delegate.h | 63 | ||||
-rw-r--r-- | chrome/browser/pepper_broker_observer.h | 30 | ||||
-rw-r--r-- | chrome/browser/ui/browser.cc | 10 | ||||
-rw-r--r-- | chrome/browser/ui/browser.h | 5 | ||||
-rw-r--r-- | chrome/browser/ui/tab_contents/tab_contents.cc | 2 | ||||
-rw-r--r-- | chrome/browser/ui/views/external_tab_container_win.cc | 10 | ||||
-rw-r--r-- | chrome/browser/ui/views/external_tab_container_win.h | 5 | ||||
-rw-r--r-- | chrome/chrome_browser.gypi | 4 | ||||
-rw-r--r-- | content/browser/web_contents/web_contents_impl.cc | 21 | ||||
-rw-r--r-- | content/public/browser/web_contents_delegate.cc | 8 | ||||
-rw-r--r-- | content/public/browser/web_contents_delegate.h | 9 | ||||
-rw-r--r-- | content/public/browser/web_contents_observer.cc | 8 | ||||
-rw-r--r-- | content/public/browser/web_contents_observer.h | 13 |
15 files changed, 177 insertions, 174 deletions
diff --git a/android_webview/browser/renderer_host/aw_render_view_host_ext.h b/android_webview/browser/renderer_host/aw_render_view_host_ext.h index a2b8466..a6d8dde 100644 --- a/android_webview/browser/renderer_host/aw_render_view_host_ext.h +++ b/android_webview/browser/renderer_host/aw_render_view_host_ext.h @@ -8,6 +8,7 @@ #include "content/public/browser/web_contents_observer.h" #include "android_webview/common/aw_hit_test_data.h" +#include "base/callback_forward.h" #include "base/threading/non_thread_safe.h" namespace android_webview { diff --git a/chrome/browser/pepper_broker_observer.cc b/chrome/browser/pepper_broker_infobar_delegate.cc index 77d66ff..3ef8edf 100644 --- a/chrome/browser/pepper_broker_observer.cc +++ b/chrome/browser/pepper_broker_infobar_delegate.cc @@ -2,10 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/browser/pepper_broker_observer.h" +#include "chrome/browser/pepper_broker_infobar_delegate.h" -#include "base/memory/scoped_ptr.h" -#include "chrome/browser/api/infobars/confirm_infobar_delegate.h" #include "chrome/browser/content_settings/host_content_settings_map.h" #include "chrome/browser/infobars/infobar_tab_helper.h" #include "chrome/browser/plugins/plugin_finder.h" @@ -23,59 +21,67 @@ #include "net/base/net_util.h" #include "ui/base/l10n/l10n_util.h" #include "ui/base/resource/resource_bundle.h" -#include "webkit/plugins/npapi/plugin_list.h" #include "webkit/plugins/webplugininfo.h" +// The URL for the "learn more" article about the PPAPI broker. +const char kPpapiBrokerLearnMoreUrl[] = + "https://support.google.com/chrome/?p=ib_pepper_broker"; + using content::OpenURLParams; using content::Referrer; using content::WebContents; -DEFINE_WEB_CONTENTS_USER_DATA_KEY(PepperBrokerObserver) - -namespace { +// static +void PepperBrokerInfoBarDelegate::Show( + WebContents* web_contents, + const GURL& url, + const FilePath& plugin_path, + const base::Callback<void(bool)>& callback) { + // TODO(wad): Add ephemeral device ID support for broker in guest mode. + if (Profile::IsGuestSession()) { + callback.Run(false); + return; + } -// The URL for the "learn more" article about the PPAPI broker. -const char kPpapiBrokerLearnMoreUrl[] = - "https://support.google.com/chrome/?p=ib_pepper_broker"; + Profile* profile = + Profile::FromBrowserContext(web_contents->GetBrowserContext()); + 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: { + content::RecordAction( + content::UserMetricsAction("PPAPI.BrokerSettingAllow")); + callback.Run(true); + break; + } + case CONTENT_SETTING_BLOCK: { + content::RecordAction( + content::UserMetricsAction("PPAPI.BrokerSettingDeny")); + callback.Run(false); + break; + } + case CONTENT_SETTING_ASK: { + content::RecordAction( + content::UserMetricsAction("PPAPI.BrokerInfobarDisplayed")); -class PepperBrokerInfoBarDelegate : public ConfirmInfoBarDelegate { - public: - static void Show( - content::WebContents* web_contents, - const GURL& url, - const FilePath& plugin_path, - const base::Callback<void(bool)>& callback); - - PepperBrokerInfoBarDelegate( - InfoBarTabHelper* helper, - const GURL& url, - const FilePath& plugin_path, - const std::string& languages, - HostContentSettingsMap* content_settings, - const base::Callback<void(bool)>& callback); - virtual ~PepperBrokerInfoBarDelegate(); - - // 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: - void DispatchCallback(bool result); - - const GURL url_; - const FilePath plugin_path_; - const std::string languages_; - HostContentSettingsMap* content_settings_; - base::Callback<void(bool)> callback_; - - DISALLOW_COPY_AND_ASSIGN(PepperBrokerInfoBarDelegate); -}; + InfoBarTabHelper* infobar_helper = + InfoBarTabHelper::FromWebContents(web_contents); + std::string languages = + profile->GetPrefs()->GetString(prefs::kAcceptLanguages); + infobar_helper->AddInfoBar( + new PepperBrokerInfoBarDelegate( + infobar_helper, url, plugin_path, languages, content_settings, + callback)); + break; + } + default: + NOTREACHED(); + } +} PepperBrokerInfoBarDelegate::PepperBrokerInfoBarDelegate( InfoBarTabHelper* helper, @@ -170,63 +176,3 @@ void PepperBrokerInfoBarDelegate::DispatchCallback(bool result) { CONTENT_SETTINGS_TYPE_PPAPI_BROKER, std::string(), result ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK); } - -} // namespace - -PepperBrokerObserver::PepperBrokerObserver(WebContents* web_contents) - : WebContentsObserver(web_contents) {} - -PepperBrokerObserver::~PepperBrokerObserver() {} - -bool PepperBrokerObserver::RequestPpapiBrokerPermission( - WebContents* web_contents, - const GURL& url, - const FilePath& plugin_path, - const base::Callback<void(bool)>& callback) { - Profile* profile = - Profile::FromBrowserContext(web_contents->GetBrowserContext()); - // TODO(wad): Add ephemeral device ID support for broker in guest mode. - if (Profile::IsGuestSession()) { - callback.Run(false); - return true; - } - - 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: { - content::RecordAction( - content::UserMetricsAction("PPAPI.BrokerSettingAllow")); - callback.Run(true); - break; - } - case CONTENT_SETTING_BLOCK: { - content::RecordAction( - content::UserMetricsAction("PPAPI.BrokerSettingDeny")); - callback.Run(false); - break; - } - case CONTENT_SETTING_ASK: { - content::RecordAction( - content::UserMetricsAction("PPAPI.BrokerInfobarDisplayed")); - - InfoBarTabHelper* infobar_helper = - InfoBarTabHelper::FromWebContents(web_contents); - std::string languages = - profile->GetPrefs()->GetString(prefs::kAcceptLanguages); - infobar_helper->AddInfoBar( - new PepperBrokerInfoBarDelegate( - infobar_helper, url, plugin_path, languages, content_settings, - callback)); - break; - } - default: - NOTREACHED(); - } - - return true; -} diff --git a/chrome/browser/pepper_broker_infobar_delegate.h b/chrome/browser/pepper_broker_infobar_delegate.h new file mode 100644 index 0000000..0d05371 --- /dev/null +++ b/chrome/browser/pepper_broker_infobar_delegate.h @@ -0,0 +1,63 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_PEPPER_BROKER_INFOBAR_DELEGATE_H_ +#define CHROME_BROWSER_PEPPER_BROKER_INFOBAR_DELEGATE_H_ + +#include "base/callback.h" +#include "base/file_path.h" +#include "chrome/browser/api/infobars/confirm_infobar_delegate.h" +#include "googleurl/src/gurl.h" + +class HostContentSettingsMap; +class InfoBarTabHelper; + +namespace content { +class WebContents; +} + +// Shows an infobar that asks the user whether a Pepper plug-in is allowed +// to connect to its (privileged) broker. The user decision is made "sticky" +// by storing a content setting for the site. +class PepperBrokerInfoBarDelegate : public ConfirmInfoBarDelegate { + public: + virtual ~PepperBrokerInfoBarDelegate(); + + static void Show( + content::WebContents* web_contents, + const GURL& url, + const FilePath& plugin_path, + const base::Callback<void(bool)>& callback); + + // 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: + PepperBrokerInfoBarDelegate( + InfoBarTabHelper* helper, + const GURL& url, + const FilePath& plugin_path, + const std::string& languages, + HostContentSettingsMap* content_settings, + const base::Callback<void(bool)>& callback); + + void DispatchCallback(bool result); + + const GURL url_; + const FilePath plugin_path_; + const std::string languages_; + HostContentSettingsMap* content_settings_; + base::Callback<void(bool)> callback_; + + DISALLOW_COPY_AND_ASSIGN(PepperBrokerInfoBarDelegate); +}; + +#endif // CHROME_BROWSER_PEPPER_BROKER_INFOBAR_DELEGATE_H_ diff --git a/chrome/browser/pepper_broker_observer.h b/chrome/browser/pepper_broker_observer.h deleted file mode 100644 index 966d584..0000000 --- a/chrome/browser/pepper_broker_observer.h +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_PEPPER_BROKER_OBSERVER_H_ -#define CHROME_BROWSER_PEPPER_BROKER_OBSERVER_H_ - -#include "content/public/browser/web_contents_observer.h" -#include "content/public/browser/web_contents_user_data.h" - -class PepperBrokerObserver - : public content::WebContentsObserver, - public content::WebContentsUserData<PepperBrokerObserver> { - public: - virtual ~PepperBrokerObserver(); - - private: - explicit PepperBrokerObserver(content::WebContents* web_contents); - friend class content::WebContentsUserData<PepperBrokerObserver>; - - virtual bool RequestPpapiBrokerPermission( - content::WebContents* web_contents, - const GURL& url, - const FilePath& plugin_path, - const base::Callback<void(bool)>& callback) OVERRIDE; - - DISALLOW_COPY_AND_ASSIGN(PepperBrokerObserver); -}; - -#endif // CHROME_BROWSER_PEPPER_BROKER_OBSERVER_H_ diff --git a/chrome/browser/ui/browser.cc b/chrome/browser/ui/browser.cc index 8fa3c3f..7d9721b 100644 --- a/chrome/browser/ui/browser.cc +++ b/chrome/browser/ui/browser.cc @@ -67,6 +67,7 @@ #include "chrome/browser/media/media_stream_devices_controller.h" #include "chrome/browser/net/url_fixer_upper.h" #include "chrome/browser/notifications/notification_ui_manager.h" +#include "chrome/browser/pepper_broker_infobar_delegate.h" #include "chrome/browser/platform_util.h" #include "chrome/browser/prefs/incognito_mode_prefs.h" #include "chrome/browser/prefs/pref_service.h" @@ -1766,6 +1767,15 @@ void Browser::RequestMediaAccessPermission( RequestMediaAccessPermissionHelper(web_contents, request, callback); } +bool Browser::RequestPpapiBrokerPermission( + WebContents* web_contents, + const GURL& url, + const FilePath& plugin_path, + const base::Callback<void(bool)>& callback) { + PepperBrokerInfoBarDelegate::Show(web_contents, url, plugin_path, callback); + return true; +} + /////////////////////////////////////////////////////////////////////////////// // Browser, CoreTabHelperDelegate implementation: diff --git a/chrome/browser/ui/browser.h b/chrome/browser/ui/browser.h index 87882e2..b7f3962 100644 --- a/chrome/browser/ui/browser.h +++ b/chrome/browser/ui/browser.h @@ -672,6 +672,11 @@ class Browser : public TabStripModelObserver, content::WebContents* web_contents, const content::MediaStreamRequest* request, const content::MediaResponseCallback& callback) OVERRIDE; + virtual bool RequestPpapiBrokerPermission( + content::WebContents* web_contents, + const GURL& url, + const FilePath& plugin_path, + const base::Callback<void(bool)>& callback) OVERRIDE; // Overridden from CoreTabHelperDelegate: // Note that the caller is responsible for deleting |old_tab_contents|. diff --git a/chrome/browser/ui/tab_contents/tab_contents.cc b/chrome/browser/ui/tab_contents/tab_contents.cc index d49d306..539af56 100644 --- a/chrome/browser/ui/tab_contents/tab_contents.cc +++ b/chrome/browser/ui/tab_contents/tab_contents.cc @@ -22,7 +22,6 @@ #include "chrome/browser/omnibox_search_hint.h" #include "chrome/browser/password_manager/password_manager.h" #include "chrome/browser/password_manager/password_manager_delegate_impl.h" -#include "chrome/browser/pepper_broker_observer.h" #include "chrome/browser/plugins/plugin_observer.h" #include "chrome/browser/prerender/prerender_tab_helper.h" #include "chrome/browser/printing/print_preview_message_handler.h" @@ -151,7 +150,6 @@ TabContents::TabContents(WebContents* contents) PasswordManagerDelegateImpl::CreateForWebContents(contents); PasswordManager::CreateForWebContentsAndDelegate( contents, PasswordManagerDelegateImpl::FromWebContents(contents)); - PepperBrokerObserver::CreateForWebContents(contents); PluginObserver::CreateForWebContents(contents); PrefsTabHelper::CreateForWebContents(contents); prerender::PrerenderTabHelper::CreateForWebContents(contents); diff --git a/chrome/browser/ui/views/external_tab_container_win.cc b/chrome/browser/ui/views/external_tab_container_win.cc index bab0013..8533731 100644 --- a/chrome/browser/ui/views/external_tab_container_win.cc +++ b/chrome/browser/ui/views/external_tab_container_win.cc @@ -25,6 +25,7 @@ #include "chrome/browser/history/history_tab_helper.h" #include "chrome/browser/history/history_types.h" #include "chrome/browser/infobars/infobar_tab_helper.h" +#include "chrome/browser/pepper_broker_infobar_delegate.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/repost_form_warning_controller.h" #include "chrome/browser/themes/theme_service.h" @@ -826,6 +827,15 @@ void ExternalTabContainerWin::RequestMediaAccessPermission( Browser::RequestMediaAccessPermissionHelper(web_contents, request, callback); } +bool ExternalTabContainerWin::RequestPpapiBrokerPermission( + WebContents* web_contents, + const GURL& url, + const FilePath& plugin_path, + const base::Callback<void(bool)>& callback) { + PepperBrokerInfoBarDelegate::Show(web_contents, url, plugin_path, callback); + return true; +} + bool ExternalTabContainerWin::OnMessageReceived(const IPC::Message& message) { bool handled = true; IPC_BEGIN_MESSAGE_MAP(ExternalTabContainerWin, message) diff --git a/chrome/browser/ui/views/external_tab_container_win.h b/chrome/browser/ui/views/external_tab_container_win.h index 42868d1..9b9a8e1 100644 --- a/chrome/browser/ui/views/external_tab_container_win.h +++ b/chrome/browser/ui/views/external_tab_container_win.h @@ -179,6 +179,11 @@ class ExternalTabContainerWin : public ExternalTabContainer, content::WebContents* web_contents, const content::MediaStreamRequest* request, const content::MediaResponseCallback& callback) OVERRIDE; + virtual bool RequestPpapiBrokerPermission( + content::WebContents* web_contents, + const GURL& url, + const FilePath& plugin_path, + const base::Callback<void(bool)>& callback) OVERRIDE; void RegisterRenderViewHost(content::RenderViewHost* render_view_host); void UnregisterRenderViewHost(content::RenderViewHost* render_view_host); diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 17a8aca..4308e3b 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -1220,8 +1220,8 @@ 'browser/password_manager/password_store_win.h', 'browser/password_manager/password_store_x.cc', 'browser/password_manager/password_store_x.h', - 'browser/pepper_broker_observer.cc', - 'browser/pepper_broker_observer.h', + 'browser/pepper_broker_infobar_delegate.cc', + 'browser/pepper_broker_infobar_delegate.h', 'browser/pepper_flash_settings_manager.cc', 'browser/pepper_flash_settings_manager.h', 'browser/pepper_gtalk_message_filter.cc', diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc index c9968d0..73260d3 100644 --- a/content/browser/web_contents/web_contents_impl.cc +++ b/content/browser/web_contents/web_contents_impl.cc @@ -2316,19 +2316,18 @@ void WebContentsImpl::OnRequestPpapiBrokerPermission( int request_id, const GURL& url, const FilePath& plugin_path) { - base::Callback<void(bool)> callback = - base::Bind(&WebContentsImpl::OnPpapiBrokerPermissionResult, - base::Unretained(this), request_id); - ObserverListBase<WebContentsObserver>::Iterator it(observers_); - WebContentsObserver* observer; - while ((observer = it.GetNext()) != NULL) { - if (observer->RequestPpapiBrokerPermission(this, url, plugin_path, - callback)) - return; + if (!delegate_) { + OnPpapiBrokerPermissionResult(request_id, false); + return; } - // Fall back to allowing the request if no observer handled it. - OnPpapiBrokerPermissionResult(request_id, true); + if (!delegate_->RequestPpapiBrokerPermission( + this, url, plugin_path, + base::Bind(&WebContentsImpl::OnPpapiBrokerPermissionResult, + base::Unretained(this), request_id))) { + NOTIMPLEMENTED(); + OnPpapiBrokerPermissionResult(request_id, false); + } } void WebContentsImpl::OnPpapiBrokerPermissionResult(int request_id, diff --git a/content/public/browser/web_contents_delegate.cc b/content/public/browser/web_contents_delegate.cc index 09488ff..e617e82 100644 --- a/content/public/browser/web_contents_delegate.cc +++ b/content/public/browser/web_contents_delegate.cc @@ -145,6 +145,14 @@ void WebContentsDelegate::WebIntentDispatch( delete intents_dispatcher; } +bool WebContentsDelegate::RequestPpapiBrokerPermission( + WebContents* web_contents, + const GURL& url, + const FilePath& plugin_path, + const base::Callback<void(bool)>& callback) { + return false; +} + WebContentsDelegate::~WebContentsDelegate() { while (!attached_contents_.empty()) { WebContents* web_contents = *attached_contents_.begin(); diff --git a/content/public/browser/web_contents_delegate.h b/content/public/browser/web_contents_delegate.h index c8e4256..db63498b 100644 --- a/content/public/browser/web_contents_delegate.h +++ b/content/public/browser/web_contents_delegate.h @@ -422,6 +422,15 @@ class CONTENT_EXPORT WebContentsDelegate { const MediaStreamRequest* request, const MediaResponseCallback& callback) {} + // Requests permission to access the PPAPI broker. The delegate should return + // true and call the passed in |callback| with the result, or return false + // to indicate that it does not support asking for permission. + virtual bool RequestPpapiBrokerPermission( + WebContents* web_contents, + const GURL& url, + const FilePath& plugin_path, + const base::Callback<void(bool)>& callback); + protected: virtual ~WebContentsDelegate(); diff --git a/content/public/browser/web_contents_observer.cc b/content/public/browser/web_contents_observer.cc index f40db1d..1479029 100644 --- a/content/public/browser/web_contents_observer.cc +++ b/content/public/browser/web_contents_observer.cc @@ -37,14 +37,6 @@ void WebContentsObserver::Observe(WebContents* web_contents) { } } -bool WebContentsObserver::RequestPpapiBrokerPermission( - WebContents* web_contents, - const GURL& url, - const FilePath& plugin_path, - const base::Callback<void(bool)>& callback) { - return false; -} - bool WebContentsObserver::OnMessageReceived(const IPC::Message& message) { return false; } diff --git a/content/public/browser/web_contents_observer.h b/content/public/browser/web_contents_observer.h index 93565da..14c7e77 100644 --- a/content/public/browser/web_contents_observer.h +++ b/content/public/browser/web_contents_observer.h @@ -5,7 +5,6 @@ #ifndef CONTENT_PUBLIC_BROWSER_WEB_CONTENTS_OBSERVER_H_ #define CONTENT_PUBLIC_BROWSER_WEB_CONTENTS_OBSERVER_H_ -#include "base/callback_forward.h" #include "base/process_util.h" #include "content/common/content_export.h" #include "content/public/browser/navigation_controller.h" @@ -138,18 +137,6 @@ class CONTENT_EXPORT WebContentsObserver : public IPC::Listener, // Called when the user agent override for a WebContents has been changed. virtual void UserAgentOverrideSet(const std::string& user_agent) {} - // Requests permission to access the PPAPI broker. If the object handles the - // request, it should return true and eventually call the passed in |callback| - // with the result. Otherwise it should return false, in which case the next - // observer will be called. - // Implementations should make sure not to call the callback after the - // WebContents has been destroyed. - virtual bool RequestPpapiBrokerPermission( - WebContents* web_contents, - const GURL& url, - const FilePath& plugin_path, - const base::Callback<void(bool)>& callback); - // Indicates that client 3D APIs (Pepper 3D, WebGL) were just // blocked on the current page, specifically because the GPU was // reset recently. |