chrome_proto.js revision 5f1c94371a64b3196d4be9466099bb892df9b88e
1// Copyright (c) 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// This file contains various hacks needed to inform JSCompiler of various 6// WebKit- and Chrome-specific properties and methods. It is used only with 7// JSCompiler to verify the type-correctness of our code. 8 9/** @type {Object} */ 10var chrome = {}; 11 12 13/** @type {Object} */ 14chrome.app = {}; 15 16/** @type {Object} */ 17chrome.app.runtime = { 18 /** @type {chrome.Event} */ 19 onLaunched: null 20}; 21 22 23/** @type {Object} */ 24chrome.app.window = { 25 /** 26 * @param {string} name 27 * @param {Object} parameters 28 * @param {function()=} opt_callback 29 */ 30 create: function(name, parameters, opt_callback) {}, 31 /** 32 * @return {AppWindow} 33 */ 34 current: function() {} 35}; 36 37 38/** @type {Object} */ 39chrome.runtime = { 40 /** @type {Object} */ 41 lastError: { 42 /** @type {string} */ 43 message: '' 44 }, 45 /** @return {{version: string, app: {background: Object}}} */ 46 getManifest: function() {} 47}; 48 49/** 50 * @type {?function(string):chrome.extension.Port} 51 */ 52chrome.runtime.connectNative = function(name) {}; 53 54/** 55 * @param {string} extensionId 56 * @param {*} message 57 * @param {Object=} opt_options 58 * @param {function(*)=} opt_callback 59 */ 60chrome.runtime.sendMessage = function( 61 extensionId, message, opt_options, opt_callback) {}; 62 63/** @type {Object} */ 64chrome.extension = {}; 65 66/** @constructor */ 67chrome.extension.Port = function() {}; 68 69/** @type {chrome.Event} */ 70chrome.extension.Port.prototype.onMessage; 71 72/** @type {chrome.Event} */ 73chrome.extension.Port.prototype.onDisconnect; 74 75/** 76 * @param {Object} message 77 */ 78chrome.extension.Port.prototype.postMessage = function(message) {}; 79 80/** 81 * @param {*} message 82 */ 83chrome.extension.sendMessage = function(message) {} 84 85/** @type {chrome.Event} */ 86chrome.extension.onMessage; 87 88 89/** @type {Object} */ 90chrome.i18n = {}; 91 92/** 93 * @param {string} messageName 94 * @param {(string|Array.<string>)=} opt_args 95 * @return {string} 96 */ 97chrome.i18n.getMessage = function(messageName, opt_args) {}; 98 99 100/** @type {Object} */ 101chrome.storage = {}; 102 103/** @type {chrome.Storage} */ 104chrome.storage.local; 105 106/** @type {chrome.Storage} */ 107chrome.storage.sync; 108 109/** @constructor */ 110chrome.Storage = function() {}; 111 112/** 113 * @param {string|Array.<string>|Object.<string>} items 114 * @param {function(Object.<string>):void} callback 115 * @return {void} 116 */ 117chrome.Storage.prototype.get = function(items, callback) {}; 118 119/** 120 * @param {Object.<string>} items 121 * @param {function():void=} opt_callback 122 * @return {void} 123 */ 124chrome.Storage.prototype.set = function(items, opt_callback) {}; 125 126/** 127 * @param {string|Array.<string>} items 128 * @param {function():void=} opt_callback 129 * @return {void} 130 */ 131chrome.Storage.prototype.remove = function(items, opt_callback) {}; 132 133/** 134 * @param {function():void=} opt_callback 135 * @return {void} 136 */ 137chrome.Storage.prototype.clear = function(opt_callback) {}; 138 139 140/** 141 * @type {Object} 142 * src/chrome/common/extensions/api/context_menus.json 143 */ 144chrome.contextMenus = {}; 145/** @type {ChromeEvent} */ 146chrome.contextMenus.onClicked; 147/** 148 * @param {!Object} createProperties 149 * @param {function()=} opt_callback 150 */ 151chrome.contextMenus.create = function(createProperties, opt_callback) {}; 152/** 153 * @param {string|number} id 154 * @param {!Object} updateProperties 155 * @param {function()=} opt_callback 156 */ 157chrome.contextMenus.update = function(id, updateProperties, opt_callback) {}; 158/** 159 * @param {string|number} menuItemId 160 * @param {function()=} opt_callback 161 */ 162chrome.contextMenus.remove = function(menuItemId, opt_callback) {}; 163/** 164 * @param {function()=} opt_callback 165 */ 166chrome.contextMenus.removeAll = function(opt_callback) {}; 167 168/** @constructor */ 169function OnClickData() {} 170/** @type {string|number} */ 171OnClickData.prototype.menuItemId; 172/** @type {string|number} */ 173OnClickData.prototype.parentMenuItemId; 174/** @type {string} */ 175OnClickData.prototype.mediaType; 176/** @type {string} */ 177OnClickData.prototype.linkUrl; 178/** @type {string} */ 179OnClickData.prototype.srcUrl; 180/** @type {string} */ 181OnClickData.prototype.pageUrl; 182/** @type {string} */ 183OnClickData.prototype.frameUrl; 184/** @type {string} */ 185OnClickData.prototype.selectionText; 186/** @type {boolean} */ 187OnClickData.prototype.editable; 188/** @type {boolean} */ 189OnClickData.prototype.wasChecked; 190/** @type {boolean} */ 191OnClickData.prototype.checked; 192 193 194/** @type {Object} */ 195chrome.identity = { 196 /** 197 * @param {Object.<string>} parameters 198 * @param {function(string):void} callback 199 */ 200 getAuthToken: function(parameters, callback) {}, 201 /** 202 * @param {Object.<string>} parameters 203 * @param {function():void} callback 204 */ 205 removeCachedAuthToken: function(parameters, callback) {}, 206 /** 207 * @param {Object.<string>} parameters 208 * @param {function(string):void} callback 209 */ 210 launchWebAuthFlow: function(parameters, callback) {} 211}; 212 213// TODO(garykac): Combine chrome.Event and ChromeEvent 214/** @constructor */ 215function ChromeEvent() {} 216/** @param {Function} callback */ 217ChromeEvent.prototype.addListener = function(callback) {}; 218/** @param {Function} callback */ 219ChromeEvent.prototype.removeListener = function(callback) {}; 220/** @param {Function} callback */ 221ChromeEvent.prototype.hasListener = function(callback) {}; 222/** @param {Function} callback */ 223ChromeEvent.prototype.hasListeners = function(callback) {}; 224 225/** @constructor */ 226chrome.Event = function() {}; 227 228/** @param {function():void} callback */ 229chrome.Event.prototype.addListener = function(callback) {}; 230 231/** @param {function():void} callback */ 232chrome.Event.prototype.removeListener = function(callback) {}; 233 234 235/** @type {Object} */ 236chrome.permissions = { 237 /** 238 * @param {Object.<string>} permissions 239 * @param {function(boolean):void} callback 240 */ 241 contains: function(permissions, callback) {}, 242 /** 243 * @param {Object.<string>} permissions 244 * @param {function(boolean):void} callback 245 */ 246 request: function(permissions, callback) {} 247}; 248 249 250/** @type {Object} */ 251chrome.tabs = {}; 252 253/** @param {function(chrome.Tab):void} callback */ 254chrome.tabs.getCurrent = function(callback) {}; 255 256/** @constructor */ 257chrome.Tab = function() { 258 /** @type {boolean} */ 259 this.pinned = false; 260 /** @type {number} */ 261 this.windowId = 0; 262}; 263 264 265/** @type {Object} */ 266chrome.windows = {}; 267 268/** @param {number} id 269 * @param {Object?} getInfo 270 * @param {function(chrome.Window):void} callback */ 271chrome.windows.get = function(id, getInfo, callback) {}; 272 273/** @constructor */ 274chrome.Window = function() { 275 /** @type {string} */ 276 this.state = ''; 277 /** @type {string} */ 278 this.type = ''; 279}; 280 281/** @constructor */ 282var AppWindow = function() { 283 /** @type {Window} */ 284 this.contentWindow = null; 285 /** @type {chrome.Event} */ 286 this.onRestored = null; 287 /** @type {chrome.Event} */ 288 this.onMaximized = null; 289 /** @type {chrome.Event} */ 290 this.onFullscreened = null; 291}; 292 293AppWindow.prototype.close = function() {}; 294AppWindow.prototype.drawAttention = function() {}; 295AppWindow.prototype.maximize = function() {}; 296AppWindow.prototype.minimize = function() {}; 297AppWindow.prototype.restore = function() {}; 298AppWindow.prototype.fullscreen = function() {}; 299/** @return {boolean} */ 300AppWindow.prototype.isFullscreen = function() {}; 301/** @return {boolean} */ 302AppWindow.prototype.isMaximized = function() {}; 303 304/** 305 * @param {{rects: Array.<ClientRect>}} rects 306 */ 307AppWindow.prototype.setShape = function(rects) {}; 308 309/** 310 * @param {{rects: Array.<ClientRect>}} rects 311 */ 312AppWindow.prototype.setInputRegion = function(rects) {}; 313 314/** @constructor */ 315var LaunchData = function() { 316 /** @type {string} */ 317 this.id = ''; 318 /** @type {Array.<{type: string, entry: FileEntry}>} */ 319 this.items = []; 320}; 321 322/** @constructor */ 323function ClientRect() { 324 /** @type {number} */ 325 this.width = 0; 326 /** @type {number} */ 327 this.height = 0; 328 /** @type {number} */ 329 this.top = 0; 330 /** @type {number} */ 331 this.bottom = 0; 332 /** @type {number} */ 333 this.left = 0; 334 /** @type {number} */ 335 this.right = 0; 336}; 337