This commit is contained in:
Ben Turner 2012-02-23 07:09:44 -08:00
Родитель 28e6b059fc 47e723700e
Коммит 1df9973ac5
15 изменённых файлов: 91 добавлений и 289 удалений

Просмотреть файл

@ -529,7 +529,6 @@ using mozilla::dom::indexedDB::IDBWrapperCache;
#ifdef MOZ_B2G_RIL
#include "Telephony.h"
#include "TelephonyCall.h"
#include "TelephonyCallArray.h"
#include "CallEvent.h"
#endif
@ -1630,8 +1629,6 @@ static nsDOMClassInfoData sClassInfoData[] = {
EVENTTARGET_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(TelephonyCall, nsEventTargetSH,
EVENTTARGET_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(TelephonyCallArray, nsDOMGenericSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(CallEvent, nsDOMGenericSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS)
#endif
@ -4374,10 +4371,6 @@ nsDOMClassInfo::Init()
DOM_CLASSINFO_MAP_ENTRY(nsIDOMEventTarget)
DOM_CLASSINFO_MAP_END
DOM_CLASSINFO_MAP_BEGIN(TelephonyCallArray, nsIDOMTelephonyCallArray)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMTelephonyCallArray)
DOM_CLASSINFO_MAP_END
DOM_CLASSINFO_MAP_BEGIN(CallEvent, nsIDOMCallEvent)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMCallEvent)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMEvent)

Просмотреть файл

@ -538,7 +538,6 @@ DOMCI_CLASS(CustomEvent)
#ifdef MOZ_B2G_RIL
DOMCI_CLASS(Telephony)
DOMCI_CLASS(TelephonyCall)
DOMCI_CLASS(TelephonyCallArray)
DOMCI_CLASS(CallEvent)
#endif

Просмотреть файл

@ -88,7 +88,6 @@ XPIDLSRCS = \
nsIDOMPerformance.idl \
nsIDOMPerformanceTiming.idl \
nsIDOMPerformanceNavigation.idl \
nsIDOMTelephonyCallArray.idl \
$(NULL)
include $(topsrcdir)/config/rules.mk

Просмотреть файл

@ -1,51 +0,0 @@
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
/* vim: set ts=2 et sw=2 tw=40: */
/* ***** 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 Telephony.
*
* The Initial Developer of the Original Code is
* The Mozilla Foundation.
* Portions created by the Initial Developer are Copyright (C) 2012
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Ben Turner <bent.mozilla@gmail.com> (Original Author)
*
* 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 ***** */
#include "nsISupports.idl"
interface nsIDOMTelephonyCall;
[scriptable, builtinclass, uuid(5a0dfc8f-1bca-4922-82b2-f86721edf72a)]
interface nsIDOMTelephonyCallArray : nsISupports
{
readonly attribute unsigned long length;
[getter, noscript, notxpcom, nostdcall]
nsIDOMTelephonyCall getCallAt(in unsigned long index);
};

Просмотреть файл

@ -43,7 +43,6 @@
#include "Telephony.h"
#include "TelephonyCall.h"
#include "TelephonyCallArray.h"
USING_TELEPHONY_NAMESPACE

Просмотреть файл

@ -53,7 +53,6 @@ include $(topsrcdir)/dom/dom-config.mk
CPPSRCS = \
Telephony.cpp \
TelephonyCall.cpp \
TelephonyCallArray.cpp \
CallEvent.cpp \
$(NULL)
@ -64,7 +63,10 @@ XPIDLSRCS = \
nsIDOMCallEvent.idl \
$(NULL)
# Needed for dombindings.h
LOCAL_INCLUDES += -I$(topsrcdir)/js/xpconnect/src
#LOCAL_INCLUDES = \
# -I$(topsrcdir)/dom/base \
# -I$(topsrcdir)/dom/system/b2g \
# -I$(topsrcdir)/content/events/src \
# $(NULL)
include $(topsrcdir)/config/rules.mk

Просмотреть файл

