Browse Source

Bug 21218: Switch search engine on about:tor if the one in the search bar changes

WARNING: Work in progress, don't merge.

 * Displays the "Something went wrong" about:tor failure message, except
   when you set a breakpoint on the `onSubmit()` function and
   singlestep.  In which case it works, because, being able to use the
   debugger to debug is overrated.

 * Someone should do something with `searchProviderInfo`.
Yawning Angel 2 years ago
parent
commit
b0fc7810f5
1 changed files with 38 additions and 1 deletions
  1. 38 1
      src/chrome/content/aboutTor/aboutTor.xhtml

+ 38 - 1
src/chrome/content/aboutTor/aboutTor.xhtml

@@ -155,6 +155,43 @@ function insertPropertyStrings()
   } catch(e) {};
 }
 
+function onSubmit() {
+  // Extract the query string.
+  let searchQuery = document.searchForm.q.value;
+  if (searchQuery == "") {
+    // No actual query.
+    return false;
+  }
+
+  // Query the current search engine.
+  let browserSearchService = Components.classes["@mozilla.org/browser/search-service;1"]
+                             .getService(Components.interfaces.nsIBrowserSearchService);
+  let e = browserSearchService.currentEngine;
+  if (e == null) {
+    // That's odd, there's no search engine configured.
+    return false;
+  }
+
+  // Get the URL for the search.
+  let submission = e.getSubmission(searchQuery, null);
+  if (submission == null) {
+    // No submission returned.
+    return false;
+  }
+
+  // Grab the current window.
+  try {
+    let wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
+                       .getService(Components.interfaces.nsIWindowMediator);
+    let browserWindow = wm.getMostRecentWindow("navigator:browser");
+    let browser = browserWindow.getBrowser();
+    browser.loadURIWithFlags(submission.uri.spec, 0, null, null, submission.postData);
+    return true;
+  } catch(e) {};
+
+  return false;
+}
+
 window.addEventListener("pageshow", function() {
   let evt = new CustomEvent("AboutTorLoad", { bubbles: true });
   document.dispatchEvent(evt);
@@ -196,7 +233,7 @@ window.addEventListener("pageshow", function() {
 </div>
 
 <div class="searchbox hideIfTorOff"> <!-- begin form based search -->
-  <form action="&aboutTor.searchDDGPost.link;" method="post">
+  <form name="searchForm" action="" onsubmit="onSubmit()">
   <div id="sxw">
     <div id="sbutton">
       <input name="b" id="sb" value="" title="&aboutTor.search.label;"