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
3 // found in the LICENSE file.
9 if (!chrome
.embeddedSearch
) {
10 chrome
.embeddedSearch
= new function() {
11 this.searchBox
= new function() {
13 // =======================================================================
15 // =======================================================================
16 native function Focus();
17 native function GetDisplayInstantResults();
18 native function GetMostVisitedItemData();
19 native function GetQuery();
20 native function GetSearchRequestParams();
21 native function GetRightToLeft();
22 native function GetStartMargin();
23 native function GetSuggestionToPrefetch();
24 native function IsFocused();
25 native function IsKeyCaptureEnabled();
26 native function Paste();
27 native function SetVoiceSearchSupported();
28 native function StartCapturingKeyStrokes();
29 native function StopCapturingKeyStrokes();
31 // =======================================================================
33 // =======================================================================
34 this.__defineGetter__('displayInstantResults', GetDisplayInstantResults
);
35 this.__defineGetter__('isFocused', IsFocused
);
36 this.__defineGetter__('isKeyCaptureEnabled', IsKeyCaptureEnabled
);
37 this.__defineGetter__('rtl', GetRightToLeft
);
38 this.__defineGetter__('startMargin', GetStartMargin
);
39 this.__defineGetter__('suggestion', GetSuggestionToPrefetch
);
40 this.__defineGetter__('value', GetQuery
);
41 Object
.defineProperty(this, 'requestParams',
42 { get: GetSearchRequestParams
});
44 this.focus = function() {
48 // This method is restricted to chrome-search://most-visited pages by
49 // checking the invoking context's origin in searchbox_extension.cc.
50 this.getMostVisitedItemData = function(restrictedId
) {
51 var item
= GetMostVisitedItemData(restrictedId
);
53 var sizeInPx
= Math
.floor(48 * window
.devicePixelRatio
+ 0.5);
54 // Populate large icon and fallback icon data, if they exist. We'll
55 // render everything here, once these become available by default.
56 if (item
.largeIconUrl
) {
58 sizeInPx
+ "/" + item
.renderViewId
+ "/" + item
.rid
;
60 if (item
.fallbackIconUrl
) {
61 item
.fallbackIconUrl
+=
62 sizeInPx
+ ",,,,/" + item
.renderViewId
+ "/" + item
.rid
;
68 this.paste = function(value
) {
72 this.setVoiceSearchSupported = function(supported
) {
73 SetVoiceSearchSupported(supported
);
76 this.startCapturingKeyStrokes = function() {
77 StartCapturingKeyStrokes();
80 this.stopCapturingKeyStrokes = function() {
81 StopCapturingKeyStrokes();
84 this.onfocuschange
= null;
85 this.onkeycapturechange
= null;
86 this.onmarginchange
= null;
88 this.onsuggestionchange
= null;
89 this.ontogglevoicesearch
= null;
91 //TODO(jered): Remove this empty method when google no longer requires it.
92 this.setRestrictedValue = function() {};
95 this.newTabPage
= new function() {
97 // =======================================================================
99 // =======================================================================
100 native function CheckIsUserSignedInToChromeAs();
101 native function CheckIsUserSyncingHistory();
102 native function DeleteMostVisitedItem();
103 native function GetAppLauncherEnabled();
104 native function GetDispositionFromClick();
105 native function GetMostVisitedItems();
106 native function GetThemeBackgroundInfo();
107 native function IsInputInProgress();
108 native function LogEvent();
109 native function LogMostVisitedImpression();
110 native function LogMostVisitedNavigation();
111 native function NavigateContentWindow();
112 native function UndoAllMostVisitedDeletions();
113 native function UndoMostVisitedDeletion();
115 function GetMostVisitedItemsWrapper() {
116 var mostVisitedItems
= GetMostVisitedItems();
117 for (var i
= 0, item
; item
= mostVisitedItems
[i
]; ++i
) {
118 item
.faviconUrl
= GenerateFaviconURL(item
.renderViewId
, item
.rid
);
120 // These properties are private data and should not be returned to
121 // the page. They are only accessible via getMostVisitedItemData().
125 delete item
.direction
;
126 delete item
.renderViewId
;
127 delete item
.largeIconUrl
;
128 delete item
.fallbackIconUrl
;
130 return mostVisitedItems
;
133 function GenerateFaviconURL(renderViewId
, rid
) {
134 return "chrome-search://favicon/size/16@" +
135 window
.devicePixelRatio
+ "x/" +
136 renderViewId
+ "/" + rid
;
139 // =======================================================================
140 // Exported functions
141 // =======================================================================
142 this.__defineGetter__('appLauncherEnabled', GetAppLauncherEnabled
);
143 this.__defineGetter__('isInputInProgress', IsInputInProgress
);
144 this.__defineGetter__('mostVisited', GetMostVisitedItemsWrapper
);
145 this.__defineGetter__('themeBackgroundInfo', GetThemeBackgroundInfo
);
147 this.deleteMostVisitedItem = function(restrictedId
) {
148 DeleteMostVisitedItem(restrictedId
);
151 this.getDispositionFromClick = function(middle_button
,
156 return GetDispositionFromClick(middle_button
,
163 this.checkIsUserSignedIntoChromeAs = function(identity
) {
164 CheckIsUserSignedInToChromeAs(identity
);
167 this.checkIsUserSyncingHistory = function() {
168 CheckIsUserSyncingHistory();
171 // This method is restricted to chrome-search://most-visited pages by
172 // checking the invoking context's origin in searchbox_extension.cc.
173 this.logEvent = function(histogram_name
) {
174 LogEvent(histogram_name
);
177 // This method is restricted to chrome-search://most-visited pages by
178 // checking the invoking context's origin in searchbox_extension.cc.
179 this.logMostVisitedImpression = function(position
, provider
) {
180 LogMostVisitedImpression(position
, provider
);
183 // This method is restricted to chrome-search://most-visited pages by
184 // checking the invoking context's origin in searchbox_extension.cc.
185 this.logMostVisitedNavigation = function(position
, provider
) {
186 LogMostVisitedNavigation(position
, provider
);
189 this.navigateContentWindow = function(destination
, disposition
) {
190 NavigateContentWindow(destination
, disposition
);
193 this.undoAllMostVisitedDeletions = function() {
194 UndoAllMostVisitedDeletions();
197 this.undoMostVisitedDeletion = function(restrictedId
) {
198 UndoMostVisitedDeletion(restrictedId
);
201 this.onsignedincheckdone
= null;
202 this.onhistorysynccheckdone
= null;
203 this.oninputcancel
= null;
204 this.oninputstart
= null;
205 this.onmostvisitedchange
= null;
206 this.onthemechange
= null;
209 // TODO(jered): Remove when google no longer expects this object.
210 chrome
.searchBox
= this.searchBox
;