mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 714358: Time manager implementation. r=jlebar
This commit is contained in:
parent
1085335781
commit
16761404d2
@ -203,6 +203,7 @@
|
||||
@BINPATH@/components/dom_xpath.xpt
|
||||
@BINPATH@/components/dom_xul.xpt
|
||||
@BINPATH@/components/dom_loadsave.xpt
|
||||
@BINPATH@/components/dom_time.xpt
|
||||
@BINPATH@/components/downloads.xpt
|
||||
@BINPATH@/components/editor.xpt
|
||||
@BINPATH@/components/embed_base.xpt
|
||||
|
@ -722,6 +722,7 @@ GK_ATOM(onmozfullscreenchange, "onmozfullscreenchange")
|
||||
GK_ATOM(onmozfullscreenerror, "onmozfullscreenerror")
|
||||
GK_ATOM(onmozpointerlockchange, "onmozpointerlockchange")
|
||||
GK_ATOM(onmozpointerlockerror, "onmozpointerlockerror")
|
||||
GK_ATOM(onmoztimechange, "onmoztimechange")
|
||||
GK_ATOM(onMozMousePixelScroll, "onMozMousePixelScroll")
|
||||
GK_ATOM(onMozScrolledAreaChanged, "onMozScrolledAreaChanged")
|
||||
GK_ATOM(onnoupdate, "onnoupdate")
|
||||
|
@ -463,6 +463,10 @@ WINDOW_ONLY_EVENT(devicelight,
|
||||
NS_DEVICE_LIGHT,
|
||||
EventNameType_None,
|
||||
NS_EVENT)
|
||||
WINDOW_ONLY_EVENT(moztimechange,
|
||||
NS_MOZ_TIME_CHANGE_EVENT,
|
||||
EventNameType_None,
|
||||
NS_EVENT)
|
||||
|
||||
TOUCH_EVENT(touchstart,
|
||||
NS_TOUCH_START,
|
||||
|
@ -54,6 +54,7 @@
|
||||
#include "nsJSEnvironment.h"
|
||||
#include "xpcpublic.h"
|
||||
#include "nsSandboxFlags.h"
|
||||
#include "TimeChangeObserver.h"
|
||||
|
||||
using namespace mozilla::dom;
|
||||
using namespace mozilla::hal;
|
||||
@ -276,6 +277,8 @@ nsEventListenerManager::AddEventListener(nsIDOMEventListener *aListener,
|
||||
EnableDevice(NS_DEVICE_LIGHT);
|
||||
} else if (aTypeAtom == nsGkAtoms::ondevicemotion) {
|
||||
EnableDevice(NS_DEVICE_MOTION);
|
||||
} else if (aTypeAtom == nsGkAtoms::onmoztimechange) {
|
||||
EnableTimeChangeNotifications();
|
||||
} else if ((aType >= NS_MOZTOUCH_DOWN && aType <= NS_MOZTOUCH_UP) ||
|
||||
(aTypeAtom == nsGkAtoms::ontouchstart ||
|
||||
aTypeAtom == nsGkAtoms::ontouchend ||
|
||||
@ -401,6 +404,7 @@ nsEventListenerManager::RemoveEventListener(nsIDOMEventListener *aListener,
|
||||
uint32_t count = mListeners.Length();
|
||||
uint32_t typeCount = 0;
|
||||
bool deviceType = IsDeviceType(aType);
|
||||
bool timeChangeEvent = (aType == NS_MOZ_TIME_CHANGE_EVENT);
|
||||
|
||||
for (uint32_t i = 0; i < count; ++i) {
|
||||
ls = &mListeners.ElementAt(i);
|
||||
@ -414,7 +418,7 @@ nsEventListenerManager::RemoveEventListener(nsIDOMEventListener *aListener,
|
||||
mNoListenerForEvent = NS_EVENT_TYPE_NULL;
|
||||
mNoListenerForEventAtom = nullptr;
|
||||
|
||||
if (!deviceType) {
|
||||
if (!deviceType && !timeChangeEvent) {
|
||||
return;
|
||||
}
|
||||
--typeCount;
|
||||
@ -424,6 +428,8 @@ nsEventListenerManager::RemoveEventListener(nsIDOMEventListener *aListener,
|
||||
|
||||
if (deviceType && typeCount == 0) {
|
||||
DisableDevice(aType);
|
||||
} else if (timeChangeEvent && typeCount == 0) {
|
||||
DisableTimeChangeNotifications();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1165,3 +1171,27 @@ nsEventListenerManager::UnmarkGrayJSListeners()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
nsEventListenerManager::EnableTimeChangeNotifications()
|
||||
{
|
||||
nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(mTarget);
|
||||
if (!window) {
|
||||
return;
|
||||
}
|
||||
|
||||
NS_ASSERTION(window->IsInnerWindow(), "Target should not be an outer window");
|
||||
window->EnableTimeChangeNotifications();
|
||||
}
|
||||
|
||||
void
|
||||
nsEventListenerManager::DisableTimeChangeNotifications()
|
||||
{
|
||||
nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(mTarget);
|
||||
if (!window) {
|
||||
return;
|
||||
}
|
||||
|
||||
NS_ASSERTION(window->IsInnerWindow(), "Target should not be an outer window");
|
||||
window->DisableTimeChangeNotifications();
|
||||
}
|
||||
|
@ -269,6 +269,9 @@ protected:
|
||||
void EnableDevice(uint32_t aType);
|
||||
void DisableDevice(uint32_t aType);
|
||||
|
||||
void EnableTimeChangeNotifications();
|
||||
void DisableTimeChangeNotifications();
|
||||
|
||||
public:
|
||||
/**
|
||||
* Set the "inline" event listener for aEventName to |v|. This
|
||||
|
@ -43,6 +43,7 @@
|
||||
#include "nsIPermissionManager.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsIHttpChannel.h"
|
||||
#include "TimeManager.h"
|
||||
|
||||
#ifdef MOZ_MEDIA_NAVIGATOR
|
||||
#include "MediaManager.h"
|
||||
@ -126,6 +127,7 @@ NS_INTERFACE_MAP_BEGIN(Navigator)
|
||||
#endif
|
||||
NS_INTERFACE_MAP_ENTRY(nsIDOMNavigatorCamera)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIDOMNavigatorSystemMessages)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIDOMMozNavigatorTime)
|
||||
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(Navigator)
|
||||
NS_INTERFACE_MAP_END
|
||||
|
||||
@ -210,6 +212,9 @@ Navigator::Invalidate()
|
||||
}
|
||||
mDeviceStorageStores.Clear();
|
||||
|
||||
if (mTimeManager) {
|
||||
mTimeManager = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
nsPIDOMWindow *
|
||||
@ -1314,6 +1319,38 @@ Navigator::MozSetMessageHandler(const nsAString& aType,
|
||||
#endif
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
// Navigator::nsIDOMNavigatorTime
|
||||
//*****************************************************************************
|
||||
NS_IMETHODIMP
|
||||
Navigator::GetMozTime(nsIDOMMozTimeManager** aTime)
|
||||
{
|
||||
nsCOMPtr<nsPIDOMWindow> window = do_QueryReferent(mWindow);
|
||||
NS_ENSURE_TRUE(window, NS_OK);
|
||||
|
||||
nsCOMPtr<nsIDocument> document = do_QueryInterface(window->GetExtantDocument());
|
||||
NS_ENSURE_TRUE(document, NS_OK);
|
||||
nsCOMPtr<nsIPrincipal> principal = document->NodePrincipal();
|
||||
nsCOMPtr<nsIPermissionManager> permMgr =
|
||||
do_GetService(NS_PERMISSIONMANAGER_CONTRACTID);
|
||||
NS_ENSURE_TRUE(permMgr, NS_OK);
|
||||
|
||||
uint32_t permission = nsIPermissionManager::DENY_ACTION;
|
||||
permMgr->TestPermissionFromPrincipal(principal, "time", &permission);
|
||||
|
||||
if (permission != nsIPermissionManager::ALLOW_ACTION) {
|
||||
return NS_ERROR_DOM_SECURITY_ERR;
|
||||
}
|
||||
|
||||
if (!mTimeManager) {
|
||||
*aTime = nullptr;
|
||||
mTimeManager = new time::TimeManager();
|
||||
}
|
||||
|
||||
NS_ADDREF(*aTime = mTimeManager);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
// nsNavigator::nsIDOMNavigatorCamera
|
||||
//*****************************************************************************
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include "nsINavigatorMobileConnection.h"
|
||||
#endif
|
||||
#include "nsAutoPtr.h"
|
||||
#include "nsIDOMNavigatorTime.h"
|
||||
#include "nsWeakReference.h"
|
||||
#include "DeviceStorage.h"
|
||||
|
||||
@ -74,6 +75,10 @@ namespace power {
|
||||
class PowerManager;
|
||||
} // namespace power
|
||||
|
||||
namespace time {
|
||||
class TimeManager;
|
||||
} // namespace time
|
||||
|
||||
class Navigator : public nsIDOMNavigator
|
||||
, public nsIDOMClientInformation
|
||||
, public nsIDOMNavigatorDeviceStorage
|
||||
@ -96,6 +101,7 @@ class Navigator : public nsIDOMNavigator
|
||||
#endif
|
||||
, public nsIDOMNavigatorCamera
|
||||
, public nsIDOMNavigatorSystemMessages
|
||||
, public nsIDOMMozNavigatorTime
|
||||
{
|
||||
public:
|
||||
Navigator(nsPIDOMWindow *aInnerWindow);
|
||||
@ -124,6 +130,7 @@ public:
|
||||
NS_DECL_NSIDOMNAVIGATORBLUETOOTH
|
||||
#endif
|
||||
NS_DECL_NSIDOMNAVIGATORSYSTEMMESSAGES
|
||||
NS_DECL_NSIDOMMOZNAVIGATORTIME
|
||||
|
||||
static void Init();
|
||||
|
||||
@ -176,6 +183,7 @@ private:
|
||||
nsRefPtr<nsDOMCameraManager> mCameraManager;
|
||||
nsCOMPtr<nsIDOMNavigatorSystemMessages> mMessagesManager;
|
||||
nsTArray<nsRefPtr<nsDOMDeviceStorage> > mDeviceStorageStores;
|
||||
nsRefPtr<time::TimeManager> mTimeManager;
|
||||
nsWeakPtr mWindow;
|
||||
};
|
||||
|
||||
|
@ -526,6 +526,7 @@ using mozilla::dom::indexedDB::IDBWrapperCache;
|
||||
#include "nsIDOMNavigatorSystemMessages.h"
|
||||
|
||||
#include "mozilla/dom/Activity.h"
|
||||
#include "TimeManager.h"
|
||||
|
||||
#include "DOMCameraManager.h"
|
||||
#include "DOMCameraControl.h"
|
||||
@ -1717,6 +1718,9 @@ static nsDOMClassInfoData sClassInfoData[] = {
|
||||
EVENTTARGET_SCRIPTABLE_FLAGS)
|
||||
NS_DEFINE_CLASSINFO_DATA(MozActivity, nsEventTargetSH,
|
||||
EVENTTARGET_SCRIPTABLE_FLAGS)
|
||||
|
||||
NS_DEFINE_CLASSINFO_DATA(MozTimeManager, nsDOMGenericSH,
|
||||
DOM_DEFAULT_SCRIPTABLE_FLAGS)
|
||||
};
|
||||
|
||||
// Objects that should be constructable through |new Name();|
|
||||
@ -2497,6 +2501,7 @@ nsDOMClassInfo::Init()
|
||||
#endif
|
||||
DOM_CLASSINFO_MAP_ENTRY(nsIDOMNavigatorCamera)
|
||||
DOM_CLASSINFO_MAP_ENTRY(nsIDOMNavigatorSystemMessages)
|
||||
DOM_CLASSINFO_MAP_ENTRY(nsIDOMMozNavigatorTime)
|
||||
|
||||
DOM_CLASSINFO_MAP_END
|
||||
|
||||
@ -4556,6 +4561,10 @@ nsDOMClassInfo::Init()
|
||||
DOM_CLASSINFO_MAP_ENTRY(nsIDOMEventTarget)
|
||||
DOM_CLASSINFO_MAP_END
|
||||
|
||||
DOM_CLASSINFO_MAP_BEGIN(MozTimeManager, nsIDOMMozTimeManager)
|
||||
DOM_CLASSINFO_MAP_ENTRY(nsIDOMMozTimeManager)
|
||||
DOM_CLASSINFO_MAP_END
|
||||
|
||||
#ifdef DEBUG
|
||||
{
|
||||
uint32_t i = ArrayLength(sClassInfoData);
|
||||
|
@ -541,3 +541,5 @@ DOMCI_CLASS(FileRequest)
|
||||
DOMCI_CLASS(LockedFile)
|
||||
|
||||
DOMCI_CLASS(MozActivity)
|
||||
|
||||
DOMCI_CLASS(MozTimeManager)
|
||||
|
@ -223,6 +223,7 @@
|
||||
#include "nsIAppsService.h"
|
||||
#include "prrng.h"
|
||||
#include "nsSandboxFlags.h"
|
||||
#include "TimeChangeObserver.h"
|
||||
|
||||
#ifdef ANDROID
|
||||
#include <android/log.h>
|
||||
@ -1052,6 +1053,7 @@ nsGlobalWindow::CleanUp(bool aIgnoreModalDialog)
|
||||
mIdleTimer = nullptr;
|
||||
}
|
||||
|
||||
DisableTimeChangeNotifications();
|
||||
#ifdef DEBUG
|
||||
nsCycleCollector_DEBUG_shouldBeFreed(static_cast<nsIScriptGlobalObject*>(this));
|
||||
#endif
|
||||
@ -10649,6 +10651,18 @@ nsGlobalWindow::GetURL(nsIDOMMozURLProperty** aURL)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
nsGlobalWindow::EnableTimeChangeNotifications()
|
||||
{
|
||||
nsSystemTimeChangeObserver::AddWindowListener(this);
|
||||
}
|
||||
|
||||
void
|
||||
nsGlobalWindow::DisableTimeChangeNotifications()
|
||||
{
|
||||
nsSystemTimeChangeObserver::RemoveWindowListener(this);
|
||||
}
|
||||
|
||||
// static
|
||||
bool
|
||||
nsGlobalWindow::HasIndexedDBSupport()
|
||||
|
@ -534,6 +534,9 @@ public:
|
||||
virtual void EnableDeviceSensor(uint32_t aType);
|
||||
virtual void DisableDeviceSensor(uint32_t aType);
|
||||
|
||||
virtual void EnableTimeChangeNotifications();
|
||||
virtual void DisableTimeChangeNotifications();
|
||||
|
||||
virtual nsresult SetArguments(nsIArray *aArguments, nsIPrincipal *aOrigin);
|
||||
|
||||
static bool DOMWindowDumpEnabled();
|
||||
|
@ -571,6 +571,9 @@ public:
|
||||
*/
|
||||
virtual void DisableDeviceSensor(uint32_t aType) = 0;
|
||||
|
||||
virtual void EnableTimeChangeNotifications() = 0;
|
||||
virtual void DisableTimeChangeNotifications() = 0;
|
||||
|
||||
/**
|
||||
* Set a arguments for this window. This will be set on the window
|
||||
* right away (if there's an existing document) and it will also be
|
||||
|
@ -16,7 +16,14 @@ FORCE_STATIC_LIB = 1
|
||||
|
||||
include $(topsrcdir)/dom/dom-config.mk
|
||||
|
||||
CPPSRCS = $(NULL)
|
||||
CPPSRCS = \
|
||||
TimeManager.cpp \
|
||||
TimeChangeObserver.cpp \
|
||||
$(NULL)
|
||||
|
||||
EXPORTS = \
|
||||
TimeChangeObserver.h \
|
||||
$(NULL)
|
||||
|
||||
XPIDLSRCS = \
|
||||
nsIDOMNavigatorTime.idl \
|
||||
@ -24,4 +31,5 @@ XPIDLSRCS = \
|
||||
$(NULL)
|
||||
|
||||
include $(topsrcdir)/config/config.mk
|
||||
include $(topsrcdir)/ipc/chromium/chromium-config.mk
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
109
dom/time/TimeChangeObserver.cpp
Normal file
109
dom/time/TimeChangeObserver.cpp
Normal file
@ -0,0 +1,109 @@
|
||||
/* -*- 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 "TimeChangeObserver.h"
|
||||
#include "mozilla/ClearOnShutdown.h"
|
||||
#include "mozilla/StaticPtr.h"
|
||||
#include "nsPIDOMWindow.h"
|
||||
#include "nsDOMEvent.h"
|
||||
#include "nsContentUtils.h"
|
||||
|
||||
using namespace mozilla::hal;
|
||||
using namespace mozilla;
|
||||
|
||||
StaticAutoPtr<nsSystemTimeChangeObserver> sObserver;
|
||||
|
||||
nsSystemTimeChangeObserver* nsSystemTimeChangeObserver::GetInstance()
|
||||
{
|
||||
if (!sObserver) {
|
||||
sObserver = new nsSystemTimeChangeObserver();
|
||||
ClearOnShutdown(&sObserver);
|
||||
}
|
||||
return sObserver;
|
||||
}
|
||||
|
||||
nsSystemTimeChangeObserver::~nsSystemTimeChangeObserver()
|
||||
{
|
||||
mWindowListeners.Clear();
|
||||
UnregisterSystemTimeChangeObserver(this);
|
||||
}
|
||||
|
||||
void
|
||||
nsSystemTimeChangeObserver::Notify(const SystemTimeChange& aReason)
|
||||
{
|
||||
//Copy mWindowListeners and iterate over windowListeners instead because
|
||||
//mWindowListeners may be modified while we loop.
|
||||
nsTArray<nsWeakPtr> windowListeners;
|
||||
for (uint32 i = 0; i < mWindowListeners.Length(); i++) {
|
||||
windowListeners.AppendElement(mWindowListeners.SafeElementAt(i));
|
||||
}
|
||||
|
||||
for (int32 i = windowListeners.Length() - 1; i >= 0; i--) {
|
||||
nsCOMPtr<nsIDOMWindow> window = do_QueryReferent(windowListeners[i]);
|
||||
if (!window) {
|
||||
mWindowListeners.RemoveElement(windowListeners[i]);
|
||||
return;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDOMDocument> domdoc;
|
||||
window->GetDocument(getter_AddRefs(domdoc));
|
||||
nsCOMPtr<nsIDocument> doc(do_QueryInterface(domdoc));
|
||||
if (!domdoc) {
|
||||
return;
|
||||
}
|
||||
|
||||
nsContentUtils::DispatchTrustedEvent(doc, window,
|
||||
NS_LITERAL_STRING("moztimechange"), /* bubbles = */ true,
|
||||
/* canceable = */ false);
|
||||
}
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsSystemTimeChangeObserver::AddWindowListener(nsIDOMWindow* aWindow)
|
||||
{
|
||||
return GetInstance()->AddWindowListenerImpl(aWindow);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsSystemTimeChangeObserver::AddWindowListenerImpl(nsIDOMWindow* aWindow)
|
||||
{
|
||||
if (!aWindow) {
|
||||
return NS_ERROR_ILLEGAL_VALUE;
|
||||
}
|
||||
|
||||
if (mWindowListeners.IndexOf(NS_GetWeakReference(aWindow)) !=
|
||||
nsTArray<nsIDOMWindow*>::NoIndex) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (mWindowListeners.Length() == 0) {
|
||||
RegisterSystemTimeChangeObserver(sObserver);
|
||||
}
|
||||
|
||||
mWindowListeners.AppendElement(NS_GetWeakReference(aWindow));
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsSystemTimeChangeObserver::RemoveWindowListener(nsIDOMWindow* aWindow)
|
||||
{
|
||||
if (!sObserver) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
return GetInstance()->RemoveWindowListenerImpl(aWindow);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsSystemTimeChangeObserver::RemoveWindowListenerImpl(nsIDOMWindow* aWindow)
|
||||
{
|
||||
mWindowListeners.RemoveElement(NS_GetWeakReference(aWindow));
|
||||
|
||||
if (mWindowListeners.Length() == 0) {
|
||||
UnregisterSystemTimeChangeObserver(sObserver);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
32
dom/time/TimeChangeObserver.h
Normal file
32
dom/time/TimeChangeObserver.h
Normal file
@ -0,0 +1,32 @@
|
||||
/* -*- 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/. */
|
||||
|
||||
#ifndef _mozilla_time_change_observer_h_
|
||||
#define _mozilla_time_change_observer_h_
|
||||
|
||||
#include "mozilla/Hal.h"
|
||||
#include "mozilla/Observer.h"
|
||||
#include "mozilla/HalTypes.h"
|
||||
#include "nsPIDOMWindow.h"
|
||||
#include "nsWeakPtr.h"
|
||||
|
||||
typedef mozilla::Observer<mozilla::hal::SystemTimeChange> SystemTimeChangeObserver;
|
||||
|
||||
class nsSystemTimeChangeObserver : public SystemTimeChangeObserver
|
||||
{
|
||||
public:
|
||||
static nsSystemTimeChangeObserver* GetInstance();
|
||||
virtual ~nsSystemTimeChangeObserver();
|
||||
void Notify(const mozilla::hal::SystemTimeChange& aReason);
|
||||
static nsresult AddWindowListener(nsIDOMWindow* aWindow);
|
||||
static nsresult RemoveWindowListener(nsIDOMWindow* aWindow);
|
||||
private:
|
||||
nsresult AddWindowListenerImpl(nsIDOMWindow* aWindow);
|
||||
nsresult RemoveWindowListenerImpl(nsIDOMWindow* aWindow);
|
||||
nsSystemTimeChangeObserver() { };
|
||||
nsTArray<nsWeakPtr> mWindowListeners;
|
||||
};
|
||||
|
||||
#endif //_mozilla_time_change_observer_h_
|
57
dom/time/TimeManager.cpp
Normal file
57
dom/time/TimeManager.cpp
Normal file
@ -0,0 +1,57 @@
|
||||
/* 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 "jsapi.h"
|
||||
#include "mozilla/Hal.h"
|
||||
#include "nsDOMEvent.h"
|
||||
#include "nsDOMEventTargetHelper.h"
|
||||
#include "nsIDOMClassInfo.h"
|
||||
#include "prtime.h"
|
||||
#include "TimeManager.h"
|
||||
|
||||
using namespace mozilla::hal;
|
||||
|
||||
DOMCI_DATA(MozTimeManager, mozilla::dom::time::TimeManager)
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
namespace time {
|
||||
|
||||
NS_INTERFACE_MAP_BEGIN(TimeManager)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIDOMMozTimeManager)
|
||||
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
||||
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(MozTimeManager)
|
||||
NS_INTERFACE_MAP_END
|
||||
|
||||
NS_IMPL_ADDREF(TimeManager)
|
||||
NS_IMPL_RELEASE(TimeManager)
|
||||
|
||||
nsresult
|
||||
TimeManager::Set(const JS::Value& date, JSContext* ctx) {
|
||||
double nowMSec = JS_Now() / 1000;
|
||||
double dateMSec;
|
||||
|
||||
if (date.isObject()) {
|
||||
JSObject* dateObj = JSVAL_TO_OBJECT(date);
|
||||
|
||||
if (JS_ObjectIsDate(ctx, dateObj) && js_DateIsValid(ctx, dateObj)) {
|
||||
dateMSec = js_DateGetMsecSinceEpoch(ctx, dateObj);
|
||||
}
|
||||
else {
|
||||
NS_WARN_IF_FALSE(JS_ObjectIsDate(ctx, dateObj), "This is not a Date object");
|
||||
NS_WARN_IF_FALSE(js_DateIsValid(ctx, dateObj), "Date is not valid");
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
} else if (date.isNumber()) {
|
||||
dateMSec = date.toNumber();
|
||||
} else {
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
|
||||
hal::AdjustSystemClock(JS_DoubleToInt32(dateMSec - nowMSec));
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
} // namespace time
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
31
dom/time/TimeManager.h
Normal file
31
dom/time/TimeManager.h
Normal file
@ -0,0 +1,31 @@
|
||||
/* 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_time_TimeManager_h
|
||||
#define mozilla_dom_time_TimeManager_h
|
||||
|
||||
#include "mozilla/HalTypes.h"
|
||||
#include "nsIDOMTimeManager.h"
|
||||
#include "mozilla/Observer.h"
|
||||
|
||||
class nsPIDOMWindow;
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
typedef Observer<hal::SystemTimeChange> SystemTimeObserver;
|
||||
|
||||
namespace dom {
|
||||
namespace time {
|
||||
class TimeManager : public nsIDOMMozTimeManager
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIDOMMOZTIMEMANAGER
|
||||
};
|
||||
|
||||
} // namespace time
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
#endif //mozilla_dom_time_TimeManager_h
|
@ -7,6 +7,14 @@
|
||||
[scriptable, builtinclass, uuid(d29beaaa-bd54-4fd5-9f18-e0eedb1dc96d)]
|
||||
interface nsIDOMMozTimeManager : nsISupports
|
||||
{
|
||||
// jsval could be Date object or UTC seconds
|
||||
/* Set the system time.
|
||||
*
|
||||
* The |time| argument can be either a Date object or a number.
|
||||
*
|
||||
* - If |time| is a number, it's interpreted as seconds since the epoch
|
||||
* (midnight UTC on January 1, 1970)
|
||||
* - If |time| is a Date object, |set(time)| is equivalent to
|
||||
* |set(time.getTime())|.
|
||||
*/
|
||||
void set(in jsval time);
|
||||
};
|
||||
|
@ -83,6 +83,7 @@ SHARED_LIBRARY_LIBS = \
|
||||
$(DEPTH)/dom/indexedDB/$(LIB_PREFIX)dom_indexeddb_s.$(LIB_SUFFIX) \
|
||||
$(DEPTH)/dom/indexedDB/ipc/$(LIB_PREFIX)dom_indexeddb_ipc_s.$(LIB_SUFFIX) \
|
||||
$(DEPTH)/dom/browser-element/$(LIB_PREFIX)dom_browserelement_s.$(LIB_SUFFIX) \
|
||||
$(DEPTH)/dom/time/$(LIB_PREFIX)dom_time_s.$(LIB_SUFFIX) \
|
||||
$(DEPTH)/editor/libeditor/text/$(LIB_PREFIX)texteditor_s.$(LIB_SUFFIX) \
|
||||
$(DEPTH)/editor/libeditor/base/$(LIB_PREFIX)editorbase_s.$(LIB_SUFFIX) \
|
||||
$(DEPTH)/parser/html/$(LIB_PREFIX)html5p_s.$(LIB_SUFFIX) \
|
||||
|
@ -472,6 +472,9 @@ class nsHashKey;
|
||||
#define NS_WHEEL_EVENT_START 5400
|
||||
#define NS_WHEEL_WHEEL (NS_WHEEL_EVENT_START)
|
||||
|
||||
//System time is changed
|
||||
#define NS_MOZ_TIME_CHANGE_EVENT 5500
|
||||
|
||||
/**
|
||||
* Return status for event processors, nsEventStatus, is defined in
|
||||
* nsEvent.h.
|
||||
|
Loading…
Reference in New Issue
Block a user