diff --git a/app/generated_resources.grd b/app/generated_resources.grd index 3bce8a32e5bb..5748c3fd175c 100644 --- a/app/generated_resources.grd +++ b/app/generated_resources.grd @@ -10935,6 +10935,9 @@ Please help our engineers fix this problem. Tell us what happened right before y Watch + + Publish and retrieve files from IPFS + diff --git a/chromium_src/chrome/common/DEPS b/chromium_src/chrome/common/DEPS index 246eda060af2..0cd460876a8e 100644 --- a/chromium_src/chrome/common/DEPS +++ b/chromium_src/chrome/common/DEPS @@ -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 \ No newline at end of file diff --git a/chromium_src/chrome/common/extensions/permissions/chrome_api_permissions.cc b/chromium_src/chrome/common/extensions/permissions/chrome_api_permissions.cc new file mode 100644 index 000000000000..7a69efeb2668 --- /dev/null +++ b/chromium_src/chrome/common/extensions/permissions/chrome_api_permissions.cc @@ -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 +class PermissionsContainer { + public: + constexpr PermissionsContainer(base::span chromium, + base::span 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 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 + final_permissions(base::make_span(permissions_to_register), + base::make_span(brave_permissions_to_register)); + +} // namespace + +base::span GetPermissionInfos() { + return final_permissions.GetPermissionInfos(); +} + +} // namespace chrome_api_permissions +} // namespace extensions diff --git a/chromium_src/chrome/common/extensions/permissions/chrome_permission_message_rules.cc b/chromium_src/chrome/common/extensions/permissions/chrome_permission_message_rules.cc new file mode 100644 index 000000000000..b5c79979c58b --- /dev/null +++ b/chromium_src/chrome/common/extensions/permissions/chrome_permission_message_rules.cc @@ -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::GetAllRules() { + auto rules = ChromePermissionMessageRule::GetAllRules_ChromiumImpl(); + rules.push_back( + {IDS_EXTENSION_PROMPT_WARNING_IPFS, {APIPermission::kIpfs}, {}}); + return rules; +} + +} // namespace extensions diff --git a/chromium_src/chrome/common/extensions/permissions/chrome_permission_message_rules.h b/chromium_src/chrome/common/extensions/permissions/chrome_permission_message_rules.h new file mode 100644 index 000000000000..c17e8b179da2 --- /dev/null +++ b/chromium_src/chrome/common/extensions/permissions/chrome_permission_message_rules.h @@ -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 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_ diff --git a/chromium_src/extensions/common/permissions/api_permission.h b/chromium_src/extensions/common/permissions/api_permission.h new file mode 100644 index 000000000000..55a2f06b7d4a --- /dev/null +++ b/chromium_src/extensions/common/permissions/api_permission.h @@ -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_ diff --git a/common/extensions/api/_ipfs_api_features.json b/common/extensions/api/_ipfs_api_features.json index 2c7dbfae3833..b1aaec7677f1 100644 --- a/common/extensions/api/_ipfs_api_features.json +++ b/common/extensions/api/_ipfs_api_features.json @@ -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"] }] } diff --git a/common/extensions/api/_permission_features.json b/common/extensions/api/_permission_features.json index 0f3756a2a5e5..3549e110caba 100644 --- a/common/extensions/api/_permission_features.json +++ b/common/extensions/api/_permission_features.json @@ -20,5 +20,9 @@ "226CF815E39A363090A1E547D53063472B8279FA", // Media Router Release "A321D47A2B4CA86898167A55CA8B2E02385EA7CD" // Brave Shields ] - }] + }], + "ipfs": { + "channel": "stable", + "extension_types": ["extension"] + } } diff --git a/patches/extensions-common-permissions-api_permission.h.patch b/patches/extensions-common-permissions-api_permission.h.patch new file mode 100644 index 000000000000..fbdac904bc9b --- /dev/null +++ b/patches/extensions-common-permissions-api_permission.h.patch @@ -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).