michael@0: /* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "Navigator.h" michael@0: michael@0: #include "mozilla/dom/WorkerNavigatorBinding.h" michael@0: michael@0: #include "RuntimeService.h" michael@0: #include "WorkerPrivate.h" michael@0: michael@0: BEGIN_WORKERS_NAMESPACE michael@0: michael@0: NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_0(WorkerNavigator) michael@0: michael@0: NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(WorkerNavigator, AddRef) michael@0: NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(WorkerNavigator, Release) michael@0: michael@0: /* static */ already_AddRefed michael@0: WorkerNavigator::Create(bool aOnLine) michael@0: { michael@0: RuntimeService* rts = RuntimeService::GetService(); michael@0: MOZ_ASSERT(rts); michael@0: michael@0: const RuntimeService::NavigatorProperties& properties = michael@0: rts->GetNavigatorProperties(); michael@0: michael@0: nsRefPtr navigator = michael@0: new WorkerNavigator(properties, aOnLine); michael@0: michael@0: return navigator.forget(); michael@0: } michael@0: michael@0: JSObject* michael@0: WorkerNavigator::WrapObject(JSContext* aCx) michael@0: { michael@0: return WorkerNavigatorBinding_workers::Wrap(aCx, this); michael@0: } michael@0: michael@0: void michael@0: WorkerNavigator::GetAppName(nsString& aAppName) const michael@0: { michael@0: WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate(); michael@0: MOZ_ASSERT(workerPrivate); michael@0: michael@0: if (!mProperties.mAppNameOverridden.IsEmpty() && michael@0: !workerPrivate->UsesSystemPrincipal()) { michael@0: aAppName = mProperties.mAppNameOverridden; michael@0: } else { michael@0: aAppName = mProperties.mAppName; michael@0: } michael@0: } michael@0: michael@0: void michael@0: WorkerNavigator::GetAppVersion(nsString& aAppVersion) const michael@0: { michael@0: WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate(); michael@0: MOZ_ASSERT(workerPrivate); michael@0: michael@0: if (!mProperties.mAppVersionOverridden.IsEmpty() && michael@0: !workerPrivate->UsesSystemPrincipal()) { michael@0: aAppVersion = mProperties.mAppVersionOverridden; michael@0: } else { michael@0: aAppVersion = mProperties.mAppVersion; michael@0: } michael@0: } michael@0: michael@0: void michael@0: WorkerNavigator::GetPlatform(nsString& aPlatform) const michael@0: { michael@0: WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate(); michael@0: MOZ_ASSERT(workerPrivate); michael@0: michael@0: if (!mProperties.mPlatformOverridden.IsEmpty() && michael@0: !workerPrivate->UsesSystemPrincipal()) { michael@0: aPlatform = mProperties.mPlatformOverridden; michael@0: } else { michael@0: aPlatform = mProperties.mPlatform; michael@0: } michael@0: } michael@0: michael@0: END_WORKERS_NAMESPACE