| 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 // This script contains unprivileged javascript APIs related to chrome | 10 // This script contains unprivileged javascript APIs related to chrome |
| 11 // extensions. It is loaded by any extension-related context, such as content | 11 // extensions. It is loaded by any extension-related context, such as content |
| 12 // scripts or toolstrips. | 12 // scripts or toolstrips. |
| 13 // See user_script_slave.cc for script that is loaded by content scripts only. | 13 // See user_script_slave.cc for script that is loaded by content scripts only. |
| 14 // TODO(mpcomplete): we also load this in regular web pages, but don't need | 14 // TODO(mpcomplete): we also load this in regular web pages, but don't need |
| 15 // to. | 15 // to. |
| 16 | 16 |
| 17 var chrome = chrome || {}; | 17 var chrome = chrome || {}; |
| 18 (function () { | 18 (function () { |
| 19 native function OpenChannelToExtension(id); | 19 native function OpenChannelToExtension(id, name); |
| 20 native function CloseChannel(portId); | 20 native function CloseChannel(portId); |
| 21 native function PortAddRef(portId); | 21 native function PortAddRef(portId); |
| 22 native function PortRelease(portId); | 22 native function PortRelease(portId); |
| 23 native function PostMessage(portId, msg); | 23 native function PostMessage(portId, msg); |
| 24 native function GetChromeHidden(); | 24 native function GetChromeHidden(); |
| 25 | 25 |
| 26 var chromeHidden = GetChromeHidden(); | 26 var chromeHidden = GetChromeHidden(); |
| 27 | 27 |
| 28 // Map of port IDs to port object. | 28 // Map of port IDs to port object. |
| 29 var ports = {}; | 29 var ports = {}; |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 } | 108 } |
| 109 | 109 |
| 110 // Extension object. | 110 // Extension object. |
| 111 chrome.Extension = function(id) { | 111 chrome.Extension = function(id) { |
| 112 this.id_ = id; | 112 this.id_ = id; |
| 113 this.onConnect = new chrome.Event('channel-connect:' + id); | 113 this.onConnect = new chrome.Event('channel-connect:' + id); |
| 114 }; | 114 }; |
| 115 | 115 |
| 116 // Opens a message channel to the extension. Returns a Port for | 116 // Opens a message channel to the extension. Returns a Port for |
| 117 // message passing. | 117 // message passing. |
| 118 chrome.Extension.prototype.connect = function(opt_name) { | 118 chrome.Extension.prototype.connect = function(connectInfo) { |
| 119 var portId = OpenChannelToExtension(this.id_, opt_name || ""); | 119 var name = ""; |
| 120 if (connectInfo) { |
| 121 name = connectInfo.name || name; |
| 122 } |
| 123 var portId = OpenChannelToExtension(this.id_, name); |
| 120 if (portId == -1) | 124 if (portId == -1) |
| 121 throw new Error("No such extension: '" + this.id_ + "'"); | 125 throw new Error("No such extension: '" + this.id_ + "'"); |
| 122 return chromeHidden.Port.createPort(portId, opt_name); | 126 return chromeHidden.Port.createPort(portId, name); |
| 123 }; | 127 }; |
| 124 | 128 |
| 125 // Returns a resource URL that can be used to fetch a resource from this | 129 // Returns a resource URL that can be used to fetch a resource from this |
| 126 // extension. | 130 // extension. |
| 127 chrome.Extension.prototype.getURL = function(path) { | 131 chrome.Extension.prototype.getURL = function(path) { |
| 128 return "chrome-extension://" + this.id_ + "/" + path; | 132 return "chrome-extension://" + this.id_ + "/" + path; |
| 129 }; | 133 }; |
| 130 | 134 |
| 131 chrome.self = chrome.self || {}; | 135 chrome.self = chrome.self || {}; |
| 132 })(); | 136 })(); |
| OLD | NEW |