OLD | NEW |
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 Loading... |
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(); |
| 110 native function GetSuggestionData(); |
112 | 111 |
113 function SafeWrapSuggestion(restrictedText) { | 112 function SafeWrapSuggestion(restrictedText) { |
114 return SafeWrap(restrictedText, 22); | 113 return SafeWrap(restrictedText, 22); |
115 } | 114 } |
116 | 115 |
117 // Wraps the AutocompleteResult query and URL into ShadowDOM nodes so that | 116 // Wraps the AutocompleteResult query and URL into ShadowDOM nodes so that |
118 // the JS cannot access them and deletes the raw values. Also replaces the | 117 // the JS cannot access them and deletes the raw values. Also replaces the |
119 // destination_url with the chrome search URL that should be used as the | 118 // destination_url with the chrome search URL that should be used as the |
120 // iframe. | 119 // iframe. |
121 // TODO(shishir): Remove code to support ShadowDOM once server side | 120 // TODO(shishir): Remove code to support ShadowDOM once server side |
122 // changes are live. | 121 // changes are live. |
123 function GetAutocompleteResultsWrapper() { | 122 function GetAutocompleteResultsWrapper() { |
124 var autocompleteResults = DedupeAutocompleteResults( | 123 var autocompleteResults = DedupeAutocompleteResults( |
125 GetAutocompleteResults()); | 124 GetAutocompleteResults()); |
126 var userInput = GetQuery(); | 125 var userInput = GetQuery(); |
127 for (var i = 0, result; result = autocompleteResults[i]; ++i) { | 126 for (var i = 0, result; result = autocompleteResults[i]; ++i) { |
128 var className = result.is_search ? 'chrome_search' : 'chrome_url'; | 127 var className = result.is_search ? 'chrome_search' : 'chrome_url'; |
129 var combinedElement = '<span class=' + className + '>' + | 128 var combinedElement = '<span class=' + className + '>' + |
130 escapeHTML(result.contents) + '</span>'; | 129 escapeHTML(result.contents) + '</span>'; |
131 if (result.description) { | 130 if (result.description) { |
132 combinedElement += '<span class=chrome_separator> – </span>' + | 131 combinedElement += '<span class=chrome_separator> – </span>' + |
133 '<span class=chrome_title>' + | 132 '<span class=chrome_title>' + |
134 escapeHTML(result.description) + '</span>'; | 133 escapeHTML(result.description) + '</span>'; |
135 } | 134 } |
136 result.combinedNode = SafeWrapSuggestion(combinedElement); | 135 result.combinedNode = SafeWrapSuggestion(combinedElement); |
137 delete result.contents; | 136 delete result.contents; |
138 delete result.description; | 137 delete result.description; |
139 result.destination_url = GetSuggestionIframeURLPrefix() + result.rid; | 138 delete result.destination_url; |
140 } | 139 } |
141 return autocompleteResults; | 140 return autocompleteResults; |
142 } | 141 } |
143 | 142 |
144 // TODO(dcblack): Do this in C++ instead of JS. | 143 // TODO(dcblack): Do this in C++ instead of JS. |
145 function CanonicalizeUrl(url) { | 144 function CanonicalizeUrl(url) { |
146 return url.replace(HTTP_REGEX, '').replace(WWW_REGEX, ''); | 145 return url.replace(HTTP_REGEX, '').replace(WWW_REGEX, ''); |
147 } | 146 } |
148 | 147 |
149 // Removes duplicates from AutocompleteResults. | 148 // Removes duplicates from AutocompleteResults. |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 this.__defineGetter__('selectionStart', GetSelectionStart); | 222 this.__defineGetter__('selectionStart', GetSelectionStart); |
224 this.__defineGetter__('selectionEnd', GetSelectionEnd); | 223 this.__defineGetter__('selectionEnd', GetSelectionEnd); |
225 this.__defineGetter__('startMargin', GetStartMargin); | 224 this.__defineGetter__('startMargin', GetStartMargin); |
226 this.__defineGetter__('rtl', GetRightToLeft); | 225 this.__defineGetter__('rtl', GetRightToLeft); |
227 this.__defineGetter__('nativeSuggestions', GetAutocompleteResultsWrapper); | 226 this.__defineGetter__('nativeSuggestions', GetAutocompleteResultsWrapper); |
228 this.__defineGetter__('isKeyCaptureEnabled', IsKeyCaptureEnabled); | 227 this.__defineGetter__('isKeyCaptureEnabled', IsKeyCaptureEnabled); |
229 this.__defineGetter__('displayInstantResults', GetDisplayInstantResults); | 228 this.__defineGetter__('displayInstantResults', GetDisplayInstantResults); |
230 this.__defineGetter__('font', GetFont); | 229 this.__defineGetter__('font', GetFont); |
231 this.__defineGetter__('fontSize', GetFontSize); | 230 this.__defineGetter__('fontSize', GetFontSize); |
232 | 231 |
| 232 // This method is restricted to chrome-search://suggestion pages. |
| 233 this.getSuggestionData = function(restrictedId) { |
| 234 return GetSuggestionData(restrictedId); |
| 235 }; |
233 this.setSuggestions = function(text) { | 236 this.setSuggestions = function(text) { |
234 SetSuggestions(text); | 237 SetSuggestions(text); |
235 }; | 238 }; |
236 this.setAutocompleteText = function(text, behavior) { | 239 this.setAutocompleteText = function(text, behavior) { |
237 SetSuggestion(text, behavior); | 240 SetSuggestion(text, behavior); |
238 }; | 241 }; |
239 this.setRestrictedAutocompleteText = function(autocompleteResultId) { | 242 this.setRestrictedAutocompleteText = function(autocompleteResultId) { |
240 SetSuggestionFromAutocompleteResult(autocompleteResultId); | 243 SetSuggestionFromAutocompleteResult(autocompleteResultId); |
241 }; | 244 }; |
242 this.setValue = function(text, type) { | 245 this.setValue = function(text, type) { |
(...skipping 11 matching lines...) Expand all Loading... |
254 }; | 257 }; |
255 this.focus = function() { | 258 this.focus = function() { |
256 FocusOmnibox(); | 259 FocusOmnibox(); |
257 }; | 260 }; |
258 this.startCapturingKeyStrokes = function() { | 261 this.startCapturingKeyStrokes = function() { |
259 StartCapturingKeyStrokes(); | 262 StartCapturingKeyStrokes(); |
260 }; | 263 }; |
261 this.stopCapturingKeyStrokes = function() { | 264 this.stopCapturingKeyStrokes = function() { |
262 StopCapturingKeyStrokes(); | 265 StopCapturingKeyStrokes(); |
263 }; | 266 }; |
264 this.setSuggestionStyle = function(url_color, title_color) { | |
265 SetSuggestionStyle(url_color, title_color); | |
266 }; | |
267 this.navigateContentWindow = function(destination, disposition) { | 267 this.navigateContentWindow = function(destination, disposition) { |
268 NavigateSearchBox(destination, disposition); | 268 NavigateSearchBox(destination, disposition); |
269 } | 269 } |
270 this.showBars = function() { | 270 this.showBars = function() { |
271 ShowBars(); | 271 ShowBars(); |
272 }; | 272 }; |
273 this.hideBars = function() { | 273 this.hideBars = function() { |
274 HideBars(); | 274 HideBars(); |
275 }; | 275 }; |
276 this.onchange = null; | 276 this.onchange = null; |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 | 346 |
347 this.onmostvisitedchange = null; | 347 this.onmostvisitedchange = null; |
348 this.onthemechange = null; | 348 this.onthemechange = null; |
349 }; | 349 }; |
350 | 350 |
351 // Export legacy searchbox API. | 351 // Export legacy searchbox API. |
352 // TODO: Remove this when Instant Extended is fully launched. | 352 // TODO: Remove this when Instant Extended is fully launched. |
353 chrome.searchBox = this.searchBox; | 353 chrome.searchBox = this.searchBox; |
354 }; | 354 }; |
355 } | 355 } |
OLD | NEW |