Merge central to inbound

This commit is contained in:
Marco Bonardo 2012-02-24 18:22:14 +01:00
commit 89ab3a4b9e
13 changed files with 459 additions and 1 deletions

View File

@ -28,6 +28,10 @@
<command id="cmd_close" oncommand="CommandUpdater.doCommand(this.id);"/>
</commandset>
<browser id="homescreen" type="content-primary" flex="1" style="overflow: hidden;"/>
<browser id="homescreen"
type="content-primary"
flex="1"
style="overflow: hidden;"
src="data:text/html;base64,PCFET0NUWVBFIGh0bWw+PGh0bWw+PGJvZHkgc3R5bGU9ImJhY2tncm91bmQ6YmxhY2s7Ij48L2JvZHk+PC9odG1sPgo="/>
</window>

173
dom/base/DOMRequest.cpp Normal file
View File

@ -0,0 +1,173 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=2 et sw=2 tw=80: */
/* 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 "DOMRequest.h"
#include "mozilla/Util.h"
#include "nsDOMClassInfo.h"
#include "DOMError.h"
#include "nsEventDispatcher.h"
#include "nsIPrivateDOMEvent.h"
#include "nsDOMEvent.h"
using mozilla::dom::DOMRequest;
using mozilla::dom::DOMRequestService;
DOMRequest::DOMRequest(nsIDOMWindow* aWindow)
: mDone(false)
, mResult(JSVAL_VOID)
, mRooted(false)
{
nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(aWindow);
mOwner = window->IsInnerWindow() ? window.get() :
window->GetCurrentInnerWindow();
nsCOMPtr<nsIScriptGlobalObject> sgo = do_QueryInterface(aWindow);
mScriptContext = sgo->GetContext();
}
DOMCI_DATA(DOMRequest, DOMRequest)
NS_IMPL_CYCLE_COLLECTION_CLASS(DOMRequest)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(DOMRequest,
nsDOMEventTargetHelper)
NS_CYCLE_COLLECTION_TRAVERSE_EVENT_HANDLER(success)
NS_CYCLE_COLLECTION_TRAVERSE_EVENT_HANDLER(error)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(DOMRequest,
nsDOMEventTargetHelper)
tmp->mResult = JSVAL_VOID;
tmp->UnrootResultVal();
NS_CYCLE_COLLECTION_UNLINK_EVENT_HANDLER(success)
NS_CYCLE_COLLECTION_UNLINK_EVENT_HANDLER(error)
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(DOMRequest,
nsDOMEventTargetHelper)
// Don't need NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER because
// nsDOMEventTargetHelper does it for us.
if (JSVAL_IS_GCTHING(tmp->mResult)) {
void *gcThing = JSVAL_TO_GCTHING(tmp->mResult);
NS_IMPL_CYCLE_COLLECTION_TRACE_JS_CALLBACK(gcThing, "mResult")
}
NS_IMPL_CYCLE_COLLECTION_TRACE_END
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(DOMRequest)
NS_INTERFACE_MAP_ENTRY(nsIDOMDOMRequest)
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(DOMRequest)
NS_INTERFACE_MAP_END_INHERITING(nsDOMEventTargetHelper)
NS_IMPL_ADDREF_INHERITED(DOMRequest, nsDOMEventTargetHelper)
NS_IMPL_RELEASE_INHERITED(DOMRequest, nsDOMEventTargetHelper)
NS_IMPL_EVENT_HANDLER(DOMRequest, success);
NS_IMPL_EVENT_HANDLER(DOMRequest, error);
NS_IMETHODIMP
DOMRequest::GetReadyState(nsAString& aReadyState)
{
mDone ? aReadyState.AssignLiteral("done") :
aReadyState.AssignLiteral("pending");
return NS_OK;
}
NS_IMETHODIMP
DOMRequest::GetResult(jsval* aResult)
{
NS_ASSERTION(mDone || mResult == JSVAL_VOID,
"Result should be undefined when pending");
*aResult = mResult;
return NS_OK;
}
NS_IMETHODIMP
DOMRequest::GetError(nsIDOMDOMError** aError)
{
NS_ASSERTION(mDone || !mError,
"Error should be null when pending");
NS_IF_ADDREF(*aError = mError);
return NS_OK;
}
void
DOMRequest::FireSuccess(jsval aResult)
{
NS_ABORT_IF_FALSE(!mDone, "Already fired success/error");
mDone = true;
RootResultVal();
mResult = aResult;
FireEvent(NS_LITERAL_STRING("success"));
}
void
DOMRequest::FireError(const nsAString& aError)
{
NS_ABORT_IF_FALSE(!mDone, "Already fired success/error");
mDone = true;
mError = DOMError::CreateWithName(aError);
FireEvent(NS_LITERAL_STRING("error"));
}
void
DOMRequest::FireEvent(const nsAString& aType)
{
if (NS_FAILED(CheckInnerWindowCorrectness())) {
return;
}
nsRefPtr<nsDOMEvent> event = new nsDOMEvent(nsnull, nsnull);
nsresult rv = event->InitEvent(aType, false, false);
if (NS_FAILED(rv)) {
return;
}
rv = event->SetTrusted(PR_TRUE);
if (NS_FAILED(rv)) {
return;
}
bool dummy;
DispatchEvent(event, &dummy);
}
NS_IMPL_ISUPPORTS1(DOMRequestService, nsIDOMRequestService)
NS_IMETHODIMP
DOMRequestService::CreateRequest(nsIDOMWindow* aWindow,
nsIDOMDOMRequest** aRequest)
{
NS_ADDREF(*aRequest = new DOMRequest(aWindow));
return NS_OK;
}
NS_IMETHODIMP
DOMRequestService::FireSuccess(nsIDOMDOMRequest* aRequest,
const jsval& aResult)
{
static_cast<DOMRequest*>(aRequest)->FireSuccess(aResult);
return NS_OK;
}
NS_IMETHODIMP
DOMRequestService::FireError(nsIDOMDOMRequest* aRequest,
const nsAString& aError)
{
static_cast<DOMRequest*>(aRequest)->FireError(aError);
return NS_OK;
}

89
dom/base/DOMRequest.h Normal file
View File

@ -0,0 +1,89 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=2 et sw=2 tw=80: */
/* 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/. */
#ifndef mozilla_dom_domrequest_h__
#define mozilla_dom_domrequest_h__
#include "nsIDOMDOMRequest.h"
#include "nsIDOMDOMError.h"
#include "nsDOMEventTargetHelper.h"
#include "nsContentUtils.h"
#include "nsCOMPtr.h"
namespace mozilla {
namespace dom {
class DOMRequest : public nsDOMEventTargetHelper,
public nsIDOMDOMRequest
{
bool mDone;
jsval mResult;
nsCOMPtr<nsIDOMDOMError> mError;
bool mRooted;
NS_DECL_EVENT_HANDLER(success)
NS_DECL_EVENT_HANDLER(error)
public:
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_NSIDOMDOMREQUEST
NS_FORWARD_NSIDOMEVENTTARGET(nsDOMEventTargetHelper::)
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(DOMRequest,
nsDOMEventTargetHelper)
void FireSuccess(jsval aResult);
void FireError(const nsAString& aError);
DOMRequest(nsIDOMWindow* aWindow);
virtual ~DOMRequest()
{
UnrootResultVal();
}
private:
void FireEvent(const nsAString& aType);
void RootResultVal()
{
if (!mRooted) {
NS_HOLD_JS_OBJECTS(this, DOMRequest);
mRooted = true;
}
}
void UnrootResultVal()
{
if (mRooted) {
NS_DROP_JS_OBJECTS(this, DOMRequest);
mRooted = false;
}
}
};
class DOMRequestService : public nsIDOMRequestService
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIDOMREQUESTSERVICE
// Returns an owning reference! No one should call this but the factory.
static DOMRequestService* FactoryCreate()
{
DOMRequestService* res = new DOMRequestService;
NS_ADDREF(res);
return res;
}
};
} // namespace dom
} // namespace mozilla
#define DOMREQUEST_SERVICE_CONTRACTID "@mozilla.org/dom/dom-request-service;1"
#endif // mozilla_dom_domrequest_h__

