Bug 1723838 - WebIDL bindings for the 'dns' WebExtensions API namespace. r=willdurand,webidl,smaug

Differential Revision: https://phabricator.services.mozilla.com/D167594
This commit is contained in:
Luca Greco 2023-01-27 20:33:25 +00:00
Родитель fb2f3314d9
Коммит 487ce9d828
15 изменённых файлов: 180 добавлений и 14 удалений

Просмотреть файл

@ -1687,6 +1687,11 @@ DOMInterfaces = {
'nativeType': 'mozilla::extensions::ExtensionMockAPI',
},
'ExtensionDns': {
'headerFile': 'mozilla/extensions/ExtensionDns.h',
'nativeType': 'mozilla::extensions::ExtensionDns',
},
'ExtensionEventManager': {
'headerFile': 'mozilla/extensions/ExtensionEventManager.h',
'nativeType': 'mozilla::extensions::ExtensionEventManager',

Просмотреть файл

@ -35,6 +35,11 @@ interface ExtensionBrowser {
Func="mozilla::extensions::ExtensionAlarms::IsAllowed"]
readonly attribute ExtensionAlarms alarms;
// `browser.dns` API namespace
[Replaceable, SameObject, BinaryName="GetExtensionDns",
Func="mozilla::extensions::ExtensionDns::IsAllowed"]
readonly attribute ExtensionDns dns;
// `browser.runtime` API namespace
[Replaceable, SameObject, BinaryName="GetExtensionRuntime",
Func="mozilla::extensions::ExtensionRuntime::IsAllowed"]

Просмотреть файл

@ -0,0 +1,30 @@
/*
* THIS IS AN AUTOGENERATED FILE. DO NOT EDIT
*
* The content of this file has been generated based on the WebExtensions API
* JSONSchema using the following command:
*
* export SCRIPT_DIR="toolkit/components/extensions/webidl-api"
* mach python $SCRIPT_DIR/GenerateWebIDLBindings.py -- dns
*
* More info about generating webidl API bindings for WebExtensions API at:
*
* https://firefox-source-docs.mozilla.org/toolkit/components/extensions/webextensions/webidl_bindings.html
*/
/* 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/.
*
* You are granted a license to use, reproduce and create derivative works of
* this document.
*/
// WebIDL definition for the "dns" WebExtensions API
[Exposed=(ServiceWorker), LegacyNoInterfaceObject]
interface ExtensionDns {
// API methods.
[Throws, WebExtensionStub="AsyncAmbiguous"]
any resolve(any... args);
};

Просмотреть файл

@ -1110,6 +1110,7 @@ WEBIDL_FILES += [
WEBIDL_FILES += [
"ExtensionAlarms.webidl",
"ExtensionBrowser.webidl",
"ExtensionDns.webidl",
"ExtensionEventManager.webidl",
# ExtensionMockAPI is not a real WebExtensions API, and it is only enabled in tests.
"ExtensionMockAPI.webidl",

Просмотреть файл

@ -100,7 +100,7 @@ add_task(async function startup() {
await AddonTestUtils.promiseStartupManager();
});
add_task(async function test_dns_resolve() {
async function test_dns_resolve() {
let extension = getExtension();
await extension.startup();
await extension.awaitMessage("ready");
@ -137,9 +137,9 @@ add_task(async function test_dns_resolve() {
}
await extension.unload();
});
}
add_task(async function test_dns_resolve_socks() {
async function test_dns_resolve_socks() {
let extension = getExtension();
await extension.startup();
await extension.awaitMessage("ready");
@ -173,4 +173,13 @@ add_task(async function test_dns_resolve_socks() {
`expected error ${result.message}`
);
await extension.unload();
});
}
add_task(test_dns_resolve);
add_task(
{
// TODO(Bug 1748313): remove the skip_if once we have introduced the proxy API namespace.
skip_if: () => ExtensionTestUtils.isInBackgroundServiceWorkerTests(),
},
test_dns_resolve_socks
);

Просмотреть файл

@ -20,6 +20,7 @@ prefs =
[test_ext_alarms_replaces.js]
[test_ext_background_service_worker.js]
[test_ext_contentscript_dynamic_registration.js]
[test_ext_dns.js]
[test_ext_runtime_getBackgroundPage.js]
[test_ext_scripting_contentScripts.js]
[test_ext_scripting_contentScripts_css.js]

Просмотреть файл

@ -9,8 +9,7 @@
#include "mozilla/dom/{{ webidl_name }}Binding.h"
#include "nsIGlobalObject.h"
namespace mozilla {
namespace extensions {
namespace mozilla::extensions {
NS_IMPL_CYCLE_COLLECTING_ADDREF({{ webidl_name }});
NS_IMPL_CYCLE_COLLECTING_RELEASE({{ webidl_name }})
@ -51,5 +50,4 @@ ExtensionEventManager* {{ webidl_name}}::OnEVENTNAME() {
}
*/
} // namespace extensions
} // namespace mozilla
} // namespace mozilla::extensions

Просмотреть файл

@ -20,9 +20,7 @@
class nsIGlobalObject;
namespace mozilla {
namespace extensions {
namespace mozilla::extensions {
class ExtensionEventManager;
@ -68,7 +66,6 @@ class {{ webidl_name }} final : public nsISupports,
// RefPtr<ExtensionEventManager> mOnEVENTNAMEEventMgr;
};
} // namespace extensions
} // namespace mozilla
} // namespace mozilla::extensions
#endif // mozilla_extensions_{{ webidl_name }}_h

Просмотреть файл

@ -1,4 +1,4 @@
/*
/*
* THIS IS AN AUTOGENERATED FILE. DO NOT EDIT
*
* The content of this file has been generated based on the WebExtensions API

Просмотреть файл

@ -10,6 +10,7 @@
#include "mozilla/dom/ExtensionPortBinding.h" // ExtensionPortDescriptor
#include "mozilla/dom/WorkerScope.h" // GetWorkerPrivateFromContext
#include "mozilla/extensions/ExtensionAlarms.h"
#include "mozilla/extensions/ExtensionDns.h"
#include "mozilla/extensions/ExtensionMockAPI.h"
#include "mozilla/extensions/ExtensionPort.h"
#include "mozilla/extensions/ExtensionRuntime.h"
@ -32,6 +33,7 @@ NS_INTERFACE_MAP_END
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(ExtensionBrowser)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mGlobal)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mExtensionAlarms)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mExtensionDns)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mExtensionMockAPI)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mExtensionRuntime)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mExtensionScripting)
@ -44,6 +46,7 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_END
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(ExtensionBrowser)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mGlobal)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mExtensionAlarms)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mExtensionDns)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mExtensionMockAPI)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mExtensionRuntime)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mExtensionScripting)
@ -197,6 +200,14 @@ ExtensionAlarms* ExtensionBrowser::GetExtensionAlarms() {
return mExtensionAlarms;
}
ExtensionDns* ExtensionBrowser::GetExtensionDns() {
if (!mExtensionDns) {
mExtensionDns = new ExtensionDns(mGlobal, this);
}
return mExtensionDns;
}
ExtensionMockAPI* ExtensionBrowser::GetExtensionMockAPI() {
if (!mExtensionMockAPI) {
mExtensionMockAPI = new ExtensionMockAPI(mGlobal, this);

Просмотреть файл

@ -21,6 +21,7 @@ class ErrorResult;
namespace extensions {
class ExtensionAlarms;
class ExtensionDns;
class ExtensionMockAPI;
class ExtensionPort;
class ExtensionRuntime;
@ -103,6 +104,7 @@ class ExtensionBrowser final : public nsISupports, public nsWrapperCache {
nsIGlobalObject* GetParentObject() const;
ExtensionAlarms* GetExtensionAlarms();
ExtensionDns* GetExtensionDns();
ExtensionMockAPI* GetExtensionMockAPI();
ExtensionRuntime* GetExtensionRuntime();
ExtensionScripting* GetExtensionScripting();
@ -118,6 +120,7 @@ class ExtensionBrowser final : public nsISupports, public nsWrapperCache {
JS::Heap<JS::Value> mLastError;
bool mCheckedLastError;
RefPtr<ExtensionAlarms> mExtensionAlarms;
RefPtr<ExtensionDns> mExtensionDns;
RefPtr<ExtensionMockAPI> mExtensionMockAPI;
RefPtr<ExtensionRuntime> mExtensionRuntime;
RefPtr<ExtensionScripting> mExtensionScripting;

Просмотреть файл

@ -0,0 +1,40 @@
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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/. */
#include "ExtensionDns.h"
#include "ExtensionEventManager.h"
#include "mozilla/dom/ExtensionDnsBinding.h"
#include "nsIGlobalObject.h"
namespace mozilla::extensions {
NS_IMPL_CYCLE_COLLECTING_ADDREF(ExtensionDns);
NS_IMPL_CYCLE_COLLECTING_RELEASE(ExtensionDns)
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(ExtensionDns, mGlobal, mExtensionBrowser);
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(ExtensionDns)
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_INTERFACE_MAP_END
ExtensionDns::ExtensionDns(nsIGlobalObject* aGlobal,
ExtensionBrowser* aExtensionBrowser)
: mGlobal(aGlobal), mExtensionBrowser(aExtensionBrowser) {
MOZ_DIAGNOSTIC_ASSERT(mGlobal);
MOZ_DIAGNOSTIC_ASSERT(mExtensionBrowser);
}
/* static */
bool ExtensionDns::IsAllowed(JSContext* aCx, JSObject* aGlobal) { return true; }
JSObject* ExtensionDns::WrapObject(JSContext* aCx,
JS::Handle<JSObject*> aGivenProto) {
return dom::ExtensionDns_Binding::Wrap(aCx, this, aGivenProto);
}
nsIGlobalObject* ExtensionDns::GetParentObject() const { return mGlobal; }
} // namespace mozilla::extensions

Просмотреть файл

@ -0,0 +1,63 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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 mozilla_extensions_ExtensionDns_h
#define mozilla_extensions_ExtensionDns_h
#include "js/TypeDecls.h"
#include "mozilla/Attributes.h"
#include "mozilla/dom/BindingDeclarations.h"
#include "nsCycleCollectionParticipant.h"
#include "nsCOMPtr.h"
#include "nsISupports.h"
#include "nsWrapperCache.h"
#include "ExtensionAPIBase.h"
#include "ExtensionBrowser.h"
class nsIGlobalObject;
namespace mozilla::extensions {
class ExtensionEventManager;
class ExtensionDns final : public nsISupports,
public nsWrapperCache,
public ExtensionAPINamespace {
public:
ExtensionDns(nsIGlobalObject* aGlobal, ExtensionBrowser* aExtensionBrowser);
// ExtensionAPIBase methods
nsIGlobalObject* GetGlobalObject() const override { return mGlobal; }
ExtensionBrowser* GetExtensionBrowser() const override {
return mExtensionBrowser;
}
nsString GetAPINamespace() const override { return u"dns"_ns; }
// nsWrapperCache interface methods
JSObject* WrapObject(JSContext* aCx,
JS::Handle<JSObject*> aGivenProto) override;
// DOM bindings methods
static bool IsAllowed(JSContext* aCx, JSObject* aGlobal);
nsIGlobalObject* GetParentObject() const;
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(ExtensionDns)
private:
~ExtensionDns() = default;
nsCOMPtr<nsIGlobalObject> mGlobal;
RefPtr<ExtensionBrowser> mExtensionBrowser;
};
} // namespace mozilla::extensions
#endif // mozilla_extensions_ExtensionDns_h

Просмотреть файл

@ -60,6 +60,7 @@ WEBIDL_PRIMITIVE_TYPES = set([
#
# NOTE: Please keep this table in alphabetic order.
WEBEXT_STUBS_MAPPING = {
"dns.resolve": "AsyncAmbiguous",
"runtime.connect": "ReturnsPort",
"runtime.connectNative": "ReturnsPort",
"runtime.getURL": "ReturnsString",

Просмотреть файл

@ -28,6 +28,7 @@ EXPORTS.mozilla.extensions += [
# WebExtensions API namespaces.
UNIFIED_SOURCES += [
"ExtensionAlarms.cpp",
"ExtensionDns.cpp",
"ExtensionRuntime.cpp",
"ExtensionScripting.cpp",
"ExtensionTest.cpp",
@ -35,6 +36,7 @@ UNIFIED_SOURCES += [
EXPORTS.mozilla.extensions += [
"ExtensionAlarms.h",
"ExtensionDns.h",
"ExtensionRuntime.h",
"ExtensionScripting.h",
"ExtensionTest.h",