Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ipfs api permission rule #8289

Merged
merged 1 commit into from
Mar 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/generated_resources.grd
Original file line number Diff line number Diff line change
Expand Up @@ -10935,6 +10935,9 @@ Please help our engineers fix this problem. Tell us what happened right before y
<message name="IDS_SHOW_KALEIDOSCOPE" desc="Menu item to launch the Brave watch feature">
Watch
</message>
<message name="IDS_EXTENSION_PROMPT_WARNING_IPFS" desc="Permisson string for access to ipfs api.">
Publish and retrieve files from IPFS
</message>
spylogsster marked this conversation as resolved.
Show resolved Hide resolved

<!-- BraveLabs bubble -->
<message name="IDS_CHROMELABS_RELAUNCH_BUTTON_LABEL" desc="Label on the button in the footer of the Brave Labs bubble which will relaunch the browser.">
Expand Down
2 changes: 2 additions & 0 deletions chromium_src/chrome/common/DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ include_rules = [
"+../../../../chrome/common",
"+../../../../../chrome/common/importer",
"+../../../../../chrome/common/media",
"+../../../../../../chrome/common/extensions/permissions",
"+brave/common",
"+chrome/common",
"+components/version_info",
]
6
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/* Copyright (c) 2021 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/. */

#define GetPermissionInfos GetPermissionInfos_ChromiumImpl
#include "../../../../../../chrome/common/extensions/permissions/chrome_api_permissions.cc"
#undef GetPermissionInfos

namespace extensions {
namespace chrome_api_permissions {

namespace {

constexpr APIPermissionInfo::InitInfo brave_permissions_to_register[] = {
{APIPermission::kIpfs, "ipfs",
APIPermissionInfo::kFlagImpliesFullURLAccess}};

// Merges Brave and Chrormium constant arrays to final list of permissions.
template <typename T, size_t N>
class PermissionsContainer {
public:
constexpr PermissionsContainer(base::span<const T> chromium,
base::span<const T> brave) {
CHECK(N == chromium.size() + brave.size());
size_t last_index = 0;
for (const auto& item : chromium) {
permissions_[last_index++] = item;
}
for (const auto& item : brave) {
permissions_[last_index++] = item;
}
}
base::span<const T> GetPermissionInfos() const {
return base::make_span(permissions_);
}

private:
T permissions_[N];
};

constexpr size_t PermissionsTotal = base::size(permissions_to_register) +
base::size(brave_permissions_to_register);

const PermissionsContainer<APIPermissionInfo::InitInfo, PermissionsTotal>
final_permissions(base::make_span(permissions_to_register),
base::make_span(brave_permissions_to_register));

} // namespace

base::span<const APIPermissionInfo::InitInfo> GetPermissionInfos() {
return final_permissions.GetPermissionInfos();
}

} // namespace chrome_api_permissions
} // namespace extensions
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/* Copyright (c) 2021 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/. */

#include "chrome/common/extensions/permissions/chrome_permission_message_rules.h"
#include "brave/grit/brave_generated_resources.h"

#define GetAllRules GetAllRules_ChromiumImpl
#include "../../../../../../chrome/common/extensions/permissions/chrome_permission_message_rules.cc"
#undef GetAllRules

namespace extensions {

// static
std::vector<ChromePermissionMessageRule>
ChromePermissionMessageRule::GetAllRules() {
auto rules = ChromePermissionMessageRule::GetAllRules_ChromiumImpl();
rules.push_back(
{IDS_EXTENSION_PROMPT_WARNING_IPFS, {APIPermission::kIpfs}, {}});
return rules;
}

} // namespace extensions
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* Copyright (c) 2021 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef BRAVE_CHROMIUM_SRC_CHROME_COMMON_EXTENSIONS_PERMISSIONS_CHROME_PERMISSION_MESSAGE_RULES_H_
#define BRAVE_CHROMIUM_SRC_CHROME_COMMON_EXTENSIONS_PERMISSIONS_CHROME_PERMISSION_MESSAGE_RULES_H_

#define GetAllRules \
GetAllRules_ChromiumImpl(); \
static std::vector<ChromePermissionMessageRule> GetAllRules
#include "../../../../../../chrome/common/extensions/permissions/chrome_permission_message_rules.h"
#undef GetAllRules

