Merge mozilla-inbound to mozilla-central

This commit is contained in:
Marco Bonardo 2011-06-29 11:18:14 +02:00
commit b4624606bd
28 changed files with 413 additions and 126 deletions

View File

@ -147,6 +147,12 @@ SessionStartup.prototype = {
initialState && initialState.session && initialState.session.state &&
initialState.session.state == STATE_RUNNING_STR;
// Report shutdown success via telemetry. Shortcoming here are
// being-killed-by-OS-shutdown-logic, shutdown freezing after
// session restore was written, etc.
let Telemetry = Cc["@mozilla.org/base/telemetry;1"].getService(Ci.nsITelemetry);
Telemetry.getHistogramById("SHUTDOWN_OK").add(!lastSessionCrashed);
// set the startup type
if (lastSessionCrashed && resumeFromCrash)
this._sessionType = Ci.nsISessionStartup.RECOVER_SESSION;

View File

@ -55,6 +55,7 @@ endif
DIRS += pgo
ifdef ENABLE_TESTS
ifeq (Android,$(OS_TARGET))
DIRS += mobile/sutagent/android \
mobile/sutagent/android/watcher \
@ -62,6 +63,7 @@ ifeq (Android,$(OS_TARGET))
mobile/sutagent/android/fencp \
$(NULL)
endif
endif
include $(topsrcdir)/config/rules.mk

View File

@ -61,5 +61,6 @@ CPPSRCS = \
include $(topsrcdir)/config/rules.mk
INCLUDES += -I$(srcdir)/../include \
-I$(topsrcdir)/js/src/xpconnect/src
-I$(topsrcdir)/js/src/xpconnect/src \
-I$(topsrcdir)/dom/base

View File

@ -53,6 +53,10 @@
#include "nsNetCID.h"
#include "nsIClassInfoImpl.h"
#include "jsobj.h"
#include "nsJSUtils.h"
#include "nsPIDOMWindow.h"
#include "nsIScriptGlobalObject.h"
#include "nsIDocument.h"
///////////////////////
// nsSecurityNameSet //
@ -157,6 +161,23 @@ netscape_security_enablePrivilege(JSContext *cx, uintN argc, jsval *vp)
if (!getBytesArgument(cx, obj, 0, argc, JS_ARGV(cx, vp), &cap))
return JS_FALSE;
// Can't use nsContentUtils::GetDocumentFromCaller because that
// depends on various XPConnect stuff that's not set up here.
{
JSAutoEnterCompartment ac;
if (ac.enter(cx, obj)) {
nsCOMPtr<nsPIDOMWindow> win =
do_QueryInterface(nsJSUtils::GetStaticScriptGlobal(cx, obj));
if (win) {
nsCOMPtr<nsIDocument> doc =
do_QueryInterface(win->GetExtantDocument());
if (doc) {
doc->WarnOnceAbout(nsIDocument::eEnablePrivilege);
}
}
}
}
nsresult rv;
nsCOMPtr<nsIScriptSecurityManager> securityManager =
do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv);

View File

@ -54,6 +54,7 @@ nsContentErrors.h \
nsContentPolicyUtils.h \
nsContentUtils.h \
nsIDocument.h \
nsDeprecatedOperationList.h \
nsIDocumentObserver.h \
nsIMutationObserver.h \
nsIMutationObserver2.h \

View File

