Skip to content

Commit

Permalink
Bug 1561435 - Format devtools/server/, a=automatic-formatting
Browse files Browse the repository at this point in the history
# ignore-this-changeset

Differential Revision: https://phabricator.services.mozilla.com/D35891

--HG--
extra : source : d2dc183b9bf9086d4b862e0e9a0cfa0bf773193f
  • Loading branch information
Victor Porof committed Jul 5, 2019
1 parent 60b8254 commit 24d2c75
Show file tree
Hide file tree
Showing 437 changed files with 23,141 additions and 13,901 deletions.
1 change: 0 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ toolkit/components/telemetry/healthreport-prefs.js
# Ignore all devtools directories for now, except the debugger.
devtools/docs/**
devtools/platform/**
devtools/server/**
devtools/shared/**
devtools/startup/**

Expand Down
20 changes: 14 additions & 6 deletions devtools/server/actors/accessibility/accessibility-parent.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ class AccessibilityParent {
this.onAccessibilityMessage = this.onAccessibilityMessage.bind(this);
this.setMessageManager(mm);

this.userPref = Services.prefs.getIntPref(PREF_ACCESSIBILITY_FORCE_DISABLED);
this.userPref = Services.prefs.getIntPref(
PREF_ACCESSIBILITY_FORCE_DISABLED
);
Services.obs.addObserver(this, "a11y-consumers-changed");
Services.prefs.addObserver(PREF_ACCESSIBILITY_FORCE_DISABLED, this);

Expand All @@ -30,7 +32,8 @@ class AccessibilityParent {
// started elsewhere to ensure that parent process a11y service does not
// get GC'ed away.
this.accService = Cc["@mozilla.org/accessibilityService;1"].getService(
Ci.nsIAccessibilityService);
Ci.nsIAccessibilityService
);
}

this.messageManager.sendAsyncMessage(`${this._msgName}:event`, {
Expand Down Expand Up @@ -105,8 +108,11 @@ class AccessibilityParent {
topic: "can-be-disabled-change",
data: !PlatformAPI,
});
} else if (!this.disabling && topic === "nsPref:changed" &&
data === PREF_ACCESSIBILITY_FORCE_DISABLED) {
} else if (
!this.disabling &&
topic === "nsPref:changed" &&
data === PREF_ACCESSIBILITY_FORCE_DISABLED
) {
// PREF_ACCESSIBILITY_FORCE_DISABLED preference change event. When set to
// >=1, it means that the user wants to disable accessibility service and
// prevent it from starting in the future. Note: we also check
Expand Down Expand Up @@ -138,7 +144,8 @@ class AccessibilityParent {
get canBeDisabled() {
if (this.enabled) {
const a11yService = Cc["@mozilla.org/accessibilityService;1"].getService(
Ci.nsIAccessibilityService);
Ci.nsIAccessibilityService
);
const { PlatformAPI } = JSON.parse(a11yService.getConsumers());
return !PlatformAPI;
}
Expand All @@ -165,7 +172,8 @@ class AccessibilityParent {
}

this.accService = Cc["@mozilla.org/accessibilityService;1"].getService(
Ci.nsIAccessibilityService);
Ci.nsIAccessibilityService
);
}

/**
Expand Down
45 changes: 34 additions & 11 deletions devtools/server/actors/accessibility/accessibility.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ const { Actor, ActorClassWithSpec } = require("devtools/shared/protocol");
const defer = require("devtools/shared/defer");
const { accessibilitySpec } = require("devtools/shared/specs/accessibility");

loader.lazyRequireGetter(this, "AccessibleWalkerActor", "devtools/server/actors/accessibility/walker", true);
loader.lazyRequireGetter(
this,
"AccessibleWalkerActor",
"devtools/server/actors/accessibility/walker",
true
);
loader.lazyRequireGetter(this, "events", "devtools/shared/event-emitter");

const PREF_ACCESSIBILITY_FORCE_DISABLED = "accessibility.force_disabled";
Expand All @@ -35,9 +40,14 @@ const AccessibilityActor = ActorClassWithSpec(accessibilitySpec, {
});

this.onMessage = this.onMessage.bind(this);
this.messageManager.addMessageListener(`${this._msgName}:event`, this.onMessage);
this.messageManager.addMessageListener(
`${this._msgName}:event`,
this.onMessage
);
} else {
this.userPref = Services.prefs.getIntPref(PREF_ACCESSIBILITY_FORCE_DISABLED);
this.userPref = Services.prefs.getIntPref(
PREF_ACCESSIBILITY_FORCE_DISABLED
);
Services.obs.addObserver(this, "a11y-consumers-changed");
Services.prefs.addObserver(PREF_ACCESSIBILITY_FORCE_DISABLED, this);
this.initializedDeferred.resolve();
Expand Down Expand Up @@ -88,7 +98,8 @@ const AccessibilityActor = ActorClassWithSpec(accessibilitySpec, {
get messageManager() {
if (!DebuggerServer.isInChildProcess) {
throw new Error(
"Message manager should only be used when actor is in child process.");
"Message manager should only be used when actor is in child process."
);
}

return this.conn.parentMessageManager;
Expand All @@ -107,7 +118,9 @@ const AccessibilityActor = ActorClassWithSpec(accessibilitySpec, {
// parent process and the service was shut down there). We need to sync the two
// services if possible.
if (!data.enabled && this.enabled && data.canBeEnabled) {
this.messageManager.sendAsyncMessage(this._msgName, { action: "enable" });
this.messageManager.sendAsyncMessage(this._msgName, {
action: "enable",
});
}

this.initializedDeferred.resolve();
Expand Down Expand Up @@ -159,7 +172,9 @@ const AccessibilityActor = ActorClassWithSpec(accessibilitySpec, {
this.disabling = true;
const shutdownPromise = this.once("shutdown");
if (DebuggerServer.isInChildProcess) {
this.messageManager.sendAsyncMessage(this._msgName, { action: "disable" });
this.messageManager.sendAsyncMessage(this._msgName, {
action: "disable",
});
} else {
// Set PREF_ACCESSIBILITY_FORCE_DISABLED to 1 to force disable
// accessibility service. This is the only way to guarantee an immediate
Expand All @@ -173,7 +188,10 @@ const AccessibilityActor = ActorClassWithSpec(accessibilitySpec, {
// set value. This will not start accessibility service until the user
// activates it again. It simply ensures that accessibility service can
// start again (when value is below 1).
Services.prefs.setIntPref(PREF_ACCESSIBILITY_FORCE_DISABLED, this.userPref);
Services.prefs.setIntPref(
PREF_ACCESSIBILITY_FORCE_DISABLED,
this.userPref
);
}

await shutdownPromise;
Expand Down Expand Up @@ -217,8 +235,11 @@ const AccessibilityActor = ActorClassWithSpec(accessibilitySpec, {
// set, we can no longer disable accessibility service.
const { PlatformAPI } = JSON.parse(data);
events.emit(this, "can-be-disabled-change", !PlatformAPI);
} else if (!this.disabling && topic === "nsPref:changed" &&
data === PREF_ACCESSIBILITY_FORCE_DISABLED) {
} else if (
!this.disabling &&
topic === "nsPref:changed" &&
data === PREF_ACCESSIBILITY_FORCE_DISABLED
) {
// PREF_ACCESSIBILITY_FORCE_DISABLED preference change event. When set to
// >=1, it means that the user wants to disable accessibility service and
// prevent it from starting in the future. Note: we also check
Expand Down Expand Up @@ -262,8 +283,10 @@ const AccessibilityActor = ActorClassWithSpec(accessibilitySpec, {

Services.obs.removeObserver(this, "a11y-init-or-shutdown");
if (DebuggerServer.isInChildProcess) {
this.messageManager.removeMessageListener(`${this._msgName}:event`,
this.onMessage);
this.messageManager.removeMessageListener(
`${this._msgName}:event`,
this.onMessage
);
} else {
Services.obs.removeObserver(this, "a11y-consumers-changed");
Services.prefs.removeObserver(PREF_ACCESSIBILITY_FORCE_DISABLED, this);
Expand Down
128 changes: 84 additions & 44 deletions devtools/server/actors/accessibility/accessible.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,34 @@
const { Ci, Cu } = require("chrome");
const { Actor, ActorClassWithSpec } = require("devtools/shared/protocol");
const { accessibleSpec } = require("devtools/shared/specs/accessibility");
const { accessibility: { AUDIT_TYPE } } = require("devtools/shared/constants");

loader.lazyRequireGetter(this, "getContrastRatioFor", "devtools/server/actors/accessibility/audit/contrast", true);
loader.lazyRequireGetter(this, "auditTextLabel", "devtools/server/actors/accessibility/audit/text-label", true);
loader.lazyRequireGetter(this, "isDefunct", "devtools/server/actors/utils/accessibility", true);
loader.lazyRequireGetter(this, "findCssSelector", "devtools/shared/inspector/css-logic", true);
const {
accessibility: { AUDIT_TYPE },
} = require("devtools/shared/constants");

loader.lazyRequireGetter(
this,
"getContrastRatioFor",
"devtools/server/actors/accessibility/audit/contrast",
true
);
loader.lazyRequireGetter(
this,
"auditTextLabel",
"devtools/server/actors/accessibility/audit/text-label",
true
);
loader.lazyRequireGetter(
this,
"isDefunct",
"devtools/server/actors/utils/accessibility",
true
);
loader.lazyRequireGetter(
this,
"findCssSelector",
"devtools/shared/inspector/css-logic",
true
);
loader.lazyRequireGetter(this, "events", "devtools/shared/event-emitter");

const RELATIONS_TO_IGNORE = new Set([
Expand Down Expand Up @@ -49,9 +71,10 @@ function getNodeDescription(node) {
nodeType,
// If node is a text node, we find a unique CSS selector for its parent and add a
// CSS_TEXT_SELECTOR postfix to indicate that it's a text node.
nodeCssSelector: nodeType === Node.TEXT_NODE ?
`${findCssSelector(node.parentNode)}${CSS_TEXT_SELECTOR}` :
findCssSelector(node),
nodeCssSelector:
nodeType === Node.TEXT_NODE
? `${findCssSelector(node.parentNode)}${CSS_TEXT_SELECTOR}`
: findCssSelector(node),
};
}

Expand All @@ -69,7 +92,7 @@ function getNodeDescription(node) {
function getSnapshot(acc, a11yService) {
if (isDefunct(acc)) {
return {
states: [ a11yService.getStringStates(0, STATE_DEFUNCT) ],
states: [a11yService.getStringStates(0, STATE_DEFUNCT)],
};
}

Expand All @@ -88,9 +111,7 @@ function getSnapshot(acc, a11yService) {
const state = {};
const extState = {};
acc.getState(state, extState);
const states = [
...a11yService.getStringStates(state.value, extState.value),
];
const states = [...a11yService.getStringStates(state.value, extState.value)];

const children = [];
for (let child = acc.firstChild; child; child = child.nextSibling) {
Expand Down Expand Up @@ -229,7 +250,11 @@ const AccessibleActor = ActorClassWithSpec(accessibleSpec, {
return children;
}

for (let child = this.rawAccessible.firstChild; child; child = child.nextSibling) {
for (
let child = this.rawAccessible.firstChild;
child;
child = child.nextSibling
) {
children.push(this.walker.addRef(child));
}
return children;
Expand Down Expand Up @@ -291,7 +316,10 @@ const AccessibleActor = ActorClassWithSpec(accessibleSpec, {
return null;
}

let x = {}, y = {}, w = {}, h = {};
let x = {},
y = {},
w = {},
h = {};
try {
this.rawAccessible.getBoundsInCSSPixels(x, y, w, h);
x = x.value;
Expand All @@ -303,7 +331,10 @@ const AccessibleActor = ActorClassWithSpec(accessibleSpec, {
}

// Check if accessible bounds are invalid.
const left = x, right = x + w, top = y, bottom = y + h;
const left = x,
right = x + w,
top = y,
bottom = y + h;
if (left === right || top === bottom) {
return null;
}
Expand All @@ -317,8 +348,9 @@ const AccessibleActor = ActorClassWithSpec(accessibleSpec, {
return relationObjects;
}

const relations =
[...this.rawAccessible.getRelations().enumerate(Ci.nsIAccessibleRelation)];
const relations = [
...this.rawAccessible.getRelations().enumerate(Ci.nsIAccessibleRelation),
];
if (relations.length === 0) {
return relationObjects;
}
Expand All @@ -329,7 +361,9 @@ const AccessibleActor = ActorClassWithSpec(accessibleSpec, {
return;
}

const type = this.walker.a11yService.getStringRelationType(relation.relationType);
const type = this.walker.a11yService.getStringRelationType(
relation.relationType
);
const targets = [...relation.getTargets().enumerate(Ci.nsIAccessible)];
let relationObject;
for (const target of targets) {
Expand Down Expand Up @@ -394,9 +428,12 @@ const AccessibleActor = ActorClassWithSpec(accessibleSpec, {
},

_isValidTextLeaf(rawAccessible) {
return !isDefunct(rawAccessible) &&
TEXT_ROLES.has(rawAccessible.role) &&
rawAccessible.name && rawAccessible.name.trim().length > 0;
return (
!isDefunct(rawAccessible) &&
TEXT_ROLES.has(rawAccessible.role) &&
rawAccessible.name &&
rawAccessible.name.trim().length > 0
);
},

/**
Expand Down Expand Up @@ -461,7 +498,7 @@ const AccessibleActor = ActorClassWithSpec(accessibleSpec, {
*
* @return {Object|null}
* Audit results for the accessible object.
*/
*/
audit(options = {}) {
if (this._auditing) {
return this._auditing;
Expand All @@ -478,28 +515,31 @@ const AccessibleActor = ActorClassWithSpec(accessibleSpec, {
// invalid states, etc. (For example see bug 1518808).
this._auditing = Promise.all(
auditTypes.map(auditType => this._getAuditByType(auditType))
).then(results => {
if (this.isDefunct || this.isDestroyed) {
return null;
}
)
.then(results => {
if (this.isDefunct || this.isDestroyed) {
return null;
}

const audit = results.reduce((auditResults, result, index) => {
auditResults[auditTypes[index]] = result;
return auditResults;
}, {});
this._lastAudit = this._lastAudit || {};
Object.assign(this._lastAudit, audit);
events.emit(this, "audited", audit);

return audit;
}).catch(error => {
if (!this.isDefunct && !this.isDestroyed) {
throw error;
}
return null;
}).finally(() => {
this._auditing = null;
});
const audit = results.reduce((auditResults, result, index) => {
auditResults[auditTypes[index]] = result;
return auditResults;
}, {});
this._lastAudit = this._lastAudit || {};
Object.assign(this._lastAudit, audit);
events.emit(this, "audited", audit);

return audit;
})
.catch(error => {
if (!this.isDefunct && !this.isDestroyed) {
throw error;
}
return null;
})
.finally(() => {
this._auditing = null;
});

return this._auditing;
},
Expand Down
Loading

0 comments on commit 24d2c75

Please sign in to comment.