| 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 var kRemoveChars = /(\r|\n|\t|\u2028|\u2029)/gm; |
| 453 return text.trimLeft().replace(kRemoveChars, ''); |
| 454 } |
| 455 |
| 448 // Parses the xml syntax supported by omnibox suggestion results. Returns an | 456 // Parses the xml syntax supported by omnibox suggestion results. Returns an |
| 449 // object with two properties: 'description', which is just the text content, | 457 // object with two properties: 'description', which is just the text content, |
| 450 // and 'descriptionStyles', which is an array of style objects in a format | 458 // and 'descriptionStyles', which is an array of style objects in a format |
| 451 // understood by the C++ backend. | 459 // understood by the C++ backend. |
| 452 function parseOmniboxDescription(input) { | 460 function parseOmniboxDescription(input) { |
| 453 var domParser = new DOMParser(); | 461 var domParser = new DOMParser(); |
| 454 | 462 |
| 455 // The XML parser requires a single top-level element, but we want to | 463 // 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 | 464 // support things like 'hello, <match>world</match>!'. So we wrap the |
| 457 // provided text in generated root level element. | 465 // provided text in generated root level element. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 469 var result = { | 477 var result = { |
| 470 description: '', | 478 description: '', |
| 471 descriptionStyles: [] | 479 descriptionStyles: [] |
| 472 }; | 480 }; |
| 473 | 481 |
| 474 // Recursively walk the tree. | 482 // Recursively walk the tree. |
| 475 (function(node) { | 483 (function(node) { |
| 476 for (var i = 0, child; child = node.childNodes[i]; i++) { | 484 for (var i = 0, child; child = node.childNodes[i]; i++) { |
| 477 // Append text nodes to our description. | 485 // Append text nodes to our description. |
| 478 if (child.nodeType == Node.TEXT_NODE) { | 486 if (child.nodeType == Node.TEXT_NODE) { |
| 479 result.description += child.nodeValue; | 487 result.description += sanitizeString(child.nodeValue); |
| 480 continue; | 488 continue; |
| 481 } | 489 } |
| 482 | 490 |
| 483 // Process and descend into a subset of recognized tags. | 491 // Process and descend into a subset of recognized tags. |
| 484 if (child.nodeType == Node.ELEMENT_NODE && | 492 if (child.nodeType == Node.ELEMENT_NODE && |
| 485 (child.nodeName == 'dim' || child.nodeName == 'match' || | 493 (child.nodeName == 'dim' || child.nodeName == 'match' || |
| 486 child.nodeName == 'url')) { | 494 child.nodeName == 'url')) { |
| 487 var style = { | 495 var style = { |
| 488 'type': child.nodeName, | 496 'type': child.nodeName, |
| 489 'offset': result.description.length | 497 'offset': result.description.length |
| (...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1033 | 1041 |
| 1034 if (!chrome.tts) | 1042 if (!chrome.tts) |
| 1035 chrome.tts = {}; | 1043 chrome.tts = {}; |
| 1036 | 1044 |
| 1037 if (!chrome.ttsEngine) | 1045 if (!chrome.ttsEngine) |
| 1038 chrome.ttsEngine = {}; | 1046 chrome.ttsEngine = {}; |
| 1039 | 1047 |
| 1040 if (!chrome.experimental.downloads) | 1048 if (!chrome.experimental.downloads) |
| 1041 chrome.experimental.downloads = {}; | 1049 chrome.experimental.downloads = {}; |
| 1042 })(); | 1050 })(); |
| OLD | NEW |