diff options
author | xians@chromium.org <xians@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-12-11 11:05:34 +0000 |
---|---|---|
committer | xians@chromium.org <xians@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-12-11 11:05:34 +0000 |
commit | 0bacc191a88137c1ba8602b681e96cf95ec825da (patch) | |
tree | 05e1fe060e54b6a0eee5f5004d6d9d6fa27749ea /chrome/browser/content_settings | |
parent | db2213b17e3a9f644b274d8089cccdb973406ad3 (diff) | |
download | chromium_src-0bacc191a88137c1ba8602b681e96cf95ec825da.zip chromium_src-0bacc191a88137c1ba8602b681e96cf95ec825da.tar.gz chromium_src-0bacc191a88137c1ba8602b681e96cf95ec825da.tar.bz2 |
This CL is part of the code in https://codereview.chromium.org/11316275/ to refactor the media UI.
This patch does
# split CONTENT_SETTINGS_TYPE_MEDIASTREAM into CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC and CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA
# use ContentSetting as value for CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC/CAMERA, deprecate CONTENT_SETTINGS_TYPE_MEDIASTREAM compound values.
# CONTENT_SETTINGS_TYPE_MEDIASTREAM will be used only for default setting.
# On the content setting media exceptions, show two columns, one for audio and one for video.
BUG=163940
TEST=browser_tests, manual tests like
go to content setting media, use webrtc demo like https://webrtc-demos.appspot.com/html/pc1.html to make an exception, verify the exception show correctly in content settting.
Review URL: https://chromiumcodereview.appspot.com/11316306
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@172302 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/content_settings')
6 files changed, 77 insertions, 6 deletions
diff --git a/chrome/browser/content_settings/content_settings_default_provider.cc b/chrome/browser/content_settings/content_settings_default_provider.cc index e519007..b4a18cf 100644 --- a/chrome/browser/content_settings/content_settings_default_provider.cc +++ b/chrome/browser/content_settings/content_settings_default_provider.cc @@ -45,6 +45,8 @@ const ContentSetting kDefaultSettings[] = { CONTENT_SETTING_ASK, // CONTENT_SETTINGS_TYPE_MOUSELOCK CONTENT_SETTING_DEFAULT, // CONTENT_SETTINGS_TYPE_MIXEDSCRIPT CONTENT_SETTING_ASK, // CONTENT_SETTINGS_TYPE_MEDIASTREAM + CONTENT_SETTING_ASK, // CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC + CONTENT_SETTING_ASK, // CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA CONTENT_SETTING_DEFAULT, // CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS CONTENT_SETTING_ASK, // CONTENT_SETTINGS_TYPE_PPAPI_BROKER #if defined(OS_WIN) diff --git a/chrome/browser/content_settings/content_settings_policy_provider.cc b/chrome/browser/content_settings/content_settings_policy_provider.cc index c3c25d5..0175901 100644 --- a/chrome/browser/content_settings/content_settings_policy_provider.cc +++ b/chrome/browser/content_settings/content_settings_policy_provider.cc @@ -38,6 +38,8 @@ const char* kPrefToManageType[] = { NULL, // No policy for default value of mouse lock requests NULL, // No policy for default value of mixed script blocking prefs::kManagedDefaultMediaStreamSetting, + NULL, // No policy for default value of media stream mic + NULL, // No policy for default value of media stream camera NULL, // No policy for default value of protocol handlers NULL, // No policy for default value of PPAPI broker #if defined(OS_WIN) diff --git a/chrome/browser/content_settings/content_settings_pref_provider.cc b/chrome/browser/content_settings/content_settings_pref_provider.cc index cf2c0fc..6c5e1be 100644 --- a/chrome/browser/content_settings/content_settings_pref_provider.cc +++ b/chrome/browser/content_settings/content_settings_pref_provider.cc @@ -37,6 +37,8 @@ typedef std::pair<std::string, std::string> StringPair; typedef std::map<std::string, std::string> StringMap; const char kPerPluginPrefName[] = "per_plugin"; +const char kAudioKey[] = "audio"; +const char kVideoKey[] = "video"; ContentSetting FixObsoleteCookiePromptMode(ContentSettingsType content_type, ContentSetting setting) { @@ -84,7 +86,6 @@ PrefProvider::PrefProvider(PrefService* prefs, is_incognito_(incognito), updating_preferences_(false) { DCHECK(prefs_); - // Verify preferences version. if (!prefs_->HasPrefPath(prefs::kContentSettingsVersion)) { prefs_->SetInteger(prefs::kContentSettingsVersion, @@ -103,6 +104,11 @@ PrefProvider::PrefProvider(PrefService* prefs, value_map_.size()); } + // Migrate the obsolete media content setting exceptions to the new settings. + // This needs to be done after ReadContentSettingsFromPref(). + if (!is_incognito_) + MigrateObsoleteMediaContentSetting(); + pref_change_registrar_.Init(prefs_); pref_change_registrar_.Add( prefs::kContentSettingsPatternPairs, @@ -296,6 +302,57 @@ void PrefProvider::UpdatePref( } } + +void PrefProvider::MigrateObsoleteMediaContentSetting() { + std::vector<Rule> rules_to_delete; + { + scoped_ptr<RuleIterator> rule_iterator( + GetRuleIterator(CONTENT_SETTINGS_TYPE_MEDIASTREAM, "", false)); + while (rule_iterator->HasNext()) { + // Skip default setting and rules without a value. + const content_settings::Rule& rule = rule_iterator->Next(); + DCHECK(rule.primary_pattern != ContentSettingsPattern::Wildcard()); + if (!rule.value.get()) + continue; + rules_to_delete.push_back(rule); + } + } + + for (std::vector<Rule>::const_iterator it = rules_to_delete.begin(); + it != rules_to_delete.end(); ++it) { + const DictionaryValue* value_dict = NULL; + if (!it->value->GetAsDictionary(&value_dict) || value_dict->empty()) + return; + + std::string audio_device, video_device; + value_dict->GetString(kAudioKey, &audio_device); + value_dict->GetString(kVideoKey, &video_device); + // Add the exception to the new microphone content setting. + if (!audio_device.empty()) { + SetWebsiteSetting(it->primary_pattern, + it->secondary_pattern, + CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, + "", + Value::CreateIntegerValue(CONTENT_SETTING_ALLOW)); + } + // Add the exception to the new camera content setting. + if (!video_device.empty()) { + SetWebsiteSetting(it->primary_pattern, + it->secondary_pattern, + CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, + "", + Value::CreateIntegerValue(CONTENT_SETTING_ALLOW)); + } + + // Remove the old exception in CONTENT_SETTINGS_TYPE_MEDIASTREAM. + SetWebsiteSetting(it->primary_pattern, + it->secondary_pattern, + CONTENT_SETTINGS_TYPE_MEDIASTREAM, + "", + NULL); + } +} + void PrefProvider::ReadContentSettingsFromPref(bool overwrite) { // |DictionaryPrefUpdate| sends out notifications when destructed. This // construction order ensures |AutoLock| gets destroyed first and |lock_| is diff --git a/chrome/browser/content_settings/content_settings_pref_provider.h b/chrome/browser/content_settings/content_settings_pref_provider.h index a397211..de13196 100644 --- a/chrome/browser/content_settings/content_settings_pref_provider.h +++ b/chrome/browser/content_settings/content_settings_pref_provider.h @@ -73,7 +73,8 @@ class PrefProvider : public ObservableProvider { const ResourceIdentifier& resource_identifier, const base::Value* value); - void MigrateObsoleteClearOnExitPref(); + // Migrate the old media setting into new mic/camera content settings. + void MigrateObsoleteMediaContentSetting(); static void CanonicalizeContentSettingsExceptions( base::DictionaryValue* all_settings_dictionary); diff --git a/chrome/browser/content_settings/content_settings_utils.cc b/chrome/browser/content_settings/content_settings_utils.cc index b6e01c6..31c6ba0 100644 --- a/chrome/browser/content_settings/content_settings_utils.cc +++ b/chrome/browser/content_settings/content_settings_utils.cc @@ -36,6 +36,8 @@ const char* kTypeNames[] = { "mouselock", "mixed-script", "media-stream", + "media-stream-mic", + "media-stream-camera", "register-protocol-handler", "ppapi-broker", #if defined(OS_WIN) diff --git a/chrome/browser/content_settings/host_content_settings_map.cc b/chrome/browser/content_settings/host_content_settings_map.cc index c501659..458d0a5 100644 --- a/chrome/browser/content_settings/host_content_settings_map.cc +++ b/chrome/browser/content_settings/host_content_settings_map.cc @@ -348,6 +348,12 @@ bool HostContentSettingsMap::IsSettingAllowedForType( return false; } + // We don't support ALLOW for media default setting. + if (content_type == CONTENT_SETTINGS_TYPE_MEDIASTREAM && + setting == CONTENT_SETTING_ALLOW) { + return false; + } + // DEFAULT, ALLOW and BLOCK are always allowed. if (setting == CONTENT_SETTING_DEFAULT || setting == CONTENT_SETTING_ALLOW || @@ -363,6 +369,8 @@ bool HostContentSettingsMap::IsSettingAllowedForType( case CONTENT_SETTINGS_TYPE_INTENTS: case CONTENT_SETTINGS_TYPE_MOUSELOCK: case CONTENT_SETTINGS_TYPE_MEDIASTREAM: + case CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC: + case CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA: case CONTENT_SETTINGS_TYPE_PPAPI_BROKER: return setting == CONTENT_SETTING_ASK; default: @@ -373,9 +381,9 @@ bool HostContentSettingsMap::IsSettingAllowedForType( // static bool HostContentSettingsMap::ContentTypeHasCompoundValue( ContentSettingsType type) { - // Values for content type CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE are - // of type dictionary/map. Compound types like dictionaries can't be mapped to - // the type |ContentSetting|. + // Values for content type CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE and + // CONTENT_SETTINGS_TYPE_MEDIASTREAM are of type dictionary/map. Compound + // types like dictionaries can't be mapped to the type |ContentSetting|. return (type == CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE || type == CONTENT_SETTINGS_TYPE_MEDIASTREAM); } @@ -461,7 +469,6 @@ void HostContentSettingsMap::MigrateObsoleteClearOnExitPref() { prefs_->SetBoolean(prefs::kContentSettingsClearOnExitMigrated, true); } - void HostContentSettingsMap::AddSettingsForOneType( const content_settings::ProviderInterface* provider, ProviderType provider_type, |