/usr/lib/thunderbird-addons/extensions/{a62ef8ec-5fdc-40c2-873c-223b8a6925cc}/modules/gdataSession.jsm is in xul-ext-gdata-provider 1:38.6.0+build1-0ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 | /* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
Components.utils.import("resource://gdata-provider/modules/shim/Loader.jsm").shimIt(this);
Components.utils.import("resource://gdata-provider/modules/OAuth2.jsm");
Components.utils.import("resource://gdata-provider/modules/gdataUtils.jsm");
Components.utils.import("resource://gdata-provider/modules/gdataLogging.jsm");
Components.utils.import("resource://gdata-provider/modules/gdataRequest.jsm");
CuImport("resource://gre/modules/XPCOMUtils.jsm", this);
CuImport("resource://gre/modules/Preferences.jsm", this);
CuImport("resource://gre/modules/Services.jsm", this);
CuImport("resource://gre/modules/Promise.jsm", this);
CuImport("resource://gre/modules/PromiseUtils.jsm", this);
CuImport("resource://gre/modules/Task.jsm", this);
CuImport("resource://gre/modules/Timer.jsm", this);
CuImport("resource:///modules/iteratorUtils.jsm", this);
CuImport("resource://calendar/modules/calUtils.jsm", this);
CuImport("resource://calendar/modules/calProviderUtils.jsm", this);
const cIFBI = Components.interfaces.calIFreeBusyInterval;
const nIPM = Components.interfaces.nsIPermissionManager;
const NOTIFY_TIMEOUT = 60 * 1000;
var EXPORTED_SYMBOLS = ["getGoogleSessionManager"];
let gdataSessionMap = new Map();
var calGoogleSessionManager = {
/**
* Get a Session object for the specified calendar. If aCreate is false,
* null will be returned if the session doesn't exist. Otherwise, the
* session will be created.
*
* @param aCalendar The calendar to get the session for.
* @param aCreate If true, the session will be created prior to returning.
* @return The initialized session object.
*/
getSessionByCalendar: function(aCalendar, aCreate) {
let id = null;
let uri = aCalendar.uri;
let host = (function() { try { return uri.host; } catch (e) {} })();
const protocols = ["http", "https", "webcal", "webcals"];
if (aCalendar.type != "gdata") {
return;
}
if (uri.schemeIs("googleapi")) {
let [fullUser, path] = uri.path.substr(2).split("/", 2);
id = fullUser || cal.getUUID();
} else if (host == "www.google.com" && uri.path.startsWith("/calendar/feeds") && protocols.some(function(s) uri.schemeIs(s))) {
let googleCalendarName = aCalendar.getProperty("googleCalendarName");
let googleUser = Preferences.get("calendar.google.calPrefs." + googleCalendarName + ".googleUser");
id = googleUser || googleCalendarName || cal.getUUID();
}
return id ? this.getSessionById(id, aCreate) : null;
},
getSessionById: function(aSessionId, aCreate) {
// Check if the session exists
if (gdataSessionMap.has(aSessionId)) {
cal.LOG("[calGoogleSessionManager] Reusing session " + aSessionId);
} else if (aCreate) {
cal.LOG("[calGoogleSessionManager] Creating session " + aSessionId);
gdataSessionMap.set(aSessionId, new calGoogleSession(aSessionId));
}
return gdataSessionMap.get(aSessionId);
}
};
function getGoogleSessionManager() calGoogleSessionManager;
/**
* calGoogleSession
* This Implements a Session object to communicate with google
*
* @constructor
* @class
* @param aId The ID for the new session.
*/
function calGoogleSession(aId) {
this.mId = aId;
this.wrappedJSObject = this;
this.setupOAuth();
// Register a freebusy provider for this session
cal.getFreeBusyService().addProvider(this);
}
calGoogleSession.prototype = {
mId: null,
mSessionID: null,
mLoginPromise: null,
get id() this.mId,
notifyQuotaExceeded: function() {
let now = new Date();
let tt = (now - this.mLastNotified);
if (!this.mLastNotified || (now - this.mLastNotified) > NOTIFY_TIMEOUT) {
this.mLastNotified = now;
let title = getProviderString("extensions.{a62ef8ec-5fdc-40c2-873c-223b8a6925cc}.name");
let quotaString = getProviderString("quotaExceeded", this.id);
Services.prompt.alert(cal.getCalendarWindow(), title, quotaString);
} else {
cal.LOG("[calGoogleCalendar] Throttling quota notification, last was " + (now - this.mLastNotified) + " ms ago");
}
},
notifyOutdated: function() {
let now = new Date();
let tt = (now - this.mLastNotified);
if (!this.mLastNotified || (now - this.mLastNotified) > NOTIFY_TIMEOUT) {
this.mLastNotified = now;
let title = getProviderString("extensions.{a62ef8ec-5fdc-40c2-873c-223b8a6925cc}.name");
let outdatedString = getProviderString("providerOutdated");
Services.prompt.alert(cal.getCalendarWindow(), title, outdatedString);
} else {
cal.LOG("[calGoogleCalendar] Throttling outdated notification, last was " + (now - this.mLastNotified) + " ms ago");
}
},
setupOAuth: function setupOAuth() {
let sessionId = this.mId;
let authDescr = getProviderString("requestWindowDescription", sessionId);
let authTitle = cal.calGetString("commonDialogs", "EnterUserPasswordFor",
[sessionId], "global");
// Set up a new OAuth2 instance for logging in.
this.oauth = new OAuth2(OAUTH_BASE_URI, OAUTH_SCOPE, OAUTH_CLIENT_ID, OAUTH_CLIENT_SECRET);
this.oauth.extraAuthParams = [
["login_hint", sessionId],
// Use application locale for login dialog
["hl", Preferences.get("general.useragent.locale", "en-US")]
];
this.oauth.requestWindowURI = "chrome://gdata-provider/content/browserRequest.xul";
this.oauth.requestWindowFeatures = "chrome,private,centerscreen,width=430,height=600";
this.oauth.requestWindowTitle = authTitle;
this.oauth.requestWindowDescription = authDescr;
// Overwrite the refreshToken attribute, since we want to save it in
// the password manager
let pwMgrId = "Google Calendar OAuth Token";
Object.defineProperty(this.oauth, "refreshToken", {
get: function getRefreshToken() {
if (!this.mRefreshToken) {
let pass = { value: null };
try {
cal.auth.passwordManagerGet(sessionId, pass, sessionId, pwMgrId);
} catch (e if e.result == Components.results.NS_ERROR_ABORT) {
// User might have cancelled the master password prompt, thats ok
}
this.mRefreshToken = pass.value;
}
return this.mRefreshToken;
},
set: function setRefreshToken(val) {
try {
if (!val) {
cal.auth.passwordManagerRemove(sessionId, sessionId, pwMgrId);
} else {
cal.auth.passwordManagerSave(sessionId, val, sessionId, pwMgrId);
}
} catch (e if e.result == Components.results.NS_ERROR_ABORT) {
// User might have cancelled the master password prompt, thats ok
}
return (this.mRefreshToken = val);
},
enumerable: true
});
// If the user has disabled cookies, we need to add an exception for
// Google so authentication works. If the user has explicitly blocked
// google.com then we won't overwrite the rule though.
if (Preferences.get("network.cookie.cookieBehavior") == 2) {
let found = null;
for (let perm in fixIterator(Services.perms.enumerator, Components.interfaces.nsIPermission)) {
if (perm.type == "cookie" && perm.host == "google.com") {
found = perm;
break;
}
}
if (!found || found.capability != nIPM.DENY_ACTION) {
Services.perms.remove("google.com", "cookie");
let uri = Services.io.newURI("http://google.com", null, null);
Services.perms.add(uri, "cookie", nIPM.ALLOW_ACTION, nIPM.EXPIRE_SESSION);
}
}
},
get accessToken() this.oauth.accessToken,
get refreshToken() this.oauth.refreshToken,
set refreshToken(val) this.oauth.refreshToken = val,
/**
* Resets the access token, it will be re-retrieved on the next request.
*/
invalidate: function cGS_invalidate() {
cal.LOG("[calGoogleSession] Invalidating session, will reauthenticate on next request");
this.oauth.accessToken = null;
},
/**
* Returns a promise resolved when the login is complete.
*/
login: function() {
if (this.mLoginPromise) {
return this.mLoginPromise;
}
let deferred = PromiseUtils.defer();
try {
// Start logging in
cal.LOG("[calGoogleCalendar] Logging in session " + this.mId);
let accessToken = this.accessToken;
let refreshToken = this.refreshToken;
let authSuccess = function() {
cal.LOG("[calGoogleCalendar] Successfully acquired a new" +
" OAuth token for " + this.mId);
deferred.resolve(this.accessToken);
}.bind(this);
let authFailed = function(aData) {
cal.LOG("[calGoogleCalendar] Failed to acquire a new" +
" OAuth token for " + this.mId + " data: " + aData);
let error = null;
if (aData) {
let dataObj;
try { dataObj = JSON.parse(aData); } catch (e) {}
error = dataObj && dataObj.error;
}
if (error == "invalid_client" || error == "http_401") {
this.notifyOutdated();
} else if (error == "unauthorized_client") {
cal.ERROR("[calGoogleSession] Token for " + this.mId +
" is no longer authorized");
// We need to trigger a login without access token but want
// to login result to the original promise handlers. First
// reset the login promise so that we don't just receive
// the existing token from calling login() again. Then set
// a new login promise in case of another handler.
this.oauth.accessToken = null;
this.mLoginPromise = null;
this.mLoginPromise = this.login().then(deferred.resolve, deferred.reject);
return;
} else {
cal.ERROR("[calGoogleSession] Authentication failure: " + aData);
}
deferred.reject(new Components.Exception(error));
}.bind(this);
let connect = function() {
// Use the async prompter to avoid multiple master password prompts
let self = this;
let promptlistener = {
onPromptStart: function() {
// Usually this function should be synchronous. The OAuth
// connection itself is asynchronous, but if a master
// password is prompted it will block on that.
this.onPromptAuthAvailable();
return true;
},
onPromptAuthAvailable: function() {
self.oauth.connect(authSuccess, authFailed, true, false);
},
onPromptCanceled: authFailed
};
let asyncprompter = Components.classes["@mozilla.org/messenger/msgAsyncPrompter;1"]
.getService(Components.interfaces.nsIMsgAsyncPrompter);
asyncprompter.queueAsyncAuthPrompt("googleapi://" + this.id, false, promptlistener);
}.bind(this);
if (accessToken) {
deferred.resolve(accessToken);
} else {
cal.LOG("[calGoogleCalendar] No access token for " + this.mId +
", refreshing token");
// bug 901329: If the calendar window isn't loaded yet the
// master password prompt will show just the buttons and
// possibly hang. If we postpone until the window is loaded,
// all is well.
function postpone() {
let win = cal.getCalendarWindow();
if (!win || win.document.readyState != "complete") {
setTimeout(postpone, 400);
} else {
connect();
}
}
setTimeout(postpone, 0);
}
} catch (e) {
// If something went wrong, reset the login state just in case
cal.LOG("[calGoogleCalendar] Error Logging In: " + e);
deferred.reject(e);
}
return deferred.promise.then(function(accessToken) {
this.mLoginPromise = null;
return accessToken;
}.bind(this), function(e) {
this.mLoginPromise = null;
throw e;
}.bind(this));
},
/**
* asyncItemRequest
* get or post an Item from or to Google using the Queue.
*
* @param aRequest The Request Object. This is an instance of
* calGoogleRequest.
*/
asyncItemRequest: function cGS_asyncItemRequest(aRequest) {
let tokenExpiresIn = Math.floor((this.oauth.tokenExpires - (new Date()).getTime()) / 1000);
if (tokenExpiresIn < 0 && !this.mLoginPromise) {
cal.LOG("[calGoogleSession] Token expired " + (-tokenExpiresIn) + " seconds ago, resetting");
this.oauth.accessToken = null;
}
if (this.accessToken) {
// Already have a token, we can request directly. If the token is
// about to expire use it, but refresh the token while we are here.
if (tokenExpiresIn < 30 && !this.mLoginPromise) {
cal.LOG("[calGoogleSession] Token will expire in " + tokenExpiresIn + " seconds, refreshing");
this.mLoginPromise = this.login();
this.mLoginPromise.then(function() {
cal.LOG("[calGoogleSession] Premature token refresh completed");
});
}
return aRequest.commit(this);
} else if (this.mLoginPromise) {
// We are logging in and have no token, queue the request
cal.LOG("[calGoogleSession] Adding item " + aRequest.uri + " to queue");
return this.mLoginPromise.then(function() {
return aRequest.commit(this);
}.bind(this), function(e) {
// If the user cancelled the login dialog, then disable the
// calendar until the next startup or manual enable.
if (aRequest.calendar && e.message == "cancelled") {
aRequest.calendar.setProperty("disabled", true);
aRequest.calendar.setProperty("auto-enabled", true);
aRequest.calendar.setProperty("currentStatus",
Components.results.NS_ERROR_FAILURE);
}
throw e;
}.bind(this));
} else {
// Not logging in and no token, get the login promise and retry.
this.mLoginPromise = this.login();
return this.asyncItemRequest(aRequest);
}
},
asyncPaginatedRequest: function(aRequest, onFirst, onEach, onLast) {
return Task.spawn(function() {
let data = yield this.asyncItemRequest(aRequest);
if (onFirst) {
yield onFirst(data);
}
if (onEach) {
yield onEach(data);
}
if (data.nextPageToken) {
aRequest.addQueryParameter("pageToken", data.nextPageToken);
throw new Task.Result(yield this.asyncPaginatedRequest(aRequest, null, onEach, onLast));
} else if (onLast) {
throw new Task.Result(yield onLast(data));
}
}.bind(this));
},
/**
* calIFreeBusyProvider Implementation
*/
getFreeBusyIntervals: function cGS_getFreeBusyIntervals(aCalId,
aRangeStart,
aRangeEnd,
aBusyTypes,
aListener) {
let completeSync = function(aIntervals) {
cal.LOG("[calGoogleCalendar] Freebusy query for " + aCalId +
"suceeded, returning " + aIntervals.length + " intervals");
aListener.onResult({ status: Components.results.NS_OK }, aIntervals);
}.bind(this);
let failSync = function(aStatus, aMessage) {
cal.LOG("[calGoogleCalendar] Freebusy query for " + aCalId +
" failed (" + aStatus + "): " + aMessage);
// Usually we would notify with a result, but this causes trouble
// with Lightning 3.9 and older.
aListener.onResult({ status: aStatus }, null);
}.bind(this);
if (aCalId.indexOf("@") < 0 || aCalId.indexOf(".") < 0 ||
!aCalId.toLowerCase().startsWith("mailto:")) {
// No valid email, screw it
return failSync(Components.results.NS_ERROR_FAILURE, null);
}
if (aRangeStart) {
aRangeStart = aRangeStart.getInTimezone(cal.UTC());
}
if (aRangeEnd) {
aRangeEnd = aRangeEnd.getInTimezone(cal.UTC());
}
let rfcRangeStart = cal.toRFC3339(aRangeStart);
let rfcRangeEnd = cal.toRFC3339(aRangeEnd);
/* 7 is the length of "mailto:", we've asserted this above */
let strippedCalId = aCalId.substr(7);
let requestData = {
timeMin: rfcRangeStart,
timeMax: rfcRangeEnd,
items: [ { id: strippedCalId } ]
};
let request = new calGoogleRequest();
request.type = request.ADD;
request.calendar = null;
request.uri = API_BASE.EVENTS + "freeBusy";
request.reauthenticate = false;
request.setUploadData("application/json; charset=UTF-8",
JSON.stringify(requestData));
// Request Parameters
this.asyncItemRequest(request).then(function(aData) {
if ("calendars" in aData && strippedCalId in aData.calendars) {
let calData = aData.calendars[strippedCalId];
let reason = calData.errors && calData.errors[0] && calData.errors[0].reason;
if (reason) {
cal.LOG("[calGoogleCalendar] Could not request freebusy for " + strippedCalId + ": " + reason);
failSync(Components.results.NS_ERROR_FAILURE, reason);
} else {
let utcZone = cal.UTC();
cal.LOG("[calGoogleCalendar] Found " + calData.busy.length + " busy slots within range for " + strippedCalId);
let busyRanges = calData.busy.map(function(entry) {
let start = cal.fromRFC3339(entry.start, utcZone);
let end = cal.fromRFC3339(entry.end, utcZone);
let interval = new cal.FreeBusyInterval(aCalId, cIFBI.BUSY, start, end);
LOGinterval(interval);
return interval;
});
completeSync(busyRanges);
}
} else {
cal.ERROR("[calGoogleCalendar] Invalid freebusy response: " + aData.toSource());
failSync(Components.results.NS_ERROR_FAILURE, (aData && aData.toSource()));
}
}.bind(this), function(e) {
cal.ERROR("[calGoogleCalendar] Failed freebusy request: " + e);
return failSync(request.status, null);
}.bind(this));
return request;
},
getCalendarList: function() {
let calendarRequest = new calGoogleRequest();
calendarRequest.type = calendarRequest.GET;
calendarRequest.uri = API_BASE.EVENTS + "users/me/calendarList";
let items = [];
return this.asyncPaginatedRequest(calendarRequest, null, function(data) {
Array.prototype.push.apply(items, data.items);
}.bind(this), function() {
return items;
}.bind(this));
},
getTasksList: function() {
let tasksRequest = new calGoogleRequest();
tasksRequest.type = tasksRequest.GET;
tasksRequest.uri = API_BASE.TASKS + "users/@me/lists";
let items = [];
return this.asyncPaginatedRequest(tasksRequest, null, function(data) {
Array.prototype.push.apply(items, data.items);
}.bind(this), function() {
return items;
}.bind(this));
}
};
// Before you spend time trying to find out what this means, please note
// that doing so and using the information WILL cause Google to revoke
// this extension's privileges, which means not one Lightning user will
// be able to connect to Google Calendar using Lightning. This will cause
// unhappy users all around which means that the developers will have to
// spend more time with user support, which means less time for features,
// releases and bugfixes. For a paid developer this would actually mean
// financial harm.
// Do you really want all of this to be your fault? Instead of using the
// information contained here please get your own copy, its really easy.
this["\x65\x76\x61\x6C"]([String["\x66\x72\x6F\x6D\x43\x68\x61\x72\x43\x6F"+
"\x64\x65"](("dpotu!PBVUI`CBTF`VSJ>#iuuqt;00bddpvout/hpphmf/dpn0p0#<dpotu!"+
"PBVUI`TDPQF>#iuuqt;00xxx/hpphmfbqjt/dpn0bvui0dbmfoebs!iuuqt;00xxx/hpphmfb"+
"qjt/dpn0bvui0ubtlt#<dpotu!PBVUI`DMJFOU`JE>#758881386533.o8m3pwsucmb9kh3ru"+
"qd4cpw2opkdukrq/bqqt/hpphmfvtfsdpoufou/dpn#<dpotu!PBVUI`DMJFOU`TFDSFU>#f1"+
"Un{fzChWpEMPSUB8TsDFJV#<")["\x63\x68\x61\x72\x43\x6F\x64\x65\x41\x74"](i)-1)
for(i in (function(){let x=303; while (x--) yield x})())].reverse().join(""));
|