Bug 1237080 - adds deprecation msg for chrome scripted DOMParser without principal. r=baku
authorDave Huseby <dhuseby@mozilla.com>
Tue, 07 Jun 2016 18:57:45 -0700
changeset 301005 79fba69d9631c22223ed9bdf3ba3eb4dc56a357b
parent 301004 b92ba4dc0af5dcaa1732aa036e1ea75d8ec19717
child 301006 ef1c787b08dc408c5b03a4d128aff0257bc96f26
push id19599
push usercbook@mozilla.com
push dateWed, 08 Jun 2016 10:16:21 +0000
treeherderfx-team@81f4cc3f6f4c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs1237080
milestone50.0a1
Bug 1237080 - adds deprecation msg for chrome scripted DOMParser without principal. r=baku MozReview-Commit-ID: FuolzJOcslX
dom/base/DOMParser.cpp
dom/locales/en-US/chrome/dom/dom.properties
--- a/dom/base/DOMParser.cpp
+++ b/dom/base/DOMParser.cpp
@@ -5,16 +5,17 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "mozilla/dom/DOMParser.h"
 
 #include "nsIDOMDocument.h"
 #include "nsNetUtil.h"
 #include "nsIStreamListener.h"
 #include "nsStringStream.h"
+#include "nsIScriptError.h"
 #include "nsIScriptSecurityManager.h"
 #include "nsCRT.h"
 #include "nsStreamUtils.h"
 #include "nsContentUtils.h"
 #include "nsDOMJSUtils.h"
 #include "nsError.h"
 #include "nsPIDOMWindow.h"
 #include "nsNullPrincipal.h"
@@ -316,34 +317,44 @@ DOMParser::ParseFromStream(nsIInputStrea
 }
 
 NS_IMETHODIMP
 DOMParser::Init(nsIPrincipal* principal, nsIURI* documentURI,
                 nsIURI* baseURI, nsIGlobalObject* aScriptObject)
 {
   NS_ENSURE_STATE(!mAttemptedInit);
   mAttemptedInit = true;
-  
   NS_ENSURE_ARG(principal || documentURI);
-
   mDocumentURI = documentURI;
   
   if (!mDocumentURI) {
     principal->GetURI(getter_AddRefs(mDocumentURI));
     // If we have the system principal, then we'll just use the null principals
     // uri.
     if (!mDocumentURI && !nsContentUtils::IsSystemPrincipal(principal)) {
       return NS_ERROR_INVALID_ARG;
     }
   }
 
   mScriptHandlingObject = do_GetWeakReference(aScriptObject);
   mPrincipal = principal;
   nsresult rv;
   if (!mPrincipal) {
+    // BUG 1237080 -- in this case we're getting a chrome privilege scripted
+    // DOMParser object creation without an explicit principal set.  This is
+    // now deprecated.
+    nsContentUtils::ReportToConsole(nsIScriptError::warningFlag,
+                                    NS_LITERAL_CSTRING("DOM"),
+                                    nullptr,
+                                    nsContentUtils::eDOM_PROPERTIES,
+                                    "ChromeScriptedDOMParserWithoutPrincipal",
+                                    nullptr,
+                                    0,
+                                    documentURI);
+
     PrincipalOriginAttributes attrs;
     mPrincipal = BasePrincipal::CreateCodebasePrincipal(mDocumentURI, attrs);
     NS_ENSURE_TRUE(mPrincipal, NS_ERROR_FAILURE);
     mOriginalPrincipal = mPrincipal;
   } else {
     mOriginalPrincipal = mPrincipal;
     if (nsContentUtils::IsSystemPrincipal(mPrincipal)) {
       // Don't give DOMParsers the system principal.  Use a null
--- a/dom/locales/en-US/chrome/dom/dom.properties
+++ b/dom/locales/en-US/chrome/dom/dom.properties
@@ -224,16 +224,17 @@ TargetPrincipalDoesNotMatch=Failed to execute ‘postMessage’ on ‘DOMWindow’: The target origin provided (‘%S’) does not match the recipient window’s origin (‘%S’).
 RewriteYoutubeEmbed=Rewriting old-style Youtube Flash embed (%S) to iframe embed (%S). Please update page to use iframe instead of embed/object, if possible.
 # LOCALIZATION NOTE: Do not translate 'youtube'. %S values are origins, like https://domain.com:port
 RewriteYoutubeEmbedInvalidQuery=Rewriting old-style Youtube Flash embed (%S) to iframe embed (%S). Query was invalid and removed from URL. Please update page to use iframe instead of embed/object, if possible.
 # LOCALIZATION NOTE: Do not translate "ServiceWorker". %1$S is the ServiceWorker scope URL. %2$S is an error string.
 PushMessageDecryptionFailure=The ServiceWorker for scope ‘%1$S’ encountered an error decrypting a push message: ‘%2$S’. For help with encryption, please see https://developer.mozilla.org/en-US/docs/Web/API/Push_API/Using_the_Push_API#Encryption
 # LOCALIZATION NOTE: %1$S is the type of a DOM event. 'passive' is a literal parameter from the DOM spec.
 PreventDefaultFromPassiveListenerWarning=Ignoring ‘preventDefault()’ call on event of type ‘%1$S’ from a listener registered as ‘passive’.
 FileLastModifiedDateWarning=File.lastModifiedDate is deprecated. Use File.lastModified instead.
+ChromeScriptedDOMParserWithoutPrincipal=Creating DOMParser without a principal is deprecated.
 IIRFilterChannelCountChangeWarning=IIRFilterNode channel count changes may produce audio glitches.
 BiquadFilterChannelCountChangeWarning=BiquadFilterNode channel count changes may produce audio glitches.
 # LOCALIZATION NOTE: Do not translate ".jpeg"
 GenericImageNameJPEG=image.jpeg
 # LOCALIZATION NOTE: Do not translate ".gif"
 GenericImageNameGIF=image.gif
 # LOCALIZATION NOTE: Do not translate ".png"
 GenericImageNamePNG=image.png