From e1368f395b17b06aded37c477c296bac609245e0 Mon Sep 17 00:00:00 2001 From: Anthony Tseng Date: Fri, 28 Oct 2016 17:04:52 -0400 Subject: [PATCH] Add openOptionsPage binding fix https://github.com/brave/browser-laptop/issues/4700 Auditors: @bridiver, @jonathansampson --- atom/atom_resources.grd | 2 ++ atom/common/api/resources/_api_features.json | 4 ++++ atom/common/api/resources/context_menus_bindings.js | 11 +++++++++++ atom/common/api/resources/runtime_extra_bindings.js | 9 +++++++++ .../extensions/atom_extensions_dispatcher_delegate.cc | 3 +++ extensions.gyp | 2 ++ 6 files changed, 31 insertions(+) create mode 100644 atom/common/api/resources/runtime_extra_bindings.js diff --git a/atom/atom_resources.grd b/atom/atom_resources.grd index 06e11f80af..14ceccd637 100644 --- a/atom/atom_resources.grd +++ b/atom/atom_resources.grd @@ -36,6 +36,8 @@ + + diff --git a/atom/common/api/resources/_api_features.json b/atom/common/api/resources/_api_features.json index 78a0c14342..b70853476b 100644 --- a/atom/common/api/resources/_api_features.json +++ b/atom/common/api/resources/_api_features.json @@ -54,6 +54,10 @@ "channel": "stable", "contexts": ["blessed_extension"] }, + "runtimeExtra": { + "channel": "stable", + "contexts": ["blessed_extension"] + }, "windows": { "channel": "stable", "contexts": ["blessed_extension"] diff --git a/atom/common/api/resources/context_menus_bindings.js b/atom/common/api/resources/context_menus_bindings.js index 275aee60e7..ca6fe0e291 100644 --- a/atom/common/api/resources/context_menus_bindings.js +++ b/atom/common/api/resources/context_menus_bindings.js @@ -13,3 +13,14 @@ var binding = { } exports.binding = binding; + +// TODO (Anthony): Move this to separated binding +var runtime = require('runtime').binding +var tabs = require('tabs').binding + +runtime.openOptionsPage = function (cb) { + let manifest = runtime.getManifest() + let optionsPageURL = runtime.getURL(manifest.options_page) + tabs.create({url: optionsPageURL}) + cb && cb() +} diff --git a/atom/common/api/resources/runtime_extra_bindings.js b/atom/common/api/resources/runtime_extra_bindings.js new file mode 100644 index 0000000000..f7ebeec2e4 --- /dev/null +++ b/atom/common/api/resources/runtime_extra_bindings.js @@ -0,0 +1,9 @@ +var runtime = require('runtime').binding +var tabs = require('tabs').binding + +runtime.openOptionsPage = function (cb) { + let manifest = runtime.getManifest() + let optionsPageURL = runtime.getURL(manifest.options_page) + tabs.create({url: optionsPageURL}) + cb && cb() +} diff --git a/atom/renderer/extensions/atom_extensions_dispatcher_delegate.cc b/atom/renderer/extensions/atom_extensions_dispatcher_delegate.cc index acbe3be818..8e4ef73d25 100644 --- a/atom/renderer/extensions/atom_extensions_dispatcher_delegate.cc +++ b/atom/renderer/extensions/atom_extensions_dispatcher_delegate.cc @@ -73,6 +73,9 @@ void AtomExtensionsDispatcherDelegate::PopulateSourceMap( IDR_ATOM_WINDOWS_BINDINGS_JS); source_map->RegisterSource("app", IDR_ATOM_APP_BINDINGS_JS); + + source_map->RegisterSource("runtimeExtra", + IDR_ATOM_RUNTIME_EXTRA_BINDINGS_JS); } void AtomExtensionsDispatcherDelegate::RequireAdditionalModules( diff --git a/extensions.gyp b/extensions.gyp index 76716fcee6..b78dd3806e 100644 --- a/extensions.gyp +++ b/extensions.gyp @@ -46,6 +46,7 @@ 'atom/common/api/resources/ipc_bindings.js', 'atom/common/api/resources/ipc_utils.js', 'atom/common/api/resources/privacy_bindings.js', + 'atom/common/api/resources/runtime_extra_bindings.js', 'atom/common/api/resources/tabs_bindings.js', 'atom/common/api/resources/web_frame.json', 'atom/common/api/resources/web_frame_bindings.js', @@ -68,6 +69,7 @@ 'atom/common/api/resources/ipc_bindings.js', 'atom/common/api/resources/ipc_utils.js', 'atom/common/api/resources/privacy_bindings.js', + 'atom/common/api/resources/runtime_extra_bindings.js', 'atom/common/api/resources/tabs_bindings.js', 'atom/common/api/resources/web_frame.json', 'atom/common/api/resources/web_frame_bindings.js',