From e5c71c22e701ba18a326a5c0abe69a279ac19f19 Mon Sep 17 00:00:00 2001 From: Bill McCloskey Date: Fri, 18 Jul 2014 08:59:00 -0700 Subject: [PATCH] Bug 1027299 - Print a deprecation warning when importing XUL into content documents (r=smaug) --- .../base/public/nsDeprecatedOperationList.h | 1 + content/base/public/nsIDocument.h | 1 + content/base/src/nsDocument.cpp | 12 +++- content/xul/content/src/nsXULElement.cpp | 25 ++++++- content/xul/content/test/chrome.ini | 1 + .../test/test_import_xul_to_content.xul | 69 +++++++++++++++++++ dom/locales/en-US/chrome/dom/dom.properties | 1 + 7 files changed, 106 insertions(+), 4 deletions(-) create mode 100644 content/xul/content/test/test_import_xul_to_content.xul diff --git a/content/base/public/nsDeprecatedOperationList.h b/content/base/public/nsDeprecatedOperationList.h index 336098a0d9eb..d9865cd8d095 100644 --- a/content/base/public/nsDeprecatedOperationList.h +++ b/content/base/public/nsDeprecatedOperationList.h @@ -65,3 +65,4 @@ DEPRECATED_OPERATION(KeyNameApps) DEPRECATED_OPERATION(KeyNameFastFwd) DEPRECATED_OPERATION(KeyNameZoom) DEPRECATED_OPERATION(KeyNameDeadKeys) +DEPRECATED_OPERATION(ImportXULIntoContent) diff --git a/content/base/public/nsIDocument.h b/content/base/public/nsIDocument.h index 64f5484ce983..ba5a87c149cb 100644 --- a/content/base/public/nsIDocument.h +++ b/content/base/public/nsIDocument.h @@ -1993,6 +1993,7 @@ public: eDeprecatedOperationCount }; #undef DEPRECATED_OPERATION + bool HasWarnedAbout(DeprecatedOperations aOperation); void WarnOnceAbout(DeprecatedOperations aOperation, bool asError = false); virtual void PostVisibilityUpdateEvent() = 0; diff --git a/content/base/src/nsDocument.cpp b/content/base/src/nsDocument.cpp index e6f94e125abf..d4a059f2ebc3 100644 --- a/content/base/src/nsDocument.cpp +++ b/content/base/src/nsDocument.cpp @@ -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); diff --git a/content/xul/content/src/nsXULElement.cpp b/content/xul/content/src/nsXULElement.cpp index 075df8faaf62..cb6ec7060bb7 100644 --- a/content/xul/content/src/nsXULElement.cpp +++ b/content/xul/content/src/nsXULElement.cpp @@ -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 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); diff --git a/content/xul/content/test/chrome.ini b/content/xul/content/test/chrome.ini index 05929edab2f2..29544814f14f 100644 --- a/content/xul/content/test/chrome.ini +++ b/content/xul/content/test/chrome.ini @@ -7,3 +7,4 @@ support-files = [test_bug236853.xul] [test_bug398289.html] [test_bug775972.xul] +[test_import_xul_to_content.xul] diff --git a/content/xul/content/test/test_import_xul_to_content.xul b/content/xul/content/test/test_import_xul_to_content.xul new file mode 100644 index 000000000000..9668066b4f1a --- /dev/null +++ b/content/xul/content/test/test_import_xul_to_content.xul @@ -0,0 +1,69 @@ + + + + + + + + + Mozilla Bug 1027299 + + + + + + + diff --git a/dom/locales/en-US/chrome/dom/dom.properties b/dom/locales/en-US/chrome/dom/dom.properties index 8ba4e340ebe8..841e54f47a3c 100644 --- a/dom/locales/en-US/chrome/dom/dom.properties +++ b/dom/locales/en-US/chrome/dom/dom.properties @@ -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.