Home | History | Annotate | Download | only in data
      1 <script type="text/javascript">
      2 function sizeChanged(evt) {
      3   var data = JSON.parse(evt.detail);
      4   document.title = "AutoSize(" + data.newWidth + ", " + data.newHeight + ")";
      5 }
      6 
      7 function SetSrc(src) {
      8   var plugin = document.getElementById('plugin');
      9   plugin.src = src;
     10 }
     11 function SetSize(w, h) {
     12   var plugin = document.getElementById('plugin');
     13   plugin.width = w;
     14   plugin.height = h;
     15 }
     16 function PostMessage(data, shouldTargetIframe) {
     17   plugin = document.getElementById('plugin');
     18   // TODO(fsamuel): contentWindow can be accessed directly once
     19   // http://wkbug.com/85679 lands.
     20   if (shouldTargetIframe) {
     21     plugin.contentWindow.frames[0].postMessage('testing123', '*');
     22   } else {
     23     plugin.contentWindow.frames.postMessage('testing123', '*');
     24   }
     25 }
     26 function SetTitle(str) {
     27   document.title = str;
     28 }
     29 document.title = 'embedder';
     30 </script>
     31 
     32 <object id="plugin"
     33     tabindex="0"
     34     type="application/browser-plugin"
     35     width="640"
     36     height="480"
     37     border="0px"></object>
     38 <script type="text/javascript">
     39 var msg;
     40 function receiveMessage(event) {
     41   msg = event.data;
     42   if (msg == 'ready') {
     43     document.title = 'ready';
     44     return;
     45   }
     46   if (msg.indexOf('stop_ack') == -1) {
     47     event.source.postMessage('stop', '*');
     48   } else {
     49     var name = msg.replace("stop_ack", "").trim();
     50     if (name !== '') {
     51       window.document.title = name;
     52     } else {
     53       window.document.title = 'main guest';
     54     }
     55   }
     56 }
     57 
     58 var plugin = document.getElementById('plugin');
     59 window.addEventListener('message', receiveMessage, false);
     60 plugin.addEventListener('-internal-sizechanged', sizeChanged);
     61 plugin.addEventListener('-internal-instanceid-allocated', function(e) {
     62   plugin['-internal-attach']({});
     63 });
     64 </script>
     65