summaryrefslogtreecommitdiffstats
path: root/application/basilisk/components/search/content/searchReset.js
diff options
context:
space:
mode:
authorwolfbeast <mcwerewolf@gmail.com>2018-06-04 13:17:38 +0200
committerwolfbeast <mcwerewolf@gmail.com>2018-06-04 13:17:38 +0200
commita1be17c1cea81ebb1e8b131a662c698d78f3f7f2 (patch)
treea92f7de513be600cc07bac458183e9af40e00c06 /application/basilisk/components/search/content/searchReset.js
parentbf11fdd304898ac675e39b01b280d39550e419d0 (diff)
downloadUXP-a1be17c1cea81ebb1e8b131a662c698d78f3f7f2.tar
UXP-a1be17c1cea81ebb1e8b131a662c698d78f3f7f2.tar.gz
UXP-a1be17c1cea81ebb1e8b131a662c698d78f3f7f2.tar.lz
UXP-a1be17c1cea81ebb1e8b131a662c698d78f3f7f2.tar.xz
UXP-a1be17c1cea81ebb1e8b131a662c698d78f3f7f2.zip
Issue #303 Part 1: Move basilisk files from /browser to /application/basilisk
Diffstat (limited to 'application/basilisk/components/search/content/searchReset.js')
-rw-r--r--application/basilisk/components/search/content/searchReset.js90
1 files changed, 90 insertions, 0 deletions
diff --git a/application/basilisk/components/search/content/searchReset.js b/application/basilisk/components/search/content/searchReset.js
new file mode 100644
index 000000000..b541d41da
--- /dev/null
+++ b/application/basilisk/components/search/content/searchReset.js
@@ -0,0 +1,90 @@
+/* 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/. */
+
+"use strict";
+
+var {classes: Cc, interfaces: Ci, utils: Cu} = Components;
+
+Cu.import("resource://gre/modules/Services.jsm");
+
+const TELEMETRY_RESULT_ENUM = {
+ RESTORED_DEFAULT: 0,
+ KEPT_CURRENT: 1,
+ CHANGED_ENGINE: 2,
+ CLOSED_PAGE: 3,
+ OPENED_SETTINGS: 4
+};
+
+window.onload = function() {
+ let defaultEngine = document.getElementById("defaultEngine");
+ let originalDefault = Services.search.originalDefaultEngine;
+ defaultEngine.textContent = originalDefault.name;
+ defaultEngine.style.backgroundImage =
+ 'url("' + originalDefault.iconURI.spec + '")';
+
+ document.getElementById("searchResetChangeEngine").focus();
+ window.addEventListener("unload", recordPageClosed);
+ document.getElementById("linkSettingsPage")
+ .addEventListener("click", openingSettings);
+};
+
+function doSearch() {
+ let queryString = "";
+ let purpose = "";
+ let params = window.location.href.match(/^about:searchreset\?([^#]*)/);
+ if (params) {
+ params = params[1].split("&");
+ for (let param of params) {
+ if (param.startsWith("data="))
+ queryString = decodeURIComponent(param.slice(5));
+ else if (param.startsWith("purpose="))
+ purpose = param.slice(8);
+ }
+ }
+
+ let engine = Services.search.currentEngine;
+ let submission = engine.getSubmission(queryString, null, purpose);
+
+ window.removeEventListener("unload", recordPageClosed);
+
+ let win = window.QueryInterface(Ci.nsIInterfaceRequestor)
+ .getInterface(Ci.nsIWebNavigation)
+ .QueryInterface(Ci.nsIDocShellTreeItem)
+ .rootTreeItem
+ .QueryInterface(Ci.nsIInterfaceRequestor)
+ .getInterface(Ci.nsIDOMWindow);
+ win.openUILinkIn(submission.uri.spec, "current", false, submission.postData);
+}
+
+function openingSettings() {
+ record(TELEMETRY_RESULT_ENUM.OPENED_SETTINGS);
+ window.removeEventListener("unload", recordPageClosed);
+}
+
+function record(result) {
+ Services.telemetry.getHistogramById("SEARCH_RESET_RESULT").add(result);
+}
+
+function keepCurrentEngine() {
+ // Calling the currentEngine setter will force a correct loadPathHash to be
+ // written for this engine, so that we don't prompt the user again.
+ Services.search.currentEngine = Services.search.currentEngine;
+ record(TELEMETRY_RESULT_ENUM.KEPT_CURRENT);
+ doSearch();
+}
+
+function changeSearchEngine() {
+ let engine = Services.search.originalDefaultEngine;
+ if (engine.hidden)
+ engine.hidden = false;
+ Services.search.currentEngine = engine;
+
+ record(TELEMETRY_RESULT_ENUM.RESTORED_DEFAULT);
+
+ doSearch();
+}
+
+function recordPageClosed() {
+ record(TELEMETRY_RESULT_ENUM.CLOSED_PAGE);
+}