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 // tests for hooking keyboard and mouse handlers | |
Matt Perry
2013/07/22 18:07:05
Use full sentences for comments.
| |
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 for (var i = 0; i < hookNames.length; i++) { | |
337 // handler on Element | |
338 code += 'document.body.' + hookNames[i] + ' = handlerHook;'; | |
339 | |
340 // handler on a Document | |
341 code += 'document.' + hookNames[i] + ' = handlerHook;'; | |
342 | |
343 // handler on a Window | |
344 code += 'window.' + hookNames[i] + ' = handlerHook;'; | |
345 } | |
346 | |
327 chrome.tabs.onUpdated.addListener( | 347 chrome.tabs.onUpdated.addListener( |
328 function callback(tabId, changeInfo, tab) { | 348 function callback(tabId, changeInfo, tab) { |
329 if (changeInfo['status'] === 'complete' && | 349 if (changeInfo['status'] === 'complete' && |
330 tab.url.match(/google\.com/g)) { | 350 tab.url.match(/google\.com/g)) { |
331 chrome.tabs.onUpdated.removeListener(callback); | 351 chrome.tabs.onUpdated.removeListener(callback); |
332 chrome.tabs.executeScript( | 352 chrome.tabs.executeScript( |
333 tabId, {'code': code}, | 353 tabId, {'code': code}, |
334 function() { | 354 function() { |
335 chrome.tabs.remove(tabId); | 355 chrome.tabs.remove(tabId); |
336 appendCompleted('executeDOMChangesOnTabUpdated'); | 356 appendCompleted('executeDOMChangesOnTabUpdated'); |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
420 } | 440 } |
421 if ($('incognito_checkbox') != null) { | 441 if ($('incognito_checkbox') != null) { |
422 $('incognito_checkbox').addEventListener( | 442 $('incognito_checkbox').addEventListener( |
423 'click', | 443 'click', |
424 function() { useIncognito = $('incognito_checkbox').checked; }); | 444 function() { useIncognito = $('incognito_checkbox').checked; }); |
425 } | 445 } |
426 completed = 0; | 446 completed = 0; |
427 appendCompleted('setup events'); | 447 appendCompleted('setup events'); |
428 } | 448 } |
429 document.addEventListener('DOMContentLoaded', setupEvents); | 449 document.addEventListener('DOMContentLoaded', setupEvents); |
OLD | NEW |