Bug 814497 - Cleanup console service cache when a window is destroyed. r=nfroyd

This commit is contained in:
Alexandre Poirot 2015-07-09 06:49:00 -04:00
parent 6ee2137af7
commit 653adb0d6f
3 changed files with 53 additions and 1 deletions

View File

@ -42,6 +42,7 @@
#include "WindowNamedPropertiesHandler.h"
#include "nsFrameSelection.h"
#include "nsNetUtil.h"
#include "nsIConsoleService.h"
// Helper Classes
#include "nsJSUtils.h"
@ -1562,6 +1563,12 @@ nsGlobalWindow::FreeInnerObjects()
{
NS_ASSERTION(IsInnerWindow(), "Don't free inner objects on an outer window");
// Prune messages related to this window in the console cache
nsCOMPtr<nsIConsoleService> console(do_GetService("@mozilla.org/consoleservice;1"));
if (console) {
console->ClearMessagesForWindowID(mWindowID);
}
// Make sure that this is called before we null out the document and
// other members that the window destroyed observers could
// re-create.

View File

@ -20,6 +20,7 @@
#include "nsIClassInfoImpl.h"
#include "nsIConsoleListener.h"
#include "nsPrintfCString.h"
#include "nsIScriptError.h"
#include "mozilla/Preferences.h"
@ -66,6 +67,45 @@ nsConsoleService::nsConsoleService()
mBufferSize = 250;
}
NS_IMETHODIMP
nsConsoleService::ClearMessagesForWindowID(const uint64_t innerID)
{
// Remove the messages related to this window
for (uint32_t i = 0; i < mBufferSize && mMessages[i]; i++) {
// Only messages implementing nsIScriptError interface exposes the inner window ID
nsCOMPtr<nsIScriptError> scriptError = do_QueryInterface(mMessages[i]);
if (!scriptError) {
continue;
}
uint64_t innerWindowID;
nsresult rv = scriptError->GetInnerWindowID(&innerWindowID);
if (NS_FAILED(rv) || innerWindowID != innerID) {
continue;
}
// Free this matching message!
NS_RELEASE(mMessages[i]);
uint32_t j = i;
// Now shift all the following messages
for (; j < mBufferSize - 1 && mMessages[j + 1]; j++) {
mMessages[j] = mMessages[j + 1];
}
// Nullify the current slot
mMessages[j] = nullptr;
mCurrent = j;
// The array is no longer full
mFull = false;
// Ensure the next iteration handles the messages we just shifted down
i--;
}
return NS_OK;
}
nsConsoleService::~nsConsoleService()
{
uint32_t i = 0;

View File

@ -8,7 +8,7 @@
interface nsIConsoleListener;
interface nsIConsoleMessage;
[scriptable, uuid(0eb81d20-c37e-42d4-82a8-ca9ae96bdf52)]
[scriptable, uuid(2436031e-2167-4307-9f1c-a3f38b55a224)]
interface nsIConsoleService : nsISupports
{
void logMessage(in nsIConsoleMessage message);
@ -44,6 +44,11 @@ interface nsIConsoleService : nsISupports
* Clear the message buffer (e.g. for privacy reasons).
*/
void reset();
/**
* Clear the message buffer for a given inner window.
*/
void clearMessagesForWindowID(in uint64_t innerWindowID);
};