OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2009 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 var button = null; |
| 6 var my_window = null; |
| 7 var screenshot_url = null; |
| 8 var child_loaded = false; |
| 9 var have_screenshot = false; |
| 10 |
| 11 function registerHandlers() { |
| 12 button = document.getElementById("button"); |
| 13 button.addEventListener("click",handleClick); |
| 14 } |
| 15 |
| 16 function waitForChildLoaded() { |
| 17 if(child_loaded && have_screenshot) { |
| 18 var foo = my_window.document.getElementById("replacer"); |
| 19 foo.src = screenshot_url; |
| 20 have_screenshot = false; |
| 21 } else { |
| 22 window.setTimeout(waitForChildLoaded, 50); |
| 23 } |
| 24 } |
| 25 |
| 26 function handleClick() { |
| 27 child_loaded = false; |
| 28 chrome.tabs.getVisibleTabCapture(null, |
| 29 function(img) { |
| 30 try { |
| 31 have_screenshot = true; |
| 32 screenshot_url = img; |
| 33 } catch(e) { |
| 34 for(var f in e) { |
| 35 console.log(f + ":" + e[f]); |
| 36 } |
| 37 } |
| 38 }); |
| 39 my_window = window.open('popup.html'); |
| 40 window.setTimeout(waitForChildLoaded, 50); |
| 41 } |
| 42 |
| 43 function childLoaded() { |
| 44 child_loaded = true; |
| 45 } |
OLD | NEW |