@ -53,18 +53,72 @@
#include "CallEvent.h"
#include "TelephonyCall.h"
#include "TelephonyCallArray.h"
USING_TELEPHONY_NAMESPACE
using mozilla::Preferences;
#define DOM_TELEPHONY_APP_PHONE_URL_PREF "dom.telephony.app.phone.url"
namespace {
template <class T>
inline nsresult
nsTArrayToJSArray(JSContext* aCx, JSObject* aGlobal,
const nsTArray<nsRefPtr<T> >& aSourceArray,
JSObject** aResultArray)
{
NS_ASSERTION(aCx, "Null context!");
NS_ASSERTION(aGlobal, "Null global!");
JSAutoRequest ar(aCx);
JSAutoEnterCompartment ac;
if (!ac.enter(aCx, aGlobal)) {
NS_WARNING("Failed to enter compartment!");
return NS_ERROR_FAILURE;
}
JSObject* arrayObj;
if (aSourceArray.IsEmpty()) {
arrayObj = JS_NewArrayObject(aCx, 0, nsnull);
} else {
nsTArray<jsval> valArray;
valArray.SetLength(aSourceArray.Length());
for (PRUint32 index = 0; index < valArray.Length(); index++) {
nsISupports* obj = aSourceArray[index]->ToISupports();
nsresult rv =
nsContentUtils::WrapNative(aCx, aGlobal, obj, &valArray[index]);
NS_ENSURE_SUCCESS(rv, rv);
}
arrayObj = JS_NewArrayObject(aCx, valArray.Length(), valArray.Elements());
}
if (!arrayObj) {
return NS_ERROR_OUT_OF_MEMORY;
}
// XXX This is not what Jonas wants. He wants it to be live.
if (!JS_FreezeObject(aCx, arrayObj)) {
return NS_ERROR_FAILURE;
}
*aResultArray = arrayObj;
return NS_OK;
}
} // anonymous namespace
Telephony::~Telephony()
{
if (mRIL && mRILTelephonyCallback) {
mRIL->UnregisterCallback(mRILTelephonyCallback);
}
if (mRooted) {
NS_DROP_JS_OBJECTS(this, Telephony);
}
}
// static
@ -110,22 +164,25 @@ NS_IMPL_CYCLE_COLLECTION_CLASS(Telephony)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(Telephony,
nsDOMEventTargetHelper)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
NS_CYCLE_COLLECTION_TRAVERSE_EVENT_HANDLER(incoming)
for (PRUint32 index = 0; index < tmp->mCalls.Length(); index++) {
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mCalls[i]");
cb.NoteXPCOMChild(tmp->mCalls[index]->ToISupports());
}
if (tmp->mCallsArray) {
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mCallsArray);
}
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(Telephony,
nsDOMEventTargetHelper)
NS_IMPL_CYCLE_COLLECTION_TRACE_JS_CALLBACK(tmp->mCallsArray, "mCallsArray")
NS_IMPL_CYCLE_COLLECTION_TRACE_END
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(Telephony,
nsDOMEventTargetHelper)
NS_CYCLE_COLLECTION_UNLINK_EVENT_HANDLER(incoming)
tmp->mCalls.Clear();
tmp->mActiveCall = nsnull;
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mCallsArray)
tmp->mCallsArray = nsnull;
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(Telephony)
@ -249,17 +306,24 @@ Telephony::SetActive(const jsval& aActive)
}
NS_IMETHODIMP
Telephony::GetCalls(nsIDOMTelephonyCallArray** aCalls)
Telephony::GetCalls(jsval* aCalls)
{
nsRefPtr<TelephonyCallArray> calls = mCallsArray;
JSObject* calls = mCallsArray;
if (!calls) {
calls = TelephonyCallArray::Create(this);
NS_ASSERTION(calls, "This should never fail!");
nsresult rv =
nsTArrayToJSArray(mScriptContext->GetNativeContext(),
mScriptContext->GetNativeGlobal(), mCalls, &calls);
NS_ENSURE_SUCCESS(rv, rv);
if (!mRooted) {
NS_HOLD_JS_OBJECTS(this, Telephony);
mRooted = true;
}
mCallsArray = calls;
}
calls.forget(aCalls);
aCalls->setObject(*calls);
return NS_OK;
}

