Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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 {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components; |
michael@0 | 8 | |
michael@0 | 9 | Cu.import("resource://gre/modules/XPCOMUtils.jsm"); |
michael@0 | 10 | Cu.import("resource://gre/modules/Services.jsm"); |
michael@0 | 11 | |
michael@0 | 12 | let MMDB = {}; |
michael@0 | 13 | Cu.import("resource://gre/modules/MobileMessageDB.jsm", MMDB); |
michael@0 | 14 | |
michael@0 | 15 | const RIL_MOBILEMESSAGEDATABASESERVICE_CONTRACTID = |
michael@0 | 16 | "@mozilla.org/mobilemessage/rilmobilemessagedatabaseservice;1"; |
michael@0 | 17 | const RIL_MOBILEMESSAGEDATABASESERVICE_CID = |
michael@0 | 18 | Components.ID("{29785f90-6b5b-11e2-9201-3b280170b2ec}"); |
michael@0 | 19 | |
michael@0 | 20 | XPCOMUtils.defineLazyServiceGetter(this, "gDiskSpaceWatcher", |
michael@0 | 21 | "@mozilla.org/toolkit/disk-space-watcher;1", |
michael@0 | 22 | "nsIDiskSpaceWatcher"); |
michael@0 | 23 | |
michael@0 | 24 | const DB_NAME = "sms"; |
michael@0 | 25 | |
michael@0 | 26 | /** |
michael@0 | 27 | * MobileMessageDatabaseService |
michael@0 | 28 | */ |
michael@0 | 29 | function MobileMessageDatabaseService() { |
michael@0 | 30 | // Prime the directory service's cache to ensure that the ProfD entry exists |
michael@0 | 31 | // by the time IndexedDB queries for it off the main thread. (See bug 743635.) |
michael@0 | 32 | Services.dirsvc.get("ProfD", Ci.nsIFile); |
michael@0 | 33 | |
michael@0 | 34 | let mmdb = new MMDB.MobileMessageDB(); |
michael@0 | 35 | mmdb.init(DB_NAME, 0, mmdb.updatePendingTransactionToError.bind(mmdb)); |
michael@0 | 36 | mmdb.isDiskFull = function() { |
michael@0 | 37 | return gDiskSpaceWatcher.isDiskFull; |
michael@0 | 38 | }; |
michael@0 | 39 | this.mmdb = mmdb; |
michael@0 | 40 | } |
michael@0 | 41 | MobileMessageDatabaseService.prototype = { |
michael@0 | 42 | |
michael@0 | 43 | classID: RIL_MOBILEMESSAGEDATABASESERVICE_CID, |
michael@0 | 44 | QueryInterface: XPCOMUtils.generateQI([Ci.nsIRilMobileMessageDatabaseService, |
michael@0 | 45 | Ci.nsIMobileMessageDatabaseService, |
michael@0 | 46 | Ci.nsIObserver]), |
michael@0 | 47 | |
michael@0 | 48 | /** |
michael@0 | 49 | * MobileMessageDB instance. |
michael@0 | 50 | */ |
michael@0 | 51 | mmdb: null, |
michael@0 | 52 | |
michael@0 | 53 | /** |
michael@0 | 54 | * nsIObserver |
michael@0 | 55 | */ |
michael@0 | 56 | observe: function() {}, |
michael@0 | 57 | |
michael@0 | 58 | /** |
michael@0 | 59 | * nsIRilMobileMessageDatabaseService API |
michael@0 | 60 | */ |
michael@0 | 61 | |
michael@0 | 62 | saveReceivedMessage: function(aMessage, aCallback) { |
michael@0 | 63 | this.mmdb.saveReceivedMessage(aMessage, aCallback); |
michael@0 | 64 | }, |
michael@0 | 65 | |
michael@0 | 66 | saveSendingMessage: function(aMessage, aCallback) { |
michael@0 | 67 | this.mmdb.saveSendingMessage(aMessage, aCallback); |
michael@0 | 68 | }, |
michael@0 | 69 | |
michael@0 | 70 | setMessageDeliveryByMessageId: function(aMessageId, aReceiver, aDelivery, |
michael@0 | 71 | aDeliveryStatus, aEnvelopeId, |
michael@0 | 72 | aCallback) { |
michael@0 | 73 | this.mmdb.updateMessageDeliveryById(aMessageId, "messageId", aReceiver, |
michael@0 | 74 | aDelivery, aDeliveryStatus, |
michael@0 | 75 | aEnvelopeId, aCallback); |
michael@0 | 76 | }, |
michael@0 | 77 | |
michael@0 | 78 | setMessageDeliveryStatusByEnvelopeId: function(aEnvelopeId, aReceiver, |
michael@0 | 79 | aDeliveryStatus, aCallback) { |
michael@0 | 80 | this.mmdb.updateMessageDeliveryById(aEnvelopeId, "envelopeId", aReceiver, |
michael@0 | 81 | null, aDeliveryStatus, null, aCallback); |
michael@0 | 82 | }, |
michael@0 | 83 | |
michael@0 | 84 | setMessageReadStatusByEnvelopeId: function(aEnvelopeId, aReceiver, |
michael@0 | 85 | aReadStatus, aCallback) { |
michael@0 | 86 | this.mmdb.setMessageReadStatusByEnvelopeId(aEnvelopeId, aReceiver, |
michael@0 | 87 | aReadStatus, aCallback); |
michael@0 | 88 | }, |
michael@0 | 89 | |
michael@0 | 90 | getMessageRecordByTransactionId: function(aTransactionId, aCallback) { |
michael@0 | 91 | this.mmdb.getMessageRecordByTransactionId(aTransactionId, aCallback); |
michael@0 | 92 | }, |
michael@0 | 93 | |
michael@0 | 94 | getMessageRecordById: function(aMessageId, aCallback) { |
michael@0 | 95 | this.mmdb.getMessageRecordById(aMessageId, aCallback); |
michael@0 | 96 | }, |
michael@0 | 97 | |
michael@0 | 98 | translateCrErrorToMessageCallbackError: function(aCrError) { |
michael@0 | 99 | return this.mmdb.translateCrErrorToMessageCallbackError(aCrError); |
michael@0 | 100 | }, |
michael@0 | 101 | |
michael@0 | 102 | saveSmsSegment: function(aSmsSegment, aCallback) { |
michael@0 | 103 | this.mmdb.saveSmsSegment(aSmsSegment, aCallback); |
michael@0 | 104 | }, |
michael@0 | 105 | |
michael@0 | 106 | /** |
michael@0 | 107 | * nsIMobileMessageDatabaseService API |
michael@0 | 108 | */ |
michael@0 | 109 | |
michael@0 | 110 | getMessage: function(aMessageId, aRequest) { |
michael@0 | 111 | this.mmdb.getMessage(aMessageId, aRequest); |
michael@0 | 112 | }, |
michael@0 | 113 | |
michael@0 | 114 | deleteMessage: function(aMessageIds, aLength, aRequest) { |
michael@0 | 115 | this.mmdb.deleteMessage(aMessageIds, aLength, aRequest); |
michael@0 | 116 | }, |
michael@0 | 117 | |
michael@0 | 118 | createMessageCursor: function(aFilter, aReverse, aCallback) { |
michael@0 | 119 | return this.mmdb.createMessageCursor(aFilter, aReverse, aCallback); |
michael@0 | 120 | }, |
michael@0 | 121 | |
michael@0 | 122 | markMessageRead: function(aMessageId, aValue, aSendReadReport, aRequest) { |
michael@0 | 123 | this.mmdb.markMessageRead(aMessageId, aValue, aSendReadReport, aRequest); |
michael@0 | 124 | }, |
michael@0 | 125 | |
michael@0 | 126 | createThreadCursor: function(aCallback) { |
michael@0 | 127 | return this.mmdb.createThreadCursor(aCallback); |
michael@0 | 128 | } |
michael@0 | 129 | }; |
michael@0 | 130 | |
michael@0 | 131 | this.NSGetFactory = XPCOMUtils.generateNSGetFactory([MobileMessageDatabaseService]); |