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/** @constructor */
13chrome.Event = function() {};
14
15/** @param {Function} callback */
16chrome.Event.prototype.addListener = function(callback) {};
17
18/** @param {Function} callback */
19chrome.Event.prototype.removeListener = function(callback) {};
20
21/** @type {Object} */
22chrome.app = {};
23
24/** @type {Object} */
25chrome.app.runtime = {
26  /** @type {chrome.Event} */
27  onLaunched: null
28};
29
30
31/** @type {Object} */
32chrome.app.window = {
33  /**
34   * @param {string} name
35   * @param {Object} parameters
36   * @param {function()=} opt_callback
37   */
38  create: function(name, parameters, opt_callback) {},
39  /**
40   * @return {AppWindow}
41   */
42  current: function() {},
43  /**
44   * @param {string} id
45   * @param {function()=} opt_callback
46   */
47  get: function(id, opt_callback) {}
48};
49
50
51/** @type {Object} */
52chrome.runtime = {
53  /** @type {Object} */
54  lastError: {
55    /** @type {string} */
56    message: ''
57  },
58  /** @return {{version: string, app: {background: Object}}} */
59  getManifest: function() {},
60  /** @type {chrome.Event} */
61  onSuspend: null,
62  /** @type {chrome.Event} */
63  onSuspendCanceled: null,
64  /** @type {chrome.Event} */
65  onConnect: null,
66  /** @type {chrome.Event} */
67  onConnectExternal: null,
68  /** @type {chrome.Event} */
69  onMessage: null,
70  /** @type {chrome.Event} */
71  onMessageExternal: null
72};
73
74/**
75 * @type {?function(string):chrome.runtime.Port}
76 */
77chrome.runtime.connectNative = function(name) {};
78
79/**
80 * @param {{ name: string}} config
81 * @return {chrome.runtime.Port}
82 */
83chrome.runtime.connect = function(config) {};
84
85/**
86 * @param {string} extensionId
87 * @param {*} message
88 * @param {Object=} opt_options
89 * @param {function(*)=} opt_callback
90 */
91chrome.runtime.sendMessage = function(
92    extensionId, message, opt_options, opt_callback) {};
93
94/** @constructor */
95chrome.runtime.MessageSender = function(){
96  /** @type {chrome.Tab} */
97  this.tab = null;
98};
99
100/** @constructor */
101chrome.runtime.Port = function() {
102  this.onMessage = new chrome.Event();
103  this.onDisconnect = new chrome.Event();
104
105  /** @type {string} */
106  this.name = '';
107
108  /** @type {chrome.runtime.MessageSender} */
109  this.sender = null;
110};
111
112/** @type {chrome.Event} */
113chrome.runtime.Port.prototype.onMessage = null;
114
115/** @type {chrome.Event} */
116chrome.runtime.Port.prototype.onDisconnect = null;
117
118chrome.runtime.Port.prototype.disconnect = function() {};
119
120/**
121 * @param {Object} message
122 */
123chrome.runtime.Port.prototype.postMessage = function(message) {};
124
125
126/** @type {Object} */
127chrome.extension = {};
128
129/**
130 * @param {*} message
131 */
132chrome.extension.sendMessage = function(message) {}
133
134/** @type {chrome.Event} */
135chrome.extension.onMessage;
136
137
138/** @type {Object} */
139chrome.i18n = {};
140
141/**
142 * @param {string} messageName
143 * @param {(string|Array.<string>)=} opt_args
144 * @return {string}
145 */
146chrome.i18n.getMessage = function(messageName, opt_args) {};
147
148
149/** @type {Object} */
150chrome.storage = {};
151
152/** @type {chrome.Storage} */
153chrome.storage.local;
154
155/** @type {chrome.Storage} */
156chrome.storage.sync;
157
158/** @constructor */
159chrome.Storage = function() {};
160
161/**
162 * @param {string|Array.<string>|Object.<string>} items
163 * @param {function(Object.<string>):void} callback
164 * @return {void}
165 */
166chrome.Storage.prototype.get = function(items, callback) {};
167
168/**
169 * @param {Object.<string>} items
170 * @param {function():void=} opt_callback
171 * @return {void}
172 */
173chrome.Storage.prototype.set = function(items, opt_callback) {};
174
175/**
176 * @param {string|Array.<string>} items
177 * @param {function():void=} opt_callback
178 * @return {void}
179 */
180chrome.Storage.prototype.remove = function(items, opt_callback) {};
181
182/**
183 * @param {function():void=} opt_callback
184 * @return {void}
185 */
186chrome.Storage.prototype.clear = function(opt_callback) {};
187
188
189/**
190 * @type {Object}
191 * src/chrome/common/extensions/api/context_menus.json
192 */
193chrome.contextMenus = {};
194/** @type {chrome.Event} */
195chrome.contextMenus.onClicked;
196/**
197 * @param {!Object} createProperties
198 * @param {function()=} opt_callback
199 */
200chrome.contextMenus.create = function(createProperties, opt_callback) {};
201/**
202 * @param {string|number} id
203 * @param {!Object} updateProperties
204 * @param {function()=} opt_callback
205 */
206chrome.contextMenus.update = function(id, updateProperties, opt_callback) {};
207/**
208 * @param {string|number} menuItemId
209 * @param {function()=} opt_callback
210 */
211chrome.contextMenus.remove = function(menuItemId, opt_callback) {};
212/**
213 * @param {function()=} opt_callback
214 */
215chrome.contextMenus.removeAll = function(opt_callback) {};
216
217/** @constructor */
218function OnClickData() {}
219/** @type {string|number} */
220OnClickData.prototype.menuItemId;
221/** @type {string|number} */
222OnClickData.prototype.parentMenuItemId;
223/** @type {string} */
224OnClickData.prototype.mediaType;
225/** @type {string} */
226OnClickData.prototype.linkUrl;
227/** @type {string} */
228OnClickData.prototype.srcUrl;
229/** @type {string} */
230OnClickData.prototype.pageUrl;
231/** @type {string} */
232OnClickData.prototype.frameUrl;
233/** @type {string} */
234OnClickData.prototype.selectionText;
235/** @type {boolean} */
236OnClickData.prototype.editable;
237/** @type {boolean} */
238OnClickData.prototype.wasChecked;
239/** @type {boolean} */
240OnClickData.prototype.checked;
241
242
243/** @type {Object} */
244chrome.fileSystem = {
245  /**
246   * @param {Object.<string>?} options
247   * @param {function(Entry, Array.<FileEntry>):void} callback
248   */
249  chooseEntry: function(options, callback) {},
250  /**
251   * @param {FileEntry} fileEntry
252   * @param {function(string):void} callback
253   */
254  getDisplayPath: function(fileEntry, callback) {}
255};
256
257/** @type {Object} */
258chrome.identity = {
259  /**
260   * @param {Object.<string>} parameters
261   * @param {function(string):void} callback
262   */
263  getAuthToken: function(parameters, callback) {},
264  /**
265   * @param {Object.<string>} parameters
266   * @param {function():void} callback
267   */
268  removeCachedAuthToken: function(parameters, callback) {},
269  /**
270   * @param {Object.<string>} parameters
271   * @param {function(string):void} callback
272   */
273  launchWebAuthFlow: function(parameters, callback) {}
274};
275
276
277/** @type {Object} */
278chrome.permissions = {
279  /**
280   * @param {Object.<string>} permissions
281   * @param {function(boolean):void} callback
282   */
283  contains: function(permissions, callback) {},
284  /**
285   * @param {Object.<string>} permissions
286   * @param {function(boolean):void} callback
287   */
288  request: function(permissions, callback) {}
289};
290
291
292/** @type {Object} */
293chrome.tabs = {};
294
295/** @param {function(chrome.Tab):void} callback */
296chrome.tabs.getCurrent = function(callback) {};
297
298/**
299 * @param {Object?} options
300 * @param {function(chrome.Tab)=} opt_callback
301 */
302chrome.tabs.create = function(options, opt_callback) {};
303
304/**
305 * @param {string} id
306 * @param {function(chrome.Tab)} callback
307 */
308chrome.tabs.get = function(id, callback) {};
309
310/**
311 * @param {string} id
312 * @param {function()=} opt_callback
313 */
314chrome.tabs.remove = function(id, opt_callback) {};
315
316
317/** @constructor */
318chrome.Tab = function() {
319  /** @type {boolean} */
320  this.pinned = false;
321  /** @type {number} */
322  this.windowId = 0;
323  /** @type {string} */
324  this.id = '';
325};
326
327
328/** @type {Object} */
329chrome.windows = {};
330
331/** @param {number} id
332 *  @param {Object?} getInfo
333 *  @param {function(chrome.Window):void} callback */
334chrome.windows.get = function(id, getInfo, callback) {};
335
336/** @constructor */
337chrome.Window = function() {
338  /** @type {string} */
339  this.state = '';
340  /** @type {string} */
341  this.type = '';
342};
343
344/** @constructor */
345var AppWindow = function() {
346  /** @type {Window} */
347  this.contentWindow = null;
348  /** @type {chrome.Event} */
349  this.onClosed = null;
350  /** @type {chrome.Event} */
351  this.onRestored = null;
352  /** @type {chrome.Event} */
353  this.onMaximized = null;
354  /** @type {chrome.Event} */
355  this.onFullscreened = null;
356  /** @type {string} */
357  this.id = '';
358};
359
360AppWindow.prototype.close = function() {};
361AppWindow.prototype.drawAttention = function() {};
362AppWindow.prototype.maximize = function() {};
363AppWindow.prototype.minimize = function() {};
364AppWindow.prototype.restore = function() {};
365AppWindow.prototype.show = function() {};
366AppWindow.prototype.fullscreen = function() {};
367/** @return {boolean} */
368AppWindow.prototype.isFullscreen = function() {};
369/** @return {boolean} */
370AppWindow.prototype.isMaximized = function() {};
371
372/**
373 * @param {{rects: Array.<ClientRect>}} rects
374 */
375AppWindow.prototype.setShape = function(rects) {};
376
377/**
378 * @param {{rects: Array.<ClientRect>}} rects
379 */
380AppWindow.prototype.setInputRegion = function(rects) {};
381
382/** @constructor */
383var LaunchData = function() {
384  /** @type {string} */
385  this.id = '';
386  /** @type {Array.<{type: string, entry: FileEntry}>} */
387  this.items = [];
388};
389
390/** @constructor */
391function ClientRect() {
392  /** @type {number} */
393  this.width = 0;
394  /** @type {number} */
395  this.height = 0;
396  /** @type {number} */
397  this.top = 0;
398  /** @type {number} */
399  this.bottom = 0;
400  /** @type {number} */
401  this.left = 0;
402  /** @type {number} */
403  this.right = 0;
404};
405
406/** @type {Object} */
407chrome.cast = {};
408
409/** @constructor */
410chrome.cast.AutoJoinPolicy = function() {};
411
412/** @type {chrome.cast.AutoJoinPolicy} */
413chrome.cast.AutoJoinPolicy.PAGE_SCOPED;
414
415/** @type {chrome.cast.AutoJoinPolicy} */
416chrome.cast.AutoJoinPolicy.ORIGIN_SCOPED;
417
418/** @type {chrome.cast.AutoJoinPolicy} */
419chrome.cast.AutoJoinPolicy.TAB_AND_ORIGIN_SCOPED;
420
421/** @constructor */
422chrome.cast.DefaultActionPolicy = function() {};
423
424/** @type {chrome.cast.DefaultActionPolicy} */
425chrome.cast.DefaultActionPolicy.CAST_THIS_TAB;
426
427/** @type {chrome.cast.DefaultActionPolicy} */
428chrome.cast.DefaultActionPolicy.CREATE_SESSION;
429
430/** @constructor */
431chrome.cast.Error = function() {};
432
433/** @constructor */
434chrome.cast.ReceiverAvailability = function() {};
435
436/** @type {chrome.cast.ReceiverAvailability} */
437chrome.cast.ReceiverAvailability.AVAILABLE;
438
439/** @type {chrome.cast.ReceiverAvailability} */
440chrome.cast.ReceiverAvailability.UNAVAILABLE;
441
442/** @type {Object} */
443chrome.cast.media = {};
444
445/** @constructor */
446chrome.cast.media.Media = function() {
447  /** @type {number} */
448  this.mediaSessionId = 0;
449};
450
451/** @constructor */
452chrome.cast.Session = function() {
453  /** @type {Array.<chrome.cast.media.Media>} */
454  this.media = [];
455
456  /** @type {string} */
457  this.sessionId = '';
458};
459
460/**
461 * @param {string} namespace
462 * @param {Object} message
463 * @param {function():void} successCallback
464 * @param {function(chrome.cast.Error):void} errorCallback
465 */
466chrome.cast.Session.prototype.sendMessage =
467    function(namespace, message, successCallback, errorCallback) {};
468
469/**
470 * @param {function(chrome.cast.media.Media):void} listener
471 */
472chrome.cast.Session.prototype.addMediaListener = function(listener) {};
473
474/**
475 * @param {function(boolean):void} listener
476 */
477chrome.cast.Session.prototype.addUpdateListener = function(listener) {};
478
479/**
480 * @param {string} namespace
481 * @param {function(chrome.cast.media.Media):void} listener
482 */
483chrome.cast.Session.prototype.addMessageListener =
484    function(namespace, listener){};
485
486/**
487 * @param {function():void} successCallback
488 * @param {function(chrome.cast.Error):void} errorCallback
489 */
490chrome.cast.Session.prototype.stop =
491    function(successCallback, errorCallback) {};
492
493/**
494 * @constructor
495 * @param {string} applicationID
496 */
497chrome.cast.SessionRequest = function(applicationID) {};
498
499/**
500 * @constructor
501 * @param {chrome.cast.SessionRequest} sessionRequest
502 * @param {function(chrome.cast.Session):void} sessionListener
503 * @param {function(chrome.cast.ReceiverAvailability):void} receiverListener
504 * @param {chrome.cast.AutoJoinPolicy=} opt_autoJoinPolicy
505 * @param {chrome.cast.DefaultActionPolicy=} opt_defaultActionPolicy
506 */
507chrome.cast.ApiConfig = function(sessionRequest,
508                                 sessionListener,
509                                 receiverListener,
510                                 opt_autoJoinPolicy,
511                                 opt_defaultActionPolicy) {};
512
513/**
514 * @param {chrome.cast.ApiConfig} apiConfig
515 * @param {function():void} onInitSuccess
516 * @param {function(chrome.cast.Error):void} onInitError
517 */
518chrome.cast.initialize =
519    function(apiConfig, onInitSuccess, onInitError) {};
520
521/**
522 * @param {function(chrome.cast.Session):void} successCallback
523 * @param {function(chrome.cast.Error):void} errorCallback
524 */
525chrome.cast.requestSession =
526    function(successCallback, errorCallback) {};
527
528/** @type {Object} */
529chrome.sockets = {};
530
531/** @type {Object} */
532chrome.sockets.tcp = {};
533
534/** @constructor */
535chrome.sockets.tcp.CreateInfo = function() {
536  /** @type {number} */
537  this.socketId = 0;
538}
539
540/**
541 * @param {Object} properties
542 * @param {function(chrome.sockets.tcp.CreateInfo):void} callback
543 */
544chrome.sockets.tcp.create = function(properties, callback) {};
545
546
547/** @constructor */
548chrome.sockets.tcp.ConnectInfo = function() {
549  /** @type {number} */
550  this.result = 0;
551}
552
553/**
554 * @param {number} socketId
555 * @param {string} peerAddress
556 * @param {number} peerPort
557 * @param {function(chrome.sockets.tcp.ConnectInfo):void} callback
558 */
559chrome.sockets.tcp.connect =
560    function(socketId, peerAddress, peerPort, callback) {};
561
562
563/** @constructor */
564chrome.sockets.tcp.SendInfo = function() {
565  /** @type {number} */
566  this.resultCode = 0;
567
568  /** @type {number} */
569  this.bytesSent = 0;
570}
571
572/**
573 * @param {number} socketId
574 * @param {ArrayBuffer} data
575 * @param {function(chrome.sockets.tcp.SendInfo):void} callback
576 */
577chrome.sockets.tcp.send = function(socketId, data, callback) {};
578
579
580/**
581 * @param {number} socketId
582 */
583chrome.sockets.tcp.close = function(socketId) {};
584
585/**
586 * @param {number} socketId
587 * @param {Object} options
588 * @param {function(number):void} callback
589 */
590chrome.sockets.tcp.secure = function(socketId, options, callback) {};
591
592/** @constructor */
593chrome.sockets.tcp.ReceiveInfo = function() {
594  /** @type {number} */
595  this.socketId = 0;
596
597  /** @type {ArrayBuffer} */
598  this.data = null;
599}
600
601/** @type {chrome.Event} */
602chrome.sockets.tcp.onReceive = null;
603
604/** @constructor */
605chrome.sockets.tcp.ReceiveErrorInfo = function() {
606  /** @type {number} */
607  this.socketId = 0;
608
609  /** @type {number} */
610  this.resultCode = 0;
611}
612
613/** @type {chrome.Event} */
614chrome.sockets.tcp.onReceiveError = null;
615
616/** @type {Object} */
617chrome.socket = {};
618
619/** @constructor */
620chrome.socket.CreateInfo = function() {
621  /** @type {number} */
622  this.socketId = 0;
623}
624
625/**
626 * @param {string} socketType
627 * @param {Object} options
628 * @param {function(chrome.socket.CreateInfo):void} callback
629 */
630chrome.socket.create = function(socketType, options, callback) {};
631
632/**
633 * @param {number} socketId
634 * @param {string} hostname
635 * @param {number} port
636 * @param {function(number):void} callback
637 */
638chrome.socket.connect =
639    function(socketId, hostname, port, callback) {};
640
641/** @constructor */
642chrome.socket.WriteInfo = function() {
643  /** @type {number} */
644  this.bytesWritten = 0;
645}
646
647/**
648 * @param {number} socketId
649 * @param {ArrayBuffer} data
650 * @param {function(chrome.socket.WriteInfo):void} callback
651 */
652chrome.socket.write = function(socketId, data, callback) {};
653
654/** @constructor */
655chrome.socket.ReadInfo = function() {
656  /** @type {number} */
657  this.resultCode = 0;
658
659  /** @type {ArrayBuffer} */
660  this.data = null;
661}
662
663/**
664 * @param {number} socketId
665 * @param {function(chrome.socket.ReadInfo):void} callback
666 */
667chrome.socket.read = function(socketId, callback) {};
668
669/**
670 * @param {number} socketId
671 */
672chrome.socket.destroy = function(socketId) {};
673
674/**
675 * @param {number} socketId
676 * @param {Object} options
677 * @param {function(number):void} callback
678 */
679chrome.socket.secure = function(socketId, options, callback) {};
680