| 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/webrtc/media_stream_devices_controller.h" | 5 #include "chrome/browser/media/webrtc/media_stream_devices_controller.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 #include "content/public/browser/browser_thread.h" | 34 #include "content/public/browser/browser_thread.h" |
| 35 #include "content/public/browser/render_frame_host.h" | 35 #include "content/public/browser/render_frame_host.h" |
| 36 #include "content/public/browser/render_process_host.h" | 36 #include "content/public/browser/render_process_host.h" |
| 37 #include "content/public/browser/render_widget_host_view.h" | 37 #include "content/public/browser/render_widget_host_view.h" |
| 38 #include "content/public/common/media_stream_request.h" | 38 #include "content/public/common/media_stream_request.h" |
| 39 #include "content/public/common/origin_util.h" | 39 #include "content/public/common/origin_util.h" |
| 40 #include "extensions/common/constants.h" | 40 #include "extensions/common/constants.h" |
| 41 #include "ui/base/l10n/l10n_util.h" | 41 #include "ui/base/l10n/l10n_util.h" |
| 42 #include "ui/gfx/vector_icons_public.h" | 42 #include "ui/gfx/vector_icons_public.h" |
| 43 | 43 |
| 44 #if BUILDFLAG(ANDROID_JAVA_UI) | 44 #if defined(OS_ANDROID) |
| 45 #include <vector> | 45 #include <vector> |
| 46 | 46 |
| 47 #include "chrome/browser/android/preferences/pref_service_bridge.h" | 47 #include "chrome/browser/android/preferences/pref_service_bridge.h" |
| 48 #include "chrome/browser/permissions/permission_update_infobar_delegate_android.
h" | 48 #include "chrome/browser/permissions/permission_update_infobar_delegate_android.
h" |
| 49 #include "chrome/grit/theme_resources.h" | 49 #include "chrome/grit/theme_resources.h" |
| 50 #include "content/public/browser/android/content_view_core.h" | 50 #include "content/public/browser/android/content_view_core.h" |
| 51 #include "ui/android/window_android.h" | 51 #include "ui/android/window_android.h" |
| 52 #endif // BUILDFLAG(ANDROID_JAVA_UI) | 52 #endif // defined(OS_ANDROID) |
| 53 | 53 |
| 54 using content::BrowserThread; | 54 using content::BrowserThread; |
| 55 | 55 |
| 56 namespace { | 56 namespace { |
| 57 | 57 |
| 58 // Returns true if the given ContentSettingsType is being requested in | 58 // Returns true if the given ContentSettingsType is being requested in |
| 59 // |request|. | 59 // |request|. |
| 60 bool ContentTypeIsRequested(content::PermissionType type, | 60 bool ContentTypeIsRequested(content::PermissionType type, |
| 61 const content::MediaStreamRequest& request) { | 61 const content::MediaStreamRequest& request) { |
| 62 if (request.request_type == content::MEDIA_OPEN_DEVICE_PEPPER_ONLY) | 62 if (request.request_type == content::MEDIA_OPEN_DEVICE_PEPPER_ONLY) |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 request_, &denial_reason); | 178 request_, &denial_reason); |
| 179 old_video_setting_ = GetContentSetting( | 179 old_video_setting_ = GetContentSetting( |
| 180 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, request_, &denial_reason); | 180 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, request_, &denial_reason); |
| 181 | 181 |
| 182 // If either setting is ask, we show the infobar. | 182 // If either setting is ask, we show the infobar. |
| 183 if (old_audio_setting_ == CONTENT_SETTING_ASK || | 183 if (old_audio_setting_ == CONTENT_SETTING_ASK || |
| 184 old_video_setting_ == CONTENT_SETTING_ASK) { | 184 old_video_setting_ == CONTENT_SETTING_ASK) { |
| 185 return; | 185 return; |
| 186 } | 186 } |
| 187 | 187 |
| 188 #if BUILDFLAG(ANDROID_JAVA_UI) | 188 #if defined(OS_ANDROID) |
| 189 std::vector<ContentSettingsType> content_settings_types; | 189 std::vector<ContentSettingsType> content_settings_types; |
| 190 if (IsAllowedForAudio()) | 190 if (IsAllowedForAudio()) |
| 191 content_settings_types.push_back(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC); | 191 content_settings_types.push_back(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC); |
| 192 | 192 |
| 193 if (IsAllowedForVideo()) { | 193 if (IsAllowedForVideo()) { |
| 194 content_settings_types.push_back( | 194 content_settings_types.push_back( |
| 195 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA); | 195 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA); |
| 196 } | 196 } |
| 197 | 197 |
| 198 // If the site had been previously granted the access to audio or video but | 198 // If the site had been previously granted the access to audio or video but |
| (...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 595 result = CONTENT_SETTING_ALLOW; | 595 result = CONTENT_SETTING_ALLOW; |
| 596 } else if (user_decision == CONTENT_SETTING_BLOCK) { | 596 } else if (user_decision == CONTENT_SETTING_BLOCK) { |
| 597 result = CONTENT_SETTING_BLOCK; | 597 result = CONTENT_SETTING_BLOCK; |
| 598 } | 598 } |
| 599 } | 599 } |
| 600 return result; | 600 return result; |
| 601 } | 601 } |
| 602 | 602 |
| 603 bool MediaStreamDevicesController::IsUserAcceptAllowed( | 603 bool MediaStreamDevicesController::IsUserAcceptAllowed( |
| 604 ContentSettingsType content_type) const { | 604 ContentSettingsType content_type) const { |
| 605 #if BUILDFLAG(ANDROID_JAVA_UI) | 605 #if defined(OS_ANDROID) |
| 606 content::ContentViewCore* cvc = | 606 content::ContentViewCore* cvc = |
| 607 content::ContentViewCore::FromWebContents(web_contents_); | 607 content::ContentViewCore::FromWebContents(web_contents_); |
| 608 if (!cvc) | 608 if (!cvc) |
| 609 return false; | 609 return false; |
| 610 | 610 |
| 611 ui::WindowAndroid* window_android = cvc->GetWindowAndroid(); | 611 ui::WindowAndroid* window_android = cvc->GetWindowAndroid(); |
| 612 if (!window_android) | 612 if (!window_android) |
| 613 return false; | 613 return false; |
| 614 | 614 |
| 615 std::string android_permission = | 615 std::string android_permission = |
| 616 PrefServiceBridge::GetAndroidPermissionForContentSetting(content_type); | 616 PrefServiceBridge::GetAndroidPermissionForContentSetting(content_type); |
| 617 bool android_permission_blocked = false; | 617 bool android_permission_blocked = false; |
| 618 if (!android_permission.empty()) { | 618 if (!android_permission.empty()) { |
| 619 android_permission_blocked = | 619 android_permission_blocked = |
| 620 !window_android->HasPermission(android_permission) && | 620 !window_android->HasPermission(android_permission) && |
| 621 !window_android->CanRequestPermission(android_permission); | 621 !window_android->CanRequestPermission(android_permission); |
| 622 } | 622 } |
| 623 if (android_permission_blocked) | 623 if (android_permission_blocked) |
| 624 return false; | 624 return false; |
| 625 | 625 |
| 626 // Don't approve device requests if the tab was hidden. | 626 // Don't approve device requests if the tab was hidden. |
| 627 // TODO(qinmin): Add a test for this. http://crbug.com/396869. | 627 // TODO(qinmin): Add a test for this. http://crbug.com/396869. |
| 628 // TODO(raymes): Shouldn't this apply to all permissions not just audio/video? | 628 // TODO(raymes): Shouldn't this apply to all permissions not just audio/video? |
| 629 return web_contents_->GetRenderWidgetHostView()->IsShowing(); | 629 return web_contents_->GetRenderWidgetHostView()->IsShowing(); |
| 630 #endif | 630 #endif |
| 631 return true; | 631 return true; |
| 632 } | 632 } |
| OLD | NEW |