Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | 5 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
| 6 | 6 |
| 7 #include <list> | 7 #include <list> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| 11 #include "base/prefs/pref_service.h" | |
| 11 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 12 #include "chrome/browser/browsing_data/browsing_data_appcache_helper.h" | 13 #include "chrome/browser/browsing_data/browsing_data_appcache_helper.h" |
| 13 #include "chrome/browser/browsing_data/browsing_data_cookie_helper.h" | 14 #include "chrome/browser/browsing_data/browsing_data_cookie_helper.h" |
| 14 #include "chrome/browser/browsing_data/browsing_data_database_helper.h" | 15 #include "chrome/browser/browsing_data/browsing_data_database_helper.h" |
| 15 #include "chrome/browser/browsing_data/browsing_data_file_system_helper.h" | 16 #include "chrome/browser/browsing_data/browsing_data_file_system_helper.h" |
| 16 #include "chrome/browser/browsing_data/browsing_data_indexed_db_helper.h" | 17 #include "chrome/browser/browsing_data/browsing_data_indexed_db_helper.h" |
| 17 #include "chrome/browser/browsing_data/browsing_data_local_storage_helper.h" | 18 #include "chrome/browser/browsing_data/browsing_data_local_storage_helper.h" |
| 18 #include "chrome/browser/browsing_data/cookies_tree_model.h" | 19 #include "chrome/browser/browsing_data/cookies_tree_model.h" |
| 19 #include "chrome/browser/chrome_notification_types.h" | 20 #include "chrome/browser/chrome_notification_types.h" |
| 20 #include "chrome/browser/content_settings/content_settings_details.h" | 21 #include "chrome/browser/content_settings/content_settings_details.h" |
| 21 #include "chrome/browser/content_settings/content_settings_utils.h" | 22 #include "chrome/browser/content_settings/content_settings_utils.h" |
| 22 #include "chrome/browser/content_settings/host_content_settings_map.h" | 23 #include "chrome/browser/content_settings/host_content_settings_map.h" |
| 24 #include "chrome/browser/media/media_stream_capture_indicator.h" | |
| 23 #include "chrome/browser/prerender/prerender_manager.h" | 25 #include "chrome/browser/prerender/prerender_manager.h" |
| 24 #include "chrome/browser/profiles/profile.h" | 26 #include "chrome/browser/profiles/profile.h" |
| 25 #include "chrome/common/chrome_switches.h" | 27 #include "chrome/common/chrome_switches.h" |
| 28 #include "chrome/common/pref_names.h" | |
| 26 #include "chrome/common/render_messages.h" | 29 #include "chrome/common/render_messages.h" |
| 27 #include "content/public/browser/browser_thread.h" | 30 #include "content/public/browser/browser_thread.h" |
| 28 #include "content/public/browser/navigation_controller.h" | 31 #include "content/public/browser/navigation_controller.h" |
| 29 #include "content/public/browser/navigation_details.h" | 32 #include "content/public/browser/navigation_details.h" |
| 30 #include "content/public/browser/navigation_entry.h" | 33 #include "content/public/browser/navigation_entry.h" |
| 31 #include "content/public/browser/notification_registrar.h" | 34 #include "content/public/browser/notification_registrar.h" |
| 32 #include "content/public/browser/notification_service.h" | 35 #include "content/public/browser/notification_service.h" |
| 33 #include "content/public/browser/render_frame_host.h" | 36 #include "content/public/browser/render_frame_host.h" |
| 34 #include "content/public/browser/render_view_host.h" | 37 #include "content/public/browser/render_view_host.h" |
| 35 #include "content/public/browser/web_contents.h" | 38 #include "content/public/browser/web_contents.h" |
| 36 #include "content/public/browser/web_contents_delegate.h" | 39 #include "content/public/browser/web_contents_delegate.h" |
| 37 #include "net/cookies/canonical_cookie.h" | 40 #include "net/cookies/canonical_cookie.h" |
| 38 #include "storage/common/fileapi/file_system_types.h" | 41 #include "storage/common/fileapi/file_system_types.h" |
| 39 | 42 |
| 40 using content::BrowserThread; | 43 using content::BrowserThread; |
| 41 using content::NavigationController; | 44 using content::NavigationController; |
| 42 using content::NavigationEntry; | 45 using content::NavigationEntry; |
| 43 using content::RenderViewHost; | 46 using content::RenderViewHost; |
| 44 using content::WebContents; | 47 using content::WebContents; |
| 45 | 48 |
| 46 DEFINE_WEB_CONTENTS_USER_DATA_KEY(TabSpecificContentSettings); | 49 DEFINE_WEB_CONTENTS_USER_DATA_KEY(TabSpecificContentSettings); |
| 50 STATIC_CONST_MEMBER_DEFINITION const | |
| 51 TabSpecificContentSettings::MicrophoneCameraState | |
| 52 TabSpecificContentSettings::MICROPHONE_CAMERA_NOT_ACCESSED; | |
| 53 STATIC_CONST_MEMBER_DEFINITION const | |
| 54 TabSpecificContentSettings::MicrophoneCameraState | |
| 55 TabSpecificContentSettings::MICROPHONE_ACCESSED; | |
| 56 STATIC_CONST_MEMBER_DEFINITION const | |
| 57 TabSpecificContentSettings::MicrophoneCameraState | |
| 58 TabSpecificContentSettings::MICROPHONE_BLOCKED; | |
| 59 STATIC_CONST_MEMBER_DEFINITION const | |
| 60 TabSpecificContentSettings::MicrophoneCameraState | |
| 61 TabSpecificContentSettings::CAMERA_ACCESSED; | |
| 62 STATIC_CONST_MEMBER_DEFINITION const | |
| 63 TabSpecificContentSettings::MicrophoneCameraState | |
| 64 TabSpecificContentSettings::CAMERA_BLOCKED; | |
| 47 | 65 |
| 48 TabSpecificContentSettings::SiteDataObserver::SiteDataObserver( | 66 TabSpecificContentSettings::SiteDataObserver::SiteDataObserver( |
| 49 TabSpecificContentSettings* tab_specific_content_settings) | 67 TabSpecificContentSettings* tab_specific_content_settings) |
| 50 : tab_specific_content_settings_(tab_specific_content_settings) { | 68 : tab_specific_content_settings_(tab_specific_content_settings) { |
| 51 tab_specific_content_settings_->AddSiteDataObserver(this); | 69 tab_specific_content_settings_->AddSiteDataObserver(this); |
| 52 } | 70 } |
| 53 | 71 |
| 54 TabSpecificContentSettings::SiteDataObserver::~SiteDataObserver() { | 72 TabSpecificContentSettings::SiteDataObserver::~SiteDataObserver() { |
| 55 if (tab_specific_content_settings_) | 73 if (tab_specific_content_settings_) |
| 56 tab_specific_content_settings_->RemoveSiteDataObserver(this); | 74 tab_specific_content_settings_->RemoveSiteDataObserver(this); |
| 57 } | 75 } |
| 58 | 76 |
| 59 void TabSpecificContentSettings::SiteDataObserver::ContentSettingsDestroyed() { | 77 void TabSpecificContentSettings::SiteDataObserver::ContentSettingsDestroyed() { |
| 60 tab_specific_content_settings_ = NULL; | 78 tab_specific_content_settings_ = NULL; |
| 61 } | 79 } |
| 62 | 80 |
| 63 TabSpecificContentSettings::TabSpecificContentSettings(WebContents* tab) | 81 TabSpecificContentSettings::TabSpecificContentSettings(WebContents* tab) |
| 64 : content::WebContentsObserver(tab), | 82 : content::WebContentsObserver(tab), |
| 65 profile_(Profile::FromBrowserContext(tab->GetBrowserContext())), | 83 profile_(Profile::FromBrowserContext(tab->GetBrowserContext())), |
| 66 allowed_local_shared_objects_(profile_), | 84 allowed_local_shared_objects_(profile_), |
| 67 blocked_local_shared_objects_(profile_), | 85 blocked_local_shared_objects_(profile_), |
| 68 geolocation_usages_state_(profile_, CONTENT_SETTINGS_TYPE_GEOLOCATION), | 86 geolocation_usages_state_(profile_, CONTENT_SETTINGS_TYPE_GEOLOCATION), |
| 69 midi_usages_state_(profile_, CONTENT_SETTINGS_TYPE_MIDI_SYSEX), | 87 midi_usages_state_(profile_, CONTENT_SETTINGS_TYPE_MIDI_SYSEX), |
| 70 pending_protocol_handler_(ProtocolHandler::EmptyProtocolHandler()), | 88 pending_protocol_handler_(ProtocolHandler::EmptyProtocolHandler()), |
| 71 previous_protocol_handler_(ProtocolHandler::EmptyProtocolHandler()), | 89 previous_protocol_handler_(ProtocolHandler::EmptyProtocolHandler()), |
| 72 pending_protocol_handler_setting_(CONTENT_SETTING_DEFAULT), | 90 pending_protocol_handler_setting_(CONTENT_SETTING_DEFAULT), |
| 73 load_plugins_link_enabled_(true), | 91 load_plugins_link_enabled_(true), |
| 92 microphone_camera_state_(MICROPHONE_CAMERA_NOT_ACCESSED), | |
| 74 observer_(this) { | 93 observer_(this) { |
| 75 ClearBlockedContentSettingsExceptForCookies(); | 94 ClearBlockedContentSettingsExceptForCookies(); |
| 76 ClearCookieSpecificContentSettings(); | 95 ClearCookieSpecificContentSettings(); |
| 77 | 96 |
| 78 observer_.Add(profile_->GetHostContentSettingsMap()); | 97 observer_.Add(profile_->GetHostContentSettingsMap()); |
| 79 } | 98 } |
| 80 | 99 |
| 81 TabSpecificContentSettings::~TabSpecificContentSettings() { | 100 TabSpecificContentSettings::~TabSpecificContentSettings() { |
| 82 FOR_EACH_OBSERVER( | 101 FOR_EACH_OBSERVER( |
| 83 SiteDataObserver, observer_list_, ContentSettingsDestroyed()); | 102 SiteDataObserver, observer_list_, ContentSettingsDestroyed()); |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 265 content_type != CONTENT_SETTINGS_TYPE_MIDI_SYSEX) { | 284 content_type != CONTENT_SETTINGS_TYPE_MIDI_SYSEX) { |
| 266 return false; | 285 return false; |
| 267 } | 286 } |
| 268 | 287 |
| 269 return content_allowed_[content_type]; | 288 return content_allowed_[content_type]; |
| 270 } | 289 } |
| 271 | 290 |
| 272 void TabSpecificContentSettings::OnContentBlocked(ContentSettingsType type) { | 291 void TabSpecificContentSettings::OnContentBlocked(ContentSettingsType type) { |
| 273 DCHECK(type != CONTENT_SETTINGS_TYPE_GEOLOCATION) | 292 DCHECK(type != CONTENT_SETTINGS_TYPE_GEOLOCATION) |
| 274 << "Geolocation settings handled by OnGeolocationPermissionSet"; | 293 << "Geolocation settings handled by OnGeolocationPermissionSet"; |
| 294 DCHECK(type != CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC && | |
| 295 type != CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA) | |
| 296 << "Media stream settings handled by OnMediaStreamPermissionSet"; | |
| 275 if (type < 0 || type >= CONTENT_SETTINGS_NUM_TYPES) | 297 if (type < 0 || type >= CONTENT_SETTINGS_NUM_TYPES) |
| 276 return; | 298 return; |
| 277 | 299 |
| 278 // Media is different from other content setting types since it allows new | 300 // TODO(robwu): Should this be restricted to cookies only? |
| 279 // setting to kick in without reloading the page, and the UI for media is | 301 // In the past, content_allowed_ was set to false, but this logic was inverted |
| 280 // always reflecting the newest permission setting. | 302 // in https://codereview.chromium.org/13375004 to fix an issue with the cookie |
| 281 switch (type) { | 303 // permission UI. This unconditional assignment seems incorrect, because the |
| 282 case CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC: | 304 // flag will now always be true after calling either OnContentBlocked or |
| 283 case CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA: | 305 // OnContentAllowed. Consequently IsContentAllowed will always return true |
| 284 #if defined(OS_ANDROID) | 306 // for every supported setting that is not handled elsewhere. |
| 285 case CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER: | 307 content_allowed_[type] = true; |
| 286 #endif | |
| 287 content_allowed_[type] = false; | |
| 288 break; | |
| 289 default: | |
| 290 content_allowed_[type] = true; | |
| 291 break; | |
| 292 } | |
| 293 | 308 |
| 294 #if defined(OS_ANDROID) | 309 #if defined(OS_ANDROID) |
| 295 if (type == CONTENT_SETTINGS_TYPE_POPUPS) { | 310 if (type == CONTENT_SETTINGS_TYPE_POPUPS) { |
| 296 // For Android we do not have a persistent button that will always be | 311 // For Android we do not have a persistent button that will always be |
| 297 // visible for blocked popups. Instead we have info bars which could be | 312 // visible for blocked popups. Instead we have info bars which could be |
| 298 // dismissed. Have to clear the blocked state so we properly notify the | 313 // dismissed. Have to clear the blocked state so we properly notify the |
| 299 // relevant pieces again. | 314 // relevant pieces again. |
| 300 content_blocked_[type] = false; | 315 content_blocked_[type] = false; |
| 301 content_blockage_indicated_to_user_[type] = false; | 316 content_blockage_indicated_to_user_[type] = false; |
| 302 } | 317 } |
| 303 #endif | 318 #endif |
| 304 | 319 |
| 305 if (!content_blocked_[type]) { | 320 if (!content_blocked_[type]) { |
| 306 content_blocked_[type] = true; | 321 content_blocked_[type] = true; |
| 307 // TODO: it would be nice to have a way of mocking this in tests. | 322 // TODO: it would be nice to have a way of mocking this in tests. |
| 308 content::NotificationService::current()->Notify( | 323 content::NotificationService::current()->Notify( |
| 309 chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED, | 324 chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED, |
| 310 content::Source<WebContents>(web_contents()), | 325 content::Source<WebContents>(web_contents()), |
| 311 content::NotificationService::NoDetails()); | 326 content::NotificationService::NoDetails()); |
| 312 } | 327 } |
| 313 } | 328 } |
| 314 | 329 |
| 315 void TabSpecificContentSettings::OnContentAllowed(ContentSettingsType type) { | 330 void TabSpecificContentSettings::OnContentAllowed(ContentSettingsType type) { |
| 316 DCHECK(type != CONTENT_SETTINGS_TYPE_GEOLOCATION) | 331 DCHECK(type != CONTENT_SETTINGS_TYPE_GEOLOCATION) |
| 317 << "Geolocation settings handled by OnGeolocationPermissionSet"; | 332 << "Geolocation settings handled by OnGeolocationPermissionSet"; |
| 333 DCHECK(type != CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC && | |
| 334 type != CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA) | |
| 335 << "Media stream settings handled by OnMediaStreamPermissionSet"; | |
| 318 bool access_changed = false; | 336 bool access_changed = false; |
| 319 switch (type) { | 337 switch (type) { |
| 320 case CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC: | |
| 321 case CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA: | |
| 322 #if defined(OS_ANDROID) | 338 #if defined(OS_ANDROID) |
| 323 case CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER: | 339 case CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER: |
| 324 #endif | 340 // content_allowed_[type] is always set to true in OnContentBlocked, so we |
| 325 // The setting for media is overwritten here because media does not need | 341 // have to use content_blocked_ to detect whether the protected media |
| 326 // to reload the page to have the new setting kick in. See issue/175993. | 342 // setting has changed. |
| 327 if (content_blocked_[type]) { | 343 if (content_blocked_[type]) { |
| 328 content_blocked_[type] = false; | 344 content_blocked_[type] = false; |
| 329 access_changed = true; | 345 access_changed = true; |
| 330 } | 346 } |
| 331 break; | 347 break; |
| 348 #endif | |
| 332 default: | 349 default: |
| 333 break; | 350 break; |
| 334 } | 351 } |
| 335 | 352 |
| 336 if (!content_allowed_[type]) { | 353 if (!content_allowed_[type]) { |
| 337 content_allowed_[type] = true; | 354 content_allowed_[type] = true; |
| 338 access_changed = true; | 355 access_changed = true; |
| 339 } | 356 } |
| 340 | 357 |
| 341 if (access_changed) { | 358 if (access_changed) { |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 471 if (allowed) { | 488 if (allowed) { |
| 472 OnContentAllowed(CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER); | 489 OnContentAllowed(CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER); |
| 473 } else { | 490 } else { |
| 474 OnContentBlocked(CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER); | 491 OnContentBlocked(CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER); |
| 475 } | 492 } |
| 476 } | 493 } |
| 477 #endif | 494 #endif |
| 478 | 495 |
| 479 TabSpecificContentSettings::MicrophoneCameraState | 496 TabSpecificContentSettings::MicrophoneCameraState |
| 480 TabSpecificContentSettings::GetMicrophoneCameraState() const { | 497 TabSpecificContentSettings::GetMicrophoneCameraState() const { |
| 481 if (IsContentAllowed(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) && | 498 return microphone_camera_state_; |
| 482 IsContentAllowed(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA)) { | 499 } |
| 483 return MICROPHONE_CAMERA_ACCESSED; | |
| 484 } else if (IsContentAllowed(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC)) { | |
| 485 return MICROPHONE_ACCESSED; | |
| 486 } else if (IsContentAllowed(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA)) { | |
| 487 return CAMERA_ACCESSED; | |
| 488 } | |
| 489 | 500 |
| 490 if (IsContentBlocked(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) && | 501 bool TabSpecificContentSettings::IsMicrophoneCameraStateChanged() const { |
| 491 IsContentBlocked(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA)) { | 502 if ((microphone_camera_state_ & (MICROPHONE_ACCESSED | MICROPHONE_BLOCKED)) ? |
| 492 return MICROPHONE_CAMERA_BLOCKED; | 503 !IsContentBlocked(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) : |
| 493 } else if (IsContentBlocked(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC)) { | 504 !IsContentAllowed(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC)) |
| 494 return MICROPHONE_BLOCKED; | 505 return true; |
| 495 } else if (IsContentBlocked(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA)) { | |
| 496 return CAMERA_BLOCKED; | |
| 497 } | |
| 498 | 506 |
| 499 return MICROPHONE_CAMERA_NOT_ACCESSED; | 507 if ((microphone_camera_state_ & (CAMERA_ACCESSED | CAMERA_BLOCKED)) ? |
| 508 !IsContentBlocked(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA) : | |
| 509 !IsContentAllowed(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA)) | |
| 510 return true; | |
| 511 | |
| 512 PrefService* prefs = | |
| 513 Profile::FromBrowserContext(web_contents()->GetBrowserContext())-> | |
| 514 GetPrefs(); | |
| 515 scoped_refptr<MediaStreamCaptureIndicator> media_indicator = | |
| 516 MediaCaptureDevicesDispatcher::GetInstance()-> | |
| 517 GetMediaStreamCaptureIndicator(); | |
| 518 | |
| 519 if ((microphone_camera_state_ & MICROPHONE_ACCESSED) && | |
| 520 prefs->GetString(prefs::kDefaultAudioCaptureDevice) != | |
| 521 media_stream_selected_audio_device() && | |
| 522 media_indicator->IsCapturingAudio(web_contents())) | |
| 523 return true; | |
| 524 | |
| 525 if ((microphone_camera_state_ & CAMERA_ACCESSED) && | |
| 526 prefs->GetString(prefs::kDefaultVideoCaptureDevice) != | |
| 527 media_stream_selected_video_device() && | |
| 528 media_indicator->IsCapturingVideo(web_contents())) | |
| 529 return true; | |
| 530 | |
| 531 return false; | |
| 500 } | 532 } |
| 501 | 533 |
| 502 void TabSpecificContentSettings::OnMediaStreamPermissionSet( | 534 void TabSpecificContentSettings::OnMediaStreamPermissionSet( |
| 503 const GURL& request_origin, | 535 const GURL& request_origin, |
| 504 const MediaStreamDevicesController::MediaStreamTypeSettingsMap& | 536 const MediaStreamDevicesController::MediaStreamTypeSettingsMap& |
| 505 request_permissions) { | 537 request_permissions) { |
| 506 media_stream_access_origin_ = request_origin; | 538 media_stream_access_origin_ = request_origin; |
| 539 unsigned prev_microphone_camera_state = microphone_camera_state_; | |
|
Bernhard Bauer
2014/09/25 16:18:27
Unsigned what? I thought you had the typedef Micro
robwu
2014/09/25 19:15:53
Done.
| |
| 540 microphone_camera_state_ = MICROPHONE_CAMERA_NOT_ACCESSED; | |
| 507 | 541 |
| 542 PrefService* prefs = | |
| 543 Profile::FromBrowserContext(web_contents()->GetBrowserContext())-> | |
| 544 GetPrefs(); | |
| 508 MediaStreamDevicesController::MediaStreamTypeSettingsMap::const_iterator it = | 545 MediaStreamDevicesController::MediaStreamTypeSettingsMap::const_iterator it = |
| 509 request_permissions.find(content::MEDIA_DEVICE_AUDIO_CAPTURE); | 546 request_permissions.find(content::MEDIA_DEVICE_AUDIO_CAPTURE); |
| 510 if (it != request_permissions.end()) { | 547 if (it != request_permissions.end()) { |
| 511 media_stream_requested_audio_device_ = it->second.requested_device_id; | 548 media_stream_requested_audio_device_ = it->second.requested_device_id; |
| 512 switch (it->second.permission) { | 549 media_stream_selected_audio_device_ = |
| 513 case MediaStreamDevicesController::MEDIA_NONE: | 550 media_stream_requested_audio_device_.empty() ? |
| 514 NOTREACHED(); | 551 prefs->GetString(prefs::kDefaultAudioCaptureDevice) : |
| 515 break; | 552 media_stream_requested_audio_device_; |
| 516 case MediaStreamDevicesController::MEDIA_ALLOWED: | 553 DCHECK_NE(MediaStreamDevicesController::MEDIA_NONE, it->second.permission); |
| 517 OnContentAllowed(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC); | 554 const bool mic_allowed = |
|
Bernhard Bauer
2014/09/25 16:18:27
Nit: We usually don't bother with making purely lo
robwu
2014/09/25 19:15:53
Done.
| |
| 518 break; | 555 it->second.permission == MediaStreamDevicesController::MEDIA_ALLOWED; |
| 519 // TODO(grunell): UI should show for what reason access has been blocked. | 556 content_allowed_[CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC] = mic_allowed; |
| 520 case MediaStreamDevicesController::MEDIA_BLOCKED_BY_POLICY: | 557 content_blocked_[CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC] = !mic_allowed; |
| 521 case MediaStreamDevicesController::MEDIA_BLOCKED_BY_USER_SETTING: | 558 microphone_camera_state_ |= |
| 522 case MediaStreamDevicesController::MEDIA_BLOCKED_BY_USER: | 559 MICROPHONE_ACCESSED | (mic_allowed ? 0 : MICROPHONE_BLOCKED); |
| 523 OnContentBlocked(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC); | |
| 524 break; | |
| 525 } | |
| 526 } | 560 } |
| 527 | 561 |
| 528 it = request_permissions.find(content::MEDIA_DEVICE_VIDEO_CAPTURE); | 562 it = request_permissions.find(content::MEDIA_DEVICE_VIDEO_CAPTURE); |
| 529 if (it != request_permissions.end()) { | 563 if (it != request_permissions.end()) { |
| 530 media_stream_requested_video_device_ = it->second.requested_device_id; | 564 media_stream_requested_video_device_ = it->second.requested_device_id; |
| 531 switch (it->second.permission) { | 565 media_stream_selected_video_device_ = |
| 532 case MediaStreamDevicesController::MEDIA_NONE: | 566 media_stream_requested_video_device_.empty() ? |
| 533 NOTREACHED(); | 567 prefs->GetString(prefs::kDefaultVideoCaptureDevice) : |
| 534 break; | 568 media_stream_requested_video_device_; |
| 535 case MediaStreamDevicesController::MEDIA_ALLOWED: | 569 DCHECK_NE(MediaStreamDevicesController::MEDIA_NONE, it->second.permission); |
| 536 OnContentAllowed(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA); | 570 const bool cam_allowed = |
| 537 break; | 571 it->second.permission == MediaStreamDevicesController::MEDIA_ALLOWED; |
| 538 // TODO(grunell): UI should show for what reason access has been blocked. | 572 content_allowed_[CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA] = cam_allowed; |
| 539 case MediaStreamDevicesController::MEDIA_BLOCKED_BY_POLICY: | 573 content_blocked_[CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA] = !cam_allowed; |
| 540 case MediaStreamDevicesController::MEDIA_BLOCKED_BY_USER_SETTING: | 574 microphone_camera_state_ |= |
| 541 case MediaStreamDevicesController::MEDIA_BLOCKED_BY_USER: | 575 CAMERA_ACCESSED | (cam_allowed ? 0 : CAMERA_BLOCKED); |
| 542 OnContentBlocked(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA); | 576 } |
| 543 break; | 577 |
| 544 } | 578 if (microphone_camera_state_ != prev_microphone_camera_state) { |
| 579 content::NotificationService::current()->Notify( | |
| 580 chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED, | |
| 581 content::Source<WebContents>(web_contents()), | |
| 582 content::NotificationService::NoDetails()); | |
| 545 } | 583 } |
| 546 } | 584 } |
| 547 | 585 |
| 548 void TabSpecificContentSettings::OnMidiSysExAccessed( | 586 void TabSpecificContentSettings::OnMidiSysExAccessed( |
| 549 const GURL& requesting_origin) { | 587 const GURL& requesting_origin) { |
| 550 midi_usages_state_.OnPermissionSet(requesting_origin, true); | 588 midi_usages_state_.OnPermissionSet(requesting_origin, true); |
| 551 OnContentAllowed(CONTENT_SETTINGS_TYPE_MIDI_SYSEX); | 589 OnContentAllowed(CONTENT_SETTINGS_TYPE_MIDI_SYSEX); |
| 552 } | 590 } |
| 553 | 591 |
| 554 void TabSpecificContentSettings::OnMidiSysExAccessBlocked( | 592 void TabSpecificContentSettings::OnMidiSysExAccessBlocked( |
| 555 const GURL& requesting_origin) { | 593 const GURL& requesting_origin) { |
| 556 midi_usages_state_.OnPermissionSet(requesting_origin, false); | 594 midi_usages_state_.OnPermissionSet(requesting_origin, false); |
| 557 OnContentBlocked(CONTENT_SETTINGS_TYPE_MIDI_SYSEX); | 595 OnContentBlocked(CONTENT_SETTINGS_TYPE_MIDI_SYSEX); |
| 558 } | 596 } |
| 559 | 597 |
| 560 void TabSpecificContentSettings::ClearBlockedContentSettingsExceptForCookies() { | 598 void TabSpecificContentSettings::ClearBlockedContentSettingsExceptForCookies() { |
| 561 for (size_t i = 0; i < arraysize(content_blocked_); ++i) { | 599 for (size_t i = 0; i < arraysize(content_blocked_); ++i) { |
| 562 if (i == CONTENT_SETTINGS_TYPE_COOKIES) | 600 if (i == CONTENT_SETTINGS_TYPE_COOKIES) |
| 563 continue; | 601 continue; |
| 564 content_blocked_[i] = false; | 602 content_blocked_[i] = false; |
| 565 content_allowed_[i] = false; | 603 content_allowed_[i] = false; |
| 566 content_blockage_indicated_to_user_[i] = false; | 604 content_blockage_indicated_to_user_[i] = false; |
| 567 } | 605 } |
| 606 microphone_camera_state_ = MICROPHONE_CAMERA_NOT_ACCESSED; | |
| 568 load_plugins_link_enabled_ = true; | 607 load_plugins_link_enabled_ = true; |
| 569 content::NotificationService::current()->Notify( | 608 content::NotificationService::current()->Notify( |
| 570 chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED, | 609 chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED, |
| 571 content::Source<WebContents>(web_contents()), | 610 content::Source<WebContents>(web_contents()), |
| 572 content::NotificationService::NoDetails()); | 611 content::NotificationService::NoDetails()); |
| 573 } | 612 } |
| 574 | 613 |
| 575 void TabSpecificContentSettings::ClearCookieSpecificContentSettings() { | 614 void TabSpecificContentSettings::ClearCookieSpecificContentSettings() { |
| 576 blocked_local_shared_objects_.Reset(); | 615 blocked_local_shared_objects_.Reset(); |
| 577 allowed_local_shared_objects_.Reset(); | 616 allowed_local_shared_objects_.Reset(); |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 700 NavigationEntry* entry = controller.GetVisibleEntry(); | 739 NavigationEntry* entry = controller.GetVisibleEntry(); |
| 701 GURL entry_url; | 740 GURL entry_url; |
| 702 if (entry) | 741 if (entry) |
| 703 entry_url = entry->GetURL(); | 742 entry_url = entry->GetURL(); |
| 704 if (details.update_all() || | 743 if (details.update_all() || |
| 705 // The visible NavigationEntry is the URL in the URL field of a tab. | 744 // The visible NavigationEntry is the URL in the URL field of a tab. |
| 706 // Currently this should be matched by the |primary_pattern|. | 745 // Currently this should be matched by the |primary_pattern|. |
| 707 details.primary_pattern().Matches(entry_url)) { | 746 details.primary_pattern().Matches(entry_url)) { |
| 708 Profile* profile = | 747 Profile* profile = |
| 709 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | 748 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
| 749 const HostContentSettingsMap* map = profile->GetHostContentSettingsMap(); | |
| 750 | |
| 751 if (content_type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC || | |
| 752 content_type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA) { | |
| 753 const GURL media_origin = media_stream_access_origin(); | |
| 754 ContentSetting setting = map->GetContentSetting(media_origin, | |
| 755 media_origin, | |
| 756 content_type, | |
| 757 std::string()); | |
| 758 content_allowed_[content_type] = setting == CONTENT_SETTING_ALLOW; | |
| 759 content_blocked_[content_type] = setting == CONTENT_SETTING_BLOCK; | |
| 760 } | |
| 710 RendererContentSettingRules rules; | 761 RendererContentSettingRules rules; |
| 711 GetRendererContentSettingRules(profile->GetHostContentSettingsMap(), | 762 GetRendererContentSettingRules(map, &rules); |
| 712 &rules); | |
| 713 Send(new ChromeViewMsg_SetContentSettingRules(rules)); | 763 Send(new ChromeViewMsg_SetContentSettingRules(rules)); |
| 714 } | 764 } |
| 715 } | 765 } |
| 716 | 766 |
| 717 void TabSpecificContentSettings::AddSiteDataObserver( | 767 void TabSpecificContentSettings::AddSiteDataObserver( |
| 718 SiteDataObserver* observer) { | 768 SiteDataObserver* observer) { |
| 719 observer_list_.AddObserver(observer); | 769 observer_list_.AddObserver(observer); |
| 720 } | 770 } |
| 721 | 771 |
| 722 void TabSpecificContentSettings::RemoveSiteDataObserver( | 772 void TabSpecificContentSettings::RemoveSiteDataObserver( |
| 723 SiteDataObserver* observer) { | 773 SiteDataObserver* observer) { |
| 724 observer_list_.RemoveObserver(observer); | 774 observer_list_.RemoveObserver(observer); |
| 725 } | 775 } |
| 726 | 776 |
| 727 void TabSpecificContentSettings::NotifySiteDataObservers() { | 777 void TabSpecificContentSettings::NotifySiteDataObservers() { |
| 728 FOR_EACH_OBSERVER(SiteDataObserver, observer_list_, OnSiteDataAccessed()); | 778 FOR_EACH_OBSERVER(SiteDataObserver, observer_list_, OnSiteDataAccessed()); |
| 729 } | 779 } |
| OLD | NEW |