dom/workers/Navigator.cpp

branch
TOR_BUG_9701
changeset 15
b8a032363ba2
equal deleted inserted replaced
-1:000000000000 0:35f8e97089e2
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/. */
5
6 #include "Navigator.h"
7
8 #include "mozilla/dom/WorkerNavigatorBinding.h"
9
10 #include "RuntimeService.h"
11 #include "WorkerPrivate.h"
12
13 BEGIN_WORKERS_NAMESPACE
14
15 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_0(WorkerNavigator)
16
17 NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(WorkerNavigator, AddRef)
18 NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(WorkerNavigator, Release)
19
20 /* static */ already_AddRefed<WorkerNavigator>
21 WorkerNavigator::Create(bool aOnLine)
22 {
23 RuntimeService* rts = RuntimeService::GetService();
24 MOZ_ASSERT(rts);
25
26 const RuntimeService::NavigatorProperties& properties =
27 rts->GetNavigatorProperties();
28
29 nsRefPtr<WorkerNavigator> navigator =
30 new WorkerNavigator(properties, aOnLine);
31
32 return navigator.forget();
33 }
34
35 JSObject*
36 WorkerNavigator::WrapObject(JSContext* aCx)
37 {
38 return WorkerNavigatorBinding_workers::Wrap(aCx, this);
39 }
40
41 void
42 WorkerNavigator::GetAppName(nsString& aAppName) const
43 {
44 WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate();
45 MOZ_ASSERT(workerPrivate);
46
47 if (!mProperties.mAppNameOverridden.IsEmpty() &&
48 !workerPrivate->UsesSystemPrincipal()) {
49 aAppName = mProperties.mAppNameOverridden;
50 } else {
51 aAppName = mProperties.mAppName;
52 }
53 }
54
55 void
56 WorkerNavigator::GetAppVersion(nsString& aAppVersion) const
57 {
58 WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate();
59 MOZ_ASSERT(workerPrivate);
60
61 if (!mProperties.mAppVersionOverridden.IsEmpty() &&
62 !workerPrivate->UsesSystemPrincipal()) {
63 aAppVersion = mProperties.mAppVersionOverridden;
64 } else {
65 aAppVersion = mProperties.mAppVersion;
66 }
67 }
68
69 void
70 WorkerNavigator::GetPlatform(nsString& aPlatform) const
71 {
72 WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate();
73 MOZ_ASSERT(workerPrivate);
74
75 if (!mProperties.mPlatformOverridden.IsEmpty() &&
76 !workerPrivate->UsesSystemPrincipal()) {
77 aPlatform = mProperties.mPlatformOverridden;
78 } else {
79 aPlatform = mProperties.mPlatform;
80 }
81 }
82
83 END_WORKERS_NAMESPACE

mercurial