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

Side by Side Diff: chrome/renderer/resources/extensions/searchbox_api.js

Issue 12771013: Instant: Make clicks on Most Visited items work. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Cancel Created 7 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/instant/instant_controller.cc ('k') | chrome/renderer/searchbox/searchbox.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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() {
11 11
12 // ========================================================================= 12 // =========================================================================
13 // Private functions 13 // Private functions
14 // ========================================================================= 14 // =========================================================================
15 native function GetFont(); 15 native function GetFont();
16 // DEPRECATED. TODO(sreeram): Remove once google.com no longer uses this.
16 native function NavigateContentWindow(); 17 native function NavigateContentWindow();
17 18
18 function escapeHTML(text) { 19 function escapeHTML(text) {
19 return text.replace(/[<>&"']/g, function(match) { 20 return text.replace(/[<>&"']/g, function(match) {
20 switch (match) { 21 switch (match) {
21 case '<': return '&lt;'; 22 case '<': return '&lt;';
22 case '>': return '&gt;'; 23 case '>': return '&gt;';
23 case '&': return '&amp;'; 24 case '&': return '&amp;';
24 case '"': return '&quot;'; 25 case '"': return '&quot;';
25 case "'": return '&apos;'; 26 case "'": return '&apos;';
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 // |embeddedSearchOnWindowReady| is used for initializing window context 58 // |embeddedSearchOnWindowReady| is used for initializing window context
58 // and should be called only once per context. 59 // and should be called only once per context.
59 safeObjects.createShadowRoot = Element.prototype.webkitCreateShadowRoot; 60 safeObjects.createShadowRoot = Element.prototype.webkitCreateShadowRoot;
60 safeObjects.defineProperty = Object.defineProperty; 61 safeObjects.defineProperty = Object.defineProperty;
61 delete window.chrome.embeddedSearchOnWindowReady; 62 delete window.chrome.embeddedSearchOnWindowReady;
62 }; 63 };
63 64
64 // ========================================================================= 65 // =========================================================================
65 // Exported functions 66 // Exported functions
66 // ========================================================================= 67 // =========================================================================
68 // DEPRECATED. TODO(sreeram): Remove once google.com no longer uses this.
67 this.navigateContentWindow = function(destination, disposition) { 69 this.navigateContentWindow = function(destination, disposition) {
68 return NavigateContentWindow(destination, disposition); 70 return NavigateContentWindow(destination, disposition);
69 }; 71 };
70 72
71 this.searchBox = new function() { 73 this.searchBox = new function() {
72 74
73 // ======================================================================= 75 // =======================================================================
74 // Constants 76 // Constants
75 // ======================================================================= 77 // =======================================================================
76 var MAX_CLIENT_SUGGESTIONS_TO_DEDUPE = 6; 78 var MAX_CLIENT_SUGGESTIONS_TO_DEDUPE = 6;
(...skipping 18 matching lines...) Expand all
95 native function IsKeyCaptureEnabled(); 97 native function IsKeyCaptureEnabled();
96 native function SetSuggestions(); 98 native function SetSuggestions();
97 native function SetQuerySuggestion(); 99 native function SetQuerySuggestion();
98 native function SetQuerySuggestionFromAutocompleteResult(); 100 native function SetQuerySuggestionFromAutocompleteResult();
99 native function SetQuery(); 101 native function SetQuery();
100 native function SetQueryFromAutocompleteResult(); 102 native function SetQueryFromAutocompleteResult();
101 native function ShowOverlay(); 103 native function ShowOverlay();
102 native function FocusOmnibox(); 104 native function FocusOmnibox();
103 native function StartCapturingKeyStrokes(); 105 native function StartCapturingKeyStrokes();
104 native function StopCapturingKeyStrokes(); 106 native function StopCapturingKeyStrokes();
107 native function NavigateSearchBox();
105 108
106 function SafeWrapSuggestion(restrictedText) { 109 function SafeWrapSuggestion(restrictedText) {
107 return SafeWrap(restrictedText, window.innerWidth - 155, 22); 110 return SafeWrap(restrictedText, window.innerWidth - 155, 22);
108 } 111 }
109 112
110 // Wraps the AutocompleteResult query and URL into ShadowDOM nodes so that 113 // Wraps the AutocompleteResult query and URL into ShadowDOM nodes so that
111 // the JS cannot access them and deletes the raw values. 114 // the JS cannot access them and deletes the raw values.
112 function GetAutocompleteResultsWrapper() { 115 function GetAutocompleteResultsWrapper() {
113 var autocompleteResults = DedupeAutocompleteResults( 116 var autocompleteResults = DedupeAutocompleteResults(
114 GetAutocompleteResults()); 117 GetAutocompleteResults());
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 this.__defineGetter__('displayInstantResults', GetDisplayInstantResults); 235 this.__defineGetter__('displayInstantResults', GetDisplayInstantResults);
233 this.__defineGetter__('font', GetFont); 236 this.__defineGetter__('font', GetFont);
234 this.__defineGetter__('fontSize', GetFontSize); 237 this.__defineGetter__('fontSize', GetFontSize);
235 238
236 this.setSuggestions = function(text) { 239 this.setSuggestions = function(text) {
237 SetSuggestions(text); 240 SetSuggestions(text);
238 }; 241 };
239 this.setAutocompleteText = function(text, behavior) { 242 this.setAutocompleteText = function(text, behavior) {
240 SetQuerySuggestion(text, behavior); 243 SetQuerySuggestion(text, behavior);
241 }; 244 };
242 this.setRestrictedAutocompleteText = function(resultId) { 245 this.setRestrictedAutocompleteText = function(autocompleteResultId) {
243 SetQuerySuggestionFromAutocompleteResult(resultId); 246 SetQuerySuggestionFromAutocompleteResult(autocompleteResultId);
244 }; 247 };
245 this.setValue = function(text, type) { 248 this.setValue = function(text, type) {
246 SetQuery(text, type); 249 SetQuery(text, type);
247 }; 250 };
248 this.setRestrictedValue = function(resultId) { 251 this.setRestrictedValue = function(autocompleteResultId) {
249 SetQueryFromAutocompleteResult(resultId); 252 SetQueryFromAutocompleteResult(autocompleteResultId);
250 }; 253 };
251 // TODO(jered): Remove the deprecated "reason" argument. 254 // TODO(jered): Remove the deprecated "reason" argument.
252 this.showOverlay = function(reason, height) { 255 this.showOverlay = function(reason, height) {
253 ShowOverlay(reason, height); 256 ShowOverlay(reason, height);
254 }; 257 };
255 // TODO(jered): Remove this when GWS knows about showOverlay(). 258 // TODO(jered): Remove this when GWS knows about showOverlay().
256 this.show = this.showOverlay; 259 this.show = this.showOverlay;
257 this.markDuplicateSuggestions = function(clientSuggestions) { 260 this.markDuplicateSuggestions = function(clientSuggestions) {
258 return DedupeClientSuggestions(clientSuggestions); 261 return DedupeClientSuggestions(clientSuggestions);
259 }; 262 };
260 this.focus = function() { 263 this.focus = function() {
261 FocusOmnibox(); 264 FocusOmnibox();
262 }; 265 };
263 this.startCapturingKeyStrokes = function() { 266 this.startCapturingKeyStrokes = function() {
264 StartCapturingKeyStrokes(); 267 StartCapturingKeyStrokes();
265 }; 268 };
266 this.stopCapturingKeyStrokes = function() { 269 this.stopCapturingKeyStrokes = function() {
267 StopCapturingKeyStrokes(); 270 StopCapturingKeyStrokes();
268 }; 271 };
272 this.navigateContentWindow = function(destination, disposition) {
273 NavigateSearchBox(destination, disposition);
274 }
269 this.onchange = null; 275 this.onchange = null;
270 this.onsubmit = null; 276 this.onsubmit = null;
271 this.oncancel = null; 277 this.oncancel = null;
272 this.onresize = null; 278 this.onresize = null;
273 this.onkeypress = null; 279 this.onkeypress = null;
274 this.onkeycapturechange = null; 280 this.onkeycapturechange = null;
275 this.oncontextchange = null; 281 this.oncontextchange = null;
276 this.onmarginchange = null; 282 this.onmarginchange = null;
277 this.onnativesuggestions = null; 283 this.onnativesuggestions = null;
278 284
(...skipping 12 matching lines...) Expand all
291 this.newTabPage = new function() { 297 this.newTabPage = new function() {
292 298
293 // ======================================================================= 299 // =======================================================================
294 // Private functions 300 // Private functions
295 // ======================================================================= 301 // =======================================================================
296 native function GetMostVisitedItems(); 302 native function GetMostVisitedItems();
297 native function GetThemeBackgroundInfo(); 303 native function GetThemeBackgroundInfo();
298 native function DeleteMostVisitedItem(); 304 native function DeleteMostVisitedItem();
299 native function UndoAllMostVisitedDeletions(); 305 native function UndoAllMostVisitedDeletions();
300 native function UndoMostVisitedDeletion(); 306 native function UndoMostVisitedDeletion();
307 native function NavigateNewTabPage();
301 308
302 function SafeWrapMostVisited(restrictedText, width, opt_direction) { 309 function SafeWrapMostVisited(restrictedText, width, opt_direction) {
303 return SafeWrap(restrictedText, width, 18, 11, opt_direction); 310 return SafeWrap(restrictedText, width, 18, 11, opt_direction);
304 } 311 }
305 312
306 function GetMostVisitedItemsWrapper() { 313 function GetMostVisitedItemsWrapper() {
307 var mostVisitedItems = GetMostVisitedItems(); 314 var mostVisitedItems = GetMostVisitedItems();
308 for (var i = 0, item; item = mostVisitedItems[i]; ++i) { 315 for (var i = 0, item; item = mostVisitedItems[i]; ++i) {
309 var title = escapeHTML(item.title); 316 var title = escapeHTML(item.title);
310 var domain = escapeHTML(item.domain); 317 var domain = escapeHTML(item.domain);
(...skipping 14 matching lines...) Expand all
325 332
326 this.deleteMostVisitedItem = function(restrictId) { 333 this.deleteMostVisitedItem = function(restrictId) {
327 DeleteMostVisitedItem(restrictId); 334 DeleteMostVisitedItem(restrictId);
328 }; 335 };
329 this.undoAllMostVisitedDeletions = function() { 336 this.undoAllMostVisitedDeletions = function() {
330 UndoAllMostVisitedDeletions(); 337 UndoAllMostVisitedDeletions();
331 }; 338 };
332 this.undoMostVisitedDeletion = function(restrictId) { 339 this.undoMostVisitedDeletion = function(restrictId) {
333 UndoMostVisitedDeletion(restrictId); 340 UndoMostVisitedDeletion(restrictId);
334 }; 341 };
342 this.navigateContentWindow = function(destination, disposition) {
343 NavigateNewTabPage(destination, disposition);
344 }
335 345
336 this.onmostvisitedchange = null; 346 this.onmostvisitedchange = null;
337 this.onthemechange = null; 347 this.onthemechange = null;
338 }; 348 };
339 349
340 // Export legacy searchbox API. 350 // Export legacy searchbox API.
341 // TODO: Remove this when Instant Extended is fully launched. 351 // TODO: Remove this when Instant Extended is fully launched.
342 chrome.searchBox = this.searchBox; 352 chrome.searchBox = this.searchBox;
343 }; 353 };
344 } 354 }
OLDNEW
« no previous file with comments | « chrome/browser/instant/instant_controller.cc ('k') | chrome/renderer/searchbox/searchbox.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698