|
1 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
2 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
4 |
|
5 let Ci = Components.interfaces; |
|
6 let Cc = Components.classes; |
|
7 |
|
8 Components.utils.import("resource://gre/modules/Services.jsm"); |
|
9 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); |
|
10 |
|
11 let unsafeAboutModule = { |
|
12 QueryInterface: XPCOMUtils.generateQI([Ci.nsIAboutModule]), |
|
13 newChannel: function (aURI) { |
|
14 let chan = Services.io.newChannel("about:blank", null, null); |
|
15 chan.owner = Services.scriptSecurityManager.getSystemPrincipal(); |
|
16 return chan; |
|
17 }, |
|
18 getURIFlags: function (aURI) { |
|
19 return Ci.nsIAboutModule.URI_SAFE_FOR_UNTRUSTED_CONTENT; |
|
20 } |
|
21 }; |
|
22 |
|
23 let factory = { |
|
24 createInstance: function(aOuter, aIID) { |
|
25 if (aOuter) |
|
26 throw Components.results.NS_ERROR_NO_AGGREGATION; |
|
27 return unsafeAboutModule.QueryInterface(aIID); |
|
28 }, |
|
29 lockFactory: function(aLock) { |
|
30 throw Components.results.NS_ERROR_NOT_IMPLEMENTED; |
|
31 }, |
|
32 QueryInterface: XPCOMUtils.generateQI([Ci.nsIFactory]) |
|
33 }; |
|
34 |
|
35 function run_test() { |
|
36 let registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar); |
|
37 let classID = Cc["@mozilla.org/uuid-generator;1"].getService(Ci.nsIUUIDGenerator).generateUUID(); |
|
38 registrar.registerFactory(classID, "", "@mozilla.org/network/protocol/about;1?what=unsafe", factory); |
|
39 |
|
40 let aboutUnsafeURI = Services.io.newURI("about:unsafe", null, null); |
|
41 let aboutUnsafeChan = Services.io.newChannelFromURI(aboutUnsafeURI); |
|
42 do_check_null(aboutUnsafeChan.owner, "URI_SAFE_FOR_UNTRUSTED_CONTENT channel has no owner"); |
|
43 |
|
44 registrar.unregisterFactory(classID, factory); |
|
45 } |