Skip to content

Commit

Permalink
Bug 1695817 - Part 2: Introduce a blank page about:third-party r=Gijs…
Browse files Browse the repository at this point in the history
…,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
  • Loading branch information
Toshihito Kikuchi committed May 28, 2021
1 parent f77b225 commit 657c893
Show file tree
Hide file tree
Showing 17 changed files with 294 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down
4 changes: 4 additions & 0 deletions docshell/base/nsAboutRedirector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down
2 changes: 2 additions & 0 deletions docshell/build/components.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down
85 changes: 85 additions & 0 deletions toolkit/components/aboutthirdparty/AboutThirdParty.cpp
Original file line number Diff line number Diff line change
@@ -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 changes: 46 additions & 0 deletions toolkit/components/aboutthirdparty/AboutThirdParty.h
Original file line number Diff line number Diff line change
@@ -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 changes: 17 additions & 0 deletions toolkit/components/aboutthirdparty/components.conf
Original file line number Diff line number Diff line change
@@ -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,
},
]
Original file line number Diff line number Diff line change
@@ -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 changes: 22 additions & 0 deletions toolkit/components/aboutthirdparty/content/aboutThirdParty.html
Original file line number Diff line number Diff line change
@@ -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 changes: 20 additions & 0 deletions toolkit/components/aboutthirdparty/content/aboutThirdParty.js
Original file line number Diff line number Diff line change
@@ -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 changes: 8 additions & 0 deletions toolkit/components/aboutthirdparty/jar.mn
Original file line number Diff line number Diff line change
@@ -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 changes: 24 additions & 0 deletions toolkit/components/aboutthirdparty/moz.build
Original file line number Diff line number Diff line change
@@ -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 changes: 16 additions & 0 deletions toolkit/components/aboutthirdparty/nsIAboutThirdParty.idl
Original file line number Diff line number Diff line change
@@ -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 changes: 9 additions & 0 deletions toolkit/components/aboutthirdparty/tests/xpcshell/head.js
Original file line number Diff line number Diff line change
@@ -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
);
Original file line number Diff line number Diff line change
@@ -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."
);
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[DEFAULT]
head = head.js

[test_aboutthirdparty.js]
2 changes: 1 addition & 1 deletion toolkit/components/moz.build
Original file line number Diff line number Diff line change
Expand Up @@ -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 += [
Expand Down
5 changes: 5 additions & 0 deletions toolkit/locales/en-US/toolkit/about/aboutThirdParty.ftl
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 657c893

Please sign in to comment.