Commits

Satyr Murky committed 93b630f

Utils: Fixed `parseHtml`. (bitbucket#19)

  • Participants
  • Parent commits 50eda83

Comments (0)

Files changed (2)

ubiquity/modules/cmdutils.js

   };
   function parseDocument(doc) {
     var {$} = global, results = [], $doc = $(doc);
+    Utils.log(doc, $doc)
     function find($_, key) let (path = parser[key])
       !path ? $() : path.call ? path.call($_, $_) : $_.find(path);
     if ("container" in parser)

ubiquity/modules/utils.js

   var iframe = document.createElement("iframe");
   iframe.setAttribute("collapsed", true); // hide
   iframe.setAttribute("type", "content"); // secure
-  // needed to create a docshell
-  document.documentElement.appendChild(iframe);
-  var {docShell} = iframe;
+  var {docShell} = document.documentElement.appendChild(iframe);
   docShell.QueryInterface(Ci.nsIWebNavigation)
     .stop(Ci.nsIWebNavigation.STOP_NETWORK); // stop loading about:blank
   // turn off unneeded/unwanted/bad things
-  (docShell.allowJavascript =
-   docShell.allowAuth =
-   docShell.allowPlugins =
-   docShell.allowMetaRedirects =
-   docShell.allowSubframes =
-   docShell.allowImages = false);
-
-  // Convert the HTML text into an input stream.
-  var converter = Utils.UnicodeConverter;
-  converter.charset = "UTF-8";
-  var stream = converter.convertToInputStream(htmlText);
-  // Set up a channel to load the input stream.
-  var channel = (Cc["@mozilla.org/network/input-stream-channel;1"]
-                 .createInstance(Ci.nsIInputStreamChannel));
-  channel.setURI(Utils.IOService.newURI("about:blank", null, null));
-  channel.contentStream = stream;
-  // Load in the background so we don't trigger web progress listeners.
-  channel.QueryInterface(Ci.nsIRequest)
-    .loadFlags |= Ci.nsIRequest.LOAD_BACKGROUND;
-  // need to specify content type,
-  // so user isn't prompted to download "unknown" file type
-  var baseChannel = channel.QueryInterface(Ci.nsIChannel);
-  baseChannel.contentType = "text/html";
-  baseChannel.contentCharset = "UTF-8";
-
-  // background loads don't fire "load" events
+  docShell.allowJavascript    =
+  docShell.allowAuth          =
+  docShell.allowPlugins       =
+  docShell.allowMetaRedirects =
+  docShell.allowSubframes     =
+  docShell.allowImages        = false;
+  docShell.loadURI(
+    'data:text/html;charset=UTF-8,' + encodeURIComponent(htmlText),
+    Ci.nsIWebNavigation, null, null, null);
   listenOnce(iframe, "DOMContentLoaded", function onParsed() {
-    var doc = iframe.contentDocument;
+    callback(iframe.contentDocument);
     iframe.parentNode.removeChild(iframe);
-    callback(doc);
   }, true);
-  Cc["@mozilla.org/uriloader;1"].getService(Ci.nsIURILoader)
-    .openURI(channel, true, docShell);
 }
 
 // ** {{{ Utils.trim(str) }}} **