1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- 2 * vim: sw=2 ts=4 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 #ifndef GMPProcessParent_h 8 #define GMPProcessParent_h 1 9 10 #include "mozilla/Attributes.h" 11 #include "base/basictypes.h" 12 #include "base/file_path.h" 13 #include "base/thread.h" 14 #include "chrome/common/child_process_host.h" 15 #include "mozilla/ipc/GeckoChildProcessHost.h" 16 17 class nsIRunnable; 18 19 namespace mozilla { 20 namespace gmp { 21 22 class GMPProcessParent final : public mozilla::ipc::GeckoChildProcessHost { 23 public: 24 explicit GMPProcessParent(const std::string& aGMPPath); 25 26 // Synchronously launch the plugin process. If the process fails to launch 27 // after timeoutMs, this method will return false. 28 bool Launch(int32_t aTimeoutMs); 29 30 void Delete(nsCOMPtr<nsIRunnable> aCallback = nullptr); 31 CanShutdown()32 bool CanShutdown() override { return true; } GetPluginFilePath()33 const std::string& GetPluginFilePath() { return mGMPPath; } 34 35 #if defined(XP_MACOSX) && defined(MOZ_SANDBOX) 36 // Init static members on the main thread 37 static void InitStaticMainThread(); 38 39 // Read prefs and environment variables to determine 40 // when and if to start the Mac sandbox for the child 41 // process. Starting the sandbox at launch is the new 42 // preferred method. Code to support starting the sandbox 43 // later at plugin start time should be removed once 44 // starting at launch is stable and shipping. 45 bool IsMacSandboxLaunchEnabled() override; 46 47 // For process sandboxing purposes, set whether or not this 48 // instance of the GMP process requires access to the macOS 49 // window server. At present, Widevine requires window server 50 // access, but OpenH264 decoding does not. 51 void SetRequiresWindowServer(bool aRequiresWindowServer); 52 53 // Return the sandbox type to be used with this process type. GetMacSandboxType()54 static MacSandboxType GetMacSandboxType() { return MacSandboxType_GMP; }; 55 #endif 56 57 #if defined(XP_MACOSX) && defined(__aarch64__) SetLaunchArchitecture(uint32_t aArch)58 void SetLaunchArchitecture(uint32_t aArch) { mChildLaunchArch = aArch; } 59 #endif 60 61 using mozilla::ipc::GeckoChildProcessHost::GetChannel; 62 using mozilla::ipc::GeckoChildProcessHost::GetChildProcessHandle; 63 64 private: 65 ~GMPProcessParent(); 66 67 void DoDelete(); 68 69 std::string mGMPPath; 70 nsCOMPtr<nsIRunnable> mDeletedCallback; 71 72 #if defined(XP_MACOSX) && defined(MOZ_SANDBOX) 73 // Indicates whether we'll start the Mac GMP sandbox during 74 // process launch (earlyinit) which is the new preferred method 75 // or later in the process lifetime. 76 static bool sLaunchWithMacSandbox; 77 78 // Whether or not Mac sandbox violation logging is enabled. 79 static bool sMacSandboxGMPLogging; 80 81 // Override so we can set GMP-specific sandbox parameters 82 bool FillMacSandboxInfo(MacSandboxInfo& aInfo) override; 83 84 // For normalizing paths to be compatible with sandboxing. 85 // We use normalized paths to generate the sandbox ruleset. Once 86 // the sandbox has been started, resolving symlinks that point to 87 // allowed directories could require reading paths not allowed by 88 // the sandbox, so we should only attempt to load plugin libraries 89 // using normalized paths. 90 static nsresult NormalizePath(const char* aPath, nsACString& aNormalizedPath); 91 92 // Controls whether or not the sandbox will be configured with 93 // window service access. 94 bool mRequiresWindowServer; 95 96 # if defined(DEBUG) 97 // Used to assert InitStaticMainThread() is called before the constructor. 98 static bool sIsMainThreadInitDone; 99 # endif 100 #endif 101 102 #if defined(XP_MACOSX) && defined(__aarch64__) 103 uint32_t mChildLaunchArch; 104 #endif 105 106 DISALLOW_COPY_AND_ASSIGN(GMPProcessParent); 107 }; 108 109 } // namespace gmp 110 } // namespace mozilla 111 112 #endif // ifndef GMPProcessParent_h 113