Bug 810164: Disable bfcache for pages with active PeerConnections; r=smaug,jesup

This commit is contained in:
Anant Narayanan 2012-11-09 15:27:38 -08:00
parent 272e9d57c4
commit 6517e45991
4 changed files with 56 additions and 2 deletions

View File

@ -143,6 +143,7 @@
#ifdef MOZ_MEDIA #ifdef MOZ_MEDIA
#include "nsHTMLMediaElement.h" #include "nsHTMLMediaElement.h"
#endif // MOZ_MEDIA #endif // MOZ_MEDIA
#include "IPeerConnection.h"
#include "mozAutoDocUpdate.h" #include "mozAutoDocUpdate.h"
#include "nsGlobalWindow.h" #include "nsGlobalWindow.h"
@ -6742,6 +6743,18 @@ nsDocument::CanSavePresentation(nsIRequest *aNewRequest)
return false; return false;
} }
// Check if we have active PeerConnections
nsCOMPtr<IPeerConnectionManager> pcManager =
do_GetService(IPEERCONNECTION_MANAGER_CONTRACTID);
if (pcManager && win) {
bool active;
pcManager->HasActivePeerConnection(win->WindowID(), &active);
if (active) {
return false;
}
}
bool canCache = true; bool canCache = true;
if (mSubDocuments) if (mSubDocuments)
PL_DHashTableEnumerate(mSubDocuments, CanCacheSubDocument, &canCache); PL_DHashTableEnumerate(mSubDocuments, CanCacheSubDocument, &canCache);

View File

