dom/time/TimeManager.cpp
author David Anderson <danderson@mozilla.com>
Fri, 01 Jul 2016 01:15:16 -0700
changeset 343414 887adb3d9482c267c5928f5d900252361f35ac25
parent 289753 404e5944dc5901b62eeaf450648203d28a77aa07
child 453497 7c637da65c1fec33fc36a014485acad5413e09ea
permissions -rw-r--r--
Move InProcessCompositorWidget to its own file. (bug 1281998 part 3, r=jimm)

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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 "TimeManager.h"

#include "mozilla/dom/Date.h"
#include "mozilla/dom/MozTimeManagerBinding.h"
#include "nsITimeService.h"
#include "nsServiceManagerUtils.h"

namespace mozilla {
namespace dom {
namespace time {

NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(TimeManager)
  NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
  NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_INTERFACE_MAP_END

NS_IMPL_CYCLE_COLLECTING_ADDREF(TimeManager)
NS_IMPL_CYCLE_COLLECTING_RELEASE(TimeManager)

NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(TimeManager, mWindow)

JSObject*
TimeManager::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
{
  return MozTimeManagerBinding::Wrap(aCx, this, aGivenProto);
}

void
TimeManager::Set(Date& aDate)
{
  Set(aDate.ToDouble());
}

void
TimeManager::Set(double aTime)
{
  nsCOMPtr<nsITimeService> timeService = do_GetService(TIMESERVICE_CONTRACTID);
  if (timeService) {
    timeService->Set(aTime);
  }
}

} // namespace time
} // namespace dom
} // namespace mozilla