Bug 1348409 - Stop supporting the showDialog argument for window.find. r=mrbkap, a=gchang
authorMike Conley <mconley@mozilla.com>
Thu, 13 Apr 2017 11:54:15 -0400
changeset 396019 a236801aa0225218df1f74cc365bd68b6305a5db
parent 396018 7f717abab712539d4134e4ce6bc23c63019fd102
child 396020 29dc135a663736818cc4106c2f4dfb35b08682ae
push id1468
push userasasaki@mozilla.com
push dateMon, 05 Jun 2017 19:31:07 +0000
treeherdermozilla-release@0641fc6ee9d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmrbkap, gchang
bugs1348409, 1182569, 1232432
milestone54.0
Bug 1348409 - Stop supporting the showDialog argument for window.find. r=mrbkap, a=gchang The dialog functionality of the non-standard window.find API has been broken with e10s since it shipped, and bug 1182569 or bug 1232432 (or both) have broken it for non-e10s. This patch remove showDialog support entirely, for both e10s and non-e10s, in a more deliberate way. We now ignore the argument. MozReview-Commit-ID: 1CTzgEkDhHW
dom/base/nsGlobalWindow.cpp
dom/tests/mochitest/bugs/mochitest.ini
dom/tests/mochitest/bugs/test_no_find_showDialog.html
--- a/dom/base/nsGlobalWindow.cpp
+++ b/dom/base/nsGlobalWindow.cpp
@@ -9956,16 +9956,18 @@ nsGlobalWindow::GetSelection()
 bool
 nsGlobalWindow::FindOuter(const nsAString& aString, bool aCaseSensitive,
                           bool aBackwards, bool aWrapAround, bool aWholeWord,
                           bool aSearchInFrames, bool aShowDialog,
                           ErrorResult& aError)
 {
   MOZ_RELEASE_ASSERT(IsOuterWindow());
 
+  Unused << aShowDialog;
+
   if (Preferences::GetBool("dom.disable_window_find", false)) {
     aError.Throw(NS_ERROR_NOT_AVAILABLE);
     return false;
   }
 
   nsCOMPtr<nsIWebBrowserFind> finder(do_GetInterface(mDocShell));
   if (!finder) {
     aError.Throw(NS_ERROR_NOT_AVAILABLE);
@@ -9988,42 +9990,17 @@ nsGlobalWindow::FindOuter(const nsAStrin
   // frame. If we're being called from JS (as here), this window
   // should be the current search frame.
   nsCOMPtr<nsIWebBrowserFindInFrames> framesFinder(do_QueryInterface(finder));
   if (framesFinder) {
     framesFinder->SetRootSearchFrame(AsOuter());   // paranoia
     framesFinder->SetCurrentSearchFrame(AsOuter());
   }
 
-  // The Find API does not accept empty strings. Launch the Find Dialog.
-  if (aString.IsEmpty() || aShowDialog) {
-    // See if the find dialog is already up using nsIWindowMediator
-    nsCOMPtr<nsIWindowMediator> windowMediator =
-      do_GetService(NS_WINDOWMEDIATOR_CONTRACTID);
-
-    nsCOMPtr<mozIDOMWindowProxy> findDialog;
-
-    if (windowMediator) {
-      windowMediator->GetMostRecentWindow(u"findInPage",
-                                          getter_AddRefs(findDialog));
-    }
-
-    if (findDialog) {
-      // The Find dialog is already open, bring it to the top.
-      auto* piFindDialog = nsPIDOMWindowOuter::From(findDialog);
-      aError = piFindDialog->Focus();
-    } else if (finder) {
-      // Open a Find dialog
-      nsCOMPtr<nsPIDOMWindowOuter> dialog;
-      aError = OpenDialog(NS_LITERAL_STRING("chrome://global/content/finddialog.xul"),
-                          NS_LITERAL_STRING("_blank"),
-                          NS_LITERAL_STRING("chrome, resizable=no, dependent=yes"),
-                          finder, getter_AddRefs(dialog));
-    }
-
+  if (aString.IsEmpty()) {
     return false;
   }
 
   // Launch the search with the passed in search string
   bool didFind = false;
   aError = finder->FindNext(&didFind);
   return didFind;
 }
--- a/dom/tests/mochitest/bugs/mochitest.ini
+++ b/dom/tests/mochitest/bugs/mochitest.ini
@@ -157,8 +157,10 @@ skip-if = toolkit == 'android' || os == 
 skip-if = toolkit == 'android' #Windows can't change size on Android
 [test_toJSON.html]
 [test_window_bar.html]
 skip-if = toolkit == 'android'
 [test_bug1022869.html]
 [test_bug1112040.html]
 [test_bug1160342_marquee.html]
 [test_bug1171215.html]
+[test_no_find_showDialog.html]
+skip-if = toolkit == 'android' # Bug 1358633 - window.find doesn't work for Android
new file mode 100644
--- /dev/null
+++ b/dom/tests/mochitest/bugs/test_no_find_showDialog.html
@@ -0,0 +1,92 @@
+<!DOCTYPE html>
+<html>
+<head>
+  <meta charset="utf-8">
+  <title>Test for Bug 1348409</title>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="application/javascript" src="/tests/SimpleTest/SpawnTask.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+  <iframe src="about:blank"></iframe>
+  <script type="text/javascript; version=1.8">
+
+  function checkForFindDialog() {
+    let chromeScript = SpecialPowers.loadChromeScript(_ => {
+      addMessageListener("test:check", () => {
+        const { utils: Cu } = Components;
+
+        Cu.import("resource://gre/modules/Services.jsm");
+
+        let sawFind = false;
+        let findDialog = Services.wm.getMostRecentWindow("findInPage");
+        if (findDialog) {
+          findDialog.close();
+          sawFind = true;
+        }
+
+        return sawFind;
+      });
+
+    });
+
+    let sawFind = chromeScript.sendSyncMessage("test:check")[0][0];
+    chromeScript.destroy();
+    return sawFind;
+  }
+
+  function ensureFinished(chromeScript) {
+    return new Promise(resolve => {
+      chromeScript.addMessageListener("test:disarm:done", (sawWindow) => {
+        resolve(sawWindow);
+      });
+      chromeScript.sendAsyncMessage("test:disarm");
+    });
+  }
+
+  function doWraparoundFind(findString, showDialog) {
+    let result = window.find(findString,
+                             false /* aCaseSensitive */,
+                             false /* aBackwards*/,
+                             true /* aWrapAround */,
+                             false /* aWholeWord */,
+                             false /* aSearchInFrames */,
+                             showDialog /* aShowInDialog */)
+    // Collapse selection so that we can do another find outside
+    // of the selection result.
+    document.getSelection().collapseToStart();
+    return result;
+  }
+
+  function startTest() {
+    add_task(function*() {
+      ok(doWraparoundFind("text to search for", false),
+         "Found the text in the document body.");
+
+      // We're asking for the dialog now. We should just ignore that request.
+      ok(doWraparoundFind("fhqwhgads", true),
+         "Should return true and not show a dialog if the string exists in the page.");
+      ok(!doWraparoundFind(null, true),
+         "Should return false and not show a dialog if we pass a null string.");
+      ok(!doWraparoundFind("", true),
+         "Should return false and not show a dialog if we pass an empty string.");
+
+      // Double check to ensure that the parent didn't open a find dialog
+      let sawWindow = checkForFindDialog();
+      ok(!sawWindow, "Should never have seen the dialog.");
+    });
+  }
+  </script>
+</head>
+<body onload="startTest()">
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1348409">Mozilla Bug 1348409</a>
+
+<p>
+  Here's some text to search for: fhqwhgads! A hovercraft full of eels!
+</p>
+
+<p id="display"></p>
+<div id="content" style="display: none">
+</div>
+<pre id="test">
+</pre>
+</body>
+</html>
\ No newline at end of file