mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-06 00:55:37 +00:00
7e20285e70
The -*- file variable lines -*- establish per-file settings that Emacs will pick up. This patch makes the following changes to those lines (and touches nothing else): - Never set the buffer's mode. Years ago, Emacs did not have a good JavaScript mode, so it made sense to use Java or C++ mode in .js files. However, Emacs has had js-mode for years now; it's perfectly serviceable, and is available and enabled by default in all major Emacs packagings. Selecting a mode in the -*- file variable line -*- is almost always the wrong thing to do anyway. It overrides Emacs's default choice, which is (now) reasonable; and even worse, it overrides settings the user might have made in their '.emacs' file for that file extension. It's only useful when there's something specific about that particular file that makes a particular mode appropriate. - Correctly propagate settings that establish the correct indentation level for this file: c-basic-offset and js2-basic-offset should be js-indent-level. Whatever value they're given should be preserved; different parts of our tree use different indentation styles. - We don't use tabs in Mozilla JS code. Always set indent-tabs-mode: nil. Remove tab-width: settings, at least in files that don't contain tab characters. - Remove js2-mode settings that belong in the user's .emacs file, like js2-skip-preprocessor-directives.
167 lines
5.1 KiB
JavaScript
167 lines
5.1 KiB
JavaScript
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- /
|
|
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
|
|
/* 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/. */
|
|
|
|
// This JS shim contains the callbacks to fire DOMRequest events for
|
|
// navigator.pay API within the payment processor's scope.
|
|
|
|
"use strict";
|
|
|
|
let { classes: Cc, interfaces: Ci, utils: Cu } = Components;
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
|
Cu.import("resource://gre/modules/Services.jsm");
|
|
|
|
XPCOMUtils.defineLazyServiceGetter(this, "cpmm",
|
|
"@mozilla.org/childprocessmessagemanager;1",
|
|
"nsIMessageSender");
|
|
|
|
XPCOMUtils.defineLazyServiceGetter(this, "uuidgen",
|
|
"@mozilla.org/uuid-generator;1",
|
|
"nsIUUIDGenerator");
|
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "Logger",
|
|
"resource://gre/modules/identity/LogUtils.jsm");
|
|
|
|
function log(...aMessageArgs) {
|
|
Logger.log.apply(Logger, ["injected identity.js"].concat(aMessageArgs));
|
|
}
|
|
|
|
log("\n\n======================= identity.js =======================\n\n");
|
|
|
|
// This script may be injected more than once into an iframe.
|
|
// Ensure we don't redefine contstants
|
|
if (typeof kIdentityJSLoaded === 'undefined') {
|
|
const kIdentityDelegateWatch = "identity-delegate-watch";
|
|
const kIdentityDelegateRequest = "identity-delegate-request";
|
|
const kIdentityDelegateLogout = "identity-delegate-logout";
|
|
const kIdentityDelegateReady = "identity-delegate-ready";
|
|
const kIdentityDelegateFinished = "identity-delegate-finished";
|
|
const kIdentityControllerDoMethod = "identity-controller-doMethod";
|
|
const kIdentktyJSLoaded = true;
|
|
}
|
|
|
|
var showUI = false;
|
|
var options = {};
|
|
var isLoaded = false;
|
|
var func = null;
|
|
|
|
/*
|
|
* Message back to the SignInToWebsite pipe. Message should be an
|
|
* object with the following keys:
|
|
*
|
|
* method: one of 'login', 'logout', 'ready'
|
|
* assertion: optional assertion
|
|
*/
|
|
function identityCall(message) {
|
|
if (options._internal) {
|
|
message._internal = options._internal;
|
|
}
|
|
sendAsyncMessage(kIdentityControllerDoMethod, message);
|
|
}
|
|
|
|
/*
|
|
* To close the dialog, we first tell the gecko SignInToWebsite manager that it
|
|
* can clean up. Then we tell the gaia component that we are finished. It is
|
|
* necessary to notify gecko first, so that the message can be sent before gaia
|
|
* destroys our context.
|
|
*/
|
|
function closeIdentityDialog() {
|
|
// tell gecko we're done.
|
|
func = null; options = null;
|
|
sendAsyncMessage(kIdentityDelegateFinished);
|
|
}
|
|
|
|
/*
|
|
* doInternalWatch - call the internal.watch api and relay the results
|
|
* up to the controller.
|
|
*/
|
|
function doInternalWatch() {
|
|
log("doInternalWatch:", options, isLoaded);
|
|
if (options && isLoaded) {
|
|
let BrowserID = content.wrappedJSObject.BrowserID;
|
|
BrowserID.internal.watch(function(aParams, aInternalParams) {
|
|
identityCall(aParams);
|
|
if (aParams.method === "ready") {
|
|
closeIdentityDialog();
|
|
}
|
|
},
|
|
JSON.stringify(options),
|
|
function(...things) {
|
|
// internal watch log callback
|
|
log("(watch) internal: ", things);
|
|
}
|
|
);
|
|
}
|
|
}
|
|
|
|
function doInternalRequest() {
|
|
log("doInternalRequest:", options && isLoaded);
|
|
if (options && isLoaded) {
|
|
var stringifiedOptions = JSON.stringify(options);
|
|
content.wrappedJSObject.BrowserID.internal.get(
|
|
options.origin,
|
|
function(assertion, internalParams) {
|
|
internalParams = internalParams || {};
|
|
if (assertion) {
|
|
identityCall({
|
|
method: 'login',
|
|
assertion: assertion,
|
|
_internalParams: internalParams});
|
|
} else {
|
|
identityCall({
|
|
method: 'cancel'
|
|
});
|
|
}
|
|
closeIdentityDialog();
|
|
},
|
|
stringifiedOptions);
|
|
}
|
|
}
|
|
function doInternalLogout(aOptions) {
|
|
log("doInternalLogout:", (options && isLoaded));
|
|
if (options && isLoaded) {
|
|
let BrowserID = content.wrappedJSObject.BrowserID;
|
|
BrowserID.internal.logout(options.origin, function() {
|
|
identityCall({method:'logout'});
|
|
closeIdentityDialog();
|
|
});
|
|
}
|
|
}
|
|
|
|
addEventListener("DOMContentLoaded", function(e) {
|
|
content.addEventListener("load", function(e) {
|
|
isLoaded = true;
|
|
// bring da func
|
|
if (func) func();
|
|
});
|
|
});
|
|
|
|
// listen for request
|
|
addMessageListener(kIdentityDelegateRequest, function(aMessage) {
|
|
log("injected identity.js received", kIdentityDelegateRequest);
|
|
options = aMessage.json;
|
|
showUI = true;
|
|
func = doInternalRequest;
|
|
func();
|
|
});
|
|
|
|
// listen for watch
|
|
addMessageListener(kIdentityDelegateWatch, function(aMessage) {
|
|
log("injected identity.js received", kIdentityDelegateWatch);
|
|
options = aMessage.json;
|
|
showUI = false;
|
|
func = doInternalWatch;
|
|
func();
|
|
});
|
|
|
|
// listen for logout
|
|
addMessageListener(kIdentityDelegateLogout, function(aMessage) {
|
|
log("injected identity.js received", kIdentityDelegateLogout);
|
|
options = aMessage.json;
|
|
showUI = false;
|
|
func = doInternalLogout;
|
|
func();
|
|
});
|