Bug 1180715 (4/4) - Use nsIURL methods instead of RegExp. review=ttaubert
authorOliver Henshaw <oliver.henshaw@gmail.com>
Tue, 20 Oct 2015 10:45:40 +0530
changeset 303649 0c42cb5532d79c78803208c0c25f0aa00ec27ad5
parent 303648 7b4f0495cf6d5f40298755b6d8d15434f449fa0c
child 303650 048e4bbd0fdd564a08496f34c282b60e1c05649b
push id1001
push userraliiev@mozilla.com
push dateMon, 18 Jan 2016 19:06:03 +0000
treeherdermozilla-release@8b89261f3ac4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1180715
milestone44.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 1180715 (4/4) - Use nsIURL methods instead of RegExp. review=ttaubert Also move host check from the parseURI caller to parseURI itself.
toolkit/components/thumbnails/PageThumbsProtocol.js
--- a/toolkit/components/thumbnails/PageThumbsProtocol.js
+++ b/toolkit/components/thumbnails/PageThumbsProtocol.js
@@ -115,19 +115,16 @@ Protocol.prototype = {
     throw Cr.NS_ERROR_NOT_AVAILABLE;
   },
 
   hasSubstitution(root) {
     return false;
   },
 
   resolveURI(resURI) {
-    if (resURI.host != PageThumbs.staticHost)
-      throw Cr.NS_ERROR_NOT_AVAILABLE;
-
     let {url} = parseURI(resURI);
     let path = PageThumbsStorage.getFilePathForURL(url);
     return OS.Path.toFileURI(path);
   },
 
   // xpcom machinery
   classID: Components.ID("{5a4ae9b5-f475-48ae-9dce-0b4c1d347884}"),
   QueryInterface: XPCOMUtils.generateQI([Ci.nsIProtocolHandler,
@@ -137,19 +134,20 @@ Protocol.prototype = {
 this.NSGetFactory = XPCOMUtils.generateNSGetFactory([Protocol]);
 
 /**
  * Parses a given URI and extracts all parameters relevant to this protocol.
  * @param aURI The URI to parse.
  * @return The parsed parameters.
  */
 function parseURI(aURI) {
-  let {scheme, staticHost} = PageThumbs;
-  let re = new RegExp("^" + scheme + "://" + staticHost + ".*?\\?");
-  let query = aURI.spec.replace(re, "");
+  if (aURI.host != PageThumbs.staticHost)
+    throw Cr.NS_ERROR_NOT_AVAILABLE;
+
+  let {query} = aURI.QueryInterface(Ci.nsIURL);
   let params = {};
 
   query.split("&").forEach(function (aParam) {
     let [key, value] = aParam.split("=").map(decodeURIComponent);
     params[key.toLowerCase()] = value;
   });
 
   return params;