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 return GetMostVisitedItemData(restrictedId);
54 this.paste = function(value) {
58 this.setVoiceSearchSupported = function(supported) {
59 SetVoiceSearchSupported(supported);
62 this.startCapturingKeyStrokes = function() {
63 StartCapturingKeyStrokes();
66 this.stopCapturingKeyStrokes = function() {
67 StopCapturingKeyStrokes();
70 this.onfocuschange = null;
71 this.onkeycapturechange = null;
72 this.onmarginchange = null;
74 this.onsuggestionchange = null;
75 this.ontogglevoicesearch = null;
77 //TODO(jered): Remove this empty method when google no longer requires it.
78 this.setRestrictedValue = function() {};
81 this.newTabPage = new function() {
83 // =======================================================================
85 // =======================================================================
86 native function CheckIsUserSignedInToChromeAs();
87 native function CheckIsUserSyncingHistory();
88 native function DeleteMostVisitedItem();
89 native function GetAppLauncherEnabled();
90 native function GetDispositionFromClick();
91 native function GetMostVisitedItems();
92 native function GetThemeBackgroundInfo();
93 native function IsInputInProgress();
94 native function LogEvent();
95 native function LogMostVisitedImpression();
96 native function LogMostVisitedNavigation();
97 native function NavigateContentWindow();
98 native function UndoAllMostVisitedDeletions();
99 native function UndoMostVisitedDeletion();
101 function GetMostVisitedItemsWrapper() {
102 var mostVisitedItems = GetMostVisitedItems();
103 for (var i = 0, item; item = mostVisitedItems[i]; ++i) {
104 item.faviconUrl = GenerateFaviconURL(item.renderViewId, item.rid);
105 // These properties are private data and should not be returned to
106 // the page. They are only accessible via getMostVisitedItemData().
110 item.direction = null;
111 item.renderViewId = null;
113 return mostVisitedItems;
116 function GenerateFaviconURL(renderViewId, rid) {
117 return "chrome-search://favicon/size/16@" +
118 window.devicePixelRatio + "x/" +
119 renderViewId + "/" + rid;
122 // =======================================================================
123 // Exported functions
124 // =======================================================================
125 this.__defineGetter__('appLauncherEnabled', GetAppLauncherEnabled);
126 this.__defineGetter__('isInputInProgress', IsInputInProgress);
127 this.__defineGetter__('mostVisited', GetMostVisitedItemsWrapper);
128 this.__defineGetter__('themeBackgroundInfo', GetThemeBackgroundInfo);
130 this.deleteMostVisitedItem = function(restrictedId) {
131 DeleteMostVisitedItem(restrictedId);
134 this.getDispositionFromClick = function(middle_button,
139 return GetDispositionFromClick(middle_button,
146 this.checkIsUserSignedIntoChromeAs = function(identity) {
147 CheckIsUserSignedInToChromeAs(identity);
150 this.checkIsUserSyncingHistory = function() {
151 CheckIsUserSyncingHistory();
154 // This method is restricted to chrome-search://most-visited pages by
155 // checking the invoking context's origin in searchbox_extension.cc.
156 this.logEvent = function(histogram_name) {
157 LogEvent(histogram_name);
160 // This method is restricted to chrome-search://most-visited pages by
161 // checking the invoking context's origin in searchbox_extension.cc.
162 this.logMostVisitedImpression = function(position, provider) {
163 LogMostVisitedImpression(position, provider);
166 // This method is restricted to chrome-search://most-visited pages by
167 // checking the invoking context's origin in searchbox_extension.cc.
168 this.logMostVisitedNavigation = function(position, provider) {
169 LogMostVisitedNavigation(position, provider);
172 this.navigateContentWindow = function(destination, disposition) {
173 NavigateContentWindow(destination, disposition);
176 this.undoAllMostVisitedDeletions = function() {
177 UndoAllMostVisitedDeletions();
180 this.undoMostVisitedDeletion = function(restrictedId) {
181 UndoMostVisitedDeletion(restrictedId);
184 this.onsignedincheckdone = null;
185 this.onhistorysynccheckdone = null;
186 this.oninputcancel = null;
187 this.oninputstart = null;
188 this.onmostvisitedchange = null;
189 this.onthemechange = null;
192 // TODO(jered): Remove when google no longer expects this object.
193 chrome.searchBox = this.searchBox;