OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 var defaultUrl = 'http://www.google.com'; | 5 var defaultUrl = 'http://www.google.com'; |
6 | 6 |
7 // Utility function to open a URL in a new tab. If the useIncognito global is | 7 // Utility function to open a URL in a new tab. If the useIncognito global is |
8 // true, the URL is opened in a new incognito window, otherwise it is opened in | 8 // true, the URL is opened in a new incognito window, otherwise it is opened in |
9 // a new tab in the current window. Alternatively, whether to use incognito | 9 // a new tab in the current window. Alternatively, whether to use incognito |
10 // can be specified as a second argument which overrides the global setting. | 10 // can be specified as a second argument which overrides the global setting. |
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 'var testContext = testCanvas.getContext("2d");'; | 317 'var testContext = testCanvas.getContext("2d");'; |
318 | 318 |
319 // Does an XHR from inside a content script. | 319 // Does an XHR from inside a content script. |
320 code += 'var request = new XMLHttpRequest(); ' + | 320 code += 'var request = new XMLHttpRequest(); ' + |
321 'request.open("POST", "http://www.cnn.com", false); ' + | 321 'request.open("POST", "http://www.cnn.com", false); ' + |
322 'request.setRequestHeader("Content-type", ' + | 322 'request.setRequestHeader("Content-type", ' + |
323 ' "text/plain;charset=UTF-8"); ' + | 323 ' "text/plain;charset=UTF-8"); ' + |
324 'request.send(); ' + | 324 'request.send(); ' + |
325 'document.write("sent an XHR");'; | 325 'document.write("sent an XHR");'; |
326 | 326 |
| 327 // This function is used as a handler for hooking mouse and keyboard events. |
| 328 code += 'function handlerHook(event) { };'; |
| 329 |
| 330 hookNames = ['onclick', 'ondblclick', 'ondrag', 'ondragend', 'ondragenter', |
| 331 'ondragleave', 'ondragover', 'ondragstart', 'ondrop', 'oninput', |
| 332 'onkeydown', 'onkeypress', 'onkeyup', 'onmousedown', |
| 333 'onmouseenter', 'onmouseleave', 'onmousemove', 'onmouseout', |
| 334 'onmouseover', 'onmouseup', 'onmousewheel']; |
| 335 |
| 336 // Access to each hook can be monitored for Element, Document, and Window. |
| 337 for (var i = 0; i < hookNames.length; i++) { |
| 338 // handler on Element |
| 339 code += 'document.body.' + hookNames[i] + ' = handlerHook;'; |
| 340 |
| 341 // handler on a Document |
| 342 code += 'document.' + hookNames[i] + ' = handlerHook;'; |
| 343 |
| 344 // handler on a Window |
| 345 code += 'window.' + hookNames[i] + ' = handlerHook;'; |
| 346 } |
| 347 |
327 chrome.tabs.onUpdated.addListener( | 348 chrome.tabs.onUpdated.addListener( |
328 function callback(tabId, changeInfo, tab) { | 349 function callback(tabId, changeInfo, tab) { |
329 if (changeInfo['status'] === 'complete' && | 350 if (changeInfo['status'] === 'complete' && |
330 tab.url.match(/google\.com/g)) { | 351 tab.url.match(/google\.com/g)) { |
331 chrome.tabs.onUpdated.removeListener(callback); | 352 chrome.tabs.onUpdated.removeListener(callback); |
332 chrome.tabs.executeScript( | 353 chrome.tabs.executeScript( |
333 tabId, {'code': code}, | 354 tabId, {'code': code}, |
334 function() { | 355 function() { |
335 chrome.tabs.remove(tabId); | 356 chrome.tabs.remove(tabId); |
336 appendCompleted('executeDOMChangesOnTabUpdated'); | 357 appendCompleted('executeDOMChangesOnTabUpdated'); |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
420 } | 441 } |
421 if ($('incognito_checkbox') != null) { | 442 if ($('incognito_checkbox') != null) { |
422 $('incognito_checkbox').addEventListener( | 443 $('incognito_checkbox').addEventListener( |
423 'click', | 444 'click', |
424 function() { useIncognito = $('incognito_checkbox').checked; }); | 445 function() { useIncognito = $('incognito_checkbox').checked; }); |
425 } | 446 } |
426 completed = 0; | 447 completed = 0; |
427 appendCompleted('setup events'); | 448 appendCompleted('setup events'); |
428 } | 449 } |
429 document.addEventListener('DOMContentLoaded', setupEvents); | 450 document.addEventListener('DOMContentLoaded', setupEvents); |
OLD | NEW |