Просмотреть файл

@ -62,14 +62,20 @@ class Telephony : public nsDOMEventTargetHelper,
TelephonyCall* mActiveCall;
nsTArray<nsRefPtr<TelephonyCall> > mCalls;
nsRefPtr<TelephonyCallArray> mCallsArray;
// Cached calls array object. Cleared whenever mCalls changes and then rebuilt
// once a page looks for the liveCalls attribute.
JSObject* mCallsArray;
bool mRooted;
public:
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_NSIDOMTELEPHONY
NS_DECL_NSIRILTELEPHONYCALLBACK
NS_FORWARD_NSIDOMEVENTTARGET(nsDOMEventTargetHelper::)
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(Telephony, nsDOMEventTargetHelper)
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(
Telephony,
nsDOMEventTargetHelper)
static already_AddRefed<Telephony>
Create(nsPIDOMWindow* aOwner, nsIRadioInterfaceLayer* aRIL);
@ -92,6 +98,7 @@ public:
{
NS_ASSERTION(!mCalls.Contains(aCall), "Already know about this one!");
mCalls.AppendElement(aCall);
mCallsArray = nsnull;
}
void
@ -99,6 +106,7 @@ public:
{
NS_ASSERTION(mCalls.Contains(aCall), "Didn't know about this one!");
mCalls.RemoveElement(aCall);
mCallsArray = nsnull;
}
nsIRadioInterfaceLayer*
@ -119,15 +127,9 @@ public:
return mScriptContext;
}
const nsTArray<nsRefPtr<TelephonyCall> >&
Calls() const
{
return mCalls;
}
private:
Telephony()
: mActiveCall(nsnull)
: mActiveCall(nsnull), mCallsArray(nsnull), mRooted(false)
{ }
~Telephony();

Просмотреть файл

@ -43,7 +43,6 @@
#include "CallEvent.h"
#include "Telephony.h"
#include "TelephonyCallArray.h"
USING_TELEPHONY_NAMESPACE

Просмотреть файл

@ -1,124 +0,0 @@
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
/* vim: set ts=2 et sw=2 tw=40: */
/* ***** 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 Telephony.
*
* The Initial Developer of the Original Code is
* The Mozilla Foundation.
* Portions created by the Initial Developer are Copyright (C) 2012
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Ben Turner <bent.mozilla@gmail.com> (Original Author)
*
* 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 ***** */
#include "TelephonyCallArray.h"
// For NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER...
#include "nsINode.h"
#include "dombindings.h"
#include "nsDOMClassInfo.h"
#include "Telephony.h"
#include "TelephonyCall.h"
USING_TELEPHONY_NAMESPACE
TelephonyCallArray::TelephonyCallArray(Telephony* aTelephony)
: mTelephony(aTelephony)
{
SetIsProxy();
}
TelephonyCallArray::~TelephonyCallArray()
{ }
// static
already_AddRefed<TelephonyCallArray>
TelephonyCallArray::Create(Telephony* aTelephony)
{
nsRefPtr<TelephonyCallArray> array = new TelephonyCallArray(aTelephony);
return array.forget();
}
NS_IMPL_CYCLE_COLLECTION_CLASS(TelephonyCallArray)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(TelephonyCallArray)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mTelephony");
cb.NoteXPCOMChild(tmp->mTelephony->ToISupports());
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(TelephonyCallArray)
NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER
NS_IMPL_CYCLE_COLLECTION_TRACE_END
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(TelephonyCallArray)
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mTelephony)
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
NS_IMPL_CYCLE_COLLECTING_ADDREF(TelephonyCallArray)
NS_IMPL_CYCLE_COLLECTING_RELEASE(TelephonyCallArray)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(TelephonyCallArray)
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(TelephonyCallArray)
NS_INTERFACE_MAP_ENTRY(nsIDOMTelephonyCallArray)
NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_INTERFACE_MAP_END
DOMCI_DATA(TelephonyCallArray, TelephonyCallArray)
NS_IMETHODIMP
TelephonyCallArray::GetLength(PRUint32* aLength)
{
NS_ASSERTION(aLength, "Null pointer!");
*aLength = mTelephony->Calls().Length();
return NS_OK;
}
nsIDOMTelephonyCall*
TelephonyCallArray::GetCallAt(PRUint32 aIndex)
{
return mTelephony->Calls().SafeElementAt(aIndex);
}
nsISupports*
TelephonyCallArray::GetParentObject() const
{
return mTelephony->ToISupports();
}
JSObject*
TelephonyCallArray::WrapObject(JSContext* aCx, XPCWrappedNativeScope* aScope,
bool* aTriedToWrap)
{
return mozilla::dom::binding::TelephonyCallArray::create(aCx, aScope, this,
aTriedToWrap);
}

