OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // This script contains unprivileged javascript APIs related to chrome | 5 // This script contains unprivileged javascript APIs related to chrome |
6 // extensions. It is loaded by any extension-related context, such as content | 6 // extensions. It is loaded by any extension-related context, such as content |
7 // scripts or toolstrips. | 7 // scripts or toolstrips. |
8 // See user_script_slave.cc for script that is loaded by content scripts only. | 8 // See user_script_slave.cc for script that is loaded by content scripts only. |
9 // TODO(mpcomplete): we also load this in regular web pages, but don't need to. | 9 // TODO(mpcomplete): we also load this in regular web pages, but don't need to. |
10 | 10 |
(...skipping 28 matching lines...) Expand all Loading... |
39 // which messages can be passed. | 39 // which messages can be passed. |
40 chrome.Port = function(portId, opt_name) { | 40 chrome.Port = function(portId, opt_name) { |
41 this.portId_ = portId; | 41 this.portId_ = portId; |
42 this.name = opt_name; | 42 this.name = opt_name; |
43 this.onDisconnect = new chrome.Event(); | 43 this.onDisconnect = new chrome.Event(); |
44 this.onMessage = new chrome.Event(); | 44 this.onMessage = new chrome.Event(); |
45 }; | 45 }; |
46 | 46 |
47 chromeHidden.Port = {}; | 47 chromeHidden.Port = {}; |
48 | 48 |
| 49 // Returns true if the specified port id is in this context. This is used by |
| 50 // the C++ to avoid creating the javascript message for all the contexts that |
| 51 // don't care about a particular message. |
| 52 chromeHidden.Port.hasPort = function(portId) { |
| 53 return portId in ports; |
| 54 }; |
| 55 |
49 // Hidden port creation function. We don't want to expose an API that lets | 56 // Hidden port creation function. We don't want to expose an API that lets |
50 // people add arbitrary port IDs to the port list. | 57 // people add arbitrary port IDs to the port list. |
51 chromeHidden.Port.createPort = function(portId, opt_name) { | 58 chromeHidden.Port.createPort = function(portId, opt_name) { |
52 if (ports[portId]) { | 59 if (ports[portId]) { |
53 throw new Error("Port '" + portId + "' already exists."); | 60 throw new Error("Port '" + portId + "' already exists."); |
54 } | 61 } |
55 var port = new chrome.Port(portId, opt_name); | 62 var port = new chrome.Port(portId, opt_name); |
56 ports[portId] = port; | 63 ports[portId] = port; |
57 portReleasers[portId] = PortRelease.bind(this, portId); | 64 portReleasers[portId] = PortRelease.bind(this, portId); |
58 chromeHidden.onUnload.addListener(portReleasers[portId]); | 65 chromeHidden.onUnload.addListener(portReleasers[portId]); |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 "extension.onRequestExternal", | 360 "extension.onRequestExternal", |
354 "extension.setUpdateUrlData", | 361 "extension.setUpdateUrlData", |
355 "i18n.getAcceptLanguages" | 362 "i18n.getAcceptLanguages" |
356 ]; | 363 ]; |
357 for (var i = 0; i < privileged.length; i++) { | 364 for (var i = 0; i < privileged.length; i++) { |
358 createStub(privileged[i]); | 365 createStub(privileged[i]); |
359 } | 366 } |
360 } | 367 } |
361 | 368 |
362 })(); | 369 })(); |
OLD | NEW |