OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 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 CHROME_BROWSER_USB_USB_CHOOSER_CONTEXT_H_ |
| 6 #define CHROME_BROWSER_USB_USB_CHOOSER_CONTEXT_H_ |
| 7 |
| 8 #include <map> |
| 9 #include <set> |
| 10 #include <string> |
| 11 |
| 12 #include "base/macros.h" |
| 13 #include "base/scoped_observer.h" |
| 14 #include "chrome/browser/permissions/chooser_context_base.h" |
| 15 #include "device/usb/usb_service.h" |
| 16 |
| 17 class UsbChooserContext : public ChooserContextBase, |
| 18 public device::UsbService::Observer { |
| 19 public: |
| 20 explicit UsbChooserContext(Profile* profile); |
| 21 ~UsbChooserContext() override; |
| 22 |
| 23 // These methods from ChooserContextBase are overridden in order to expose |
| 24 // ephemeral devices through the public interface. |
| 25 ScopedVector<base::DictionaryValue> GetPreviouslyChosenObjects( |
| 26 const GURL& requesting_origin, |
| 27 const GURL& embedding_origin) override; |
| 28 void RevokeObjectPermission(const GURL& requesting_origin, |
| 29 const GURL& embedding_origin, |
| 30 const base::DictionaryValue& object) override; |
| 31 |
| 32 // Grants |requesting_origin| access to the USB device known to |
| 33 // device::UsbService as |guid|. |
| 34 void GrantDevicePermission(const GURL& requesting_origin, |
| 35 const GURL& embedding_origin, |
| 36 const std::string& guid); |
| 37 |
| 38 // Revokes |requesting_origin|'s access to the USB device known to |
| 39 // device::UsbService as |guid|. |
| 40 void RevokeDevicePermission(const GURL& requesting_origin, |
| 41 const GURL& embedding_origin, |
| 42 const std::string& guid); |
| 43 |
| 44 // Checks if |requesting_origin| (when embedded within |embedding_origin| has |
| 45 // access to the USB device known to device::UsbService as |guid|. |
| 46 bool HasDevicePermission(const GURL& requesting_origin, |
| 47 const GURL& embedding_origin, |
| 48 const std::string& guid); |
| 49 |
| 50 private: |
| 51 // ChooserContextBase implementation. |
| 52 bool IsValidObject(const base::DictionaryValue& object) override; |
| 53 |
| 54 // device::UsbService::Observer implementation. |
| 55 void OnDeviceRemoved(scoped_refptr<device::UsbDevice> device) override; |
| 56 |
| 57 std::map<GURL, std::set<std::string>> ephemeral_devices_; |
| 58 device::UsbService* usb_service_; |
| 59 ScopedObserver<device::UsbService, device::UsbService::Observer> observer_; |
| 60 |
| 61 DISALLOW_COPY_AND_ASSIGN(UsbChooserContext); |
| 62 }; |
| 63 |
| 64 #endif // CHROME_BROWSER_USB_USB_CHOOSER_CONTEXT_H_ |
OLD | NEW |