@ -0,0 +1,73 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Mozilla Foundation.
* Portions created by the Initial Developer are Copyright (C) 2011
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/*
* This file contains the list of deprecated DOM operations. It is
* designed to be used as input to the C preprocessor *only*.
*/
DEPRECATED_OPERATION(GetAttributeNode)
DEPRECATED_OPERATION(SetAttributeNode)
DEPRECATED_OPERATION(GetAttributeNodeNS)
DEPRECATED_OPERATION(SetAttributeNodeNS)
DEPRECATED_OPERATION(RemoveAttributeNode)
DEPRECATED_OPERATION(CreateAttribute)
DEPRECATED_OPERATION(CreateAttributeNS)
DEPRECATED_OPERATION(Specified)
DEPRECATED_OPERATION(OwnerElement)
DEPRECATED_OPERATION(NodeName)
DEPRECATED_OPERATION(NodeValue)
DEPRECATED_OPERATION(NodeType)
DEPRECATED_OPERATION(ParentNode)
DEPRECATED_OPERATION(ChildNodes)
DEPRECATED_OPERATION(HasChildNodes)
DEPRECATED_OPERATION(HasAttributes)
DEPRECATED_OPERATION(FirstChild)
DEPRECATED_OPERATION(LastChild)
DEPRECATED_OPERATION(PreviousSibling)
DEPRECATED_OPERATION(NextSibling)
DEPRECATED_OPERATION(Attributes)
DEPRECATED_OPERATION(InsertBefore)
DEPRECATED_OPERATION(ReplaceChild)
DEPRECATED_OPERATION(RemoveChild)
DEPRECATED_OPERATION(AppendChild)
DEPRECATED_OPERATION(CloneNode)
DEPRECATED_OPERATION(OwnerDocument)
DEPRECATED_OPERATION(Normalize)
DEPRECATED_OPERATION(IsSupported)
DEPRECATED_OPERATION(IsEqualNode)
DEPRECATED_OPERATION(TextContent)
DEPRECATED_OPERATION(EnablePrivilege)

View File

@ -1526,39 +1526,12 @@ public:
virtual Element* FindImageMap(const nsAString& aNormalizedMapName) = 0;
#define DEPRECATED_OPERATION(_op) e##_op,
enum DeprecatedOperations {
eGetAttributeNode = 0,
eSetAttributeNode,
eGetAttributeNodeNS,
eSetAttributeNodeNS,
eRemoveAttributeNode,
eCreateAttribute,
eCreateAttributeNS,
eSpecified,
eOwnerElement,
eNodeName,
eNodeValue,
eNodeType,
eParentNode,
eChildNodes,
eHasChildNodes,
eHasAttributes,
eFirstChild,
eLastChild,
ePreviousSibling,
eNextSibling,
eAttributes,
eInsertBefore,
eReplaceChild,
eRemoveChild,
eAppendChild,
eCloneNode,
eOwnerDocument,
eNormalize,
eIsSupported,
eIsEqualNode,
eTextContent
#include "nsDeprecatedOperationList.h"
eDeprecatedOperationCount
};
#undef DEPRECATED_OPERATION
void WarnOnceAbout(DeprecatedOperations aOperation);
private:

View File

