mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-17 06:09:19 +00:00
Bug 1695817 - Part 2: Introduce a blank page about:third-party r=Gijs,fluent-reviewers,xpcom-reviewers,kmag
This patch adds a blank page about:third-party along with a skeleton XPCOM object AboutThirdParty which has a method to invoke a background task in C++. Differential Revision: https://phabricator.services.mozilla.com/D109303
This commit is contained in:
parent
f77b225313
commit
657c8933b2
@ -245,6 +245,11 @@ var whitelist = [
|
||||
file:
|
||||
"resource://gre/localization/en-US/toolkit/updates/backgroundupdate.ftl",
|
||||
},
|
||||
// Bug 1713242 - referenced by aboutThirdParty.html which is only for Windows
|
||||
{
|
||||
file: "resource://gre/localization/en-US/toolkit/about/aboutThirdParty.ftl",
|
||||
platforms: ["linux", "macosx"],
|
||||
},
|
||||
];
|
||||
|
||||
if (AppConstants.NIGHTLY_BUILD && AppConstants.platform != "win") {
|
||||
|
@ -137,6 +137,10 @@ static const RedirEntry kRedirMap[] = {
|
||||
nsIAboutModule::MAKE_LINKABLE | nsIAboutModule::URI_CAN_LOAD_IN_CHILD},
|
||||
{"support", "chrome://global/content/aboutSupport.xhtml",
|
||||
nsIAboutModule::ALLOW_SCRIPT},
|
||||
#ifdef XP_WIN
|
||||
{"third-party", "chrome://global/content/aboutThirdParty.html",
|
||||
nsIAboutModule::ALLOW_SCRIPT},
|
||||
#endif
|
||||
#ifndef MOZ_GLEAN_ANDROID
|
||||
{"glean", "chrome://global/content/aboutGlean.html",
|
||||
nsIAboutModule::HIDE_FROM_ABOUTABOUT | nsIAboutModule::ALLOW_SCRIPT},
|
||||
|
@ -37,6 +37,8 @@ if defined('MOZ_CRASHREPORTER'):
|
||||
about_pages.append('crashes')
|
||||
if buildconfig.substs['MOZ_WIDGET_TOOLKIT'] != 'android':
|
||||
about_pages.append('profiles')
|
||||
if buildconfig.substs['MOZ_WIDGET_TOOLKIT'] == 'windows':
|
||||
about_pages.append('third-party')
|
||||
if not defined('MOZ_GLEAN_ANDROID'):
|
||||
about_pages.append('glean')
|
||||
|
||||
|
85
toolkit/components/aboutthirdparty/AboutThirdParty.cpp
vendored
Normal file
85
toolkit/components/aboutthirdparty/AboutThirdParty.cpp
vendored
Normal file
@ -0,0 +1,85 @@
|
||||
/* -*- 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 "AboutThirdParty.h"
|
||||
|
||||
#include "mozilla/ClearOnShutdown.h"
|
||||
#include "mozilla/dom/Promise.h"
|
||||
#include "mozilla/StaticPtr.h"
|
||||
#include "nsThreadUtils.h"
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
static StaticRefPtr<AboutThirdParty> sSingleton;
|
||||
|
||||
NS_IMPL_ISUPPORTS(AboutThirdParty, nsIAboutThirdParty);
|
||||
|
||||
/*static*/
|
||||
already_AddRefed<AboutThirdParty> AboutThirdParty::GetSingleton() {
|
||||
if (!sSingleton) {
|
||||
sSingleton = new AboutThirdParty;
|
||||
ClearOnShutdown(&sSingleton);
|
||||
}
|
||||
|
||||
return do_AddRef(sSingleton);
|
||||
}
|
||||
|
||||
AboutThirdParty::AboutThirdParty()
|
||||
: mPromise(new BackgroundThreadPromise::Private(__func__)) {}
|
||||
|
||||
void AboutThirdParty::BackgroundThread() {
|
||||
MOZ_ASSERT(!NS_IsMainThread());
|
||||
MOZ_ASSERT(mWorkerState == WorkerState::Running);
|
||||
|
||||
mWorkerState = WorkerState::Done;
|
||||
}
|
||||
|
||||
RefPtr<BackgroundThreadPromise> AboutThirdParty::CollectSystemInfoAsync() {
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
// Allow only the first call to start a background task.
|
||||
if (mWorkerState.compareExchange(WorkerState::Init, WorkerState::Running)) {
|
||||
nsCOMPtr<nsIRunnable> runnable = NS_NewRunnableFunction(
|
||||
"AboutThirdParty::BackgroundThread", [self = RefPtr{this}]() mutable {
|
||||
self->BackgroundThread();
|
||||
NS_DispatchToMainThread(NS_NewRunnableFunction(
|
||||
"AboutThirdParty::BackgroundThread Done",
|
||||
[self]() { self->mPromise->Resolve(true, __func__); }));
|
||||
});
|
||||
|
||||
nsresult rv =
|
||||
NS_DispatchBackgroundTask(runnable.forget(), NS_DISPATCH_NORMAL);
|
||||
if (NS_FAILED(rv)) {
|
||||
mPromise->Reject(rv, __func__);
|
||||
}
|
||||
}
|
||||
|
||||
return mPromise;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
AboutThirdParty::CollectSystemInfo(JSContext* aCx, dom::Promise** aResult) {
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
nsIGlobalObject* global = xpc::CurrentNativeGlobal(aCx);
|
||||
MOZ_ASSERT(global);
|
||||
|
||||
ErrorResult result;
|
||||
RefPtr<dom::Promise> promise(dom::Promise::Create(global, result));
|
||||
if (NS_WARN_IF(result.Failed())) {
|
||||
return result.StealNSResult();
|
||||
}
|
||||
|
||||
CollectSystemInfoAsync()->Then(
|
||||
GetMainThreadSerialEventTarget(), __func__,
|
||||
[promise](bool) { promise->MaybeResolve(JS::NullHandleValue); },
|
||||
[promise](nsresult aRv) { promise->MaybeReject(aRv); });
|
||||
|
||||
promise.forget(aResult);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
} // namespace mozilla
|
46
toolkit/components/aboutthirdparty/AboutThirdParty.h
vendored
Normal file
46
toolkit/components/aboutthirdparty/AboutThirdParty.h
vendored
Normal file
@ -0,0 +1,46 @@
|
||||
/* -*- 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 __AboutThirdParty_h__
|
||||
#define __AboutThirdParty_h__
|
||||
|
||||
#include "mozilla/MozPromise.h"
|
||||
#include "nsIAboutThirdParty.h"
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
using BackgroundThreadPromise =
|
||||
MozPromise<bool /* aIgnored */, nsresult, /* IsExclusive */ false>;
|
||||
|
||||
class AboutThirdParty final : public nsIAboutThirdParty {
|
||||
// Atomic only supports 32-bit or 64-bit types.
|
||||
enum class WorkerState : uint32_t {
|
||||
Init,
|
||||
Running,
|
||||
Done,
|
||||
};
|
||||
Atomic<WorkerState, SequentiallyConsistent> mWorkerState;
|
||||
RefPtr<BackgroundThreadPromise::Private> mPromise;
|
||||
|
||||
~AboutThirdParty() = default;
|
||||
void BackgroundThread();
|
||||
|
||||
public:
|
||||
static already_AddRefed<AboutThirdParty> GetSingleton();
|
||||
|
||||
AboutThirdParty();
|
||||
|
||||
NS_DECL_THREADSAFE_ISUPPORTS
|
||||
NS_DECL_NSIABOUTTHIRDPARTY
|
||||
|
||||
// Have a function separated from dom::Promise so that
|
||||
// both JS method and GTest can use.
|
||||
RefPtr<BackgroundThreadPromise> CollectSystemInfoAsync();
|
||||
};
|
||||
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // __AboutThirdParty_h__
|
17
toolkit/components/aboutthirdparty/components.conf
vendored
Normal file
17
toolkit/components/aboutthirdparty/components.conf
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
|
||||
# vim: set filetype=python:
|
||||
# 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/.
|
||||
|
||||
Classes = [
|
||||
{
|
||||
'cid': '{bb6afd78-2e02-4e96-b6b9-eef8cbcdc29c}',
|
||||
'contract_ids': ['@mozilla.org/about-thirdparty;1'],
|
||||
'type': 'AboutThirdParty',
|
||||
'singleton': True,
|
||||
'constructor': 'mozilla::AboutThirdParty::GetSingleton',
|
||||
'headers': ['mozilla/AboutThirdParty.h'],
|
||||
'processes': ProcessSelector.MAIN_PROCESS_ONLY,
|
||||
},
|
||||
]
|
3
toolkit/components/aboutthirdparty/content/aboutThirdParty.css
vendored
Normal file
3
toolkit/components/aboutthirdparty/content/aboutThirdParty.css
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
/* 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/. */
|
22
toolkit/components/aboutthirdparty/content/aboutThirdParty.html
vendored
Normal file
22
toolkit/components/aboutthirdparty/content/aboutThirdParty.html
vendored
Normal file
@ -0,0 +1,22 @@
|
||||
<!-- 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/. -->
|
||||
|
||||
<!DOCTYPE html>
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<title data-l10n-id="third-party-page-title"></title>
|
||||
<meta http-equiv="Content-Security-Policy"
|
||||
content="default-src chrome:; object-src 'none'">
|
||||
<link rel="stylesheet" href="chrome://global/content/aboutThirdParty.css">
|
||||
<link rel="localization" href="branding/brand.ftl"/>
|
||||
<link rel="localization" href="toolkit/about/aboutThirdParty.ftl"/>
|
||||
<script src="chrome://global/content/aboutThirdParty.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1 data-l10n-id="third-party-page-title"></h1>
|
||||
</body>
|
||||
|
||||
</html>
|
20
toolkit/components/aboutthirdparty/content/aboutThirdParty.js
vendored
Normal file
20
toolkit/components/aboutthirdparty/content/aboutThirdParty.js
vendored
Normal file
@ -0,0 +1,20 @@
|
||||
/* 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/. */
|
||||
|
||||
"use strict";
|
||||
|
||||
let AboutThirdParty = null;
|
||||
|
||||
function onLoad() {}
|
||||
|
||||
try {
|
||||
AboutThirdParty = Cc["@mozilla.org/about-thirdparty;1"].getService(
|
||||
Ci.nsIAboutThirdParty
|
||||
);
|
||||
document.addEventListener("DOMContentLoaded", onLoad, { once: true });
|
||||
} catch (ex) {
|
||||
// Do nothing if we fail to create a singleton instance,
|
||||
// showing the default no-module message.
|
||||
Cu.reportError(ex);
|
||||
}
|
8
toolkit/components/aboutthirdparty/jar.mn
vendored
Normal file
8
toolkit/components/aboutthirdparty/jar.mn
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
# 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/.
|
||||
|
||||
toolkit.jar:
|
||||
content/global/aboutThirdParty.css (content/aboutThirdParty.css)
|
||||
content/global/aboutThirdParty.html (content/aboutThirdParty.html)
|
||||
content/global/aboutThirdParty.js (content/aboutThirdParty.js)
|
24
toolkit/components/aboutthirdparty/moz.build
vendored
Normal file
24
toolkit/components/aboutthirdparty/moz.build
vendored
Normal file
@ -0,0 +1,24 @@
|
||||
# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
|
||||
# vim: set filetype=python:
|
||||
# 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/.
|
||||
|
||||
with Files("**"):
|
||||
BUG_COMPONENT = ("Firefox", "Launcher Process")
|
||||
|
||||
FINAL_LIBRARY = "xul"
|
||||
|
||||
XPCSHELL_TESTS_MANIFESTS += ["tests/xpcshell/xpcshell.ini"]
|
||||
JAR_MANIFESTS += ["jar.mn"]
|
||||
XPCOM_MANIFESTS += ["components.conf"]
|
||||
XPIDL_MODULE = "AboutThirdParty"
|
||||
XPIDL_SOURCES += ["nsIAboutThirdParty.idl"]
|
||||
|
||||
EXPORTS.mozilla += [
|
||||
"AboutThirdParty.h",
|
||||
]
|
||||
|
||||
SOURCES += [
|
||||
"AboutThirdParty.cpp",
|
||||
]
|
16
toolkit/components/aboutthirdparty/nsIAboutThirdParty.idl
vendored
Normal file
16
toolkit/components/aboutthirdparty/nsIAboutThirdParty.idl
vendored
Normal file
@ -0,0 +1,16 @@
|
||||
/* -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 8 -*- */
|
||||
/* 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 "nsISupports.idl"
|
||||
|
||||
[scriptable, uuid(d33ff086-b328-4ae6-aaf5-52d41aa5df38)]
|
||||
interface nsIAboutThirdParty : nsISupports
|
||||
{
|
||||
/**
|
||||
* Posts a background task to collect system information and resolves
|
||||
* the returned promise when the task is finished.
|
||||
*/
|
||||
[implicit_jscontext] Promise collectSystemInfo();
|
||||
};
|
9
toolkit/components/aboutthirdparty/tests/xpcshell/head.js
vendored
Normal file
9
toolkit/components/aboutthirdparty/tests/xpcshell/head.js
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
/* 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/. */
|
||||
|
||||
"use strict";
|
||||
|
||||
const kATP = Cc["@mozilla.org/about-thirdparty;1"].getService(
|
||||
Ci.nsIAboutThirdParty
|
||||
);
|
23
toolkit/components/aboutthirdparty/tests/xpcshell/test_aboutthirdparty.js
vendored
Normal file
23
toolkit/components/aboutthirdparty/tests/xpcshell/test_aboutthirdparty.js
vendored
Normal file
@ -0,0 +1,23 @@
|
||||
/* 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/. */
|
||||
|
||||
add_task(async () => {
|
||||
// Make sure successive calls of collectSystemInfo() do not
|
||||
// cause anything bad.
|
||||
const kLoopCount = 100;
|
||||
const promises = [];
|
||||
for (let i = 0; i < kLoopCount; ++i) {
|
||||
promises.push(kATP.collectSystemInfo());
|
||||
}
|
||||
|
||||
const collectSystemInfoResults = await Promise.allSettled(promises);
|
||||
Assert.equal(collectSystemInfoResults.length, kLoopCount);
|
||||
|
||||
for (const result of collectSystemInfoResults) {
|
||||
Assert.ok(
|
||||
result.status == "fulfilled",
|
||||
"All results from collectSystemInfo() are resolved."
|
||||
);
|
||||
}
|
||||
});
|
4
toolkit/components/aboutthirdparty/tests/xpcshell/xpcshell.ini
vendored
Normal file
4
toolkit/components/aboutthirdparty/tests/xpcshell/xpcshell.ini
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
[DEFAULT]
|
||||
head = head.js
|
||||
|
||||
[test_aboutthirdparty.js]
|
@ -116,7 +116,7 @@ if CONFIG["MOZ_UPDATE_AGENT"]:
|
||||
DIRS += ["build"]
|
||||
|
||||
if CONFIG["MOZ_WIDGET_TOOLKIT"] == "windows":
|
||||
DIRS += ["gfx"]
|
||||
DIRS += ["aboutthirdparty", "gfx"]
|
||||
|
||||
if CONFIG["MOZ_WIDGET_TOOLKIT"] != "android":
|
||||
EXTRA_JS_MODULES += [
|
||||
|
5
toolkit/locales/en-US/toolkit/about/aboutThirdParty.ftl
Normal file
5
toolkit/locales/en-US/toolkit/about/aboutThirdParty.ftl
Normal file
@ -0,0 +1,5 @@
|
||||
# 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/.
|
||||
|
||||
third-party-page-title = Third-party Module Information
|
Loading…
x
Reference in New Issue
Block a user