Bug 1472829. Add use counters for document.open. r=smaug a=lizzard
authorBoris Zbarsky <bzbarsky@mit.edu>
Tue, 03 Jul 2018 17:48:53 -0400
changeset 477851 5db3df3d5a433545830b6199ba28d28c93ef5d34
parent 477850 e5972354da953a684cda4885accf6539eb09eae6
child 477852 ad56b08003a84f5bc1783cf38b760c41d9b915da
push id9445
push userarchaeopteryx@coole-files.de
push dateSat, 07 Jul 2018 21:43:02 +0000
treeherdermozilla-beta@0a939a1cd7f9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug, lizzard
bugs1472829
milestone62.0
Bug 1472829. Add use counters for document.open. r=smaug a=lizzard The idea is to count non-no-op document.open and to count how many times that's done with the replace argument set to "replace".
dom/base/UseCounters.conf
dom/html/nsHTMLDocument.cpp
--- a/dom/base/UseCounters.conf
+++ b/dom/base/UseCounters.conf
@@ -110,8 +110,12 @@ method console.groupCollapsed
 method console.groupEnd
 method console.time
 method console.timeLog
 method console.timeEnd
 method console.exception
 method console.timeStamp
 method console.profile
 method console.profileEnd
+
+// document.open information
+custom DocumentOpen calls document.open in a way that creates a new Window object
+custom DocumentOpenReplace calls document.open in a way that creates a new Window object and replaces the old history entry.
--- a/dom/html/nsHTMLDocument.cpp
+++ b/dom/html/nsHTMLDocument.cpp
@@ -1334,16 +1334,24 @@ nsHTMLDocument::Open(JSContext* cx,
            callerDocURI ? callerDocURI->GetSpecOrDefault().get() : "",
            thisURI ? thisURI->GetSpecOrDefault().get() : "");
 #endif
 
     aError.Throw(NS_ERROR_DOM_SECURITY_ERR);
     return nullptr;
   }
 
+  // At this point we know this is a valid-enough document.open() call
+  // and not a no-op.  Increment our use counters.
+  SetDocumentAndPageUseCounter(eUseCounter_custom_DocumentOpen);
+  bool isReplace = aReplace.LowerCaseEqualsLiteral("replace");
+  if (isReplace) {
+    SetDocumentAndPageUseCounter(eUseCounter_custom_DocumentOpenReplace);
+  }
+
   // Stop current loads targeted at the window this document is in.
   if (mScriptGlobalObject) {
     nsCOMPtr<nsIContentViewer> cv;
     shell->GetContentViewer(getter_AddRefs(cv));
 
     if (cv) {
       bool okToUnload;
       if (NS_SUCCEEDED(cv->PermitUnload(&okToUnload)) && !okToUnload) {
@@ -1562,18 +1570,17 @@ nsHTMLDocument::Open(JSContext* cx,
   // Prepare the docshell and the document viewer for the impending
   // out of band document.write()
   shell->PrepareForNewContentModel();
 
   // Now check whether we were opened with a "replace" argument.  If
   // so, we need to tell the docshell to not create a new history
   // entry for this load. Otherwise, make sure that we're doing a normal load,
   // not whatever type of load was previously done on this docshell.
-  shell->SetLoadType(aReplace.LowerCaseEqualsLiteral("replace") ?
-                       LOAD_NORMAL_REPLACE : LOAD_NORMAL);
+  shell->SetLoadType(isReplace ? LOAD_NORMAL_REPLACE : LOAD_NORMAL);
 
   nsCOMPtr<nsIContentViewer> cv;
   shell->GetContentViewer(getter_AddRefs(cv));
   if (cv) {
     cv->LoadStart(this);
   }
 
   // Add a wyciwyg channel request into the document load group