Bug 1696976 - Log a deprecation warning for extension use of canvas drawWindow r=baku,rpl

Differential Revision: https://phabricator.services.mozilla.com/D107582
This commit is contained in:
Tomislav Jovanovic 2021-03-15 12:30:54 +00:00
Родитель ebbbcc765b
Коммит 75c7d56381
6 изменённых файлов: 16 добавлений и 1 удалений

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

@ -38,6 +38,7 @@ DEPRECATED_OPERATION(DeprecatedTestingInterface)
DEPRECATED_OPERATION(DeprecatedTestingMethod)
DEPRECATED_OPERATION(DeprecatedTestingAttribute)
DEPRECATED_OPERATION(CreateImageBitmapCanvasRenderingContext2D)
DEPRECATED_OPERATION(DrawWindowCanvasRenderingContext2D)
DEPRECATED_OPERATION(MozRequestFullScreenDeprecatedPrefix)
DEPRECATED_OPERATION(MozfullscreenchangeDeprecatedPrefix)
DEPRECATED_OPERATION(MozfullscreenerrorDeprecatedPrefix)

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

@ -4789,6 +4789,7 @@ void CanvasRenderingContext2D::DrawWindow(nsGlobalWindowInner& aWindow,
double aX, double aY, double aW,
double aH, const nsACString& aBgColor,
uint32_t aFlags,
nsIPrincipal& aSubjectPrincipal,
ErrorResult& aError) {
if (int32_t(aW) == 0 || int32_t(aH) == 0) {
return;
@ -4801,6 +4802,12 @@ void CanvasRenderingContext2D::DrawWindow(nsGlobalWindowInner& aWindow,
return;
}
Document* doc = aWindow.GetExtantDoc();
if (doc && aSubjectPrincipal.GetIsAddonOrExpandedAddonPrincipal()) {
doc->WarnOnceAbout(
DeprecatedOperations::eDrawWindowCanvasRenderingContext2D);
}
// Flush layout updates
if (!(aFlags & CanvasRenderingContext2D_Binding::DRAWWINDOW_DO_NOT_FLUSH)) {
nsContentUtils::FlushLayoutForTree(aWindow.GetOuterWindow());

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

@ -390,6 +390,7 @@ class CanvasRenderingContext2D final : public nsICanvasRenderingContextInternal,
void DrawWindow(nsGlobalWindowInner& aWindow, double aX, double aY, double aW,
double aH, const nsACString& aBgColor, uint32_t aFlags,
nsIPrincipal& aSubjectPrincipal,
mozilla::ErrorResult& aError);
// Eventually this should be deprecated. Keeping for now to keep the binding

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

@ -346,6 +346,8 @@ DeprecatedTestingMethodWarning=TestingDeprecatedInterface.deprecatedMethod() is
DeprecatedTestingAttributeWarning=TestingDeprecatedInterface.deprecatedAttribute is a testing-only attribute and this is its testing deprecation message.
# LOCALIZATION NOTE (CreateImageBitmapCanvasRenderingContext2DWarning): Do not translate CanvasRenderingContext2D and createImageBitmap.
CreateImageBitmapCanvasRenderingContext2DWarning=Use of CanvasRenderingContext2D in createImageBitmap is deprecated.
# LOCALIZATION NOTE (DrawWindowCanvasRenderingContext2DWarning): Do not translate CanvasRenderingContext2D, drawWindow and tabs.captureTab.
DrawWindowCanvasRenderingContext2DWarning=Use of drawWindow method from CanvasRenderingContext2D is deprecated. Use tabs.captureTab extensions API instead https://developer.mozilla.org/docs/Mozilla/Add-ons/WebExtensions/API/tabs/captureTab
# LOCALIZATION NOTE (MozRequestFullScreenDeprecatedPrefixWarning): Do not translate mozRequestFullScreen.
MozRequestFullScreenDeprecatedPrefixWarning=mozRequestFullScreen() is deprecated.
# LOCALIZATION NOTE (MozfullscreenchangeDeprecatedPrefixWarning): Do not translate onmozfullscreenchange.

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

@ -113,7 +113,7 @@ interface CanvasRenderingContext2D {
* This API cannot currently be used by Web content. It is chrome
* and Web Extensions (with a permission) only.
*/
[Throws, Func="CanvasUtils::HasDrawWindowPrivilege"]
[Throws, NeedsSubjectPrincipal, Func="CanvasUtils::HasDrawWindowPrivilege"]
void drawWindow(Window window, double x, double y, double w, double h,
UTF8String bgColor, optional unsigned long flags = 0);

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

@ -4,6 +4,7 @@
<title>Test content script access to canvas drawWindow()</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<script src="/tests/SimpleTest/ExtensionTestUtils.js"></script>
<script src="head.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<script>
@ -51,6 +52,8 @@ add_task(async function test_drawWindow() {
files
});
consoleMonitor.start([{ message: /Use of drawWindow [\w\s]+ is deprecated. Use tabs.captureTab/ }]);
await first.startup();
await second.startup();
@ -65,6 +68,7 @@ add_task(async function test_drawWindow() {
win.close();
await first.unload();
await second.unload();
await consoleMonitor.finished();
});
add_task(async function test_tainted_canvas() {