forked from mozilla/gecko-dev
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
Toshihito Kikuchi
committed
May 28, 2021
1 parent
f77b225
commit 657c893
Showing
17 changed files
with
294 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}, | ||
] |
3 changes: 3 additions & 0 deletions
3
toolkit/components/aboutthirdparty/content/aboutThirdParty.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
22
toolkit/components/aboutthirdparty/content/aboutThirdParty.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
20
toolkit/components/aboutthirdparty/content/aboutThirdParty.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
); |
23 changes: 23 additions & 0 deletions
23
toolkit/components/aboutthirdparty/tests/xpcshell/test_aboutthirdparty.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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." | ||
); | ||
} | ||
}); |
4 changes: 4 additions & 0 deletions
4
toolkit/components/aboutthirdparty/tests/xpcshell/xpcshell.ini
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[DEFAULT] | ||
head = head.js | ||
|
||
[test_aboutthirdparty.js] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |