OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_DEVICE_CHOOSER_CONTROLLER_H_ | 5 #ifndef CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_DEVICE_CHOOSER_CONTROLLER_H_ |
6 #define CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_DEVICE_CHOOSER_CONTROLLER_H_ | 6 #define CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_DEVICE_CHOOSER_CONTROLLER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
11 #include "base/time/time.h" | 11 #include "base/time/time.h" |
12 #include "base/timer/timer.h" | 12 #include "base/timer/timer.h" |
13 #include "content/common/content_export.h" | 13 #include "content/common/content_export.h" |
14 #include "content/public/browser/bluetooth_chooser.h" | 14 #include "content/public/browser/bluetooth_chooser.h" |
15 #include "third_party/WebKit/public/platform/modules/bluetooth/web_bluetooth.moj om.h" | 15 #include "third_party/WebKit/public/platform/modules/bluetooth/web_bluetooth.moj om.h" |
16 | 16 |
17 namespace device { | 17 namespace device { |
18 class BluetoothAdapter; | 18 class BluetoothAdapter; |
19 class BluetoothDevice; | 19 class BluetoothDevice; |
20 class BluetoothDiscoveryFilter; | 20 class BluetoothDiscoveryFilter; |
21 class BluetoothDiscoverySession; | 21 class BluetoothDiscoverySession; |
22 } | 22 } |
23 | 23 |
24 namespace url { | |
25 class Origin; | |
26 } | |
27 | |
24 namespace content { | 28 namespace content { |
25 | 29 |
30 class BluetoothAllowedDevicesMap; | |
26 class RenderFrameHost; | 31 class RenderFrameHost; |
27 class WebContents; | 32 class WebContents; |
28 class WebBluetoothServiceImpl; | 33 class WebBluetoothServiceImpl; |
29 | 34 |
30 // Class that interacts with a chooser and starts a bluetooth discovery session. | 35 // Class that interacts with a chooser and starts a bluetooth discovery session. |
31 // This class needs to be re-instantiated for each call to GetDevice(). Calling | 36 // This class needs to be re-instantiated for each call to GetDevice(). Calling |
32 // GetDevice() twice for the same instance will DCHECK. | 37 // GetDevice() twice for the same instance will DCHECK. |
33 class CONTENT_EXPORT BluetoothDeviceChooserController final { | 38 class CONTENT_EXPORT BluetoothDeviceChooserController final { |
34 public: | 39 public: |
35 typedef base::Callback<void(blink::mojom::WebBluetoothRequestDeviceOptionsPtr, | 40 typedef base::Callback<void(blink::mojom::WebBluetoothRequestDeviceOptionsPtr, |
36 const std::string& device_address)> | 41 const std::string& device_address)> |
37 SuccessCallback; | 42 SuccessCallback; |
38 typedef base::Callback<void(blink::mojom::WebBluetoothError error)> | 43 typedef base::Callback<void(blink::mojom::WebBluetoothError error)> |
39 ErrorCallback; | 44 ErrorCallback; |
40 | 45 |
41 // |web_bluetooth_service_| service that owns this class. | 46 // |web_bluetooth_service_| service that owns this class. |
42 // |render_frame_host| should be the RenderFrameHost that owns the | 47 // |render_frame_host| should be the RenderFrameHost that owns the |
43 // |web_bluetooth_service_|. | 48 // |web_bluetooth_service_|. |
44 // |adapter| should be the adapter used to scan for Bluetooth devices. | 49 // |adapter| should be the adapter used to scan for Bluetooth devices. |
45 BluetoothDeviceChooserController( | 50 BluetoothDeviceChooserController( |
46 WebBluetoothServiceImpl* web_bluetooth_service_, | 51 WebBluetoothServiceImpl* web_bluetooth_service_, |
47 RenderFrameHost* render_frame_host, | 52 RenderFrameHost* render_frame_host, |
48 device::BluetoothAdapter* adapter); | 53 device::BluetoothAdapter* adapter, |
54 const BluetoothAllowedDevicesMap& bluetooth_allowed_devices_map, | |
Jeffrey Yasskin
2016/09/14 20:08:36
Taking this by reference requires that the Chooser
juncai
2016/09/14 23:13:07
Done.
| |
55 const url::Origin& origin); | |
49 ~BluetoothDeviceChooserController(); | 56 ~BluetoothDeviceChooserController(); |
50 | 57 |
51 // This function performs the following checks before starting a discovery | 58 // This function performs the following checks before starting a discovery |
52 // session: | 59 // session: |
53 // - Validates filters in |request_device_options|. | 60 // - Validates filters in |request_device_options|. |
54 // - Removes any blacklisted UUIDs from | 61 // - Removes any blacklisted UUIDs from |
55 // |request_device_options.optinal_services|. | 62 // |request_device_options.optinal_services|. |
56 // - Checks if the request came from a cross-origin iframe. | 63 // - Checks if the request came from a cross-origin iframe. |
57 // - Checks if the request came from a unique origin. | 64 // - Checks if the request came from a unique origin. |
58 // - Checks if the adapter is present. | 65 // - Checks if the adapter is present. |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
139 // Automatically stops Bluetooth discovery a set amount of time after it was | 146 // Automatically stops Bluetooth discovery a set amount of time after it was |
140 // started. | 147 // started. |
141 base::Timer discovery_session_timer_; | 148 base::Timer discovery_session_timer_; |
142 | 149 |
143 // The last discovery session to be started. | 150 // The last discovery session to be started. |
144 // TODO(ortuno): This should be null unless there is an active discovery | 151 // TODO(ortuno): This should be null unless there is an active discovery |
145 // session. We need to null it when the platform stops discovery. | 152 // session. We need to null it when the platform stops discovery. |
146 // http://crbug.com/611852 | 153 // http://crbug.com/611852 |
147 std::unique_ptr<device::BluetoothDiscoverySession> discovery_session_; | 154 std::unique_ptr<device::BluetoothDiscoverySession> discovery_session_; |
148 | 155 |
156 const BluetoothAllowedDevicesMap& bluetooth_allowed_devices_map_; | |
157 url::Origin origin_; | |
158 | |
149 // Weak pointer factory for generating 'this' pointers that might live longer | 159 // Weak pointer factory for generating 'this' pointers that might live longer |
150 // than we do. | 160 // than we do. |
151 // Note: This should remain the last member so it'll be destroyed and | 161 // Note: This should remain the last member so it'll be destroyed and |
152 // invalidate its weak pointers before any other members are destroyed. | 162 // invalidate its weak pointers before any other members are destroyed. |
153 base::WeakPtrFactory<BluetoothDeviceChooserController> weak_ptr_factory_; | 163 base::WeakPtrFactory<BluetoothDeviceChooserController> weak_ptr_factory_; |
154 }; | 164 }; |
155 | 165 |
156 } // namespace content | 166 } // namespace content |
157 | 167 |
158 #endif // CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_DEVICE_CHOOSER_CONTROLLER_H_ | 168 #endif // CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_DEVICE_CHOOSER_CONTROLLER_H_ |
OLD | NEW |