| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 cr.define('options', function() { | 5 cr.define('options', function() { |
| 6 /** @const */ var Page = cr.ui.pageManager.Page; | 6 /** @const */ var Page = cr.ui.pageManager.Page; |
| 7 /** @const */ var PageManager = cr.ui.pageManager.PageManager; | 7 /** @const */ var PageManager = cr.ui.pageManager.PageManager; |
| 8 | 8 |
| 9 /** | 9 /** |
| 10 * Encapsulated handling of a search bubble. | 10 * Encapsulated handling of a search bubble. |
| 11 * @constructor | 11 * @constructor |
| 12 */ | 12 */ |
| 13 function SearchBubble(text) { | 13 function SearchBubble(text) { |
| 14 var el = cr.doc.createElement('div'); | 14 var el = cr.doc.createElement('div'); |
| 15 SearchBubble.decorate(el); | 15 SearchBubble.decorate(el); |
| 16 el.content = text; | 16 el.content = text; |
| 17 return el; | 17 return el; |
| 18 } | 18 } |
| 19 | 19 |
| 20 /** |
| 21 * Prohibit search for guests on desktop. |
| 22 */ |
| 23 function ShouldEnableSearch() { |
| 24 return !loadTimeData.getBoolean('profileIsGuest') || cr.isChromeOS; |
| 25 } |
| 26 |
| 20 SearchBubble.decorate = function(el) { | 27 SearchBubble.decorate = function(el) { |
| 21 el.__proto__ = SearchBubble.prototype; | 28 el.__proto__ = SearchBubble.prototype; |
| 22 el.decorate(); | 29 el.decorate(); |
| 23 }; | 30 }; |
| 24 | 31 |
| 25 SearchBubble.prototype = { | 32 SearchBubble.prototype = { |
| 26 __proto__: HTMLDivElement.prototype, | 33 __proto__: HTMLDivElement.prototype, |
| 27 | 34 |
| 28 decorate: function() { | 35 decorate: function() { |
| 29 this.className = 'search-bubble'; | 36 this.className = 'search-bubble'; |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 * Update the UI to reflect whether we are in a search state. | 187 * Update the UI to reflect whether we are in a search state. |
| 181 * @param {boolean} active True if we are on the search page. | 188 * @param {boolean} active True if we are on the search page. |
| 182 * @private | 189 * @private |
| 183 */ | 190 */ |
| 184 setSearchActive_: function(active) { | 191 setSearchActive_: function(active) { |
| 185 // It's fine to exit if search wasn't active and we're not going to | 192 // It's fine to exit if search wasn't active and we're not going to |
| 186 // activate it now. | 193 // activate it now. |
| 187 if (!this.searchActive_ && !active) | 194 if (!this.searchActive_ && !active) |
| 188 return; | 195 return; |
| 189 | 196 |
| 190 // Guest users should never have active search. | 197 if (!ShouldEnableSearch()) |
| 191 if (loadTimeData.getBoolean('profileIsGuest')) | |
| 192 return; | 198 return; |
| 193 | 199 |
| 194 this.searchActive_ = active; | 200 this.searchActive_ = active; |
| 195 | 201 |
| 196 if (active) { | 202 if (active) { |
| 197 var hash = location.hash; | 203 var hash = location.hash; |
| 198 if (hash) { | 204 if (hash) { |
| 199 this.searchField.value = | 205 this.searchField.value = |
| 200 decodeURIComponent(hash.slice(1).replace(/\+/g, ' ')); | 206 decodeURIComponent(hash.slice(1).replace(/\+/g, ' ')); |
| 201 } else if (!this.searchField.value) { | 207 } else if (!this.searchField.value) { |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 } | 263 } |
| 258 } | 264 } |
| 259 }, | 265 }, |
| 260 | 266 |
| 261 /** | 267 /** |
| 262 * Set the current search criteria. | 268 * Set the current search criteria. |
| 263 * @param {string} text Search text. | 269 * @param {string} text Search text. |
| 264 * @private | 270 * @private |
| 265 */ | 271 */ |
| 266 setSearchText_: function(text) { | 272 setSearchText_: function(text) { |
| 267 // Guest users should never have search text. | 273 if (!ShouldEnableSearch()) |
| 268 if (loadTimeData.getBoolean('profileIsGuest')) | |
| 269 return; | 274 return; |
| 270 | 275 |
| 271 // Prevent recursive execution of this method. | 276 // Prevent recursive execution of this method. |
| 272 if (this.insideSetSearchText_) return; | 277 if (this.insideSetSearchText_) return; |
| 273 this.insideSetSearchText_ = true; | 278 this.insideSetSearchText_ = true; |
| 274 | 279 |
| 275 // Cleanup the search query string. | 280 // Cleanup the search query string. |
| 276 text = SearchPage.canonicalizeQuery(text); | 281 text = SearchPage.canonicalizeQuery(text); |
| 277 | 282 |
| 278 // Set the hash on the current page, and the enclosing uber page. Only do | 283 // Set the hash on the current page, and the enclosing uber page. Only do |
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 576 // Trim beginning and ending whitespace. | 581 // Trim beginning and ending whitespace. |
| 577 return text.replace(/^\s+|\s+$/g, ''); | 582 return text.replace(/^\s+|\s+$/g, ''); |
| 578 }; | 583 }; |
| 579 | 584 |
| 580 // Export | 585 // Export |
| 581 return { | 586 return { |
| 582 SearchPage: SearchPage | 587 SearchPage: SearchPage |
| 583 }; | 588 }; |
| 584 | 589 |
| 585 }); | 590 }); |
| OLD | NEW |