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

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

Issue 11413018: alternate ntp: implement searchbox api for instant overlay to adopt themes (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: addressed sreeram's comments, fixed to not set theme fields if no theme Created 8 years, 1 month 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/common/render_messages.h ('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 (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 var chrome; 5 var chrome;
6 if (!chrome) 6 if (!chrome)
7 chrome = {}; 7 chrome = {};
8 if (!chrome.searchBox) { 8 if (!chrome.searchBox) {
9 chrome.searchBox = new function() { 9 chrome.searchBox = new function() {
10 // ========================================================================= 10 // =========================================================================
(...skipping 12 matching lines...) Expand all
23 native function GetQuery(); 23 native function GetQuery();
24 native function GetVerbatim(); 24 native function GetVerbatim();
25 native function GetSelectionStart(); 25 native function GetSelectionStart();
26 native function GetSelectionEnd(); 26 native function GetSelectionEnd();
27 native function GetX(); 27 native function GetX();
28 native function GetY(); 28 native function GetY();
29 native function GetWidth(); 29 native function GetWidth();
30 native function GetHeight(); 30 native function GetHeight();
31 native function GetAutocompleteResults(); 31 native function GetAutocompleteResults();
32 native function GetContext(); 32 native function GetContext();
33 native function GetThemeBackgroundInfo();
34 native function GetThemeAreaHeight();
33 native function NavigateContentWindow(); 35 native function NavigateContentWindow();
34 native function SetSuggestions(); 36 native function SetSuggestions();
35 native function SetQuerySuggestion(); 37 native function SetQuerySuggestion();
36 native function SetQuerySuggestionFromAutocompleteResult(); 38 native function SetQuerySuggestionFromAutocompleteResult();
37 native function SetQuery(); 39 native function SetQuery();
38 native function SetQueryFromAutocompleteResult(); 40 native function SetQueryFromAutocompleteResult();
39 native function Show(); 41 native function Show();
40 42
41 // Returns the |restrictedText| wrapped in a ShadowDOM. 43 // Returns the |restrictedText| wrapped in a ShadowDOM.
42 function SafeWrap(restrictedText) { 44 function SafeWrap(restrictedText) {
43 var node = document.createElement('div'); 45 var node = document.createElement('div');
44 var nodeShadow = new WebKitShadowRoot(node); 46 var nodeShadow = new WebKitShadowRoot(node);
45 nodeShadow.applyAuthorStyles = true; 47 nodeShadow.applyAuthorStyles = true;
46 nodeShadow.innerHTML = 48 nodeShadow.innerHTML =
47 '<div style="width:700px!important;' + 49 '<div style="width:700px!important;' +
48 ' height:22px!important;' + 50 ' height:22px!important;' +
49 ' font-family:\'Chrome Droid Sans\',\'Arial\'!important;' + 51 ' font-family:\'Chrome Droid Sans\',\'Arial\'!important;' +
50 ' overflow:hidden!important;' + 52 ' overflow:hidden!important;' +
51 ' text-overflow:ellipsis!important">' + 53 ' text-overflow:ellipsis!important">' +
52 ' <nobr>' + restrictedText + '</nobr>' + 54 ' <nobr>' + restrictedText + '</nobr>' +
53 '</div>'; 55 '</div>';
54 return node; 56 return node;
55 } 57 }
56 58
57 // Wraps the AutocompleteResult query and URL into ShadowDOM nodes so that 59 // Wraps the AutocompleteResult query and URL into ShadowDOM nodes so that
58 // the JS cannot access them and deletes the raw values. 60 // the JS cannot access them and deletes the raw values.
59 function GetAutocompleteResultsWrapper() { 61 function GetAutocompleteResultsWrapper() {
60 var autocompleteResults = DedupeAutcompleteResults( 62 var autocompleteResults = DedupeAutocompleteResults(
61 GetAutocompleteResults()); 63 GetAutocompleteResults());
62 var userInput = GetQuery(); 64 var userInput = GetQuery();
63 for (var i = 0, result; result = autocompleteResults[i]; ++i) { 65 for (var i = 0, result; result = autocompleteResults[i]; ++i) {
64 var title = result.contents; 66 var title = result.contents;
65 var url = CleanUrl(result.destination_url, userInput); 67 var url = CleanUrl(result.destination_url, userInput);
66 var combinedHtml = '<span class=chrome_url>' + url + '</span>'; 68 var combinedHtml = '<span class=chrome_url>' + url + '</span>';
67 if (title) { 69 if (title) {
68 result.titleNode = SafeWrap(title); 70 result.titleNode = SafeWrap(title);
69 combinedHtml += '<span class=chrome_separator> &ndash; </span>' + 71 combinedHtml += '<span class=chrome_separator> &ndash; </span>' +
70 '<span class=chrome_title>' + title + '</span>'; 72 '<span class=chrome_title>' + title + '</span>';
(...skipping 18 matching lines...) Expand all
89 return url.replace(WWW_REGEX, ''); 91 return url.replace(WWW_REGEX, '');
90 } 92 }
91 93
92 // TODO(dcblack): Do this in C++ instead of JS. 94 // TODO(dcblack): Do this in C++ instead of JS.
93 function CanonicalizeUrl(url) { 95 function CanonicalizeUrl(url) {
94 return url.replace(HTTP_REGEX, '').replace(WWW_REGEX, ''); 96 return url.replace(HTTP_REGEX, '').replace(WWW_REGEX, '');
95 } 97 }
96 98
97 // Removes duplicates from AutocompleteResults. 99 // Removes duplicates from AutocompleteResults.
98 // TODO(dcblack): Do this in C++ instead of JS. 100 // TODO(dcblack): Do this in C++ instead of JS.
99 function DedupeAutcompleteResults(autocompleteResults) { 101 function DedupeAutocompleteResults(autocompleteResults) {
100 var urlToResultMap = {}; 102 var urlToResultMap = {};
101 for (var i = 0, result; result = autocompleteResults[i]; ++i) { 103 for (var i = 0, result; result = autocompleteResults[i]; ++i) {
102 var url = CanonicalizeUrl(result.destination_url); 104 var url = CanonicalizeUrl(result.destination_url);
103 if (url in urlToResultMap) { 105 if (url in urlToResultMap) {
104 var oldRelevance = urlToResultMap[url].rankingData.relevance; 106 var oldRelevance = urlToResultMap[url].rankingData.relevance;
105 var newRelevance = result.rankingData.relevance; 107 var newRelevance = result.rankingData.relevance;
106 if (newRelevance > oldRelevance) { 108 if (newRelevance > oldRelevance) {
107 urlToResultMap[url] = result; 109 urlToResultMap[url] = result;
108 } 110 }
109 } else { 111 } else {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 this.__defineGetter__('value', GetQuery); 170 this.__defineGetter__('value', GetQuery);
169 this.__defineGetter__('verbatim', GetVerbatim); 171 this.__defineGetter__('verbatim', GetVerbatim);
170 this.__defineGetter__('selectionStart', GetSelectionStart); 172 this.__defineGetter__('selectionStart', GetSelectionStart);
171 this.__defineGetter__('selectionEnd', GetSelectionEnd); 173 this.__defineGetter__('selectionEnd', GetSelectionEnd);
172 this.__defineGetter__('x', GetX); 174 this.__defineGetter__('x', GetX);
173 this.__defineGetter__('y', GetY); 175 this.__defineGetter__('y', GetY);
174 this.__defineGetter__('width', GetWidth); 176 this.__defineGetter__('width', GetWidth);
175 this.__defineGetter__('height', GetHeight); 177 this.__defineGetter__('height', GetHeight);
176 this.__defineGetter__('nativeSuggestions', GetAutocompleteResultsWrapper); 178 this.__defineGetter__('nativeSuggestions', GetAutocompleteResultsWrapper);
177 this.__defineGetter__('context', GetContext); 179 this.__defineGetter__('context', GetContext);
180 this.__defineGetter__('themeBackgroundInfo', GetThemeBackgroundInfo);
181 this.__defineGetter__('themeAreaHeight', GetThemeAreaHeight);
178 this.setSuggestions = function(text) { 182 this.setSuggestions = function(text) {
179 SetSuggestions(text); 183 SetSuggestions(text);
180 }; 184 };
181 this.setAutocompleteText = function(text, behavior) { 185 this.setAutocompleteText = function(text, behavior) {
182 SetQuerySuggestion(text, behavior); 186 SetQuerySuggestion(text, behavior);
183 }; 187 };
184 this.setRestrictedAutocompleteText = function(resultId) { 188 this.setRestrictedAutocompleteText = function(resultId) {
185 SetQuerySuggestionFromAutocompleteResult(resultId); 189 SetQuerySuggestionFromAutocompleteResult(resultId);
186 }; 190 };
187 this.setValue = function(text, type) { 191 this.setValue = function(text, type) {
(...skipping 13 matching lines...) Expand all
201 }; 205 };
202 this.onchange = null; 206 this.onchange = null;
203 this.onsubmit = null; 207 this.onsubmit = null;
204 this.oncancel = null; 208 this.oncancel = null;
205 this.onresize = null; 209 this.onresize = null;
206 this.onautocompleteresults = null; 210 this.onautocompleteresults = null;
207 this.onkeypress = null; 211 this.onkeypress = null;
208 this.oncontextchange = null; 212 this.oncontextchange = null;
209 }; 213 };
210 } 214 }
OLDNEW
« no previous file with comments | « chrome/common/render_messages.h ('k') | chrome/renderer/searchbox/searchbox.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698