Bug 1385222 - Add the search functionality in the sitePermissions.xul dialog. r=johannh
authorPrathiksha <prathikshaprasadsuman@gmail.com>
Tue, 08 Aug 2017 12:19:47 +0530
changeset 374315 7fbddf36c4cdfde02897295113df18fef68a1c8f
parent 374314 0ebb9924affaa4dc16687986d57dda7c773d8a25
child 374316 64e7486cf038872939913a21c2e1e68f09cb1000
push id32320
push userarchaeopteryx@coole-files.de
push dateSat, 12 Aug 2017 21:35:10 +0000
treeherdermozilla-central@6062341662fc [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjohannh
bugs1385222
milestone57.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1385222 - Add the search functionality in the sitePermissions.xul dialog. r=johannh MozReview-Commit-ID: JFkZPfL0hJl
browser/components/preferences/in-content-new/tests/browser_permissions_dialog.js
browser/components/preferences/sitePermissions.js
browser/components/preferences/sitePermissions.xul
browser/locales/en-US/chrome/browser/preferences/permissions.dtd
--- a/browser/components/preferences/in-content-new/tests/browser_permissions_dialog.js
+++ b/browser/components/preferences/in-content-new/tests/browser_permissions_dialog.js
@@ -203,13 +203,35 @@ add_task(async function onPermissionDele
 
   await waitForCondition(() => richlistbox.itemCount == 0);
 
   doc.getElementById("cancel").click();
 
   Assert.equal(SitePermissions.get(URI, "desktop-notification").state,
                SitePermissions.ALLOW,
                "Permission state does not change on clicking cancel");
+
+  SitePermissions.remove(URI, "desktop-notification");
+});
+
+add_task(async function onSearch() {
+  await openPermissionsDialog();
+  let doc = sitePermissionsDialog.document;
+  let richlistbox = doc.getElementById("permissionsBox");
+  let searchBox = doc.getElementById("searchBox");
+
+  SitePermissions.set(URI, "desktop-notification", SitePermissions.ALLOW);
+  searchBox.value = "www.example.com";
+
+  let u = Services.io.newURI("http://www.test.com");
+  SitePermissions.set(u, "desktop-notification", SitePermissions.ALLOW);
+
+  Assert.equal(doc.getElementsByAttribute("origin", "http://www.test.com")[0], null);
+  Assert.equal(doc.getElementsByAttribute("origin", "http://www.example.com")[0],
+               richlistbox.getItemAtIndex(0));
+
+  SitePermissions.remove(URI, "desktop-notification");
+  SitePermissions.remove(u, "desktop-notification");
 });
 
 add_task(async function removeTab() {
   gBrowser.removeCurrentTab();
 });
--- a/browser/components/preferences/sitePermissions.js
+++ b/browser/components/preferences/sitePermissions.js
@@ -19,16 +19,17 @@ var gSitePermissionsManager = {
   _isObserving: false,
   _permissions: new Map(),
   _permissionsToChange: new Map(),
   _permissionsToDelete: new Map(),
   _list: null,
   _bundle: null,
   _removeButton: null,
   _removeAllButton: null,
+  _searchBox: null,
 
   onLoad() {
     let params = window.arguments[0];
     this.init(params);
   },
 
   init(params) {
     if (!this._isObserving) {
@@ -36,25 +37,28 @@ var gSitePermissionsManager = {
       this._isObserving = true;
     }
 
     this._bundle = document.getElementById("bundlePreferences");
     this._type = params.permissionType;
     this._list = document.getElementById("permissionsBox");
     this._removeButton = document.getElementById("removePermission");
     this._removeAllButton = document.getElementById("removeAllPermissions");
+    this._searchBox = document.getElementById("searchBox");
 
     let permissionsText = document.getElementById("permissionsText");
     while (permissionsText.hasChildNodes())
       permissionsText.firstChild.remove();
     permissionsText.appendChild(document.createTextNode(params.introText));
 
     document.title = params.windowTitle;
 
     this._loadPermissions();
+
+    this._searchBox.focus();
   },
 
   uninit() {
     if (this._isObserving) {
       Services.obs.removeObserver(this, "perm-changed");
       this._isObserving = false;
     }
   },
@@ -66,16 +70,19 @@ var gSitePermissionsManager = {
     let permission = subject.QueryInterface(Components.interfaces.nsIPermission);
 
     // Ignore unrelated permission types.
     if (permission.type !== this._type)
       return;
 
     if (data == "added") {
       this._addPermissionToList(permission);
+      if (this._searchBox.value != "") {
+        this.filterPermissionsList();
+      }
     } else if (data == "changed") {
       let p = this._permissions.get(permission.principal.origin);
       p.capability = permission.capability;
       p.capabilityString = this._getCapabilityString(permission.capability);
       this._handleCapabilityChange(p);
     } else if (data == "deleted") {
       this._removePermissionFromList(permission.principal.origin);
     }
@@ -247,9 +254,28 @@ var gSitePermissionsManager = {
     }
 
     for (let p of this._permissionsToDelete.values()) {
       let uri = Services.io.newURI(p.origin);
       SitePermissions.remove(uri, p.type);
     }
     window.close();
   },
+
+  filterPermissionsList() {
+    // Clear old entries.
+    let oldItems = this._list.querySelectorAll("richlistitem");
+    for (let item of oldItems) {
+      item.remove();
+    }
+
+    let keyword = this._searchBox.value.toLowerCase().trim();
+    let permissions = this._permissions;
+    for (let [origin, permission] of permissions) {
+      if (keyword && !origin.includes(keyword)) {
+        continue;
+      }
+
+      this._createPermissionListItem(permission);
+    }
+    this._setRemoveButtonState();
+  },
 };
--- a/browser/components/preferences/sitePermissions.xul
+++ b/browser/components/preferences/sitePermissions.xul
@@ -27,18 +27,18 @@
   <keyset>
     <key key="&windowClose.key;" modifiers="accel" oncommand="window.close();"/>
   </keyset>
 
   <vbox class="contentPane largeDialogContainer" flex="1">
     <description id="permissionsText" control="url"/>
     <separator class="thin"/>
     <hbox align="start">
-      <textbox id="url" flex="1" placeholder="Search Website"
-               type="search"/>
+      <textbox id="searchBox" flex="1" placeholder="&searchbox.placeholder;"
+               type="search" oncommand="gSitePermissionsManager.filterPermissionsList();"/>
     </hbox>
     <separator class="thin"/>
     <richlistbox id="permissionsBox" selected="false"
                  hidecolumnpicker="true" flex="1"
                  onkeypress="gSitePermissionsManager.onPermissionKeyPress(event);"
                  onselect="gSitePermissionsManager.onPermissionSelect();">
       <listheader>
         <treecol id="siteCol" label="&treehead.sitename2.label;" flex="3"
--- a/browser/locales/en-US/chrome/browser/preferences/permissions.dtd
+++ b/browser/locales/en-US/chrome/browser/preferences/permissions.dtd
@@ -21,8 +21,9 @@
 <!ENTITY allow.accesskey              "A">
 <!ENTITY windowClose.key              "w">
 
 <!ENTITY button.cancel.label          "Cancel">
 <!ENTITY button.cancel.accesskey      "C">
 <!ENTITY button.ok.label              "Save Changes">
 <!ENTITY button.ok.accesskey          "S">
 
+<!ENTITY searchbox.placeholder        "Search Website">