| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 // ----------------------------------------------------------------------------- | 5 // ----------------------------------------------------------------------------- |
| 6 // NOTE: If you change this file you need to touch renderer_resources.grd to | 6 // NOTE: If you change this file you need to touch renderer_resources.grd to |
| 7 // have your change take effect. | 7 // have your change take effect. |
| 8 // ----------------------------------------------------------------------------- | 8 // ----------------------------------------------------------------------------- |
| 9 | 9 |
| 10 var chrome = chrome || {}; | 10 var chrome = chrome || {}; |
| 11 (function () { | 11 (function () { |
| 12 native function OpenChannelToExtension(id); | 12 native function OpenChannelToExtension(id); |
| 13 native function CloseChannel(portId); |
| 13 native function PostMessage(portId, msg); | 14 native function PostMessage(portId, msg); |
| 14 native function GetChromeHidden(); | 15 native function GetChromeHidden(); |
| 15 | 16 |
| 16 var chromeHidden = GetChromeHidden(); | 17 var chromeHidden = GetChromeHidden(); |
| 17 | 18 |
| 18 // Map of port IDs to port object. | 19 // Map of port IDs to port object. |
| 19 var ports = {}; | 20 var ports = {}; |
| 20 | 21 |
| 21 // Port object. Represents a connection to another script context through | 22 // Port object. Represents a connection to another script context through |
| 22 // which messages can be passed. | 23 // which messages can be passed. |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 chrome.Port.prototype.postMessage = function(msg) { | 72 chrome.Port.prototype.postMessage = function(msg) { |
| 72 // JSON.stringify doesn't support a root object which is undefined. | 73 // JSON.stringify doesn't support a root object which is undefined. |
| 73 if (msg === undefined) | 74 if (msg === undefined) |
| 74 msg = null; | 75 msg = null; |
| 75 PostMessage(this.portId_, JSON.stringify(msg)); | 76 PostMessage(this.portId_, JSON.stringify(msg)); |
| 76 }; | 77 }; |
| 77 | 78 |
| 78 // Disconnects the port from the other end. | 79 // Disconnects the port from the other end. |
| 79 chrome.Port.prototype.disconnect = function() { | 80 chrome.Port.prototype.disconnect = function() { |
| 80 delete ports[this.portId_]; | 81 delete ports[this.portId_]; |
| 81 //CloseChannel(this.portId_); // TODO(mpcomplete) | 82 CloseChannel(this.portId_); |
| 82 } | 83 } |
| 83 | 84 |
| 84 // Extension object. | 85 // Extension object. |
| 85 chrome.Extension = function(id) { | 86 chrome.Extension = function(id) { |
| 86 this.id_ = id; | 87 this.id_ = id; |
| 87 }; | 88 }; |
| 88 | 89 |
| 89 // Opens a message channel to the extension. Returns a Port for | 90 // Opens a message channel to the extension. Returns a Port for |
| 90 // message passing. | 91 // message passing. |
| 91 chrome.Extension.prototype.connect = function() { | 92 chrome.Extension.prototype.connect = function() { |
| 92 var portId = OpenChannelToExtension(this.id_); | 93 var portId = OpenChannelToExtension(this.id_); |
| 93 if (portId == -1) | 94 if (portId == -1) |
| 94 throw new Error("No such extension: '" + this.id_ + "'"); | 95 throw new Error("No such extension: '" + this.id_ + "'"); |
| 95 return new chrome.Port(portId); | 96 return new chrome.Port(portId); |
| 96 }; | 97 }; |
| 97 | 98 |
| 98 // Returns a resource URL that can be used to fetch a resource from this | 99 // Returns a resource URL that can be used to fetch a resource from this |
| 99 // extension. | 100 // extension. |
| 100 chrome.Extension.prototype.getURL = function(path) { | 101 chrome.Extension.prototype.getURL = function(path) { |
| 101 return "chrome-extension://" + this.id_ + "/" + path; | 102 return "chrome-extension://" + this.id_ + "/" + path; |
| 102 }; | 103 }; |
| 103 })(); | 104 })(); |
| OLD | NEW |