diff options
author | yzshen@chromium.org <yzshen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-11 20:36:21 +0000 |
---|---|---|
committer | yzshen@chromium.org <yzshen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-11 20:36:21 +0000 |
commit | 55bcab8cc96da2b0f8bd51d4317c5d13c4016933 (patch) | |
tree | efae6dfd4a0d76354a7cfeb79b2dc6f0bcb25527 | |
parent | 27f24edaf473cfad1e552dfdc92749c7f192d971 (diff) | |
download | chromium_src-55bcab8cc96da2b0f8bd51d4317c5d13c4016933.zip chromium_src-55bcab8cc96da2b0f8bd51d4317c5d13c4016933.tar.gz chromium_src-55bcab8cc96da2b0f8bd51d4317c5d13c4016933.tar.bz2 |
Pepper Flash settings integration - camera and microphone.
BUG=112190
TEST=None
Review URL: https://chromiumcodereview.appspot.com/10479015
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@141482 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/app/generated_resources.grd | 12 | ||||
-rw-r--r-- | chrome/browser/DEPS | 2 | ||||
-rw-r--r-- | chrome/browser/pepper_flash_settings_manager.cc | 351 | ||||
-rw-r--r-- | chrome/browser/pepper_flash_settings_manager.h | 35 | ||||
-rw-r--r-- | chrome/browser/resources/options2/content_settings.html | 21 | ||||
-rw-r--r-- | chrome/browser/resources/options2/content_settings.js | 15 | ||||
-rw-r--r-- | chrome/browser/resources/options2/content_settings_exceptions_area.html | 4 | ||||
-rw-r--r-- | chrome/browser/resources/options2/content_settings_exceptions_area.js | 3 | ||||
-rw-r--r-- | chrome/browser/ui/webui/options2/content_settings_handler2.cc | 432 | ||||
-rw-r--r-- | chrome/browser/ui/webui/options2/content_settings_handler2.h | 56 | ||||
-rw-r--r-- | chrome/tools/chromeactions.txt | 4 | ||||
-rw-r--r-- | content/ppapi_plugin/broker_process_dispatcher.cc | 192 | ||||
-rw-r--r-- | content/ppapi_plugin/broker_process_dispatcher.h | 38 | ||||
-rw-r--r-- | ppapi/ppapi_shared.gypi | 1 | ||||
-rw-r--r-- | ppapi/proxy/ppapi_messages.h | 36 | ||||
-rw-r--r-- | ppapi/shared_impl/ppp_flash_browser_operations_shared.h | 33 |
16 files changed, 1088 insertions, 147 deletions
diff --git a/chrome/app/generated_resources.grd b/chrome/app/generated_resources.grd index a54505c..5cb849c 100644 --- a/chrome/app/generated_resources.grd +++ b/chrome/app/generated_resources.grd @@ -6960,6 +6960,18 @@ The following plug-in is unresponsive: <ph name="PLUGIN_NAME">$1 <message name="IDS_MOUSE_LOCK_BLOCK_RADIO" desc="A radio button in the Content Settings dialog for blocking all sites ability to disable the mouse cursor."> Do not allow any site to disable the mouse cursor </message> + <message name="IDS_PEPPER_FLASH_CAMERAMIC_TAB_LABEL" desc="Label for Pepper Flash camera and microphone tab on Content Settings dialog"> + Flash camera and microphone + </message> + <message name="IDS_PEPPER_FLASH_CAMERAMIC_HEADER" desc="Label for Pepper Flash camera and microphone exception management page on Content Settings dialog"> + Flash camera and microphone exceptions + </message> + <message name="IDS_PEPPER_FLASH_CAMERAMIC_ASK_RADIO" desc="A radio button in the Content Settings dialog for asking before allowing sites to use the camera or microphone."> + Ask me when a site wants to use the camera or microphone (recommended) + </message> + <message name="IDS_PEPPER_FLASH_CAMERAMIC_BLOCK_RADIO" desc="A radio button in the Content Settings dialog for blocking all sites from using the camera and microphone."> + Block all sites from using the camera and microphone + </message> <if expr="pp_ifdef('chromeos')"> <message name="IDS_PROTECTED_CONTENT_TAB_LABEL" desc="Label for the Protected Content tab on the Content Settings dialog."> Protected Content diff --git a/chrome/browser/DEPS b/chrome/browser/DEPS index cdd5f55..992f259 100644 --- a/chrome/browser/DEPS +++ b/chrome/browser/DEPS @@ -16,6 +16,8 @@ include_rules = [ "+ppapi/c", # For various types. "+ppapi/proxy", "+ppapi/shared_impl/api_id.h", + # Defines some types that are marshalled over IPC. + "+ppapi/shared_impl/ppp_flash_browser_operations_shared.h", "+rlz", "+sandbox/linux", "+sandbox/src", # The path doesn't say it, but this is the Windows sandbox. diff --git a/chrome/browser/pepper_flash_settings_manager.cc b/chrome/browser/pepper_flash_settings_manager.cc index ba7192d..8e246fb 100644 --- a/chrome/browser/pepper_flash_settings_manager.cc +++ b/chrome/browser/pepper_flash_settings_manager.cc @@ -40,6 +40,17 @@ class PepperFlashSettingsManager::Core void Detach(); void DeauthorizeContentLicenses(uint32 request_id); + void GetPermissionSettings( + uint32 request_id, + PP_Flash_BrowserOperations_SettingType setting_type); + void SetDefaultPermission( + uint32 request_id, + PP_Flash_BrowserOperations_SettingType setting_type, + PP_Flash_BrowserOperations_Permission permission, + bool clear_site_specific); + void SetSitePermission(uint32 request_id, + PP_Flash_BrowserOperations_SettingType setting_type, + const ppapi::FlashSiteSettings& sites); // IPC::Channel::Listener implementation. virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; @@ -51,14 +62,34 @@ class PepperFlashSettingsManager::Core enum RequestType { INVALID_REQUEST_TYPE = 0, - DEAUTHORIZE_CONTENT_LICENSES + DEAUTHORIZE_CONTENT_LICENSES, + GET_PERMISSION_SETTINGS, + SET_DEFAULT_PERMISSION, + SET_SITE_PERMISSION }; struct PendingRequest { - PendingRequest() : id(0), type(INVALID_REQUEST_TYPE) {} + PendingRequest() + : id(0), + type(INVALID_REQUEST_TYPE), + setting_type(PP_FLASH_BROWSEROPERATIONS_SETTINGTYPE_CAMERAMIC), + permission(PP_FLASH_BROWSEROPERATIONS_PERMISSION_DEFAULT), + clear_site_specific(false) { + } uint32 id; RequestType type; + + // Used by GET_PERMISSION_SETTINGS, SET_DEFAULT_PERMISSION and + // SET_SITE_PERMISSION. + PP_Flash_BrowserOperations_SettingType setting_type; + + // Used by SET_DEFAULT_PERMISSION. + PP_Flash_BrowserOperations_Permission permission; + bool clear_site_specific; + + // Used by SET_SITE_PERMISSION. + ppapi::FlashSiteSettings sites; }; virtual ~Core(); @@ -67,15 +98,43 @@ class PepperFlashSettingsManager::Core void ConnectToChannel(bool success, const IPC::ChannelHandle& handle); void DeauthorizeContentLicensesOnIOThread(uint32 request_id); + void GetPermissionSettingsOnIOThread( + uint32 request_id, + PP_Flash_BrowserOperations_SettingType setting_type); + void SetDefaultPermissionOnIOThread( + uint32 request_id, + PP_Flash_BrowserOperations_SettingType setting_type, + PP_Flash_BrowserOperations_Permission permission, + bool clear_site_specific); + void SetSitePermissionOnIOThread( + uint32 request_id, + PP_Flash_BrowserOperations_SettingType setting_type, + const ppapi::FlashSiteSettings& sites); + void NotifyErrorFromIOThread(); void NotifyDeauthorizeContentLicensesCompleted(uint32 request_id, bool success); + void NotifyGetPermissionSettingsCompleted( + uint32 request_id, + bool success, + PP_Flash_BrowserOperations_Permission default_permission, + const ppapi::FlashSiteSettings& sites); + void NotifySetDefaultPermissionCompleted(uint32 request_id, bool success); + void NotifySetSitePermissionCompleted(uint32 request_id, bool success); + void NotifyError( const std::vector<std::pair<uint32, RequestType> >& notifications); // Message handlers. void OnDeauthorizeContentLicensesResult(uint32 request_id, bool success); + void OnGetPermissionSettingsResult( + uint32 request_id, + bool success, + PP_Flash_BrowserOperations_Permission default_permission, + const ppapi::FlashSiteSettings& sites); + void OnSetDefaultPermissionResult(uint32 request_id, bool success); + void OnSetSitePermissionResult(uint32 request_id, bool success); // Used only on the UI thread. PepperFlashSettingsManager* manager_; @@ -140,11 +199,53 @@ void PepperFlashSettingsManager::Core::DeauthorizeContentLicenses( request_id)); } +void PepperFlashSettingsManager::Core::GetPermissionSettings( + uint32 request_id, + PP_Flash_BrowserOperations_SettingType setting_type) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + + BrowserThread::PostTask( + BrowserThread::IO, FROM_HERE, + base::Bind(&Core::GetPermissionSettingsOnIOThread, this, request_id, + setting_type)); +} + +void PepperFlashSettingsManager::Core::SetDefaultPermission( + uint32 request_id, + PP_Flash_BrowserOperations_SettingType setting_type, + PP_Flash_BrowserOperations_Permission permission, + bool clear_site_specific) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + + BrowserThread::PostTask( + BrowserThread::IO, FROM_HERE, + base::Bind(&Core::SetDefaultPermissionOnIOThread, this, request_id, + setting_type, permission, clear_site_specific)); +} + +void PepperFlashSettingsManager::Core::SetSitePermission( + uint32 request_id, + PP_Flash_BrowserOperations_SettingType setting_type, + const ppapi::FlashSiteSettings& sites) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + + BrowserThread::PostTask( + BrowserThread::IO, FROM_HERE, + base::Bind(&Core::SetSitePermissionOnIOThread, this, request_id, + setting_type, sites)); +} + bool PepperFlashSettingsManager::Core::OnMessageReceived( const IPC::Message& message) { IPC_BEGIN_MESSAGE_MAP(Core, message) IPC_MESSAGE_HANDLER(PpapiHostMsg_DeauthorizeContentLicensesResult, OnDeauthorizeContentLicensesResult) + IPC_MESSAGE_HANDLER(PpapiHostMsg_GetPermissionSettingsResult, + OnGetPermissionSettingsResult) + IPC_MESSAGE_HANDLER(PpapiHostMsg_SetDefaultPermissionResult, + OnSetDefaultPermissionResult) + IPC_MESSAGE_HANDLER(PpapiHostMsg_SetSitePermissionResult, + OnSetSitePermissionResult) IPC_MESSAGE_UNHANDLED_ERROR() IPC_END_MESSAGE_MAP() @@ -190,14 +291,14 @@ void PepperFlashSettingsManager::Core::ConnectToChannel( DCHECK(!channel_.get()); if (!success) { - LOG(ERROR) << "Couldn't open plugin channel"; + DLOG(ERROR) << "Couldn't open plugin channel"; NotifyErrorFromIOThread(); return; } channel_.reset(new IPC::Channel(handle, IPC::Channel::MODE_CLIENT, this)); if (!channel_->Connect()) { - LOG(ERROR) << "Couldn't connect to plugin"; + DLOG(ERROR) << "Couldn't connect to plugin"; NotifyErrorFromIOThread(); return; } @@ -213,6 +314,17 @@ void PepperFlashSettingsManager::Core::ConnectToChannel( case DEAUTHORIZE_CONTENT_LICENSES: DeauthorizeContentLicensesOnIOThread(iter->id); break; + case GET_PERMISSION_SETTINGS: + GetPermissionSettingsOnIOThread(iter->id, iter->setting_type); + break; + case SET_DEFAULT_PERMISSION: + SetDefaultPermissionOnIOThread( + iter->id, iter->setting_type, iter->permission, + iter->clear_site_specific); + break; + case SET_SITE_PERMISSION: + SetSitePermissionOnIOThread(iter->id, iter->setting_type, iter->sites); + break; default: NOTREACHED(); break; @@ -237,7 +349,90 @@ void PepperFlashSettingsManager::Core::DeauthorizeContentLicensesOnIOThread( IPC::Message* msg = new PpapiMsg_DeauthorizeContentLicenses(request_id, plugin_data_path_); if (!channel_->Send(msg)) { - LOG(ERROR) << "Couldn't send DeauthorizeContentLicenses message"; + DLOG(ERROR) << "Couldn't send DeauthorizeContentLicenses message"; + // A failure notification for the current request will be sent since + // |pending_responses_| has been updated. + NotifyErrorFromIOThread(); + } +} + +void PepperFlashSettingsManager::Core::GetPermissionSettingsOnIOThread( + uint32 request_id, + PP_Flash_BrowserOperations_SettingType setting_type) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); + + if (!initialized_) { + PendingRequest request; + request.id = request_id; + request.type = GET_PERMISSION_SETTINGS; + request.setting_type = setting_type; + pending_requests_.push_back(request); + return; + } + + pending_responses_.insert( + std::make_pair(request_id, GET_PERMISSION_SETTINGS)); + IPC::Message* msg = new PpapiMsg_GetPermissionSettings( + request_id, plugin_data_path_, setting_type); + if (!channel_->Send(msg)) { + DLOG(ERROR) << "Couldn't send GetPermissionSettings message"; + // A failure notification for the current request will be sent since + // |pending_responses_| has been updated. + NotifyErrorFromIOThread(); + } +} + +void PepperFlashSettingsManager::Core::SetDefaultPermissionOnIOThread( + uint32 request_id, + PP_Flash_BrowserOperations_SettingType setting_type, + PP_Flash_BrowserOperations_Permission permission, + bool clear_site_specific) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); + + if (!initialized_) { + PendingRequest request; + request.id = request_id; + request.type = SET_DEFAULT_PERMISSION; + request.setting_type = setting_type; + request.permission = permission; + request.clear_site_specific = clear_site_specific; + pending_requests_.push_back(request); + return; + } + + pending_responses_.insert(std::make_pair(request_id, SET_DEFAULT_PERMISSION)); + IPC::Message* msg = new PpapiMsg_SetDefaultPermission( + request_id, plugin_data_path_, setting_type, permission, + clear_site_specific); + if (!channel_->Send(msg)) { + DLOG(ERROR) << "Couldn't send SetDefaultPermission message"; + // A failure notification for the current request will be sent since + // |pending_responses_| has been updated. + NotifyErrorFromIOThread(); + } +} + +void PepperFlashSettingsManager::Core::SetSitePermissionOnIOThread( + uint32 request_id, + PP_Flash_BrowserOperations_SettingType setting_type, + const ppapi::FlashSiteSettings& sites) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); + + if (!initialized_) { + pending_requests_.push_back(PendingRequest()); + PendingRequest& request = pending_requests_.back(); + request.id = request_id; + request.type = SET_SITE_PERMISSION; + request.setting_type = setting_type; + request.sites = sites; + return; + } + + pending_responses_.insert(std::make_pair(request_id, SET_SITE_PERMISSION)); + IPC::Message* msg = new PpapiMsg_SetSitePermission( + request_id, plugin_data_path_, setting_type, sites); + if (!channel_->Send(msg)) { + DLOG(ERROR) << "Couldn't send SetSitePermission message"; // A failure notification for the current request will be sent since // |pending_responses_| has been updated. NotifyErrorFromIOThread(); @@ -274,6 +469,41 @@ PepperFlashSettingsManager::Core::NotifyDeauthorizeContentLicensesCompleted( } } +void PepperFlashSettingsManager::Core::NotifyGetPermissionSettingsCompleted( + uint32 request_id, + bool success, + PP_Flash_BrowserOperations_Permission default_permission, + const ppapi::FlashSiteSettings& sites) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + + if (manager_) { + manager_->client_->OnGetPermissionSettingsCompleted( + request_id, success, default_permission, sites); + } +} + +void PepperFlashSettingsManager::Core::NotifySetDefaultPermissionCompleted( + uint32 request_id, + bool success) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + + if (manager_) { + manager_->client_->OnSetDefaultPermissionCompleted( + request_id, success); + } +} + +void PepperFlashSettingsManager::Core::NotifySetSitePermissionCompleted( + uint32 request_id, + bool success) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + + if (manager_) { + manager_->client_->OnSetSitePermissionCompleted( + request_id, success); + } +} + void PepperFlashSettingsManager::Core::NotifyError( const std::vector<std::pair<uint32, RequestType> >& notifications) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); @@ -286,8 +516,20 @@ void PepperFlashSettingsManager::Core::NotifyError( if (manager_) { switch (iter->second) { case DEAUTHORIZE_CONTENT_LICENSES: - manager_->client_->OnDeauthorizeContentLicensesCompleted(iter->first, - false); + manager_->client_->OnDeauthorizeContentLicensesCompleted( + iter->first, false); + break; + case GET_PERMISSION_SETTINGS: + manager_->client_->OnGetPermissionSettingsCompleted( + iter->first, false, PP_FLASH_BROWSEROPERATIONS_PERMISSION_DEFAULT, + ppapi::FlashSiteSettings()); + break; + case SET_DEFAULT_PERMISSION: + manager_->client_->OnSetDefaultPermissionCompleted( + iter->first, false); + break; + case SET_SITE_PERMISSION: + manager_->client_->OnSetSitePermissionCompleted(iter->first, false); break; default: NOTREACHED(); @@ -304,7 +546,7 @@ void PepperFlashSettingsManager::Core::OnDeauthorizeContentLicensesResult( uint32 request_id, bool success) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - LOG_IF(ERROR, !success) << "DeauthorizeContentLicenses returned error"; + DLOG_IF(ERROR, !success) << "DeauthorizeContentLicenses returned error"; std::map<uint32, RequestType>::iterator iter = pending_responses_.find(request_id); @@ -319,6 +561,65 @@ void PepperFlashSettingsManager::Core::OnDeauthorizeContentLicensesResult( } } +void PepperFlashSettingsManager::Core::OnGetPermissionSettingsResult( + uint32 request_id, + bool success, + PP_Flash_BrowserOperations_Permission default_permission, + const ppapi::FlashSiteSettings& sites) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); + DLOG_IF(ERROR, !success) << "GetPermissionSettings returned error"; + + std::map<uint32, RequestType>::iterator iter = + pending_responses_.find(request_id); + if (iter != pending_responses_.end()) { + DCHECK_EQ(iter->second, GET_PERMISSION_SETTINGS); + + pending_responses_.erase(iter); + BrowserThread::PostTask( + BrowserThread::UI, FROM_HERE, + base::Bind(&Core::NotifyGetPermissionSettingsCompleted, this, + request_id, success, default_permission, sites)); + } +} + +void PepperFlashSettingsManager::Core::OnSetDefaultPermissionResult( + uint32 request_id, + bool success) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); + DLOG_IF(ERROR, !success) << "SetDefaultPermission returned error"; + + std::map<uint32, RequestType>::iterator iter = + pending_responses_.find(request_id); + if (iter != pending_responses_.end()) { + DCHECK_EQ(iter->second, SET_DEFAULT_PERMISSION); + + pending_responses_.erase(iter); + BrowserThread::PostTask( + BrowserThread::UI, FROM_HERE, + base::Bind(&Core::NotifySetDefaultPermissionCompleted, this, + request_id, success)); + } +} + +void PepperFlashSettingsManager::Core::OnSetSitePermissionResult( + uint32 request_id, + bool success) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); + DLOG_IF(ERROR, !success) << "SetSitePermission returned error"; + + std::map<uint32, RequestType>::iterator iter = + pending_responses_.find(request_id); + if (iter != pending_responses_.end()) { + DCHECK_EQ(iter->second, SET_SITE_PERMISSION); + + pending_responses_.erase(iter); + BrowserThread::PostTask( + BrowserThread::UI, FROM_HERE, + base::Bind(&Core::NotifySetSitePermissionCompleted, this, request_id, + success)); + } +} + PepperFlashSettingsManager::PepperFlashSettingsManager( Client* client, content::BrowserContext* browser_context) @@ -380,6 +681,40 @@ uint32 PepperFlashSettingsManager::DeauthorizeContentLicenses() { return id; } +uint32 PepperFlashSettingsManager::GetPermissionSettings( + PP_Flash_BrowserOperations_SettingType setting_type) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + + EnsureCoreExists(); + uint32 id = GetNextRequestId(); + core_->GetPermissionSettings(id, setting_type); + return id; +} + +uint32 PepperFlashSettingsManager::SetDefaultPermission( + PP_Flash_BrowserOperations_SettingType setting_type, + PP_Flash_BrowserOperations_Permission permission, + bool clear_site_specific) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + + EnsureCoreExists(); + uint32 id = GetNextRequestId(); + core_->SetDefaultPermission(id, setting_type, permission, + clear_site_specific); + return id; +} + +uint32 PepperFlashSettingsManager::SetSitePermission( + PP_Flash_BrowserOperations_SettingType setting_type, + const ppapi::FlashSiteSettings& sites) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + + EnsureCoreExists(); + uint32 id = GetNextRequestId(); + core_->SetSitePermission(id, setting_type, sites); + return id; +} + uint32 PepperFlashSettingsManager::GetNextRequestId() { return next_request_id_++; } diff --git a/chrome/browser/pepper_flash_settings_manager.h b/chrome/browser/pepper_flash_settings_manager.h index 4a20df3..1048912 100644 --- a/chrome/browser/pepper_flash_settings_manager.h +++ b/chrome/browser/pepper_flash_settings_manager.h @@ -8,6 +8,8 @@ #include "base/basictypes.h" #include "base/memory/ref_counted.h" +#include "ppapi/c/private/ppp_flash_browser_operations.h" +#include "ppapi/shared_impl/ppp_flash_browser_operations_shared.h" class PluginPrefs; class PrefService; @@ -29,7 +31,18 @@ class PepperFlashSettingsManager { virtual ~Client() {} virtual void OnDeauthorizeContentLicensesCompleted(uint32 request_id, - bool success) = 0; + bool success) {} + virtual void OnGetPermissionSettingsCompleted( + uint32 request_id, + bool success, + PP_Flash_BrowserOperations_Permission default_permission, + const ppapi::FlashSiteSettings& sites) {} + + virtual void OnSetDefaultPermissionCompleted(uint32 request_id, + bool success) {} + + virtual void OnSetSitePermissionCompleted(uint32 request_id, + bool success) {} }; // |client| must outlive this object. It is guaranteed that |client| won't @@ -52,6 +65,26 @@ class PepperFlashSettingsManager { // Client::OnDeauthorizeContentLicensesCompleted(). uint32 DeauthorizeContentLicenses(); + // Gets permission settings. + // Client::OnGetPermissionSettingsCompleted() will be called when the + // operation is completed. + uint32 GetPermissionSettings( + PP_Flash_BrowserOperations_SettingType setting_type); + + // Sets default permission. + // Client::OnSetDefaultPermissionCompleted() will be called when the + // operation is completed. + uint32 SetDefaultPermission( + PP_Flash_BrowserOperations_SettingType setting_type, + PP_Flash_BrowserOperations_Permission permission, + bool clear_site_specific); + + // Sets site-specific permission. + // Client::OnSetSitePermissionCompleted() will be called when the operation + // is completed. + uint32 SetSitePermission(PP_Flash_BrowserOperations_SettingType setting_type, + const ppapi::FlashSiteSettings& sites); + private: // Core does most of the work. It is ref-counted so that its lifespan can be // independent of the containing object's: diff --git a/chrome/browser/resources/options2/content_settings.html b/chrome/browser/resources/options2/content_settings.html index 4f813bf..6060800 100644 --- a/chrome/browser/resources/options2/content_settings.html +++ b/chrome/browser/resources/options2/content_settings.html @@ -257,6 +257,27 @@ </label> </div> </section> + <!-- Pepper Flash camera and microphone filter --> + <section id="pepper-flash-cameramic-section" class="pepper-flash-settings"> + <h3 i18n-content="pepperFlashCameramicTabLabel"></h3> + <div> + <div class="radio"> + <label> + <input type="radio" name="pepper-flash-cameramic" value="ask"> + <span i18n-content="pepperFlashCameramicAsk"></span> + </label> + </div> + <div class="radio"> + <label> + <input type="radio" name="pepper-flash-cameramic" value="block"> + <span i18n-content="pepperFlashCameramicBlock"></span> + </label> + </div> + <button class="exceptions-list-button" + contentType="pepper-flash-cameramic" + i18n-content="manage_exceptions"></button> + </div> + </section> <if expr="pp_ifdef('chromeos')"> <!-- Protected Content filter --> <section guest-visibility="disabled"> diff --git a/chrome/browser/resources/options2/content_settings.js b/chrome/browser/resources/options2/content_settings.js index af4af7a..ccabdafa 100644 --- a/chrome/browser/resources/options2/content_settings.js +++ b/chrome/browser/resources/options2/content_settings.js @@ -86,8 +86,6 @@ cr.define('options', function() { OptionsPage.navigateToPage('cookies'); }; - // Remove from DOM instead of hiding so :last-of-type applies the style - // correctly. var intentsSection = $('intents-section'); if (!loadTimeData.getBoolean('enable_web_intents') && intentsSection) intentsSection.parentNode.removeChild(intentsSection); @@ -99,6 +97,9 @@ cr.define('options', function() { $('content-settings-overlay-confirm').onclick = OptionsPage.closeOverlay.bind(OptionsPage); + + $('pepper-flash-cameramic-section').style.display = 'none'; + $('pepper-flash-cameramic-exceptions-div').style.display = 'none'; }, /** @@ -227,6 +228,16 @@ cr.define('options', function() { exceptionsList.patternValidityCheckComplete(pattern, valid); }; + /** + * Enables the Pepper Flash camera and microphone settings. + * Please note that whether the settings are actually showed or not is also + * affected by the style class pepper-flash-settings. + */ + ContentSettings.enablePepperFlashCameraMicSettings = function() { + $('pepper-flash-cameramic-section').style.display = ''; + $('pepper-flash-cameramic-exceptions-div').style.display = ''; + } + // Export return { ContentSettings: ContentSettings diff --git a/chrome/browser/resources/options2/content_settings_exceptions_area.html b/chrome/browser/resources/options2/content_settings_exceptions_area.html index 1aec06c..a2b2f0d 100644 --- a/chrome/browser/resources/options2/content_settings_exceptions_area.html +++ b/chrome/browser/resources/options2/content_settings_exceptions_area.html @@ -76,6 +76,10 @@ <list mode="otr"></list> </div> </div> + <div id="pepper-flash-cameramic-exceptions-div" + contentType="pepper-flash-cameramic" class="pepper-flash-settings"> + <list mode="normal"></list> + </div> </div> <div class="action-area"> <div class="button-strip"> diff --git a/chrome/browser/resources/options2/content_settings_exceptions_area.js b/chrome/browser/resources/options2/content_settings_exceptions_area.js index ef4fa6b..17bc9b7 100644 --- a/chrome/browser/resources/options2/content_settings_exceptions_area.js +++ b/chrome/browser/resources/options2/content_settings_exceptions_area.js @@ -375,7 +375,8 @@ cr.define('options.contentSettings', function() { var exceptionList = this; // Whether the exceptions in this list allow an 'Ask every time' option. - this.enableAskOption = this.contentType == 'plugins'; + this.enableAskOption = this.contentType == 'plugins' || + this.contentType == 'pepper-flash-cameramic'; this.autoExpands = true; this.reset(); diff --git a/chrome/browser/ui/webui/options2/content_settings_handler2.cc b/chrome/browser/ui/webui/options2/content_settings_handler2.cc index 1e27409..168da09 100644 --- a/chrome/browser/ui/webui/options2/content_settings_handler2.cc +++ b/chrome/browser/ui/webui/options2/content_settings_handler2.cc @@ -4,8 +4,6 @@ #include "chrome/browser/ui/webui/options2/content_settings_handler2.h" -#include <map> -#include <string> #include <vector> #include "base/bind.h" @@ -41,6 +39,7 @@ #include "content/public/common/content_switches.h" #include "grit/generated_resources.h" #include "grit/locale_settings.h" +#include "net/base/net_util.h" #include "ui/base/l10n/l10n_util.h" #if defined(OS_CHROMEOS) @@ -51,9 +50,10 @@ using content::UserMetricsAction; namespace { -struct ContentSettingsTypeNameEntry { - ContentSettingsType type; - const char* name; +enum ExContentSettingsTypeEnum { + EX_CONTENT_SETTINGS_TYPE_PEPPER_FLASH_CAMERAMIC = + CONTENT_SETTINGS_NUM_TYPES, + EX_CONTENT_SETTINGS_NUM_TYPES }; typedef std::map<ContentSettingsPattern, ContentSetting> OnePatternSettings; @@ -67,33 +67,8 @@ const char* kSource = "source"; const char* kAppName = "appName"; const char* kAppId = "appId"; const char* kEmbeddingOrigin = "embeddingOrigin"; - -const ContentSettingsTypeNameEntry kContentSettingsTypeGroupNames[] = { - {CONTENT_SETTINGS_TYPE_COOKIES, "cookies"}, - {CONTENT_SETTINGS_TYPE_IMAGES, "images"}, - {CONTENT_SETTINGS_TYPE_JAVASCRIPT, "javascript"}, - {CONTENT_SETTINGS_TYPE_PLUGINS, "plugins"}, - {CONTENT_SETTINGS_TYPE_POPUPS, "popups"}, - {CONTENT_SETTINGS_TYPE_GEOLOCATION, "location"}, - {CONTENT_SETTINGS_TYPE_NOTIFICATIONS, "notifications"}, - {CONTENT_SETTINGS_TYPE_INTENTS, "intents"}, - {CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE, "auto-select-certificate"}, - {CONTENT_SETTINGS_TYPE_FULLSCREEN, "fullscreen"}, - {CONTENT_SETTINGS_TYPE_MOUSELOCK, "mouselock"}, -}; -COMPILE_ASSERT(arraysize(kContentSettingsTypeGroupNames) == - CONTENT_SETTINGS_NUM_TYPES, - MISSING_CONTENT_SETTINGS_TYPE); - -ContentSettingsType ContentSettingsTypeFromGroupName(const std::string& name) { - for (size_t i = 0; i < arraysize(kContentSettingsTypeGroupNames); ++i) { - if (name == kContentSettingsTypeGroupNames[i].name) - return kContentSettingsTypeGroupNames[i].type; - } - - NOTREACHED() << name << " is not a recognized content settings type."; - return CONTENT_SETTINGS_TYPE_DEFAULT; -} +const char* kDefaultProviderID = "default"; +const char* kPreferencesSource = "preferences"; std::string ContentSettingToString(ContentSetting setting) { switch (setting) { @@ -244,10 +219,109 @@ void AddExceptionsGrantedByHostedApps( } } +ContentSetting FlashPermissionToContentSetting( + PP_Flash_BrowserOperations_Permission permission) { + switch (permission) { + case PP_FLASH_BROWSEROPERATIONS_PERMISSION_DEFAULT: + return CONTENT_SETTING_DEFAULT; + case PP_FLASH_BROWSEROPERATIONS_PERMISSION_ALLOW: + return CONTENT_SETTING_ALLOW; + case PP_FLASH_BROWSEROPERATIONS_PERMISSION_BLOCK: + return CONTENT_SETTING_BLOCK; + case PP_FLASH_BROWSEROPERATIONS_PERMISSION_ASK: + return CONTENT_SETTING_ASK; + default: + NOTREACHED(); + return CONTENT_SETTING_DEFAULT; + } +} + +PP_Flash_BrowserOperations_Permission FlashPermissionFromContentSetting( + ContentSetting setting) { + switch (setting) { + case CONTENT_SETTING_DEFAULT: + return PP_FLASH_BROWSEROPERATIONS_PERMISSION_DEFAULT; + case CONTENT_SETTING_ALLOW: + return PP_FLASH_BROWSEROPERATIONS_PERMISSION_ALLOW; + case CONTENT_SETTING_BLOCK: + return PP_FLASH_BROWSEROPERATIONS_PERMISSION_BLOCK; + case CONTENT_SETTING_ASK: + return PP_FLASH_BROWSEROPERATIONS_PERMISSION_ASK; + default: + NOTREACHED(); + return PP_FLASH_BROWSEROPERATIONS_PERMISSION_DEFAULT; + } +} + +std::string CanonicalizeHost(const std::string& host) { + url_canon::CanonHostInfo info; + return net::CanonicalizeHost(host, &info); +} + +bool IsValidHost(const std::string& host) { + std::string canonicalized_host = CanonicalizeHost(host); + return !canonicalized_host.empty(); +} + } // namespace namespace options2 { +class ContentSettingsHandler::ExContentSettingsType { + public: + explicit ExContentSettingsType(int value) : value_(value) { + DCHECK(value_ < EX_CONTENT_SETTINGS_NUM_TYPES); + } + explicit ExContentSettingsType(ContentSettingsType type) : value_(type) {} + explicit ExContentSettingsType(ExContentSettingsTypeEnum type) + : value_(type) {} + + bool IsExtraContentSettingsType() const { + return value_ >= CONTENT_SETTINGS_NUM_TYPES; + } + + operator int() const { return value_; } + + ContentSettingsType ToContentSettingsType() const { + DCHECK(value_ < CONTENT_SETTINGS_NUM_TYPES); + return static_cast<ContentSettingsType>(value_); + } + + private: + int value_; +}; + +ContentSettingsHandler::CachedPepperFlashSettings::CachedPepperFlashSettings() + : default_permission(PP_FLASH_BROWSEROPERATIONS_PERMISSION_BLOCK), + initialized(false) { +} + +ContentSettingsHandler::CachedPepperFlashSettings::~CachedPepperFlashSettings() { +} + +struct ContentSettingsHandler::ExContentSettingsTypeNameEntry { + ExContentSettingsType type; + const char* name; +}; + +const ContentSettingsHandler::ExContentSettingsTypeNameEntry + ContentSettingsHandler::kExContentSettingsTypeGroupNames[] = { + {ExContentSettingsType(CONTENT_SETTINGS_TYPE_COOKIES), "cookies"}, + {ExContentSettingsType(CONTENT_SETTINGS_TYPE_IMAGES), "images"}, + {ExContentSettingsType(CONTENT_SETTINGS_TYPE_JAVASCRIPT), "javascript"}, + {ExContentSettingsType(CONTENT_SETTINGS_TYPE_PLUGINS), "plugins"}, + {ExContentSettingsType(CONTENT_SETTINGS_TYPE_POPUPS), "popups"}, + {ExContentSettingsType(CONTENT_SETTINGS_TYPE_GEOLOCATION), "location"}, + {ExContentSettingsType(CONTENT_SETTINGS_TYPE_NOTIFICATIONS), "notifications"}, + {ExContentSettingsType(CONTENT_SETTINGS_TYPE_INTENTS), "intents"}, + {ExContentSettingsType(CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE), + "auto-select-certificate"}, + {ExContentSettingsType(CONTENT_SETTINGS_TYPE_FULLSCREEN), "fullscreen"}, + {ExContentSettingsType(CONTENT_SETTINGS_TYPE_MOUSELOCK), "mouselock"}, + {ExContentSettingsType(EX_CONTENT_SETTINGS_TYPE_PEPPER_FLASH_CAMERAMIC), + "pepper-flash-cameramic"}, +}; + ContentSettingsHandler::ContentSettingsHandler() { } @@ -328,6 +402,12 @@ void ContentSettingsHandler::GetLocalizedValues( { "mouselock_allow", IDS_MOUSE_LOCK_ALLOW_RADIO }, { "mouselock_ask", IDS_MOUSE_LOCK_ASK_RADIO }, { "mouselock_block", IDS_MOUSE_LOCK_BLOCK_RADIO }, + // Pepper Flash camera and microphone filter. + { "pepperFlashCameramicTabLabel", IDS_PEPPER_FLASH_CAMERAMIC_TAB_LABEL }, + // The header has to be named as <content_type_name>_header. + { "pepper-flash-cameramic_header", IDS_PEPPER_FLASH_CAMERAMIC_HEADER }, + { "pepperFlashCameramicAsk", IDS_PEPPER_FLASH_CAMERAMIC_ASK_RADIO }, + { "pepperFlashCameramicBlock", IDS_PEPPER_FLASH_CAMERAMIC_BLOCK_RADIO }, #if defined(OS_CHROMEOS) // Protected Content filter { "protectedContentTabLabel", IDS_PROTECTED_CONTENT_TAB_LABEL }, @@ -360,6 +440,8 @@ void ContentSettingsHandler::GetLocalizedValues( IDS_FULLSCREEN_TAB_LABEL); RegisterTitle(localized_strings, "mouselock", IDS_MOUSE_LOCK_TAB_LABEL); + RegisterTitle(localized_strings, "pepper-flash-cameramic", + IDS_PEPPER_FLASH_CAMERAMIC_TAB_LABEL); Profile* profile = Profile::FromWebUI(web_ui()); localized_strings->SetBoolean( @@ -393,11 +475,18 @@ void ContentSettingsHandler::InitializeHandler() { PrefService* prefs = profile->GetPrefs(); pref_change_registrar_.Init(prefs); pref_change_registrar_.Add(prefs::kGeolocationContentSettings, this); + pref_change_registrar_.Add(prefs::kPepperFlashSettingsEnabled, this); + + flash_settings_manager_.reset(new PepperFlashSettingsManager(this, profile)); } void ContentSettingsHandler::InitializePage() { UpdateHandlersEnabledRadios(); UpdateAllExceptionsViewsFromModel(); + + flash_cameramic_settings_ = CachedPepperFlashSettings(); + flash_settings_manager_->GetPermissionSettings( + PP_FLASH_BROWSEROPERATIONS_SETTINGTYPE_CAMERAMIC); } void ContentSettingsHandler::Observe( @@ -431,18 +520,27 @@ void ContentSettingsHandler::Observe( content::Details<const ContentSettingsDetails>(details).ptr(); // TODO(estade): we pretend update_all() is always true. - if (settings_details->update_all_types()) + if (settings_details->update_all_types()) { UpdateAllExceptionsViewsFromModel(); - else - UpdateExceptionsViewFromModel(settings_details->type()); + } else { + UpdateExceptionsViewFromModel( + ExContentSettingsType(settings_details->type())); + } break; } case chrome::NOTIFICATION_PREF_CHANGED: { const std::string& pref_name = *content::Details<std::string>(details).ptr(); - if (pref_name == prefs::kGeolocationContentSettings) + if (pref_name == prefs::kGeolocationContentSettings) { UpdateGeolocationExceptionsView(); + } else if (pref_name == prefs::kPepperFlashSettingsEnabled) { + if (!flash_cameramic_settings_.initialized) { + flash_settings_manager_->GetPermissionSettings( + PP_FLASH_BROWSEROPERATIONS_SETTINGTYPE_CAMERAMIC); + } + } + break; } @@ -461,15 +559,36 @@ void ContentSettingsHandler::Observe( } } +void ContentSettingsHandler::OnGetPermissionSettingsCompleted( + uint32 /* request_id */, + bool success, + PP_Flash_BrowserOperations_Permission default_permission, + const ppapi::FlashSiteSettings& sites) { + if (success && !flash_cameramic_settings_.initialized) { + flash_cameramic_settings_.initialized = true; + flash_cameramic_settings_.default_permission = default_permission; + for (ppapi::FlashSiteSettings::const_iterator iter = sites.begin(); + iter != sites.end(); ++iter) { + if (IsValidHost(iter->site)) + flash_cameramic_settings_.sites[iter->site] = iter->permission; + } + UpdateExceptionsViewFromModel( + ExContentSettingsType(EX_CONTENT_SETTINGS_TYPE_PEPPER_FLASH_CAMERAMIC)); + + web_ui()->CallJavascriptFunction( + "ContentSettings.enablePepperFlashCameraMicSettings"); + } +} + void ContentSettingsHandler::UpdateSettingDefaultFromModel( - ContentSettingsType type) { + const ExContentSettingsType& type) { DictionaryValue filter_settings; std::string provider_id; - filter_settings.SetString(ContentSettingsTypeToGroupName(type) + ".value", - GetSettingDefaultFromModel(type, &provider_id)); filter_settings.SetString( - ContentSettingsTypeToGroupName(type) + ".managedBy", - provider_id); + ExContentSettingsTypeToGroupName(type) + ".value", + GetSettingDefaultFromModel(type, &provider_id)); + filter_settings.SetString( + ExContentSettingsTypeToGroupName(type) + ".managedBy", provider_id); web_ui()->CallJavascriptFunction( "ContentSettings.setContentFilterSettingsValue", filter_settings); @@ -478,17 +597,21 @@ void ContentSettingsHandler::UpdateSettingDefaultFromModel( } std::string ContentSettingsHandler::GetSettingDefaultFromModel( - ContentSettingsType type, std::string* provider_id) { + const ExContentSettingsType& type, std::string* provider_id) { Profile* profile = Profile::FromWebUI(web_ui()); ContentSetting default_setting; if (type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) { default_setting = DesktopNotificationServiceFactory::GetForProfile(profile)-> GetDefaultContentSetting(provider_id); + } else if (type == EX_CONTENT_SETTINGS_TYPE_PEPPER_FLASH_CAMERAMIC) { + default_setting = FlashPermissionToContentSetting( + flash_cameramic_settings_.default_permission); + *provider_id = kDefaultProviderID; } else { default_setting = profile->GetHostContentSettingsMap()-> - GetDefaultContentSetting(type, provider_id); + GetDefaultContentSetting(type.ToContentSettingsType(), provider_id); } return ContentSettingToString(default_setting); @@ -505,25 +628,25 @@ void ContentSettingsHandler::UpdateHandlersEnabledRadios() { void ContentSettingsHandler::UpdateAllExceptionsViewsFromModel() { for (int type = CONTENT_SETTINGS_TYPE_DEFAULT + 1; - type < CONTENT_SETTINGS_NUM_TYPES; ++type) { + type < EX_CONTENT_SETTINGS_NUM_TYPES; ++type) { // The content settings type CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE // is supposed to be set by policy only. Hence there is no user facing UI // for this content type and we skip it here. if (type == CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE) continue; - UpdateExceptionsViewFromModel(static_cast<ContentSettingsType>(type)); + UpdateExceptionsViewFromModel(ExContentSettingsType(type)); } } void ContentSettingsHandler::UpdateAllOTRExceptionsViewsFromModel() { for (int type = CONTENT_SETTINGS_TYPE_DEFAULT + 1; - type < CONTENT_SETTINGS_NUM_TYPES; ++type) { - UpdateOTRExceptionsViewFromModel(static_cast<ContentSettingsType>(type)); + type < EX_CONTENT_SETTINGS_NUM_TYPES; ++type) { + UpdateOTRExceptionsViewFromModel(ExContentSettingsType(type)); } } void ContentSettingsHandler::UpdateExceptionsViewFromModel( - ContentSettingsType type) { + const ExContentSettingsType& type) { // Don't update intents settings at this point. // Turn on when enable_web_intents_tag is enabled. if (type == CONTENT_SETTINGS_TYPE_INTENTS) @@ -536,22 +659,28 @@ void ContentSettingsHandler::UpdateExceptionsViewFromModel( case CONTENT_SETTINGS_TYPE_NOTIFICATIONS: UpdateNotificationExceptionsView(); break; + case EX_CONTENT_SETTINGS_TYPE_PEPPER_FLASH_CAMERAMIC: + UpdateFlashCameraMicExceptionsView(); + break; default: - UpdateExceptionsViewFromHostContentSettingsMap(type); + UpdateExceptionsViewFromHostContentSettingsMap( + type.ToContentSettingsType()); break; } } void ContentSettingsHandler::UpdateOTRExceptionsViewFromModel( - ContentSettingsType type) { + const ExContentSettingsType& type) { switch (type) { case CONTENT_SETTINGS_TYPE_GEOLOCATION: case CONTENT_SETTINGS_TYPE_NOTIFICATIONS: case CONTENT_SETTINGS_TYPE_INTENTS: case CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE: + case EX_CONTENT_SETTINGS_TYPE_PEPPER_FLASH_CAMERAMIC: break; default: - UpdateExceptionsViewFromOTRHostContentSettingsMap(type); + UpdateExceptionsViewFromOTRHostContentSettingsMap( + type.ToContentSettingsType()); break; } } @@ -575,7 +704,7 @@ void ContentSettingsHandler::UpdateGeolocationExceptionsView() { // Don't add default settings. if (i->primary_pattern == ContentSettingsPattern::Wildcard() && i->secondary_pattern == ContentSettingsPattern::Wildcard() && - i->source != "preferences") { + i->source != kPreferencesSource) { continue; } all_patterns_settings[i->primary_pattern][i->secondary_pattern] = @@ -622,7 +751,8 @@ void ContentSettingsHandler::UpdateGeolocationExceptionsView() { // This is mainly here to keep this function ideologically parallel to // UpdateExceptionsViewFromHostContentSettingsMap(). - UpdateSettingDefaultFromModel(CONTENT_SETTINGS_TYPE_GEOLOCATION); + UpdateSettingDefaultFromModel( + ExContentSettingsType(CONTENT_SETTINGS_TYPE_GEOLOCATION)); } void ContentSettingsHandler::UpdateNotificationExceptionsView() { @@ -644,7 +774,7 @@ void ContentSettingsHandler::UpdateNotificationExceptionsView() { // Don't add default settings. if (i->primary_pattern == ContentSettingsPattern::Wildcard() && i->secondary_pattern == ContentSettingsPattern::Wildcard() && - i->source != "preferences") { + i->source != kPreferencesSource) { continue; } @@ -660,7 +790,31 @@ void ContentSettingsHandler::UpdateNotificationExceptionsView() { // This is mainly here to keep this function ideologically parallel to // UpdateExceptionsViewFromHostContentSettingsMap(). - UpdateSettingDefaultFromModel(CONTENT_SETTINGS_TYPE_NOTIFICATIONS); + UpdateSettingDefaultFromModel( + ExContentSettingsType(CONTENT_SETTINGS_TYPE_NOTIFICATIONS)); +} + +void ContentSettingsHandler::UpdateFlashCameraMicExceptionsView() { + ListValue exceptions; + for (CachedPepperFlashSettings::SiteMap::iterator iter = + flash_cameramic_settings_.sites.begin(); + iter != flash_cameramic_settings_.sites.end(); ++iter) { + DictionaryValue* exception = new DictionaryValue(); + exception->SetString(kDisplayPattern, iter->first); + exception->SetString( + kSetting, + ContentSettingToString(FlashPermissionToContentSetting(iter->second))); + exception->SetString(kSource, kPreferencesSource); + exceptions.Append(exception); + } + + StringValue type_string(ExContentSettingsTypeToGroupName( + ExContentSettingsType(EX_CONTENT_SETTINGS_TYPE_PEPPER_FLASH_CAMERAMIC))); + web_ui()->CallJavascriptFunction("ContentSettings.setExceptions", + type_string, exceptions); + + UpdateSettingDefaultFromModel( + ExContentSettingsType(EX_CONTENT_SETTINGS_TYPE_PEPPER_FLASH_CAMERAMIC)); } void ContentSettingsHandler::UpdateExceptionsViewFromHostContentSettingsMap( @@ -706,7 +860,7 @@ void ContentSettingsHandler::UpdateExceptionsViewFromHostContentSettingsMap( // The default may also have changed (we won't get a separate notification). // If it hasn't changed, this call will be harmless. - UpdateSettingDefaultFromModel(type); + UpdateSettingDefaultFromModel(ExContentSettingsType(type)); } void ContentSettingsHandler::UpdateExceptionsViewFromOTRHostContentSettingsMap( @@ -802,7 +956,8 @@ void ContentSettingsHandler::SetContentFilter(const ListValue* args) { } ContentSetting default_setting = ContentSettingFromString(setting); - ContentSettingsType content_type = ContentSettingsTypeFromGroupName(group); + ExContentSettingsType content_type = + ExContentSettingsTypeFromGroupName(group); Profile* profile = Profile::FromWebUI(web_ui()); #if defined(OS_CHROMEOS) @@ -815,10 +970,17 @@ void ContentSettingsHandler::SetContentFilter(const ListValue* args) { if (content_type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) { DesktopNotificationServiceFactory::GetForProfile(profile)-> SetDefaultContentSetting(default_setting); + } else if (content_type == EX_CONTENT_SETTINGS_TYPE_PEPPER_FLASH_CAMERAMIC) { + flash_cameramic_settings_.default_permission = + FlashPermissionFromContentSetting(default_setting); + flash_settings_manager_->SetDefaultPermission( + PP_FLASH_BROWSEROPERATIONS_SETTINGTYPE_CAMERAMIC, + flash_cameramic_settings_.default_permission, false); } else { HostContentSettingsMap* map = profile->GetHostContentSettingsMap(); - ApplyWhitelist(content_type, default_setting); - map->SetDefaultContentSetting(content_type, default_setting); + ContentSettingsType converted_type = content_type.ToContentSettingsType(); + ApplyWhitelist(converted_type, default_setting); + map->SetDefaultContentSetting(converted_type, default_setting); } switch (content_type) { case CONTENT_SETTINGS_TYPE_COOKIES: @@ -857,6 +1019,10 @@ void ContentSettingsHandler::SetContentFilter(const ListValue* args) { content::RecordAction( UserMetricsAction("Options_DefaultMouseLockSettingChanged")); break; + case EX_CONTENT_SETTINGS_TYPE_PEPPER_FLASH_CAMERAMIC: + content::RecordAction( + UserMetricsAction("Options_DefaultFlashCameraMicSettingChanged")); + break; default: break; } @@ -868,7 +1034,8 @@ void ContentSettingsHandler::RemoveException(const ListValue* args) { CHECK(args->GetString(arg_i++, &type_string)); Profile* profile = Profile::FromWebUI(web_ui()); - ContentSettingsType type = ContentSettingsTypeFromGroupName(type_string); + ExContentSettingsType type = ExContentSettingsTypeFromGroupName( + type_string); if (type == CONTENT_SETTINGS_TYPE_GEOLOCATION) { std::string origin; std::string embedding_origin; @@ -905,18 +1072,37 @@ void ContentSettingsHandler::RemoveException(const ListValue* args) { rv = args->GetString(arg_i++, &pattern); DCHECK(rv); - HostContentSettingsMap* settings_map = - mode == "normal" ? GetContentSettingsMap() : - GetOTRContentSettingsMap(); - // The settings map could be null if the mode was OTR but the OTR profile - // got destroyed before we received this message. - if (settings_map) { - settings_map->SetContentSetting( - ContentSettingsPattern::FromString(pattern), - ContentSettingsPattern::Wildcard(), - ContentSettingsTypeFromGroupName(type_string), - "", - CONTENT_SETTING_DEFAULT); + if (type == EX_CONTENT_SETTINGS_TYPE_PEPPER_FLASH_CAMERAMIC) { + DCHECK_EQ(mode, "normal"); + + CachedPepperFlashSettings::SiteMap::iterator iter = + flash_cameramic_settings_.sites.find(pattern); + if (iter != flash_cameramic_settings_.sites.end()) { + flash_cameramic_settings_.sites.erase(iter); + ppapi::FlashSiteSettings site_settings(1, + ppapi::FlashSiteSetting( + pattern, PP_FLASH_BROWSEROPERATIONS_PERMISSION_DEFAULT)); + flash_settings_manager_->SetSitePermission( + PP_FLASH_BROWSEROPERATIONS_SETTINGTYPE_CAMERAMIC, + site_settings); + } else { + NOTREACHED(); + } + UpdateFlashCameraMicExceptionsView(); + } else { + HostContentSettingsMap* settings_map = + mode == "normal" ? GetContentSettingsMap() : + GetOTRContentSettingsMap(); + // The settings map could be null if the mode was OTR but the OTR profile + // got destroyed before we received this message. + if (settings_map) { + settings_map->SetContentSetting( + ContentSettingsPattern::FromString(pattern), + ContentSettingsPattern::Wildcard(), + type.ToContentSettingsType(), + "", + CONTENT_SETTING_DEFAULT); + } } } } @@ -932,48 +1118,71 @@ void ContentSettingsHandler::SetException(const ListValue* args) { std::string setting; CHECK(args->GetString(arg_i++, &setting)); - ContentSettingsType type = ContentSettingsTypeFromGroupName(type_string); + ExContentSettingsType type = ExContentSettingsTypeFromGroupName(type_string); if (type == CONTENT_SETTINGS_TYPE_GEOLOCATION || type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) { NOTREACHED(); - return; - } + } else if (type == EX_CONTENT_SETTINGS_TYPE_PEPPER_FLASH_CAMERAMIC) { + DCHECK(IsValidHost(pattern)); - HostContentSettingsMap* settings_map = - mode == "normal" ? GetContentSettingsMap() : - GetOTRContentSettingsMap(); + if (flash_cameramic_settings_.sites.find(pattern) == + flash_cameramic_settings_.sites.end()) { + pattern = CanonicalizeHost(pattern); + } + PP_Flash_BrowserOperations_Permission permission = + FlashPermissionFromContentSetting(ContentSettingFromString(setting)); + flash_cameramic_settings_.sites[pattern] = permission; + ppapi::FlashSiteSettings + site_settings(1, ppapi::FlashSiteSetting(pattern, permission)); + flash_settings_manager_->SetSitePermission( + PP_FLASH_BROWSEROPERATIONS_SETTINGTYPE_CAMERAMIC, + site_settings); + UpdateFlashCameraMicExceptionsView(); + } else { + HostContentSettingsMap* settings_map = + mode == "normal" ? GetContentSettingsMap() : + GetOTRContentSettingsMap(); - // The settings map could be null if the mode was OTR but the OTR profile - // got destroyed before we received this message. - if (!settings_map) - return; - settings_map->SetContentSetting(ContentSettingsPattern::FromString(pattern), - ContentSettingsPattern::Wildcard(), - type, - "", - ContentSettingFromString(setting)); + // The settings map could be null if the mode was OTR but the OTR profile + // got destroyed before we received this message. + if (!settings_map) + return; + settings_map->SetContentSetting(ContentSettingsPattern::FromString(pattern), + ContentSettingsPattern::Wildcard(), + type.ToContentSettingsType(), + "", + ContentSettingFromString(setting)); + } } void ContentSettingsHandler::CheckExceptionPatternValidity( const ListValue* args) { size_t arg_i = 0; - Value* type; - CHECK(args->Get(arg_i++, &type)); + std::string type_string; + CHECK(args->GetString(arg_i++, &type_string)); std::string mode_string; CHECK(args->GetString(arg_i++, &mode_string)); std::string pattern_string; CHECK(args->GetString(arg_i++, &pattern_string)); - ContentSettingsPattern pattern = - ContentSettingsPattern::FromString(pattern_string); + ExContentSettingsType type = ExContentSettingsTypeFromGroupName(type_string); + bool is_valid = false; + if (type == EX_CONTENT_SETTINGS_TYPE_PEPPER_FLASH_CAMERAMIC) { + is_valid = IsValidHost(pattern_string); + } else { + ContentSettingsPattern pattern = + ContentSettingsPattern::FromString(pattern_string); + is_valid = pattern.IsValid(); + } + scoped_ptr<Value> type_value(Value::CreateStringValue(type_string)); scoped_ptr<Value> mode_value(Value::CreateStringValue(mode_string)); scoped_ptr<Value> pattern_value(Value::CreateStringValue(pattern_string)); - scoped_ptr<Value> valid_value(Value::CreateBooleanValue(pattern.IsValid())); + scoped_ptr<Value> valid_value(Value::CreateBooleanValue(is_valid)); web_ui()->CallJavascriptFunction( "ContentSettings.patternValidityCheckComplete", - *type, + *type_value.get(), *mode_value.get(), *pattern_value.get(), *valid_value.get()); @@ -982,13 +1191,7 @@ void ContentSettingsHandler::CheckExceptionPatternValidity( // static std::string ContentSettingsHandler::ContentSettingsTypeToGroupName( ContentSettingsType type) { - for (size_t i = 0; i < arraysize(kContentSettingsTypeGroupNames); ++i) { - if (type == kContentSettingsTypeGroupNames[i].type) - return kContentSettingsTypeGroupNames[i].name; - } - - NOTREACHED(); - return std::string(); + return ExContentSettingsTypeToGroupName(ExContentSettingsType(type)); } HostContentSettingsMap* ContentSettingsHandler::GetContentSettingsMap() { @@ -1007,4 +1210,33 @@ HostContentSettingsMap* return NULL; } +// static +ContentSettingsHandler::ExContentSettingsType + ContentSettingsHandler::ExContentSettingsTypeFromGroupName( + const std::string& name) { + COMPILE_ASSERT(arraysize(kExContentSettingsTypeGroupNames) == + EX_CONTENT_SETTINGS_NUM_TYPES, + MISSING_CONTENT_SETTINGS_TYPE); + + for (size_t i = 0; i < arraysize(kExContentSettingsTypeGroupNames); ++i) { + if (name == kExContentSettingsTypeGroupNames[i].name) + return kExContentSettingsTypeGroupNames[i].type; + } + + NOTREACHED() << name << " is not a recognized content settings type."; + return ExContentSettingsType(CONTENT_SETTINGS_TYPE_DEFAULT); +} + +// static +std::string ContentSettingsHandler::ExContentSettingsTypeToGroupName( + const ExContentSettingsType& type) { + for (size_t i = 0; i < arraysize(kExContentSettingsTypeGroupNames); ++i) { + if (type == kExContentSettingsTypeGroupNames[i].type) + return kExContentSettingsTypeGroupNames[i].name; + } + + NOTREACHED(); + return std::string(); +} + } // namespace options2 diff --git a/chrome/browser/ui/webui/options2/content_settings_handler2.h b/chrome/browser/ui/webui/options2/content_settings_handler2.h index 2ec6909..8c4ae5f 100644 --- a/chrome/browser/ui/webui/options2/content_settings_handler2.h +++ b/chrome/browser/ui/webui/options2/content_settings_handler2.h @@ -6,7 +6,11 @@ #define CHROME_BROWSER_UI_WEBUI_OPTIONS2_CONTENT_SETTINGS_HANDLER2_H_ #pragma once -#include "chrome/browser/plugin_data_remover_helper.h" +#include <map> +#include <string> + +#include "base/memory/scoped_ptr.h" +#include "chrome/browser/pepper_flash_settings_manager.h" #include "chrome/browser/prefs/pref_change_registrar.h" #include "chrome/browser/ui/webui/options2/options_ui2.h" #include "chrome/common/content_settings_types.h" @@ -19,7 +23,8 @@ class ProtocolHandlerRegistry; namespace options2 { -class ContentSettingsHandler : public OptionsPageUIHandler { +class ContentSettingsHandler : public OptionsPageUIHandler, + public PepperFlashSettingsManager::Client { public: ContentSettingsHandler(); virtual ~ContentSettingsHandler(); @@ -35,20 +40,46 @@ class ContentSettingsHandler : public OptionsPageUIHandler { const content::NotificationSource& source, const content::NotificationDetails& details) OVERRIDE; + // PepperFlashSettingsManager::Client implementation. + virtual void OnGetPermissionSettingsCompleted( + uint32 request_id, + bool success, + PP_Flash_BrowserOperations_Permission default_permission, + const ppapi::FlashSiteSettings& sites) OVERRIDE; + // Gets a string identifier for the group name, for use in HTML. static std::string ContentSettingsTypeToGroupName(ContentSettingsType type); private: + // Extends ContentSettingsType with some other types that will be also + // displayed in the content settings UI. + class ExContentSettingsType; + struct ExContentSettingsTypeNameEntry; + + struct CachedPepperFlashSettings { + CachedPepperFlashSettings(); + ~CachedPepperFlashSettings(); + + PP_Flash_BrowserOperations_Permission default_permission; + + typedef std::map<std::string, PP_Flash_BrowserOperations_Permission> + SiteMap; + SiteMap sites; + + bool initialized; + }; + // Functions that call into the page ----------------------------------------- // Updates the page with the default settings (allow, ask, block, etc.) - void UpdateSettingDefaultFromModel(ContentSettingsType type); + void UpdateSettingDefaultFromModel(const ExContentSettingsType& type); // Clobbers and rebuilds the specific content setting type exceptions table. - void UpdateExceptionsViewFromModel(ContentSettingsType type); + void UpdateExceptionsViewFromModel(const ExContentSettingsType& type); // Clobbers and rebuilds the specific content setting type exceptions // OTR table. - void UpdateOTRExceptionsViewFromModel(ContentSettingsType type); + void UpdateOTRExceptionsViewFromModel( + const ExContentSettingsType& type); // Clobbers and rebuilds all the exceptions tables in the page (both normal // and OTR tables). void UpdateAllExceptionsViewsFromModel(); @@ -58,6 +89,9 @@ class ContentSettingsHandler : public OptionsPageUIHandler { void UpdateGeolocationExceptionsView(); // Clobbers and rebuilds just the desktop notification exception table. void UpdateNotificationExceptionsView(); + // Clobbers and rebuilds just the Pepper Flash camera and microphone exception + // table. + void UpdateFlashCameraMicExceptionsView(); // Clobbers and rebuilds an exception table that's managed by the host content // settings map. void UpdateExceptionsViewFromHostContentSettingsMap(ContentSettingsType type); @@ -102,16 +136,26 @@ class ContentSettingsHandler : public OptionsPageUIHandler { // Gets the default setting in string form. If |provider_id| is not NULL, the // id of the provider which provided the default setting is assigned to it. - std::string GetSettingDefaultFromModel(ContentSettingsType type, + std::string GetSettingDefaultFromModel(const ExContentSettingsType& type, std::string* provider_id); // Gets the ProtocolHandlerRegistry for the normal profile. ProtocolHandlerRegistry* GetProtocolHandlerRegistry(); + static ExContentSettingsType ExContentSettingsTypeFromGroupName( + const std::string& name); + static std::string ExContentSettingsTypeToGroupName( + const ExContentSettingsType& type); + // Member variables --------------------------------------------------------- content::NotificationRegistrar notification_registrar_; PrefChangeRegistrar pref_change_registrar_; + scoped_ptr<PepperFlashSettingsManager> flash_settings_manager_; + CachedPepperFlashSettings flash_cameramic_settings_; + + static const ExContentSettingsTypeNameEntry + kExContentSettingsTypeGroupNames[]; DISALLOW_COPY_AND_ASSIGN(ContentSettingsHandler); }; diff --git a/chrome/tools/chromeactions.txt b/chrome/tools/chromeactions.txt index f50b740..2908df8 100644 --- a/chrome/tools/chromeactions.txt +++ b/chrome/tools/chromeactions.txt @@ -118,6 +118,7 @@ 0x3c463d9eb1c92f64 BadMessageTerminate_DSMF_1 0x8b956c45b0f38be9 BadMessageTerminate_DSMF_2 0x6ebaa5e3651107fa BadMessageTerminate_EFD +0xff06108fb2aa73fa BadMessageTerminate_FAMF 0xbecb3852be04c506 BadMessageTerminate_IDBMF 0xd7e4d61883121c76 BadMessageTerminate_NC 0x448f44d226b839b7 BadMessageTerminate_NC17 @@ -934,6 +935,7 @@ 0xe2fd858f8395432f Options_CustomFrame_Disable 0x531823c36ca21da2 Options_CustomFrame_Enable 0x33e7b018e003c5b1 Options_DefaultCookieSettingChanged +0xd5a152f698cfa270 Options_DefaultFlashCameraMicSettingChanged 0x3864ed1197ddceb8 Options_DefaultGeolocationSettingChanged 0x3f92cd6678d2f595 Options_DefaultHandlersSettingChanged 0x5dfe307474e6b526 Options_DefaultImagesSettingChanged @@ -977,6 +979,8 @@ 0x4aa2c70a745dbb49 Options_MetricsReportingCheckbox_Enable 0x224b0bf60dccdeda Options_MousePrimaryRight_Disable 0xb23cd3cde814d929 Options_MousePrimaryRight_Enable +0x820f29cc9c44d0d5 Options_PasswordGenerationCheckbox_Disable +0x4df19d1fb4741c2a Options_PasswordGenerationCheckbox_Enable 0xc5fbe9d9b3a165dd Options_PasswordManager_Disable 0x59b4f208d9d9f648 Options_PasswordManager_Enable 0x6149925370ef4f47 Options_PluginsCheckbox_Disable diff --git a/content/ppapi_plugin/broker_process_dispatcher.cc b/content/ppapi_plugin/broker_process_dispatcher.cc index e4b4cb3..5e717e4 100644 --- a/content/ppapi_plugin/broker_process_dispatcher.cc +++ b/content/ppapi_plugin/broker_process_dispatcher.cc @@ -6,11 +6,15 @@ #include "base/bind.h" #include "base/bind_helpers.h" +#include "base/memory/scoped_ptr.h" #include "base/utf_string_conversions.h" #include "content/common/child_process.h" #include "ppapi/c/pp_bool.h" #include "ppapi/c/private/ppp_flash_browser_operations.h" #include "ppapi/proxy/ppapi_messages.h" +#include "ppapi/shared_impl/ppapi_globals.h" +#include "ppapi/shared_impl/var.h" +#include "ppapi/shared_impl/var_tracker.h" namespace { @@ -26,14 +30,70 @@ std::string ConvertPluginDataPath(const FilePath& plugin_data_path) { #endif } +struct GetPermissionSettingsContext { + GetPermissionSettingsContext( + const base::WeakPtr<BrokerProcessDispatcher> in_dispatcher, + uint32 in_request_id) + : dispatcher(in_dispatcher), + request_id(in_request_id) { + } + + base::WeakPtr<BrokerProcessDispatcher> dispatcher; + uint32 request_id; +}; + +void GetPermissionSettingsCallback( + void* user_data, + PP_Bool success, + PP_Flash_BrowserOperations_Permission default_permission, + uint32_t site_count, + const PP_Flash_BrowserOperations_SiteSetting sites[]) { + scoped_ptr<GetPermissionSettingsContext> context( + reinterpret_cast<GetPermissionSettingsContext*>(user_data)); + + if (!context->dispatcher) + return; + + ppapi::FlashSiteSettings site_vector; + if (success) { + site_vector.reserve(site_count); + for (uint32_t i = 0; i < site_count; ++i) { + ppapi::StringVar* string_var = ppapi::StringVar::FromPPVar(sites[i].site); + if (!string_var) { + success = PP_FALSE; + break; + } + site_vector.push_back( + ppapi::FlashSiteSetting(string_var->value(), sites[i].permission)); + } + + if (!success) + site_vector.clear(); + } + context->dispatcher->OnGetPermissionSettingsCompleted( + context->request_id, PP_ToBool(success), default_permission, site_vector); +} + } // namespace BrokerProcessDispatcher::BrokerProcessDispatcher( PP_GetInterface_Func get_plugin_interface, PP_ConnectInstance_Func connect_instance) : ppapi::proxy::BrokerSideDispatcher(connect_instance), - get_plugin_interface_(get_plugin_interface) { + get_plugin_interface_(get_plugin_interface), + flash_browser_operations_1_1_(NULL), + flash_browser_operations_1_0_(NULL) { ChildProcess::current()->AddRefProcess(); + + if (get_plugin_interface) { + flash_browser_operations_1_0_ = + static_cast<const PPP_Flash_BrowserOperations_1_0*>( + get_plugin_interface_(PPP_FLASH_BROWSEROPERATIONS_INTERFACE_1_0)); + + flash_browser_operations_1_1_ = + static_cast<const PPP_Flash_BrowserOperations_1_1*>( + get_plugin_interface_(PPP_FLASH_BROWSEROPERATIONS_INTERFACE_1_1)); + } } BrokerProcessDispatcher::~BrokerProcessDispatcher() { @@ -55,11 +115,25 @@ bool BrokerProcessDispatcher::OnMessageReceived(const IPC::Message& msg) { IPC_MESSAGE_HANDLER(PpapiMsg_ClearSiteData, OnMsgClearSiteData) IPC_MESSAGE_HANDLER(PpapiMsg_DeauthorizeContentLicenses, OnMsgDeauthorizeContentLicenses) + IPC_MESSAGE_HANDLER(PpapiMsg_GetPermissionSettings, + OnMsgGetPermissionSettings) + IPC_MESSAGE_HANDLER(PpapiMsg_SetDefaultPermission, + OnMsgSetDefaultPermission) + IPC_MESSAGE_HANDLER(PpapiMsg_SetSitePermission, OnMsgSetSitePermission) IPC_MESSAGE_UNHANDLED(return BrokerSideDispatcher::OnMessageReceived(msg)) IPC_END_MESSAGE_MAP() return true; } +void BrokerProcessDispatcher::OnGetPermissionSettingsCompleted( + uint32 request_id, + bool success, + PP_Flash_BrowserOperations_Permission default_permission, + const ppapi::FlashSiteSettings& sites) { + Send(new PpapiHostMsg_GetPermissionSettingsResult( + request_id, success, default_permission, sites)); +} + void BrokerProcessDispatcher::OnMsgClearSiteData( const FilePath& plugin_data_path, const std::string& site, @@ -76,34 +150,62 @@ void BrokerProcessDispatcher::OnMsgDeauthorizeContentLicenses( request_id, DeauthorizeContentLicenses(plugin_data_path))); } +void BrokerProcessDispatcher::OnMsgGetPermissionSettings( + uint32 request_id, + const FilePath& plugin_data_path, + PP_Flash_BrowserOperations_SettingType setting_type) { + if (!flash_browser_operations_1_1_) { + OnGetPermissionSettingsCompleted( + request_id, false, PP_FLASH_BROWSEROPERATIONS_PERMISSION_DEFAULT, + ppapi::FlashSiteSettings()); + return; + } + + std::string data_str = ConvertPluginDataPath(plugin_data_path); + // The GetPermissionSettingsContext object will be deleted in + // GetPermissionSettingsCallback(). + flash_browser_operations_1_1_->GetPermissionSettings( + data_str.c_str(), setting_type, &GetPermissionSettingsCallback, + new GetPermissionSettingsContext(AsWeakPtr(), request_id)); +} + +void BrokerProcessDispatcher::OnMsgSetDefaultPermission( + uint32 request_id, + const FilePath& plugin_data_path, + PP_Flash_BrowserOperations_SettingType setting_type, + PP_Flash_BrowserOperations_Permission permission, + bool clear_site_specific) { + Send(new PpapiHostMsg_SetDefaultPermissionResult( + request_id, + SetDefaultPermission(plugin_data_path, setting_type, permission, + clear_site_specific))); +} + +void BrokerProcessDispatcher::OnMsgSetSitePermission( + uint32 request_id, + const FilePath& plugin_data_path, + PP_Flash_BrowserOperations_SettingType setting_type, + const ppapi::FlashSiteSettings& sites) { + Send(new PpapiHostMsg_SetSitePermissionResult( + request_id, SetSitePermission(plugin_data_path, setting_type, sites))); +} + bool BrokerProcessDispatcher::ClearSiteData(const FilePath& plugin_data_path, const std::string& site, uint64 flags, uint64 max_age) { - if (!get_plugin_interface_) - return false; - - const PPP_Flash_BrowserOperations_1_1* browser_interface = - static_cast<const PPP_Flash_BrowserOperations_1_1*>( - get_plugin_interface_(PPP_FLASH_BROWSEROPERATIONS_INTERFACE_1_1)); - if (browser_interface) { - std::string data_str = ConvertPluginDataPath(plugin_data_path); - browser_interface->ClearSiteData(data_str.c_str(), - site.empty() ? NULL : site.c_str(), - flags, max_age); + std::string data_str = ConvertPluginDataPath(plugin_data_path); + if (flash_browser_operations_1_1_) { + flash_browser_operations_1_1_->ClearSiteData( + data_str.c_str(), site.empty() ? NULL : site.c_str(), flags, max_age); return true; } // TODO(viettrungluu): Remove this (and the 1.0 interface) sometime after M21 // goes to Stable. - const PPP_Flash_BrowserOperations_1_0* browser_interface_1_0 = - static_cast<const PPP_Flash_BrowserOperations_1_0*>( - get_plugin_interface_(PPP_FLASH_BROWSEROPERATIONS_INTERFACE_1_0)); - if (browser_interface_1_0) { - std::string data_str = ConvertPluginDataPath(plugin_data_path); - browser_interface_1_0->ClearSiteData(data_str.c_str(), - site.empty() ? NULL : site.c_str(), - flags, max_age); + if (flash_browser_operations_1_0_) { + flash_browser_operations_1_0_->ClearSiteData( + data_str.c_str(), site.empty() ? NULL : site.c_str(), flags, max_age); return true; } @@ -112,16 +214,52 @@ bool BrokerProcessDispatcher::ClearSiteData(const FilePath& plugin_data_path, bool BrokerProcessDispatcher::DeauthorizeContentLicenses( const FilePath& plugin_data_path) { - if (!get_plugin_interface_) - return false; - const PPP_Flash_BrowserOperations_1_1* browser_interface = - static_cast<const PPP_Flash_BrowserOperations_1_1*>( - get_plugin_interface_(PPP_FLASH_BROWSEROPERATIONS_INTERFACE_1_1)); - if (!browser_interface) + if (!flash_browser_operations_1_1_) return false; std::string data_str = ConvertPluginDataPath(plugin_data_path); - return PP_ToBool(browser_interface->DeauthorizeContentLicenses( + return PP_ToBool(flash_browser_operations_1_1_->DeauthorizeContentLicenses( data_str.c_str())); } +bool BrokerProcessDispatcher::SetDefaultPermission( + const FilePath& plugin_data_path, + PP_Flash_BrowserOperations_SettingType setting_type, + PP_Flash_BrowserOperations_Permission permission, + bool clear_site_specific) { + if (!flash_browser_operations_1_1_) + return false; + + std::string data_str = ConvertPluginDataPath(plugin_data_path); + return PP_ToBool(flash_browser_operations_1_1_->SetDefaultPermission( + data_str.c_str(), setting_type, permission, + PP_FromBool(clear_site_specific))); +} + +bool BrokerProcessDispatcher::SetSitePermission( + const FilePath& plugin_data_path, + PP_Flash_BrowserOperations_SettingType setting_type, + const ppapi::FlashSiteSettings& sites) { + if (!flash_browser_operations_1_1_) + return false; + + if (sites.empty()) + return true; + + std::string data_str = ConvertPluginDataPath(plugin_data_path); + scoped_array<PP_Flash_BrowserOperations_SiteSetting> site_array( + new PP_Flash_BrowserOperations_SiteSetting[sites.size()]); + + for (size_t i = 0; i < sites.size(); ++i) { + site_array[i].site = ppapi::StringVar::StringToPPVar(sites[i].site); + site_array[i].permission = sites[i].permission; + } + + PP_Bool result = flash_browser_operations_1_1_->SetSitePermission( + data_str.c_str(), setting_type, sites.size(), site_array.get()); + + for (size_t i = 0; i < sites.size(); ++i) + ppapi::PpapiGlobals::Get()->GetVarTracker()->ReleaseVar(site_array[i].site); + + return PP_ToBool(result); +} diff --git a/content/ppapi_plugin/broker_process_dispatcher.h b/content/ppapi_plugin/broker_process_dispatcher.h index b33a4e8..7da07bf 100644 --- a/content/ppapi_plugin/broker_process_dispatcher.h +++ b/content/ppapi_plugin/broker_process_dispatcher.h @@ -6,13 +6,17 @@ #define CONTENT_PPAPI_PLUGIN_BROKER_PROCESS_DISPATCHER_H_ #include "base/basictypes.h" +#include "base/memory/weak_ptr.h" #include "ppapi/c/ppp.h" #include "ppapi/proxy/broker_dispatcher.h" +#include "ppapi/shared_impl/ppp_flash_browser_operations_shared.h" // Wrapper around a BrokerDispatcher that provides the necessary integration // for plugin process management. This class is to avoid direct dependencies // from the PPAPI proxy on the Chrome multiprocess infrastructure. -class BrokerProcessDispatcher : public ppapi::proxy::BrokerSideDispatcher { +class BrokerProcessDispatcher + : public ppapi::proxy::BrokerSideDispatcher, + public base::SupportsWeakPtr<BrokerProcessDispatcher> { public: BrokerProcessDispatcher(PP_GetInterface_Func get_plugin_interface, PP_ConnectInstance_Func connect_instance); @@ -21,14 +25,34 @@ class BrokerProcessDispatcher : public ppapi::proxy::BrokerSideDispatcher { // IPC::Channel::Listener overrides. virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE; + void OnGetPermissionSettingsCompleted( + uint32 request_id, + bool success, + PP_Flash_BrowserOperations_Permission default_permission, + const ppapi::FlashSiteSettings& sites); + private: void OnMsgClearSiteData(const FilePath& plugin_data_path, const std::string& site, uint64 flags, uint64 max_age); - void OnMsgDeauthorizeContentLicenses(uint32 request_id, const FilePath& plugin_data_path); + void OnMsgGetPermissionSettings( + uint32 request_id, + const FilePath& plugin_data_path, + PP_Flash_BrowserOperations_SettingType setting_type); + void OnMsgSetDefaultPermission( + uint32 request_id, + const FilePath& plugin_data_path, + PP_Flash_BrowserOperations_SettingType setting_type, + PP_Flash_BrowserOperations_Permission permission, + bool clear_site_specific); + void OnMsgSetSitePermission( + uint32 request_id, + const FilePath& plugin_data_path, + PP_Flash_BrowserOperations_SettingType setting_type, + const ppapi::FlashSiteSettings& sites); // Requests that the plugin clear data, returning true on success. bool ClearSiteData(const FilePath& plugin_data_path, @@ -36,9 +60,19 @@ class BrokerProcessDispatcher : public ppapi::proxy::BrokerSideDispatcher { uint64 flags, uint64 max_age); bool DeauthorizeContentLicenses(const FilePath& plugin_data_path); + bool SetDefaultPermission(const FilePath& plugin_data_path, + PP_Flash_BrowserOperations_SettingType setting_type, + PP_Flash_BrowserOperations_Permission permission, + bool clear_site_specific); + bool SetSitePermission(const FilePath& plugin_data_path, + PP_Flash_BrowserOperations_SettingType setting_type, + const ppapi::FlashSiteSettings& sites); PP_GetInterface_Func get_plugin_interface_; + const PPP_Flash_BrowserOperations_1_1* flash_browser_operations_1_1_; + const PPP_Flash_BrowserOperations_1_0* flash_browser_operations_1_0_; + DISALLOW_COPY_AND_ASSIGN(BrokerProcessDispatcher); }; diff --git a/ppapi/ppapi_shared.gypi b/ppapi/ppapi_shared.gypi index 5afcefe..e993398 100644 --- a/ppapi/ppapi_shared.gypi +++ b/ppapi/ppapi_shared.gypi @@ -112,6 +112,7 @@ 'shared_impl/ppb_video_capture_shared.h', 'shared_impl/ppb_view_shared.cc', 'shared_impl/ppb_view_shared.h', + 'shared_impl/ppp_flash_browser_operations_shared.h', 'shared_impl/ppp_instance_combined.cc', 'shared_impl/ppp_instance_combined.h', 'shared_impl/proxy_lock.cc', diff --git a/ppapi/proxy/ppapi_messages.h b/ppapi/proxy/ppapi_messages.h index 16c57c1..2889ea4 100644 --- a/ppapi/proxy/ppapi_messages.h +++ b/ppapi/proxy/ppapi_messages.h @@ -45,6 +45,7 @@ #include "ppapi/shared_impl/ppb_network_list_private_shared.h" #include "ppapi/shared_impl/ppb_url_request_info_shared.h" #include "ppapi/shared_impl/ppb_view_shared.h" +#include "ppapi/shared_impl/ppp_flash_browser_operations_shared.h" #include "ppapi/shared_impl/private/ppb_host_resolver_shared.h" #include "ppapi/shared_impl/private/ppb_x509_certificate_private_shared.h" @@ -118,6 +119,11 @@ IPC_STRUCT_TRAITS_BEGIN(ppapi::DeviceRefData) IPC_STRUCT_TRAITS_MEMBER(id) IPC_STRUCT_TRAITS_END() +IPC_STRUCT_TRAITS_BEGIN(ppapi::FlashSiteSetting) + IPC_STRUCT_TRAITS_MEMBER(site) + IPC_STRUCT_TRAITS_MEMBER(permission) +IPC_STRUCT_TRAITS_END() + IPC_STRUCT_TRAITS_BEGIN(ppapi::ViewData) IPC_STRUCT_TRAITS_MEMBER(rect) IPC_STRUCT_TRAITS_MEMBER(is_fullscreen) @@ -270,6 +276,36 @@ IPC_MESSAGE_CONTROL2(PpapiHostMsg_DeauthorizeContentLicensesResult, uint32 /* request_id */, bool /* success */) +IPC_MESSAGE_CONTROL3(PpapiMsg_GetPermissionSettings, + uint32 /* request_id */, + FilePath /* plugin_data_path */, + PP_Flash_BrowserOperations_SettingType /* setting_type */) +IPC_MESSAGE_CONTROL4( + PpapiHostMsg_GetPermissionSettingsResult, + uint32 /* request_id */, + bool /* success */, + PP_Flash_BrowserOperations_Permission /* default_permission */, + ppapi::FlashSiteSettings /* sites */) + +IPC_MESSAGE_CONTROL5(PpapiMsg_SetDefaultPermission, + uint32 /* request_id */, + FilePath /* plugin_data_path */, + PP_Flash_BrowserOperations_SettingType /* setting_type */, + PP_Flash_BrowserOperations_Permission /* permission */, + bool /* clear_site_specific */) +IPC_MESSAGE_CONTROL2(PpapiHostMsg_SetDefaultPermissionResult, + uint32 /* request_id */, + bool /* success */) + +IPC_MESSAGE_CONTROL4(PpapiMsg_SetSitePermission, + uint32 /* request_id */, + FilePath /* plugin_data_path */, + PP_Flash_BrowserOperations_SettingType /* setting_type */, + ppapi::FlashSiteSettings /* sites */) +IPC_MESSAGE_CONTROL2(PpapiHostMsg_SetSitePermissionResult, + uint32 /* request_id */, + bool /* success */) + // Broker Process. IPC_SYNC_MESSAGE_CONTROL2_1(PpapiMsg_ConnectToPlugin, PP_Instance /* instance */, diff --git a/ppapi/shared_impl/ppp_flash_browser_operations_shared.h b/ppapi/shared_impl/ppp_flash_browser_operations_shared.h new file mode 100644 index 0000000..c77ad2b --- /dev/null +++ b/ppapi/shared_impl/ppp_flash_browser_operations_shared.h @@ -0,0 +1,33 @@ +// 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 PPAPI_SHARED_IMPL_PPP_FLASH_BROWSER_OPERATIONS_SHARED_H_ +#define PPAPI_SHARED_IMPL_PPP_FLASH_BROWSER_OPERATIONS_SHARED_H_ + +#include <string> +#include <vector> + +#include "ppapi/c/private/ppp_flash_browser_operations.h" + +namespace ppapi { + +struct FlashSiteSetting { + FlashSiteSetting() + : permission(PP_FLASH_BROWSEROPERATIONS_PERMISSION_DEFAULT) { + } + FlashSiteSetting(const std::string& in_site, + PP_Flash_BrowserOperations_Permission in_permission) + : site(in_site), + permission(in_permission) { + } + + std::string site; + PP_Flash_BrowserOperations_Permission permission; +}; + +typedef std::vector<FlashSiteSetting> FlashSiteSettings; + +} // namespace ppapi + +#endif // PPAPI_SHARED_IMPL_PPP_FLASH_BROWSER_OPERATIONS_SHARED_H_ |