Sat, 03 Jan 2015 20:18:00 +0100
Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.
michael@0 | 1 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 2 | http://creativecommons.org/publicdomain/zero/1.0/ */ |
michael@0 | 3 | |
michael@0 | 4 | const Cc = Components.classes; |
michael@0 | 5 | const Ci = Components.interfaces; |
michael@0 | 6 | const Cu = Components.utils; |
michael@0 | 7 | |
michael@0 | 8 | const { DebuggerServer } = Cu.import("resource://gre/modules/devtools/dbg-server.jsm"); |
michael@0 | 9 | const { DebuggerClient } = Cu.import("resource://gre/modules/devtools/dbg-client.jsm"); |
michael@0 | 10 | |
michael@0 | 11 | const { FileUtils } = Cu.import("resource://gre/modules/FileUtils.jsm"); |
michael@0 | 12 | const { Services } = Cu.import("resource://gre/modules/Services.jsm"); |
michael@0 | 13 | |
michael@0 | 14 | let gClient, gActor; |
michael@0 | 15 | |
michael@0 | 16 | function connect(onDone) { |
michael@0 | 17 | |
michael@0 | 18 | if (Services.appinfo.name == "B2G") { |
michael@0 | 19 | // On b2g, we try to exercice the code that launches the production debugger server |
michael@0 | 20 | let settingsService = Cc["@mozilla.org/settingsService;1"].getService(Ci.nsISettingsService); |
michael@0 | 21 | settingsService.createLock().set("devtools.debugger.remote-enabled", true, null); |
michael@0 | 22 | // We can't use `set` callback as it is fired before shell.js code listening for this setting |
michael@0 | 23 | // is actually called. Same thing applies to mozsettings-changed obs notification. |
michael@0 | 24 | // So listen to a custom event until bug 942756 lands |
michael@0 | 25 | let observer = { |
michael@0 | 26 | observe: function (subject, topic, data) { |
michael@0 | 27 | Services.obs.removeObserver(observer, "debugger-server-started"); |
michael@0 | 28 | let transport = debuggerSocketConnect("127.0.0.1", 6000); |
michael@0 | 29 | startClient(transport, onDone); |
michael@0 | 30 | } |
michael@0 | 31 | }; |
michael@0 | 32 | Services.obs.addObserver(observer, "debugger-server-started", false); |
michael@0 | 33 | } else { |
michael@0 | 34 | // Initialize a loopback remote protocol connection |
michael@0 | 35 | DebuggerServer.init(function () { return true; }); |
michael@0 | 36 | // We need to register browser actors to have `listTabs` working |
michael@0 | 37 | // and also have a root actor |
michael@0 | 38 | DebuggerServer.addBrowserActors(); |
michael@0 | 39 | let transport = DebuggerServer.connectPipe(); |
michael@0 | 40 | startClient(transport, onDone); |
michael@0 | 41 | } |
michael@0 | 42 | } |
michael@0 | 43 | |
michael@0 | 44 | function startClient(transport, onDone) { |
michael@0 | 45 | // Setup client and actor used in all tests |
michael@0 | 46 | gClient = new DebuggerClient(transport); |
michael@0 | 47 | gClient.connect(function onConnect() { |
michael@0 | 48 | gClient.listTabs(function onListTabs(aResponse) { |
michael@0 | 49 | gActor = aResponse.webappsActor; |
michael@0 | 50 | if (gActor) |
michael@0 | 51 | webappActorRequest({type: "watchApps"}, onDone); |
michael@0 | 52 | }); |
michael@0 | 53 | }); |
michael@0 | 54 | |
michael@0 | 55 | gClient.addListener("appInstall", function (aState, aType, aPacket) { |
michael@0 | 56 | sendAsyncMessage("installed-event", { manifestURL: aType.manifestURL }); |
michael@0 | 57 | }); |
michael@0 | 58 | |
michael@0 | 59 | gClient.addListener("appUninstall", function (aState, aType, aPacket) { |
michael@0 | 60 | sendAsyncMessage("uninstalled-event", { manifestURL: aType.manifestURL }); |
michael@0 | 61 | }); |
michael@0 | 62 | |
michael@0 | 63 | addMessageListener("appActorRequest", request => { |
michael@0 | 64 | webappActorRequest(request, response => { |
michael@0 | 65 | sendAsyncMessage("appActorResponse", response); |
michael@0 | 66 | }); |
michael@0 | 67 | }); |
michael@0 | 68 | } |
michael@0 | 69 | |
michael@0 | 70 | function webappActorRequest(request, onResponse) { |
michael@0 | 71 | if (!gActor) { |
michael@0 | 72 | connect(webappActorRequest.bind(null, request, onResponse)); |
michael@0 | 73 | return; |
michael@0 | 74 | } |
michael@0 | 75 | |
michael@0 | 76 | request.to = gActor; |
michael@0 | 77 | gClient.request(request, onResponse); |
michael@0 | 78 | } |
michael@0 | 79 | |
michael@0 | 80 | |
michael@0 | 81 | function downloadURL(url, file) { |
michael@0 | 82 | let channel = Services.io.newChannel(url, null, null); |
michael@0 | 83 | let istream = channel.open(); |
michael@0 | 84 | let bstream = Cc["@mozilla.org/binaryinputstream;1"] |
michael@0 | 85 | .createInstance(Ci.nsIBinaryInputStream); |
michael@0 | 86 | bstream.setInputStream(istream); |
michael@0 | 87 | let data = bstream.readBytes(bstream.available()); |
michael@0 | 88 | |
michael@0 | 89 | let ostream = Cc["@mozilla.org/network/safe-file-output-stream;1"] |
michael@0 | 90 | .createInstance(Ci.nsIFileOutputStream); |
michael@0 | 91 | ostream.init(file, 0x04 | 0x08 | 0x20, 0600, 0); |
michael@0 | 92 | ostream.write(data, data.length); |
michael@0 | 93 | ostream.QueryInterface(Ci.nsISafeOutputStream).finish(); |
michael@0 | 94 | } |
michael@0 | 95 | |
michael@0 | 96 | // Install a test packaged webapp from data folder |
michael@0 | 97 | addMessageListener("install", function (aMessage) { |
michael@0 | 98 | let url = aMessage.url; |
michael@0 | 99 | let appId = aMessage.appId; |
michael@0 | 100 | |
michael@0 | 101 | try { |
michael@0 | 102 | // Download its content from mochitest http server |
michael@0 | 103 | // Copy our package to tmp folder, where the actor retrieves it |
michael@0 | 104 | let zip = FileUtils.getDir("TmpD", ["b2g", appId], true, true); |
michael@0 | 105 | zip.append("application.zip"); |
michael@0 | 106 | downloadURL(url, zip); |
michael@0 | 107 | |
michael@0 | 108 | let request = {type: "install", appId: appId}; |
michael@0 | 109 | webappActorRequest(request, function (aResponse) { |
michael@0 | 110 | sendAsyncMessage("installed", aResponse); |
michael@0 | 111 | }); |
michael@0 | 112 | } catch(e) { |
michael@0 | 113 | dump("installTestApp exception: " + e + "\n"); |
michael@0 | 114 | } |
michael@0 | 115 | }); |
michael@0 | 116 | |
michael@0 | 117 | addMessageListener("cleanup", function () { |
michael@0 | 118 | webappActorRequest({type: "unwatchApps"}, function () { |
michael@0 | 119 | gClient.close(); |
michael@0 | 120 | }); |
michael@0 | 121 | }); |
michael@0 | 122 |