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 DeleteMostVisitedItem();
88 native function GetAppLauncherEnabled();
89 native function GetDispositionFromClick();
90 native function GetMostVisitedItems();
91 native function GetThemeBackgroundInfo();
92 native function IsInputInProgress();
93 native function LogEvent();
94 native function LogMostVisitedImpression();
95 native function LogMostVisitedNavigation();
96 native function NavigateContentWindow();
97 native function UndoAllMostVisitedDeletions();
98 native function UndoMostVisitedDeletion();
100 function GetMostVisitedItemsWrapper() {
101 var mostVisitedItems = GetMostVisitedItems();
102 for (var i = 0, item; item = mostVisitedItems[i]; ++i) {
103 item.faviconUrl = GenerateFaviconURL(item.renderViewId, item.rid);
104 // These properties are private data and should not be returned to
105 // the page. They are only accessible via getMostVisitedItemData().
109 item.direction = null;
110 item.renderViewId = null;
112 return mostVisitedItems;
115 function GenerateFaviconURL(renderViewId, rid) {
116 return "chrome-search://favicon/size/16@" +
117 window.devicePixelRatio + "x/" +
118 renderViewId + "/" + rid;
121 // =======================================================================
122 // Exported functions
123 // =======================================================================
124 this.__defineGetter__('appLauncherEnabled', GetAppLauncherEnabled);
125 this.__defineGetter__('isInputInProgress', IsInputInProgress);
126 this.__defineGetter__('mostVisited', GetMostVisitedItemsWrapper);
127 this.__defineGetter__('themeBackgroundInfo', GetThemeBackgroundInfo);
129 this.deleteMostVisitedItem = function(restrictedId) {
130 DeleteMostVisitedItem(restrictedId);
133 this.getDispositionFromClick = function(middle_button,
138 return GetDispositionFromClick(middle_button,
145 this.checkIsUserSignedIntoChromeAs = function(identity) {
146 CheckIsUserSignedInToChromeAs(identity);
149 // This method is restricted to chrome-search://most-visited pages by
150 // checking the invoking context's origin in searchbox_extension.cc.
151 this.logEvent = function(histogram_name) {
152 LogEvent(histogram_name);
155 // This method is restricted to chrome-search://most-visited pages by
156 // checking the invoking context's origin in searchbox_extension.cc.
157 this.logMostVisitedImpression = function(position, provider) {
158 LogMostVisitedImpression(position, provider);
161 // This method is restricted to chrome-search://most-visited pages by
162 // checking the invoking context's origin in searchbox_extension.cc.
163 this.logMostVisitedNavigation = function(position, provider) {
164 LogMostVisitedNavigation(position, provider);
167 this.navigateContentWindow = function(destination, disposition) {
168 NavigateContentWindow(destination, disposition);
171 this.undoAllMostVisitedDeletions = function() {
172 UndoAllMostVisitedDeletions();
175 this.undoMostVisitedDeletion = function(restrictedId) {
176 UndoMostVisitedDeletion(restrictedId);
179 this.onsignedincheckdone = null;
180 this.oninputcancel = null;
181 this.oninputstart = null;
182 this.onmostvisitedchange = null;
183 this.onthemechange = null;
186 // TODO(jered): Remove when google no longer expects this object.
187 chrome.searchBox = this.searchBox;