| 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 -> |
| 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 } | 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 Loading... |
| 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 }; |
| 243 this.setSuggestions = function(text) { | 241 this.setSuggestions = function(text) { |
| 244 SetSuggestions(text); | 242 SetSuggestions(text); |
| 245 }; | 243 }; |
| 246 this.setAutocompleteText = function(text, behavior) { | 244 this.setAutocompleteText = function(text, behavior) { |
| 247 SetSuggestion(text, behavior); | 245 SetSuggestion(text, behavior); |
| 248 }; | 246 }; |
| 249 this.setRestrictedAutocompleteText = function(autocompleteResultId) { | 247 this.setRestrictedAutocompleteText = function(autocompleteResultId) { |
| 250 SetSuggestionFromAutocompleteResult(autocompleteResultId); | 248 SetSuggestionFromAutocompleteResult(autocompleteResultId); |
| 251 }; | 249 }; |
| 252 this.setValue = function(text, type) { | 250 this.setValue = function(text, type) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 264 }; | 262 }; |
| 265 this.focus = function() { | 263 this.focus = function() { |
| 266 FocusOmnibox(); | 264 FocusOmnibox(); |
| 267 }; | 265 }; |
| 268 this.startCapturingKeyStrokes = function() { | 266 this.startCapturingKeyStrokes = function() { |
| 269 StartCapturingKeyStrokes(); | 267 StartCapturingKeyStrokes(); |
| 270 }; | 268 }; |
| 271 this.stopCapturingKeyStrokes = function() { | 269 this.stopCapturingKeyStrokes = function() { |
| 272 StopCapturingKeyStrokes(); | 270 StopCapturingKeyStrokes(); |
| 273 }; | 271 }; |
| 274 this.setSuggestionStyle = function(url_color, title_color) { | |
| 275 SetSuggestionStyle(url_color, title_color); | |
| 276 }; | |
| 277 this.navigateContentWindow = function(destination, disposition) { | 272 this.navigateContentWindow = function(destination, disposition) { |
| 278 NavigateSearchBox(destination, disposition); | 273 NavigateSearchBox(destination, disposition); |
| 279 } | 274 } |
| 280 this.showBars = function() { | 275 this.showBars = function() { |
| 281 ShowBars(); | 276 ShowBars(); |
| 282 }; | 277 }; |
| 283 this.hideBars = function() { | 278 this.hideBars = function() { |
| 284 HideBars(); | 279 HideBars(); |
| 285 }; | 280 }; |
| 286 this.onchange = null; | 281 this.onchange = null; |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 | 351 |
| 357 this.onmostvisitedchange = null; | 352 this.onmostvisitedchange = null; |
| 358 this.onthemechange = null; | 353 this.onthemechange = null; |
| 359 }; | 354 }; |
| 360 | 355 |
| 361 // Export legacy searchbox API. | 356 // Export legacy searchbox API. |
| 362 // TODO: Remove this when Instant Extended is fully launched. | 357 // TODO: Remove this when Instant Extended is fully launched. |
| 363 chrome.searchBox = this.searchBox; | 358 chrome.searchBox = this.searchBox; |
| 364 }; | 359 }; |
| 365 } | 360 } |
| OLD | NEW |