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" |
| 23 #include "chrome/browser/prerender/prerender_manager.h" | 24 #include "chrome/browser/prerender/prerender_manager.h" |
| 24 #include "chrome/browser/profiles/profile.h" | 25 #include "chrome/browser/profiles/profile.h" |
| 25 #include "chrome/common/chrome_switches.h" | 26 #include "chrome/common/chrome_switches.h" |
| 27 #include "chrome/common/pref_names.h" | |
| 26 #include "chrome/common/render_messages.h" | 28 #include "chrome/common/render_messages.h" |
| 27 #include "content/public/browser/browser_thread.h" | 29 #include "content/public/browser/browser_thread.h" |
| 28 #include "content/public/browser/navigation_controller.h" | 30 #include "content/public/browser/navigation_controller.h" |
| 29 #include "content/public/browser/navigation_details.h" | 31 #include "content/public/browser/navigation_details.h" |
| 30 #include "content/public/browser/navigation_entry.h" | 32 #include "content/public/browser/navigation_entry.h" |
| 31 #include "content/public/browser/notification_registrar.h" | 33 #include "content/public/browser/notification_registrar.h" |
| 32 #include "content/public/browser/notification_service.h" | 34 #include "content/public/browser/notification_service.h" |
| 33 #include "content/public/browser/render_frame_host.h" | 35 #include "content/public/browser/render_frame_host.h" |
| 34 #include "content/public/browser/render_view_host.h" | 36 #include "content/public/browser/render_view_host.h" |
| 35 #include "content/public/browser/web_contents.h" | 37 #include "content/public/browser/web_contents.h" |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 64 : content::WebContentsObserver(tab), | 66 : content::WebContentsObserver(tab), |
| 65 profile_(Profile::FromBrowserContext(tab->GetBrowserContext())), | 67 profile_(Profile::FromBrowserContext(tab->GetBrowserContext())), |
| 66 allowed_local_shared_objects_(profile_), | 68 allowed_local_shared_objects_(profile_), |
| 67 blocked_local_shared_objects_(profile_), | 69 blocked_local_shared_objects_(profile_), |
| 68 geolocation_usages_state_(profile_, CONTENT_SETTINGS_TYPE_GEOLOCATION), | 70 geolocation_usages_state_(profile_, CONTENT_SETTINGS_TYPE_GEOLOCATION), |
| 69 midi_usages_state_(profile_, CONTENT_SETTINGS_TYPE_MIDI_SYSEX), | 71 midi_usages_state_(profile_, CONTENT_SETTINGS_TYPE_MIDI_SYSEX), |
| 70 pending_protocol_handler_(ProtocolHandler::EmptyProtocolHandler()), | 72 pending_protocol_handler_(ProtocolHandler::EmptyProtocolHandler()), |
| 71 previous_protocol_handler_(ProtocolHandler::EmptyProtocolHandler()), | 73 previous_protocol_handler_(ProtocolHandler::EmptyProtocolHandler()), |
| 72 pending_protocol_handler_setting_(CONTENT_SETTING_DEFAULT), | 74 pending_protocol_handler_setting_(CONTENT_SETTING_DEFAULT), |
| 73 load_plugins_link_enabled_(true), | 75 load_plugins_link_enabled_(true), |
| 76 microphone_camera_state_(MICROPHONE_CAMERA_NOT_ACCESSED), | |
| 74 observer_(this) { | 77 observer_(this) { |
| 75 ClearBlockedContentSettingsExceptForCookies(); | 78 ClearBlockedContentSettingsExceptForCookies(); |
| 76 ClearCookieSpecificContentSettings(); | 79 ClearCookieSpecificContentSettings(); |
| 77 | 80 |
| 78 observer_.Add(profile_->GetHostContentSettingsMap()); | 81 observer_.Add(profile_->GetHostContentSettingsMap()); |
| 79 } | 82 } |
| 80 | 83 |
| 81 TabSpecificContentSettings::~TabSpecificContentSettings() { | 84 TabSpecificContentSettings::~TabSpecificContentSettings() { |
| 82 FOR_EACH_OBSERVER( | 85 FOR_EACH_OBSERVER( |
| 83 SiteDataObserver, observer_list_, ContentSettingsDestroyed()); | 86 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) { | 268 content_type != CONTENT_SETTINGS_TYPE_MIDI_SYSEX) { |
| 266 return false; | 269 return false; |
| 267 } | 270 } |
| 268 | 271 |
| 269 return content_allowed_[content_type]; | 272 return content_allowed_[content_type]; |
| 270 } | 273 } |
| 271 | 274 |
| 272 void TabSpecificContentSettings::OnContentBlocked(ContentSettingsType type) { | 275 void TabSpecificContentSettings::OnContentBlocked(ContentSettingsType type) { |
| 273 DCHECK(type != CONTENT_SETTINGS_TYPE_GEOLOCATION) | 276 DCHECK(type != CONTENT_SETTINGS_TYPE_GEOLOCATION) |
| 274 << "Geolocation settings handled by OnGeolocationPermissionSet"; | 277 << "Geolocation settings handled by OnGeolocationPermissionSet"; |
| 278 DCHECK(type != CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC && | |
| 279 type != CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA) | |
| 280 << "Media stream settings handled by OnMediaStreamPermissionSet"; | |
| 275 if (type < 0 || type >= CONTENT_SETTINGS_NUM_TYPES) | 281 if (type < 0 || type >= CONTENT_SETTINGS_NUM_TYPES) |
| 276 return; | 282 return; |
| 277 | 283 |
| 278 // Media is different from other content setting types since it allows new | |
| 279 // setting to kick in without reloading the page, and the UI for media is | |
| 280 // always reflecting the newest permission setting. | |
| 281 switch (type) { | 284 switch (type) { |
| 282 case CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC: | |
| 283 case CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA: | |
| 284 #if defined(OS_ANDROID) | 285 #if defined(OS_ANDROID) |
| 286 // Media is different from other content setting types since it allows new | |
| 287 // setting to kick in without reloading the page, and the UI for media is | |
|
Peter Kasting
2014/09/22 23:11:22
Nit: setting -> settings
"the UI for media" is a
robwu
2014/09/24 00:03:04
I have just deleted this comment since it is no lo
Peter Kasting
2014/09/24 01:33:00
OK, but in that case, as a reader I'm still going
robwu
2014/09/24 23:38:44
According to IsContentAllowed, this field is only
| |
| 288 // always reflecting the newest permission setting. | |
|
Peter Kasting
2014/09/22 23:11:22
Nit: is always reflecting -> always reflects
| |
| 285 case CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER: | 289 case CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER: |
| 286 #endif | |
| 287 content_allowed_[type] = false; | 290 content_allowed_[type] = false; |
| 288 break; | 291 break; |
| 292 #endif | |
| 289 default: | 293 default: |
| 290 content_allowed_[type] = true; | 294 content_allowed_[type] = true; |
| 291 break; | 295 break; |
| 292 } | 296 } |
| 293 | 297 |
| 294 #if defined(OS_ANDROID) | 298 #if defined(OS_ANDROID) |
| 295 if (type == CONTENT_SETTINGS_TYPE_POPUPS) { | 299 if (type == CONTENT_SETTINGS_TYPE_POPUPS) { |
| 296 // For Android we do not have a persistent button that will always be | 300 // 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 | 301 // 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 | 302 // dismissed. Have to clear the blocked state so we properly notify the |
| 299 // relevant pieces again. | 303 // relevant pieces again. |
| 300 content_blocked_[type] = false; | 304 content_blocked_[type] = false; |
| 301 content_blockage_indicated_to_user_[type] = false; | 305 content_blockage_indicated_to_user_[type] = false; |
| 302 } | 306 } |
| 303 #endif | 307 #endif |
| 304 | 308 |
| 305 if (!content_blocked_[type]) { | 309 if (!content_blocked_[type]) { |
| 306 content_blocked_[type] = true; | 310 content_blocked_[type] = true; |
| 307 // TODO: it would be nice to have a way of mocking this in tests. | 311 // TODO: it would be nice to have a way of mocking this in tests. |
| 308 content::NotificationService::current()->Notify( | 312 content::NotificationService::current()->Notify( |
| 309 chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED, | 313 chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED, |
| 310 content::Source<WebContents>(web_contents()), | 314 content::Source<WebContents>(web_contents()), |
| 311 content::NotificationService::NoDetails()); | 315 content::NotificationService::NoDetails()); |
| 312 } | 316 } |
| 313 } | 317 } |
| 314 | 318 |
| 315 void TabSpecificContentSettings::OnContentAllowed(ContentSettingsType type) { | 319 void TabSpecificContentSettings::OnContentAllowed(ContentSettingsType type) { |
| 316 DCHECK(type != CONTENT_SETTINGS_TYPE_GEOLOCATION) | 320 DCHECK(type != CONTENT_SETTINGS_TYPE_GEOLOCATION) |
| 317 << "Geolocation settings handled by OnGeolocationPermissionSet"; | 321 << "Geolocation settings handled by OnGeolocationPermissionSet"; |
| 322 DCHECK(type != CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC && | |
| 323 type != CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA) | |
| 324 << "Media stream settings handled by OnMediaStreamPermissionSet"; | |
| 318 bool access_changed = false; | 325 bool access_changed = false; |
| 319 switch (type) { | 326 switch (type) { |
| 320 case CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC: | |
| 321 case CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA: | |
| 322 #if defined(OS_ANDROID) | 327 #if defined(OS_ANDROID) |
| 323 case CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER: | 328 case CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER: |
| 324 #endif | |
| 325 // The setting for media is overwritten here because media does not need | 329 // The setting for media is overwritten here because media does not need |
| 326 // to reload the page to have the new setting kick in. See issue/175993. | 330 // to reload the page to have the new setting kick in. See issue/175993. |
| 327 if (content_blocked_[type]) { | 331 if (content_blocked_[type]) { |
| 328 content_blocked_[type] = false; | 332 content_blocked_[type] = false; |
| 329 access_changed = true; | 333 access_changed = true; |
| 330 } | 334 } |
| 331 break; | 335 break; |
| 336 #endif | |
| 332 default: | 337 default: |
| 333 break; | 338 break; |
| 334 } | 339 } |
| 335 | 340 |
| 336 if (!content_allowed_[type]) { | 341 if (!content_allowed_[type]) { |
| 337 content_allowed_[type] = true; | 342 content_allowed_[type] = true; |
| 338 access_changed = true; | 343 access_changed = true; |
| 339 } | 344 } |
| 340 | 345 |
| 341 if (access_changed) { | 346 if (access_changed) { |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 471 if (allowed) { | 476 if (allowed) { |
| 472 OnContentAllowed(CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER); | 477 OnContentAllowed(CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER); |
| 473 } else { | 478 } else { |
| 474 OnContentBlocked(CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER); | 479 OnContentBlocked(CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER); |
| 475 } | 480 } |
| 476 } | 481 } |
| 477 #endif | 482 #endif |
| 478 | 483 |
| 479 TabSpecificContentSettings::MicrophoneCameraState | 484 TabSpecificContentSettings::MicrophoneCameraState |
| 480 TabSpecificContentSettings::GetMicrophoneCameraState() const { | 485 TabSpecificContentSettings::GetMicrophoneCameraState() const { |
| 481 if (IsContentAllowed(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) && | 486 return microphone_camera_state_; |
| 482 IsContentAllowed(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA)) { | 487 } |
| 483 return MICROPHONE_CAMERA_ACCESSED; | 488 |
| 484 } else if (IsContentAllowed(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC)) { | 489 bool TabSpecificContentSettings::IsMicrophoneCameraStateChanged() const { |
| 485 return MICROPHONE_ACCESSED; | 490 switch (microphone_camera_state_) { |
| 486 } else if (IsContentAllowed(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA)) { | 491 case MICROPHONE_CAMERA_ACCESSED: |
| 487 return CAMERA_ACCESSED; | 492 return !IsContentAllowed(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) || |
| 493 !IsContentAllowed(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA); | |
| 494 case MICROPHONE_ACCESSED: | |
| 495 return !IsContentAllowed(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC); | |
| 496 case CAMERA_ACCESSED: | |
| 497 return !IsContentAllowed(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA); | |
| 498 case MICROPHONE_CAMERA_BLOCKED: | |
| 499 return !IsContentBlocked(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) || | |
| 500 !IsContentBlocked(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA); | |
| 501 case MICROPHONE_BLOCKED: | |
| 502 return !IsContentBlocked(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC); | |
| 503 case CAMERA_BLOCKED: | |
| 504 return !IsContentBlocked(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA); | |
| 505 case MICROPHONE_CAMERA_NOT_ACCESSED: | |
| 506 return false; | |
| 507 default: | |
| 508 NOTREACHED(); | |
| 488 } | 509 } |
| 489 | |
| 490 if (IsContentBlocked(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) && | |
| 491 IsContentBlocked(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA)) { | |
| 492 return MICROPHONE_CAMERA_BLOCKED; | |
| 493 } else if (IsContentBlocked(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC)) { | |
| 494 return MICROPHONE_BLOCKED; | |
| 495 } else if (IsContentBlocked(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA)) { | |
| 496 return CAMERA_BLOCKED; | |
| 497 } | |
| 498 | |
| 499 return MICROPHONE_CAMERA_NOT_ACCESSED; | |
| 500 } | 510 } |
| 501 | 511 |
| 502 void TabSpecificContentSettings::OnMediaStreamPermissionSet( | 512 void TabSpecificContentSettings::OnMediaStreamPermissionSet( |
| 503 const GURL& request_origin, | 513 const GURL& request_origin, |
| 504 const MediaStreamDevicesController::MediaStreamTypeSettingsMap& | 514 const MediaStreamDevicesController::MediaStreamTypeSettingsMap& |
| 505 request_permissions) { | 515 request_permissions) { |
| 506 media_stream_access_origin_ = request_origin; | 516 media_stream_access_origin_ = request_origin; |
| 507 | 517 |
| 518 PrefService* prefs = | |
| 519 Profile::FromBrowserContext(web_contents()->GetBrowserContext())-> | |
| 520 GetPrefs(); | |
| 508 MediaStreamDevicesController::MediaStreamTypeSettingsMap::const_iterator it = | 521 MediaStreamDevicesController::MediaStreamTypeSettingsMap::const_iterator it = |
| 509 request_permissions.find(content::MEDIA_DEVICE_AUDIO_CAPTURE); | 522 request_permissions.find(content::MEDIA_DEVICE_AUDIO_CAPTURE); |
| 510 if (it != request_permissions.end()) { | 523 if (it != request_permissions.end()) { |
| 511 media_stream_requested_audio_device_ = it->second.requested_device_id; | 524 media_stream_requested_audio_device_ = it->second.requested_device_id; |
| 525 media_stream_selected_audio_device_ = | |
| 526 media_stream_requested_audio_device_.empty() ? | |
| 527 prefs->GetString(prefs::kDefaultAudioCaptureDevice) : | |
|
Peter Kasting
2014/09/22 23:11:22
Nit: I'd indent this line and the next 4 more (2
robwu
2014/09/24 00:03:04
Done.
| |
| 528 media_stream_requested_audio_device_; | |
| 512 switch (it->second.permission) { | 529 switch (it->second.permission) { |
|
Peter Kasting
2014/09/22 23:11:23
Nit: Shorter:
DCHECK_NE(MediaStreamDevicesContr
robwu
2014/09/24 00:03:04
Done.
| |
| 513 case MediaStreamDevicesController::MEDIA_NONE: | 530 case MediaStreamDevicesController::MEDIA_NONE: |
| 514 NOTREACHED(); | 531 NOTREACHED(); |
| 515 break; | 532 break; |
| 516 case MediaStreamDevicesController::MEDIA_ALLOWED: | 533 case MediaStreamDevicesController::MEDIA_ALLOWED: |
| 517 OnContentAllowed(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC); | 534 content_allowed_[CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC] = true; |
| 535 content_blocked_[CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC] = false; | |
| 518 break; | 536 break; |
| 519 // TODO(grunell): UI should show for what reason access has been blocked. | 537 // TODO(grunell): UI should show for what reason access has been blocked. |
| 520 case MediaStreamDevicesController::MEDIA_BLOCKED_BY_POLICY: | 538 case MediaStreamDevicesController::MEDIA_BLOCKED_BY_POLICY: |
| 521 case MediaStreamDevicesController::MEDIA_BLOCKED_BY_USER_SETTING: | 539 case MediaStreamDevicesController::MEDIA_BLOCKED_BY_USER_SETTING: |
| 522 case MediaStreamDevicesController::MEDIA_BLOCKED_BY_USER: | 540 case MediaStreamDevicesController::MEDIA_BLOCKED_BY_USER: |
| 523 OnContentBlocked(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC); | 541 content_allowed_[CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC] = false; |
| 542 content_blocked_[CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC] = true; | |
| 524 break; | 543 break; |
| 525 } | 544 } |
| 526 } | 545 } |
| 527 | 546 |
| 528 it = request_permissions.find(content::MEDIA_DEVICE_VIDEO_CAPTURE); | 547 it = request_permissions.find(content::MEDIA_DEVICE_VIDEO_CAPTURE); |
| 529 if (it != request_permissions.end()) { | 548 if (it != request_permissions.end()) { |
| 530 media_stream_requested_video_device_ = it->second.requested_device_id; | 549 media_stream_requested_video_device_ = it->second.requested_device_id; |
| 550 media_stream_selected_video_device_ = | |
| 551 media_stream_requested_video_device_.empty() ? | |
| 552 prefs->GetString(prefs::kDefaultVideoCaptureDevice) : | |
| 553 media_stream_requested_video_device_; | |
| 531 switch (it->second.permission) { | 554 switch (it->second.permission) { |
| 532 case MediaStreamDevicesController::MEDIA_NONE: | 555 case MediaStreamDevicesController::MEDIA_NONE: |
| 533 NOTREACHED(); | 556 NOTREACHED(); |
| 534 break; | 557 break; |
| 535 case MediaStreamDevicesController::MEDIA_ALLOWED: | 558 case MediaStreamDevicesController::MEDIA_ALLOWED: |
| 536 OnContentAllowed(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA); | 559 content_allowed_[CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA] = true; |
| 560 content_blocked_[CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA] = false; | |
| 537 break; | 561 break; |
| 538 // TODO(grunell): UI should show for what reason access has been blocked. | 562 // TODO(grunell): UI should show for what reason access has been blocked. |
| 539 case MediaStreamDevicesController::MEDIA_BLOCKED_BY_POLICY: | 563 case MediaStreamDevicesController::MEDIA_BLOCKED_BY_POLICY: |
| 540 case MediaStreamDevicesController::MEDIA_BLOCKED_BY_USER_SETTING: | 564 case MediaStreamDevicesController::MEDIA_BLOCKED_BY_USER_SETTING: |
| 541 case MediaStreamDevicesController::MEDIA_BLOCKED_BY_USER: | 565 case MediaStreamDevicesController::MEDIA_BLOCKED_BY_USER: |
| 542 OnContentBlocked(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA); | 566 content_allowed_[CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA] = false; |
| 567 content_blocked_[CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA] = true; | |
| 543 break; | 568 break; |
| 544 } | 569 } |
| 545 } | 570 } |
| 571 | |
| 572 MicrophoneCameraState prev_microphone_camera_state = microphone_camera_state_; | |
| 573 if (IsContentAllowed(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) && | |
|
Peter Kasting
2014/09/22 23:11:23
Nit: Slightly shorter and does fewer redundant che
robwu
2014/09/24 00:03:04
Done.
| |
| 574 IsContentAllowed(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA)) { | |
| 575 microphone_camera_state_ = MICROPHONE_CAMERA_ACCESSED; | |
| 576 } else if (IsContentAllowed(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC)) { | |
| 577 microphone_camera_state_ = MICROPHONE_ACCESSED; | |
| 578 } else if (IsContentAllowed(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA)) { | |
| 579 microphone_camera_state_ = CAMERA_ACCESSED; | |
| 580 } else if (IsContentBlocked(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) && | |
| 581 IsContentBlocked(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA)) { | |
| 582 microphone_camera_state_ = MICROPHONE_CAMERA_BLOCKED; | |
| 583 } else if (IsContentBlocked(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC)) { | |
| 584 microphone_camera_state_ = MICROPHONE_BLOCKED; | |
| 585 } else if (IsContentBlocked(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA)) { | |
| 586 microphone_camera_state_ = CAMERA_BLOCKED; | |
| 587 } | |
| 588 | |
| 589 if (microphone_camera_state_ != prev_microphone_camera_state) { | |
| 590 content::NotificationService::current()->Notify( | |
| 591 chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED, | |
| 592 content::Source<WebContents>(web_contents()), | |
| 593 content::NotificationService::NoDetails()); | |
| 594 } | |
| 546 } | 595 } |
| 547 | 596 |
| 548 void TabSpecificContentSettings::OnMidiSysExAccessed( | 597 void TabSpecificContentSettings::OnMidiSysExAccessed( |
| 549 const GURL& requesting_origin) { | 598 const GURL& requesting_origin) { |
| 550 midi_usages_state_.OnPermissionSet(requesting_origin, true); | 599 midi_usages_state_.OnPermissionSet(requesting_origin, true); |
| 551 OnContentAllowed(CONTENT_SETTINGS_TYPE_MIDI_SYSEX); | 600 OnContentAllowed(CONTENT_SETTINGS_TYPE_MIDI_SYSEX); |
| 552 } | 601 } |
| 553 | 602 |
| 554 void TabSpecificContentSettings::OnMidiSysExAccessBlocked( | 603 void TabSpecificContentSettings::OnMidiSysExAccessBlocked( |
| 555 const GURL& requesting_origin) { | 604 const GURL& requesting_origin) { |
| 556 midi_usages_state_.OnPermissionSet(requesting_origin, false); | 605 midi_usages_state_.OnPermissionSet(requesting_origin, false); |
| 557 OnContentBlocked(CONTENT_SETTINGS_TYPE_MIDI_SYSEX); | 606 OnContentBlocked(CONTENT_SETTINGS_TYPE_MIDI_SYSEX); |
| 558 } | 607 } |
| 559 | 608 |
| 560 void TabSpecificContentSettings::ClearBlockedContentSettingsExceptForCookies() { | 609 void TabSpecificContentSettings::ClearBlockedContentSettingsExceptForCookies() { |
| 561 for (size_t i = 0; i < arraysize(content_blocked_); ++i) { | 610 for (size_t i = 0; i < arraysize(content_blocked_); ++i) { |
| 562 if (i == CONTENT_SETTINGS_TYPE_COOKIES) | 611 if (i == CONTENT_SETTINGS_TYPE_COOKIES) |
| 563 continue; | 612 continue; |
| 564 content_blocked_[i] = false; | 613 content_blocked_[i] = false; |
| 565 content_allowed_[i] = false; | 614 content_allowed_[i] = false; |
| 566 content_blockage_indicated_to_user_[i] = false; | 615 content_blockage_indicated_to_user_[i] = false; |
| 567 } | 616 } |
| 617 microphone_camera_state_ = MICROPHONE_CAMERA_NOT_ACCESSED; | |
| 568 load_plugins_link_enabled_ = true; | 618 load_plugins_link_enabled_ = true; |
| 569 content::NotificationService::current()->Notify( | 619 content::NotificationService::current()->Notify( |
| 570 chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED, | 620 chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED, |
| 571 content::Source<WebContents>(web_contents()), | 621 content::Source<WebContents>(web_contents()), |
| 572 content::NotificationService::NoDetails()); | 622 content::NotificationService::NoDetails()); |
| 573 } | 623 } |
| 574 | 624 |
| 575 void TabSpecificContentSettings::ClearCookieSpecificContentSettings() { | 625 void TabSpecificContentSettings::ClearCookieSpecificContentSettings() { |
| 576 blocked_local_shared_objects_.Reset(); | 626 blocked_local_shared_objects_.Reset(); |
| 577 allowed_local_shared_objects_.Reset(); | 627 allowed_local_shared_objects_.Reset(); |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 700 NavigationEntry* entry = controller.GetVisibleEntry(); | 750 NavigationEntry* entry = controller.GetVisibleEntry(); |
| 701 GURL entry_url; | 751 GURL entry_url; |
| 702 if (entry) | 752 if (entry) |
| 703 entry_url = entry->GetURL(); | 753 entry_url = entry->GetURL(); |
| 704 if (details.update_all() || | 754 if (details.update_all() || |
| 705 // The visible NavigationEntry is the URL in the URL field of a tab. | 755 // The visible NavigationEntry is the URL in the URL field of a tab. |
| 706 // Currently this should be matched by the |primary_pattern|. | 756 // Currently this should be matched by the |primary_pattern|. |
| 707 details.primary_pattern().Matches(entry_url)) { | 757 details.primary_pattern().Matches(entry_url)) { |
| 708 Profile* profile = | 758 Profile* profile = |
| 709 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | 759 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
| 760 const HostContentSettingsMap* map = profile->GetHostContentSettingsMap(); | |
| 761 | |
| 762 if (content_type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC || | |
| 763 content_type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA) { | |
| 764 const GURL media_origin = media_stream_access_origin(); | |
| 765 ContentSetting setting = map->GetContentSetting(media_origin, | |
| 766 media_origin, | |
| 767 content_type, | |
| 768 std::string()); | |
| 769 if (setting == CONTENT_SETTING_BLOCK) { | |
|
Peter Kasting
2014/09/22 23:11:22
Nit: Shorter:
content_allowed_[content_type
robwu
2014/09/24 00:03:04
Done.
| |
| 770 content_allowed_[content_type] = false; | |
| 771 content_blocked_[content_type] = true; | |
| 772 } else if (setting == CONTENT_SETTING_ALLOW) { | |
| 773 content_allowed_[content_type] = true; | |
| 774 content_blocked_[content_type] = false; | |
| 775 } else if (setting == CONTENT_SETTING_ASK) { | |
| 776 content_allowed_[content_type] = false; | |
| 777 content_blocked_[content_type] = false; | |
| 778 } else { | |
| 779 NOTREACHED(); | |
| 780 } | |
| 781 } | |
| 710 RendererContentSettingRules rules; | 782 RendererContentSettingRules rules; |
| 711 GetRendererContentSettingRules(profile->GetHostContentSettingsMap(), | 783 GetRendererContentSettingRules(map, &rules); |
| 712 &rules); | |
| 713 Send(new ChromeViewMsg_SetContentSettingRules(rules)); | 784 Send(new ChromeViewMsg_SetContentSettingRules(rules)); |
| 714 } | 785 } |
| 715 } | 786 } |
| 716 | 787 |
| 717 void TabSpecificContentSettings::AddSiteDataObserver( | 788 void TabSpecificContentSettings::AddSiteDataObserver( |
| 718 SiteDataObserver* observer) { | 789 SiteDataObserver* observer) { |
| 719 observer_list_.AddObserver(observer); | 790 observer_list_.AddObserver(observer); |
| 720 } | 791 } |
| 721 | 792 |
| 722 void TabSpecificContentSettings::RemoveSiteDataObserver( | 793 void TabSpecificContentSettings::RemoveSiteDataObserver( |
| 723 SiteDataObserver* observer) { | 794 SiteDataObserver* observer) { |
| 724 observer_list_.RemoveObserver(observer); | 795 observer_list_.RemoveObserver(observer); |
| 725 } | 796 } |
| 726 | 797 |
| 727 void TabSpecificContentSettings::NotifySiteDataObservers() { | 798 void TabSpecificContentSettings::NotifySiteDataObservers() { |
| 728 FOR_EACH_OBSERVER(SiteDataObserver, observer_list_, OnSiteDataAccessed()); | 799 FOR_EACH_OBSERVER(SiteDataObserver, observer_list_, OnSiteDataAccessed()); |
| 729 } | 800 } |
| OLD | NEW |