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(); |
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 -> |
samarth
2013/04/05 22:30:25
Add a TODO here to delete the shadow DOM stuff.
Jered
2013/04/06 02:45:16
Shishir has that TODO above.
| |
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> – </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> – </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 Loading... | |
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 by | |
240 // checking the invoking context's origin in searchbox_extension.cc. | |
241 this.getSuggestionData = function(restrictedId) { | |
242 return GetSuggestionData(restrictedId); | |
243 }; | |
244 this.setSuggestions = function(text) { | 244 this.setSuggestions = function(text) { |
245 SetSuggestions(text); | 245 SetSuggestions(text); |
246 }; | 246 }; |
247 this.setAutocompleteText = function(text, behavior) { | 247 this.setAutocompleteText = function(text, behavior) { |
248 SetSuggestion(text, behavior); | 248 SetSuggestion(text, behavior); |
249 }; | 249 }; |
250 this.setRestrictedAutocompleteText = function(autocompleteResultId) { | 250 this.setRestrictedAutocompleteText = function(autocompleteResultId) { |
251 SetSuggestionFromAutocompleteResult(autocompleteResultId); | 251 SetSuggestionFromAutocompleteResult(autocompleteResultId); |
252 }; | 252 }; |
253 this.setValue = function(text, type) { | 253 this.setValue = function(text, type) { |
(...skipping 11 matching lines...) Expand all Loading... | |
265 }; | 265 }; |
266 this.focus = function() { | 266 this.focus = function() { |
267 FocusOmnibox(); | 267 FocusOmnibox(); |
268 }; | 268 }; |
269 this.startCapturingKeyStrokes = function() { | 269 this.startCapturingKeyStrokes = function() { |
270 StartCapturingKeyStrokes(); | 270 StartCapturingKeyStrokes(); |
271 }; | 271 }; |
272 this.stopCapturingKeyStrokes = function() { | 272 this.stopCapturingKeyStrokes = function() { |
273 StopCapturingKeyStrokes(); | 273 StopCapturingKeyStrokes(); |
274 }; | 274 }; |
275 this.setSuggestionStyle = function(url_color, title_color) { | |
276 SetSuggestionStyle(url_color, title_color); | |
277 }; | |
278 this.navigateContentWindow = function(destination, disposition) { | 275 this.navigateContentWindow = function(destination, disposition) { |
279 NavigateSearchBox(destination, disposition); | 276 NavigateSearchBox(destination, disposition); |
280 } | 277 } |
281 this.showBars = function() { | 278 this.showBars = function() { |
282 ShowBars(); | 279 ShowBars(); |
283 }; | 280 }; |
284 this.hideBars = function() { | 281 this.hideBars = function() { |
285 HideBars(); | 282 HideBars(); |
286 }; | 283 }; |
287 this.onchange = null; | 284 this.onchange = null; |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
357 | 354 |
358 this.onmostvisitedchange = null; | 355 this.onmostvisitedchange = null; |
359 this.onthemechange = null; | 356 this.onthemechange = null; |
360 }; | 357 }; |
361 | 358 |
362 // Export legacy searchbox API. | 359 // Export legacy searchbox API. |
363 // TODO: Remove this when Instant Extended is fully launched. | 360 // TODO: Remove this when Instant Extended is fully launched. |
364 chrome.searchBox = this.searchBox; | 361 chrome.searchBox = this.searchBox; |
365 }; | 362 }; |
366 } | 363 } |
OLD | NEW |