Bug 875784 - Move MozTimeManager to WebIDL; r=smaug

This commit is contained in:
Ms2ger 2013-06-12 09:00:07 +02:00
parent d98902ff9a
commit 68ea30a57e
11 changed files with 79 additions and 73 deletions

View File

@ -1480,7 +1480,7 @@ Navigator::MozSetMessageHandler(const nsAString& aType,
//***************************************************************************** //*****************************************************************************
#ifdef MOZ_TIME_MANAGER #ifdef MOZ_TIME_MANAGER
NS_IMETHODIMP NS_IMETHODIMP
Navigator::GetMozTime(nsIDOMMozTimeManager** aTime) Navigator::GetMozTime(nsISupports** aTime)
{ {
*aTime = nullptr; *aTime = nullptr;
@ -1489,7 +1489,7 @@ Navigator::GetMozTime(nsIDOMMozTimeManager** aTime)
} }
if (!mTimeManager) { if (!mTimeManager) {
mTimeManager = new time::TimeManager(); mTimeManager = new time::TimeManager(GetWindow());
} }
NS_ADDREF(*aTime = mTimeManager); NS_ADDREF(*aTime = mTimeManager);

View File

@ -797,11 +797,6 @@ static nsDOMClassInfoData sClassInfoData[] = {
EVENTTARGET_SCRIPTABLE_FLAGS) EVENTTARGET_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(CSSFontFeatureValuesRule, nsDOMGenericSH, NS_DEFINE_CLASSINFO_DATA(CSSFontFeatureValuesRule, nsDOMGenericSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS) DOM_DEFAULT_SCRIPTABLE_FLAGS)
#ifdef MOZ_TIME_MANAGER
NS_DEFINE_CLASSINFO_DATA(MozTimeManager, nsDOMGenericSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS)
#endif
}; };
#define NS_DEFINE_CONTRACT_CTOR(_class, _contract_id) \ #define NS_DEFINE_CONTRACT_CTOR(_class, _contract_id) \
@ -1925,12 +1920,6 @@ nsDOMClassInfo::Init()
DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSFontFeatureValuesRule) DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSFontFeatureValuesRule)
DOM_CLASSINFO_MAP_END DOM_CLASSINFO_MAP_END
#ifdef MOZ_TIME_MANAGER
DOM_CLASSINFO_MAP_BEGIN(MozTimeManager, nsIDOMMozTimeManager)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMMozTimeManager)
DOM_CLASSINFO_MAP_END
#endif
MOZ_STATIC_ASSERT(MOZ_ARRAY_LENGTH(sClassInfoData) == eDOMClassInfoIDCount, MOZ_STATIC_ASSERT(MOZ_ARRAY_LENGTH(sClassInfoData) == eDOMClassInfoIDCount,
"The number of items in sClassInfoData doesn't match the " "The number of items in sClassInfoData doesn't match the "
"number of nsIDOMClassInfo ID's, this is bad! Fix it!"); "number of nsIDOMClassInfo ID's, this is bad! Fix it!");

View File

@ -191,10 +191,3 @@ DOMCI_CLASS(AsyncScrollEventDetail)
DOMCI_CLASS(LockedFile) DOMCI_CLASS(LockedFile)
DOMCI_CLASS(CSSFontFeatureValuesRule) DOMCI_CLASS(CSSFontFeatureValuesRule)
#ifdef MOZ_TIME_MANAGER
DOMCI_CLASS(MozTimeManager)
#endif
#ifdef MOZ_WEBRTC
#endif

View File

