dom/phonenumberutils/PhoneNumberService.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

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 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
michael@0 3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 "use strict";
michael@0 6
michael@0 7 const DEBUG = false;
michael@0 8 function debug(s) { dump("-*- PhoneNumberService.js: " + s + "\n"); }
michael@0 9
michael@0 10 const Cc = Components.classes;
michael@0 11 const Ci = Components.interfaces;
michael@0 12 const Cu = Components.utils;
michael@0 13
michael@0 14 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
michael@0 15 Cu.import("resource://gre/modules/Services.jsm");
michael@0 16 Cu.import("resource://gre/modules/DOMRequestHelper.jsm");
michael@0 17 Cu.import("resource://gre/modules/PhoneNumberUtils.jsm");
michael@0 18 Cu.import("resource://gre/modules/PhoneNumberNormalizer.jsm");
michael@0 19
michael@0 20 XPCOMUtils.defineLazyServiceGetter(this, "cpmm",
michael@0 21 "@mozilla.org/childprocessmessagemanager;1",
michael@0 22 "nsIMessageSender");
michael@0 23
michael@0 24 // PhoneNumberService
michael@0 25
michael@0 26 function PhoneNumberService()
michael@0 27 {
michael@0 28 if (DEBUG) debug("Constructor");
michael@0 29 }
michael@0 30
michael@0 31 PhoneNumberService.prototype = {
michael@0 32 __proto__: DOMRequestIpcHelper.prototype,
michael@0 33
michael@0 34 receiveMessage: function(aMessage) {
michael@0 35 if (DEBUG) debug("receiveMessage: " + aMessage.name);
michael@0 36 let msg = aMessage.json;
michael@0 37
michael@0 38 let req = this.getRequest(msg.requestID);
michael@0 39 if (!req) {
michael@0 40 return;
michael@0 41 }
michael@0 42
michael@0 43 switch (aMessage.name) {
michael@0 44 case "PhoneNumberService:FuzzyMatch:Return:KO":
michael@0 45 Services.DOMRequest.fireError(req.request, msg.errorMsg);
michael@0 46 break;
michael@0 47 case "PhoneNumberService:FuzzyMatch:Return:OK":
michael@0 48 Services.DOMRequest.fireSuccess(req.request, msg.result);
michael@0 49 break;
michael@0 50 default:
michael@0 51 if (DEBUG) debug("Wrong message: " + aMessage.name);
michael@0 52 }
michael@0 53 this.removeRequest(msg.requestID);
michael@0 54 },
michael@0 55
michael@0 56 fuzzyMatch: function(aNumber1, aNumber2) {
michael@0 57 if (DEBUG) debug("fuzzyMatch: " + aNumber1 + ", " + aNumber2);
michael@0 58 let request = this.createRequest();
michael@0 59
michael@0 60 if ((aNumber1 && !aNumber2) || (aNumber2 && !aNumber1)) {
michael@0 61 // if only one of the numbers is empty/null/undefined and the other
michael@0 62 // number is not, we can fire false result in next tick
michael@0 63 Services.DOMRequest.fireSuccessAsync(request, false);
michael@0 64 } else if ((aNumber1 === aNumber2) ||
michael@0 65 (PhoneNumberNormalizer.Normalize(aNumber1) === PhoneNumberNormalizer.Normalize(aNumber2))) {
michael@0 66 // if we have a simple match fire successful request in next tick
michael@0 67 Services.DOMRequest.fireSuccessAsync(request, true);
michael@0 68 } else {
michael@0 69 // invoke fuzzy matching in the parent
michael@0 70 let options = { number1: aNumber1, number2: aNumber2 };
michael@0 71 cpmm.sendAsyncMessage("PhoneNumberService:FuzzyMatch",
michael@0 72 {requestID: this.getRequestId({request: request}),
michael@0 73 options: options});
michael@0 74 }
michael@0 75
michael@0 76 return request;
michael@0 77 },
michael@0 78
michael@0 79 normalize: function(aNumber) {
michael@0 80 if (DEBUG) debug("normalize: " + aNumber);
michael@0 81 return PhoneNumberNormalizer.Normalize(aNumber);
michael@0 82 },
michael@0 83
michael@0 84 init: function(aWindow) {
michael@0 85 if (DEBUG) debug("init call");
michael@0 86 this.initDOMRequestHelper(aWindow, [
michael@0 87 "PhoneNumberService:FuzzyMatch:Return:OK",
michael@0 88 "PhoneNumberService:FuzzyMatch:Return:KO"
michael@0 89 ]);
michael@0 90 },
michael@0 91
michael@0 92 classID : Components.ID("{e2768710-eb17-11e2-91e2-0800200c9a66}"),
michael@0 93 contractID : "@mozilla.org/phoneNumberService;1",
michael@0 94 QueryInterface : XPCOMUtils.generateQI([Ci.nsIDOMGlobalPropertyInitializer,
michael@0 95 Ci.nsISupportsWeakReference,
michael@0 96 Ci.nsIObserver]),
michael@0 97 }
michael@0 98
michael@0 99 this.NSGetFactory = XPCOMUtils.generateNSGetFactory([PhoneNumberService]);

mercurial