OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // This script contains privileged chrome extension related javascript APIs. | 5 // This script contains privileged chrome extension related javascript APIs. |
6 // It is loaded by pages whose URL has the chrome-extension protocol. | 6 // It is loaded by pages whose URL has the chrome-extension protocol. |
7 | 7 |
8 var chrome = chrome || {}; | 8 var chrome = chrome || {}; |
9 (function() { | 9 (function() { |
10 native function GetExtensionAPIDefinition(); | 10 native function GetExtensionAPIDefinition(); |
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
438 // if there is one. | 438 // if there is one. |
439 var id = arguments[0].menuItemId; | 439 var id = arguments[0].menuItemId; |
440 var onclick = chromeHidden.contextMenus.handlers[id]; | 440 var onclick = chromeHidden.contextMenus.handlers[id]; |
441 if (onclick) { | 441 if (onclick) { |
442 onclick.apply(null, arguments); | 442 onclick.apply(null, arguments); |
443 } | 443 } |
444 }); | 444 }); |
445 }; | 445 }; |
446 } | 446 } |
447 | 447 |
| 448 // Remove invalid characters from |text| so that it is suitable to use |
| 449 // for |AutocompleteMatch::contents|. |
| 450 function sanitizeString(text) { |
| 451 // NOTE: This logic mirrors |AutocompleteMatch::SanitizeString()|. |
| 452 // 0x2028 = line separator; 0x2029 = paragraph separator. |
| 453 var kRemoveChars = /(\r|\n|\t|\u2028|\u2029)/gm; |
| 454 return text.trimLeft().replace(kRemoveChars, ''); |
| 455 } |
| 456 |
448 // Parses the xml syntax supported by omnibox suggestion results. Returns an | 457 // Parses the xml syntax supported by omnibox suggestion results. Returns an |
449 // object with two properties: 'description', which is just the text content, | 458 // object with two properties: 'description', which is just the text content, |
450 // and 'descriptionStyles', which is an array of style objects in a format | 459 // and 'descriptionStyles', which is an array of style objects in a format |
451 // understood by the C++ backend. | 460 // understood by the C++ backend. |
452 function parseOmniboxDescription(input) { | 461 function parseOmniboxDescription(input) { |
453 var domParser = new DOMParser(); | 462 var domParser = new DOMParser(); |
454 | 463 |
455 // The XML parser requires a single top-level element, but we want to | 464 // The XML parser requires a single top-level element, but we want to |
456 // support things like 'hello, <match>world</match>!'. So we wrap the | 465 // support things like 'hello, <match>world</match>!'. So we wrap the |
457 // provided text in generated root level element. | 466 // provided text in generated root level element. |
(...skipping 11 matching lines...) Expand all Loading... |
469 var result = { | 478 var result = { |
470 description: '', | 479 description: '', |
471 descriptionStyles: [] | 480 descriptionStyles: [] |
472 }; | 481 }; |
473 | 482 |
474 // Recursively walk the tree. | 483 // Recursively walk the tree. |
475 (function(node) { | 484 (function(node) { |
476 for (var i = 0, child; child = node.childNodes[i]; i++) { | 485 for (var i = 0, child; child = node.childNodes[i]; i++) { |
477 // Append text nodes to our description. | 486 // Append text nodes to our description. |
478 if (child.nodeType == Node.TEXT_NODE) { | 487 if (child.nodeType == Node.TEXT_NODE) { |
479 result.description += child.nodeValue; | 488 result.description += sanitizeString(child.nodeValue); |
480 continue; | 489 continue; |
481 } | 490 } |
482 | 491 |
483 // Process and descend into a subset of recognized tags. | 492 // Process and descend into a subset of recognized tags. |
484 if (child.nodeType == Node.ELEMENT_NODE && | 493 if (child.nodeType == Node.ELEMENT_NODE && |
485 (child.nodeName == 'dim' || child.nodeName == 'match' || | 494 (child.nodeName == 'dim' || child.nodeName == 'match' || |
486 child.nodeName == 'url')) { | 495 child.nodeName == 'url')) { |
487 var style = { | 496 var style = { |
488 'type': child.nodeName, | 497 'type': child.nodeName, |
489 'offset': result.description.length | 498 'offset': result.description.length |
(...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1033 | 1042 |
1034 if (!chrome.tts) | 1043 if (!chrome.tts) |
1035 chrome.tts = {}; | 1044 chrome.tts = {}; |
1036 | 1045 |
1037 if (!chrome.ttsEngine) | 1046 if (!chrome.ttsEngine) |
1038 chrome.ttsEngine = {}; | 1047 chrome.ttsEngine = {}; |
1039 | 1048 |
1040 if (!chrome.experimental.downloads) | 1049 if (!chrome.experimental.downloads) |
1041 chrome.experimental.downloads = {}; | 1050 chrome.experimental.downloads = {}; |
1042 })(); | 1051 })(); |
OLD | NEW |