#endif // BRAVE_CHROMIUM_SRC_CHROME_COMMON_EXTENSIONS_PERMISSIONS_CHROME_PERMISSION_MESSAGE_RULES_H_
15 changes: 15 additions & 0 deletions chromium_src/extensions/common/permissions/api_permission.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* Copyright (c) 2021 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/. */

#ifndef BRAVE_CHROMIUM_SRC_EXTENSIONS_COMMON_PERMISSIONS_API_PERMISSION_H_
#define BRAVE_CHROMIUM_SRC_EXTENSIONS_COMMON_PERMISSIONS_API_PERMISSION_H_

#define BRAVE_PERMISSION_IDS kIpfs = 750,

#include "../../../../extensions/common/permissions/api_permission.h"

#undef BRAVE_PERMISSION_IDS

#endif // BRAVE_CHROMIUM_SRC_EXTENSIONS_COMMON_PERMISSIONS_API_PERMISSION_H_
30 changes: 30 additions & 0 deletions common/extensions/api/_ipfs_api_features.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,35 @@
"channel": "stable",
"contexts": ["blessed_extension"],
"allowlist": ["780BF954C0F7C586EA9662D4F967771F49CC2114", "FF32507DC3DB5DFFD1D6733187C84D4B74713D63", "A321D47A2B4CA86898167A55CA8B2E02385EA7CD"]
}],
"ipfs.resolveIPFSURI": [{
"channel": "stable",
"contexts": ["blessed_extension"],
"dependencies": ["permission:ipfs"]
},{
"channel": "stable",
"contexts": ["blessed_extension"],
"dependencies": [],
"allowlist": ["780BF954C0F7C586EA9662D4F967771F49CC2114", "FF32507DC3DB5DFFD1D6733187C84D4B74713D63", "A321D47A2B4CA86898167A55CA8B2E02385EA7CD"]
}],
"ipfs.getIPFSEnabled": [{
"channel": "stable",
"contexts": ["blessed_extension"],
"dependencies": ["permission:ipfs"]
},{
"channel": "stable",
"contexts": ["blessed_extension"],
"dependencies": [],
"allowlist": ["780BF954C0F7C586EA9662D4F967771F49CC2114", "FF32507DC3DB5DFFD1D6733187C84D4B74713D63", "A321D47A2B4CA86898167A55CA8B2E02385EA7CD"]
}],
"ipfs.getResolveMethodType": [{
"channel": "stable",
"contexts": ["blessed_extension"],
"dependencies": ["permission:ipfs"]
},{
"channel": "stable",
"contexts": ["blessed_extension"],
"dependencies": [],
"allowlist": ["780BF954C0F7C586EA9662D4F967771F49CC2114", "FF32507DC3DB5DFFD1D6733187C84D4B74713D63", "A321D47A2B4CA86898167A55CA8B2E02385EA7CD"]
}]
}
6 changes: 5 additions & 1 deletion common/extensions/api/_permission_features.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,9 @@
"226CF815E39A363090A1E547D53063472B8279FA", // Media Router Release
"A321D47A2B4CA86898167A55CA8B2E02385EA7CD" // Brave Shields
]
}]
}],
"ipfs": {
"channel": "stable",
"extension_types": ["extension"]
}
}
12 changes: 12 additions & 0 deletions patches/extensions-common-permissions-api_permission.h.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
diff --git a/extensions/common/permissions/api_permission.h b/extensions/common/permissions/api_permission.h
index 886adb61d224a1db57f38844748ddcf163840b18..2f6d333899b6cc49206de56ef4562a8b5c8d958a 100644
--- a/extensions/common/permissions/api_permission.h
+++ b/extensions/common/permissions/api_permission.h
@@ -272,6 +272,7 @@ class APIPermission {
kSearch = 228,
kTabGroups = 229,
kScripting = 230,
+ BRAVE_PERMISSION_IDS
// Last entry: Add new entries above and ensure to update the
// "ExtensionPermission3" enum in tools/metrics/histograms/enums.xml
// (by running update_extension_permission.py).