| 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 <map> | 7 #include <map> |
| 8 | 8 |
| 9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
| 10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 #include "content/public/browser/browser_thread.h" | 30 #include "content/public/browser/browser_thread.h" |
| 31 #include "content/public/browser/render_frame_host.h" | 31 #include "content/public/browser/render_frame_host.h" |
| 32 #include "content/public/browser/render_process_host.h" | 32 #include "content/public/browser/render_process_host.h" |
| 33 #include "content/public/browser/render_widget_host_view.h" | 33 #include "content/public/browser/render_widget_host_view.h" |
| 34 #include "content/public/common/media_stream_request.h" | 34 #include "content/public/common/media_stream_request.h" |
| 35 #include "content/public/common/origin_util.h" | 35 #include "content/public/common/origin_util.h" |
| 36 #include "extensions/common/constants.h" | 36 #include "extensions/common/constants.h" |
| 37 #include "grit/theme_resources.h" | 37 #include "grit/theme_resources.h" |
| 38 #include "ui/base/l10n/l10n_util.h" | 38 #include "ui/base/l10n/l10n_util.h" |
| 39 | 39 |
| 40 #if defined(OS_ANDROID) | 40 #if defined(ANDROID_JAVA_UI) |
| 41 #include <vector> | 41 #include <vector> |
| 42 | 42 |
| 43 #include "chrome/browser/android/preferences/pref_service_bridge.h" | 43 #include "chrome/browser/android/preferences/pref_service_bridge.h" |
| 44 #include "chrome/browser/permissions/permission_update_infobar_delegate_android.
h" | 44 #include "chrome/browser/permissions/permission_update_infobar_delegate_android.
h" |
| 45 #include "content/public/browser/android/content_view_core.h" | 45 #include "content/public/browser/android/content_view_core.h" |
| 46 #include "ui/android/window_android.h" | 46 #include "ui/android/window_android.h" |
| 47 #endif // OS_ANDROID | 47 #endif // ANDROID_JAVA_UI |
| 48 | 48 |
| 49 using content::BrowserThread; | 49 using content::BrowserThread; |
| 50 | 50 |
| 51 namespace { | 51 namespace { |
| 52 | 52 |
| 53 // Returns true if the given ContentSettingsType is being requested in | 53 // Returns true if the given ContentSettingsType is being requested in |
| 54 // |request|. | 54 // |request|. |
| 55 bool ContentTypeIsRequested(ContentSettingsType type, | 55 bool ContentTypeIsRequested(ContentSettingsType type, |
| 56 const content::MediaStreamRequest& request) { | 56 const content::MediaStreamRequest& request) { |
| 57 if (request.request_type == content::MEDIA_OPEN_DEVICE_PEPPER_ONLY) | 57 if (request.request_type == content::MEDIA_OPEN_DEVICE_PEPPER_ONLY) |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 request_, &denial_reason); | 163 request_, &denial_reason); |
| 164 old_video_setting_ = GetContentSetting( | 164 old_video_setting_ = GetContentSetting( |
| 165 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, request_, &denial_reason); | 165 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, request_, &denial_reason); |
| 166 | 166 |
| 167 // If either setting is ask, we show the infobar. | 167 // If either setting is ask, we show the infobar. |
| 168 if (old_audio_setting_ == CONTENT_SETTING_ASK || | 168 if (old_audio_setting_ == CONTENT_SETTING_ASK || |
| 169 old_video_setting_ == CONTENT_SETTING_ASK) { | 169 old_video_setting_ == CONTENT_SETTING_ASK) { |
| 170 return; | 170 return; |
| 171 } | 171 } |
| 172 | 172 |
| 173 #if defined(OS_ANDROID) | 173 #if defined(ANDROID_JAVA_UI) |
| 174 std::vector<ContentSettingsType> content_settings_types; | 174 std::vector<ContentSettingsType> content_settings_types; |
| 175 if (IsAllowedForAudio()) | 175 if (IsAllowedForAudio()) |
| 176 content_settings_types.push_back(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC); | 176 content_settings_types.push_back(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC); |
| 177 | 177 |
| 178 if (IsAllowedForVideo()) { | 178 if (IsAllowedForVideo()) { |
| 179 content_settings_types.push_back( | 179 content_settings_types.push_back( |
| 180 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA); | 180 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA); |
| 181 } | 181 } |
| 182 | 182 |
| 183 // If the site had been previously granted the access to audio or video but | 183 // If the site had been previously granted the access to audio or video but |
| (...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 577 result = CONTENT_SETTING_ALLOW; | 577 result = CONTENT_SETTING_ALLOW; |
| 578 } else if (user_decision == CONTENT_SETTING_BLOCK) { | 578 } else if (user_decision == CONTENT_SETTING_BLOCK) { |
| 579 result = CONTENT_SETTING_BLOCK; | 579 result = CONTENT_SETTING_BLOCK; |
| 580 } | 580 } |
| 581 } | 581 } |
| 582 return result; | 582 return result; |
| 583 } | 583 } |
| 584 | 584 |
| 585 bool MediaStreamDevicesController::IsUserAcceptAllowed( | 585 bool MediaStreamDevicesController::IsUserAcceptAllowed( |
| 586 ContentSettingsType content_type) const { | 586 ContentSettingsType content_type) const { |
| 587 #if defined(OS_ANDROID) | 587 #if defined(ANDROID_JAVA_UI) |
| 588 content::ContentViewCore* cvc = | 588 content::ContentViewCore* cvc = |
| 589 content::ContentViewCore::FromWebContents(web_contents_); | 589 content::ContentViewCore::FromWebContents(web_contents_); |
| 590 if (!cvc) | 590 if (!cvc) |
| 591 return false; | 591 return false; |
| 592 | 592 |
| 593 ui::WindowAndroid* window_android = cvc->GetWindowAndroid(); | 593 ui::WindowAndroid* window_android = cvc->GetWindowAndroid(); |
| 594 if (!window_android) | 594 if (!window_android) |
| 595 return false; | 595 return false; |
| 596 | 596 |
| 597 std::string android_permission = | 597 std::string android_permission = |
| 598 PrefServiceBridge::GetAndroidPermissionForContentSetting(content_type); | 598 PrefServiceBridge::GetAndroidPermissionForContentSetting(content_type); |
| 599 bool android_permission_blocked = false; | 599 bool android_permission_blocked = false; |
| 600 if (!android_permission.empty()) { | 600 if (!android_permission.empty()) { |
| 601 android_permission_blocked = | 601 android_permission_blocked = |
| 602 !window_android->HasPermission(android_permission) && | 602 !window_android->HasPermission(android_permission) && |
| 603 !window_android->CanRequestPermission(android_permission); | 603 !window_android->CanRequestPermission(android_permission); |
| 604 } | 604 } |
| 605 if (android_permission_blocked) | 605 if (android_permission_blocked) |
| 606 return false; | 606 return false; |
| 607 | 607 |
| 608 // Don't approve device requests if the tab was hidden. | 608 // Don't approve device requests if the tab was hidden. |
| 609 // TODO(qinmin): Add a test for this. http://crbug.com/396869. | 609 // TODO(qinmin): Add a test for this. http://crbug.com/396869. |
| 610 // TODO(raymes): Shouldn't this apply to all permissions not just audio/video? | 610 // TODO(raymes): Shouldn't this apply to all permissions not just audio/video? |
| 611 return web_contents_->GetRenderWidgetHostView()->IsShowing(); | 611 return web_contents_->GetRenderWidgetHostView()->IsShowing(); |
| 612 #endif | 612 #endif |
| 613 return true; | 613 return true; |
| 614 } | 614 } |
| OLD | NEW |