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

Side by Side Diff: chrome/browser/resources/options/search_page.js

Issue 545953002: Let guests on ChromeOS still search. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Refactor to a helper method Created 6 years, 3 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 * Guests on Desktop cannot search. Permitted otherwise.
22 */
23 function ShouldEnableSearch() {
24 if (loadTimeData.getBoolean('profileIsGuest') && !cr.isChromeOS)
Evan Stade 2014/09/05 21:02:33 return (expression);
Mike Lerman 2014/09/08 13:51:14 Done.
25 return false;
26 return true;
27 }
28
20 SearchBubble.decorate = function(el) { 29 SearchBubble.decorate = function(el) {
21 el.__proto__ = SearchBubble.prototype; 30 el.__proto__ = SearchBubble.prototype;
22 el.decorate(); 31 el.decorate();
23 }; 32 };
24 33
25 SearchBubble.prototype = { 34 SearchBubble.prototype = {
26 __proto__: HTMLDivElement.prototype, 35 __proto__: HTMLDivElement.prototype,
27 36
28 decorate: function() { 37 decorate: function() {
29 this.className = 'search-bubble'; 38 this.className = 'search-bubble';
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 * Update the UI to reflect whether we are in a search state. 189 * Update the UI to reflect whether we are in a search state.
181 * @param {boolean} active True if we are on the search page. 190 * @param {boolean} active True if we are on the search page.
182 * @private 191 * @private
183 */ 192 */
184 setSearchActive_: function(active) { 193 setSearchActive_: function(active) {
185 // It's fine to exit if search wasn't active and we're not going to 194 // It's fine to exit if search wasn't active and we're not going to
186 // activate it now. 195 // activate it now.
187 if (!this.searchActive_ && !active) 196 if (!this.searchActive_ && !active)
188 return; 197 return;
189 198
190 // Guest users should never have active search. 199 if (!ShouldEnableSearch())
191 if (loadTimeData.getBoolean('profileIsGuest'))
192 return; 200 return;
193 201
194 this.searchActive_ = active; 202 this.searchActive_ = active;
195 203
196 if (active) { 204 if (active) {
197 var hash = location.hash; 205 var hash = location.hash;
198 if (hash) { 206 if (hash) {
199 this.searchField.value = 207 this.searchField.value =
200 decodeURIComponent(hash.slice(1).replace(/\+/g, ' ')); 208 decodeURIComponent(hash.slice(1).replace(/\+/g, ' '));
201 } else if (!this.searchField.value) { 209 } else if (!this.searchField.value) {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 } 265 }
258 } 266 }
259 }, 267 },
260 268
261 /** 269 /**
262 * Set the current search criteria. 270 * Set the current search criteria.
263 * @param {string} text Search text. 271 * @param {string} text Search text.
264 * @private 272 * @private
265 */ 273 */
266 setSearchText_: function(text) { 274 setSearchText_: function(text) {
267 // Guest users should never have search text. 275 if (!ShouldEnableSearch())
268 if (loadTimeData.getBoolean('profileIsGuest'))
269 return; 276 return;
270 277
271 // Prevent recursive execution of this method. 278 // Prevent recursive execution of this method.
272 if (this.insideSetSearchText_) return; 279 if (this.insideSetSearchText_) return;
273 this.insideSetSearchText_ = true; 280 this.insideSetSearchText_ = true;
274 281
275 // Cleanup the search query string. 282 // Cleanup the search query string.
276 text = SearchPage.canonicalizeQuery(text); 283 text = SearchPage.canonicalizeQuery(text);
277 284
278 // Set the hash on the current page, and the enclosing uber page. Only do 285 // 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
576 // Trim beginning and ending whitespace. 583 // Trim beginning and ending whitespace.
577 return text.replace(/^\s+|\s+$/g, ''); 584 return text.replace(/^\s+|\s+$/g, '');
578 }; 585 };
579 586
580 // Export 587 // Export
581 return { 588 return {
582 SearchPage: SearchPage 589 SearchPage: SearchPage
583 }; 590 };
584 591
585 }); 592 });
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698