Home | History | Annotate | Download | only in js_proto
      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} */
     10 var chrome = {};
     11 
     12 
     13 /** @type {Object} */
     14 chrome.app = {};
     15 
     16 /** @type {Object} */
     17 chrome.app.runtime = {
     18   /** @type {chrome.Event} */
     19   onLaunched: null
     20 };
     21 
     22 
     23 /** @type {Object} */
     24 chrome.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} */
     39 chrome.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  */
     52 chrome.runtime.connectNative = function(name) {};
     53 
     54 /**
     55  * @param {string} extensionId
     56  * @param {*} message
     57  * @param {Object=} opt_options
     58  * @param {function(*)=} opt_callback
     59  */
     60 chrome.runtime.sendMessage = function(
     61     extensionId, message, opt_options, opt_callback) {};
     62 
     63 /** @type {Object} */
     64 chrome.extension = {};
     65 
     66 /** @constructor */
     67 chrome.extension.Port = function() {};
     68 
     69 /** @type {chrome.Event} */
     70 chrome.extension.Port.prototype.onMessage;
     71 
     72 /** @type {chrome.Event} */
     73 chrome.extension.Port.prototype.onDisconnect;
     74 
     75 /**
     76  * @param {Object} message
     77  */
     78 chrome.extension.Port.prototype.postMessage = function(message) {};
     79 
     80 /**
     81  * @param {*} message
     82  */
     83 chrome.extension.sendMessage = function(message) {}
     84 
     85 /** @type {chrome.Event} */
     86 chrome.extension.onMessage;
     87 
     88 
     89 /** @type {Object} */
     90 chrome.i18n = {};
     91 
     92 /**
     93  * @param {string} messageName
     94  * @param {(string|Array.<string>)=} opt_args
     95  * @return {string}
     96  */
     97 chrome.i18n.getMessage = function(messageName, opt_args) {};
     98 
     99 
    100 /** @type {Object} */
    101 chrome.storage = {};
    102 
    103 /** @type {chrome.Storage} */
    104 chrome.storage.local;
    105 
    106 /** @type {chrome.Storage} */
    107 chrome.storage.sync;
    108 
    109 /** @constructor */
    110 chrome.Storage = function() {};
    111 
    112 /**
    113  * @param {string|Array.<string>|Object.<string>} items
    114  * @param {function(Object.<string>):void} callback
    115  * @return {void}
    116  */
    117 chrome.Storage.prototype.get = function(items, callback) {};
    118 
    119 /**
    120  * @param {Object.<string>} items
    121  * @param {function():void=} opt_callback
    122  * @return {void}
    123  */
    124 chrome.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  */
    131 chrome.Storage.prototype.remove = function(items, opt_callback) {};
    132 
    133 /**
    134  * @param {function():void=} opt_callback
    135  * @return {void}
    136  */
    137 chrome.Storage.prototype.clear = function(opt_callback) {};
    138 
    139 
    140 /**
    141  * @type {Object}
    142  * src/chrome/common/extensions/api/context_menus.json
    143  */
    144 chrome.contextMenus = {};
    145 /** @type {ChromeEvent} */
    146 chrome.contextMenus.onClicked;
    147 /**
    148  * @param {!Object} createProperties
    149  * @param {function()=} opt_callback
    150  */
    151 chrome.contextMenus.create = function(createProperties, opt_callback) {};
    152 /**
    153  * @param {string|number} id
    154  * @param {!Object} updateProperties
    155  * @param {function()=} opt_callback
    156  */
    157 chrome.contextMenus.update = function(id, updateProperties, opt_callback) {};
    158 /**
    159  * @param {string|number} menuItemId
    160  * @param {function()=} opt_callback
    161  */
    162 chrome.contextMenus.remove = function(menuItemId, opt_callback) {};
    163 /**
    164  * @param {function()=} opt_callback
    165  */
    166 chrome.contextMenus.removeAll = function(opt_callback) {};
    167 
    168 /** @constructor */
    169 function OnClickData() {}
    170 /** @type {string|number} */
    171 OnClickData.prototype.menuItemId;
    172 /** @type {string|number} */
    173 OnClickData.prototype.parentMenuItemId;
    174 /** @type {string} */
    175 OnClickData.prototype.mediaType;
    176 /** @type {string} */
    177 OnClickData.prototype.linkUrl;
    178 /** @type {string} */
    179 OnClickData.prototype.srcUrl;
    180 /** @type {string} */
    181 OnClickData.prototype.pageUrl;
    182 /** @type {string} */
    183 OnClickData.prototype.frameUrl;
    184 /** @type {string} */
    185 OnClickData.prototype.selectionText;
    186 /** @type {boolean} */
    187 OnClickData.prototype.editable;
    188 /** @type {boolean} */
    189 OnClickData.prototype.wasChecked;
    190 /** @type {boolean} */
    191 OnClickData.prototype.checked;
    192 
    193 
    194 /** @type {Object} */
    195 chrome.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 */
    215 function ChromeEvent() {}
    216 /** @param {Function} callback */
    217 ChromeEvent.prototype.addListener = function(callback) {};
    218 /** @param {Function} callback */
    219 ChromeEvent.prototype.removeListener = function(callback) {};
    220 /** @param {Function} callback */
    221 ChromeEvent.prototype.hasListener = function(callback) {};
    222 /** @param {Function} callback */
    223 ChromeEvent.prototype.hasListeners = function(callback) {};
    224 
    225 /** @constructor */
    226 chrome.Event = function() {};
    227 
    228 /** @param {function():void} callback */
    229 chrome.Event.prototype.addListener = function(callback) {};
    230 
    231 /** @param {function():void} callback */
    232 chrome.Event.prototype.removeListener = function(callback) {};
    233 
    234 
    235 /** @type {Object} */
    236 chrome.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} */
    251 chrome.tabs;
    252 
    253 /** @param {function(chrome.Tab):void} callback */
    254 chrome.tabs.getCurrent = function(callback) {}
    255 
    256 /** @constructor */
    257 chrome.Tab = function() {
    258   /** @type {boolean} */
    259   this.pinned = false;
    260   /** @type {number} */
    261   this.windowId = 0;
    262 };
    263 
    264 
    265 /** @type {Object} */
    266 chrome.windows;
    267 
    268 /** @param {number} id
    269  *  @param {Object?} getInfo
    270  *  @param {function(chrome.Window):void} callback */
    271 chrome.windows.get = function(id, getInfo, callback) {}
    272 
    273 /** @constructor */
    274 chrome.Window = function() {
    275   /** @type {string} */
    276   this.state = '';
    277   /** @type {string} */
    278   this.type = '';
    279 };
    280 
    281 /** @constructor */
    282 var 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 
    293 AppWindow.prototype.close = function() {};
    294 AppWindow.prototype.drawAttention = function() {};
    295 AppWindow.prototype.maximize = function() {};
    296 AppWindow.prototype.minimize = function() {};
    297 AppWindow.prototype.restore = function() {};
    298 AppWindow.prototype.fullscreen = function() {};
    299 /** @return {boolean} */
    300 AppWindow.prototype.isFullscreen = function() {};
    301 /** @return {boolean} */
    302 AppWindow.prototype.isMaximized = function() {};
    303 
    304 /**
    305  * @param {{rects: Array.<ClientRect>}} rects
    306  */
    307 AppWindow.prototype.setShape = function(rects) {};
    308 
    309 /**
    310  * @param {{rects: Array.<ClientRect>}} rects
    311  */
    312 AppWindow.prototype.setInputRegion = function(rects) {};
    313 
    314 /** @constructor */
    315 var LaunchData = function() {
    316   /** @type {string} */
    317   this.id = '';
    318   /** @type {Array.<{type: string, entry: FileEntry}>} */
    319   this.items = [];
    320 };
    321 
    322 /** @constructor */
    323 function 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