Index: chrome/browser/content_settings/tab_specific_content_settings.cc |
diff --git a/chrome/browser/content_settings/tab_specific_content_settings.cc b/chrome/browser/content_settings/tab_specific_content_settings.cc |
index cca7a210a7b9bd774c3790967c6ee6ea54d43c80..996eb7ab268f5e3eb9b498b69e1af557e82654bb 100644 |
--- a/chrome/browser/content_settings/tab_specific_content_settings.cc |
+++ b/chrome/browser/content_settings/tab_specific_content_settings.cc |
@@ -8,6 +8,7 @@ |
#include "base/command_line.h" |
#include "base/lazy_instance.h" |
+#include "base/prefs/pref_service.h" |
#include "base/strings/utf_string_conversions.h" |
#include "chrome/browser/browsing_data/browsing_data_appcache_helper.h" |
#include "chrome/browser/browsing_data/browsing_data_cookie_helper.h" |
@@ -20,9 +21,11 @@ |
#include "chrome/browser/content_settings/content_settings_details.h" |
#include "chrome/browser/content_settings/content_settings_utils.h" |
#include "chrome/browser/content_settings/host_content_settings_map.h" |
+#include "chrome/browser/media/media_stream_capture_indicator.h" |
#include "chrome/browser/prerender/prerender_manager.h" |
#include "chrome/browser/profiles/profile.h" |
#include "chrome/common/chrome_switches.h" |
+#include "chrome/common/pref_names.h" |
#include "chrome/common/render_messages.h" |
#include "content/public/browser/browser_thread.h" |
#include "content/public/browser/navigation_controller.h" |
@@ -71,6 +74,7 @@ TabSpecificContentSettings::TabSpecificContentSettings(WebContents* tab) |
previous_protocol_handler_(ProtocolHandler::EmptyProtocolHandler()), |
pending_protocol_handler_setting_(CONTENT_SETTING_DEFAULT), |
load_plugins_link_enabled_(true), |
+ microphone_camera_state_(MICROPHONE_CAMERA_NOT_ACCESSED), |
observer_(this) { |
ClearBlockedContentSettingsExceptForCookies(); |
ClearCookieSpecificContentSettings(); |
@@ -272,20 +276,18 @@ bool TabSpecificContentSettings::IsContentAllowed( |
void TabSpecificContentSettings::OnContentBlocked(ContentSettingsType type) { |
DCHECK(type != CONTENT_SETTINGS_TYPE_GEOLOCATION) |
<< "Geolocation settings handled by OnGeolocationPermissionSet"; |
+ DCHECK(type != CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC && |
+ type != CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA) |
+ << "Media stream settings handled by OnMediaStreamPermissionSet"; |
if (type < 0 || type >= CONTENT_SETTINGS_NUM_TYPES) |
return; |
- // Media is different from other content setting types since it allows new |
- // setting to kick in without reloading the page, and the UI for media is |
- // always reflecting the newest permission setting. |
switch (type) { |
- case CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC: |
- case CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA: |
#if defined(OS_ANDROID) |
case CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER: |
-#endif |
content_allowed_[type] = false; |
break; |
+#endif |
default: |
content_allowed_[type] = true; |
break; |
@@ -315,20 +317,19 @@ void TabSpecificContentSettings::OnContentBlocked(ContentSettingsType type) { |
void TabSpecificContentSettings::OnContentAllowed(ContentSettingsType type) { |
DCHECK(type != CONTENT_SETTINGS_TYPE_GEOLOCATION) |
<< "Geolocation settings handled by OnGeolocationPermissionSet"; |
+ DCHECK(type != CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC && |
+ type != CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA) |
+ << "Media stream settings handled by OnMediaStreamPermissionSet"; |
bool access_changed = false; |
switch (type) { |
- case CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC: |
- case CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA: |
#if defined(OS_ANDROID) |
case CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER: |
-#endif |
- // The setting for media is overwritten here because media does not need |
- // to reload the page to have the new setting kick in. See issue/175993. |
if (content_blocked_[type]) { |
content_blocked_[type] = false; |
access_changed = true; |
} |
break; |
+#endif |
default: |
break; |
} |
@@ -476,27 +477,46 @@ void TabSpecificContentSettings::OnProtectedMediaIdentifierPermissionSet( |
} |
#endif |
-TabSpecificContentSettings::MicrophoneCameraState |
-TabSpecificContentSettings::GetMicrophoneCameraState() const { |
- if (IsContentAllowed(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) && |
- IsContentAllowed(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA)) { |
- return MICROPHONE_CAMERA_ACCESSED; |
- } else if (IsContentAllowed(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC)) { |
- return MICROPHONE_ACCESSED; |
- } else if (IsContentAllowed(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA)) { |
- return CAMERA_ACCESSED; |
- } |
+unsigned TabSpecificContentSettings::GetMicrophoneCameraState() const { |
+ return microphone_camera_state_; |
+} |
- if (IsContentBlocked(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) && |
- IsContentBlocked(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA)) { |
- return MICROPHONE_CAMERA_BLOCKED; |
- } else if (IsContentBlocked(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC)) { |
- return MICROPHONE_BLOCKED; |
- } else if (IsContentBlocked(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA)) { |
- return CAMERA_BLOCKED; |
- } |
+bool TabSpecificContentSettings::IsMicrophoneCameraStateChanged() const { |
+ if (microphone_camera_state_ == MICROPHONE_CAMERA_NOT_ACCESSED) |
Peter Kasting
2014/09/24 01:33:00
Nit: This conditional isn't really needed.
robwu
2014/09/24 23:38:44
It is a small optimization to fail fast. The user
Peter Kasting
2014/09/25 00:53:25
We should only worry about optimizing that if the
robwu
2014/09/25 08:57:57
All right, removed.
|
+ return false; |
- return MICROPHONE_CAMERA_NOT_ACCESSED; |
+ if ((microphone_camera_state_ & MICROPHONE_ACCESSED) && |
+ ((microphone_camera_state_ & MICROPHONE_BLOCKED) ? |
+ !IsContentBlocked(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) : |
+ !IsContentAllowed(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC))) |
+ return true; |
+ |
+ if ((microphone_camera_state_ & CAMERA_ACCESSED) && |
+ ((microphone_camera_state_ & CAMERA_BLOCKED) ? |
+ !IsContentBlocked(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA) : |
+ !IsContentAllowed(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA))) |
+ return true; |
+ |
+ PrefService* prefs = |
+ Profile::FromBrowserContext(web_contents()->GetBrowserContext())-> |
+ GetPrefs(); |
+ scoped_refptr<MediaStreamCaptureIndicator> media_indicator = |
+ MediaCaptureDevicesDispatcher::GetInstance()-> |
+ GetMediaStreamCaptureIndicator(); |
+ |
+ if ((microphone_camera_state_ & MICROPHONE_ACCESSED) && |
+ prefs->GetString(prefs::kDefaultAudioCaptureDevice) != |
+ media_stream_selected_audio_device() && |
+ media_indicator->IsCapturingAudio(web_contents())) |
+ return true; |
+ |
+ if ((microphone_camera_state_ & CAMERA_ACCESSED) && |
+ prefs->GetString(prefs::kDefaultVideoCaptureDevice) != |
+ media_stream_selected_video_device() && |
+ media_indicator->IsCapturingVideo(web_contents())) |
+ return true; |
+ |
+ return false; |
} |
void TabSpecificContentSettings::OnMediaStreamPermissionSet( |
@@ -504,44 +524,52 @@ void TabSpecificContentSettings::OnMediaStreamPermissionSet( |
const MediaStreamDevicesController::MediaStreamTypeSettingsMap& |
request_permissions) { |
media_stream_access_origin_ = request_origin; |
+ unsigned prev_microphone_camera_state = microphone_camera_state_; |
+ microphone_camera_state_ = MICROPHONE_CAMERA_NOT_ACCESSED; |
+ PrefService* prefs = |
+ Profile::FromBrowserContext(web_contents()->GetBrowserContext())-> |
+ GetPrefs(); |
MediaStreamDevicesController::MediaStreamTypeSettingsMap::const_iterator it = |
request_permissions.find(content::MEDIA_DEVICE_AUDIO_CAPTURE); |
if (it != request_permissions.end()) { |
media_stream_requested_audio_device_ = it->second.requested_device_id; |
- switch (it->second.permission) { |
- case MediaStreamDevicesController::MEDIA_NONE: |
- NOTREACHED(); |
- break; |
- case MediaStreamDevicesController::MEDIA_ALLOWED: |
- OnContentAllowed(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC); |
- break; |
- // TODO(grunell): UI should show for what reason access has been blocked. |
- case MediaStreamDevicesController::MEDIA_BLOCKED_BY_POLICY: |
- case MediaStreamDevicesController::MEDIA_BLOCKED_BY_USER_SETTING: |
- case MediaStreamDevicesController::MEDIA_BLOCKED_BY_USER: |
- OnContentBlocked(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC); |
- break; |
- } |
+ media_stream_selected_audio_device_ = |
+ media_stream_requested_audio_device_.empty() ? |
+ prefs->GetString(prefs::kDefaultAudioCaptureDevice) : |
+ media_stream_requested_audio_device_; |
+ DCHECK_NE(MediaStreamDevicesController::MEDIA_NONE, it->second.permission); |
+ const bool mic_allowed = |
+ it->second.permission == MediaStreamDevicesController::MEDIA_ALLOWED; |
+ content_allowed_[CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC] = mic_allowed; |
+ content_blocked_[CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC] = !mic_allowed; |
+ microphone_camera_state_ |= MICROPHONE_ACCESSED; |
Peter Kasting
2014/09/24 01:33:00
Nit: Shorter:
microphone_camera_state_ |=
robwu
2014/09/24 23:38:44
Done.
|
+ if (!mic_allowed) |
+ microphone_camera_state_ |= MICROPHONE_BLOCKED; |
} |
it = request_permissions.find(content::MEDIA_DEVICE_VIDEO_CAPTURE); |
if (it != request_permissions.end()) { |
media_stream_requested_video_device_ = it->second.requested_device_id; |
- switch (it->second.permission) { |
- case MediaStreamDevicesController::MEDIA_NONE: |
- NOTREACHED(); |
- break; |
- case MediaStreamDevicesController::MEDIA_ALLOWED: |
- OnContentAllowed(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA); |
- break; |
- // TODO(grunell): UI should show for what reason access has been blocked. |
- case MediaStreamDevicesController::MEDIA_BLOCKED_BY_POLICY: |
- case MediaStreamDevicesController::MEDIA_BLOCKED_BY_USER_SETTING: |
- case MediaStreamDevicesController::MEDIA_BLOCKED_BY_USER: |
- OnContentBlocked(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA); |
- break; |
- } |
+ media_stream_selected_video_device_ = |
+ media_stream_requested_video_device_.empty() ? |
+ prefs->GetString(prefs::kDefaultVideoCaptureDevice) : |
+ media_stream_requested_video_device_; |
+ DCHECK_NE(MediaStreamDevicesController::MEDIA_NONE, it->second.permission); |
+ const bool cam_allowed = |
+ it->second.permission == MediaStreamDevicesController::MEDIA_ALLOWED; |
+ content_allowed_[CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA] = cam_allowed; |
+ content_blocked_[CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA] = !cam_allowed; |
+ microphone_camera_state_ |= CAMERA_ACCESSED; |
+ if (!cam_allowed) |
+ microphone_camera_state_ |= CAMERA_BLOCKED; |
+ } |
+ |
+ if (microphone_camera_state_ != prev_microphone_camera_state) { |
+ content::NotificationService::current()->Notify( |
+ chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED, |
+ content::Source<WebContents>(web_contents()), |
+ content::NotificationService::NoDetails()); |
} |
} |
@@ -565,6 +593,7 @@ void TabSpecificContentSettings::ClearBlockedContentSettingsExceptForCookies() { |
content_allowed_[i] = false; |
content_blockage_indicated_to_user_[i] = false; |
} |
+ microphone_camera_state_ = MICROPHONE_CAMERA_NOT_ACCESSED; |
load_plugins_link_enabled_ = true; |
content::NotificationService::current()->Notify( |
chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED, |
@@ -707,9 +736,20 @@ void TabSpecificContentSettings::OnContentSettingChanged( |
details.primary_pattern().Matches(entry_url)) { |
Profile* profile = |
Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
+ const HostContentSettingsMap* map = profile->GetHostContentSettingsMap(); |
+ |
+ if (content_type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC || |
+ content_type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA) { |
+ const GURL media_origin = media_stream_access_origin(); |
+ ContentSetting setting = map->GetContentSetting(media_origin, |
+ media_origin, |
+ content_type, |
+ std::string()); |
+ content_allowed_[content_type] = setting == CONTENT_SETTING_ALLOW; |
+ content_blocked_[content_type] = setting == CONTENT_SETTING_BLOCK; |
+ } |
RendererContentSettingRules rules; |
- GetRendererContentSettingRules(profile->GetHostContentSettingsMap(), |
- &rules); |
+ GetRendererContentSettingRules(map, &rules); |
Send(new ChromeViewMsg_SetContentSettingRules(rules)); |
} |
} |