mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-01-30 01:59:29 +00:00
Bug 790499 - Time API: Call JS_ClearDateCaches() to update Date object's timezone when the system timezone is reset, r=jlebar
This commit is contained in:
parent
be2864ee16
commit
b7c96225e0
64
dom/time/DateCacheCleaner.cpp
Normal file
64
dom/time/DateCacheCleaner.cpp
Normal file
@ -0,0 +1,64 @@
|
||||
/* -*- 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 "mozilla/Hal.h"
|
||||
#include "mozilla/ClearOnShutdown.h"
|
||||
#include "DateCacheCleaner.h"
|
||||
|
||||
#include "nsIJSContextStack.h"
|
||||
#include "mozilla/StaticPtr.h"
|
||||
|
||||
using namespace mozilla::hal;
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
namespace time {
|
||||
|
||||
class DateCacheCleaner : public SystemTimeChangeObserver
|
||||
{
|
||||
public:
|
||||
DateCacheCleaner()
|
||||
{
|
||||
RegisterSystemTimeChangeObserver(this);
|
||||
}
|
||||
|
||||
~DateCacheCleaner()
|
||||
{
|
||||
UnregisterSystemTimeChangeObserver(this);
|
||||
}
|
||||
void Notify(const SystemTimeChange& aReason)
|
||||
{
|
||||
if (aReason == SYS_TIME_CHANGE_CLOCK) {
|
||||
return;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIThreadJSContextStack> stack =
|
||||
do_GetService("@mozilla.org/js/xpc/ContextStack;1");
|
||||
if (!stack) {
|
||||
NS_WARNING("Failed to get JSContextStack");
|
||||
}
|
||||
JSContext *cx = stack->GetSafeJSContext();
|
||||
if (!cx) {
|
||||
NS_WARNING("Failed to GetSafeJSContext");
|
||||
}
|
||||
JS_ClearDateCaches(cx);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
StaticAutoPtr<DateCacheCleaner> sDateCacheCleaner;
|
||||
|
||||
void
|
||||
InitializeDateCacheCleaner()
|
||||
{
|
||||
if (!sDateCacheCleaner) {
|
||||
sDateCacheCleaner = new DateCacheCleaner();
|
||||
ClearOnShutdown(&sDateCacheCleaner);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace time
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
18
dom/time/DateCacheCleaner.h
Normal file
18
dom/time/DateCacheCleaner.h
Normal file
@ -0,0 +1,18 @@
|
||||
/* -*- 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/. */
|
||||
|
||||
/*
|
||||
* InitializeDateCacheCleaner registers DateCacheCleaner to
|
||||
* SystemTimeChangeObserver. When time zone is changed, DateCacheCleaner calls
|
||||
* JS_ClearDateCaches to update the time zone information.
|
||||
*/
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
namespace time {
|
||||
void InitializeDateCacheCleaner();
|
||||
} //namespace time
|
||||
} //namespace dom
|
||||
} //namespace mozilla
|
@ -24,11 +24,13 @@ CPPSRCS = \
|
||||
TimeManager.cpp \
|
||||
TimeService.cpp \
|
||||
TimeChangeObserver.cpp \
|
||||
DateCacheCleaner.cpp \
|
||||
$(NULL)
|
||||
|
||||
EXPORTS_mozilla/dom/time = \
|
||||
TimeService.h \
|
||||
TimeChangeObserver.h \
|
||||
DateCacheCleaner.h \
|
||||
$(NULL)
|
||||
|
||||
XPIDLSRCS = \
|
||||
|
@ -167,6 +167,7 @@ enum FMRadioCountry {
|
||||
};
|
||||
|
||||
typedef Observer<FMRadioOperationInformation> FMRadioObserver;
|
||||
typedef Observer<SystemTimeChange> SystemTimeChangeObserver;
|
||||
} // namespace hal
|
||||
} // namespace mozilla
|
||||
|
||||
|
@ -102,12 +102,14 @@
|
||||
#include "nsPermissionManager.h"
|
||||
#include "nsCookieService.h"
|
||||
#include "nsApplicationCacheService.h"
|
||||
#include "mozilla/dom/time/DateCacheCleaner.h"
|
||||
|
||||
extern void NS_ShutdownChainItemPool();
|
||||
|
||||
using namespace mozilla;
|
||||
using namespace mozilla::dom;
|
||||
using namespace mozilla::dom::ipc;
|
||||
using namespace mozilla::dom::time;
|
||||
|
||||
nsrefcnt nsLayoutStatics::sLayoutStaticRefcnt = 0;
|
||||
|
||||
@ -262,6 +264,8 @@ nsLayoutStatics::Initialize()
|
||||
|
||||
nsDOMStorageBaseDB::Init();
|
||||
|
||||
InitializeDateCacheCleaner();
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user