@ -652,6 +652,14 @@ DOMInterfaces = {
'workers': True, 'workers': True,
}], }],
'MozNamedAttrMap': {
'nativeType': 'nsDOMAttributeMap',
},
'MozTimeManager': {
'nativeType': 'mozilla::dom::time::TimeManager',
},
'MozStkCommandEvent' : { 'MozStkCommandEvent' : {
'nativeType': 'mozilla::dom::icc::StkCommandEvent', 'nativeType': 'mozilla::dom::icc::StkCommandEvent',
'headerFile': 'StkCommandEvent.h', 'headerFile': 'StkCommandEvent.h',
@ -672,10 +680,6 @@ DOMInterfaces = {
'previousSibling', 'nextSibling' ] 'previousSibling', 'nextSibling' ]
}, },
'MozNamedAttrMap': {
'nativeType': 'nsDOMAttributeMap',
},
'Node': { 'Node': {
'nativeType': 'nsINode', 'nativeType': 'nsINode',
'concrete': False, 'concrete': False,

View File

@ -20,7 +20,7 @@ var gData = [
{ {
perm: ["time"], perm: ["time"],
obj: "mozTime", obj: "mozTime",
idl: "nsIDOMMozTimeManager", webidl: "MozTimeManager",
}, },
] ]
</script> </script>

View File

@ -2,56 +2,46 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * 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/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "jsapi.h"
#include "nsIDOMClassInfo.h"
#include "nsITimeService.h"
#include "TimeManager.h" #include "TimeManager.h"
#ifdef MOZ_TIME_MANAGER #include "mozilla/dom/MozTimeManagerBinding.h"
DOMCI_DATA(MozTimeManager, mozilla::dom::time::TimeManager) #include "nsContentUtils.h"
#endif #include "nsITimeService.h"
#include "nsServiceManagerUtils.h"
namespace mozilla { namespace mozilla {
namespace dom { namespace dom {
namespace time { namespace time {
NS_INTERFACE_MAP_BEGIN(TimeManager) NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(TimeManager)
NS_INTERFACE_MAP_ENTRY(nsIDOMMozTimeManager) NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
NS_INTERFACE_MAP_ENTRY(nsISupports) NS_INTERFACE_MAP_ENTRY(nsISupports)
#ifdef MOZ_TIME_MANAGER
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(MozTimeManager)
#endif
NS_INTERFACE_MAP_END NS_INTERFACE_MAP_END
NS_IMPL_ADDREF(TimeManager) NS_IMPL_CYCLE_COLLECTING_ADDREF(TimeManager)
NS_IMPL_RELEASE(TimeManager) NS_IMPL_CYCLE_COLLECTING_RELEASE(TimeManager)
nsresult NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_1(TimeManager, mWindow)
TimeManager::Set(const JS::Value& date, JSContext* ctx) {
double dateMSec;
if (date.isObject()) { JSObject*
JS::Rooted<JSObject*> dateObj(ctx, date.toObjectOrNull()); TimeManager::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope)
{
return MozTimeManagerBinding::Wrap(aCx, aScope, this);
}
if (JS_ObjectIsDate(ctx, dateObj) && js_DateIsValid(dateObj)) { void
dateMSec = js_DateGetMsecSinceEpoch(dateObj); TimeManager::Set(Date& aDate)
} {
else { Set(aDate.TimeStamp());
NS_WARN_IF_FALSE(JS_ObjectIsDate(ctx, dateObj), "This is not a Date object"); }
NS_WARN_IF_FALSE(js_DateIsValid(dateObj), "Date is not valid");
return NS_ERROR_INVALID_ARG;
}
} else if (date.isNumber()) {
dateMSec = date.toNumber();
} else {
return NS_ERROR_INVALID_ARG;
}
void
TimeManager::Set(double aTime)
{
nsCOMPtr<nsITimeService> timeService = do_GetService(TIMESERVICE_CONTRACTID); nsCOMPtr<nsITimeService> timeService = do_GetService(TIMESERVICE_CONTRACTID);
if (timeService) { if (timeService) {
return timeService->Set(dateMSec); timeService->Set(aTime);
} }
return NS_OK;
} }
} // namespace time } // namespace time

View File

@ -5,18 +5,51 @@
#ifndef mozilla_dom_time_TimeManager_h #ifndef mozilla_dom_time_TimeManager_h
#define mozilla_dom_time_TimeManager_h #define mozilla_dom_time_TimeManager_h
#include "nsIDOMTimeManager.h"
#include "mozilla/Attributes.h" #include "mozilla/Attributes.h"
#include "nsISupports.h"
#include "nsPIDOMWindow.h"
#include "nsWrapperCache.h"
namespace mozilla { namespace mozilla {
namespace dom { namespace dom {
class Date;
namespace time { namespace time {
class TimeManager MOZ_FINAL : public nsIDOMMozTimeManager class TimeManager MOZ_FINAL : public nsISupports
, public nsWrapperCache
{ {
public: public:
NS_DECL_ISUPPORTS static bool PrefEnabled()
NS_DECL_NSIDOMMOZTIMEMANAGER {
#ifdef MOZ_TIME_MANAGER
return true;
#else
return false;
#endif
}
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(TimeManager)
explicit TimeManager(nsPIDOMWindow* aWindow)
: mWindow(aWindow)
{
SetIsDOMBinding();
}
nsPIDOMWindow* GetParentObject() const
{
return mWindow;
}
JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope);
void Set(Date& aDate);
void Set(double aTime);
private:
nsCOMPtr<nsPIDOMWindow> mWindow;
}; };
} // namespace time } // namespace time

View File

@ -6,7 +6,6 @@
XPIDL_SOURCES += [ XPIDL_SOURCES += [
'nsIDOMNavigatorTime.idl', 'nsIDOMNavigatorTime.idl',
'nsIDOMTimeManager.idl',
'nsITimeService.idl', 'nsITimeService.idl',
] ]
@ -17,6 +16,7 @@ MODULE = 'dom'
EXPORTS.mozilla.dom.time += [ EXPORTS.mozilla.dom.time += [
'DateCacheCleaner.h', 'DateCacheCleaner.h',
'TimeChangeObserver.h', 'TimeChangeObserver.h',
'TimeManager.h',
'TimeService.h', 'TimeService.h',
] ]

View File

@ -4,10 +4,8 @@
#include "nsISupports.idl" #include "nsISupports.idl"
interface nsIDOMMozTimeManager; [scriptable, uuid(88df63f0-814d-4424-b1f9-9184149639e5)]
[scriptable, uuid(befc186d-c249-4acb-8e70-8080f7b45e5c)]
interface nsIDOMMozNavigatorTime : nsISupports interface nsIDOMMozNavigatorTime : nsISupports
{ {
readonly attribute nsIDOMMozTimeManager mozTime; readonly attribute nsISupports /* MozTimeManager */ mozTime;
}; };

View File

@ -2,11 +2,8 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * 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/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsISupports.idl" [PrefControlled]
interface MozTimeManager {
[scriptable, builtinclass, uuid(d29beaaa-bd54-4fd5-9f18-e0eedb1dc96d)]
interface nsIDOMMozTimeManager : nsISupports
{
/* Set the system time. /* Set the system time.
* *
* The |time| argument can be either a Date object or a number. * The |time| argument can be either a Date object or a number.
@ -16,5 +13,6 @@ interface nsIDOMMozTimeManager : nsISupports
* - If |time| is a Date object, |set(time)| is equivalent to * - If |time| is a Date object, |set(time)| is equivalent to
* |set(time.getTime())|. * |set(time.getTime())|.
*/ */
[implicit_jscontext] void set(in jsval time); void set(Date time);
void set(double time);
}; };

View File

@ -181,6 +181,7 @@ webidl_files = \
MozActivity.webidl \ MozActivity.webidl \
MozMmsMessage.webidl \ MozMmsMessage.webidl \
MozNamedAttrMap.webidl \ MozNamedAttrMap.webidl \
MozTimeManager.webidl \
MutationEvent.webidl \ MutationEvent.webidl \
MutationObserver.webidl \ MutationObserver.webidl \
NetDashboard.webidl \ NetDashboard.webidl \