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. 4 5var chrome; 6if (!chrome) 7 chrome = {}; 8 9if (!chrome.embeddedSearch) { 10 chrome.embeddedSearch = new function() { 11 this.searchBox = new function() { 12 13 // ======================================================================= 14 // Private functions 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(); 29 30 // ======================================================================= 31 // Exported functions 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); 40 41 this.focus = function() { 42 Focus(); 43 }; 44 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); 49 }; 50 51 this.paste = function(value) { 52 Paste(value); 53 }; 54 55 this.setVoiceSearchSupported = function(supported) { 56 SetVoiceSearchSupported(supported); 57 }; 58 59 this.startCapturingKeyStrokes = function() { 60 StartCapturingKeyStrokes(); 61 }; 62 63 this.stopCapturingKeyStrokes = function() { 64 StopCapturingKeyStrokes(); 65 }; 66 67 this.onfocuschange = null; 68 this.onkeycapturechange = null; 69 this.onmarginchange = null; 70 this.onsubmit = null; 71 this.onsuggestionchange = null; 72 this.ontogglevoicesearch = null; 73 74 //TODO(jered): Remove this empty method when google no longer requires it. 75 this.setRestrictedValue = function() {}; 76 }; 77 78 this.newTabPage = new function() { 79 80 // ======================================================================= 81 // Private functions 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(); 96 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(). 103 item.url = null; 104 item.title = null; 105 item.domain = null; 106 item.direction = null; 107 item.renderViewId = null; 108 } 109 return mostVisitedItems; 110 } 111 112 function GenerateFaviconURL(renderViewId, rid) { 113 return "chrome-search://favicon/size/16@" + 114 window.devicePixelRatio + "x/" + 115 renderViewId + "/" + rid; 116 } 117 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); 125 126 this.deleteMostVisitedItem = function(restrictedId) { 127 DeleteMostVisitedItem(restrictedId); 128 }; 129 130 this.getDispositionFromClick = function(middle_button, 131 alt_key, 132 ctrl_key, 133 meta_key, 134 shift_key) { 135 return GetDispositionFromClick(middle_button, 136 alt_key, 137 ctrl_key, 138 meta_key, 139 shift_key); 140 }; 141 142 this.checkIsUserSignedIntoChromeAs = function(identity) { 143 CheckIsUserSignedInToChromeAs(identity); 144 }; 145 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); 150 }; 151 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); 156 }; 157 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); 162 }; 163 164 this.navigateContentWindow = function(destination, disposition) { 165 NavigateContentWindow(destination, disposition); 166 }; 167 168 this.undoAllMostVisitedDeletions = function() { 169 UndoAllMostVisitedDeletions(); 170 }; 171 172 this.undoMostVisitedDeletion = function(restrictedId) { 173 UndoMostVisitedDeletion(restrictedId); 174 }; 175 176 this.onsignedincheckdone = null; 177 this.oninputcancel = null; 178 this.oninputstart = null; 179 this.onmostvisitedchange = null; 180 this.onthemechange = null; 181 }; 182 183 // TODO(jered): Remove when google no longer expects this object. 184 chrome.searchBox = this.searchBox; 185 }; 186} 187