Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 /* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
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/. */
6 #include "Navigator.h"
8 #include "mozilla/dom/WorkerNavigatorBinding.h"
10 #include "RuntimeService.h"
11 #include "WorkerPrivate.h"
13 BEGIN_WORKERS_NAMESPACE
15 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_0(WorkerNavigator)
17 NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(WorkerNavigator, AddRef)
18 NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(WorkerNavigator, Release)
20 /* static */ already_AddRefed<WorkerNavigator>
21 WorkerNavigator::Create(bool aOnLine)
22 {
23 RuntimeService* rts = RuntimeService::GetService();
24 MOZ_ASSERT(rts);
26 const RuntimeService::NavigatorProperties& properties =
27 rts->GetNavigatorProperties();
29 nsRefPtr<WorkerNavigator> navigator =
30 new WorkerNavigator(properties, aOnLine);
32 return navigator.forget();
33 }
35 JSObject*
36 WorkerNavigator::WrapObject(JSContext* aCx)
37 {
38 return WorkerNavigatorBinding_workers::Wrap(aCx, this);
39 }
41 void
42 WorkerNavigator::GetAppName(nsString& aAppName) const
43 {
44 WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate();
45 MOZ_ASSERT(workerPrivate);
47 if (!mProperties.mAppNameOverridden.IsEmpty() &&
48 !workerPrivate->UsesSystemPrincipal()) {
49 aAppName = mProperties.mAppNameOverridden;
50 } else {
51 aAppName = mProperties.mAppName;
52 }
53 }
55 void
56 WorkerNavigator::GetAppVersion(nsString& aAppVersion) const
57 {
58 WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate();
59 MOZ_ASSERT(workerPrivate);
61 if (!mProperties.mAppVersionOverridden.IsEmpty() &&
62 !workerPrivate->UsesSystemPrincipal()) {
63 aAppVersion = mProperties.mAppVersionOverridden;
64 } else {
65 aAppVersion = mProperties.mAppVersion;
66 }
67 }
69 void
70 WorkerNavigator::GetPlatform(nsString& aPlatform) const
71 {
72 WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate();
73 MOZ_ASSERT(workerPrivate);
75 if (!mProperties.mPlatformOverridden.IsEmpty() &&
76 !workerPrivate->UsesSystemPrincipal()) {
77 aPlatform = mProperties.mPlatformOverridden;
78 } else {
79 aPlatform = mProperties.mPlatform;
80 }
81 }
83 END_WORKERS_NAMESPACE