Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(200)

Side by Side Diff: chrome/renderer/resources/extensions/schema_generated_bindings.js

Issue 8824018: Fixed regression with extension omnibox API where whitespace would get trimmed (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: comment Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 454 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 var onclick = chromeHidden.contextMenus.handlers[id]; 465 var onclick = chromeHidden.contextMenus.handlers[id];
466 if (onclick) { 466 if (onclick) {
467 onclick.apply(null, arguments); 467 onclick.apply(null, arguments);
468 } 468 }
469 }); 469 });
470 }; 470 };
471 } 471 }
472 472
473 // Remove invalid characters from |text| so that it is suitable to use 473 // Remove invalid characters from |text| so that it is suitable to use
474 // for |AutocompleteMatch::contents|. 474 // for |AutocompleteMatch::contents|.
475 function sanitizeString(text) { 475 function sanitizeString(text, shouldTrim) {
476 // NOTE: This logic mirrors |AutocompleteMatch::SanitizeString()|. 476 // NOTE: This logic mirrors |AutocompleteMatch::SanitizeString()|.
477 // 0x2028 = line separator; 0x2029 = paragraph separator. 477 // 0x2028 = line separator; 0x2029 = paragraph separator.
478 var kRemoveChars = /(\r|\n|\t|\u2028|\u2029)/gm; 478 var kRemoveChars = /(\r|\n|\t|\u2028|\u2029)/gm;
479 return text.trimLeft().replace(kRemoveChars, ''); 479 if (shouldTrim)
480 text = text.trimLeft();
481 return text.replace(kRemoveChars, '');
480 } 482 }
481 483
482 // Parses the xml syntax supported by omnibox suggestion results. Returns an 484 // Parses the xml syntax supported by omnibox suggestion results. Returns an
483 // object with two properties: 'description', which is just the text content, 485 // object with two properties: 'description', which is just the text content,
484 // and 'descriptionStyles', which is an array of style objects in a format 486 // and 'descriptionStyles', which is an array of style objects in a format
485 // understood by the C++ backend. 487 // understood by the C++ backend.
486 function parseOmniboxDescription(input) { 488 function parseOmniboxDescription(input) {
487 var domParser = new DOMParser(); 489 var domParser = new DOMParser();
488 490
489 // The XML parser requires a single top-level element, but we want to 491 // The XML parser requires a single top-level element, but we want to
(...skipping 13 matching lines...) Expand all
503 var result = { 505 var result = {
504 description: '', 506 description: '',
505 descriptionStyles: [] 507 descriptionStyles: []
506 }; 508 };
507 509
508 // Recursively walk the tree. 510 // Recursively walk the tree.
509 (function(node) { 511 (function(node) {
510 for (var i = 0, child; child = node.childNodes[i]; i++) { 512 for (var i = 0, child; child = node.childNodes[i]; i++) {
511 // Append text nodes to our description. 513 // Append text nodes to our description.
512 if (child.nodeType == Node.TEXT_NODE) { 514 if (child.nodeType == Node.TEXT_NODE) {
513 result.description += sanitizeString(child.nodeValue); 515 var shouldTrim = result.description.length == 0;
516 result.description += sanitizeString(child.nodeValue, shouldTrim);
514 continue; 517 continue;
515 } 518 }
516 519
517 // Process and descend into a subset of recognized tags. 520 // Process and descend into a subset of recognized tags.
518 if (child.nodeType == Node.ELEMENT_NODE && 521 if (child.nodeType == Node.ELEMENT_NODE &&
519 (child.nodeName == 'dim' || child.nodeName == 'match' || 522 (child.nodeName == 'dim' || child.nodeName == 'match' ||
520 child.nodeName == 'url')) { 523 child.nodeName == 'url')) {
521 var style = { 524 var style = {
522 'type': child.nodeName, 525 'type': child.nodeName,
523 'offset': result.description.length 526 'offset': result.description.length
(...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after
1108 1111
1109 if (!chrome.tts) 1112 if (!chrome.tts)
1110 chrome.tts = {}; 1113 chrome.tts = {};
1111 1114
1112 if (!chrome.ttsEngine) 1115 if (!chrome.ttsEngine)
1113 chrome.ttsEngine = {}; 1116 chrome.ttsEngine = {};
1114 1117
1115 if (!chrome.experimental.downloads) 1118 if (!chrome.experimental.downloads)
1116 chrome.experimental.downloads = {}; 1119 chrome.experimental.downloads = {};
1117 })(); 1120 })();
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698