@ -564,6 +564,9 @@ nsContentUtils::InitializeEventTable() {
{ nsGkAtoms::onMozTouchMove, NS_MOZTOUCH_MOVE, EventNameType_None, NS_MOZTOUCH_EVENT },
{ nsGkAtoms::onMozTouchUp, NS_MOZTOUCH_UP, EventNameType_None, NS_MOZTOUCH_EVENT },
{ nsGkAtoms::ondevicemotion, NS_DEVICE_MOTION, EventNameType_None, NS_EVENT },
{ nsGkAtoms::ondeviceorientation, NS_DEVICE_ORIENTATION, EventNameType_None, NS_EVENT },
{ nsGkAtoms::ontransitionend, NS_TRANSITION_END, EventNameType_None, NS_TRANSITION_EVENT },
{ nsGkAtoms::onanimationstart, NS_ANIMATION_START, EventNameType_None, NS_ANIMATION_EVENT },
{ nsGkAtoms::onanimationend, NS_ANIMATION_END, EventNameType_None, NS_ANIMATION_EVENT },

View File

@ -8130,43 +8130,17 @@ nsDocument::FindImageMap(const nsAString& aUseMapValue)
return nsnull;
}
#define DEPRECATED_OPERATION(_op) #_op "Warning",
static const char* kWarnings[] = {
"GetAttributeNodeWarning",
"SetAttributeNodeWarning",
"GetAttributeNodeNSWarning",
"SetAttributeNodeNSWarning",
"RemoveAttributeNodeWarning",
"CreateAttributeWarning",
"CreateAttributeNSWarning",
"SpecifiedWarning",
"OwnerElementWarning",
"NodeNameWarning",
"NodeValueWarning",
"NodeTypeWarning",
"ParentNodeWarning",
"ChildNodesWarning",
"HasChildNodesWarning",
"HasAttributesWarning",
"FirstChildWarning",
"LastChildWarning",
"PreviousSiblingWarning",
"NextSiblingWarning",
"AttributesWarning",
"InsertBeforeWarning",
"ReplaceChildWarning",
"RemoveChildWarning",
"AppendChildWarning",
"CloneNodeWarning",
"GetOwnerDocumentWarning",
"IsSupportedWarning",
"IsEqualNodeWarning",
"TextContentWarning"
#include "nsDeprecatedOperationList.h"
nsnull
};
#undef DEPRECATED_OPERATION
void
nsIDocument::WarnOnceAbout(DeprecatedOperations aOperation)
{
PR_STATIC_ASSERT(NS_ARRAY_LENGTH(kWarnings) < 32);
PR_STATIC_ASSERT(eDeprecatedOperationCount <= 32);
if (mWarnedAbout & (1 << aOperation)) {
return;
}

View File

@ -108,7 +108,9 @@ static const char* const sEventNames[] = {
"transitionend",
"animationstart",
"animationend",
"animationiteration"
"animationiteration",
"devicemotion",
"deviceorientation"
};
static char *sPopupAllowedEvents;
@ -1361,6 +1363,10 @@ const char* nsDOMEvent::GetEventName(PRUint32 aEventType)
return sEventNames[eDOMEvents_animationend];
case NS_ANIMATION_ITERATION:
return sEventNames[eDOMEvents_animationiteration];
case NS_DEVICE_MOTION:
return sEventNames[eDOMEvents_devicemotion];
case NS_DEVICE_ORIENTATION:
return sEventNames[eDOMEvents_deviceorientation];
default:
break;
}

View File

@ -192,7 +192,9 @@ public:
eDOMEvents_transitionend,
eDOMEvents_animationstart,
eDOMEvents_animationend,
eDOMEvents_animationiteration
eDOMEvents_animationiteration,
eDOMEvents_devicemotion,
eDOMEvents_deviceorientation
};
nsDOMEvent(nsPresContext* aPresContext, nsEvent* aEvent);

View File

@ -104,7 +104,9 @@ _TEST_FILES = \
test_bug656379-1.html \
test_bug656379-2.html \
test_bug656954.html \
test_bug662678.html \
test_bug662678.html \
test_bug667919-1.html \
test_bug667919-2.html \
$(NULL)
#bug 585630

View File

@ -0,0 +1,42 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=615597
-->
<head>
<title>Test for Bug 615597</title>
<script type="application/javascript" src="/MochiKit/packed.js"></script>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=615597">Mozilla Bug 615597</a>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
<script type="application/javascript">
/** Test for Bug 615597 **/
window.ondeviceorientation = function(event) {
is(event.alpha, 1.5);
is(event.beta, 2.25);
is(event.gamma, 3.667);
is(event.absolute, true);
SimpleTest.finish();
};
var event = DeviceOrientationEvent;
ok(!!event, "Should have seen DeviceOrientationEvent!");
event = document.createEvent("DeviceOrientationEvent");
event.initDeviceOrientationEvent('deviceorientation', true, true, 1.5, 2.25, 3.667, true);
window.dispatchEvent(event);
SimpleTest.waitForExplicitFinish();
</script>
</pre>
</body>
</html>

View File

@ -0,0 +1,42 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=615597
-->
<head>
<title>Test for Bug 615597</title>
<script type="application/javascript" src="/MochiKit/packed.js"></script>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=615597">Mozilla Bug 615597</a>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
<script type="application/javascript">
/** Test for Bug 615597 **/
window.ondeviceorientation = function(event) {
is(event.alpha, 1.5);
is(event.beta, 2.25);
is(event.gamma, 3.667);
is(event.absolute, true);
SimpleTest.finish();
};
var event = DeviceOrientationEvent;
ok(!!event, "Should have seen DeviceOrientationEvent!");
event = document.createEvent("DeviceOrientationEvent");
event.initDeviceOrientationEvent('deviceorientation', true, true, 1.5, 2.25, 3.667, true);
window.dispatchEvent(event);
SimpleTest.waitForExplicitFinish();
</script>
</pre>
</body>
</html>

