| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_OUTPUT_AUTHORIZATION_HANDLER_H
_ |
| 6 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_OUTPUT_AUTHORIZATION_HANDLER_H
_ |
| 7 |
| 8 #include <memory> |
| 9 #include <string> |
| 10 #include <utility> |
| 11 |
| 12 #include "base/callback_forward.h" |
| 13 #include "base/memory/weak_ptr.h" |
| 14 #include "content/browser/media/media_devices_permission_checker.h" |
| 15 #include "content/browser/renderer_host/media/media_stream_manager.h" |
| 16 #include "media/audio/audio_device_description.h" |
| 17 #include "media/audio/audio_manager.h" |
| 18 #include "media/base/audio_parameters.h" |
| 19 #include "media/base/output_device_info.h" |
| 20 |
| 21 namespace content { |
| 22 |
| 23 // This class, which lives on the IO thread, handles the logic of an IPC device |
| 24 // request from the renderer. It checks which device to use (in case of using |
| 25 // |session_id| to select device), verifies that the renderer is authorized to |
| 26 // use the device, and gets the default device parameters for the selected audio |
| 27 // device. |
| 28 class CONTENT_EXPORT AudioOutputAuthorizationHandler { |
| 29 public: |
| 30 // The result of an authorization check. In addition to the status, it |
| 31 // indicates whether a device was found using the |session_id| in the variable |
| 32 // |should_send_id|, in which case the renderer expects to get the id hash. It |
| 33 // also has the default audio parameters for the device, and the id for the |
| 34 // device, which is needed to open a stream for the device. This id is not |
| 35 // hashed, so it must be hashed before sending it to the renderer. |
| 36 // TODO(maxmorin): Change to OnceCallback once base:: code is ready for it. |
| 37 using AuthorizationCompletedCallback = |
| 38 base::Callback<void(media::OutputDeviceStatus status, |
| 39 bool should_send_id, |
| 40 const media::AudioParameters& params, |
| 41 const std::string& raw_device_id)>; |
| 42 |
| 43 AudioOutputAuthorizationHandler(MediaStreamManager* media_stream_manager, |
| 44 int render_process_id_, |
| 45 const std::string& salt); |
| 46 |
| 47 ~AudioOutputAuthorizationHandler(); |
| 48 |
| 49 // Checks authorization of the device with the hashed id |device_id| for the |
| 50 // given render frame id and security origin, or uses |session_id| for |
| 51 // authorization. Looks up device id (if |session_id| is used for device |
| 52 // selection) and default device parameters. |
| 53 void RequestDeviceAuthorization(int render_frame_id, |
| 54 int session_id, |
| 55 const std::string& device_id, |
| 56 const url::Origin& security_origin, |
| 57 AuthorizationCompletedCallback cb) const; |
| 58 |
| 59 // Calling this method will make the checks for permission from the user |
| 60 // always return |override_value|. |
| 61 void OverridePermissionsForTesting(bool override_value); |
| 62 |
| 63 private: |
| 64 // Convention: Something named |device_id| is hashed and something named |
| 65 // |raw_device_id| is not hashed. |
| 66 |
| 67 void AccessChecked(AuthorizationCompletedCallback cb, |
| 68 const std::string& device_id, |
| 69 const url::Origin& security_origin, |
| 70 bool has_access) const; |
| 71 |
| 72 void TranslateDeviceID(AuthorizationCompletedCallback cb, |
| 73 const std::string& device_id, |
| 74 const url::Origin& security_origin, |
| 75 const MediaDeviceEnumeration& enumeration) const; |
| 76 |
| 77 void GetDeviceParameters(AuthorizationCompletedCallback cb, |
| 78 const std::string& raw_device_id) const; |
| 79 |
| 80 void DeviceParametersReceived( |
| 81 AuthorizationCompletedCallback cb, |
| 82 bool should_send_id, |
| 83 const std::string& raw_device_id, |
| 84 const media::AudioParameters& output_params) const; |
| 85 |
| 86 MediaStreamManager* const media_stream_manager_; |
| 87 std::unique_ptr<MediaDevicesPermissionChecker> permission_checker_; |
| 88 const int render_process_id_; |
| 89 const std::string salt_; |
| 90 // All access is on the IO thread, and taking a weak pointer to const looks |
| 91 // const, so this can be mutable. |
| 92 mutable base::WeakPtrFactory<const AudioOutputAuthorizationHandler> |
| 93 weak_factory_; |
| 94 |
| 95 DISALLOW_COPY_AND_ASSIGN(AudioOutputAuthorizationHandler); |
| 96 }; |
| 97 |
| 98 } // namespace content |
| 99 |
| 100 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_OUTPUT_AUTHORIZATION_HANDLE
R_H_ |
| OLD | NEW |