chrome_proto.js revision a1401311d1ab56c4ed0a474bd38c108f75cb0cd9
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(string):void} callback 204 */ 205 launchWebAuthFlow: function(parameters, callback) {} 206}; 207 208// TODO(garykac): Combine chrome.Event and ChromeEvent 209/** @constructor */ 210function ChromeEvent() {} 211/** @param {Function} callback */ 212ChromeEvent.prototype.addListener = function(callback) {}; 213/** @param {Function} callback */ 214ChromeEvent.prototype.removeListener = function(callback) {}; 215/** @param {Function} callback */ 216ChromeEvent.prototype.hasListener = function(callback) {}; 217/** @param {Function} callback */ 218ChromeEvent.prototype.hasListeners = function(callback) {}; 219 220/** @constructor */ 221chrome.Event = function() {}; 222 223/** @param {function():void} callback */ 224chrome.Event.prototype.addListener = function(callback) {}; 225 226/** @param {function():void} callback */ 227chrome.Event.prototype.removeListener = function(callback) {}; 228 229 230/** @type {Object} */ 231chrome.permissions = { 232 /** 233 * @param {Object.<string>} permissions 234 * @param {function(boolean):void} callback 235 */ 236 contains: function(permissions, callback) {}, 237 /** 238 * @param {Object.<string>} permissions 239 * @param {function(boolean):void} callback 240 */ 241 request: function(permissions, callback) {} 242}; 243 244 245/** @type {Object} */ 246chrome.tabs; 247 248/** @param {function(chrome.Tab):void} callback */ 249chrome.tabs.getCurrent = function(callback) {} 250 251/** @constructor */ 252chrome.Tab = function() { 253 /** @type {boolean} */ 254 this.pinned = false; 255 /** @type {number} */ 256 this.windowId = 0; 257}; 258 259 260/** @type {Object} */ 261chrome.windows; 262 263/** @param {number} id 264 * @param {Object?} getInfo 265 * @param {function(chrome.Window):void} callback */ 266chrome.windows.get = function(id, getInfo, callback) {} 267 268/** @constructor */ 269chrome.Window = function() { 270 /** @type {string} */ 271 this.state = ''; 272 /** @type {string} */ 273 this.type = ''; 274}; 275 276/** @constructor */ 277var AppWindow = function() { 278 /** @type {Window} */ 279 this.contentWindow = null; 280 /** @type {chrome.Event} */ 281 this.onRestored = null; 282}; 283 284AppWindow.prototype.close = function() {}; 285AppWindow.prototype.drawAttention = function() {}; 286AppWindow.prototype.minimize = function() {}; 287 288/** 289 * @param {{rects: Array.<ClientRect>}} rects 290 */ 291AppWindow.prototype.setShape = function(rects) {}; 292 293/** 294 * @param {{rects: Array.<ClientRect>}} rects 295 */ 296AppWindow.prototype.setInputRegion = function(rects) {}; 297 298/** @constructor */ 299var LaunchData = function() { 300 /** @type {string} */ 301 this.id = ''; 302 /** @type {Array.<{type: string, entry: FileEntry}>} */ 303 this.items = []; 304}; 305 306/** @constructor */ 307function ClientRect() { 308 /** @type {number} */ 309 this.width = 0; 310 /** @type {number} */ 311 this.height = 0; 312 /** @type {number} */ 313 this.top = 0; 314 /** @type {number} */ 315 this.bottom = 0; 316 /** @type {number} */ 317 this.left = 0; 318 /** @type {number} */ 319 this.right = 0; 320}; 321