Bug 1043531 - Move PluginCrashed event generation to C++. r=smaug,jesup

This commit is contained in:
Georg Fritzsche 2014-07-28 17:41:52 +02:00
parent 6c0422fdd6
commit 34be6cd058
4 changed files with 92 additions and 22 deletions

View File

@ -108,22 +108,12 @@ GlobalPCList.prototype = {
} }
}; };
let hasPluginId = function(list, winID, pluginID, name, crashReport) { let broadcastPluginCrash = function(list, winID, pluginID, name, crashReportID) {
if (list.hasOwnProperty(winID)) { if (list.hasOwnProperty(winID)) {
list[winID].forEach(function(pcref) { list[winID].forEach(function(pcref) {
let pc = pcref.get(); let pc = pcref.get();
if (pc) { if (pc) {
if (pc._pc.pluginCrash(pluginID)) { pc._pc.pluginCrash(pluginID, name, crashReportID);
// Notify DOM window of the crash
let event = new CustomEvent("PluginCrashed",
{ bubbles: false, cancelable: false,
detail: {
pluginName: name,
pluginDumpId: crashReport,
submittedCrashReport: false }
});
pc._win.dispatchEvent(event);
}
} }
}); });
} }
@ -167,8 +157,8 @@ GlobalPCList.prototype = {
let name = rest.slice(0, sep); let name = rest.slice(0, sep);
let crashId = rest.slice(sep+1); let crashId = rest.slice(sep+1);
for (let winId in this._list) { for (let winId in this._list) {
hasPluginId(this._list, winId, pluginId, name, crashId); broadcastPluginCrash(this._list, winId, pluginId, name, crashId);
} }
} }
}, },

View File

@ -60,8 +60,8 @@ interface PeerConnectionImpl {
/* Puts the SIPCC engine back to 'kIdle', shuts down threads, deletes state */ /* Puts the SIPCC engine back to 'kIdle', shuts down threads, deletes state */
void close(); void close();
/* Notify DOM window if this plugin crash is ours */ /* Notify DOM window if this plugin crash is ours. */
boolean pluginCrash(unsigned long long pluginId); boolean pluginCrash(unsigned long long pluginId, DOMString name, DOMString pluginDumpID);
/* Attributes */ /* Attributes */
readonly attribute DOMString fingerprint; readonly attribute DOMString fingerprint;

View File

@ -45,6 +45,16 @@
#include "dtlsidentity.h" #include "dtlsidentity.h"
#ifdef MOZILLA_INTERNAL_API #ifdef MOZILLA_INTERNAL_API
#ifdef XP_WIN
// We need to undef the MS macro for nsIDocument::CreateEvent
#ifdef CreateEvent
#undef CreateEvent
#endif
#endif // XP_WIN
#ifdef MOZILLA_INTERNAL_API
#include "nsIDocument.h"
#endif
#include "nsPerformance.h" #include "nsPerformance.h"
#include "nsGlobalWindow.h" #include "nsGlobalWindow.h"
#include "nsDOMDataChannel.h" #include "nsDOMDataChannel.h"
@ -55,7 +65,6 @@
#include "nsXULAppAPI.h" #include "nsXULAppAPI.h"
#include "nsContentUtils.h" #include "nsContentUtils.h"
#include "nsDOMJSUtils.h" #include "nsDOMJSUtils.h"
#include "nsIDocument.h"
#include "nsIScriptError.h" #include "nsIScriptError.h"
#include "nsPrintfCString.h" #include "nsPrintfCString.h"
#include "nsURLHelper.h" #include "nsURLHelper.h"
@ -77,8 +86,19 @@
#include "DOMMediaStream.h" #include "DOMMediaStream.h"
#include "rlogringbuffer.h" #include "rlogringbuffer.h"
#include "WebrtcGlobalInformation.h" #include "WebrtcGlobalInformation.h"
#include "mozilla/dom/Event.h"
#include "nsIDOMCustomEvent.h"
#include "mozilla/EventDispatcher.h"
#endif #endif
#ifdef XP_WIN
// We need to undef the MS macro again in case the windows include file
// got imported after we included nsIDocument.h
#ifdef CreateEvent
#undef CreateEvent
#endif
#endif // XP_WIN
#ifndef USE_FAKE_MEDIA_STREAMS #ifndef USE_FAKE_MEDIA_STREAMS
#include "MediaSegment.h" #include "MediaSegment.h"
#endif #endif
@ -1637,14 +1657,72 @@ PeerConnectionImpl::Close()
} }
bool bool
PeerConnectionImpl::PluginCrash(uint64_t aPluginID) PeerConnectionImpl::PluginCrash(uint64_t aPluginID,
const nsAString& aPluginName,
const nsAString& aPluginDumpID)
{ {
// fire an event to the DOM window if this is "ours" // fire an event to the DOM window if this is "ours"
bool result = mMedia ? mMedia->AnyCodecHasPluginID(aPluginID) : false; bool result = mMedia ? mMedia->AnyCodecHasPluginID(aPluginID) : false;
if (result) { if (!result) {
CSFLogError(logTag, "%s: Our plugin %llu crashed", __FUNCTION__, static_cast<unsigned long long>(aPluginID)); return false;
} }
return result;
CSFLogError(logTag, "%s: Our plugin %llu crashed", __FUNCTION__, static_cast<unsigned long long>(aPluginID));
#ifdef MOZILLA_INTERNAL_API
nsCOMPtr<nsIDocument> doc = mWindow->GetExtantDoc();
if (!doc) {
NS_WARNING("Couldn't get document for PluginCrashed event!");
return true;
}
ErrorResult rv;
nsRefPtr<Event> event =
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 true;
}
nsCOMPtr<nsIWritableVariant> variant;
variant = do_CreateInstance("@mozilla.org/variant;1");
if (!variant) {
NS_WARNING("Couldn't create detail variant for PluginCrashed event!");
return true;
}
customEvent->InitCustomEvent(NS_LITERAL_STRING("PluginCrashed"),
true, true, variant);
event->SetTrusted(true);
event->GetInternalNSEvent()->mFlags.mOnlyChromeDispatch = true;
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 true;
}
// add a "pluginDumpID" property to this event
propBag->SetPropertyAsAString(NS_LITERAL_STRING("pluginDumpID"),
aPluginDumpID);
// add a "pluginName" property to this event
propBag->SetPropertyAsAString(NS_LITERAL_STRING("pluginName"),
aPluginName);
// add a "submittedCrashReport" property to this event
propBag->SetPropertyAsBool(NS_LITERAL_STRING("submittedCrashReport"),
false);
variant->SetAsISupports(propBag);
EventDispatcher::DispatchDOMEvent(mWindow, nullptr, event, nullptr, nullptr);
#endif
return true;
} }
nsresult nsresult

View File

@ -482,7 +482,9 @@ public:
rv = Close(); rv = Close();
} }
bool PluginCrash(uint64_t aPluginID); bool PluginCrash(uint64_t aPluginID,
const nsAString& aPluginName,
const nsAString& aPluginDumpID);
nsresult InitializeDataChannel(int track_id, uint16_t aLocalport, nsresult InitializeDataChannel(int track_id, uint16_t aLocalport,
uint16_t aRemoteport, uint16_t aNumstreams); uint16_t aRemoteport, uint16_t aNumstreams);