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

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: virtual 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 } 143 }
151 return autocompleteResults; 144 return autocompleteResults;
152 } 145 }
153 146
154 // TODO(dcblack): Do this in C++ instead of JS. 147 // TODO(dcblack): Do this in C++ instead of JS.
155 function CanonicalizeUrl(url) { 148 function CanonicalizeUrl(url) {
156 return url.replace(HTTP_REGEX, '').replace(WWW_REGEX, ''); 149 return url.replace(HTTP_REGEX, '').replace(WWW_REGEX, '');
157 } 150 }
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 this.__defineGetter__('selectionStart', GetSelectionStart); 226 this.__defineGetter__('selectionStart', GetSelectionStart);
234 this.__defineGetter__('selectionEnd', GetSelectionEnd); 227 this.__defineGetter__('selectionEnd', GetSelectionEnd);
235 this.__defineGetter__('startMargin', GetStartMargin); 228 this.__defineGetter__('startMargin', GetStartMargin);
236 this.__defineGetter__('rtl', GetRightToLeft); 229 this.__defineGetter__('rtl', GetRightToLeft);
237 this.__defineGetter__('nativeSuggestions', GetAutocompleteResultsWrapper); 230 this.__defineGetter__('nativeSuggestions', GetAutocompleteResultsWrapper);
238 this.__defineGetter__('isKeyCaptureEnabled', IsKeyCaptureEnabled); 231 this.__defineGetter__('isKeyCaptureEnabled', IsKeyCaptureEnabled);
239 this.__defineGetter__('displayInstantResults', GetDisplayInstantResults); 232 this.__defineGetter__('displayInstantResults', GetDisplayInstantResults);
240 this.__defineGetter__('font', GetFont); 233 this.__defineGetter__('font', GetFont);
241 this.__defineGetter__('fontSize', GetFontSize); 234 this.__defineGetter__('fontSize', GetFontSize);
242 235
236 // This method is restricted to chrome-search://suggestion pages by
237 // checking the invoking context's origin in searchbox_extension.cc.
238 this.getSuggestionData = function(restrictedId) {
239 return GetSuggestionData(restrictedId);
240 };
241
243 this.setSuggestions = function(text) { 242 this.setSuggestions = function(text) {
244 SetSuggestions(text); 243 SetSuggestions(text);
245 }; 244 };
246 this.setAutocompleteText = function(text, behavior) { 245 this.setAutocompleteText = function(text, behavior) {
247 SetSuggestion(text, behavior); 246 SetSuggestion(text, behavior);
248 }; 247 };
249 this.setRestrictedAutocompleteText = function(autocompleteResultId) { 248 this.setRestrictedAutocompleteText = function(autocompleteResultId) {
250 SetSuggestionFromAutocompleteResult(autocompleteResultId); 249 SetSuggestionFromAutocompleteResult(autocompleteResultId);
251 }; 250 };
252 this.setValue = function(text, type) { 251 this.setValue = function(text, type) {
(...skipping 11 matching lines...) Expand all
264 }; 263 };
265 this.focus = function() { 264 this.focus = function() {
266 FocusOmnibox(); 265 FocusOmnibox();
267 }; 266 };
268 this.startCapturingKeyStrokes = function() { 267 this.startCapturingKeyStrokes = function() {
269 StartCapturingKeyStrokes(); 268 StartCapturingKeyStrokes();
270 }; 269 };
271 this.stopCapturingKeyStrokes = function() { 270 this.stopCapturingKeyStrokes = function() {
272 StopCapturingKeyStrokes(); 271 StopCapturingKeyStrokes();
273 }; 272 };
274 this.setSuggestionStyle = function(url_color, title_color) {
275 SetSuggestionStyle(url_color, title_color);
276 };
277 this.navigateContentWindow = function(destination, disposition) { 273 this.navigateContentWindow = function(destination, disposition) {
278 NavigateSearchBox(destination, disposition); 274 NavigateSearchBox(destination, disposition);
279 } 275 }
280 this.showBars = function() { 276 this.showBars = function() {
281 ShowBars(); 277 ShowBars();
282 }; 278 };
283 this.hideBars = function() { 279 this.hideBars = function() {
284 HideBars(); 280 HideBars();
285 }; 281 };
286 this.onchange = null; 282 this.onchange = null;
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 352
357 this.onmostvisitedchange = null; 353 this.onmostvisitedchange = null;
358 this.onthemechange = null; 354 this.onthemechange = null;
359 }; 355 };
360 356
361 // Export legacy searchbox API. 357 // Export legacy searchbox API.
362 // TODO: Remove this when Instant Extended is fully launched. 358 // TODO: Remove this when Instant Extended is fully launched.
363 chrome.searchBox = this.searchBox; 359 chrome.searchBox = this.searchBox;
364 }; 360 };
365 } 361 }
OLDNEW
« no previous file with comments | « chrome/renderer/chrome_content_renderer_client.cc ('k') | chrome/renderer/resources/omnibox_result.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698