@ -12,10 +12,12 @@ Cu.import("resource://gre/modules/XPCOMUtils.jsm");
const PC_CONTRACT = "@mozilla.org/dom/peerconnection;1"; const PC_CONTRACT = "@mozilla.org/dom/peerconnection;1";
const PC_ICE_CONTRACT = "@mozilla.org/dom/rtcicecandidate;1"; const PC_ICE_CONTRACT = "@mozilla.org/dom/rtcicecandidate;1";
const PC_SESSION_CONTRACT = "@mozilla.org/dom/rtcsessiondescription;1"; const PC_SESSION_CONTRACT = "@mozilla.org/dom/rtcsessiondescription;1";
const PC_MANAGER_CONTRACT = "@mozilla.org/dom/peerconnectionmanager;1";
const PC_CID = Components.ID("{7cb2b368-b1ce-4560-acac-8e0dbda7d3d0}"); const PC_CID = Components.ID("{7cb2b368-b1ce-4560-acac-8e0dbda7d3d0}");
const PC_ICE_CID = Components.ID("{8c5dbd70-2c8e-4ecb-a5ad-2fc919099f01}"); const PC_ICE_CID = Components.ID("{8c5dbd70-2c8e-4ecb-a5ad-2fc919099f01}");
const PC_SESSION_CID = Components.ID("{5f21ffd9-b73f-4ba0-a685-56b4667aaf1c}"); const PC_SESSION_CID = Components.ID("{5f21ffd9-b73f-4ba0-a685-56b4667aaf1c}");
const PC_MANAGER_CID = Components.ID("{7293e901-2be3-4c02-b4bd-cbef6fc24f78}");
// Global list of PeerConnection objects, so they can be cleaned up when // Global list of PeerConnection objects, so they can be cleaned up when
// a page is torn down. (Maps inner window ID to an array of PC objects). // a page is torn down. (Maps inner window ID to an array of PC objects).
@ -25,7 +27,27 @@ function GlobalPCList() {
} }
GlobalPCList.prototype = { GlobalPCList.prototype = {
QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver, QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver,
Ci.nsISupportsWeakReference]), Ci.nsISupportsWeakReference,
Ci.IPeerConnectionManager]),
classID: PC_MANAGER_CID,
classInfo: XPCOMUtils.generateCI({classID: PC_MANAGER_CID,
contractID: PC_MANAGER_CONTRACT,
classDescription: "PeerConnectionManager",
interfaces: [
Ci.nsIObserver,
Ci.nsISupportsWeakReference,
Ci.IPeerConnectionManager
]}),
_xpcom_factory: {
createInstance: function(outer, iid) {
if (outer) {
throw Components.results.NS_ERROR_NO_AGGREGATION;
}
return _globalPCList.QueryInterface(iid);
}
},
addPC: function(pc) { addPC: function(pc) {
let winID = pc._winID; let winID = pc._winID;
@ -36,6 +58,10 @@ GlobalPCList.prototype = {
} }
}, },
hasActivePeerConnection: function(winID) {
return this._list[winID] ? true : false;
},
observe: function(subject, topic, data) { observe: function(subject, topic, data) {
if (topic != "inner-window-destroyed") { if (topic != "inner-window-destroyed") {
return; return;
@ -675,5 +701,5 @@ PeerConnectionObserver.prototype = {
}; };
this.NSGetFactory = XPCOMUtils.generateNSGetFactory( this.NSGetFactory = XPCOMUtils.generateNSGetFactory(
[IceCandidate, SessionDescription, PeerConnection] [GlobalPCList, IceCandidate, SessionDescription, PeerConnection]
); );

View File

@ -1,10 +1,12 @@
component {7cb2b368-b1ce-4560-acac-8e0dbda7d3d0} PeerConnection.js component {7cb2b368-b1ce-4560-acac-8e0dbda7d3d0} PeerConnection.js
component {8c5dbd70-2c8e-4ecb-a5ad-2fc919099f01} PeerConnection.js component {8c5dbd70-2c8e-4ecb-a5ad-2fc919099f01} PeerConnection.js
component {5f21ffd9-b73f-4ba0-a685-56b4667aaf1c} PeerConnection.js component {5f21ffd9-b73f-4ba0-a685-56b4667aaf1c} PeerConnection.js
component {7293e901-2be3-4c02-b4bd-cbef6fc24f78} PeerConnection.js
contract @mozilla.org/dom/peerconnection;1 {7cb2b368-b1ce-4560-acac-8e0dbda7d3d0} contract @mozilla.org/dom/peerconnection;1 {7cb2b368-b1ce-4560-acac-8e0dbda7d3d0}
contract @mozilla.org/dom/rtcicecandidate;1 {8c5dbd70-2c8e-4ecb-a5ad-2fc919099f01} contract @mozilla.org/dom/rtcicecandidate;1 {8c5dbd70-2c8e-4ecb-a5ad-2fc919099f01}
contract @mozilla.org/dom/rtcsessiondescription;1 {5f21ffd9-b73f-4ba0-a685-56b4667aaf1c} contract @mozilla.org/dom/rtcsessiondescription;1 {5f21ffd9-b73f-4ba0-a685-56b4667aaf1c}
contract @mozilla.org/dom/peerconnectionmanager;1 {7293e901-2be3-4c02-b4bd-cbef6fc24f78}
category JavaScript-global-constructor mozRTCPeerConnection @mozilla.org/dom/peerconnection;1 category JavaScript-global-constructor mozRTCPeerConnection @mozilla.org/dom/peerconnection;1
category JavaScript-global-constructor mozRTCIceCandidate @mozilla.org/dom/rtcicecandidate;1 category JavaScript-global-constructor mozRTCIceCandidate @mozilla.org/dom/rtcicecandidate;1

View File

@ -5,6 +5,19 @@
interface nsIDOMMediaStream; interface nsIDOMMediaStream;
interface nsIDOMDataChannel; interface nsIDOMDataChannel;
/*
* Manager interface to PeerConnection.js so it is accessible from C++.
*/
[scriptable, uuid(c2218bd2-2648-4701-8fa6-305d3379e9f8)]
interface IPeerConnectionManager : nsISupports
{
boolean hasActivePeerConnection(in unsigned long innerWindowID);
};
%{C++
#define IPEERCONNECTION_MANAGER_CONTRACTID "@mozilla.org/dom/peerconnectionmanager;1"
%}
/* Do not confuse with nsIDOMRTCPeerConnection. This interface is purely for /* Do not confuse with nsIDOMRTCPeerConnection. This interface is purely for
* communication between the PeerConnection JS DOM binding and the C++ * communication between the PeerConnection JS DOM binding and the C++
* implementation in SIPCC. * implementation in SIPCC.