TimeManager.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #include "TimeManager.h"
  6. #include "mozilla/dom/Date.h"
  7. #include "mozilla/dom/MozTimeManagerBinding.h"
  8. #include "nsITimeService.h"
  9. #include "nsServiceManagerUtils.h"
  10. namespace mozilla {
  11. namespace dom {
  12. namespace time {
  13. NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(TimeManager)
  14. NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
  15. NS_INTERFACE_MAP_ENTRY(nsISupports)
  16. NS_INTERFACE_MAP_END
  17. NS_IMPL_CYCLE_COLLECTING_ADDREF(TimeManager)
  18. NS_IMPL_CYCLE_COLLECTING_RELEASE(TimeManager)
  19. NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(TimeManager, mWindow)
  20. JSObject*
  21. TimeManager::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
  22. {
  23. return MozTimeManagerBinding::Wrap(aCx, this, aGivenProto);
  24. }
  25. void
  26. TimeManager::Set(Date& aDate)
  27. {
  28. Set(aDate.ToDouble());
  29. }
  30. void
  31. TimeManager::Set(double aTime)
  32. {
  33. nsCOMPtr<nsITimeService> timeService = do_GetService(TIMESERVICE_CONTRACTID);
  34. if (timeService) {
  35. timeService->Set(aTime);
  36. }
  37. }
  38. } // namespace time
  39. } // namespace dom
  40. } // namespace mozilla