View File

@ -1707,6 +1707,9 @@ jsid nsDOMClassInfo::sOntouchcancel_id = JSID_VOID;
jsid nsDOMClassInfo::sOnbeforeprint_id = JSID_VOID;
jsid nsDOMClassInfo::sOnafterprint_id = JSID_VOID;
jsid nsDOMClassInfo::sOndevicemotion_id = JSID_VOID;
jsid nsDOMClassInfo::sOndeviceorientation_id = JSID_VOID;
static const JSClass *sObjectClass = nsnull;
/**
@ -2043,6 +2046,9 @@ nsDOMClassInfo::DefineStaticJSVals(JSContext *cx)
SET_JSID_TO_STRING(sOntouchcancel_id, cx, "ontouchcancel");
SET_JSID_TO_STRING(sOnbeforeprint_id, cx, "onbeforeprint");
SET_JSID_TO_STRING(sOnafterprint_id, cx, "onafterprint");
SET_JSID_TO_STRING(sOndevicemotion_id, cx, "ondevicemotion");
SET_JSID_TO_STRING(sOndeviceorientation_id, cx, "ondeviceorientation");
return NS_OK;
}
@ -7653,7 +7659,9 @@ nsEventReceiverSH::ReallyIsEventName(jsid id, jschar aFirstChar)
id == sOndragover_id ||
id == sOndragstart_id ||
id == sOndrop_id ||
id == sOndurationchange_id);
id == sOndurationchange_id ||
id == sOndeviceorientation_id ||
id == sOndevicemotion_id );
case 'e' :
return (id == sOnerror_id ||
id == sOnemptied_id ||

View File

@ -367,6 +367,9 @@ public:
static jsid sOnbeforeprint_id;
static jsid sOnafterprint_id;
static jsid sOndevicemotion_id;
static jsid sOndeviceorientation_id;
protected:
static JSPropertyOp sXPCNativeWrapperGetPropertyOp;
static JSPropertyOp sXrayWrapperPropertyHolderGetPropertyOp;

View File

@ -81,8 +81,8 @@ SetAttributeNodeWarning=Use of setAttributeNode() is deprecated. Use setAttribut
GetAttributeNodeNSWarning=Use of getAttributeNodeNS() is deprecated. Use getAttributeNS() instead.
SetAttributeNodeNSWarning=Use of setAttributeNodeNS() is deprecated. Use setAttributeNS() instead.
RemoveAttributeNodeWarning=Use of removeAttributeNode() is deprecated. Use removeAttribute() instead.
CreateAttribute=Use of document.createAttribute() is deprecated. Use element.setAttribute() instead.
CreateAttributeNS=Use of document.createAttributeNS() is deprecated. Use element.setAttributeNS() instead.
CreateAttributeWarning=Use of document.createAttribute() is deprecated. Use element.setAttribute() instead.
CreateAttributeNSWarning=Use of document.createAttributeNS() is deprecated. Use element.setAttributeNS() instead.
SpecifiedWarning=Use of attributes' specified attribute is deprecated. It always returns true.
OwnerElementWarning=Use of attributes' ownerElement attribute is deprecated.
NodeNameWarning=Use of attributes' nodeName attribute is deprecated. Use name instead.
@ -102,7 +102,9 @@ ReplaceChildWarning=Use of attributes' replaceChild() is deprecated. Use value i
RemoveChildWarning=Use of attributes' removeChild() is deprecated. Use value instead.
AppendChildWarning=Use of attributes' appendChild() is deprecated. Use value instead.
CloneNodeWarning=Use of attributes' cloneNode() is deprecated.
GetOwnerDocumentWarning=Use of attributes' ownerDocument attribute is deprecated.
OwnerDocumentWarning=Use of attributes' ownerDocument attribute is deprecated.
NormalizeWarning=Use of attributes' normalize() is deprecated.
IsSupportedWarning=Use of attributes' isSupported() is deprecated.
IsEqualNodeWarning=Use of attributes' isEqualNode() is deprecated.
TextContentWarning=Use of attributes' textContent attribute is deprecated. Use value instead.
EnablePrivilegeWarning=Use of enablePrivilege is deprecated. Please use code that runs with the system principal (e.g. an extension) instead.

View File

@ -0,0 +1,16 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
Components.utils.import("resource://gre/modules/NetUtil.jsm");
function run_test() {
var cs = Cc["@mozilla.org/cookieService;1"].getService(Ci.nsICookieService);
var cm = Cc["@mozilla.org/cookiemanager;1"].getService(Ci.nsICookieManager2);
var expiry = (Date.now() + 1000) * 1000;
// Test our handling of host names with a single character consisting only
// of a single character
cm.add("a", "/", "foo", "bar", false, false, true, expiry);
do_check_eq(cm.countCookiesFromHost("a"), 1);
do_check_eq(cs.getCookieString(NetUtil.newURI("http://a"), null), "foo=bar");
}

View File

@ -5,6 +5,7 @@ tail =
[test_bug468700.js]
[test_bug526789.js]
[test_bug650522.js]
[test_bug667087.js]
[test_cookies_async_failure.js]
[test_cookies_persistence.js]
[test_cookies_privatebrowsing.js]

View File

@ -1775,14 +1775,6 @@ MarkContext(JSTracer *trc, JSContext *acx)
MarkValue(trc, acx->iterValue, "iterValue");
}
void
MarkWeakReferences(GCMarker *trc)
{
trc->drainMarkStack();
while (js_TraceWatchPoints(trc) || WeakMapBase::markAllIteratively(trc))
trc->drainMarkStack();
}
JS_REQUIRES_STACK void
MarkRuntime(JSTracer *trc)
{
@ -1813,14 +1805,9 @@ MarkRuntime(JSTracer *trc)
for (ThreadDataIter i(rt); !i.empty(); i.popFront())
i.threadData()->mark(trc);
if (IS_GC_MARKING_TRACER(trc)) {
GCMarker *gcmarker = static_cast<GCMarker *>(trc);
MarkWeakReferences(gcmarker);
}
/*
* We mark extra roots at the end so additional colors can be used
* to implement cycle collection.
* We mark extra roots at the last thing so it can use use additional
* colors to implement cycle collection.
*/
if (rt->gcExtraRootsTraceOp)
rt->gcExtraRootsTraceOp(trc, rt->gcExtraRootsData);
@ -2256,6 +2243,15 @@ MarkAndSweep(JSContext *cx, JSCompartment *comp, JSGCInvocationKind gckind GCTIM
gcmarker.drainMarkStack();
/*
* Mark weak roots.
*/
while (true) {
if (!js_TraceWatchPoints(&gcmarker) && !WeakMapBase::markAllIteratively(&gcmarker))
break;
gcmarker.drainMarkStack();
}
rt->gcMarkingTracer = NULL;
if (rt->gcCallback)

View File

@ -1329,9 +1329,6 @@ struct GCMarker : public JSTracer {
}
};
JS_FRIEND_API(void)
MarkWeakReferences(GCMarker *trc);
void
MarkStackRangeConservatively(JSTracer *trc, Value *begin, Value *end);

