Bug 965860 - patch 1 - Convert ConsoleAPIStorage in a Service, r=msucan, r=khuey

--HG--
rename : dom/base/ConsoleAPIStorage.jsm => dom/base/ConsoleAPIStorage.js
This commit is contained in:
Andrea Marchesini 2014-02-27 23:38:54 +00:00
parent 541e0d0cbf
commit ed28ed334a
16 changed files with 91 additions and 23 deletions

View File

@ -340,6 +340,7 @@
; JavaScript components
@BINPATH@/components/ConsoleAPI.manifest
@BINPATH@/components/ConsoleAPI.js
@BINPATH@/components/ConsoleAPIStorage.js
@BINPATH@/components/BrowserElementParent.manifest
@BINPATH@/components/BrowserElementParent.js
@BINPATH@/components/ContactManager.js

View File

@ -7,7 +7,7 @@
function test()
{
let storage = Cu.import("resource://gre/modules/ConsoleAPIStorage.jsm", {}).ConsoleAPIStorage;
let storage = Cc["@mozilla.org/consoleAPI-storage;1"].getService(Ci.nsIConsoleAPIStorage);
storage.clearEvents();
let console = Cu.import("resource://gre/modules/devtools/Console.jsm", {}).console;

View File

@ -11,7 +11,8 @@ function test()
const TEST_URI = "data:text/html;charset=utf8,<p>hello world! bug 874061" +
"<button onclick='console.log(\"foobar bug 874061\");" +
"fooBazBaz.yummy()'>click</button>";
let ConsoleAPIStorage = Cu.import("resource://gre/modules/ConsoleAPIStorage.jsm", {}).ConsoleAPIStorage;
let ConsoleAPIStorage = Cc["@mozilla.org/consoleAPI-storage;1"]
.getService(Ci.nsIConsoleAPIStorage);
let privateWindow, privateBrowser, privateTab, privateContent;
let hud, expectedMessages, nonPrivateMessage;

View File

@ -347,6 +347,7 @@
; JavaScript components
@BINPATH@/components/ConsoleAPI.manifest
@BINPATH@/components/ConsoleAPI.js
@BINPATH@/components/ConsoleAPIStorage.js
@BINPATH@/components/BrowserElementParent.manifest
@BINPATH@/components/BrowserElementParent.js
@BINPATH@/components/FeedProcessor.manifest

View File

@ -31,9 +31,12 @@ const MESSAGES_IN_INTERVAL = 1500;
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/ConsoleAPIStorage.jsm");
Cu.import("resource://gre/modules/PrivateBrowsingUtils.jsm");
XPCOMUtils.defineLazyServiceGetter(this, "ConsoleAPIStorage",
"@mozilla.org/consoleAPI-storage;1",
"nsIConsoleAPIStorage");
/**
* The window.console API implementation. One instance is lazily created for
* every inner window, when the window.console object is accessed.

View File

@ -1,3 +1,5 @@
component {b49c18f8-3379-4fc0-8c90-d7772c1a9ff3} ConsoleAPI.js
contract @mozilla.org/console-api;1 {b49c18f8-3379-4fc0-8c90-d7772c1a9ff3}
category JavaScript-global-property console @mozilla.org/console-api;1
component {96cf7855-dfa9-4c6d-8276-f9705b4890f2} ConsoleAPIStorage.js
contract @mozilla.org/consoleAPI-storage;1 {96cf7855-dfa9-4c6d-8276-f9705b4890f2}

View File

@ -13,10 +13,10 @@ Cu.import("resource://gre/modules/Services.jsm");
const STORAGE_MAX_EVENTS = 200;
this.EXPORTED_SYMBOLS = ["ConsoleAPIStorage"];
var _consoleStorage = new Map();
const CONSOLEAPISTORAGE_CID = Components.ID('{96cf7855-dfa9-4c6d-8276-f9705b4890f2}');
/**
* The ConsoleAPIStorage is meant to cache window.console API calls for later
* reuse by other components when needed. For example, the Web Console code can
@ -38,9 +38,20 @@ var _consoleStorage = new Map();
* // Clear the events for the given inner window ID.
* ConsoleAPIStorage.clearEvents(innerWindowID);
*/
this.ConsoleAPIStorage = {
function ConsoleAPIStorageService() {
this.init();
}
QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver]),
ConsoleAPIStorageService.prototype = {
classID : CONSOLEAPISTORAGE_CID,
QueryInterface: XPCOMUtils.generateQI([Ci.nsIConsoleAPIStorage,
Ci.nsIObserver]),
classInfo: XPCOMUtils.generateCI({
classID: CONSOLEAPISTORAGE_CID,
contractID: '@mozilla.org/consoleAPI-storage;1',
interfaces: [Ci.nsIConsoleAPIStorage, Ci.nsIObserver],
flags: Ci.nsIClassInfo.SINGLETON
}),
observe: function CS_observe(aSubject, aTopic, aData)
{
@ -140,4 +151,4 @@ this.ConsoleAPIStorage = {
},
};
ConsoleAPIStorage.init();
this.NSGetFactory = XPCOMUtils.generateNSGetFactory([ConsoleAPIStorageService]);

View File

@ -7,6 +7,7 @@
TEST_DIRS += ['test']
XPIDL_SOURCES += [
'nsIConsoleAPIStorage.idl',
'nsIDOMDOMCursor.idl',
'nsIDOMDOMRequest.idl',
'nsIEntropyCollector.idl',
@ -119,12 +120,12 @@ SOURCES += [
EXTRA_COMPONENTS += [
'ConsoleAPI.js',
'ConsoleAPI.manifest',
'ConsoleAPIStorage.js',
'SiteSpecificUserAgent.js',
'SiteSpecificUserAgent.manifest',
]
EXTRA_JS_MODULES += [
'ConsoleAPIStorage.jsm',
'DOMRequestHelper.jsm',
'IndexedDBHelper.jsm',
'ObjectWrapper.jsm',

View File

@ -0,0 +1,44 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsISupports.idl"
[scriptable, uuid(6701600a-17ca-417e-98f9-4ceb175dd15d)]
interface nsIConsoleAPIStorage : nsISupports
{
/**
* Get the events array by inner window ID or all events from all windows.
*
* @param string [aId]
* Optional, the inner window ID for which you want to get the array of
* cached events.
* @returns array
* The array of cached events for the given window. If no |aId| is
* given this function returns all of the cached events, from any
* window.
*/
jsval getEvents([optional] in DOMString aId);
/**
* Record an event associated with the given window ID.
*
* @param string aId
* The ID of the inner window for which the event occurred or "jsm" for
* messages logged from JavaScript modules..
* @param object aEvent
* A JavaScript object you want to store.
*/
void recordEvent(in DOMString aId, in jsval aEvent);
/**
* Clear storage data for the given window.
*
* @param string [aId]
* Optional, the inner window ID for which you want to clear the
* messages. If this is not specified all of the cached messages are
* cleared, from all window objects.
*/
void clearEvents([optional] in DOMString aId);
};

View File

@ -4,9 +4,8 @@
const TEST_URI = "http://example.com/browser/dom/tests/browser/test-console-api.html";
const TEST_URI_NAV = "http://example.com/browser/dom/tests/browser/";
let tempScope = {};
Cu.import("resource://gre/modules/ConsoleAPIStorage.jsm", tempScope);
let ConsoleAPIStorage = tempScope.ConsoleAPIStorage;
let ConsoleAPIStorage = Cc["@mozilla.org/consoleAPI-storage;1"]
.getService(Ci.nsIConsoleAPIStorage);
var apiCallCount;

View File

@ -12,8 +12,8 @@ function test() {
let consoleObserver;
let testURI =
"http://example.com/browser/dom/tests/browser/test-console-api.html";
let CSS = {};
Cu.import("resource://gre/modules/ConsoleAPIStorage.jsm", CSS);
let ConsoleAPIStorage = Cc["@mozilla.org/consoleAPI-storage;1"]
.getService(Ci.nsIConsoleAPIStorage);
function getInnerWindowId(aWindow) {
return aWindow.QueryInterface(Ci.nsIInterfaceRequestor)
@ -36,7 +36,7 @@ function test() {
consoleObserver = {
observe: function(aSubject, aTopic, aData) {
if (aTopic == "console-api-log-event") {
afterEvents = CSS.ConsoleAPIStorage.getEvents(innerID);
afterEvents = ConsoleAPIStorage.getEvents(innerID);
is(beforeEvents.length == afterEvents.length - 1, storageShouldOccur,
"storage should" + (storageShouldOccur ? "" : " not") + " occur");
@ -56,7 +56,7 @@ function test() {
// We expect that console API messages are always stored.
storageShouldOccur = true;
innerID = getInnerWindowId(aWindow);
beforeEvents = CSS.ConsoleAPIStorage.getEvents(innerID);
beforeEvents = ConsoleAPIStorage.getEvents(innerID);
aWindow.gBrowser.selectedBrowser.loadURI(testURI);
}

View File

@ -281,6 +281,7 @@
; JavaScript components
@BINPATH@/components/ConsoleAPI.manifest
@BINPATH@/components/ConsoleAPI.js
@BINPATH@/components/ConsoleAPIStorage.js
@BINPATH@/components/ContactManager.js
@BINPATH@/components/ContactManager.manifest
@BINPATH@/components/PhoneNumberService.js

View File

@ -22,10 +22,9 @@
this.EXPORTED_SYMBOLS = [ "console", "ConsoleAPI" ];
const Cu = Components.utils;
const {classes: Cc, interfaces: Ci, utils: Cu} = Components;
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/ConsoleAPIStorage.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "Services",
"resource://gre/modules/Services.jsm");
@ -558,6 +557,8 @@ function sendConsoleAPIMessage(aLevel, aFrame, aArgs, aOptions = {})
}
Services.obs.notifyObservers(consoleEvent, "console-api-log-event", null);
let ConsoleAPIStorage = Cc["@mozilla.org/consoleAPI-storage;1"]
.getService(Ci.nsIConsoleAPIStorage);
ConsoleAPIStorage.recordEvent("jsm", consoleEvent);
}

View File

@ -17,9 +17,6 @@ let devtools = Cu.import("resource://gre/modules/devtools/Loader.jsm", {}).devto
XPCOMUtils.defineLazyModuleGetter(this, "Services",
"resource://gre/modules/Services.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "ConsoleAPIStorage",
"resource://gre/modules/ConsoleAPIStorage.jsm");
for (let name of ["WebConsoleUtils", "ConsoleServiceListener",
"ConsoleAPIListener", "ConsoleProgressListener",
"JSTermHelpers", "JSPropertyProvider", "NetworkMonitor",
@ -778,7 +775,10 @@ WebConsoleActor.prototype =
// TODO: Bug 717611 - Web Console clear button does not clear cached errors
let windowId = !this.parentActor.isRootActor ?
WebConsoleUtils.getInnerWindowId(this.window) : null;
let ConsoleAPIStorage = Cc["@mozilla.org/consoleAPI-storage;1"]
.getService(Ci.nsIConsoleAPIStorage);
ConsoleAPIStorage.clearEvents(windowId);
if (this.parentActor.isRootActor) {
Services.console.logStringMessage(null); // for the Error Console
Services.console.reset();

View File

@ -8,11 +8,13 @@ const {classes: Cc, interfaces: Ci, utils: Cu} = Components;
const XHTML_NS = "http://www.w3.org/1999/xhtml";
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/ConsoleAPIStorage.jsm");
let devtools = Cu.import("resource://gre/modules/devtools/Loader.jsm", {}).devtools;
let WebConsoleUtils = devtools.require("devtools/toolkit/webconsole/utils").Utils;
let ConsoleAPIStorage = Cc["@mozilla.org/consoleAPI-storage;1"]
.getService(Ci.nsIConsoleAPIStorage);
let {ConsoleServiceListener, ConsoleAPIListener} =
devtools.require("devtools/toolkit/webconsole/utils");

View File

@ -12,7 +12,6 @@ Cu.import("resource://gre/modules/XPCOMUtils.jsm");
loader.lazyGetter(this, "NetworkHelper", () => require("devtools/toolkit/webconsole/network-helper"));
loader.lazyImporter(this, "Services", "resource://gre/modules/Services.jsm");
loader.lazyImporter(this, "ConsoleAPIStorage", "resource://gre/modules/ConsoleAPIStorage.jsm");
loader.lazyImporter(this, "NetUtil", "resource://gre/modules/NetUtil.jsm");
loader.lazyImporter(this, "PrivateBrowsingUtils", "resource://gre/modules/PrivateBrowsingUtils.jsm");
loader.lazyImporter(this, "LayoutHelpers", "resource://gre/modules/devtools/LayoutHelpers.jsm");
@ -1327,6 +1326,8 @@ ConsoleAPIListener.prototype =
getCachedMessages: function CAL_getCachedMessages(aIncludePrivate = false)
{
let messages = [];
let ConsoleAPIStorage = Cc["@mozilla.org/consoleAPI-storage;1"]
.getService(Ci.nsIConsoleAPIStorage);
// if !this.window, we're in a browser console. Retrieve all events
// for filtering based on privacy.