Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // <include src="assert.js"> | 5 // <include src="assert.js"> |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * Alias for document.getElementById. Found elements must be HTMLElements. | 8 * Alias for document.getElementById. Found elements must be HTMLElements. |
| 9 * @param {string} id The ID of the element to find. | 9 * @param {string} id The ID of the element to find. |
| 10 * @return {HTMLElement} The found element or null if not found. | 10 * @return {HTMLElement} The found element or null if not found. |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 206 */ | 206 */ |
| 207 function queryRequiredElement(selectors, opt_context) { | 207 function queryRequiredElement(selectors, opt_context) { |
| 208 var element = (opt_context || document).querySelector(selectors); | 208 var element = (opt_context || document).querySelector(selectors); |
| 209 return assertInstanceof(element, HTMLElement, | 209 return assertInstanceof(element, HTMLElement, |
| 210 'Missing required element: ' + selectors); | 210 'Missing required element: ' + selectors); |
| 211 } | 211 } |
| 212 | 212 |
| 213 // Handle click on a link. If the link points to a chrome: or file: url, then | 213 // Handle click on a link. If the link points to a chrome: or file: url, then |
| 214 // call into the browser to do the navigation. | 214 // call into the browser to do the navigation. |
| 215 document.addEventListener('click', function(e) { | 215 document.addEventListener('click', function(e) { |
| 216 if (e.defaultPrevented) | 216 if (e.defaultPrevented) |
|
Dan Beam
2016/08/02 06:02:44
nit: in my ideal world
if (e.defaultPrevented ||
calamity
2016/08/08 05:06:43
Acknowledged.
| |
| 217 return; | 217 return; |
| 218 | 218 |
| 219 var el = e.target; | 219 var eventPath = e.path; |
|
Dan Beam
2016/08/02 06:02:43
this code runs on safari, which may have dodgy sup
calamity
2016/08/08 05:06:43
Done.
| |
| 220 if (el.nodeType == Node.ELEMENT_NODE && | 220 var anchor = null; |
| 221 el.webkitMatchesSelector('A, A *')) { | 221 for (var i = 0; i < eventPath.length; i++) { |
| 222 while (el.tagName != 'A') { | 222 var element = eventPath[i]; |
| 223 el = el.parentElement; | 223 if (element.tagName === 'A' && element.href) { |
| 224 anchor = element; | |
| 225 break; | |
| 224 } | 226 } |
| 227 } | |
| 225 | 228 |
| 226 if ((el.protocol == 'file:' || el.protocol == 'about:') && | 229 if (!anchor) |
| 227 (e.button == 0 || e.button == 1)) { | 230 return; |
| 228 chrome.send('navigateToUrl', [ | 231 |
| 229 el.href, | 232 if ((anchor.protocol == 'file:' || anchor.protocol == 'about:') && |
| 230 el.target, | 233 (e.button == 0 || e.button == 1)) { |
| 231 e.button, | 234 chrome.send('navigateToUrl', [ |
| 232 e.altKey, | 235 anchor.href, |
| 233 e.ctrlKey, | 236 anchor.target, |
| 234 e.metaKey, | 237 e.button, |
| 235 e.shiftKey | 238 e.altKey, |
| 236 ]); | 239 e.ctrlKey, |
| 237 e.preventDefault(); | 240 e.metaKey, |
| 238 } | 241 e.shiftKey |
| 242 ]); | |
| 243 e.preventDefault(); | |
| 239 } | 244 } |
| 240 }); | 245 }); |
| 241 | 246 |
| 242 /** | 247 /** |
| 243 * Creates a new URL which is the old URL with a GET param of key=value. | 248 * Creates a new URL which is the old URL with a GET param of key=value. |
| 244 * @param {string} url The base URL. There is not sanity checking on the URL so | 249 * @param {string} url The base URL. There is not sanity checking on the URL so |
| 245 * it must be passed in a proper format. | 250 * it must be passed in a proper format. |
| 246 * @param {string} key The key of the param. | 251 * @param {string} key The key of the param. |
| 247 * @param {string} value The value of the param. | 252 * @param {string} value The value of the param. |
| 248 * @return {string} The new URL. | 253 * @return {string} The new URL. |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 432 case 0xdb: return '['; | 437 case 0xdb: return '['; |
| 433 case 0xdd: return ']'; | 438 case 0xdd: return ']'; |
| 434 } | 439 } |
| 435 return 'Unidentified'; | 440 return 'Unidentified'; |
| 436 } | 441 } |
| 437 }); | 442 }); |
| 438 } else { | 443 } else { |
| 439 window.console.log("KeyboardEvent.Key polyfill not required"); | 444 window.console.log("KeyboardEvent.Key polyfill not required"); |
| 440 } | 445 } |
| 441 // </if> /* is_ios */ | 446 // </if> /* is_ios */ |
| OLD | NEW |