| Index: chrome/browser/ui/bluetooth/bluetooth_chooser_context.cc
|
| diff --git a/chrome/browser/ui/bluetooth/bluetooth_chooser_context.cc b/chrome/browser/ui/bluetooth/bluetooth_chooser_context.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..ba60a709b59cda2607fb2affa85e5a2cecab28a6
|
| --- /dev/null
|
| +++ b/chrome/browser/ui/bluetooth/bluetooth_chooser_context.cc
|
| @@ -0,0 +1,70 @@
|
| +// Copyright 2016 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "chrome/browser/ui/bluetooth/bluetooth_chooser_context.h"
|
| +
|
| +#include <utility>
|
| +
|
| +#include "base/values.h"
|
| +#include "chrome/browser/profiles/profile.h"
|
| +
|
| +namespace {
|
| +
|
| +const char kDeviceIdKey[] = "device-id";
|
| +
|
| +const base::DictionaryValue* FindForDevice(
|
| + const std::vector<scoped_ptr<base::DictionaryValue>>& device_list,
|
| + const std::string& device_id) {
|
| + for (const scoped_ptr<base::DictionaryValue>& device_dict : device_list) {
|
| + std::string tmp_device_id;
|
| + if (device_dict->GetString(kDeviceIdKey, &tmp_device_id) &&
|
| + tmp_device_id == device_id) {
|
| + return device_dict.get();
|
| + }
|
| + }
|
| + return nullptr;
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| +BluetoothChooserContext::BluetoothChooserContext(Profile* profile)
|
| + : ChooserContextBase(profile,
|
| + CONTENT_SETTINGS_TYPE_BLUETOOTH_CHOOSER_DATA) {}
|
| +
|
| +BluetoothChooserContext::~BluetoothChooserContext() {}
|
| +
|
| +void BluetoothChooserContext::GrantDevicePermission(
|
| + const GURL& requesting_origin,
|
| + const GURL& embedding_origin,
|
| + const std::string& device_id) {
|
| + scoped_ptr<base::DictionaryValue> device_dict(new base::DictionaryValue());
|
| + device_dict->SetString(kDeviceIdKey, device_id);
|
| + GrantObjectPermission(requesting_origin, embedding_origin,
|
| + std::move(device_dict));
|
| +}
|
| +
|
| +void BluetoothChooserContext::RevokeDevicePermission(
|
| + const GURL& requesting_origin,
|
| + const GURL& embedding_origin,
|
| + const std::string& device_id) {
|
| + std::vector<scoped_ptr<base::DictionaryValue>> device_list =
|
| + GetGrantedObjects(requesting_origin, embedding_origin);
|
| + const base::DictionaryValue* entry = FindForDevice(device_list, device_id);
|
| + if (entry)
|
| + RevokeObjectPermission(requesting_origin, embedding_origin, *entry);
|
| +}
|
| +
|
| +bool BluetoothChooserContext::HasDevicePermission(
|
| + const GURL& requesting_origin,
|
| + const GURL& embedding_origin,
|
| + const std::string& device_id) {
|
| + std::vector<scoped_ptr<base::DictionaryValue>> device_list =
|
| + GetGrantedObjects(requesting_origin, embedding_origin);
|
| + return FindForDevice(device_list, device_id) != nullptr;
|
| +}
|
| +
|
| +bool BluetoothChooserContext::IsValidObject(
|
| + const base::DictionaryValue& object) {
|
| + return object.size() == 1 && object.HasKey(kDeviceIdKey);
|
| +}
|
|
|