mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-29 15:52:07 +00:00
Bug 1027299 - Print a deprecation warning when importing XUL into content documents (r=smaug)
This commit is contained in:
parent
27c889d30f
commit
e5c71c22e7
@ -65,3 +65,4 @@ DEPRECATED_OPERATION(KeyNameApps)
|
||||
DEPRECATED_OPERATION(KeyNameFastFwd)
|
||||
DEPRECATED_OPERATION(KeyNameZoom)
|
||||
DEPRECATED_OPERATION(KeyNameDeadKeys)
|
||||
DEPRECATED_OPERATION(ImportXULIntoContent)
|
||||
|
@ -1993,6 +1993,7 @@ public:
|
||||
eDeprecatedOperationCount
|
||||
};
|
||||
#undef DEPRECATED_OPERATION
|
||||
bool HasWarnedAbout(DeprecatedOperations aOperation);
|
||||
void WarnOnceAbout(DeprecatedOperations aOperation, bool asError = false);
|
||||
|
||||
virtual void PostVisibilityUpdateEvent() = 0;
|
||||
|
@ -9821,13 +9821,19 @@ static const char* kWarnings[] = {
|
||||
};
|
||||
#undef DEPRECATED_OPERATION
|
||||
|
||||
bool
|
||||
nsIDocument::HasWarnedAbout(DeprecatedOperations aOperation)
|
||||
{
|
||||
static_assert(eDeprecatedOperationCount <= 64,
|
||||
"Too many deprecated operations");
|
||||
return mWarnedAbout & (1ull << aOperation);
|
||||
}
|
||||
|
||||
void
|
||||
nsIDocument::WarnOnceAbout(DeprecatedOperations aOperation,
|
||||
bool asError /* = false */)
|
||||
{
|
||||
static_assert(eDeprecatedOperationCount <= 64,
|
||||
"Too many deprecated operations");
|
||||
if (mWarnedAbout & (1ull << aOperation)) {
|
||||
if (HasWarnedAbout(aOperation)) {
|
||||
return;
|
||||
}
|
||||
mWarnedAbout |= (1ull << aOperation);
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* 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/.
|
||||
@ -49,6 +49,7 @@
|
||||
#include "nsIRDFNode.h"
|
||||
#include "nsIRDFService.h"
|
||||
#include "nsIScriptContext.h"
|
||||
#include "nsIScriptError.h"
|
||||
#include "nsIScriptSecurityManager.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "mozilla/css/StyleRule.h"
|
||||
@ -804,12 +805,34 @@ IsInFeedSubscribeLine(nsXULElement* aElement)
|
||||
}
|
||||
#endif
|
||||
|
||||
class XULInContentErrorReporter : public nsRunnable
|
||||
{
|
||||
public:
|
||||
XULInContentErrorReporter(nsIDocument* aDocument) : mDocument(aDocument) {}
|
||||
|
||||
NS_IMETHOD Run()
|
||||
{
|
||||
mDocument->WarnOnceAbout(nsIDocument::eImportXULIntoContent, false);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
private:
|
||||
nsCOMPtr<nsIDocument> mDocument;
|
||||
};
|
||||
|
||||
nsresult
|
||||
nsXULElement::BindToTree(nsIDocument* aDocument,
|
||||
nsIContent* aParent,
|
||||
nsIContent* aBindingParent,
|
||||
bool aCompileEventHandlers)
|
||||
{
|
||||
if (!aBindingParent &&
|
||||
aDocument &&
|
||||
!aDocument->AllowXULXBL() &&
|
||||
!aDocument->HasWarnedAbout(nsIDocument::eImportXULIntoContent)) {
|
||||
nsContentUtils::AddScriptRunner(new XULInContentErrorReporter(aDocument));
|
||||
}
|
||||
|
||||
nsresult rv = nsStyledElement::BindToTree(aDocument, aParent,
|
||||
aBindingParent,
|
||||
aCompileEventHandlers);
|
||||
|
@ -7,3 +7,4 @@ support-files =
|
||||
[test_bug236853.xul]
|
||||
[test_bug398289.html]
|
||||
[test_bug775972.xul]
|
||||
[test_import_xul_to_content.xul]
|
||||
|
69
content/xul/content/test/test_import_xul_to_content.xul
Normal file
69
content/xul/content/test/test_import_xul_to_content.xul
Normal file
@ -0,0 +1,69 @@
|
||||
<?xml version="1.0"?>
|
||||
<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
|
||||
<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?>
|
||||
<window title="Mozilla Importing XUL into Content"
|
||||
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
|
||||
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
|
||||
|
||||
<!-- test results are displayed in the html:body -->
|
||||
<body xmlns="http://www.w3.org/1999/xhtml">
|
||||
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1027299"
|
||||
target="_blank">Mozilla Bug 1027299</a>
|
||||
</body>
|
||||
|
||||
<browser id="browserelt" src="about:blank" type="content"/>
|
||||
|
||||
<!-- test code goes here -->
|
||||
<script type="application/javascript">
|
||||
<![CDATA[
|
||||
|
||||
Components.utils.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
function expectWarning(expected, when, f) {
|
||||
Services.console.reset();
|
||||
|
||||
f();
|
||||
|
||||
var sawWarning = false;
|
||||
var msgs = Services.console.getMessageArray();
|
||||
for (var i = 0; i < msgs.length; i++) {
|
||||
var msg = msgs[i];
|
||||
if (!msg || !(msg instanceof Components.interfaces.nsIScriptError)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (msg.category.contains("DOM") && msg.errorMessage.contains("Importing XUL")) {
|
||||
sawWarning = true;
|
||||
}
|
||||
}
|
||||
|
||||
ok(sawWarning == expected, "correct warning condition when " + when);
|
||||
}
|
||||
|
||||
var browser = document.getElementById("browserelt");
|
||||
browser.addEventListener("load", function() {
|
||||
var doc = browser.contentDocument;
|
||||
|
||||
// We add a <video> element, which contains anonymous XUL content. This should not warn.
|
||||
var video = doc.createElement("video");
|
||||
expectWarning(false, "appending video", function() {
|
||||
doc.documentElement.appendChild(video);
|
||||
// Force a layout flush to make sure the anonymous content is added.
|
||||
let dummy = doc.documentElement.offsetLeft;
|
||||
});
|
||||
|
||||
// We add some XUL to a content document. This should generate a warning.
|
||||
var elt = document.createElement("label");
|
||||
var newElt = doc.importNode(elt, false);
|
||||
expectWarning(true, "appending XUL", function() {
|
||||
doc.documentElement.appendChild(newElt);
|
||||
});
|
||||
|
||||
SimpleTest.finish();
|
||||
});
|
||||
|
||||
]]>
|
||||
</script>
|
||||
</window>
|
@ -207,3 +207,4 @@ KeyNameFastFwdWarning=KeyboardEvent.key value "FastFwd" is obsolete and will be
|
||||
KeyNameZoomWarning=KeyboardEvent.key value "Zoom" is obsolete and will be renamed to "ZoomToggle". For more help https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent.key
|
||||
# LOCALIZATION NOTE: Do not translate "KeyboardEvent.key" and "Dead".
|
||||
KeyNameDeadKeysWarning=KeyboardEvent.key values starting with "Dead" are obsolete and will be merged into just "Dead". For more help https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent.key
|
||||
ImportXULIntoContentWarning=Importing XUL nodes into a content document is deprecated. This functionality may be removed soon.
|
||||
|
Loading…
Reference in New Issue
Block a user