Bug 981237 - Remove DataContainerEvent dependency from Plugin crash handler. r=jst,johns

This commit is contained in:
Masatoshi Kimura 2014-03-21 13:00:00 +09:00
parent 6ddc1da58c
commit 017a04a06a
5 changed files with 56 additions and 63 deletions

View File

@ -1142,15 +1142,16 @@ var gPluginHandler = {
// plugin in content.
pluginInstanceCrashed: function (plugin, aEvent) {
// Ensure the plugin and event are of the right type.
if (!(aEvent instanceof Ci.nsIDOMDataContainerEvent))
if (!(aEvent instanceof Ci.nsIDOMCustomEvent))
return;
let submittedReport = aEvent.getData("submittedCrashReport");
let doPrompt = true; // XXX followup for .getData("doPrompt");
let submitReports = true; // XXX followup for .getData("submitReports");
let pluginName = aEvent.getData("pluginName");
let pluginDumpID = aEvent.getData("pluginDumpID");
let browserDumpID = aEvent.getData("browserDumpID");
let propBag = aEvent.detail.QueryInterface(Ci.nsIPropertyBag2);
let submittedReport = propBag.getPropertyAsBool("submittedCrashReport");
let doPrompt = true; // XXX followup for .getPropertyAsBool("doPrompt");
let submitReports = true; // XXX followup for .getPropertyAsBool("submitReports");
let pluginName = propBag.getPropertyAsAString("pluginName");
let pluginDumpID = propBag.getPropertyAsAString("pluginDumpID");
let browserDumpID = propBag.getPropertyAsAString("browserDumpID");
// Remap the plugin name to a more user-presentable form.
pluginName = this.makeNicePluginName(pluginName);

View File

@ -14,7 +14,7 @@
#include "nsIContent.h"
#include "nsIDocShell.h"
#include "nsIDocument.h"
#include "nsIDOMDataContainerEvent.h"
#include "nsIDOMCustomEvent.h"
#include "nsIDOMDocument.h"
#include "nsIDOMHTMLObjectElement.h"
#include "nsIDOMHTMLAppletElement.h"
@ -318,63 +318,52 @@ nsPluginCrashedEvent::Run()
ErrorResult rv;
nsRefPtr<Event> event =
doc->CreateEvent(NS_LITERAL_STRING("datacontainerevents"), rv);
nsCOMPtr<nsIDOMDataContainerEvent> containerEvent(do_QueryObject(event));
if (!containerEvent) {
doc->CreateEvent(NS_LITERAL_STRING("customevent"), rv);
nsCOMPtr<nsIDOMCustomEvent> customEvent(do_QueryObject(event));
if (!customEvent) {
NS_WARNING("Couldn't QI event for PluginCrashed event!");
return NS_OK;
}
event->InitEvent(NS_LITERAL_STRING("PluginCrashed"), true, true);
nsCOMPtr<nsIWritableVariant> variant;
variant = do_CreateInstance("@mozilla.org/variant;1");
if (!variant) {
NS_WARNING("Couldn't create detail variant for PluginCrashed event!");
return NS_OK;
}
customEvent->InitCustomEvent(NS_LITERAL_STRING("PluginCrashed"),
true, true, variant);
event->SetTrusted(true);
event->GetInternalNSEvent()->mFlags.mOnlyChromeDispatch = true;
nsCOMPtr<nsIWritableVariant> variant;
nsCOMPtr<nsIWritablePropertyBag2> propBag;
propBag = do_CreateInstance("@mozilla.org/hash-property-bag;1");
if (!propBag) {
NS_WARNING("Couldn't create a property bag for PluginCrashed event!");
return NS_OK;
}
// add a "pluginDumpID" property to this event
variant = do_CreateInstance("@mozilla.org/variant;1");
if (!variant) {
NS_WARNING("Couldn't create pluginDumpID variant for PluginCrashed event!");
return NS_OK;
}
variant->SetAsAString(mPluginDumpID);
containerEvent->SetData(NS_LITERAL_STRING("pluginDumpID"), variant);
propBag->SetPropertyAsAString(NS_LITERAL_STRING("pluginDumpID"),
mPluginDumpID);
// add a "browserDumpID" property to this event
variant = do_CreateInstance("@mozilla.org/variant;1");
if (!variant) {
NS_WARNING("Couldn't create browserDumpID variant for PluginCrashed event!");
return NS_OK;
}
variant->SetAsAString(mBrowserDumpID);
containerEvent->SetData(NS_LITERAL_STRING("browserDumpID"), variant);
propBag->SetPropertyAsAString(NS_LITERAL_STRING("browserDumpID"),
mBrowserDumpID);
// add a "pluginName" property to this event
variant = do_CreateInstance("@mozilla.org/variant;1");
if (!variant) {
NS_WARNING("Couldn't create pluginName variant for PluginCrashed event!");
return NS_OK;
}
variant->SetAsAString(mPluginName);
containerEvent->SetData(NS_LITERAL_STRING("pluginName"), variant);
propBag->SetPropertyAsAString(NS_LITERAL_STRING("pluginName"),
mPluginName);
// add a "pluginFilename" property to this event
variant = do_CreateInstance("@mozilla.org/variant;1");
if (!variant) {
NS_WARNING("Couldn't create pluginFilename variant for PluginCrashed event!");
return NS_OK;
}
variant->SetAsAString(mPluginFilename);
containerEvent->SetData(NS_LITERAL_STRING("pluginFilename"), variant);
propBag->SetPropertyAsAString(NS_LITERAL_STRING("pluginFilename"),
mPluginFilename);
// add a "submittedCrashReport" property to this event
variant = do_CreateInstance("@mozilla.org/variant;1");
if (!variant) {
NS_WARNING("Couldn't create crashSubmit variant for PluginCrashed event!");
return NS_OK;
}
variant->SetAsBool(mSubmittedCrashReport);
containerEvent->SetData(NS_LITERAL_STRING("submittedCrashReport"), variant);
propBag->SetPropertyAsBool(NS_LITERAL_STRING("submittedCrashReport"),
mSubmittedCrashReport);
variant->SetAsISupports(propBag);
EventDispatcher::DispatchDOMEvent(mContent, nullptr, event, nullptr, nullptr);
return NS_OK;

View File

@ -92,16 +92,17 @@ function onPluginCrashed(aEvent) {
var pluginElement = document.getElementById("plugin1");
is (pluginElement, aEvent.target, "Plugin crashed event target is plugin element");
ok(aEvent instanceof Ci.nsIDOMDataContainerEvent,
ok(aEvent instanceof Ci.nsIDOMCustomEvent,
"plugin crashed event has the right interface");
var minidumpID = aEvent.getData("minidumpID");
isnot(minidumpID, "", "got a non-empty dump ID");
var pluginName = aEvent.getData("pluginName");
var propBag = aEvent.detail.QueryInterface(Ci.nsIPropertyBag2);
var pluginDumpID = propBag.getPropertyAsAString("pluginDumpID");
isnot(pluginDumpID, "", "got a non-empty dump ID");
var pluginName = propBag.getPropertyAsAString("pluginName");
is(pluginName, "Test Plug-in", "got correct plugin name");
var pluginFilename = aEvent.getData("pluginFilename");
var pluginFilename = propBag.getPropertyAsAString("pluginFilename");
isnot(pluginFilename, "", "got a non-empty filename");
var didReport = aEvent.getData("submittedCrashReport");
var didReport = propBag.getPropertyAsBool("submittedCrashReport");
// The app itself may or may not have decided to submit the report, so
// allow either true or false here.
ok((didReport == true || didReport == false), "event said crash report was submitted");

View File

@ -68,16 +68,17 @@ function onPluginCrashed(aEvent) {
var pluginElement = document.getElementById("plugin1");
is (pluginElement, aEvent.target, "Plugin crashed event target is plugin element");
ok(aEvent instanceof Components.interfaces.nsIDOMDataContainerEvent,
ok(aEvent instanceof Components.interfaces.nsIDOMCustomEvent,
"plugin crashed event has the right interface");
var minidumpID = aEvent.getData("minidumpID");
isnot(minidumpID, "", "got a non-empty dump ID");
var pluginName = aEvent.getData("pluginName");
var propBag = aEvent.detail.QueryInterface(Components.interfaces.nsIPropertyBag2);
var pluginDumpID = propBag.getPropertyAsAString("pluginDumpID");
isnot(pluginDumpID, "", "got a non-empty dump ID");
var pluginName = propBag.getPropertyAsAString("pluginName");
is(pluginName, "Test Plug-in", "got correct plugin name");
var pluginFilename = aEvent.getData("pluginFilename");
var pluginFilename = propBag.getPropertyAsAString("pluginFilename");
isnot(pluginFilename, "", "got a non-empty filename");
var didReport = aEvent.getData("submittedCrashReport");
var didReport = propBag.getPropertyAsBool("submittedCrashReport");
// The app itself may or may not have decided to submit the report, so
// allow either true or false here.
ok((didReport == true || didReport == false), "event said crash report was submitted");

View File

@ -71,11 +71,12 @@ function onPluginCrashed(aEvent) {
var pluginElement = document.getElementById("plugin1");
is (pluginElement, aEvent.target, "Plugin crashed event target is plugin element");
ok(aEvent instanceof Components.interfaces.nsIDOMDataContainerEvent,
ok(aEvent instanceof Components.interfaces.nsIDOMCustomEvent,
"plugin crashed event has the right interface");
var pluginName = aEvent.getData("pluginName");
var propBag = aEvent.detail.QueryInterface(Components.interfaces.nsIPropertyBag2);
var pluginName = propBag.getPropertyAsAString("pluginName");
is(pluginName, "Test Plug-in");
var didReport = aEvent.getData("submittedCrashReport");
var didReport = propBag.getPropertyAsBool("submittedCrashReport");
// The app itself may or may not have decided to submit the report, so
// allow either true or false here.
ok((didReport == true || didReport == false), "event said crash report was submitted");