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 GetRightToLeft();
21 native function GetStartMargin();
22 native function GetSuggestionToPrefetch();
23 native function IsFocused();
24 native function IsKeyCaptureEnabled();
25 native function Paste();
26 native function SetVoiceSearchSupported();
27 native function StartCapturingKeyStrokes();
28 native function StopCapturingKeyStrokes();
30 // =======================================================================
32 // =======================================================================
33 this.__defineGetter__('displayInstantResults', GetDisplayInstantResults);
34 this.__defineGetter__('isFocused', IsFocused);
35 this.__defineGetter__('isKeyCaptureEnabled', IsKeyCaptureEnabled);
36 this.__defineGetter__('rtl', GetRightToLeft);
37 this.__defineGetter__('startMargin', GetStartMargin);
38 this.__defineGetter__('suggestion', GetSuggestionToPrefetch);
39 this.__defineGetter__('value', GetQuery);
41 this.focus = function() {
45 // This method is restricted to chrome-search://most-visited pages by
46 // checking the invoking context's origin in searchbox_extension.cc.
47 this.getMostVisitedItemData = function(restrictedId) {
48 return GetMostVisitedItemData(restrictedId);
51 this.paste = function(value) {
55 this.setVoiceSearchSupported = function(supported) {
56 SetVoiceSearchSupported(supported);
59 this.startCapturingKeyStrokes = function() {
60 StartCapturingKeyStrokes();
63 this.stopCapturingKeyStrokes = function() {
64 StopCapturingKeyStrokes();
67 this.onfocuschange = null;
68 this.onkeycapturechange = null;
69 this.onmarginchange = null;
71 this.onsuggestionchange = null;
72 this.ontogglevoicesearch = null;
74 //TODO(jered): Remove this empty method when google no longer requires it.
75 this.setRestrictedValue = function() {};
78 this.newTabPage = new function() {
80 // =======================================================================
82 // =======================================================================
83 native function CheckIsUserSignedInToChromeAs();
84 native function DeleteMostVisitedItem();
85 native function GetAppLauncherEnabled();
86 native function GetDispositionFromClick();
87 native function GetMostVisitedItems();
88 native function GetThemeBackgroundInfo();
89 native function IsInputInProgress();
90 native function LogEvent();
91 native function LogMostVisitedImpression();
92 native function LogMostVisitedNavigation();
93 native function NavigateContentWindow();
94 native function UndoAllMostVisitedDeletions();
95 native function UndoMostVisitedDeletion();
97 function GetMostVisitedItemsWrapper() {
98 var mostVisitedItems = GetMostVisitedItems();
99 for (var i = 0, item; item = mostVisitedItems[i]; ++i) {
100 item.faviconUrl = GenerateFaviconURL(item.renderViewId, item.rid);
101 // These properties are private data and should not be returned to
102 // the page. They are only accessible via getMostVisitedItemData().
106 item.direction = null;
107 item.renderViewId = null;
109 return mostVisitedItems;
112 function GenerateFaviconURL(renderViewId, rid) {
113 return "chrome-search://favicon/size/16@" +
114 window.devicePixelRatio + "x/" +
115 renderViewId + "/" + rid;
118 // =======================================================================
119 // Exported functions
120 // =======================================================================
121 this.__defineGetter__('appLauncherEnabled', GetAppLauncherEnabled);
122 this.__defineGetter__('isInputInProgress', IsInputInProgress);
123 this.__defineGetter__('mostVisited', GetMostVisitedItemsWrapper);
124 this.__defineGetter__('themeBackgroundInfo', GetThemeBackgroundInfo);
126 this.deleteMostVisitedItem = function(restrictedId) {
127 DeleteMostVisitedItem(restrictedId);
130 this.getDispositionFromClick = function(middle_button,
135 return GetDispositionFromClick(middle_button,
142 this.checkIsUserSignedIntoChromeAs = function(identity) {
143 CheckIsUserSignedInToChromeAs(identity);
146 // This method is restricted to chrome-search://most-visited pages by
147 // checking the invoking context's origin in searchbox_extension.cc.
148 this.logEvent = function(histogram_name) {
149 LogEvent(histogram_name);
152 // This method is restricted to chrome-search://most-visited pages by
153 // checking the invoking context's origin in searchbox_extension.cc.
154 this.logMostVisitedImpression = function(position, provider) {
155 LogMostVisitedImpression(position, provider);
158 // This method is restricted to chrome-search://most-visited pages by
159 // checking the invoking context's origin in searchbox_extension.cc.
160 this.logMostVisitedNavigation = function(position, provider) {
161 LogMostVisitedNavigation(position, provider);
164 this.navigateContentWindow = function(destination, disposition) {
165 NavigateContentWindow(destination, disposition);
168 this.undoAllMostVisitedDeletions = function() {
169 UndoAllMostVisitedDeletions();
172 this.undoMostVisitedDeletion = function(restrictedId) {
173 UndoMostVisitedDeletion(restrictedId);
176 this.onsignedincheckdone = null;
177 this.oninputcancel = null;
178 this.oninputstart = null;
179 this.onmostvisitedchange = null;
180 this.onthemechange = null;
183 // TODO(jered): Remove when google no longer expects this object.
184 chrome.searchBox = this.searchBox;