mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1024668 - Extract core logic of abouthealth.js into new WebIDL interface. r=bz,gps,wchen
This commit is contained in:
parent
cb41e5c5ee
commit
d8bc8ca6e5
@ -9,33 +9,17 @@ const {classes: Cc, interfaces: Ci, utils: Cu} = Components;
|
||||
Cu.import("resource://gre/modules/Preferences.jsm");
|
||||
Cu.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
const reporter = Cc["@mozilla.org/datareporting/service;1"]
|
||||
.getService(Ci.nsISupports)
|
||||
.wrappedJSObject
|
||||
.healthReporter;
|
||||
|
||||
const policy = Cc["@mozilla.org/datareporting/service;1"]
|
||||
.getService(Ci.nsISupports)
|
||||
.wrappedJSObject
|
||||
.policy;
|
||||
|
||||
const prefs = new Preferences("datareporting.healthreport.");
|
||||
|
||||
|
||||
let healthReportWrapper = {
|
||||
init: function () {
|
||||
if (!reporter) {
|
||||
healthReportWrapper.handleInitFailure();
|
||||
return;
|
||||
}
|
||||
|
||||
reporter.onInit().then(healthReportWrapper.refreshPayload,
|
||||
healthReportWrapper.handleInitFailure);
|
||||
|
||||
let iframe = document.getElementById("remote-report");
|
||||
iframe.addEventListener("load", healthReportWrapper.initRemotePage, false);
|
||||
let report = this._getReportURI();
|
||||
iframe.src = report.spec;
|
||||
iframe.src = this._getReportURI().spec;
|
||||
iframe.onload = () => {
|
||||
MozSelfSupport.getHealthReportPayload().then(this.updatePayload,
|
||||
this.handleInitFailure);
|
||||
};
|
||||
prefs.observe("uploadEnabled", this.updatePrefState, healthReportWrapper);
|
||||
},
|
||||
|
||||
@ -48,36 +32,30 @@ let healthReportWrapper = {
|
||||
return Services.io.newURI(url, null, null);
|
||||
},
|
||||
|
||||
onOptIn: function () {
|
||||
policy.recordHealthReportUploadEnabled(true,
|
||||
"Health report page sent opt-in command.");
|
||||
this.updatePrefState();
|
||||
},
|
||||
|
||||
onOptOut: function () {
|
||||
policy.recordHealthReportUploadEnabled(false,
|
||||
"Health report page sent opt-out command.");
|
||||
setDataSubmission: function (enabled) {
|
||||
MozSelfSupport.healthReportDataSubmissionEnabled = enabled;
|
||||
this.updatePrefState();
|
||||
},
|
||||
|
||||
updatePrefState: function () {
|
||||
try {
|
||||
let prefs = {
|
||||
enabled: policy.healthReportUploadEnabled,
|
||||
}
|
||||
this.injectData("prefs", prefs);
|
||||
} catch (e) {
|
||||
this.reportFailure(this.ERROR_PREFS_FAILED);
|
||||
enabled: MozSelfSupport.healthReportDataSubmissionEnabled,
|
||||
};
|
||||
healthReportWrapper.injectData("prefs", prefs);
|
||||
}
|
||||
catch (ex) {
|
||||
healthReportWrapper.reportFailure(healthReportWrapper.ERROR_PREFS_FAILED);
|
||||
}
|
||||
},
|
||||
|
||||
refreshPayload: function () {
|
||||
reporter.collectAndObtainJSONPayload().then(healthReportWrapper.updatePayload,
|
||||
healthReportWrapper.handlePayloadFailure);
|
||||
MozSelfSupport.getHealthReportPayload().then(this.updatePayload,
|
||||
this.handlePayloadFailure);
|
||||
},
|
||||
|
||||
updatePayload: function (data) {
|
||||
healthReportWrapper.injectData("payload", data);
|
||||
updatePayload: function (payload) {
|
||||
healthReportWrapper.injectData("payload", JSON.stringify(payload));
|
||||
},
|
||||
|
||||
injectData: function (type, content) {
|
||||
@ -99,10 +77,10 @@ let healthReportWrapper = {
|
||||
handleRemoteCommand: function (evt) {
|
||||
switch (evt.detail.command) {
|
||||
case "DisableDataSubmission":
|
||||
this.onOptOut();
|
||||
this.setDataSubmission(false);
|
||||
break;
|
||||
case "EnableDataSubmission":
|
||||
this.onOptIn();
|
||||
this.setDataSubmission(true);
|
||||
break;
|
||||
case "RequestCurrentPrefs":
|
||||
this.updatePrefState();
|
||||
|
@ -17,6 +17,7 @@ DIRS += [
|
||||
'search',
|
||||
'sessionstore',
|
||||
'shell',
|
||||
'selfsupport',
|
||||
'sidebar',
|
||||
'tabview',
|
||||
'translation',
|
||||
|
74
browser/components/selfsupport/SelfSupportService.js
Normal file
74
browser/components/selfsupport/SelfSupportService.js
Normal file
@ -0,0 +1,74 @@
|
||||
/* 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/. */
|
||||
|
||||
"use strict";
|
||||
|
||||
const {classes: Cc, interfaces: Ci, utils: Cu} = Components;
|
||||
|
||||
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
|
||||
const policy = Cc["@mozilla.org/datareporting/service;1"]
|
||||
.getService(Ci.nsISupports)
|
||||
.wrappedJSObject
|
||||
.policy;
|
||||
|
||||
XPCOMUtils.defineLazyGetter(this, "reporter", () => {
|
||||
return Cc["@mozilla.org/datareporting/service;1"]
|
||||
.getService(Ci.nsISupports)
|
||||
.wrappedJSObject
|
||||
.healthReporter;
|
||||
});
|
||||
|
||||
function MozSelfSupportInterface() {
|
||||
}
|
||||
|
||||
MozSelfSupportInterface.prototype = {
|
||||
classDescription: "MozSelfSupport",
|
||||
classID: Components.ID("{d30aae8b-f352-4de3-b936-bb9d875df0bb}"),
|
||||
contractID: "@mozilla.org/mozselfsupport;1",
|
||||
QueryInterface: XPCOMUtils.generateQI([Ci.nsIDOMGlobalPropertyInitializer,
|
||||
Ci.nsIObserver]),
|
||||
|
||||
_window: null,
|
||||
|
||||
init: function (window) {
|
||||
this._window = window;
|
||||
|
||||
// FIXME: Remove this hack after static attributes work for JS-implemented
|
||||
// WebIDL (see bug 863952). For a detailed description of how this works,
|
||||
// see the comment accompanying the init function of amInstallTrigger.js.
|
||||
return window.MozSelfSupportImpl._create(this._window, this);
|
||||
},
|
||||
|
||||
get healthReportDataSubmissionEnabled() {
|
||||
return policy.healthReportUploadEnabled;
|
||||
},
|
||||
|
||||
set healthReportDataSubmissionEnabled(enabled) {
|
||||
let reason = "Self-support interface sent " +
|
||||
(enabled ? "opt-in" : "opt-out") +
|
||||
" command.";
|
||||
policy.recordHealthReportUploadEnabled(enabled, reason);
|
||||
},
|
||||
|
||||
getHealthReportPayload: function () {
|
||||
return new this._window.Promise(function (aResolve, aReject) {
|
||||
if (reporter) {
|
||||
let resolvePayload = function () {
|
||||
reporter.collectAndObtainJSONPayload(true).then(aResolve, aReject);
|
||||
};
|
||||
|
||||
if (reporter.initialized) {
|
||||
resolvePayload();
|
||||
} else {
|
||||
reporter.onInit().then(resolvePayload, aReject);
|
||||
}
|
||||
} else {
|
||||
aReject(new Error("No reporter"));
|
||||
}
|
||||
}.bind(this));
|
||||
},
|
||||
}
|
||||
|
||||
this.NSGetFactory = XPCOMUtils.generateNSGetFactory([MozSelfSupportInterface]);
|
@ -0,0 +1,4 @@
|
||||
component {d30aae8b-f352-4de3-b936-bb9d875df0bb} SelfSupportService.js
|
||||
contract @mozilla.org/mozselfsupport;1 {d30aae8b-f352-4de3-b936-bb9d875df0bb}
|
||||
|
||||
category JavaScript-global-privileged-property MozSelfSupport @mozilla.org/mozselfsupport;1
|
10
browser/components/selfsupport/moz.build
Normal file
10
browser/components/selfsupport/moz.build
Normal file
@ -0,0 +1,10 @@
|
||||
# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
|
||||
# vim: set filetype=python:
|
||||
# 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/.
|
||||
|
||||
EXTRA_COMPONENTS += [
|
||||
'SelfSupportService.js',
|
||||
'SelfSupportService.manifest',
|
||||
]
|
@ -489,6 +489,8 @@
|
||||
#endif
|
||||
#ifdef MOZ_SERVICES_HEALTHREPORT
|
||||
@BINPATH@/components/HealthReportComponents.manifest
|
||||
@BINPATH@/browser/components/SelfSupportService.manifest
|
||||
@BINPATH@/browser/components/SelfSupportService.js
|
||||
#endif
|
||||
#ifdef MOZ_SERVICES_SYNC
|
||||
@BINPATH@/components/SyncComponents.manifest
|
||||
|
41
dom/webidl/MozSelfSupport.webidl
Normal file
41
dom/webidl/MozSelfSupport.webidl
Normal file
@ -0,0 +1,41 @@
|
||||
/* 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/. */
|
||||
|
||||
/**
|
||||
* The MozSelfSupport interface allows external Mozilla support sites such as
|
||||
* FHR and SUMO to access data and control settings that are not otherwise
|
||||
* exposed to external content.
|
||||
*
|
||||
* At the moment, this is a ChromeOnly interface, but the plan is to allow
|
||||
* specific Mozilla domains to access it directly.
|
||||
*/
|
||||
[ChromeOnly,
|
||||
JSImplementation="@mozilla.org/mozselfsupport;1"]
|
||||
interface MozSelfSupportImpl
|
||||
{
|
||||
/**
|
||||
* Controls whether uploading FHR data is allowed.
|
||||
*/
|
||||
attribute boolean healthReportDataSubmissionEnabled;
|
||||
|
||||
/**
|
||||
* Retrieves the FHR payload object, which is of the form:
|
||||
*
|
||||
* {
|
||||
* version: Number,
|
||||
* clientID: String,
|
||||
* clientIDVersion: Number,
|
||||
* thisPingDate: String,
|
||||
* geckoAppInfo: Object,
|
||||
* data: Object
|
||||
* }
|
||||
*
|
||||
* Refer to the getJSONPayload function in healthreporter.jsm for more
|
||||
* information.
|
||||
*
|
||||
* @return Promise<Object>
|
||||
* Resolved when the FHR payload data has been collected.
|
||||
*/
|
||||
Promise getHealthReportPayload();
|
||||
};
|
@ -260,6 +260,7 @@ WEBIDL_FILES = [
|
||||
'MozMobileMessageManager.webidl',
|
||||
'MozNamedAttrMap.webidl',
|
||||
'MozPowerManager.webidl',
|
||||
'MozSelfSupport.webidl',
|
||||
'MozTimeManager.webidl',
|
||||
'MozWakeLock.webidl',
|
||||
'MutationEvent.webidl',
|
||||
|
Loading…
Reference in New Issue
Block a user