Skip to content

Instantly share code, notes, and snippets.

@rpl
Last active August 20, 2020 12:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rpl/0069163eec72fd9fc2a07b8a4080a5ce to your computer and use it in GitHub Desktop.
Save rpl/0069163eec72fd9fc2a07b8a4080a5ce to your computer and use it in GitHub Desktop.
WebExtensions API WebIDL bindings - ExtensionBrowser and Desktop only API namespaces
# API namespaces shared by mobile and desktop builds.
WEBIDL_FILES = [
...
'ExtensionTest.webidl',
]
# preprocessed API namespaces shared by mobile and desktop builds
# (preprocessing macros are used in the webidl file to conditionally
# exclude part of the definitions in certain builds, at the moment
# to exclude desktop-only parts on building for android)
PREPROCESSED_WEBIDL_FILES = [
'ExtensionBrowser.webidl',
'ExtensionTabs.webidl',
]
# Desktop-only API namespaces completely excluded in Android builds
# NOTE: the implementation for these webidl files does live in
# `browser/components/extensions/webidl-api` instead of
# `toolkit/components/extensions/webidl-api`.
if CONFIG['OS_TARGET'] != 'Android':
WEBIDL_FILES += [
'ExtensionPkcs11.webidl',
]
/* -*- 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/. */
#include "ExtensionBrowser.h"
...
// Include headers for the API namespaces shared by mobile and desktop builds.
#include "mozilla/extensions/ExtensionIdle.h"
#include "mozilla/extensions/ExtensionTest.h"
#include "mozilla/extensions/ExtensionTabs.h"
#include "mozilla/extensions/ExtensionRuntime.h"
// Include header for the Desktop-only API namespaces
#if !defined(ANDROID)
#include "mozilla/extensions/ExtensionPkcs11.h"
#endif
...
namespace mozilla {
namespace extensions {
NS_IMPL_CYCLE_COLLECTING_ADDREF(ExtensionBrowser);
NS_IMPL_CYCLE_COLLECTING_RELEASE(ExtensionBrowser)
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(ExtensionBrowser, mGlobal,
mExtensionTest, mExtensionIdle,
mExtensionTabs, mExtensionRuntime
// This doesn't really look that great
// TODO: look for a better way to handle this special case.
#if !defined(ANDROID)
, mExtensionPkcs11
#endif
);
...
// API namespaces getters shared by mobile and desktop builds.
ExtensionTest* ExtensionBrowser::GetExtensionTest() {
if (!mExtensionTest) {
mExtensionTest = new ExtensionTest(mGlobal, this);
}
return mExtensionTest;
}
ExtensionIdle* ExtensionBrowser::GetExtensionIdle() {
if (!mExtensionIdle) {
mExtensionIdle = new ExtensionIdle(mGlobal, this);
}
return mExtensionIdle;
}
ExtensionTabs* ExtensionBrowser::GetExtensionTabs() {
if (!mExtensionTabs) {
mExtensionTabs = new ExtensionTabs(mGlobal, this);
}
return mExtensionTabs;
}
ExtensionRuntime* ExtensionBrowser::GetExtensionRuntime() {
if (!mExtensionRuntime) {
mExtensionRuntime = new ExtensionRuntime(mGlobal, this);
}
return mExtensionRuntime;
}
// Desktop-only API namespaces getters.
#if !defined(ANDROID)
ExtensionPkcs11* ExtensionBrowser::GetExtensionPkcs11() {
if (!mExtensionPkcs11) {
mExtensionPkcs11 = new ExtensionPkcs11(mGlobal, this);
}
return mExtensionPkcs11;
}
#endif
...
} // namespace extensions
} // namespace mozilla
/* -*- 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_ExtensionBrowser_h
#define mozilla_extensions_ExtensionBrowser_h
...
namespace mozilla {
...
namespace extensions {
// Forward declaration of the API namespaces classes shared by mobile and desktop builds.
class ExtensionTest;
class ExtensionIdle;
class ExtensionTabs;
class ExtensionRuntime;
// Forward declaration of the Desktop-only API namespaces
#if !defined(ANDROID)
class ExtensionPkcs11;
#endif
...
class ExtensionBrowser final : public nsISupports, public nsWrapperCache {
nsCOMPtr<nsIGlobalObject> mGlobal;
// Properties shared by desktop and mobile builds.
RefPtr<ExtensionTest> mExtensionTest;
RefPtr<ExtensionIdle> mExtensionIdle;
RefPtr<ExtensionTabs> mExtensionTabs;
RefPtr<ExtensionRuntime> mExtensionRuntime;
// Desktop-only properties.
#if !defined(ANDROID)
RefPtr<ExtensionPkcs11> mExtensionPkcs11;
#endif
...
public:
...
// API namespaces shared by both mobile and desktop builds.
ExtensionTest* GetExtensionTest();
ExtensionIdle* GetExtensionIdle();
ExtensionTabs* GetExtensionTabs();
ExtensionRuntime* GetExtensionRuntime();
// Desktop-only API namespaces.
#if !defined(ANDROID)
ExtensionPkcs11* GetExtensionPkcs11();
...
#endif
...
};
} // namespace extensions
} // namespace mozilla
#endif // mozilla_extensions_ExtensionBrowser_h
...
[Exposed=(ServiceWorker, Window), NoInterfaceObject]
interface ExtensionBrowser {
// API namespaces shared by mobile and desktop builds.
[Replaceable, SameObject, BinaryName="GetExtensionTest",
Func="mozilla::extensions::ExtensionTest::IsAllowed"]
readonly attribute ExtensionTest test;
...
// Desktop-only API namespaces.
#if !defined(ANDROID)
[Replaceable, SameObject, BinaryName="GetExtensionPkcs11",
Func="mozilla::extensions::ExtensionPkcs11::IsAllowed"]
readonly attribute ExtensionPkcs11 pkcs11;
#endif
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment