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

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

Issue 13375003: Fixing iframe jank in the local omnibox popup. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressing cc comments. Created 7 years, 8 months 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
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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 var chrome; 5 var chrome;
6 if (!chrome) 6 if (!chrome)
7 chrome = {}; 7 chrome = {};
8 8
9 if (!chrome.embeddedSearch) { 9 if (!chrome.embeddedSearch) {
10 chrome.embeddedSearch = new function() { 10 chrome.embeddedSearch = new function() {
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 // ======================================================================= 87 // =======================================================================
88 native function GetQuery(); 88 native function GetQuery();
89 native function GetVerbatim(); 89 native function GetVerbatim();
90 native function GetSelectionStart(); 90 native function GetSelectionStart();
91 native function GetSelectionEnd(); 91 native function GetSelectionEnd();
92 native function GetStartMargin(); 92 native function GetStartMargin();
93 native function GetRightToLeft(); 93 native function GetRightToLeft();
94 native function GetAutocompleteResults(); 94 native function GetAutocompleteResults();
95 native function GetDisplayInstantResults(); 95 native function GetDisplayInstantResults();
96 native function GetFontSize(); 96 native function GetFontSize();
97 native function GetSuggestionIframeURLPrefix();
98 native function IsKeyCaptureEnabled(); 97 native function IsKeyCaptureEnabled();
99 native function SetQuery(); 98 native function SetQuery();
100 native function SetQueryFromAutocompleteResult(); 99 native function SetQueryFromAutocompleteResult();
101 native function SetSuggestion(); 100 native function SetSuggestion();
102 native function SetSuggestionFromAutocompleteResult(); 101 native function SetSuggestionFromAutocompleteResult();
103 native function SetSuggestions(); 102 native function SetSuggestions();
104 native function ShowOverlay(); 103 native function ShowOverlay();
105 native function FocusOmnibox(); 104 native function FocusOmnibox();
106 native function StartCapturingKeyStrokes(); 105 native function StartCapturingKeyStrokes();
107 native function StopCapturingKeyStrokes(); 106 native function StopCapturingKeyStrokes();
108 native function SetSuggestionStyle();
109 native function NavigateSearchBox(); 107 native function NavigateSearchBox();
110 native function ShowBars(); 108 native function ShowBars();
111 native function HideBars(); 109 native function HideBars();
112 native function ShouldUseIframes(); 110 native function GetSuggestionData();
113 111
114 function SafeWrapSuggestion(restrictedText) { 112 function SafeWrapSuggestion(restrictedText) {
115 return SafeWrap(restrictedText, 22); 113 return SafeWrap(restrictedText, 22);
116 } 114 }
117 115
118 // If shadowDom is to be used, wraps the AutocompleteResult query and URL 116 // If shadowDom is to be used, wraps the AutocompleteResult query and URL
119 // into ShadowDOM nodes so that the JS cannot access them and deletes the 117 // into ShadowDOM nodes so that the JS cannot access them and deletes the
120 // raw values. Else if iframes are to be used, replaces the 118 // raw values. Else if iframes are to be used, replaces the
121 // destination_url with the chrome search URL that should be used as the 119 // destination_url with the chrome search URL that should be used as the
122 // iframe. 120 // iframe.
123 // TODO(shishir): Remove code to support ShadowDOM once server side 121 // TODO(shishir): Remove code to support ShadowDOM once server side
124 // changes are live. 122 // changes are live.
125 function GetAutocompleteResultsWrapper() { 123 function GetAutocompleteResultsWrapper() {
126 var autocompleteResults = DedupeAutocompleteResults( 124 var autocompleteResults = DedupeAutocompleteResults(
127 GetAutocompleteResults()); 125 GetAutocompleteResults());
128 var userInput = GetQuery(); 126 var userInput = GetQuery();
129 for (var i = 0, result; result = autocompleteResults[i]; ++i) { 127 for (var i = 0, result; result = autocompleteResults[i]; ++i) {
130 if (ShouldUseIframes()) { 128 // TODO(shishir): Fix the naming violations (chrome_search ->
131 result.destination_url = GetSuggestionIframeURLPrefix() + 129 // chrome-search etc) when the server supports both names.
132 result.rid; 130 var className = result.is_search ? 'chrome_search' : 'chrome_url';
133 } else { 131 var combinedElement = '<span class=' + className + '>' +
134 // TODO(shishir): Fix the naming violations (chrome_search -> 132 escapeHTML(result.contents) + '</span>';
135 // chrome-search etc) when the server supports both names. 133 if (result.description) {
136 var className = result.is_search ? 'chrome_search' : 'chrome_url'; 134 combinedElement +=
137 var combinedElement = '<span class=' + className + '>' + 135 '<span class=chrome_separator> &ndash; </span>' +
138 escapeHTML(result.contents) + '</span>'; 136 '<span class=chrome_title>' +
139 if (result.description) { 137 escapeHTML(result.description) + '</span>';
140 combinedElement +=
141 '<span class=chrome_separator> &ndash; </span>' +
142 '<span class=chrome_title>' +
143 escapeHTML(result.description) + '</span>';
144 }
145 result.combinedNode = SafeWrapSuggestion(combinedElement);
146 result.destination_url = null;
147 } 138 }
139 result.combinedNode = SafeWrapSuggestion(combinedElement);
140 result.destination_url = null;
148 result.contents = null; 141 result.contents = null;
149 result.description = null; 142 result.description = null;
150 result.is_search = null; 143 // result.is_search is not hidden since it is needed to control
144 // content surrounding a suggestion, e.g. selecting between a
145 // magnifying glass and a page icon.
151 } 146 }
152 return autocompleteResults; 147 return autocompleteResults;
153 } 148 }
154 149
155 // TODO(dcblack): Do this in C++ instead of JS. 150 // TODO(dcblack): Do this in C++ instead of JS.
156 function CanonicalizeUrl(url) { 151 function CanonicalizeUrl(url) {
157 return url.replace(HTTP_REGEX, '').replace(WWW_REGEX, ''); 152 return url.replace(HTTP_REGEX, '').replace(WWW_REGEX, '');
158 } 153 }
159 154
160 // Removes duplicates from AutocompleteResults. 155 // Removes duplicates from AutocompleteResults.
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 this.__defineGetter__('selectionStart', GetSelectionStart); 229 this.__defineGetter__('selectionStart', GetSelectionStart);
235 this.__defineGetter__('selectionEnd', GetSelectionEnd); 230 this.__defineGetter__('selectionEnd', GetSelectionEnd);
236 this.__defineGetter__('startMargin', GetStartMargin); 231 this.__defineGetter__('startMargin', GetStartMargin);
237 this.__defineGetter__('rtl', GetRightToLeft); 232 this.__defineGetter__('rtl', GetRightToLeft);
238 this.__defineGetter__('nativeSuggestions', GetAutocompleteResultsWrapper); 233 this.__defineGetter__('nativeSuggestions', GetAutocompleteResultsWrapper);
239 this.__defineGetter__('isKeyCaptureEnabled', IsKeyCaptureEnabled); 234 this.__defineGetter__('isKeyCaptureEnabled', IsKeyCaptureEnabled);
240 this.__defineGetter__('displayInstantResults', GetDisplayInstantResults); 235 this.__defineGetter__('displayInstantResults', GetDisplayInstantResults);
241 this.__defineGetter__('font', GetFont); 236 this.__defineGetter__('font', GetFont);
242 this.__defineGetter__('fontSize', GetFontSize); 237 this.__defineGetter__('fontSize', GetFontSize);
243 238
239 // This method is restricted to chrome-search://suggestion pages.
palmer 2013/04/05 01:30:32 What enforces that restriction?
Jered 2013/04/05 15:30:23 I elaborated on the comment.
240 this.getSuggestionData = function(restrictedId) {
241 return GetSuggestionData(restrictedId);
242 };
244 this.setSuggestions = function(text) { 243 this.setSuggestions = function(text) {
245 SetSuggestions(text); 244 SetSuggestions(text);
246 }; 245 };
247 this.setAutocompleteText = function(text, behavior) { 246 this.setAutocompleteText = function(text, behavior) {
248 SetSuggestion(text, behavior); 247 SetSuggestion(text, behavior);
249 }; 248 };
250 this.setRestrictedAutocompleteText = function(autocompleteResultId) { 249 this.setRestrictedAutocompleteText = function(autocompleteResultId) {
251 SetSuggestionFromAutocompleteResult(autocompleteResultId); 250 SetSuggestionFromAutocompleteResult(autocompleteResultId);
252 }; 251 };
253 this.setValue = function(text, type) { 252 this.setValue = function(text, type) {
(...skipping 11 matching lines...) Expand all
265 }; 264 };
266 this.focus = function() { 265 this.focus = function() {
267 FocusOmnibox(); 266 FocusOmnibox();
268 }; 267 };
269 this.startCapturingKeyStrokes = function() { 268 this.startCapturingKeyStrokes = function() {
270 StartCapturingKeyStrokes(); 269 StartCapturingKeyStrokes();
271 }; 270 };
272 this.stopCapturingKeyStrokes = function() { 271 this.stopCapturingKeyStrokes = function() {
273 StopCapturingKeyStrokes(); 272 StopCapturingKeyStrokes();
274 }; 273 };
275 this.setSuggestionStyle = function(url_color, title_color) {
276 SetSuggestionStyle(url_color, title_color);
277 };
278 this.navigateContentWindow = function(destination, disposition) { 274 this.navigateContentWindow = function(destination, disposition) {
279 NavigateSearchBox(destination, disposition); 275 NavigateSearchBox(destination, disposition);
280 } 276 }
281 this.showBars = function() { 277 this.showBars = function() {
282 ShowBars(); 278 ShowBars();
283 }; 279 };
284 this.hideBars = function() { 280 this.hideBars = function() {
285 HideBars(); 281 HideBars();
286 }; 282 };
287 this.onchange = null; 283 this.onchange = null;
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 353
358 this.onmostvisitedchange = null; 354 this.onmostvisitedchange = null;
359 this.onthemechange = null; 355 this.onthemechange = null;
360 }; 356 };
361 357
362 // Export legacy searchbox API. 358 // Export legacy searchbox API.
363 // TODO: Remove this when Instant Extended is fully launched. 359 // TODO: Remove this when Instant Extended is fully launched.
364 chrome.searchBox = this.searchBox; 360 chrome.searchBox = this.searchBox;
365 }; 361 };
366 } 362 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698