Просмотреть файл

@ -1,75 +0,0 @@
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
/* vim: set ts=2 et sw=2 tw=40: */
/* ***** 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 Telephony.
*
* The Initial Developer of the Original Code is
* The Mozilla Foundation.
* Portions created by the Initial Developer are Copyright (C) 2012
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Ben Turner <bent.mozilla@gmail.com> (Original Author)
*
* 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 ***** */
#ifndef mozilla_dom_telephony_telephonycallarray_h__
#define mozilla_dom_telephony_telephonycallarray_h__
#include "TelephonyCommon.h"
#include "nsIDOMTelephonyCallArray.h"
BEGIN_TELEPHONY_NAMESPACE
class TelephonyCallArray : public nsIDOMTelephonyCallArray,
public nsWrapperCache
{
nsRefPtr<Telephony> mTelephony;
public:
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_NSIDOMTELEPHONYCALLARRAY
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(TelephonyCallArray)
static already_AddRefed<TelephonyCallArray>
Create(Telephony* aTelephony);
nsISupports*
GetParentObject() const;
virtual JSObject*
WrapObject(JSContext* aCx, XPCWrappedNativeScope* aScope, bool* aTriedToWrap);
private:
TelephonyCallArray(Telephony* aTelephony);
~TelephonyCallArray();
};
END_TELEPHONY_NAMESPACE
#endif // mozilla_dom_telephony_telephonycallarray_h__

Просмотреть файл

@ -66,8 +66,6 @@ enum {
class Telephony;
class TelephonyCall;
class TelephonyCallArray;
class CallEvent;
END_TELEPHONY_NAMESPACE

Просмотреть файл

@ -42,7 +42,6 @@
interface nsIDOMEventListener;
interface nsIDOMTelephonyCall;
interface nsIDOMTelephonyCallArray;
[scriptable, builtinclass, uuid(047be0d8-a9cd-49aa-8948-2f60ff3a7a18)]
interface nsIDOMTelephony : nsIDOMEventTarget
@ -57,7 +56,7 @@ interface nsIDOMTelephony : nsIDOMEventTarget
attribute jsval active;
// Array of all calls that are currently connected.
readonly attribute nsIDOMTelephonyCallArray calls;
readonly attribute jsval calls;
void startTone(in DOMString tone);
void stopTone();

Просмотреть файл

@ -103,7 +103,6 @@ LOCAL_INCLUDES = \
-I$(topsrcdir)/layout/style \
-I$(topsrcdir)/layout/base \
-I$(topsrcdir)/dom/base \
-I$(topsrcdir)/dom/telephony \
-I$(topsrcdir)/xpcom/ds \
$(NULL)

Просмотреть файл

@ -2,7 +2,6 @@ classes = {
'NodeList': 'nsINodeList',
'HTMLCollection': 'nsIHTMLCollection',
'HTMLOptionsCollection': 'nsHTMLOptionCollection',
'TelephonyCallArray': 'mozilla::dom::telephony::TelephonyCallArray',
}
irregularFilenames = {