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) { | |
320 case CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC: | |
321 case CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA: | |
322 #if defined(OS_ANDROID) | 337 #if defined(OS_ANDROID) |
323 case CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER: | 338 if (type == CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER && |
| 339 content_blocked_[type]) { |
| 340 // content_allowed_[type] is always set to true in OnContentBlocked, so we |
| 341 // have to use content_blocked_ to detect whether the protected media |
| 342 // setting has changed. |
| 343 content_blocked_[type] = false; |
| 344 access_changed = true; |
| 345 } |
324 #endif | 346 #endif |
325 // 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. | |
327 if (content_blocked_[type]) { | |
328 content_blocked_[type] = false; | |
329 access_changed = true; | |
330 } | |
331 break; | |
332 default: | |
333 break; | |
334 } | |
335 | 347 |
336 if (!content_allowed_[type]) { | 348 if (!content_allowed_[type]) { |
337 content_allowed_[type] = true; | 349 content_allowed_[type] = true; |
338 access_changed = true; | 350 access_changed = true; |
339 } | 351 } |
340 | 352 |
341 if (access_changed) { | 353 if (access_changed) { |
342 content::NotificationService::current()->Notify( | 354 content::NotificationService::current()->Notify( |
343 chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED, | 355 chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED, |
344 content::Source<WebContents>(web_contents()), | 356 content::Source<WebContents>(web_contents()), |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
471 if (allowed) { | 483 if (allowed) { |
472 OnContentAllowed(CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER); | 484 OnContentAllowed(CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER); |
473 } else { | 485 } else { |
474 OnContentBlocked(CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER); | 486 OnContentBlocked(CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER); |
475 } | 487 } |
476 } | 488 } |
477 #endif | 489 #endif |
478 | 490 |
479 TabSpecificContentSettings::MicrophoneCameraState | 491 TabSpecificContentSettings::MicrophoneCameraState |
480 TabSpecificContentSettings::GetMicrophoneCameraState() const { | 492 TabSpecificContentSettings::GetMicrophoneCameraState() const { |
481 if (IsContentAllowed(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) && | 493 return microphone_camera_state_; |
482 IsContentAllowed(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA)) { | 494 } |
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 | 495 |
490 if (IsContentBlocked(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) && | 496 bool TabSpecificContentSettings::IsMicrophoneCameraStateChanged() const { |
491 IsContentBlocked(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA)) { | 497 if ((microphone_camera_state_ & MICROPHONE_ACCESSED) && |
492 return MICROPHONE_CAMERA_BLOCKED; | 498 ((microphone_camera_state_& MICROPHONE_BLOCKED) ? |
493 } else if (IsContentBlocked(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC)) { | 499 !IsContentBlocked(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) : |
494 return MICROPHONE_BLOCKED; | 500 !IsContentAllowed(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC))) |
495 } else if (IsContentBlocked(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA)) { | 501 return true; |
496 return CAMERA_BLOCKED; | |
497 } | |
498 | 502 |
499 return MICROPHONE_CAMERA_NOT_ACCESSED; | 503 if ((microphone_camera_state_ & CAMERA_ACCESSED) && |
| 504 ((microphone_camera_state_ & CAMERA_BLOCKED) ? |
| 505 !IsContentBlocked(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA) : |
| 506 !IsContentAllowed(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA))) |
| 507 return true; |
| 508 |
| 509 PrefService* prefs = |
| 510 Profile::FromBrowserContext(web_contents()->GetBrowserContext())-> |
| 511 GetPrefs(); |
| 512 scoped_refptr<MediaStreamCaptureIndicator> media_indicator = |
| 513 MediaCaptureDevicesDispatcher::GetInstance()-> |
| 514 GetMediaStreamCaptureIndicator(); |
| 515 |
| 516 if ((microphone_camera_state_ & MICROPHONE_ACCESSED) && |
| 517 prefs->GetString(prefs::kDefaultAudioCaptureDevice) != |
| 518 media_stream_selected_audio_device() && |
| 519 media_indicator->IsCapturingAudio(web_contents())) |
| 520 return true; |
| 521 |
| 522 if ((microphone_camera_state_ & CAMERA_ACCESSED) && |
| 523 prefs->GetString(prefs::kDefaultVideoCaptureDevice) != |
| 524 media_stream_selected_video_device() && |
| 525 media_indicator->IsCapturingVideo(web_contents())) |
| 526 return true; |
| 527 |
| 528 return false; |
500 } | 529 } |
501 | 530 |
502 void TabSpecificContentSettings::OnMediaStreamPermissionSet( | 531 void TabSpecificContentSettings::OnMediaStreamPermissionSet( |
503 const GURL& request_origin, | 532 const GURL& request_origin, |
504 const MediaStreamDevicesController::MediaStreamTypeSettingsMap& | 533 const MediaStreamDevicesController::MediaStreamTypeSettingsMap& |
505 request_permissions) { | 534 request_permissions) { |
506 media_stream_access_origin_ = request_origin; | 535 media_stream_access_origin_ = request_origin; |
| 536 MicrophoneCameraState prev_microphone_camera_state = microphone_camera_state_; |
| 537 microphone_camera_state_ = MICROPHONE_CAMERA_NOT_ACCESSED; |
507 | 538 |
| 539 PrefService* prefs = |
| 540 Profile::FromBrowserContext(web_contents()->GetBrowserContext())-> |
| 541 GetPrefs(); |
508 MediaStreamDevicesController::MediaStreamTypeSettingsMap::const_iterator it = | 542 MediaStreamDevicesController::MediaStreamTypeSettingsMap::const_iterator it = |
509 request_permissions.find(content::MEDIA_DEVICE_AUDIO_CAPTURE); | 543 request_permissions.find(content::MEDIA_DEVICE_AUDIO_CAPTURE); |
510 if (it != request_permissions.end()) { | 544 if (it != request_permissions.end()) { |
511 media_stream_requested_audio_device_ = it->second.requested_device_id; | 545 media_stream_requested_audio_device_ = it->second.requested_device_id; |
512 switch (it->second.permission) { | 546 media_stream_selected_audio_device_ = |
513 case MediaStreamDevicesController::MEDIA_NONE: | 547 media_stream_requested_audio_device_.empty() ? |
514 NOTREACHED(); | 548 prefs->GetString(prefs::kDefaultAudioCaptureDevice) : |
515 break; | 549 media_stream_requested_audio_device_; |
516 case MediaStreamDevicesController::MEDIA_ALLOWED: | 550 DCHECK_NE(MediaStreamDevicesController::MEDIA_NONE, it->second.permission); |
517 OnContentAllowed(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC); | 551 bool mic_allowed = |
518 break; | 552 it->second.permission == MediaStreamDevicesController::MEDIA_ALLOWED; |
519 // TODO(grunell): UI should show for what reason access has been blocked. | 553 content_allowed_[CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC] = mic_allowed; |
520 case MediaStreamDevicesController::MEDIA_BLOCKED_BY_POLICY: | 554 content_blocked_[CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC] = !mic_allowed; |
521 case MediaStreamDevicesController::MEDIA_BLOCKED_BY_USER_SETTING: | 555 microphone_camera_state_ |= |
522 case MediaStreamDevicesController::MEDIA_BLOCKED_BY_USER: | 556 MICROPHONE_ACCESSED | (mic_allowed ? 0 : MICROPHONE_BLOCKED); |
523 OnContentBlocked(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC); | |
524 break; | |
525 } | |
526 } | 557 } |
527 | 558 |
528 it = request_permissions.find(content::MEDIA_DEVICE_VIDEO_CAPTURE); | 559 it = request_permissions.find(content::MEDIA_DEVICE_VIDEO_CAPTURE); |
529 if (it != request_permissions.end()) { | 560 if (it != request_permissions.end()) { |
530 media_stream_requested_video_device_ = it->second.requested_device_id; | 561 media_stream_requested_video_device_ = it->second.requested_device_id; |
531 switch (it->second.permission) { | 562 media_stream_selected_video_device_ = |
532 case MediaStreamDevicesController::MEDIA_NONE: | 563 media_stream_requested_video_device_.empty() ? |
533 NOTREACHED(); | 564 prefs->GetString(prefs::kDefaultVideoCaptureDevice) : |
534 break; | 565 media_stream_requested_video_device_; |
535 case MediaStreamDevicesController::MEDIA_ALLOWED: | 566 DCHECK_NE(MediaStreamDevicesController::MEDIA_NONE, it->second.permission); |
536 OnContentAllowed(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA); | 567 bool cam_allowed = |
537 break; | 568 it->second.permission == MediaStreamDevicesController::MEDIA_ALLOWED; |
538 // TODO(grunell): UI should show for what reason access has been blocked. | 569 content_allowed_[CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA] = cam_allowed; |
539 case MediaStreamDevicesController::MEDIA_BLOCKED_BY_POLICY: | 570 content_blocked_[CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA] = !cam_allowed; |
540 case MediaStreamDevicesController::MEDIA_BLOCKED_BY_USER_SETTING: | 571 microphone_camera_state_ |= |
541 case MediaStreamDevicesController::MEDIA_BLOCKED_BY_USER: | 572 CAMERA_ACCESSED | (cam_allowed ? 0 : CAMERA_BLOCKED); |
542 OnContentBlocked(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA); | 573 } |
543 break; | 574 |
544 } | 575 if (microphone_camera_state_ != prev_microphone_camera_state) { |
| 576 content::NotificationService::current()->Notify( |
| 577 chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED, |
| 578 content::Source<WebContents>(web_contents()), |
| 579 content::NotificationService::NoDetails()); |
545 } | 580 } |
546 } | 581 } |
547 | 582 |
548 void TabSpecificContentSettings::OnMidiSysExAccessed( | 583 void TabSpecificContentSettings::OnMidiSysExAccessed( |
549 const GURL& requesting_origin) { | 584 const GURL& requesting_origin) { |
550 midi_usages_state_.OnPermissionSet(requesting_origin, true); | 585 midi_usages_state_.OnPermissionSet(requesting_origin, true); |
551 OnContentAllowed(CONTENT_SETTINGS_TYPE_MIDI_SYSEX); | 586 OnContentAllowed(CONTENT_SETTINGS_TYPE_MIDI_SYSEX); |
552 } | 587 } |
553 | 588 |
554 void TabSpecificContentSettings::OnMidiSysExAccessBlocked( | 589 void TabSpecificContentSettings::OnMidiSysExAccessBlocked( |
555 const GURL& requesting_origin) { | 590 const GURL& requesting_origin) { |
556 midi_usages_state_.OnPermissionSet(requesting_origin, false); | 591 midi_usages_state_.OnPermissionSet(requesting_origin, false); |
557 OnContentBlocked(CONTENT_SETTINGS_TYPE_MIDI_SYSEX); | 592 OnContentBlocked(CONTENT_SETTINGS_TYPE_MIDI_SYSEX); |
558 } | 593 } |
559 | 594 |
560 void TabSpecificContentSettings::ClearBlockedContentSettingsExceptForCookies() { | 595 void TabSpecificContentSettings::ClearBlockedContentSettingsExceptForCookies() { |
561 for (size_t i = 0; i < arraysize(content_blocked_); ++i) { | 596 for (size_t i = 0; i < arraysize(content_blocked_); ++i) { |
562 if (i == CONTENT_SETTINGS_TYPE_COOKIES) | 597 if (i == CONTENT_SETTINGS_TYPE_COOKIES) |
563 continue; | 598 continue; |
564 content_blocked_[i] = false; | 599 content_blocked_[i] = false; |
565 content_allowed_[i] = false; | 600 content_allowed_[i] = false; |
566 content_blockage_indicated_to_user_[i] = false; | 601 content_blockage_indicated_to_user_[i] = false; |
567 } | 602 } |
| 603 microphone_camera_state_ = MICROPHONE_CAMERA_NOT_ACCESSED; |
568 load_plugins_link_enabled_ = true; | 604 load_plugins_link_enabled_ = true; |
569 content::NotificationService::current()->Notify( | 605 content::NotificationService::current()->Notify( |
570 chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED, | 606 chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED, |
571 content::Source<WebContents>(web_contents()), | 607 content::Source<WebContents>(web_contents()), |
572 content::NotificationService::NoDetails()); | 608 content::NotificationService::NoDetails()); |
573 } | 609 } |
574 | 610 |
575 void TabSpecificContentSettings::ClearCookieSpecificContentSettings() { | 611 void TabSpecificContentSettings::ClearCookieSpecificContentSettings() { |
576 blocked_local_shared_objects_.Reset(); | 612 blocked_local_shared_objects_.Reset(); |
577 allowed_local_shared_objects_.Reset(); | 613 allowed_local_shared_objects_.Reset(); |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
700 NavigationEntry* entry = controller.GetVisibleEntry(); | 736 NavigationEntry* entry = controller.GetVisibleEntry(); |
701 GURL entry_url; | 737 GURL entry_url; |
702 if (entry) | 738 if (entry) |
703 entry_url = entry->GetURL(); | 739 entry_url = entry->GetURL(); |
704 if (details.update_all() || | 740 if (details.update_all() || |
705 // The visible NavigationEntry is the URL in the URL field of a tab. | 741 // The visible NavigationEntry is the URL in the URL field of a tab. |
706 // Currently this should be matched by the |primary_pattern|. | 742 // Currently this should be matched by the |primary_pattern|. |
707 details.primary_pattern().Matches(entry_url)) { | 743 details.primary_pattern().Matches(entry_url)) { |
708 Profile* profile = | 744 Profile* profile = |
709 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | 745 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
| 746 const HostContentSettingsMap* map = profile->GetHostContentSettingsMap(); |
| 747 |
| 748 if (content_type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC || |
| 749 content_type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA) { |
| 750 const GURL media_origin = media_stream_access_origin(); |
| 751 ContentSetting setting = map->GetContentSetting(media_origin, |
| 752 media_origin, |
| 753 content_type, |
| 754 std::string()); |
| 755 content_allowed_[content_type] = setting == CONTENT_SETTING_ALLOW; |
| 756 content_blocked_[content_type] = setting == CONTENT_SETTING_BLOCK; |
| 757 } |
710 RendererContentSettingRules rules; | 758 RendererContentSettingRules rules; |
711 GetRendererContentSettingRules(profile->GetHostContentSettingsMap(), | 759 GetRendererContentSettingRules(map, &rules); |
712 &rules); | |
713 Send(new ChromeViewMsg_SetContentSettingRules(rules)); | 760 Send(new ChromeViewMsg_SetContentSettingRules(rules)); |
714 } | 761 } |
715 } | 762 } |
716 | 763 |
717 void TabSpecificContentSettings::AddSiteDataObserver( | 764 void TabSpecificContentSettings::AddSiteDataObserver( |
718 SiteDataObserver* observer) { | 765 SiteDataObserver* observer) { |
719 observer_list_.AddObserver(observer); | 766 observer_list_.AddObserver(observer); |
720 } | 767 } |
721 | 768 |
722 void TabSpecificContentSettings::RemoveSiteDataObserver( | 769 void TabSpecificContentSettings::RemoveSiteDataObserver( |
723 SiteDataObserver* observer) { | 770 SiteDataObserver* observer) { |
724 observer_list_.RemoveObserver(observer); | 771 observer_list_.RemoveObserver(observer); |
725 } | 772 } |
726 | 773 |
727 void TabSpecificContentSettings::NotifySiteDataObservers() { | 774 void TabSpecificContentSettings::NotifySiteDataObservers() { |
728 FOR_EACH_OBSERVER(SiteDataObserver, observer_list_, OnSiteDataAccessed()); | 775 FOR_EACH_OBSERVER(SiteDataObserver, observer_list_, OnSiteDataAccessed()); |
729 } | 776 } |
OLD | NEW |