View File

@ -373,10 +373,8 @@ void XPCJSRuntime::TraceJS(JSTracer* trc, void* data)
gcmarker->setMarkColor(XPC_GC_COLOR_GRAY);
}
self->TraceXPConnectRoots(trc);
if (gcmarker) {
js::MarkWeakReferences(gcmarker);
if (gcmarker)
gcmarker->setMarkColor(XPC_GC_COLOR_BLACK);
}
}
static void

View File

@ -65,14 +65,22 @@ class TelemetryImpl : public nsITelemetry
public:
TelemetryImpl();
~TelemetryImpl();
static bool CanRecord();
static already_AddRefed<nsITelemetry> CreateTelemetryInstance();
static void ShutdownTelemetry();
private:
// This is used for speedy JS string->Telemetry::ID conversions
typedef nsBaseHashtableET<nsCharPtrHashKey, Telemetry::ID> CharPtrEntryType;
typedef nsTHashtable<CharPtrEntryType> HistogramMapType;
HistogramMapType mHistogramMap;
bool mCanRecord;
static TelemetryImpl *sTelemetry;
};
TelemetryImpl* TelemetryImpl::sTelemetry = NULL;
// A initializer to initialize histogram collection
StatisticsRecorder gStatisticsRecorder;
@ -188,19 +196,31 @@ ReflectHistogramSnapshot(JSContext *cx, JSObject *obj, Histogram *h)
JSBool
JSHistogram_Add(JSContext *cx, uintN argc, jsval *vp)
{
jsval *argv = JS_ARGV(cx, vp);
JSString *str;
if (!JS_ConvertArguments(cx, argc, argv, "i", &str))
if (!argc) {
JS_ReportError(cx, "Expected one argument");
return JS_FALSE;
if (!JSVAL_IS_INT(argv[0]))
}
jsval v = JS_ARGV(cx, vp)[0];
int32 value;
if (!(JSVAL_IS_NUMBER(v) || JSVAL_IS_BOOLEAN(v))) {
JS_ReportError(cx, "Not a number");
return JS_FALSE;
JSObject *obj = JS_THIS_OBJECT(cx, vp);
Histogram *h = static_cast<Histogram*>(JS_GetPrivate(cx, obj));
PRUint32 value = JSVAL_TO_INT(argv[0]);
if (h->histogram_type() == Histogram::BOOLEAN_HISTOGRAM)
h->Add(!!value);
else
h->Add(value);
}
if (!JS_ValueToECMAInt32(cx, v, &value)) {
return JS_FALSE;
}
if (TelemetryImpl::CanRecord()) {
JSObject *obj = JS_THIS_OBJECT(cx, vp);
Histogram *h = static_cast<Histogram*>(JS_GetPrivate(cx, obj));
if (h->histogram_type() == Histogram::BOOLEAN_HISTOGRAM)
h->Add(!!value);
else
h->Add(value);
}
return JS_TRUE;
}
@ -236,7 +256,9 @@ WrapAndReturnHistogram(Histogram *h, JSContext *cx, jsval *ret)
&& JS_DefineFunction (cx, obj, "snapshot", JSHistogram_Snapshot, 1, 0)) ? NS_OK : NS_ERROR_FAILURE;
}
TelemetryImpl::TelemetryImpl() {
TelemetryImpl::TelemetryImpl():
mCanRecord(true)
{
mHistogramMap.Init(Telemetry::HistogramCount);
}
@ -307,16 +329,43 @@ TelemetryImpl::GetHistogramById(const nsACString &name, JSContext *cx, jsval *re
return WrapAndReturnHistogram(h, cx, ret);
}
NS_IMPL_THREADSAFE_ISUPPORTS1(TelemetryImpl, nsITelemetry)
already_AddRefed<nsITelemetry>
CreateTelemetryInstance()
{
nsCOMPtr<nsITelemetry> telemetry = new TelemetryImpl();
return telemetry.forget();
NS_IMETHODIMP
TelemetryImpl::GetCanRecord(PRBool *ret) {
*ret = mCanRecord;
return NS_OK;
}
NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsITelemetry, CreateTelemetryInstance)
NS_IMETHODIMP
TelemetryImpl::SetCanRecord(PRBool canRecord) {
mCanRecord = !!canRecord;
return NS_OK;
}
bool
TelemetryImpl::CanRecord() {
return !sTelemetry || sTelemetry->mCanRecord;
}
already_AddRefed<nsITelemetry>
TelemetryImpl::CreateTelemetryInstance()
{
NS_ABORT_IF_FALSE(sTelemetry == NULL, "CreateTelemetryInstance may only be called once, via GetService()");
sTelemetry = new TelemetryImpl();
// AddRef for the local reference
NS_ADDREF(sTelemetry);
// AddRef for the caller
NS_ADDREF(sTelemetry);
return sTelemetry;
}
void
TelemetryImpl::ShutdownTelemetry()
{
NS_IF_RELEASE(sTelemetry);
}
NS_IMPL_THREADSAFE_ISUPPORTS1(TelemetryImpl, nsITelemetry)
NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsITelemetry, TelemetryImpl::CreateTelemetryInstance)
#define NS_TELEMETRY_CID \
{0xaea477f2, 0xb3a2, 0x469c, {0xaa, 0x29, 0x0a, 0x82, 0xd1, 0x32, 0xb8, 0x29}}
@ -339,7 +388,7 @@ const Module kTelemetryModule = {
NULL,
NULL,
NULL,
NULL,
TelemetryImpl::ShutdownTelemetry
};
} // anonymous namespace
@ -350,6 +399,9 @@ namespace Telemetry {
void
Accumulate(ID aHistogram, PRUint32 aSample)
{
if (!TelemetryImpl::CanRecord()) {
return;
}
Histogram *h;
nsresult rv = GetHistogramByEnumId(aHistogram, &h);
if (NS_SUCCEEDED(rv))

View File

@ -61,3 +61,4 @@ HISTOGRAM(GLUESTARTUP_HARD_FAULTS, 1, 500, 12, EXPONENTIAL, "Hard faults count a
HISTOGRAM(HARD_PAGE_FAULTS, 8, 64 * 1024, 13, EXPONENTIAL, "Hard page faults (since last telemetry ping)")
#endif
HISTOGRAM(ZIPARCHIVE_CRC, 0, 1, 2, BOOLEAN, "Zip item CRC check pass")
HISTOGRAM(SHUTDOWN_OK, 0, 1, 2, BOOLEAN, "Did the browser start after a successful shutdown")

View File

@ -284,7 +284,7 @@ TelemetryPing.prototype = {
success = channel.QueryInterface(Ci.nsIHttpChannel).requestSucceeded;
} catch(e) {
}
hsuccess.add(success ? 1 : 0);
hsuccess.add(success);
hping.add(new Date() - startTime);
if (isTestPing)
Services.obs.notifyObservers(null, "telemetry-test-xhr-complete", null);
@ -295,6 +295,24 @@ TelemetryPing.prototype = {
request.send(nativeJSON.encode(payload));
},
attachObservers: function attachObservers() {
if (!this._initialized)
return;
let idleService = Cc["@mozilla.org/widget/idleservice;1"].
getService(Ci.nsIIdleService);
idleService.addIdleObserver(this, TELEMETRY_INTERVAL);
Services.obs.addObserver(this, "idle-daily", false);
},
detachObservers: function detachObservers() {
if (!this._initialized)
return;
let idleService = Cc["@mozilla.org/widget/idleservice;1"].
getService(Ci.nsIIdleService);
idleService.removeIdleObserver(this, TELEMETRY_INTERVAL);
Services.obs.removeObserver(this, "idle-daily");
},
/**
* Initializes telemetry within a timer. If there is no PREF_SERVER set, don't turn on telemetry.
*/
@ -306,17 +324,23 @@ TelemetryPing.prototype = {
} catch (e) {
// Prerequesite prefs aren't set
}
if (!enabled)
if (!enabled) {
// Turn off local telemetry if telemetry is disabled.
// This may change once about:telemetry is added.
Telemetry.canRecord = false;
return;
}
Services.obs.addObserver(this, "private-browsing", false);
Services.obs.addObserver(this, "profile-before-change", false);
// Delay full telemetry initialization to give the browser time to
// run various late initializers. Otherwise our gathered memory
// footprint and other numbers would be too optimistic.
let self = this;
this._timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
let timerCallback = function() {
let idleService = Cc["@mozilla.org/widget/idleservice;1"].
getService(Ci.nsIIdleService);
idleService.addIdleObserver(self, TELEMETRY_INTERVAL);
Services.obs.addObserver(self, "idle-daily", false);
Services.obs.addObserver(self, "profile-before-change", false);
self._initialized = true;
self.attachObservers();
self.gatherMemory();
delete self._timer
}
@ -327,11 +351,9 @@ TelemetryPing.prototype = {
* Remove observers to avoid leaks
*/
uninstall: function uninstall() {
let idleService = Cc["@mozilla.org/widget/idleservice;1"].
getService(Ci.nsIIdleService);
idleService.removeIdleObserver(this, TELEMETRY_INTERVAL);
Services.obs.removeObserver(this, "idle-daily");
this.detachObservers()
Services.obs.removeObserver(this, "profile-before-change");
Services.obs.removeObserver(this, "private-browsing");
},
/**
@ -351,6 +373,14 @@ TelemetryPing.prototype = {
case "idle":
this.gatherMemory();
break;
case "private-browsing":
Telemetry.canRecord = aData == "exit";
if (aData == "enter") {
this.detachObservers()
} else {
this.attachObservers()
}
break;
case "test-ping":
server = aData;
// fall through

View File

@ -87,4 +87,9 @@ interface nsITelemetry : nsISupports
*/
[implicit_jscontext]
jsval getHistogramById(in ACString id);
/**
* Set this to false to disable gathering of telemetry statistics.
*/
attribute boolean canRecord;
};

View File

@ -3,8 +3,10 @@
const Cc = Components.classes;
const Ci = Components.interfaces;
const Cu = Components.utils;
const Telemetry = Cc["@mozilla.org/base/telemetry;1"].getService(Ci.nsITelemetry);
Cu.import("resource://gre/modules/Services.jsm");
function test_histogram(histogram_type, name, min, max, bucket_count) {
var h = Telemetry.newHistogram(name, min, max, bucket_count, histogram_type);
@ -29,6 +31,13 @@ function test_histogram(histogram_type, name, min, max, bucket_count) {
do_check_eq(gh.min, min)
do_check_eq(gh.max, max)
// Check that booleans work with nonboolean histograms
h.add(false);
h.add(true);
var s = h.snapshot().counts;
do_check_eq(s[0], 2)
do_check_eq(s[1], 2)
}
function expect_fail(f) {
@ -54,11 +63,14 @@ function test_boolean_histogram()
sum += v;
h.add(v);
}
h.add(true);
h.add(false);
var s = h.snapshot();
do_check_eq(s.histogram_type, Telemetry.HISTOGRAM_BOOLEAN);
// last bucket should always be 0 since .add parameters are normalized to either 0 or 1
do_check_eq(s.counts[2],0);
do_check_eq(s.sum, 2);
do_check_eq(s.counts[2], 0);
do_check_eq(s.sum, 3);
do_check_eq(s.counts[0], 2);
}
function test_getHistogramById() {
@ -75,6 +87,18 @@ function test_getHistogramById() {
do_check_eq(s.max, 10000);
}
// Check that telemetry doesn't record in private mode
function test_privateMode() {
var h = Telemetry.newHistogram("test::private_mode_boolean", 1,2,3, Telemetry.HISTOGRAM_BOOLEAN);
var orig = h.snapshot();
Telemetry.canRecord = false;
h.add(1);
do_check_eq(uneval(orig), uneval(h.snapshot()));
Telemetry.canRecord = true;
h.add(1);
do_check_neq(uneval(orig), uneval(h.snapshot()));
}
function run_test()
{
let kinds = [Telemetry.HISTOGRAM_EXPONENTIAL, Telemetry.HISTOGRAM_LINEAR]
@ -89,4 +113,5 @@ function run_test()
test_boolean_histogram();
test_getHistogramById();
test_privateMode();
}

View File

@ -533,6 +533,11 @@ class nsHashKey;
#define NS_OPEN (NS_OPENCLOSE_EVENT_START)
#define NS_CLOSE (NS_OPENCLOSE_EVENT_START+1)
// Device motion and orientation
#define NS_DEVICE_ORIENTATION_START 4900
#define NS_DEVICE_ORIENTATION (NS_DEVICE_ORIENTATION_START)
#define NS_DEVICE_MOTION (NS_DEVICE_ORIENTATION_START+1)
/**
* Return status for event processors, nsEventStatus, is defined in
* nsEvent.h.