/src/mozilla-central/dom/media/gmp/GMPProcessParent.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
2 | | * vim: sw=2 ts=2 et : |
3 | | * This Source Code Form is subject to the terms of the Mozilla Public |
4 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
5 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | | |
7 | | #include "GMPProcessParent.h" |
8 | | #include "GMPUtils.h" |
9 | | #include "nsIFile.h" |
10 | | #include "nsIRunnable.h" |
11 | | #if defined(XP_WIN) && defined(MOZ_SANDBOX) |
12 | | #include "WinUtils.h" |
13 | | #endif |
14 | | #include "GMPLog.h" |
15 | | |
16 | | #include "base/string_util.h" |
17 | | #include "base/process_util.h" |
18 | | |
19 | | #include <string> |
20 | | |
21 | | using std::vector; |
22 | | using std::string; |
23 | | |
24 | | using mozilla::gmp::GMPProcessParent; |
25 | | using mozilla::ipc::GeckoChildProcessHost; |
26 | | |
27 | | static const int kInvalidFd = -1; |
28 | | |
29 | | namespace mozilla { |
30 | | namespace gmp { |
31 | | |
32 | | GMPProcessParent::GMPProcessParent(const std::string& aGMPPath) |
33 | | : GeckoChildProcessHost(GeckoProcessType_GMPlugin), |
34 | | mGMPPath(aGMPPath) |
35 | 0 | { |
36 | 0 | MOZ_COUNT_CTOR(GMPProcessParent); |
37 | 0 | } |
38 | | |
39 | | GMPProcessParent::~GMPProcessParent() |
40 | 0 | { |
41 | 0 | MOZ_COUNT_DTOR(GMPProcessParent); |
42 | 0 | } |
43 | | |
44 | | bool |
45 | | GMPProcessParent::Launch(int32_t aTimeoutMs) |
46 | 0 | { |
47 | 0 | vector<string> args; |
48 | 0 |
|
49 | | #if defined(XP_WIN) && defined(MOZ_SANDBOX) |
50 | | std::wstring wGMPPath = UTF8ToWide(mGMPPath.c_str()); |
51 | | |
52 | | // The sandbox doesn't allow file system rules where the paths contain |
53 | | // symbolic links or junction points. Sometimes the Users folder has been |
54 | | // moved to another drive using a junction point, so allow for this specific |
55 | | // case. See bug 1236680 for details. |
56 | | if (!widget::WinUtils::ResolveJunctionPointsAndSymLinks(wGMPPath)) { |
57 | | GMP_LOG("ResolveJunctionPointsAndSymLinks failed for GMP path=%S", |
58 | | wGMPPath.c_str()); |
59 | | NS_WARNING("ResolveJunctionPointsAndSymLinks failed for GMP path."); |
60 | | return false; |
61 | | } |
62 | | GMP_LOG("GMPProcessParent::Launch() resolved path to %S", wGMPPath.c_str()); |
63 | | |
64 | | // If the GMP path is a network path that is not mapped to a drive letter, |
65 | | // then we need to fix the path format for the sandbox rule. |
66 | | wchar_t volPath[MAX_PATH]; |
67 | | if (::GetVolumePathNameW(wGMPPath.c_str(), volPath, MAX_PATH) && |
68 | | ::GetDriveTypeW(volPath) == DRIVE_REMOTE && |
69 | | wGMPPath.compare(0, 2, L"\\\\") == 0) { |
70 | | std::wstring sandboxGMPPath(wGMPPath); |
71 | | sandboxGMPPath.insert(1, L"??\\UNC"); |
72 | | mAllowedFilesRead.push_back(sandboxGMPPath + L"\\*"); |
73 | | } else { |
74 | | mAllowedFilesRead.push_back(wGMPPath + L"\\*"); |
75 | | } |
76 | | |
77 | | args.push_back(WideToUTF8(wGMPPath)); |
78 | | #else |
79 | | args.push_back(mGMPPath); |
80 | 0 | #endif |
81 | 0 |
|
82 | | #ifdef MOZ_WIDGET_ANDROID |
83 | | // Add dummy values for pref and pref map to the file descriptors remapping |
84 | | // table. See bug 1440207 and 1481139. |
85 | | AddFdToRemap(kInvalidFd, kInvalidFd); |
86 | | AddFdToRemap(kInvalidFd, kInvalidFd); |
87 | | #endif |
88 | | return SyncLaunch(args, aTimeoutMs); |
89 | 0 | } |
90 | | |
91 | | void |
92 | | GMPProcessParent::Delete(nsCOMPtr<nsIRunnable> aCallback) |
93 | 0 | { |
94 | 0 | mDeletedCallback = aCallback; |
95 | 0 | XRE_GetIOMessageLoop()->PostTask(NewNonOwningRunnableMethod( |
96 | 0 | "gmp::GMPProcessParent::DoDelete", this, &GMPProcessParent::DoDelete)); |
97 | 0 | } |
98 | | |
99 | | void |
100 | | GMPProcessParent::DoDelete() |
101 | 0 | { |
102 | 0 | MOZ_ASSERT(MessageLoop::current() == XRE_GetIOMessageLoop()); |
103 | 0 | Join(); |
104 | 0 |
|
105 | 0 | if (mDeletedCallback) { |
106 | 0 | mDeletedCallback->Run(); |
107 | 0 | } |
108 | 0 |
|
109 | 0 | delete this; |
110 | 0 | } |
111 | | |
112 | | } // namespace gmp |
113 | | } // namespace mozilla |