View File

@ -47,6 +47,10 @@ LIBRARY_NAME = jsdombase_s
LIBXUL_LIBRARY = 1
FORCE_STATIC_LIB = 1
DIRS = \
test \
$(NULL)
EXTRA_PP_COMPONENTS = \
ConsoleAPI.js \
ConsoleAPI.manifest \
@ -67,6 +71,7 @@ endif
XPIDLSRCS = \
nsIDOMDOMError.idl \
nsIDOMDOMRequest.idl \
nsIEntropyCollector.idl \
nsIScriptChannel.idl \
$(NULL)
@ -105,6 +110,7 @@ EXPORTS = \
EXPORTS_NAMESPACES = mozilla/dom
EXPORTS_mozilla/dom = \
DOMError.h \
DOMRequest.h \
StructuredCloneTags.h \
$(NULL)
@ -135,6 +141,7 @@ CPPSRCS = \
nsPerformance.cpp \
nsDOMMemoryReporter.cpp \
DOMError.cpp \
DOMRequest.cpp \
Navigator.cpp \
$(NULL)

View File

@ -537,6 +537,7 @@ using mozilla::dom::indexedDB::IDBWrapperCache;
#endif
#include "DOMError.h"
#include "DOMRequest.h"
using namespace mozilla;
using namespace mozilla::dom;
@ -1640,6 +1641,9 @@ static nsDOMClassInfoData sClassInfoData[] = {
NS_DEFINE_CLASSINFO_DATA(DOMError, nsDOMGenericSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(DOMRequest, nsEventTargetSH,
EVENTTARGET_SCRIPTABLE_FLAGS)
};
// Objects that should be constructable through |new Name();|
@ -4387,6 +4391,11 @@ nsDOMClassInfo::Init()
DOM_CLASSINFO_MAP_ENTRY(nsIDOMDOMError)
DOM_CLASSINFO_MAP_END
DOM_CLASSINFO_MAP_BEGIN(DOMRequest, nsIDOMDOMRequest)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMDOMRequest)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMEventTarget)
DOM_CLASSINFO_MAP_END
#ifdef NS_DEBUG
{
PRUint32 i = ArrayLength(sClassInfoData);

View File

@ -546,3 +546,4 @@ DOMCI_CLASS(BluetoothAdapter)
#endif
DOMCI_CLASS(DOMError)
DOMCI_CLASS(DOMRequest)

View File

@ -0,0 +1,31 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=2 et sw=2 tw=80: */
/* 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 "nsIDOMEventTarget.idl"
interface nsIDOMDOMError;
interface nsIDOMWindow;
[scriptable, builtinclass, uuid(a3ad2846-ffb2-48d7-a786-2254cb82560d)]
interface nsIDOMDOMRequest : nsIDOMEventTarget
{
readonly attribute DOMString readyState; // "pending" or "done"
readonly attribute jsval result;
readonly attribute nsIDOMDOMError error;
attribute nsIDOMEventListener onsuccess;
attribute nsIDOMEventListener onerror;
};
[scriptable, builtinclass, uuid(eebcdf29-f8fa-4c36-bbc7-2146b1cbaf7b)]
interface nsIDOMRequestService : nsISupports
{
nsIDOMDOMRequest createRequest(in nsIDOMWindow window);
void fireSuccess(in nsIDOMDOMRequest request, in jsval result);
void fireError(in nsIDOMDOMRequest request, in DOMString error);
};

53
dom/base/test/Makefile.in Normal file
View File

@ -0,0 +1,53 @@
# ***** 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 Indexed Database Test Code.
#
# The Initial Developer of the Original Code is
# The Mozilla Foundation.
# Portions created by the Initial Developer are Copyright (C) 2010
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
# Shawn Wilsher <me@shawnwilsher.com>
#
# 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 *****
DEPTH = ../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
relativesrcdir = dom/base/test
include $(DEPTH)/config/autoconf.mk
include $(topsrcdir)/config/rules.mk
TEST_FILES = \
test_domrequest.html \
$(NULL)
libs:: $(TEST_FILES)
$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)

View File

@ -0,0 +1,63 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Test for XMLHttpRequest</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
<script class="testbody" type="application/javascript;version=1.7">
"use strict";
var reqserv = SpecialPowers.getDOMRequestService();
ok("createRequest" in reqserv, "appears to be a service");
// create a request
var req = reqserv.createRequest(window);
ok("result" in req, "request has result");
ok("error" in req, "request has error");
ok("onsuccess" in req, "request has onsuccess");
ok("onerror" in req, "request has onerror");
ok("readyState" in req, "request has readyState");
is(req.readyState, "pending", "readyState is pending");
is(req.result, undefined, "result is undefined");
is(req.onsuccess, null, "onsuccess is null");
is(req.onerror, null, "onerror is null");
// fire success
var ev = null;
req.onsuccess = function(e) {
ev = e;
}
reqserv.fireSuccess(req, "my result");
ok(ev, "got success event");
is(ev.type, "success", "correct type during success");
is(ev.target, req, "correct target during success");
is(req.readyState, "done", "correct readyState after success");
is(req.error, null, "correct error after success");
is(req.result, "my result", "correct result after success");
// fire error
req = reqserv.createRequest(window);
ev = null;
req.onerror = function(e) {
ev = e;
}
reqserv.fireError(req, "OhMyError");
ok(ev, "got success event");
is(ev.type, "error", "correct type during error");
is(ev.target, req, "correct target during error");
is(req.readyState, "done", "correct readyState after error");
is(req.error.name, "OhMyError", "correct error after error");
is(req.result, undefined, "correct result after error");
</script>
</pre>
</body>
</html>

View File

@ -76,6 +76,10 @@ AudioManager::SetMasterVolume(float aMasterVolume)
if (AudioSystem::setMasterVolume(aMasterVolume)) {
return NS_ERROR_FAILURE;
}
// For now, just set the voice volume at the same level
if (AudioSystem::setVoiceVolume(aMasterVolume)) {
return NS_ERROR_FAILURE;
}
return NS_OK;
}

View File

@ -123,4 +123,8 @@
#define INDEXEDDB_MANAGER_CID \
{ 0x1a26a7b7, 0xd06e, 0x4f45, { 0x8b, 0x45, 0xd7, 0xad, 0x60, 0xf7, 0xa9, 0xab } }
// {3160e271-138d-4cc7-9d63-6429f16957c7}
#define DOMREQUEST_SERVICE_CID \
{ 0x3160e271, 0x138d, 0x4cc7, { 0x9d, 0x63, 0x64, 0x29, 0xf1, 0x69, 0x57, 0xc7 } }
#endif /* nsLayoutCID_h__ */

View File

@ -123,8 +123,10 @@
#include "nsDOMStorage.h"
#include "nsJSON.h"
#include "mozilla/dom/indexedDB/IndexedDatabaseManager.h"
#include "mozilla/dom/DOMRequest.h"
using mozilla::dom::indexedDB::IndexedDatabaseManager;
using mozilla::dom::DOMRequestService;
#ifdef MOZ_B2G_RIL
#include "SystemWorkerManager.h"
@ -287,6 +289,8 @@ NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsDOMStorageManager,
NS_GENERIC_FACTORY_CONSTRUCTOR(nsChannelPolicy)
NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(IndexedDatabaseManager,
IndexedDatabaseManager::FactoryCreate)
NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(DOMRequestService,
DOMRequestService::FactoryCreate)
#ifdef MOZ_B2G_RIL
NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(SystemWorkerManager,
SystemWorkerManager::FactoryCreate)
@ -756,6 +760,7 @@ NS_DEFINE_NAMED_CID(NS_DOMSTORAGEMANAGER_CID);
NS_DEFINE_NAMED_CID(NS_DOMJSON_CID);
NS_DEFINE_NAMED_CID(NS_TEXTEDITOR_CID);
NS_DEFINE_NAMED_CID(INDEXEDDB_MANAGER_CID);
NS_DEFINE_NAMED_CID(DOMREQUEST_SERVICE_CID);
#ifdef MOZ_B2G_RIL
NS_DEFINE_NAMED_CID(SYSTEMWORKERMANAGER_CID);
#endif
@ -1029,6 +1034,7 @@ static const mozilla::Module::CIDEntry kLayoutCIDs[] = {
{ &kNS_DOMJSON_CID, false, NULL, NS_NewJSON },
{ &kNS_TEXTEDITOR_CID, false, NULL, nsPlaintextEditorConstructor },
{ &kINDEXEDDB_MANAGER_CID, false, NULL, IndexedDatabaseManagerConstructor },
{ &kDOMREQUEST_SERVICE_CID, false, NULL, DOMRequestServiceConstructor },
#ifdef MOZ_B2G_RIL
{ &kSYSTEMWORKERMANAGER_CID, true, NULL, SystemWorkerManagerConstructor },
#endif
@ -1167,6 +1173,7 @@ static const mozilla::Module::ContractIDEntry kLayoutContracts[] = {
{ "@mozilla.org/dom/json;1", &kNS_DOMJSON_CID },
{ "@mozilla.org/editor/texteditor;1", &kNS_TEXTEDITOR_CID },
{ INDEXEDDB_MANAGER_CONTRACTID, &kINDEXEDDB_MANAGER_CID },
{ DOMREQUEST_SERVICE_CONTRACTID, &kDOMREQUEST_SERVICE_CID },
#ifdef MOZ_B2G_RIL
{ SYSTEMWORKERMANAGER_CONTRACTID, &kSYSTEMWORKERMANAGER_CID },
#endif

View File

@ -871,6 +871,19 @@ SpecialPowersAPI.prototype = {
removeSystemEventListener(target, type, listener, useCapture);
},
getDOMRequestService: function() {
var serv = Cc["@mozilla.org/dom/dom-request-service;1"].
getService(Ci.nsIDOMRequestService);
var res = { __exposedProps__: {} };
var props = ["createRequest", "fireError", "fireSuccess"];
for (i in props) {
let prop = props[i];
res[prop] = function() { return serv[prop].apply(serv, arguments) };
res.__exposedProps__[prop] = "r";
}
return res;
},
setLogFile: function(path) {
this._mfl = new MozillaFileLogger(path);
},