diff options
author | rpaquay@chromium.org <rpaquay@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-02-12 01:40:16 +0000 |
---|---|---|
committer | rpaquay@chromium.org <rpaquay@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-02-12 01:40:16 +0000 |
commit | c0c64f8700f65e07704c992068abad215deb9c3b (patch) | |
tree | 32f2ca9cc6aaaa4634affaeef058e1237fc88658 | |
parent | 4a98a96db7b4f94e49c13ae0b17d99ec237e31b4 (diff) | |
download | chromium_src-c0c64f8700f65e07704c992068abad215deb9c3b.zip chromium_src-c0c64f8700f65e07704c992068abad215deb9c3b.tar.gz chromium_src-c0c64f8700f65e07704c992068abad215deb9c3b.tar.bz2 |
Replace "bluetooth" permission with manifest property.
BUG=336824
Review URL: https://codereview.chromium.org/145663004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@250599 0039d316-1c4b-4281-b951-d872f2087c98
34 files changed, 552 insertions, 308 deletions
diff --git a/chrome/browser/extensions/api/bluetooth/bluetooth_api.cc b/chrome/browser/extensions/api/bluetooth/bluetooth_api.cc index f921021..b6cf166 100644 --- a/chrome/browser/extensions/api/bluetooth/bluetooth_api.cc +++ b/chrome/browser/extensions/api/bluetooth/bluetooth_api.cc @@ -13,7 +13,7 @@ #include "chrome/browser/extensions/event_names.h" #include "chrome/browser/profiles/profile.h" #include "chrome/common/extensions/api/bluetooth.h" -#include "chrome/common/extensions/permissions/bluetooth_permission.h" +#include "chrome/common/extensions/api/bluetooth/bluetooth_manifest_data.h" #include "content/public/browser/browser_thread.h" #include "device/bluetooth/bluetooth_adapter.h" #include "device/bluetooth/bluetooth_device.h" @@ -125,10 +125,9 @@ bool BluetoothAddProfileFunction::RunImpl() { return false; } - BluetoothPermission::CheckParam param(params->profile.uuid); - if (!PermissionsData::CheckAPIPermissionWithParam( - GetExtension(), APIPermission::kBluetooth, ¶m)) { - SetError(kPermissionDenied); + BluetoothPermissionRequest param(params->profile.uuid); + if (!BluetoothManifestData::CheckRequest(GetExtension(), param)) { + error_ = kPermissionDenied; return false; } diff --git a/chrome/chrome_common.gypi b/chrome/chrome_common.gypi index 1f0d3f1..cc0bde1 100644 --- a/chrome/chrome_common.gypi +++ b/chrome/chrome_common.gypi @@ -111,6 +111,12 @@ 'common/custom_handlers/protocol_handler.h', 'common/descriptors_android.h', 'common/encrypted_media_messages_android.h', + 'common/extensions/api/bluetooth/bluetooth_manifest_data.cc', + 'common/extensions/api/bluetooth/bluetooth_manifest_data.h', + 'common/extensions/api/bluetooth/bluetooth_manifest_handler.cc', + 'common/extensions/api/bluetooth/bluetooth_manifest_handler.h', + 'common/extensions/api/bluetooth/bluetooth_manifest_permission.cc', + 'common/extensions/api/bluetooth/bluetooth_manifest_permission.h', 'common/extensions/api/commands/commands_handler.cc', 'common/extensions/api/commands/commands_handler.h', 'common/extensions/api/extension_action/action_info.cc', @@ -213,10 +219,6 @@ 'common/extensions/message_bundle.h', 'common/extensions/mime_types_handler.cc', 'common/extensions/mime_types_handler.h', - 'common/extensions/permissions/bluetooth_permission.cc', - 'common/extensions/permissions/bluetooth_permission.h', - 'common/extensions/permissions/bluetooth_permission_data.cc', - 'common/extensions/permissions/bluetooth_permission_data.h', 'common/extensions/permissions/chrome_api_permissions.cc', 'common/extensions/permissions/chrome_api_permissions.h', 'common/extensions/permissions/chrome_permission_message_provider.cc', diff --git a/chrome/common/extensions/api/_api_features.json b/chrome/common/extensions/api/_api_features.json index c9e5dad..d9b6c39 100644 --- a/chrome/common/extensions/api/_api_features.json +++ b/chrome/common/extensions/api/_api_features.json @@ -82,7 +82,7 @@ "contexts": ["blessed_extension"] }, "bluetooth": { - "dependencies": ["permission:bluetooth"], + "dependencies": ["manifest:bluetooth"], "contexts": ["blessed_extension"] }, "bookmarkManagerPrivate": { diff --git a/chrome/common/extensions/api/_manifest_features.json b/chrome/common/extensions/api/_manifest_features.json index ef012bf..f077d78 100644 --- a/chrome/common/extensions/api/_manifest_features.json +++ b/chrome/common/extensions/api/_manifest_features.json @@ -67,6 +67,10 @@ ], "max_manifest_version": 1 }, + "bluetooth": { + "channel": "dev", + "extension_types": ["platform_app"] + }, "browser_action": { "channel": "stable", "extension_types": ["extension"] diff --git a/chrome/common/extensions/api/_permission_features.json b/chrome/common/extensions/api/_permission_features.json index c329d9a..0d3ee2c 100644 --- a/chrome/common/extensions/api/_permission_features.json +++ b/chrome/common/extensions/api/_permission_features.json @@ -113,14 +113,6 @@ ] } ], - "bluetooth": { - "channel": "dev", - "extension_types": ["platform_app"] - }, - "bluetoothDevices": { - "channel": "dev", - "extension_types": ["platform_app"] - }, "bookmarkManagerPrivate": { "channel": "stable", "extension_types": ["extension", "legacy_packaged_app"], diff --git a/chrome/common/extensions/api/bluetooth/bluetooth_manifest_data.cc b/chrome/common/extensions/api/bluetooth/bluetooth_manifest_data.cc new file mode 100644 index 0000000..237dddb --- /dev/null +++ b/chrome/common/extensions/api/bluetooth/bluetooth_manifest_data.cc @@ -0,0 +1,53 @@ +// Copyright 2014 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/common/extensions/api/bluetooth/bluetooth_manifest_data.h" + +#include "chrome/common/extensions/api/bluetooth/bluetooth_manifest_permission.h" +#include "extensions/common/manifest_constants.h" + +namespace extensions { + +BluetoothManifestData::BluetoothManifestData( + scoped_ptr<BluetoothManifestPermission> permission) + : permission_(permission.Pass()) { + DCHECK(permission_); +} + +BluetoothManifestData::~BluetoothManifestData() {} + +// static +BluetoothManifestData* BluetoothManifestData::Get(const Extension* extension) { + return static_cast<BluetoothManifestData*>( + extension->GetManifestData(manifest_keys::kBluetooth)); +} + +// static +bool BluetoothManifestData::CheckRequest( + const Extension* extension, + const BluetoothPermissionRequest& request) { + const BluetoothManifestData* data = BluetoothManifestData::Get(extension); + return data && data->permission()->CheckRequest(extension, request); +} + +// static +scoped_ptr<BluetoothManifestData> BluetoothManifestData::FromValue( + const base::Value& value, + base::string16* error) { + scoped_ptr<BluetoothManifestPermission> permission = + BluetoothManifestPermission::FromValue(value, error); + if (!permission) + return scoped_ptr<BluetoothManifestData>(); + + return scoped_ptr<BluetoothManifestData>( + new BluetoothManifestData(permission.Pass())).Pass(); +} + +BluetoothPermissionRequest::BluetoothPermissionRequest( + const std::string& profile_uuid) + : profile_uuid(profile_uuid) {} + +BluetoothPermissionRequest::~BluetoothPermissionRequest() {} + +} // namespace extensions diff --git a/chrome/common/extensions/api/bluetooth/bluetooth_manifest_data.h b/chrome/common/extensions/api/bluetooth/bluetooth_manifest_data.h new file mode 100644 index 0000000..db7f108 --- /dev/null +++ b/chrome/common/extensions/api/bluetooth/bluetooth_manifest_data.h @@ -0,0 +1,58 @@ +// Copyright 2014 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. + +#ifndef CHROME_COMMON_EXTENSIONS_API_BLUETOOTH_BLUETOOTH_MANIFEST_DATA_H_ +#define CHROME_COMMON_EXTENSIONS_API_BLUETOOTH_BLUETOOTH_MANIFEST_DATA_H_ + +#include <vector> + +#include "base/strings/string16.h" +#include "extensions/common/extension.h" +#include "extensions/common/manifest_handler.h" + +namespace extensions { +class BluetoothManifestPermission; +struct BluetoothPermissionRequest; +} + +namespace extensions { + +// The parsed form of the "bluetooth" manifest entry. +class BluetoothManifestData : public Extension::ManifestData { + public: + explicit BluetoothManifestData( + scoped_ptr<BluetoothManifestPermission> permission); + virtual ~BluetoothManifestData(); + + // Gets the BluetoothManifestData for |extension|, or NULL if none was + // specified. + static BluetoothManifestData* Get(const Extension* extension); + + static bool CheckRequest(const Extension* extension, + const BluetoothPermissionRequest& request); + + // Tries to construct the info based on |value|, as it would have appeared in + // the manifest. Sets |error| and returns an empty scoped_ptr on failure. + static scoped_ptr<BluetoothManifestData> FromValue(const base::Value& value, + base::string16* error); + + const BluetoothManifestPermission* permission() const { + return permission_.get(); + } + + private: + scoped_ptr<BluetoothManifestPermission> permission_; +}; + +// Used for checking bluetooth permission. +struct BluetoothPermissionRequest { + explicit BluetoothPermissionRequest(const std::string& profile_uuid); + ~BluetoothPermissionRequest(); + + std::string profile_uuid; +}; + +} // namespace extensions + +#endif // CHROME_COMMON_EXTENSIONS_API_BLUETOOTH_BLUETOOTH_MANIFEST_DATA_H_ diff --git a/chrome/common/extensions/api/bluetooth/bluetooth_manifest_handler.cc b/chrome/common/extensions/api/bluetooth/bluetooth_manifest_handler.cc new file mode 100644 index 0000000..e2b9cf3 --- /dev/null +++ b/chrome/common/extensions/api/bluetooth/bluetooth_manifest_handler.cc @@ -0,0 +1,47 @@ +// Copyright 2014 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/common/extensions/api/bluetooth/bluetooth_manifest_handler.h" + +#include "chrome/common/extensions/api/bluetooth/bluetooth_manifest_data.h" +#include "chrome/common/extensions/api/bluetooth/bluetooth_manifest_permission.h" +#include "extensions/common/extension.h" +#include "extensions/common/manifest_constants.h" + +namespace extensions { + +BluetoothManifestHandler::BluetoothManifestHandler() {} + +BluetoothManifestHandler::~BluetoothManifestHandler() {} + +bool BluetoothManifestHandler::Parse(Extension* extension, + base::string16* error) { + const base::Value* bluetooth = NULL; + CHECK(extension->manifest()->Get(manifest_keys::kBluetooth, &bluetooth)); + scoped_ptr<BluetoothManifestData> data = + BluetoothManifestData::FromValue(*bluetooth, error); + if (!data) + return false; + + extension->SetManifestData(manifest_keys::kBluetooth, data.release()); + return true; +} + +ManifestPermission* BluetoothManifestHandler::CreatePermission() { + return new BluetoothManifestPermission(); +} + +ManifestPermission* BluetoothManifestHandler::CreateInitialRequiredPermission( + const Extension* extension) { + BluetoothManifestData* data = BluetoothManifestData::Get(extension); + if (data) + return data->permission()->Clone(); + return NULL; +} + +const std::vector<std::string> BluetoothManifestHandler::Keys() const { + return SingleKey(manifest_keys::kBluetooth); +} + +} // namespace extensions diff --git a/chrome/common/extensions/api/bluetooth/bluetooth_manifest_handler.h b/chrome/common/extensions/api/bluetooth/bluetooth_manifest_handler.h new file mode 100644 index 0000000..2c93502 --- /dev/null +++ b/chrome/common/extensions/api/bluetooth/bluetooth_manifest_handler.h @@ -0,0 +1,41 @@ +// Copyright 2014 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. + +#ifndef CHROME_COMMON_EXTENSIONS_API_BLUETOOTH_BLUETOOTH_MANIFEST_HANDLER_H_ +#define CHROME_COMMON_EXTENSIONS_API_BLUETOOTH_BLUETOOTH_MANIFEST_HANDLER_H_ + +#include <string> +#include <vector> + +#include "extensions/common/manifest_handler.h" + +namespace extensions { +class Extension; +class ManifestPermission; +} + +namespace extensions { + +// Parses the "bluetooth" manifest key. +class BluetoothManifestHandler : public ManifestHandler { + public: + BluetoothManifestHandler(); + virtual ~BluetoothManifestHandler(); + + // ManifestHandler overrides. + virtual bool Parse(Extension* extension, base::string16* error) OVERRIDE; + virtual ManifestPermission* CreatePermission() OVERRIDE; + virtual ManifestPermission* CreateInitialRequiredPermission( + const Extension* extension) OVERRIDE; + + private: + // ManifestHandler overrides. + virtual const std::vector<std::string> Keys() const OVERRIDE; + + DISALLOW_COPY_AND_ASSIGN(BluetoothManifestHandler); +}; + +} // namespace extensions + +#endif // CHROME_COMMON_EXTENSIONS_API_BLUETOOTH_BLUETOOTH_MANIFEST_HANDLER_H_ diff --git a/chrome/common/extensions/api/bluetooth/bluetooth_manifest_permission.cc b/chrome/common/extensions/api/bluetooth/bluetooth_manifest_permission.cc new file mode 100644 index 0000000..0f7399a --- /dev/null +++ b/chrome/common/extensions/api/bluetooth/bluetooth_manifest_permission.cc @@ -0,0 +1,222 @@ +// Copyright 2014 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/common/extensions/api/bluetooth/bluetooth_manifest_permission.h" + +#include "base/memory/scoped_ptr.h" +#include "base/stl_util.h" +#include "base/strings/utf_string_conversions.h" +#include "base/values.h" +#include "chrome/common/extensions/api/bluetooth/bluetooth_manifest_data.h" +#include "chrome/common/extensions/api/manifest_types.h" +#include "chrome/common/extensions/extension_messages.h" +#include "device/bluetooth/bluetooth_utils.h" +#include "extensions/common/error_utils.h" +#include "extensions/common/manifest_constants.h" +#include "grit/generated_resources.h" +#include "ipc/ipc_message.h" +#include "ui/base/l10n/l10n_util.h" + +namespace extensions { + +namespace bluetooth_errors { +const char kErrorInvalidProfileUuid[] = "Invalid UUID '*'"; +} + +namespace errors = bluetooth_errors; + +namespace { + +bool ParseUuid(BluetoothManifestPermission* permission, + const std::string& profile_uuid, + base::string16* error) { + std::string canonical_uuid = + device::bluetooth_utils::CanonicalUuid(profile_uuid); + if (canonical_uuid.empty()) { + *error = ErrorUtils::FormatErrorMessageUTF16( + errors::kErrorInvalidProfileUuid, profile_uuid); + return false; + } + permission->AddPermission(profile_uuid); + return true; +} + +bool ParseUuidArray(BluetoothManifestPermission* permission, + const scoped_ptr<std::vector<std::string> >& profiles, + base::string16* error) { + for (std::vector<std::string>::const_iterator it = profiles->begin(); + it != profiles->end(); + ++it) { + if (!ParseUuid(permission, *it, error)) { + return false; + } + } + return true; +} + +} // namespace + +BluetoothManifestPermission::BluetoothManifestPermission() {} + +BluetoothManifestPermission::~BluetoothManifestPermission() {} + +// static +scoped_ptr<BluetoothManifestPermission> BluetoothManifestPermission::FromValue( + const base::Value& value, + base::string16* error) { + scoped_ptr<api::manifest_types::Bluetooth> bluetooth = + api::manifest_types::Bluetooth::FromValue(value, error); + if (!bluetooth) + return scoped_ptr<BluetoothManifestPermission>(); + + scoped_ptr<BluetoothManifestPermission> result( + new BluetoothManifestPermission()); + if (bluetooth->profiles) { + if (!ParseUuidArray(result.get(), bluetooth->profiles, error)) { + return scoped_ptr<BluetoothManifestPermission>(); + } + } + return result.Pass(); +} + +bool BluetoothManifestPermission::CheckRequest( + const Extension* extension, + const BluetoothPermissionRequest& request) const { + + std::string canonical_param_uuid = + device::bluetooth_utils::CanonicalUuid(request.profile_uuid); + for (BluetoothProfileUuidSet::const_iterator it = profile_uuids_.begin(); + it != profile_uuids_.end(); + ++it) { + std::string canonical_uuid = device::bluetooth_utils::CanonicalUuid(*it); + if (canonical_uuid == canonical_param_uuid) + return true; + } + return false; +} + +std::string BluetoothManifestPermission::name() const { + return manifest_keys::kBluetooth; +} + +std::string BluetoothManifestPermission::id() const { return name(); } + +bool BluetoothManifestPermission::HasMessages() const { return true; } + +PermissionMessages BluetoothManifestPermission::GetMessages() const { + DCHECK(HasMessages()); + PermissionMessages result; + + result.push_back(PermissionMessage( + PermissionMessage::kBluetooth, + l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_WARNING_BLUETOOTH))); + + if (!profile_uuids_.empty()) { + result.push_back( + PermissionMessage(PermissionMessage::kBluetoothDevices, + l10n_util::GetStringUTF16( + IDS_EXTENSION_PROMPT_WARNING_BLUETOOTH_DEVICES))); + } + + return result; +} + +bool BluetoothManifestPermission::FromValue(const base::Value* value) { + if (!value) + return false; + base::string16 error; + scoped_ptr<BluetoothManifestPermission> manifest_permission( + BluetoothManifestPermission::FromValue(*value, &error)); + + if (!manifest_permission) + return false; + + profile_uuids_ = manifest_permission->profile_uuids_; + return true; +} + +scoped_ptr<base::Value> BluetoothManifestPermission::ToValue() const { + api::manifest_types::Bluetooth bluetooth; + bluetooth.profiles.reset(new std::vector<std::string>(profile_uuids_.begin(), + profile_uuids_.end())); + return bluetooth.ToValue().PassAs<base::Value>(); +} + +ManifestPermission* BluetoothManifestPermission::Clone() const { + scoped_ptr<BluetoothManifestPermission> result( + new BluetoothManifestPermission()); + result->profile_uuids_ = profile_uuids_; + return result.release(); +} + +ManifestPermission* BluetoothManifestPermission::Diff( + const ManifestPermission* rhs) const { + const BluetoothManifestPermission* other = + static_cast<const BluetoothManifestPermission*>(rhs); + + scoped_ptr<BluetoothManifestPermission> result( + new BluetoothManifestPermission()); + result->profile_uuids_ = base::STLSetDifference<BluetoothProfileUuidSet>( + profile_uuids_, other->profile_uuids_); + return result.release(); +} + +ManifestPermission* BluetoothManifestPermission::Union( + const ManifestPermission* rhs) const { + const BluetoothManifestPermission* other = + static_cast<const BluetoothManifestPermission*>(rhs); + + scoped_ptr<BluetoothManifestPermission> result( + new BluetoothManifestPermission()); + result->profile_uuids_ = base::STLSetUnion<BluetoothProfileUuidSet>( + profile_uuids_, other->profile_uuids_); + return result.release(); +} + +ManifestPermission* BluetoothManifestPermission::Intersect( + const ManifestPermission* rhs) const { + const BluetoothManifestPermission* other = + static_cast<const BluetoothManifestPermission*>(rhs); + + scoped_ptr<BluetoothManifestPermission> result( + new BluetoothManifestPermission()); + result->profile_uuids_ = base::STLSetIntersection<BluetoothProfileUuidSet>( + profile_uuids_, other->profile_uuids_); + return result.release(); +} + +bool BluetoothManifestPermission::Contains(const ManifestPermission* rhs) + const { + const BluetoothManifestPermission* other = + static_cast<const BluetoothManifestPermission*>(rhs); + + return base::STLIncludes(profile_uuids_, other->profile_uuids_); +} + +bool BluetoothManifestPermission::Equal(const ManifestPermission* rhs) const { + const BluetoothManifestPermission* other = + static_cast<const BluetoothManifestPermission*>(rhs); + + return (profile_uuids_ == other->profile_uuids_); +} + +void BluetoothManifestPermission::Write(IPC::Message* m) const { + IPC::WriteParam(m, profile_uuids_); +} + +bool BluetoothManifestPermission::Read(const IPC::Message* m, + PickleIterator* iter) { + return IPC::ReadParam(m, iter, &profile_uuids_); +} + +void BluetoothManifestPermission::Log(std::string* log) const { + IPC::LogParam(profile_uuids_, log); +} + +void BluetoothManifestPermission::AddPermission( + const std::string& profile_uuid) { + profile_uuids_.insert(profile_uuid); +} + +} // namespace extensions diff --git a/chrome/common/extensions/api/bluetooth/bluetooth_manifest_permission.h b/chrome/common/extensions/api/bluetooth/bluetooth_manifest_permission.h new file mode 100644 index 0000000..f9b7603 --- /dev/null +++ b/chrome/common/extensions/api/bluetooth/bluetooth_manifest_permission.h @@ -0,0 +1,71 @@ +// Copyright 2014 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. + +#ifndef CHROME_COMMON_EXTENSIONS_API_BLUETOOTH_BLUETOOTH_MANIFEST_PERMISSION_H_ +#define CHROME_COMMON_EXTENSIONS_API_BLUETOOTH_BLUETOOTH_MANIFEST_PERMISSION_H_ + +#include <set> +#include <vector> + +#include "extensions/common/install_warning.h" +#include "extensions/common/permissions/manifest_permission.h" + +namespace extensions { +class Extension; +} + +namespace extensions { +struct BluetoothPermissionRequest; +} + +namespace extensions { + +class BluetoothManifestPermission : public ManifestPermission { + public: + typedef std::set<std::string> BluetoothProfileUuidSet; + BluetoothManifestPermission(); + virtual ~BluetoothManifestPermission(); + + // Tries to construct the info based on |value|, as it would have appeared in + // the manifest. Sets |error| and returns an empty scoped_ptr on failure. + static scoped_ptr<BluetoothManifestPermission> FromValue( + const base::Value& value, + base::string16* error); + + bool CheckRequest(const Extension* extension, + const BluetoothPermissionRequest& request) const; + + void AddPermission(const std::string& profile_uuid); + + // extensions::ManifestPermission overrides. + virtual std::string name() const OVERRIDE; + virtual std::string id() const OVERRIDE; + virtual bool HasMessages() const OVERRIDE; + virtual PermissionMessages GetMessages() const OVERRIDE; + virtual bool FromValue(const base::Value* value) OVERRIDE; + virtual scoped_ptr<base::Value> ToValue() const OVERRIDE; + virtual ManifestPermission* Clone() const OVERRIDE; + virtual ManifestPermission* Diff(const ManifestPermission* rhs) + const OVERRIDE; + virtual ManifestPermission* Union(const ManifestPermission* rhs) + const OVERRIDE; + virtual ManifestPermission* Intersect(const ManifestPermission* rhs) + const OVERRIDE; + virtual bool Contains(const ManifestPermission* rhs) const OVERRIDE; + virtual bool Equal(const ManifestPermission* rhs) const OVERRIDE; + virtual void Write(IPC::Message* m) const OVERRIDE; + virtual bool Read(const IPC::Message* m, PickleIterator* iter) OVERRIDE; + virtual void Log(std::string* log) const OVERRIDE; + + const BluetoothProfileUuidSet& profile_uuids() const { + return profile_uuids_; + } + + private: + BluetoothProfileUuidSet profile_uuids_; +}; + +} // namespace extensions + +#endif // CHROME_COMMON_EXTENSIONS_API_BLUETOOTH_BLUETOOTH_MANIFEST_PERMISSION_H_ diff --git a/chrome/common/extensions/api/manifest_types.json b/chrome/common/extensions/api/manifest_types.json index ef006dd..d14b71f 100644 --- a/chrome/common/extensions/api/manifest_types.json +++ b/chrome/common/extensions/api/manifest_types.json @@ -206,6 +206,22 @@ } } } + }, + { + "id": "bluetooth", + "type": "object", + "description": "The <code>bluetooth</code> manifest property give permission to an app to use the $ref:bluetooth API. A list of profile IDs can be optionally specified to enable communication with specific device types", + "properties": { + "profiles": { + "description": "The <code>profiles</code> manifest property declares the list of profiles an app can register.", + "optional": true, + "type": "array", + "items": { + "description": "<p>The list of profiles specified as UUID strings.</p>", + "type": "string" + } + } + } } ] } diff --git a/chrome/common/extensions/api/sockets/sockets_manifest_permission.cc b/chrome/common/extensions/api/sockets/sockets_manifest_permission.cc index 61dc719..269ed94 100644 --- a/chrome/common/extensions/api/sockets/sockets_manifest_permission.cc +++ b/chrome/common/extensions/api/sockets/sockets_manifest_permission.cc @@ -5,6 +5,7 @@ #include "chrome/common/extensions/api/sockets/sockets_manifest_permission.h" #include "base/memory/scoped_ptr.h" +#include "base/stl_util.h" #include "base/strings/utf_string_conversions.h" #include "base/values.h" #include "chrome/common/extensions/api/manifest_types.h" @@ -232,11 +233,8 @@ ManifestPermission* SocketsManifestPermission::Diff( static_cast<const SocketsManifestPermission*>(rhs); scoped_ptr<SocketsManifestPermission> result(new SocketsManifestPermission()); - std::set_difference( - permissions_.begin(), permissions_.end(), - other->permissions_.begin(), other->permissions_.end(), - std::inserter<SocketPermissionEntrySet>( - result->permissions_, result->permissions_.begin())); + result->permissions_ = base::STLSetDifference<SocketPermissionEntrySet>( + permissions_, other->permissions_); return result.release(); } @@ -246,11 +244,8 @@ ManifestPermission* SocketsManifestPermission::Union( static_cast<const SocketsManifestPermission*>(rhs); scoped_ptr<SocketsManifestPermission> result(new SocketsManifestPermission()); - std::set_union( - permissions_.begin(), permissions_.end(), - other->permissions_.begin(), other->permissions_.end(), - std::inserter<SocketPermissionEntrySet>( - result->permissions_, result->permissions_.begin())); + result->permissions_ = base::STLSetUnion<SocketPermissionEntrySet>( + permissions_, other->permissions_); return result.release(); } @@ -260,11 +255,8 @@ ManifestPermission* SocketsManifestPermission::Intersect( static_cast<const SocketsManifestPermission*>(rhs); scoped_ptr<SocketsManifestPermission> result(new SocketsManifestPermission()); - std::set_intersection( - permissions_.begin(), permissions_.end(), - other->permissions_.begin(), other->permissions_.end(), - std::inserter<SocketPermissionEntrySet>( - result->permissions_, result->permissions_.begin())); + result->permissions_ = base::STLSetIntersection<SocketPermissionEntrySet>( + permissions_, other->permissions_); return result.release(); } @@ -272,9 +264,8 @@ bool SocketsManifestPermission::Contains(const ManifestPermission* rhs) const { const SocketsManifestPermission* other = static_cast<const SocketsManifestPermission*>(rhs); - return std::includes( - permissions_.begin(), permissions_.end(), - other->permissions_.begin(), other->permissions_.end()); + return base::STLIncludes<SocketPermissionEntrySet>(permissions_, + other->permissions_); } bool SocketsManifestPermission::Equal(const ManifestPermission* rhs) const { diff --git a/chrome/common/extensions/chrome_manifest_handlers.cc b/chrome/common/extensions/chrome_manifest_handlers.cc index 84d2093..9d5ebf6 100644 --- a/chrome/common/extensions/chrome_manifest_handlers.cc +++ b/chrome/common/extensions/chrome_manifest_handlers.cc @@ -4,6 +4,7 @@ #include "chrome/common/extensions/chrome_manifest_handlers.h" +#include "chrome/common/extensions/api/bluetooth/bluetooth_manifest_handler.h" #include "chrome/common/extensions/api/commands/commands_handler.h" #include "chrome/common/extensions/api/extension_action/browser_action_handler.h" #include "chrome/common/extensions/api/extension_action/page_action_handler.h" @@ -44,6 +45,7 @@ void RegisterChromeManifestHandlers() { #if defined(ENABLE_EXTENSIONS) (new AppIsolationHandler)->Register(); (new AppLaunchManifestHandler)->Register(); + (new BluetoothManifestHandler)->Register(); (new BrowserActionHandler)->Register(); (new CommandsHandler)->Register(); (new ContentScriptsHandler)->Register(); diff --git a/chrome/common/extensions/extension_messages.h b/chrome/common/extensions/extension_messages.h index 6ad9b67..c116774 100644 --- a/chrome/common/extensions/extension_messages.h +++ b/chrome/common/extensions/extension_messages.h @@ -11,7 +11,6 @@ #include "base/memory/shared_memory.h" #include "base/values.h" #include "chrome/common/extensions/api/messaging/message.h" -#include "chrome/common/extensions/permissions/bluetooth_permission_data.h" #include "chrome/common/extensions/permissions/media_galleries_permission_data.h" #include "chrome/common/extensions/permissions/socket_permission_data.h" #include "chrome/common/extensions/permissions/usb_device_permission_data.h" @@ -201,10 +200,6 @@ IPC_STRUCT_TRAITS_BEGIN(extensions::MediaGalleriesPermissionData) IPC_STRUCT_TRAITS_MEMBER(permission()) IPC_STRUCT_TRAITS_END() -IPC_STRUCT_TRAITS_BEGIN(extensions::BluetoothPermissionData) - IPC_STRUCT_TRAITS_MEMBER(uuid()) -IPC_STRUCT_TRAITS_END() - IPC_STRUCT_TRAITS_BEGIN(extensions::Message) IPC_STRUCT_TRAITS_MEMBER(data) IPC_STRUCT_TRAITS_MEMBER(user_gesture) diff --git a/chrome/common/extensions/permissions/bluetooth_permission.cc b/chrome/common/extensions/permissions/bluetooth_permission.cc deleted file mode 100644 index 15289ce..0000000 --- a/chrome/common/extensions/permissions/bluetooth_permission.cc +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright 2013 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/common/extensions/permissions/bluetooth_permission.h" - -#include <string> - -#include "base/logging.h" -#include "base/strings/string16.h" -#include "base/strings/string_util.h" -#include "base/strings/utf_string_conversions.h" -#include "chrome/common/extensions/permissions/bluetooth_permission_data.h" -#include "extensions/common/permissions/permissions_info.h" -#include "grit/generated_resources.h" -#include "ui/base/l10n/l10n_util.h" - -namespace extensions { - -BluetoothPermission::BluetoothPermission(const APIPermissionInfo* info) - : SetDisjunctionPermission<BluetoothPermissionData, - BluetoothPermission>(info) { -} - -BluetoothPermission::~BluetoothPermission() { -} - -bool BluetoothPermission::FromValue(const base::Value* value, - std::string* error) { - // Value may be omitted to gain access to non-profile functions. - if (!value) - return true; - - // Value may be an empty list for the same reason. - const base::ListValue* list = NULL; - if (value->GetAsList(&list) && list->GetSize() == 0) - return true; - - if (!SetDisjunctionPermission<BluetoothPermissionData, - BluetoothPermission>::FromValue(value, error)) { - return false; - } - - return true; -} - -PermissionMessages BluetoothPermission::GetMessages() const { - DCHECK(HasMessages()); - PermissionMessages result; - - result.push_back(PermissionMessage( - PermissionMessage::kBluetooth, - l10n_util::GetStringUTF16( - IDS_EXTENSION_PROMPT_WARNING_BLUETOOTH))); - - if (!data_set_.empty()) { - result.push_back(PermissionMessage( - PermissionMessage::kBluetoothDevices, - l10n_util::GetStringUTF16( - IDS_EXTENSION_PROMPT_WARNING_BLUETOOTH_DEVICES))); - } - - return result; -} - -} // namespace extensions diff --git a/chrome/common/extensions/permissions/bluetooth_permission.h b/chrome/common/extensions/permissions/bluetooth_permission.h deleted file mode 100644 index 8d0c009..0000000 --- a/chrome/common/extensions/permissions/bluetooth_permission.h +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright 2013 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. - -#ifndef CHROME_COMMON_EXTENSIONS_PERMISSIONS_BLUETOOTH_PERMISSION_H_ -#define CHROME_COMMON_EXTENSIONS_PERMISSIONS_BLUETOOTH_PERMISSION_H_ - -#include <string> - -#include "chrome/common/extensions/permissions/bluetooth_permission_data.h" -#include "chrome/common/extensions/permissions/set_disjunction_permission.h" -#include "extensions/common/permissions/api_permission.h" - -namespace extensions { - -// BluetoothPermission represents the permission to implement a specific -// Bluetooth Profile. -class BluetoothPermission - : public SetDisjunctionPermission<BluetoothPermissionData, - BluetoothPermission> { - public: - // A Bluetooth profile uuid that should be checked for permission to access. - struct CheckParam : APIPermission::CheckParam { - explicit CheckParam(std::string uuid) - : uuid(uuid) {} - const std::string uuid; - }; - - explicit BluetoothPermission(const APIPermissionInfo* info); - virtual ~BluetoothPermission(); - - // SetDisjunctionPermission overrides. - // BluetoothPermission permits an empty list for gaining permission to the - // Bluetooth APIs without implementing a profile. - virtual bool FromValue(const base::Value* value, - std::string* error) OVERRIDE; - - // APIPermission overrides - virtual PermissionMessages GetMessages() const OVERRIDE; -}; - -} // namespace extensions - -#endif // CHROME_COMMON_EXTENSIONS_PERMISSIONS_BLUETOOTH_PERMISSION_H_ diff --git a/chrome/common/extensions/permissions/bluetooth_permission_data.cc b/chrome/common/extensions/permissions/bluetooth_permission_data.cc deleted file mode 100644 index 70eb747..0000000 --- a/chrome/common/extensions/permissions/bluetooth_permission_data.cc +++ /dev/null @@ -1,73 +0,0 @@ -// Copyright 2013 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/common/extensions/permissions/bluetooth_permission_data.h" - -#include <string> - -#include "base/memory/scoped_ptr.h" -#include "base/values.h" -#include "chrome/common/extensions/permissions/bluetooth_permission.h" -#include "device/bluetooth/bluetooth_utils.h" - -namespace { - -const char* kUuidKey = "uuid"; - -} // namespace - -namespace extensions { - -BluetoothPermissionData::BluetoothPermissionData() {} - -BluetoothPermissionData::BluetoothPermissionData( - const std::string& uuid) : uuid_(uuid) { -} - -bool BluetoothPermissionData::Check( - const APIPermission::CheckParam* param) const { - if (!param) - return false; - const BluetoothPermission::CheckParam& specific_param = - *static_cast<const BluetoothPermission::CheckParam*>(param); - - std::string canonical_uuid = device::bluetooth_utils::CanonicalUuid(uuid_); - std::string canonical_param_uuid = device::bluetooth_utils::CanonicalUuid( - specific_param.uuid); - return canonical_uuid == canonical_param_uuid; -} - -scoped_ptr<base::Value> BluetoothPermissionData::ToValue() const { - base::DictionaryValue* result = new base::DictionaryValue(); - result->SetString(kUuidKey, uuid_); - return scoped_ptr<base::Value>(result); -} - -bool BluetoothPermissionData::FromValue(const base::Value* value) { - if (!value) - return false; - - const base::DictionaryValue* dict_value; - if (!value->GetAsDictionary(&dict_value)) - return false; - - if (!dict_value->GetString(kUuidKey, &uuid_)) { - uuid_.clear(); - return false; - } - - return true; -} - -bool BluetoothPermissionData::operator<( - const BluetoothPermissionData& rhs) const { - return uuid_ < rhs.uuid_; -} - -bool BluetoothPermissionData::operator==( - const BluetoothPermissionData& rhs) const { - return uuid_ == rhs.uuid_; -} - -} // namespace extensions diff --git a/chrome/common/extensions/permissions/bluetooth_permission_data.h b/chrome/common/extensions/permissions/bluetooth_permission_data.h deleted file mode 100644 index 25413d4..0000000 --- a/chrome/common/extensions/permissions/bluetooth_permission_data.h +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright 2013 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. - -#ifndef CHROME_COMMON_EXTENSIONS_PERMISSIONS_BLUETOOTH_PERMISSION_DATA_H_ -#define CHROME_COMMON_EXTENSIONS_PERMISSIONS_BLUETOOTH_PERMISSION_DATA_H_ - -#include <string> - -#include "base/memory/scoped_ptr.h" -#include "extensions/common/permissions/api_permission.h" - -namespace base { - -class Value; - -} // namespace base - -namespace extensions { - -// A pattern that can be used to match a Bluetooth profile permission, must be -// of a format that can be passed to device::bluetooth_utils::CanonoicalUuid(). -class BluetoothPermissionData { - public: - BluetoothPermissionData(); - explicit BluetoothPermissionData(const std::string& uuid); - - // Check if |param| (which must be a BluetoothPermission::CheckParam) - // matches the uuid of this object. - bool Check(const APIPermission::CheckParam* param) const; - - // Convert |this| into a base::Value. - scoped_ptr<base::Value> ToValue() const; - - // Populate |this| from a base::Value. - bool FromValue(const base::Value* value); - - bool operator<(const BluetoothPermissionData& rhs) const; - bool operator==(const BluetoothPermissionData& rhs) const; - - // The uuid |this| matches against. - const std::string& uuid() const { return uuid_; } - - // This accessor is provided for IPC_STRUCT_TRAITS_MEMBER. Please - // think twice before using it for anything else. - std::string& uuid() { return uuid_; } - - private: - std::string uuid_; -}; - -} // namespace extensions - -#endif // CHROME_COMMON_EXTENSIONS_PERMISSIONS_BLUETOOTH_PERMISSION_DATA_H_ diff --git a/chrome/common/extensions/permissions/chrome_api_permissions.cc b/chrome/common/extensions/permissions/chrome_api_permissions.cc index d63276b..b192ea5 100644 --- a/chrome/common/extensions/permissions/chrome_api_permissions.cc +++ b/chrome/common/extensions/permissions/chrome_api_permissions.cc @@ -4,7 +4,6 @@ #include "chrome/common/extensions/permissions/chrome_api_permissions.h" -#include "chrome/common/extensions/permissions/bluetooth_permission.h" #include "chrome/common/extensions/permissions/media_galleries_permission.h" #include "chrome/common/extensions/permissions/socket_permission.h" #include "chrome/common/extensions/permissions/usb_device_permission.h" @@ -334,13 +333,6 @@ std::vector<APIPermissionInfo*> ChromeAPIPermissions::GetAllPermissions() &CreateAPIPermission<MediaGalleriesPermission> }, { APIPermission::kPushMessaging, "pushMessaging", APIPermissionInfo::kFlagCannotBeOptional }, - // Because warning messages for the "bluetooth" permission vary based on - // the permissions parameters, no message ID or message text is specified - // here. The message ID and text used will be determined at run-time in the - // |BluetoothPermission| class. - { APIPermission::kBluetooth, "bluetooth", APIPermissionInfo::kFlagNone, - 0, PermissionMessage::kNone, - &CreateAPIPermission<BluetoothPermission> }, { APIPermission::kUsb, "usb", APIPermissionInfo::kFlagNone, IDS_EXTENSION_PROMPT_WARNING_USB, PermissionMessage::kUsb }, diff --git a/chrome/common/extensions/permissions/permission_set_unittest.cc b/chrome/common/extensions/permissions/permission_set_unittest.cc index 06f9e40..03481b7 100644 --- a/chrome/common/extensions/permissions/permission_set_unittest.cc +++ b/chrome/common/extensions/permissions/permission_set_unittest.cc @@ -746,7 +746,6 @@ TEST(PermissionsTest, PermissionMessages) { skip.insert(APIPermission::kDevtools); // Platform apps. - skip.insert(APIPermission::kBluetooth); skip.insert(APIPermission::kFileSystem); skip.insert(APIPermission::kFileSystemProvider); skip.insert(APIPermission::kFileSystemRetainEntries); diff --git a/chrome/test/data/extensions/activity_log_app/manifest.json b/chrome/test/data/extensions/activity_log_app/manifest.json index b05ad63..92bb0a5 100644 --- a/chrome/test/data/extensions/activity_log_app/manifest.json +++ b/chrome/test/data/extensions/activity_log_app/manifest.json @@ -7,5 +7,5 @@ "scripts": ["background.js"] } }, - "permissions": ["bluetooth"] + "bluetooth": {} } diff --git a/chrome/test/data/extensions/api_test/bluetooth/discovery_callback/manifest.json b/chrome/test/data/extensions/api_test/bluetooth/discovery_callback/manifest.json index 05a99c6..be8a26d 100644 --- a/chrome/test/data/extensions/api_test/bluetooth/discovery_callback/manifest.json +++ b/chrome/test/data/extensions/api_test/bluetooth/discovery_callback/manifest.json @@ -8,5 +8,5 @@ "scripts": ["runtest.js"] } }, - "permissions": ["bluetooth"] + "bluetooth": {} } diff --git a/chrome/test/data/extensions/api_test/bluetooth/discovery_in_progress/manifest.json b/chrome/test/data/extensions/api_test/bluetooth/discovery_in_progress/manifest.json index 67836cb..8ee75df 100644 --- a/chrome/test/data/extensions/api_test/bluetooth/discovery_in_progress/manifest.json +++ b/chrome/test/data/extensions/api_test/bluetooth/discovery_in_progress/manifest.json @@ -8,5 +8,5 @@ "scripts": ["runtest.js"] } }, - "permissions": ["bluetooth"] + "bluetooth": {} } diff --git a/chrome/test/data/extensions/api_test/bluetooth/get_devices/manifest.json b/chrome/test/data/extensions/api_test/bluetooth/get_devices/manifest.json index 010a1ad..73b6cd3 100644 --- a/chrome/test/data/extensions/api_test/bluetooth/get_devices/manifest.json +++ b/chrome/test/data/extensions/api_test/bluetooth/get_devices/manifest.json @@ -7,5 +7,5 @@ "scripts": ["runtest.js"] } }, - "permissions": ["bluetooth"] + "bluetooth": {} } diff --git a/chrome/test/data/extensions/api_test/bluetooth/get_devices_error/manifest.json b/chrome/test/data/extensions/api_test/bluetooth/get_devices_error/manifest.json index 61f5a56..053cc6e 100644 --- a/chrome/test/data/extensions/api_test/bluetooth/get_devices_error/manifest.json +++ b/chrome/test/data/extensions/api_test/bluetooth/get_devices_error/manifest.json @@ -7,5 +7,5 @@ "scripts": ["runtest.js"] } }, - "permissions": ["bluetooth"] + "bluetooth": {} } diff --git a/chrome/test/data/extensions/api_test/bluetooth/get_profiles/manifest.json b/chrome/test/data/extensions/api_test/bluetooth/get_profiles/manifest.json index df41127..def4ade 100644 --- a/chrome/test/data/extensions/api_test/bluetooth/get_profiles/manifest.json +++ b/chrome/test/data/extensions/api_test/bluetooth/get_profiles/manifest.json @@ -7,5 +7,5 @@ "scripts": ["runtest.js"] } }, - "permissions": ["bluetooth"] + "bluetooth": {} } diff --git a/chrome/test/data/extensions/api_test/bluetooth/on_adapter_state_changed/manifest.json b/chrome/test/data/extensions/api_test/bluetooth/on_adapter_state_changed/manifest.json index 327b2b4..ec2a91c 100644 --- a/chrome/test/data/extensions/api_test/bluetooth/on_adapter_state_changed/manifest.json +++ b/chrome/test/data/extensions/api_test/bluetooth/on_adapter_state_changed/manifest.json @@ -8,5 +8,5 @@ "scripts": ["runtest.js"] } }, - "permissions": ["bluetooth"] + "bluetooth": {} } diff --git a/chrome/test/data/extensions/api_test/bluetooth/on_connection/manifest.json b/chrome/test/data/extensions/api_test/bluetooth/on_connection/manifest.json index 1de6f18..cc70491 100644 --- a/chrome/test/data/extensions/api_test/bluetooth/on_connection/manifest.json +++ b/chrome/test/data/extensions/api_test/bluetooth/on_connection/manifest.json @@ -8,9 +8,5 @@ "scripts": ["runtest.js"] } }, - "permissions": [ - {"bluetooth": [ - {"uuid": "1234"} - ]} - ] + "bluetooth": { "profiles": ["1234"] } } diff --git a/chrome/test/data/extensions/api_test/bluetooth/profiles/manifest.json b/chrome/test/data/extensions/api_test/bluetooth/profiles/manifest.json index 7302b00..58f3ccb 100644 --- a/chrome/test/data/extensions/api_test/bluetooth/profiles/manifest.json +++ b/chrome/test/data/extensions/api_test/bluetooth/profiles/manifest.json @@ -8,10 +8,10 @@ "scripts": ["runtest.js"] } }, - "permissions": [ - {"bluetooth": [ - {"uuid": "1234"}, - {"uuid": "5678"} - ]} - ] + "bluetooth": { + "profiles": [ + "1234", + "5678" + ] + } } diff --git a/chrome/test/ext_auto/auto_provider/manifest.json b/chrome/test/ext_auto/auto_provider/manifest.json index e0f29c3..6ecc2e2 100644 --- a/chrome/test/ext_auto/auto_provider/manifest.json +++ b/chrome/test/ext_auto/auto_provider/manifest.json @@ -15,7 +15,6 @@ "audioCapture", "autotestPrivate", "background", - "bluetooth", "bookmarkManagerPrivate", "bookmarks", "browsingData", @@ -78,5 +77,6 @@ "webRequest", "webRequestBlocking", "webview" - ] + ], + "bluetooth": {} } diff --git a/extensions/common/manifest_constants.cc b/extensions/common/manifest_constants.cc index ff6acb1..f7bf1f4 100644 --- a/extensions/common/manifest_constants.cc +++ b/extensions/common/manifest_constants.cc @@ -16,6 +16,7 @@ const char kBackgroundPage[] = "background.page"; const char kBackgroundPageLegacy[] = "background_page"; const char kBackgroundPersistent[] = "background.persistent"; const char kBackgroundScripts[] = "background.scripts"; +const char kBluetooth[] = "bluetooth"; const char kBookmarkUI[] = "chrome_settings_overrides.bookmarks_ui"; const char kBrowserAction[] = "browser_action"; const char kChromeURLOverrides[] = "chrome_url_overrides"; diff --git a/extensions/common/manifest_constants.h b/extensions/common/manifest_constants.h index f008281..a9c39fe 100644 --- a/extensions/common/manifest_constants.h +++ b/extensions/common/manifest_constants.h @@ -18,6 +18,7 @@ extern const char kBackgroundPage[]; extern const char kBackgroundPageLegacy[]; extern const char kBackgroundPersistent[]; extern const char kBackgroundScripts[]; +extern const char kBluetooth[]; extern const char kBookmarkUI[]; extern const char kBrowserAction[]; extern const char kBrowseURLs[]; diff --git a/extensions/common/permissions/api_permission.h b/extensions/common/permissions/api_permission.h index 6427e57..aaf1d6e 100644 --- a/extensions/common/permissions/api_permission.h +++ b/extensions/common/permissions/api_permission.h @@ -44,7 +44,6 @@ class APIPermission { kAudioCapture, kAutoTestPrivate, kBackground, - kBluetooth, kBookmark, kBookmarkManagerPrivate, kBrailleDisplayPrivate, |