GPU workaround to simulate Out of Memory errors with large textures
[chromium-blink-merge.git] / native_client_sdk / src / build_tools / screenshot_extension / injected.js
blobf90e233b67896a22dd64989222f57be60d739e85
1 // Copyright (c) 2013 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.
5 // Only inject once.
6 if (!document.body.getAttribute('screenshot_extension_injected')) {
7 document.body.setAttribute('screenshot_extension_injected', true);
8 (function() {
10 // Bounce message from webpage to background page.
12 // Expecting a message called with:
13 // window.postMessage({
14 // id: <a value that is passed back unchanged to the response for
15 // identification>,
16 // target: 'background'
17 // }, '*');
19 // When the screenshot is captured, a message will be posted to the window.
20 // Listen for it like this:
22 // window.addEventListener('message', function(event) {
23 // if (event.source !== window)
24 // return;
26 // if (event.data.target !== 'page')
27 // return;
29 // // event.data is an object:
30 // // {
31 // // id: <the id passed to the request>,
32 // // target: 'page',
33 // // data: <a data URI of MIMEtype image/png with the tab screenshot>
34 // // }
35 // //
36 // // or if there is an error:
37 // //
38 // // {
39 // // id: <the id passed to the request>,
40 // // target: 'page',
41 // // error: <an error string>
42 // // }
43 // }, false);
45 window.addEventListener('message', function(event) {
46 if (event.source !== window)
47 return;
49 // Ignore messages not destined for the background page.
50 if (event.data.target !== 'background')
51 return;
53 var id = event.data.id;
54 console.log('sending message: id=' + id);
56 chrome.runtime.sendMessage(null, {},
57 function(responseData) {
58 // Bounce response from background page back to webpage.
59 var lastError = chrome.runtime.lastError;
60 if (lastError) {
61 console.log('lastError: ' + lastError);
63 window.postMessage({id: id, target: 'page', error: lastError},
64 '*');
65 return;
68 console.log('received response: id=' + id);
70 window.postMessage({id: id, target: 'page', data: responseData},
71 '*');
72 });
73 }, false);
74 })();