1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/workers/Navigator.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,83 @@ 1.4 +/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#include "Navigator.h" 1.10 + 1.11 +#include "mozilla/dom/WorkerNavigatorBinding.h" 1.12 + 1.13 +#include "RuntimeService.h" 1.14 +#include "WorkerPrivate.h" 1.15 + 1.16 +BEGIN_WORKERS_NAMESPACE 1.17 + 1.18 +NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_0(WorkerNavigator) 1.19 + 1.20 +NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(WorkerNavigator, AddRef) 1.21 +NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(WorkerNavigator, Release) 1.22 + 1.23 +/* static */ already_AddRefed<WorkerNavigator> 1.24 +WorkerNavigator::Create(bool aOnLine) 1.25 +{ 1.26 + RuntimeService* rts = RuntimeService::GetService(); 1.27 + MOZ_ASSERT(rts); 1.28 + 1.29 + const RuntimeService::NavigatorProperties& properties = 1.30 + rts->GetNavigatorProperties(); 1.31 + 1.32 + nsRefPtr<WorkerNavigator> navigator = 1.33 + new WorkerNavigator(properties, aOnLine); 1.34 + 1.35 + return navigator.forget(); 1.36 +} 1.37 + 1.38 +JSObject* 1.39 +WorkerNavigator::WrapObject(JSContext* aCx) 1.40 +{ 1.41 + return WorkerNavigatorBinding_workers::Wrap(aCx, this); 1.42 +} 1.43 + 1.44 +void 1.45 +WorkerNavigator::GetAppName(nsString& aAppName) const 1.46 +{ 1.47 + WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate(); 1.48 + MOZ_ASSERT(workerPrivate); 1.49 + 1.50 + if (!mProperties.mAppNameOverridden.IsEmpty() && 1.51 + !workerPrivate->UsesSystemPrincipal()) { 1.52 + aAppName = mProperties.mAppNameOverridden; 1.53 + } else { 1.54 + aAppName = mProperties.mAppName; 1.55 + } 1.56 +} 1.57 + 1.58 +void 1.59 +WorkerNavigator::GetAppVersion(nsString& aAppVersion) const 1.60 +{ 1.61 + WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate(); 1.62 + MOZ_ASSERT(workerPrivate); 1.63 + 1.64 + if (!mProperties.mAppVersionOverridden.IsEmpty() && 1.65 + !workerPrivate->UsesSystemPrincipal()) { 1.66 + aAppVersion = mProperties.mAppVersionOverridden; 1.67 + } else { 1.68 + aAppVersion = mProperties.mAppVersion; 1.69 + } 1.70 +} 1.71 + 1.72 +void 1.73 +WorkerNavigator::GetPlatform(nsString& aPlatform) const 1.74 +{ 1.75 + WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate(); 1.76 + MOZ_ASSERT(workerPrivate); 1.77 + 1.78 + if (!mProperties.mPlatformOverridden.IsEmpty() && 1.79 + !workerPrivate->UsesSystemPrincipal()) { 1.80 + aPlatform = mProperties.mPlatformOverridden; 1.81 + } else { 1.82 + aPlatform = mProperties.mPlatform; 1.83 + } 1.84 +} 1.85 + 1.86 +END_WORKERS_NAMESPACE