diff --git a/BUILD.gn b/BUILD.gn index 3eafaf96a0..7eb34dd57d 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", "//chrome/common:resources", "//chrome/renderer:resources", "//content:resources", diff --git a/atom/browser/BUILD.gn b/atom/browser/BUILD.gn index 1fdebf4bfe..a7a923f02d 100644 --- a/atom/browser/BUILD.gn +++ b/atom/browser/BUILD.gn @@ -306,11 +306,15 @@ source_set("browser") { } if (enable_extensions) { + deps += [ "//electron:brave_resources" ] + sources += [ "extensions/api/atom_extensions_api_client.cc", "extensions/api/atom_extensions_api_client.h", "extensions/atom_browser_client_extensions_part.cc", "extensions/atom_browser_client_extensions_part.h", + "extensions/atom_component_extensions.cc", + "extensions/atom_component_extensions.h", "extensions/atom_extension_host_delegate.cc", "extensions/atom_extension_host_delegate.h", "extensions/atom_extensions_network_delegate.cc", 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 <map> + +#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<base::FilePath, int> 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<base::FilePath, int>::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 4699941007..6732691d89 100644 --- a/atom/browser/extensions/atom_extensions_browser_client.cc +++ b/atom/browser/extensions/atom_extensions_browser_client.cc @@ -22,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" @@ -71,6 +72,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 { @@ -228,29 +230,11 @@ 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); process_manager_delegate_.reset(new AtomProcessManagerDelegate); - resource_manager_.reset(new AtomComponentExtensionResourceManager); + resource_manager_.reset(new ChromeComponentExtensionResourceManager); } AtomExtensionsBrowserClient::~AtomExtensionsBrowserClient() {} @@ -439,6 +423,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>, + api::CryptotokenPrivateCanOriginAssertAppIdFunction::function_name(), + api::CryptotokenPrivateCanOriginAssertAppIdFunction::histogram_value(), + }, + }; + + for (const auto& entry : chromeEntries) { + registry->Register(entry); + } } std::unique_ptr<RuntimeAPIDelegate> diff --git a/atom/browser/extensions/atom_extensions_browser_client.h b/atom/browser/extensions/atom_extensions_browser_client.h index 3411ad3b4e..66ef3f2733 100644 --- a/atom/browser/extensions/atom_extensions_browser_client.h +++ b/atom/browser/extensions/atom_extensions_browser_client.h @@ -14,6 +14,7 @@ #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" @@ -29,7 +30,6 @@ class BrowserContext; namespace extensions { class AtomProcessManagerDelegate; -class AtomComponentExtensionResourceManager; class ExtensionsAPIClient; // Implementation of BrowserClient for Chrome, which includes @@ -139,7 +139,7 @@ class AtomExtensionsBrowserClient : public ExtensionsBrowserClient { // Client for API implementations. std::unique_ptr<ExtensionsAPIClient> api_client_; - std::unique_ptr<AtomComponentExtensionResourceManager> resource_manager_; + std::unique_ptr<ChromeComponentExtensionResourceManager> resource_manager_; std::unique_ptr<ExtensionCache> extension_cache_; 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/brave/brave_resources.grd b/brave/brave_resources.grd index f64e253773..7773bfad00 100644 --- a/brave/brave_resources.grd +++ b/brave/brave_resources.grd @@ -22,6 +22,7 @@ <include name="IDR_CHROME_CONTENT_PLUGIN_MANIFEST_OVERLAY" file="${root_gen_dir}\chrome\app\chrome_content_plugin_manifest_overlay.json" type="BINDATA" /> <include name="IDR_CHROME_CONTENT_RENDERER_MANIFEST_OVERLAY" file="${root_gen_dir}\chrome\app\chrome_content_renderer_manifest_overlay.json" type="BINDATA" /> <include name="IDR_CHROME_CONTENT_UTILITY_MANIFEST_OVERLAY" file="${root_gen_dir}\chrome\app\chrome_content_utility_manifest_overlay.json" type="BINDATA" /> + <include name="IDR_CRYPTOTOKEN_MANIFEST" file="..\..\chrome\browser\resources\cryptotoken\manifest.json" type="BINDATA" /> </includes> </release> </grit> diff --git a/brave/browser/api/brave_api_extension.cc b/brave/browser/api/brave_api_extension.cc index 5a54cad7de..9abe79b079 100644 --- a/brave/browser/api/brave_api_extension.cc +++ b/brave/browser/api/brave_api_extension.cc @@ -9,16 +9,19 @@ #include <string> #include <vector> +#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" -#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 +31,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 +41,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 +107,17 @@ scoped_refptr<extensions::Extension> LoadExtension(const base::FilePath& path, return NULL; std::vector<extensions::InstallWarning> warnings; - if (!extensions::file_util::ValidateExtension(extension.get(), - error, - &warnings)) - return NULL; + + int 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(), + error, + &warnings)) { + return NULL; + } + } extension->AddInstallWarnings(warnings); return extension; @@ -155,6 +171,41 @@ Extension::~Extension() { } } +std::unique_ptr<base::DictionaryValue> Extension::LoadManifest( + const base::FilePath& extension_root, + std::string* error) { + int resource_id; + if (IsComponentExtension(extension_root, &resource_id)) { + const ResourceBundle& rb = ResourceBundle::GetSharedInstance(); + base::StringPiece manifest_contents = rb.GetRawDataResource(resource_id); + + JSONStringValueDeserializer deserializer(manifest_contents); + std::unique_ptr<base::Value> 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<base::DictionaryValue> manifest, extensions::Manifest::Location manifest_location, @@ -163,7 +214,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<Extension>, v8::Isolate* isolate_; // not owned BraveBrowserContext* browser_context_; + std::unique_ptr<base::DictionaryValue> LoadManifest(const base::FilePath& extension_root, std::string* error); + DISALLOW_COPY_AND_ASSIGN(Extension); }; diff --git a/chromium_src/BUILD.gn b/chromium_src/BUILD.gn index d30f13251d..96b7e567ff 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", @@ -504,10 +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/incognito_connectability.cc", "//chrome/browser/extensions/api/messaging/incognito_connectability.h", "//chrome/browser/extensions/api/messaging/chrome_messaging_delegate.cc", @@ -536,6 +543,7 @@ source_set("browser") { "//chrome/browser/extensions/api/tabs/tabs_constants.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/event_router_forwarder.cc", "//chrome/browser/extensions/event_router_forwarder.h", ] 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() { +} 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<component_updater::ComponentUpdateService> &, bool use_brave_server); + std::unique_ptr<ChromeDeviceClient> device_client_; + DISALLOW_COPY_AND_ASSIGN(MuonBrowserProcessImpl); };