| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 document.addEventListener('DOMContentLoaded', function() { |
| 6 |
| 7 var deleteNode = function(node) { |
| 8 node.parentNode.removeChild(node); |
| 9 }; |
| 10 |
| 11 var deleteAWebview = function() { |
| 12 deleteNode(document.querySelector('.ib')); |
| 13 }; |
| 14 |
| 15 var findContainer = function(node) { |
| 16 var container = node; |
| 17 while (container && !container.classList.contains('ib')) { |
| 18 container = container.parentElement; |
| 19 } |
| 20 return container; |
| 21 }; |
| 22 |
| 23 var handleDelete = function(event) { |
| 24 var container = findContainer(event.target); |
| 25 if (container) { |
| 26 deleteNode(container); |
| 27 } |
| 28 }; |
| 29 |
| 30 var viewScreenshot = function(wv) { |
| 31 return function(data) { |
| 32 chrome.app.window.create('display.html', { |
| 33 innerBounds: { width: wv.clientWidth, height: wv.clientHeight } |
| 34 }, |
| 35 function(aw) { |
| 36 var d = aw.contentWindow.document; |
| 37 d.addEventListener('DOMContentLoaded', function() { |
| 38 var img = d.createElement('img'); |
| 39 img.src = data; |
| 40 d.body.appendChild(img); |
| 41 }); |
| 42 }); |
| 43 }; |
| 44 }; |
| 45 |
| 46 var handleScreenshot = function(event) { |
| 47 var container = findContainer(event.target); |
| 48 var wv = container.querySelector('webview'); |
| 49 wv.captureVisibleRegion({format:'png'}, viewScreenshot(wv)); |
| 50 }; |
| 51 |
| 52 var getControls = (function() { |
| 53 var controls = document.createElement('div'); |
| 54 controls.className = 'controls'; |
| 55 controls.innerHTML = '<button id="screenshot">Screenshot</button>' + |
| 56 '<button id="delete">Delete webview</button>'; |
| 57 |
| 58 return function() { |
| 59 var c = controls.cloneNode(true); |
| 60 c.querySelector('#delete').addEventListener('click', handleDelete); |
| 61 c.querySelector('#screenshot'). |
| 62 addEventListener('click', handleScreenshot); |
| 63 return c; |
| 64 }; |
| 65 })(); |
| 66 |
| 67 var createWebview = (function(){ |
| 68 var id = 0; |
| 69 return function() { |
| 70 var wv = document.createElement('webview'); |
| 71 wv.partition = "partition"; |
| 72 wv.src = 'test2.html'; |
| 73 wv.allowtransparency = document.getElementById('transparent').checked; |
| 74 wv.style.width = "640px"; |
| 75 wv.style.height = "480px"; |
| 76 |
| 77 var container = document.createElement('div'); |
| 78 container.id = 'wvid0' + id; |
| 79 id++; |
| 80 |
| 81 container.className = 'ib'; |
| 82 |
| 83 container.appendChild(wv); |
| 84 container.appendChild(getControls()); |
| 85 return container; |
| 86 }; |
| 87 })(); |
| 88 |
| 89 document.getElementById('delete_wv'). |
| 90 addEventListener('click', deleteAWebview); |
| 91 document.getElementById('add_wv'). |
| 92 addEventListener('click', function() { |
| 93 document.body.appendChild(createWebview()); |
| 94 }); |
| 95 }); |
| OLD | NEW |