content/base/test/file_mozfiledataurl_inner.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/content/base/test/file_mozfiledataurl_inner.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,73 @@
     1.4 +<!doctype html>
     1.5 +<html>
     1.6 +<script type="application/javascript;version=1.8">
     1.7 +var img;
     1.8 +var audio;
     1.9 +var iframe;
    1.10 +
    1.11 +addEventListener("message", function(e) {
    1.12 +  mess = JSON.parse(e.data);
    1.13 +  
    1.14 +  if ("img" in mess)
    1.15 +    img.src = mess.img;
    1.16 +  else if ("audio" in mess)
    1.17 +    audio.src = mess.audio
    1.18 +  else if ("iframe" in mess)
    1.19 +    iframe.src = mess.iframe;
    1.20 +  else if ("xhr" in mess) {
    1.21 +    let xhr = new XMLHttpRequest();
    1.22 +    xhr.onload = function() {
    1.23 +      sendItUp({ text: xhr.responseText });
    1.24 +    }
    1.25 +    try {
    1.26 +      xhr.open("GET", mess.xhr);
    1.27 +      xhr.send();
    1.28 +    }
    1.29 +    catch (ex) {
    1.30 +      sendItUp({ didThrow: true });
    1.31 +    }
    1.32 +  }
    1.33 +
    1.34 +}, false);
    1.35 +
    1.36 +function sendItUp(obj) {
    1.37 +  window.parent.postMessage(JSON.stringify(obj), "*");
    1.38 +}
    1.39 +
    1.40 +function audioNotifyParent(e) {
    1.41 +  sendItUp({ type: e.type });
    1.42 +}
    1.43 +
    1.44 +function imgNotifyParent(e) {
    1.45 +  sendItUp({ type: e.type,
    1.46 +             width: e.target.width,
    1.47 +             height: e.target.height });
    1.48 +}
    1.49 +
    1.50 +function iframeNotifyParent(e) {
    1.51 +  res = { type: e.type };
    1.52 +  try {
    1.53 +    res.text = e.target.contentDocument.getElementsByTagName("p")[0].textContent;
    1.54 +  } catch (ex) {}
    1.55 +  try {
    1.56 +    res.imgWidth = e.target.contentDocument.getElementById("img").width;
    1.57 +  } catch (ex) {}
    1.58 +
    1.59 +  sendItUp(res);
    1.60 +}
    1.61 +
    1.62 +onload = function() {
    1.63 +  img = document.getElementById('img');
    1.64 +  img.onerror = img.onload = imgNotifyParent;
    1.65 +  iframe = document.getElementById('iframe');
    1.66 +  iframe.onerror = iframe.onload = iframeNotifyParent;
    1.67 +  audio = document.getElementById('audio');
    1.68 +  audio.onerror = audio.onloadeddata = audioNotifyParent;
    1.69 +}
    1.70 +
    1.71 +</script>
    1.72 +<body>
    1.73 +<img id=img>
    1.74 +<audio id=audio>
    1.75 +<iframe id=iframe></iframe>
    1.76 +</html>

mercurial