content/base/test/file_mozfiledataurl_inner.html

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 <!doctype html>
     2 <html>
     3 <script type="application/javascript;version=1.8">
     4 var img;
     5 var audio;
     6 var iframe;
     8 addEventListener("message", function(e) {
     9   mess = JSON.parse(e.data);
    11   if ("img" in mess)
    12     img.src = mess.img;
    13   else if ("audio" in mess)
    14     audio.src = mess.audio
    15   else if ("iframe" in mess)
    16     iframe.src = mess.iframe;
    17   else if ("xhr" in mess) {
    18     let xhr = new XMLHttpRequest();
    19     xhr.onload = function() {
    20       sendItUp({ text: xhr.responseText });
    21     }
    22     try {
    23       xhr.open("GET", mess.xhr);
    24       xhr.send();
    25     }
    26     catch (ex) {
    27       sendItUp({ didThrow: true });
    28     }
    29   }
    31 }, false);
    33 function sendItUp(obj) {
    34   window.parent.postMessage(JSON.stringify(obj), "*");
    35 }
    37 function audioNotifyParent(e) {
    38   sendItUp({ type: e.type });
    39 }
    41 function imgNotifyParent(e) {
    42   sendItUp({ type: e.type,
    43              width: e.target.width,
    44              height: e.target.height });
    45 }
    47 function iframeNotifyParent(e) {
    48   res = { type: e.type };
    49   try {
    50     res.text = e.target.contentDocument.getElementsByTagName("p")[0].textContent;
    51   } catch (ex) {}
    52   try {
    53     res.imgWidth = e.target.contentDocument.getElementById("img").width;
    54   } catch (ex) {}
    56   sendItUp(res);
    57 }
    59 onload = function() {
    60   img = document.getElementById('img');
    61   img.onerror = img.onload = imgNotifyParent;
    62   iframe = document.getElementById('iframe');
    63   iframe.onerror = iframe.onload = iframeNotifyParent;
    64   audio = document.getElementById('audio');
    65   audio.onerror = audio.onloadeddata = audioNotifyParent;
    66 }
    68 </script>
    69 <body>
    70 <img id=img>
    71 <audio id=audio>
    72 <iframe id=iframe></iframe>
    73 </html>

mercurial