From b39c033825b9eb4108b2d220efedddf30ec3e3c6 Mon Sep 17 00:00:00 2001 From: eV Date: Sat, 29 Jul 2017 07:36:36 +0000 Subject: [PATCH 1/5] add cryptotokenPrivate, windows.get for u2f --- .../atom_extensions_browser_client.cc | 16 +++++++++++ atom/common/api/resources/windows_bindings.js | 6 +++- chromium_src/BUILD.gn | 15 ++++++++++ lib/browser/api/extensions.js | 28 ++++++++++++++++++- muon/browser/muon_browser_process_impl.cc | 3 ++ muon/browser/muon_browser_process_impl.h | 4 +++ 6 files changed, 70 insertions(+), 2 deletions(-) diff --git a/atom/browser/extensions/atom_extensions_browser_client.cc b/atom/browser/extensions/atom_extensions_browser_client.cc index 4699941007..7e3bc6a6f9 100644 --- a/atom/browser/extensions/atom_extensions_browser_client.cc +++ b/atom/browser/extensions/atom_extensions_browser_client.cc @@ -71,6 +71,7 @@ #include "electron/brave/common/extensions/api/generated_api_registration.h" #include "extensions/browser/api/generated_api_registration.h" +#include "chrome/browser/extensions/api/cryptotoken_private/cryptotoken_private_api.h" namespace { @@ -439,6 +440,21 @@ void AtomExtensionsBrowserClient::RegisterExtensionFunctions( ExtensionFunctionRegistry* registry) const { api::GeneratedFunctionRegistry::RegisterAll(registry); api::BraveGeneratedFunctionRegistry::RegisterAll(registry); + + // Instead of registering all Chrome extension functions, + // via api::ChromeGeneratedFunctionRegistry::RegisterAll(registry) + // explicitly register just the ones we want + constexpr ExtensionFunctionRegistry::FactoryEntry chromeEntries[] = { + { + &NewExtensionFunction, + api::CryptotokenPrivateCanOriginAssertAppIdFunction::function_name(), + api::CryptotokenPrivateCanOriginAssertAppIdFunction::histogram_value(), + }, + }; + + for (const auto& entry : chromeEntries) { + registry->Register(entry); + } } std::unique_ptr diff --git a/atom/common/api/resources/windows_bindings.js b/atom/common/api/resources/windows_bindings.js index 84bcf1acf6..4daa9fbf60 100644 --- a/atom/common/api/resources/windows_bindings.js +++ b/atom/common/api/resources/windows_bindings.js @@ -23,7 +23,11 @@ binding.registerCustomHook(function (bindingsAPI, extensionId) { }) apiFunctions.setHandleRequest('get', function (windowId, getInfo, cb) { - console.warn('chrome.windows.get is not supported yet') + var responseId = ipc.guid() + ipc.once('chrome-windows-get-response-' + responseId, function (evt, win) { + cb(win) + }) + ipc.send('chrome-windows-get', responseId, windowId, getInfo) }) apiFunctions.setHandleRequest('create', function (createData, cb) { diff --git a/chromium_src/BUILD.gn b/chromium_src/BUILD.gn index d30f13251d..2b2f3c76b9 100644 --- a/chromium_src/BUILD.gn +++ b/chromium_src/BUILD.gn @@ -187,6 +187,9 @@ source_set("browser") { "chrome/browser/background/background_mode_manager.cc", "//chrome/browser/background/background_mode_manager.h", + "//chrome/browser/chrome_device_client.cc", + "//chrome/browser/chrome_device_client.h", + # extensions "//chrome/browser/extensions/global_shortcut_listener.cc", "//chrome/browser/extensions/global_shortcut_listener.h", @@ -508,6 +511,10 @@ source_set("browser") { "//chrome/browser/extensions/extension_util.h", "chrome/browser/extensions/extension_tab_util.cc", "//chrome/browser/extensions/extension_tab_util.h", + "//chrome/browser/extensions/api/cryptotoken_private/cryptotoken_private_api.cc", + "//chrome/browser/extensions/api/cryptotoken_private/cryptotoken_private_api.h", + "//chrome/browser/extensions/api/messaging/extension_message_port.cc", + "//chrome/browser/extensions/api/messaging/extension_message_port.h", "chrome/browser/extensions/api/messaging/incognito_connectability.cc", "//chrome/browser/extensions/api/messaging/incognito_connectability.h", "//chrome/browser/extensions/api/messaging/chrome_messaging_delegate.cc", @@ -534,10 +541,18 @@ source_set("browser") { "//chrome/browser/extensions/api/spellcheck/spellcheck_api.h", "//chrome/browser/extensions/api/tabs/tabs_constants.cc", "//chrome/browser/extensions/api/tabs/tabs_constants.h", + "//chrome/browser/extensions/api/tabs/windows_util.cc", + "//chrome/browser/extensions/api/tabs/windows_util.h", "//chrome/browser/extensions/chrome_extension_api_frame_id_map_helper.cc", "//chrome/browser/extensions/chrome_extension_api_frame_id_map_helper.h", + "//chrome/browser/extensions/chrome_extension_function_details.cc", + "//chrome/browser/extensions/chrome_extension_function_details.h", "//chrome/browser/extensions/event_router_forwarder.cc", "//chrome/browser/extensions/event_router_forwarder.h", + "//chrome/browser/extensions/window_controller.cc", + "//chrome/browser/extensions/window_controller.h", + "//chrome/browser/extensions/window_controller_list.cc", + "//chrome/browser/extensions/window_controller_list.h", ] deps += [ diff --git a/lib/browser/api/extensions.js b/lib/browser/api/extensions.js index e4624619e8..69c12f79ed 100644 --- a/lib/browser/api/extensions.js +++ b/lib/browser/api/extensions.js @@ -634,6 +634,28 @@ ipcMain.on('chrome-windows-create', function (evt, responseId, createData) { process.emit('chrome-windows-create-action', responseId, createData, evt) }) +ipcMain.on('chrome-windows-get', function (evt, responseId, windowId, getInfo) { + var response = { + id: -1, + focused: false, + incognito: false // TODO(bridiver) + } + if (getInfo && getInfo.windowTypes) { + console.warn('getWindow with windowTypes not supported yet') + } + var win = BrowserWindow.fromId(windowId) + if (win) { + if (getInfo && getInfo.populate) { + response = windowInfo(win, getInfo.populate) + } else { + response = windowInfo(win, false) + } + } + + evt.sender.send('chrome-windows-get-response-' + responseId, + response) +}) + ipcMain.on('chrome-windows-get-current', function (evt, responseId, getInfo) { var response = { id: -1, @@ -657,7 +679,11 @@ ipcMain.on('chrome-windows-get-all', function (evt, responseId, getInfo) { console.warn('getWindow with windowTypes not supported yet') } var response = BrowserWindow.getAllWindows().map((win) => { - return windowInfo(win, getInfo.populate) + if (getInfo && getInfo.populate) { + return windowInfo(win, getInfo.populate) + } else { + return windowInfo(win, false) + } }) evt.sender.send('chrome-windows-get-all-response-' + responseId, diff --git a/muon/browser/muon_browser_process_impl.cc b/muon/browser/muon_browser_process_impl.cc index 20b9a7b041..cc7ad1ccd3 100644 --- a/muon/browser/muon_browser_process_impl.cc +++ b/muon/browser/muon_browser_process_impl.cc @@ -7,6 +7,7 @@ #include "atom/browser/api/atom_api_app.h" #include "atom/browser/atom_resource_dispatcher_host_delegate.h" #include "brave/browser/component_updater/brave_component_updater_configurator.h" +#include "chrome/browser/chrome_device_client.h" #include "chrome/browser/io_thread.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile_manager.h" @@ -19,6 +20,8 @@ MuonBrowserProcessImpl::MuonBrowserProcessImpl( const base::CommandLine& command_line) : BrowserProcessImpl(local_state_task_runner, command_line) { g_browser_process = this; + + device_client_.reset(new ChromeDeviceClient); } MuonBrowserProcessImpl::~MuonBrowserProcessImpl() { diff --git a/muon/browser/muon_browser_process_impl.h b/muon/browser/muon_browser_process_impl.h index 5d4de792fe..188858b417 100644 --- a/muon/browser/muon_browser_process_impl.h +++ b/muon/browser/muon_browser_process_impl.h @@ -8,6 +8,8 @@ #include "build/build_config.h" #include "chrome/browser/browser_process_impl.h" +class ChromeDeviceClient; + namespace atom { namespace api { class App; @@ -46,6 +48,8 @@ class MuonBrowserProcessImpl : public BrowserProcessImpl { std::unique_ptr &, bool use_brave_server); + std::unique_ptr device_client_; + DISALLOW_COPY_AND_ASSIGN(MuonBrowserProcessImpl); }; From 9cd49b489d85dcacd6a94ba6fe5a3db57e48e81c Mon Sep 17 00:00:00 2001 From: eV Date: Wed, 16 Aug 2017 05:27:19 +0000 Subject: [PATCH 2/5] Allow loading cryptotoken extension from pak via brave extension API --- BUILD.gn | 2 + atom/browser/BUILD.gn | 2 + ...om_component_extension_resource_manager.cc | 71 +++++++++++++++ ...tom_component_extension_resource_manager.h | 43 ++++++++++ .../atom_extensions_browser_client.cc | 19 +--- .../atom_extensions_browser_client.h | 2 +- brave/brave_resources.grd | 1 + brave/browser/api/brave_api_extension.cc | 86 +++++++++++++++++-- brave/browser/api/brave_api_extension.h | 2 + 9 files changed, 200 insertions(+), 28 deletions(-) create mode 100644 atom/browser/extensions/atom_component_extension_resource_manager.cc create mode 100644 atom/browser/extensions/atom_component_extension_resource_manager.h diff --git a/BUILD.gn b/BUILD.gn index bf4d12bbe0..3c3ceb182e 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -114,6 +114,7 @@ repack("packed_extra_resources") { "$root_gen_dir/brave/brave_resources.pak", "$root_gen_dir/brave/brave_strings.pak", "$root_gen_dir/chrome/common_resources.pak", + "$root_gen_dir/chrome/component_extension_resources.pak", "$root_gen_dir/blink/public/resources/blink_resources.pak", "$root_gen_dir/content/app/strings/content_strings_en-US.pak", "$root_gen_dir/content/browser/tracing/tracing_resources.pak", @@ -130,6 +131,7 @@ repack("packed_extra_resources") { ":atom_resources", ":brave_resources", "app:brave_strings", + "//chrome/browser/resources:component_extension_resources_grit", "//chrome/common:resources", "//chrome/renderer:resources", "//content:resources", diff --git a/atom/browser/BUILD.gn b/atom/browser/BUILD.gn index c8cadb33a5..c5aeb67f4b 100644 --- a/atom/browser/BUILD.gn +++ b/atom/browser/BUILD.gn @@ -310,6 +310,8 @@ source_set("browser") { "extensions/api/atom_extensions_api_client.h", "extensions/atom_browser_client_extensions_part.cc", "extensions/atom_browser_client_extensions_part.h", + "extensions/atom_component_extension_resource_manager.cc", + "extensions/atom_component_extension_resource_manager.h", "extensions/atom_extension_api_frame_id_map.cc", "extensions/atom_extension_api_frame_id_map.h", "extensions/atom_extension_api_frame_id_map_helper_impl.cc", diff --git a/atom/browser/extensions/atom_component_extension_resource_manager.cc b/atom/browser/extensions/atom_component_extension_resource_manager.cc new file mode 100644 index 0000000000..c99b0984dd --- /dev/null +++ b/atom/browser/extensions/atom_component_extension_resource_manager.cc @@ -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. + +#include "atom/browser/extensions/atom_component_extension_resource_manager.h" + +#include "base/logging.h" +#include "base/macros.h" +#include "base/path_service.h" +#include "build/build_config.h" +#include "brave/grit/brave_resources.h" +#include "chrome/common/chrome_paths.h" +#include "chrome/grit/component_extension_resources_map.h" + +namespace extensions { + +AtomComponentExtensionResourceManager:: +AtomComponentExtensionResourceManager() { + static const GritResourceMap kExtraComponentExtensionResources[] = { + {"cryptotoken/manifest.json", IDR_CRYPTOTOKEN_MANIFEST}, + }; + + AddComponentResourceEntries( + kComponentExtensionResources, + kComponentExtensionResourcesSize); + AddComponentResourceEntries( + kExtraComponentExtensionResources, + arraysize(kExtraComponentExtensionResources)); +} + +AtomComponentExtensionResourceManager:: +~AtomComponentExtensionResourceManager() {} + +bool AtomComponentExtensionResourceManager::IsComponentExtensionResource( + const base::FilePath& extension_path, + const base::FilePath& resource_path, + int* resource_id) const { + base::FilePath directory_path = extension_path; + base::FilePath resources_dir; + base::FilePath relative_path; + + if (!PathService::Get(chrome::DIR_RESOURCES, &resources_dir) || + !resources_dir.AppendRelativePath(directory_path, &relative_path)) { + return false; + } + relative_path = relative_path.Append(resource_path); + relative_path = relative_path.NormalizePathSeparators(); + + std::map::const_iterator entry = + path_to_resource_id_.find(relative_path); + if (entry != path_to_resource_id_.end()) + *resource_id = entry->second; + + return entry != path_to_resource_id_.end(); +} + +void AtomComponentExtensionResourceManager::AddComponentResourceEntries( + const GritResourceMap* entries, + size_t size) { + for (size_t i = 0; i < size; ++i) { + base::FilePath resource_path = base::FilePath().AppendASCII( + entries[i].name); + resource_path = resource_path.NormalizePathSeparators(); + + DCHECK(path_to_resource_id_.find(resource_path) == + path_to_resource_id_.end()); + path_to_resource_id_[resource_path] = entries[i].value; + } +} + +} // namespace extensions diff --git a/atom/browser/extensions/atom_component_extension_resource_manager.h b/atom/browser/extensions/atom_component_extension_resource_manager.h new file mode 100644 index 0000000000..22ceee6ffd --- /dev/null +++ b/atom/browser/extensions/atom_component_extension_resource_manager.h @@ -0,0 +1,43 @@ +// 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 ATOM_BROWSER_EXTENSIONS_CHROME_COMPONENT_EXTENSION_RESOURCE_MANAGER_H_ +#define ATOM_BROWSER_EXTENSIONS_CHROME_COMPONENT_EXTENSION_RESOURCE_MANAGER_H_ + +#include + +#include + +#include "base/files/file_path.h" +#include "base/macros.h" +#include "extensions/browser/component_extension_resource_manager.h" + +struct GritResourceMap; + +namespace extensions { + +class AtomComponentExtensionResourceManager + : public ComponentExtensionResourceManager { + public: + AtomComponentExtensionResourceManager(); + ~AtomComponentExtensionResourceManager() override; + + // Overridden from ComponentExtensionResourceManager: + bool IsComponentExtensionResource(const base::FilePath& extension_path, + const base::FilePath& resource_path, + int* resource_id) const override; + + private: + void AddComponentResourceEntries(const GritResourceMap* entries, size_t size); + + // A map from a resource path to the resource ID. Used by + // IsComponentExtensionResource. + std::map path_to_resource_id_; + + DISALLOW_COPY_AND_ASSIGN(AtomComponentExtensionResourceManager); +}; + +} // namespace extensions + +#endif // ATOM_BROWSER_EXTENSIONS_CHROME_COMPONENT_EXTENSION_RESOURCE_MANAGER_H_ diff --git a/atom/browser/extensions/atom_extensions_browser_client.cc b/atom/browser/extensions/atom_extensions_browser_client.cc index 7e3bc6a6f9..01a0d2de91 100644 --- a/atom/browser/extensions/atom_extensions_browser_client.cc +++ b/atom/browser/extensions/atom_extensions_browser_client.cc @@ -8,6 +8,7 @@ #include "atom/browser/browser.h" #include "atom/browser/extensions/api/atom_extensions_api_client.h" +#include "atom/browser/extensions/atom_component_extension_resource_manager.h" #include "atom/browser/extensions/atom_extension_host_delegate.h" #include "atom/browser/extensions/atom_extension_system_factory.h" #include "atom/browser/extensions/atom_extension_web_contents_observer.h" @@ -229,24 +230,6 @@ class AtomRuntimeAPIDelegate : public RuntimeAPIDelegate { DISALLOW_COPY_AND_ASSIGN(AtomRuntimeAPIDelegate); }; -class AtomComponentExtensionResourceManager - : public ComponentExtensionResourceManager { - public: - AtomComponentExtensionResourceManager() {} - ~AtomComponentExtensionResourceManager() override {}; - - bool IsComponentExtensionResource( - const base::FilePath& extension_path, - const base::FilePath& resource_path, - int* resource_id) const override { - // TODO(bridiver) - bundle extension resources - return false; - }; - - private: - DISALLOW_COPY_AND_ASSIGN(AtomComponentExtensionResourceManager); -}; - AtomExtensionsBrowserClient::AtomExtensionsBrowserClient() : extension_cache_(new NullExtensionCache()) { api_client_.reset(new AtomExtensionsAPIClient); diff --git a/atom/browser/extensions/atom_extensions_browser_client.h b/atom/browser/extensions/atom_extensions_browser_client.h index 3411ad3b4e..8c86fea458 100644 --- a/atom/browser/extensions/atom_extensions_browser_client.h +++ b/atom/browser/extensions/atom_extensions_browser_client.h @@ -9,6 +9,7 @@ #include #include +#include "atom/browser/extensions/atom_component_extension_resource_manager.h" #include "base/compiler_specific.h" #include "base/lazy_instance.h" #include "base/macros.h" @@ -29,7 +30,6 @@ class BrowserContext; namespace extensions { class AtomProcessManagerDelegate; -class AtomComponentExtensionResourceManager; class ExtensionsAPIClient; // Implementation of BrowserClient for Chrome, which includes diff --git a/brave/brave_resources.grd b/brave/brave_resources.grd index f64e253773..8266c4f0d4 100644 --- a/brave/brave_resources.grd +++ b/brave/brave_resources.grd @@ -22,6 +22,7 @@ + diff --git a/brave/browser/api/brave_api_extension.cc b/brave/browser/api/brave_api_extension.cc index 5a54cad7de..39e5f36168 100644 --- a/brave/browser/api/brave_api_extension.cc +++ b/brave/browser/api/brave_api_extension.cc @@ -12,13 +12,15 @@ #include "atom/browser/extensions/atom_extension_system.h" #include "atom/browser/extensions/tab_helper.h" #include "atom/common/api/event_emitter_caller.h" -#include "brave/common/converters/callback_converter.h" -#include "brave/common/converters/gurl_converter.h" -#include "brave/common/converters/file_path_converter.h" -#include "brave/common/converters/value_converter.h" #include "atom/common/node_includes.h" #include "base/files/file_path.h" +#include "base/json/json_string_value_serializer.h" #include "base/strings/string_util.h" +#include "brave/common/converters/callback_converter.h" +#include "brave/common/converters/file_path_converter.h" +#include "brave/common/converters/gurl_converter.h" +#include "brave/common/converters/value_converter.h" +#include "chrome/common/chrome_paths.h" #include "components/prefs/pref_service.h" #include "components/user_prefs/user_prefs.h" #include "content/public/browser/browser_thread.h" @@ -28,6 +30,7 @@ #include "content/public/browser/web_contents.h" #include "content/public/child/v8_value_converter.h" #include "content/public/common/url_constants.h" +#include "extensions/browser/component_extension_resource_manager.h" #include "extensions/browser/extension_host.h" #include "extensions/browser/extension_registry.h" #include "extensions/browser/extension_system.h" @@ -37,9 +40,14 @@ #include "extensions/common/extension.h" #include "extensions/common/disable_reason.h" #include "extensions/common/file_util.h" +#include "extensions/common/manifest_constants.h" #include "extensions/common/manifest_handlers/background_info.h" #include "extensions/common/one_shot_event.h" +#include "extensions/strings/grit/extensions_strings.h" #include "gin/dictionary.h" +#include "ui/base/l10n/l10n_util.h" +#include "ui/base/resource/resource_bundle.h" + using base::Callback; using content::BrowserURLHandler; @@ -98,10 +106,26 @@ scoped_refptr LoadExtension(const base::FilePath& path, return NULL; std::vector warnings; - if (!extensions::file_util::ValidateExtension(extension.get(), - error, - &warnings)) - return NULL; + + int resource_id; + const extensions::ComponentExtensionResourceManager* + component_extension_resource_manager = + extensions::ExtensionsBrowserClient::Get() + ->GetComponentExtensionResourceManager(); + + if (!(component_extension_resource_manager && + component_extension_resource_manager->IsComponentExtensionResource( + path, + base::FilePath(extensions::kManifestFilename), + &resource_id))) { + // Component extensions contained inside the resources pak fail manifest validation + // so we skip validation. + if (!extensions::file_util::ValidateExtension(extension.get(), + error, + &warnings)) { + return NULL; + } + } extension->AddInstallWarnings(warnings); return extension; @@ -155,6 +179,50 @@ Extension::~Extension() { } } +std::unique_ptr Extension::LoadManifest( + const base::FilePath& extension_root, + std::string* error) { + int resource_id; + const extensions::ComponentExtensionResourceManager* + component_extension_resource_manager = + extensions::ExtensionsBrowserClient::Get() + ->GetComponentExtensionResourceManager(); + + if (component_extension_resource_manager && + component_extension_resource_manager->IsComponentExtensionResource( + extension_root, + base::FilePath(extensions::kManifestFilename), + &resource_id)) { + const ResourceBundle& rb = ResourceBundle::GetSharedInstance(); + base::StringPiece manifest_contents = rb.GetRawDataResource(resource_id); + + JSONStringValueDeserializer deserializer(manifest_contents); + std::unique_ptr root(deserializer.Deserialize(NULL, error)); + if (!root.get()) { + if (error->empty()) { + // If |error| is empty, than the file could not be read. + // It would be cleaner to have the JSON reader give a specific error + // in this case, but other code tests for a file error with + // error->empty(). For now, be consistent. + *error = l10n_util::GetStringUTF8(IDS_EXTENSION_MANIFEST_UNREADABLE); + } else { + *error = base::StringPrintf( + "%s %s", extensions::manifest_errors::kManifestParseError, error->c_str()); + } + return NULL; + } + + if (!root->IsType(base::Value::Type::DICTIONARY)) { + *error = l10n_util::GetStringUTF8(IDS_EXTENSION_MANIFEST_INVALID); + return NULL; + } + + return base::DictionaryValue::From(std::move(root)); + } else { + return extensions::file_util::LoadManifest(extension_root, error); + } +} + void Extension::LoadOnFILEThread(const base::FilePath path, std::unique_ptr manifest, extensions::Manifest::Location manifest_location, @@ -163,7 +231,7 @@ void Extension::LoadOnFILEThread(const base::FilePath path, std::string error; if (manifest->empty()) { - manifest = extensions::file_util::LoadManifest(path, &error); + manifest = LoadManifest(path, &error); } if (!manifest || !error.empty()) { diff --git a/brave/browser/api/brave_api_extension.h b/brave/browser/api/brave_api_extension.h index 2faf06677d..fe5e942a41 100644 --- a/brave/browser/api/brave_api_extension.h +++ b/brave/browser/api/brave_api_extension.h @@ -82,6 +82,8 @@ class Extension : public gin::Wrappable, v8::Isolate* isolate_; // not owned BraveBrowserContext* browser_context_; + std::unique_ptr LoadManifest(const base::FilePath& extension_root, std::string* error); + DISALLOW_COPY_AND_ASSIGN(Extension); }; From efa647be6a37698c46f766a9192a6482fcb6a513 Mon Sep 17 00:00:00 2001 From: eV Date: Thu, 21 Dec 2017 18:58:53 +0000 Subject: [PATCH 3/5] address review comments --- BUILD.gn | 2 +- atom/browser/BUILD.gn | 4 +- ...om_component_extension_resource_manager.cc | 71 ------------------- ...tom_component_extension_resource_manager.h | 43 ----------- .../extensions/atom_component_extensions.cc | 32 +++++++++ .../extensions/atom_component_extensions.h | 13 ++++ .../atom_extensions_browser_client.cc | 4 +- .../atom_extensions_browser_client.h | 4 +- brave/brave_resources.grd | 2 +- brave/browser/api/brave_api_extension.cc | 23 +----- chromium_src/BUILD.gn | 13 +--- .../chrome_extension_function_details.cc | 15 ++++ 12 files changed, 74 insertions(+), 152 deletions(-) delete mode 100644 atom/browser/extensions/atom_component_extension_resource_manager.cc delete mode 100644 atom/browser/extensions/atom_component_extension_resource_manager.h create mode 100644 atom/browser/extensions/atom_component_extensions.cc create mode 100644 atom/browser/extensions/atom_component_extensions.h create mode 100644 chromium_src/chrome/browser/extensions/chrome_extension_function_details.cc diff --git a/BUILD.gn b/BUILD.gn index 3c3ceb182e..c3aee917bd 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -131,7 +131,7 @@ repack("packed_extra_resources") { ":atom_resources", ":brave_resources", "app:brave_strings", - "//chrome/browser/resources:component_extension_resources_grit", + "//chrome/browser/resources:component_extension_resources", "//chrome/common:resources", "//chrome/renderer:resources", "//content:resources", diff --git a/atom/browser/BUILD.gn b/atom/browser/BUILD.gn index c5aeb67f4b..bdc7a66824 100644 --- a/atom/browser/BUILD.gn +++ b/atom/browser/BUILD.gn @@ -310,8 +310,8 @@ source_set("browser") { "extensions/api/atom_extensions_api_client.h", "extensions/atom_browser_client_extensions_part.cc", "extensions/atom_browser_client_extensions_part.h", - "extensions/atom_component_extension_resource_manager.cc", - "extensions/atom_component_extension_resource_manager.h", + "extensions/atom_component_extensions.cc", + "extensions/atom_component_extensions.h", "extensions/atom_extension_api_frame_id_map.cc", "extensions/atom_extension_api_frame_id_map.h", "extensions/atom_extension_api_frame_id_map_helper_impl.cc", diff --git a/atom/browser/extensions/atom_component_extension_resource_manager.cc b/atom/browser/extensions/atom_component_extension_resource_manager.cc deleted file mode 100644 index c99b0984dd..0000000000 --- a/atom/browser/extensions/atom_component_extension_resource_manager.cc +++ /dev/null @@ -1,71 +0,0 @@ -// 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 "atom/browser/extensions/atom_component_extension_resource_manager.h" - -#include "base/logging.h" -#include "base/macros.h" -#include "base/path_service.h" -#include "build/build_config.h" -#include "brave/grit/brave_resources.h" -#include "chrome/common/chrome_paths.h" -#include "chrome/grit/component_extension_resources_map.h" - -namespace extensions { - -AtomComponentExtensionResourceManager:: -AtomComponentExtensionResourceManager() { - static const GritResourceMap kExtraComponentExtensionResources[] = { - {"cryptotoken/manifest.json", IDR_CRYPTOTOKEN_MANIFEST}, - }; - - AddComponentResourceEntries( - kComponentExtensionResources, - kComponentExtensionResourcesSize); - AddComponentResourceEntries( - kExtraComponentExtensionResources, - arraysize(kExtraComponentExtensionResources)); -} - -AtomComponentExtensionResourceManager:: -~AtomComponentExtensionResourceManager() {} - -bool AtomComponentExtensionResourceManager::IsComponentExtensionResource( - const base::FilePath& extension_path, - const base::FilePath& resource_path, - int* resource_id) const { - base::FilePath directory_path = extension_path; - base::FilePath resources_dir; - base::FilePath relative_path; - - if (!PathService::Get(chrome::DIR_RESOURCES, &resources_dir) || - !resources_dir.AppendRelativePath(directory_path, &relative_path)) { - return false; - } - relative_path = relative_path.Append(resource_path); - relative_path = relative_path.NormalizePathSeparators(); - - std::map::const_iterator entry = - path_to_resource_id_.find(relative_path); - if (entry != path_to_resource_id_.end()) - *resource_id = entry->second; - - return entry != path_to_resource_id_.end(); -} - -void AtomComponentExtensionResourceManager::AddComponentResourceEntries( - const GritResourceMap* entries, - size_t size) { - for (size_t i = 0; i < size; ++i) { - base::FilePath resource_path = base::FilePath().AppendASCII( - entries[i].name); - resource_path = resource_path.NormalizePathSeparators(); - - DCHECK(path_to_resource_id_.find(resource_path) == - path_to_resource_id_.end()); - path_to_resource_id_[resource_path] = entries[i].value; - } -} - -} // namespace extensions diff --git a/atom/browser/extensions/atom_component_extension_resource_manager.h b/atom/browser/extensions/atom_component_extension_resource_manager.h deleted file mode 100644 index 22ceee6ffd..0000000000 --- a/atom/browser/extensions/atom_component_extension_resource_manager.h +++ /dev/null @@ -1,43 +0,0 @@ -// 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 ATOM_BROWSER_EXTENSIONS_CHROME_COMPONENT_EXTENSION_RESOURCE_MANAGER_H_ -#define ATOM_BROWSER_EXTENSIONS_CHROME_COMPONENT_EXTENSION_RESOURCE_MANAGER_H_ - -#include - -#include - -#include "base/files/file_path.h" -#include "base/macros.h" -#include "extensions/browser/component_extension_resource_manager.h" - -struct GritResourceMap; - -namespace extensions { - -class AtomComponentExtensionResourceManager - : public ComponentExtensionResourceManager { - public: - AtomComponentExtensionResourceManager(); - ~AtomComponentExtensionResourceManager() override; - - // Overridden from ComponentExtensionResourceManager: - bool IsComponentExtensionResource(const base::FilePath& extension_path, - const base::FilePath& resource_path, - int* resource_id) const override; - - private: - void AddComponentResourceEntries(const GritResourceMap* entries, size_t size); - - // A map from a resource path to the resource ID. Used by - // IsComponentExtensionResource. - std::map path_to_resource_id_; - - DISALLOW_COPY_AND_ASSIGN(AtomComponentExtensionResourceManager); -}; - -} // namespace extensions - -#endif // ATOM_BROWSER_EXTENSIONS_CHROME_COMPONENT_EXTENSION_RESOURCE_MANAGER_H_ diff --git a/atom/browser/extensions/atom_component_extensions.cc b/atom/browser/extensions/atom_component_extensions.cc new file mode 100644 index 0000000000..90beb5050d --- /dev/null +++ b/atom/browser/extensions/atom_component_extensions.cc @@ -0,0 +1,32 @@ +#include "atom/browser/extensions/atom_component_extensions.h" + +#include + +#include "base/files/file_path.h" +#include "base/path_service.h" +#include "brave/grit/brave_resources.h" +#include "chrome/common/chrome_paths.h" + +static const std::map componentExtensionManifests = { + {base::FilePath("cryptotoken"), IDR_CRYPTOTOKEN_MANIFEST}, +}; + +bool IsComponentExtension(const base::FilePath& extension_path, int* resource_id) { + base::FilePath directory_path = extension_path; + base::FilePath resources_dir; + base::FilePath relative_path; + + if (!PathService::Get(chrome::DIR_RESOURCES, &resources_dir) || + !resources_dir.AppendRelativePath(directory_path, &relative_path)) { + return false; + } + relative_path = relative_path.NormalizePathSeparators(); + + std::map::const_iterator entry = + componentExtensionManifests.find(relative_path); + + if (entry != componentExtensionManifests.end()) + *resource_id = entry->second; + + return entry != componentExtensionManifests.end(); +} diff --git a/atom/browser/extensions/atom_component_extensions.h b/atom/browser/extensions/atom_component_extensions.h new file mode 100644 index 0000000000..77417d655d --- /dev/null +++ b/atom/browser/extensions/atom_component_extensions.h @@ -0,0 +1,13 @@ +/** @file atom_component_extensions.h + * @brief FIXME + * + * @author Evey Quirk + */ +#ifndef _ATOM_COMPONENT_EXTENSIONS_H +#define _ATOM_COMPONENT_EXTENSIONS_H + +#include "base/files/file_path.h" + +bool IsComponentExtension(const base::FilePath& extension_path, int* resource_id); + +#endif /* _ATOM_COMPONENT_EXTENSIONS_H */ diff --git a/atom/browser/extensions/atom_extensions_browser_client.cc b/atom/browser/extensions/atom_extensions_browser_client.cc index 01a0d2de91..6732691d89 100644 --- a/atom/browser/extensions/atom_extensions_browser_client.cc +++ b/atom/browser/extensions/atom_extensions_browser_client.cc @@ -8,7 +8,6 @@ #include "atom/browser/browser.h" #include "atom/browser/extensions/api/atom_extensions_api_client.h" -#include "atom/browser/extensions/atom_component_extension_resource_manager.h" #include "atom/browser/extensions/atom_extension_host_delegate.h" #include "atom/browser/extensions/atom_extension_system_factory.h" #include "atom/browser/extensions/atom_extension_web_contents_observer.h" @@ -23,6 +22,7 @@ #include "base/version.h" #include "brave/browser/brave_browser_context.h" #include "chrome/browser/browser_process.h" +#include "chrome/browser/extensions/chrome_component_extension_resource_manager.h" #include "chrome/browser/extensions/chrome_extension_api_frame_id_map_helper.h" #include "chrome/browser/extensions/event_router_forwarder.h" #include "chrome/browser/renderer_host/chrome_navigation_ui_data.h" @@ -234,7 +234,7 @@ AtomExtensionsBrowserClient::AtomExtensionsBrowserClient() : extension_cache_(new NullExtensionCache()) { api_client_.reset(new AtomExtensionsAPIClient); process_manager_delegate_.reset(new AtomProcessManagerDelegate); - resource_manager_.reset(new AtomComponentExtensionResourceManager); + resource_manager_.reset(new ChromeComponentExtensionResourceManager); } AtomExtensionsBrowserClient::~AtomExtensionsBrowserClient() {} diff --git a/atom/browser/extensions/atom_extensions_browser_client.h b/atom/browser/extensions/atom_extensions_browser_client.h index 8c86fea458..66ef3f2733 100644 --- a/atom/browser/extensions/atom_extensions_browser_client.h +++ b/atom/browser/extensions/atom_extensions_browser_client.h @@ -9,12 +9,12 @@ #include #include -#include "atom/browser/extensions/atom_component_extension_resource_manager.h" #include "base/compiler_specific.h" #include "base/lazy_instance.h" #include "base/macros.h" #include "base/memory/ref_counted.h" #include "build/build_config.h" +#include "chrome/browser/extensions/chrome_component_extension_resource_manager.h" #include "extensions/browser/extension_host_delegate.h" #include "extensions/browser/extensions_browser_client.h" #include "extensions/browser/kiosk/kiosk_delegate.h" @@ -139,7 +139,7 @@ class AtomExtensionsBrowserClient : public ExtensionsBrowserClient { // Client for API implementations. std::unique_ptr api_client_; - std::unique_ptr resource_manager_; + std::unique_ptr resource_manager_; std::unique_ptr extension_cache_; diff --git a/brave/brave_resources.grd b/brave/brave_resources.grd index 8266c4f0d4..7773bfad00 100644 --- a/brave/brave_resources.grd +++ b/brave/brave_resources.grd @@ -22,7 +22,7 @@ - + diff --git a/brave/browser/api/brave_api_extension.cc b/brave/browser/api/brave_api_extension.cc index 39e5f36168..9abe79b079 100644 --- a/brave/browser/api/brave_api_extension.cc +++ b/brave/browser/api/brave_api_extension.cc @@ -9,6 +9,7 @@ #include #include +#include "atom/browser/extensions/atom_component_extensions.h" #include "atom/browser/extensions/atom_extension_system.h" #include "atom/browser/extensions/tab_helper.h" #include "atom/common/api/event_emitter_caller.h" @@ -108,16 +109,7 @@ scoped_refptr LoadExtension(const base::FilePath& path, std::vector warnings; int resource_id; - const extensions::ComponentExtensionResourceManager* - component_extension_resource_manager = - extensions::ExtensionsBrowserClient::Get() - ->GetComponentExtensionResourceManager(); - - if (!(component_extension_resource_manager && - component_extension_resource_manager->IsComponentExtensionResource( - path, - base::FilePath(extensions::kManifestFilename), - &resource_id))) { + if (!IsComponentExtension(path, &resource_id)) { // Component extensions contained inside the resources pak fail manifest validation // so we skip validation. if (!extensions::file_util::ValidateExtension(extension.get(), @@ -183,16 +175,7 @@ std::unique_ptr Extension::LoadManifest( const base::FilePath& extension_root, std::string* error) { int resource_id; - const extensions::ComponentExtensionResourceManager* - component_extension_resource_manager = - extensions::ExtensionsBrowserClient::Get() - ->GetComponentExtensionResourceManager(); - - if (component_extension_resource_manager && - component_extension_resource_manager->IsComponentExtensionResource( - extension_root, - base::FilePath(extensions::kManifestFilename), - &resource_id)) { + if (IsComponentExtension(extension_root, &resource_id)) { const ResourceBundle& rb = ResourceBundle::GetSharedInstance(); base::StringPiece manifest_contents = rb.GetRawDataResource(resource_id); diff --git a/chromium_src/BUILD.gn b/chromium_src/BUILD.gn index 2b2f3c76b9..96b7e567ff 100644 --- a/chromium_src/BUILD.gn +++ b/chromium_src/BUILD.gn @@ -507,14 +507,14 @@ source_set("browser") { if (enable_extensions) { sources += [ + "//chrome/browser/extensions/chrome_component_extension_resource_manager.cc", + "//chrome/browser/extensions/chrome_component_extension_resource_manager.h", "chrome/browser/extensions/extension_util.cc", "//chrome/browser/extensions/extension_util.h", "chrome/browser/extensions/extension_tab_util.cc", "//chrome/browser/extensions/extension_tab_util.h", "//chrome/browser/extensions/api/cryptotoken_private/cryptotoken_private_api.cc", "//chrome/browser/extensions/api/cryptotoken_private/cryptotoken_private_api.h", - "//chrome/browser/extensions/api/messaging/extension_message_port.cc", - "//chrome/browser/extensions/api/messaging/extension_message_port.h", "chrome/browser/extensions/api/messaging/incognito_connectability.cc", "//chrome/browser/extensions/api/messaging/incognito_connectability.h", "//chrome/browser/extensions/api/messaging/chrome_messaging_delegate.cc", @@ -541,18 +541,11 @@ source_set("browser") { "//chrome/browser/extensions/api/spellcheck/spellcheck_api.h", "//chrome/browser/extensions/api/tabs/tabs_constants.cc", "//chrome/browser/extensions/api/tabs/tabs_constants.h", - "//chrome/browser/extensions/api/tabs/windows_util.cc", - "//chrome/browser/extensions/api/tabs/windows_util.h", "//chrome/browser/extensions/chrome_extension_api_frame_id_map_helper.cc", "//chrome/browser/extensions/chrome_extension_api_frame_id_map_helper.h", - "//chrome/browser/extensions/chrome_extension_function_details.cc", - "//chrome/browser/extensions/chrome_extension_function_details.h", + "chrome/browser/extensions/chrome_extension_function_details.cc", "//chrome/browser/extensions/event_router_forwarder.cc", "//chrome/browser/extensions/event_router_forwarder.h", - "//chrome/browser/extensions/window_controller.cc", - "//chrome/browser/extensions/window_controller.h", - "//chrome/browser/extensions/window_controller_list.cc", - "//chrome/browser/extensions/window_controller_list.h", ] deps += [ diff --git a/chromium_src/chrome/browser/extensions/chrome_extension_function_details.cc b/chromium_src/chrome/browser/extensions/chrome_extension_function_details.cc new file mode 100644 index 0000000000..4897b700a9 --- /dev/null +++ b/chromium_src/chrome/browser/extensions/chrome_extension_function_details.cc @@ -0,0 +1,15 @@ +// 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/browser/extensions/chrome_extension_function_details.h" + +#include "extensions/browser/extension_function.h" + +ChromeExtensionFunctionDetails::ChromeExtensionFunctionDetails( + UIThreadExtensionFunction* function) + : function_(function) { +} + +ChromeExtensionFunctionDetails::~ChromeExtensionFunctionDetails() { +} From 1c56f2fe8c947ef539ffd5b60af001c57edf18c2 Mon Sep 17 00:00:00 2001 From: eV Date: Tue, 2 Jan 2018 22:24:29 +0000 Subject: [PATCH 4/5] add data_dep for brave_resources --- atom/browser/BUILD.gn | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/atom/browser/BUILD.gn b/atom/browser/BUILD.gn index 904db5b345..21434b5e19 100644 --- a/atom/browser/BUILD.gn +++ b/atom/browser/BUILD.gn @@ -20,6 +20,8 @@ source_set("browser") { "//third_party/WebKit/public:blink_headers", ] + data_deps = [] + deps = [ "//electron:common", "//electron/muon/app", @@ -306,6 +308,8 @@ source_set("browser") { } if (enable_extensions) { + data_deps += [ "//electron:brave_resources" ] + sources += [ "extensions/api/atom_extensions_api_client.cc", "extensions/api/atom_extensions_api_client.h", From 50cd55911fa0e5c171d2a4a39ab7eaf1db564a7f Mon Sep 17 00:00:00 2001 From: eV Date: Fri, 5 Jan 2018 01:24:40 +0000 Subject: [PATCH 5/5] deps not data_deps --- atom/browser/BUILD.gn | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/atom/browser/BUILD.gn b/atom/browser/BUILD.gn index 21434b5e19..a7a923f02d 100644 --- a/atom/browser/BUILD.gn +++ b/atom/browser/BUILD.gn @@ -20,8 +20,6 @@ source_set("browser") { "//third_party/WebKit/public:blink_headers", ] - data_deps = [] - deps = [ "//electron:common", "//electron/muon/app", @@ -308,7 +306,7 @@ source_set("browser") { } if (enable_extensions) { - data_deps += [ "//electron:brave_resources" ] + deps += [ "//electron:brave_resources" ] sources += [ "extensions/api/atom_extensions_api_client.cc",