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/media/media_stream_devices_controller.h" | 5 #include "chrome/browser/media/media_stream_devices_controller.h" |
6 | 6 |
7 #include "base/metrics/histogram.h" | 7 #include "base/metrics/histogram.h" |
8 #include "base/prefs/scoped_user_pref_update.h" | 8 #include "base/prefs/scoped_user_pref_update.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
11 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | 11 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
12 #include "chrome/browser/media/media_capture_devices_dispatcher.h" | 12 #include "chrome/browser/media/media_capture_devices_dispatcher.h" |
13 #include "chrome/browser/media/media_permission.h" | 13 #include "chrome/browser/media/media_permission.h" |
14 #include "chrome/browser/media/media_stream_capture_indicator.h" | 14 #include "chrome/browser/media/media_stream_capture_indicator.h" |
15 #include "chrome/browser/media/media_stream_device_permissions.h" | 15 #include "chrome/browser/media/media_stream_device_permissions.h" |
16 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
17 #include "chrome/browser/ui/browser.h" | 17 #include "chrome/browser/ui/browser.h" |
18 #include "chrome/common/chrome_switches.h" | 18 #include "chrome/common/chrome_switches.h" |
19 #include "chrome/common/pref_names.h" | 19 #include "chrome/common/pref_names.h" |
20 #include "chrome/grit/generated_resources.h" | 20 #include "chrome/grit/generated_resources.h" |
21 #include "components/content_settings/core/browser/host_content_settings_map.h" | 21 #include "components/content_settings/core/browser/host_content_settings_map.h" |
22 #include "components/content_settings/core/common/content_settings_pattern.h" | 22 #include "components/content_settings/core/common/content_settings_pattern.h" |
23 #include "components/pref_registry/pref_registry_syncable.h" | 23 #include "components/pref_registry/pref_registry_syncable.h" |
24 #include "content/public/browser/browser_thread.h" | 24 #include "content/public/browser/browser_thread.h" |
25 #include "content/public/browser/render_widget_host_view.h" | 25 #include "content/public/browser/render_widget_host_view.h" |
26 #include "content/public/common/media_stream_request.h" | 26 #include "content/public/common/media_stream_request.h" |
27 #include "grit/theme_resources.h" | 27 #include "grit/theme_resources.h" |
28 #include "ui/base/l10n/l10n_util.h" | 28 #include "ui/base/l10n/l10n_util.h" |
29 | 29 |
30 #if defined(OS_ANDROID) | 30 #if defined(OS_ANDROID) && !defined(USE_AURA) |
31 #include "chrome/browser/android/preferences/pref_service_bridge.h" | 31 #include "chrome/browser/android/preferences/pref_service_bridge.h" |
32 #include "content/public/browser/android/content_view_core.h" | 32 #include "content/public/browser/android/content_view_core.h" |
33 #include "ui/android/window_android.h" | 33 #include "ui/android/window_android.h" |
34 #endif // OS_ANDROID | 34 #endif // OS_ANDROID |
35 | 35 |
36 using content::BrowserThread; | 36 using content::BrowserThread; |
37 | 37 |
38 namespace { | 38 namespace { |
39 | 39 |
40 enum DevicePermissionActions { | 40 enum DevicePermissionActions { |
(...skipping 404 matching lines...) Loading... |
445 result = CONTENT_SETTING_ALLOW; | 445 result = CONTENT_SETTING_ALLOW; |
446 } else if (user_decision == CONTENT_SETTING_BLOCK) { | 446 } else if (user_decision == CONTENT_SETTING_BLOCK) { |
447 result = CONTENT_SETTING_BLOCK; | 447 result = CONTENT_SETTING_BLOCK; |
448 } | 448 } |
449 } | 449 } |
450 return result; | 450 return result; |
451 } | 451 } |
452 | 452 |
453 bool MediaStreamDevicesController::IsUserAcceptAllowed( | 453 bool MediaStreamDevicesController::IsUserAcceptAllowed( |
454 ContentSettingsType content_type) const { | 454 ContentSettingsType content_type) const { |
455 #if defined(OS_ANDROID) | 455 #if defined(OS_ANDROID) && !defined(USE_AURA) |
456 content::ContentViewCore* cvc = | 456 content::ContentViewCore* cvc = |
457 content::ContentViewCore::FromWebContents(web_contents_); | 457 content::ContentViewCore::FromWebContents(web_contents_); |
458 if (!cvc) | 458 if (!cvc) |
459 return false; | 459 return false; |
460 | 460 |
461 ui::WindowAndroid* window_android = cvc->GetWindowAndroid(); | 461 ui::WindowAndroid* window_android = cvc->GetWindowAndroid(); |
462 if (!window_android) | 462 if (!window_android) |
463 return false; | 463 return false; |
464 | 464 |
465 std::string android_permission = | 465 std::string android_permission = |
466 PrefServiceBridge::GetAndroidPermissionForContentSetting(content_type); | 466 PrefServiceBridge::GetAndroidPermissionForContentSetting(content_type); |
467 bool android_permission_blocked = false; | 467 bool android_permission_blocked = false; |
468 if (!android_permission.empty()) { | 468 if (!android_permission.empty()) { |
469 android_permission_blocked = | 469 android_permission_blocked = |
470 !window_android->HasPermission(android_permission) && | 470 !window_android->HasPermission(android_permission) && |
471 !window_android->CanRequestPermission(android_permission); | 471 !window_android->CanRequestPermission(android_permission); |
472 } | 472 } |
473 if (android_permission_blocked) | 473 if (android_permission_blocked) |
474 return false; | 474 return false; |
475 | 475 |
476 // Don't approve device requests if the tab was hidden. | 476 // Don't approve device requests if the tab was hidden. |
477 // TODO(qinmin): Add a test for this. http://crbug.com/396869. | 477 // TODO(qinmin): Add a test for this. http://crbug.com/396869. |
478 // TODO(raymes): Shouldn't this apply to all permissions not just audio/video? | 478 // TODO(raymes): Shouldn't this apply to all permissions not just audio/video? |
479 return web_contents_->GetRenderWidgetHostView()->IsShowing(); | 479 return web_contents_->GetRenderWidgetHostView()->IsShowing(); |
480 #endif | 480 #endif |
481 return true; | 481 return true; |
482 } | 482 } |
OLD | NEW |