Bug 688083 - Plugin Crash: Sync Submit Report Checkbox With Pref Between Instances. r=dolske

This commit is contained in:
Felix Fung 2011-10-03 13:26:08 -07:00
Родитель c9753d7a14
Коммит 19d291991e
2 изменённых файлов: 47 добавлений и 9 удалений

Просмотреть файл

@ -7061,8 +7061,7 @@ var gPluginHandler = {
return; return;
let submittedReport = aEvent.getData("submittedCrashReport"); let submittedReport = aEvent.getData("submittedCrashReport");
let doPrompt = true; // XXX followup for .getData("doPrompt"); let doPrompt = true; // XXX followup to get via gCrashReporter
let submitReports = true; // XXX followup for .getData("submitReports");
let pluginName = aEvent.getData("pluginName"); let pluginName = aEvent.getData("pluginName");
let pluginFilename = aEvent.getData("pluginFilename"); let pluginFilename = aEvent.getData("pluginFilename");
let pluginDumpID = aEvent.getData("pluginDumpID"); let pluginDumpID = aEvent.getData("pluginDumpID");
@ -7080,6 +7079,7 @@ var gPluginHandler = {
let overlay = doc.getAnonymousElementByAttribute(plugin, "class", "mainBox"); let overlay = doc.getAnonymousElementByAttribute(plugin, "class", "mainBox");
let statusDiv = doc.getAnonymousElementByAttribute(plugin, "class", "submitStatus"); let statusDiv = doc.getAnonymousElementByAttribute(plugin, "class", "submitStatus");
#ifdef MOZ_CRASHREPORTER #ifdef MOZ_CRASHREPORTER
let submitReports = gCrashReporter.submitReports;
let status; let status;
// Determine which message to show regarding crash reports. // Determine which message to show regarding crash reports.
@ -7090,9 +7090,14 @@ var gPluginHandler = {
status = "noSubmit"; status = "noSubmit";
} }
else { // doPrompt else { // doPrompt
// link submit checkbox to gCrashReporter submitReports preference
let submitChk = doc.getAnonymousElementByAttribute( let submitChk = doc.getAnonymousElementByAttribute(
plugin, "class", "pleaseSubmitCheckbox"); plugin, "class", "pleaseSubmitCheckbox");
submitChk.checked = submitReports; submitChk.checked = submitReports;
submitChk.addEventListener("click", function() {
gCrashReporter.submitReports = this.checked;
}, false);
status = "please"; status = "please";
} }
@ -7109,10 +7114,23 @@ var gPluginHandler = {
let helpIcon = doc.getAnonymousElementByAttribute(plugin, "class", "helpIcon"); let helpIcon = doc.getAnonymousElementByAttribute(plugin, "class", "helpIcon");
this.addLinkClickCallback(helpIcon, "openHelpPage"); this.addLinkClickCallback(helpIcon, "openHelpPage");
// If we're showing the link to manually trigger report submission, we'll // If we're showing the checkbox to trigger report submission, we'll want
// want to be able to update all the instances of the UI for this crash to // to be able to update all the instances of the UI for this crash when
// show an updated message when a report is submitted. // one instance of the checkbox is modified or the status is updated.
if (doPrompt) { if (doPrompt) {
let submitReportsPrefObserver = {
QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver,
Ci.nsISupportsWeakReference]),
observe : function(subject, topic, data) {
let submitChk = doc.getAnonymousElementByAttribute(
plugin, "class", "pleaseSubmitCheckbox");
submitChk.checked = gCrashReporter.submitReports;
},
handleEvent : function(event) {
// Not expected to be called, just here for the closure.
}
};
let observer = { let observer = {
QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver, QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver,
Ci.nsISupportsWeakReference]), Ci.nsISupportsWeakReference]),
@ -7129,16 +7147,21 @@ var gPluginHandler = {
handleEvent : function(event) { handleEvent : function(event) {
// Not expected to be called, just here for the closure. // Not expected to be called, just here for the closure.
} }
} };
// Use a weak reference, so we don't have to remove it... // Use a weak reference, so we don't have to remove it...
Services.obs.addObserver(observer, "crash-report-status", true); Services.obs.addObserver(observer, "crash-report-status", true);
Services.obs.addObserver(
submitReportsPrefObserver, "submit-reports-pref-changed", true);
// ...alas, now we need something to hold a strong reference to prevent // ...alas, now we need something to hold a strong reference to prevent
// it from being GC. But I don't want to manually manage the reference's // it from being GC. But I don't want to manually manage the reference's
// lifetime (which should be no greater than the page). // lifetime (which should be no greater than the page).
// Clever solution? Use a closure with an event listener on the document. // Clever solution? Use a closure with an event listener on the document.
// When the doc goes away, so do the listener references and the closure. // When the doc goes away, so do the listener references and the closure.
doc.addEventListener("mozCleverClosureHack", observer, false); doc.addEventListener("mozCleverClosureHack", observer, false);
doc.addEventListener(
"mozCleverClosureHack", submitReportsPrefObserver, false);
} }
#endif #endif

Просмотреть файл

@ -38,7 +38,8 @@
* ***** END LICENSE BLOCK ***** */ * ***** END LICENSE BLOCK ***** */
#include "mozilla/dom/CrashReporterChild.h" #include "mozilla/dom/CrashReporterChild.h"
#include "mozilla/Services.h"
#include "nsIObserverService.h"
#include "mozilla/Util.h" #include "mozilla/Util.h"
#include "nsXULAppAPI.h" #include "nsXULAppAPI.h"
@ -1551,7 +1552,21 @@ nsresult GetSubmitReports(bool* aSubmitReports)
nsresult SetSubmitReports(bool aSubmitReports) nsresult SetSubmitReports(bool aSubmitReports)
{ {
return PrefSubmitReports(&aSubmitReports, true); nsresult rv;
nsCOMPtr<nsIObserverService> obsServ =
mozilla::services::GetObserverService();
if (!obsServ) {
return NS_ERROR_FAILURE;
}
rv = PrefSubmitReports(&aSubmitReports, true);
if (NS_FAILED(rv)) {
return rv;
}
obsServ->NotifyObservers(nsnull, "submit-reports-pref-changed", nsnull);
return NS_OK;
} }
// The "pending" dir is Crash Reports/pending, from which minidumps // The "pending" dir is Crash Reports/pending, from which minidumps