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 5 var chrome; 6 if (!chrome) 7 chrome = {}; 8 9 if (!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 GetMostVisitedItems(); 87 native function GetThemeBackgroundInfo(); 88 native function IsInputInProgress(); 89 native function LogEvent(); 90 native function LogImpression(); 91 native function NavigateContentWindow(); 92 native function UndoAllMostVisitedDeletions(); 93 native function UndoMostVisitedDeletion(); 94 95 function GetMostVisitedItemsWrapper() { 96 var mostVisitedItems = GetMostVisitedItems(); 97 for (var i = 0, item; item = mostVisitedItems[i]; ++i) { 98 item.faviconUrl = GenerateFaviconURL(item.renderViewId, item.rid); 99 // These properties are private data and should not be returned to 100 // the page. They are only accessible via getMostVisitedItemData(). 101 item.url = null; 102 item.title = null; 103 item.domain = null; 104 item.direction = null; 105 item.renderViewId = null; 106 } 107 return mostVisitedItems; 108 } 109 110 function GenerateFaviconURL(renderViewId, rid) { 111 return "chrome-search://favicon/size/16@" + 112 window.devicePixelRatio + "x/" + 113 renderViewId + "/" + rid; 114 } 115 116 // ======================================================================= 117 // Exported functions 118 // ======================================================================= 119 this.__defineGetter__('appLauncherEnabled', GetAppLauncherEnabled); 120 this.__defineGetter__('isInputInProgress', IsInputInProgress); 121 this.__defineGetter__('mostVisited', GetMostVisitedItemsWrapper); 122 this.__defineGetter__('themeBackgroundInfo', GetThemeBackgroundInfo); 123 124 this.deleteMostVisitedItem = function(restrictedId) { 125 DeleteMostVisitedItem(restrictedId); 126 }; 127 128 this.checkIsUserSignedIntoChromeAs = function(identity) { 129 CheckIsUserSignedInToChromeAs(identity); 130 }; 131 132 // This method is restricted to chrome-search://most-visited pages by 133 // checking the invoking context's origin in searchbox_extension.cc. 134 this.logEvent = function(histogram_name) { 135 LogEvent(histogram_name); 136 }; 137 138 // This method is restricted to chrome-search://most-visited pages by 139 // checking the invoking context's origin in searchbox_extension.cc. 140 this.logImpression = function(position, provider) { 141 LogImpression(position, provider); 142 }; 143 144 this.navigateContentWindow = function(destination, disposition) { 145 NavigateContentWindow(destination, disposition); 146 }; 147 148 this.undoAllMostVisitedDeletions = function() { 149 UndoAllMostVisitedDeletions(); 150 }; 151 152 this.undoMostVisitedDeletion = function(restrictedId) { 153 UndoMostVisitedDeletion(restrictedId); 154 }; 155 156 this.onsignedincheckdone = null; 157 this.oninputcancel = null; 158 this.oninputstart = null; 159 this.onmostvisitedchange = null; 160 this.onthemechange = null; 161 }; 162 163 // TODO(jered): Remove when google no longer expects this object. 164 chrome.searchBox = this.searchBox; 165 }; 166 } 167