From 741fb93d5a8012931fb0818f1e52c3ed0bd6d851 Mon Sep 17 00:00:00 2001 From: "Carsten \"Tomcat\" Book" Date: Thu, 9 Oct 2014 12:48:24 +0200 Subject: [PATCH] Backed out changeset e7545921e875 (bug 1060179) --- content/media/gmp/GMPService.cpp | 216 +----------------- content/media/gmp/GMPService.h | 4 +- content/media/gmp/GMPStorageParent.cpp | 41 ++-- .../media/gmp/mozIGeckoMediaPluginService.idl | 9 +- 4 files changed, 34 insertions(+), 236 deletions(-) diff --git a/content/media/gmp/GMPService.cpp b/content/media/gmp/GMPService.cpp index c7ade09e270a4..2a35af2928608 100644 --- a/content/media/gmp/GMPService.cpp +++ b/content/media/gmp/GMPService.cpp @@ -26,11 +26,6 @@ #if defined(XP_LINUX) && defined(MOZ_GMP_SANDBOX) #include "mozilla/Sandbox.h" #endif -#include "nsAppDirectoryServiceDefs.h" -#include "nsDirectoryServiceUtils.h" -#include "nsDirectoryServiceDefs.h" -#include "nsHashKeys.h" -#include "nsIFile.h" namespace mozilla { @@ -160,7 +155,7 @@ GeckoMediaPluginService::~GeckoMediaPluginService() MOZ_ASSERT(mAsyncShutdownPlugins.IsEmpty()); } -nsresult +void GeckoMediaPluginService::Init() { MOZ_ASSERT(NS_IsMainThread()); @@ -175,26 +170,9 @@ GeckoMediaPluginService::Init() prefs->AddObserver("media.gmp.plugin.crash", this, false); } - // Directory service is main thread only, so cache the profile dir here - // so that we can use it off main thread. - nsresult rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR, getter_AddRefs(mStorageBaseDir)); - if (NS_WARN_IF(NS_FAILED(rv))) { - return rv; - } - - rv = mStorageBaseDir->AppendNative(NS_LITERAL_CSTRING("gmp")); - if (NS_WARN_IF(NS_FAILED(rv))) { - return rv; - } - - rv = mStorageBaseDir->Create(nsIFile::DIRECTORY_TYPE, 0700); - if (NS_WARN_IF(NS_FAILED(rv) && rv != NS_ERROR_FILE_ALREADY_EXISTS)) { - return rv; - } - // Kick off scanning for plugins nsCOMPtr thread; - return GetThread(getter_AddRefs(thread)); + unused << GetThread(getter_AddRefs(thread)); } void @@ -877,86 +855,6 @@ GeckoMediaPluginService::ReAddOnGMPThread(nsRefPtr& aOld) NS_DispatchToCurrentThread(WrapRunnableNM(&Dummy, aOld)); } -NS_IMETHODIMP -GeckoMediaPluginService::GetStorageDir(nsIFile** aOutFile) -{ - if (NS_WARN_IF(!mStorageBaseDir)) { - return NS_ERROR_FAILURE; - } - return mStorageBaseDir->Clone(aOutFile); -} - -static nsresult -WriteToFile(nsIFile* aPath, - const nsCString& aFileName, - const nsCString& aData) -{ - nsCOMPtr path; - nsresult rv = aPath->Clone(getter_AddRefs(path)); - if (NS_WARN_IF(NS_FAILED(rv))) { - return rv; - } - - rv = path->AppendNative(aFileName); - if (NS_WARN_IF(NS_FAILED(rv))) { - return rv; - } - - PRFileDesc* f = nullptr; - rv = path->OpenNSPRFileDesc(PR_WRONLY | PR_CREATE_FILE, PR_IRWXU, &f); - if (NS_WARN_IF(NS_FAILED(rv))) { - return rv; - } - - int32_t len = PR_Write(f, aData.get(), aData.Length()); - PR_Close(f); - if (NS_WARN_IF(len < 0 || (size_t)len != aData.Length())) { - return NS_ERROR_FAILURE; - } - - return NS_OK; -} - -static nsresult -ReadFromFile(nsIFile* aPath, - const nsCString& aFileName, - nsCString& aOutData, - int32_t aMaxLength) -{ - nsCOMPtr path; - nsresult rv = aPath->Clone(getter_AddRefs(path)); - if (NS_WARN_IF(NS_FAILED(rv))) { - return rv; - } - - rv = path->AppendNative(aFileName); - if (NS_WARN_IF(NS_FAILED(rv))) { - return rv; - } - - PRFileDesc* f = nullptr; - rv = path->OpenNSPRFileDesc(PR_RDONLY | PR_CREATE_FILE, PR_IRWXU, &f); - if (NS_WARN_IF(NS_FAILED(rv))) { - return rv; - } - - auto size = PR_Seek(f, 0, PR_SEEK_END); - PR_Seek(f, 0, PR_SEEK_SET); - - if (size > aMaxLength) { - return NS_ERROR_FAILURE; - } - aOutData.SetLength(size); - - auto len = PR_Read(f, aOutData.BeginWriting(), size); - PR_Close(f); - if (NS_WARN_IF(len != size)) { - return NS_ERROR_FAILURE; - } - - return NS_OK; -} - NS_IMETHODIMP GeckoMediaPluginService::GetNodeId(const nsAString& aOrigin, const nsAString& aTopLevelOrigin, @@ -969,116 +867,14 @@ GeckoMediaPluginService::GetNodeId(const nsAString& aOrigin, NS_ConvertUTF16toUTF8(aTopLevelOrigin).get(), (aInPrivateBrowsing ? "PrivateBrowsing" : "NonPrivateBrowsing"))); - nsresult rv; - const uint32_t NodeIdSaltLength = 32; - - if (aInPrivateBrowsing || - aOrigin.EqualsLiteral("null") || - aOrigin.IsEmpty() || - aTopLevelOrigin.EqualsLiteral("null") || - aTopLevelOrigin.IsEmpty()) { - // Non-persistent session; just generate a random node id. - nsAutoCString salt; - rv = GenerateRandomPathName(salt, NodeIdSaltLength); - aOutId = salt; - return rv; - } - - // Otherwise, try to see if we've previously generated and stored salt - // for this origin pair. - nsCOMPtr path; // $profileDir/gmp/ - rv = GetStorageDir(getter_AddRefs(path)); - if (NS_WARN_IF(NS_FAILED(rv))) { - return rv; - } - - rv = path->AppendNative(NS_LITERAL_CSTRING("id")); - if (NS_WARN_IF(NS_FAILED(rv))) { - return rv; - } - - // $profileDir/gmp/id/ - rv = path->Create(nsIFile::DIRECTORY_TYPE, 0700); - if (rv != NS_ERROR_FILE_ALREADY_EXISTS && NS_WARN_IF(NS_FAILED(rv))) { - return rv; - } - - uint32_t hash = AddToHash(HashString(aOrigin), - HashString(aTopLevelOrigin)); - nsAutoCString hashStr; - hashStr.AppendInt((int64_t)hash); - - // $profileDir/gmp/id/$hash - rv = path->AppendNative(hashStr); - if (NS_WARN_IF(NS_FAILED(rv))) { - return rv; - } - - rv = path->Create(nsIFile::DIRECTORY_TYPE, 0700); - if (rv != NS_ERROR_FILE_ALREADY_EXISTS && NS_WARN_IF(NS_FAILED(rv))) { - return rv; - } - - nsCOMPtr saltFile; - rv = path->Clone(getter_AddRefs(saltFile)); - if (NS_WARN_IF(NS_FAILED(rv))) { - return rv; - } - - rv = saltFile->AppendNative(NS_LITERAL_CSTRING("salt")); - if (NS_WARN_IF(NS_FAILED(rv))) { - return rv; - } - nsAutoCString salt; - bool exists = false; - rv = saltFile->Exists(&exists); - if (NS_WARN_IF(NS_FAILED(rv))) { - return rv; - } - if (!exists) { - // No stored salt for this origin. Generate salt, and store it and - // the origin on disk. - nsresult rv = GenerateRandomPathName(salt, NodeIdSaltLength); - if (NS_WARN_IF(NS_FAILED(rv))) { - return rv; - } - MOZ_ASSERT(salt.Length() == NodeIdSaltLength); - - // $profileDir/gmp/id/$hash/salt - rv = WriteToFile(path, NS_LITERAL_CSTRING("salt"), salt); - if (NS_WARN_IF(NS_FAILED(rv))) { - return rv; - } - - // $profileDir/gmp/id/$hash/origin - rv = WriteToFile(path, - NS_LITERAL_CSTRING("origin"), - NS_ConvertUTF16toUTF8(aOrigin)); - if (NS_WARN_IF(NS_FAILED(rv))) { - return rv; - } - - // $profileDir/gmp/id/$hash/topLevelOrigin - rv = WriteToFile(path, - NS_LITERAL_CSTRING("topLevelOrigin"), - NS_ConvertUTF16toUTF8(aTopLevelOrigin)); - if (NS_WARN_IF(NS_FAILED(rv))) { - return rv; - } - - } else { - rv = ReadFromFile(path, - NS_LITERAL_CSTRING("salt"), - salt, - NodeIdSaltLength); - if (NS_WARN_IF(NS_FAILED(rv))) { - return rv; - } - } + nsresult rv = GenerateRandomPathName(salt, 32); + NS_ENSURE_SUCCESS(rv, rv); aOutId = salt; + // TODO: Store salt, so it can be retrieved in subsequent sessions. + return NS_OK; } diff --git a/content/media/gmp/GMPService.h b/content/media/gmp/GMPService.h index 8f28b1c7d32b4..0ea8683165823 100644 --- a/content/media/gmp/GMPService.h +++ b/content/media/gmp/GMPService.h @@ -32,7 +32,7 @@ class GeckoMediaPluginService MOZ_FINAL : public mozIGeckoMediaPluginService static already_AddRefed GetGeckoMediaPluginService(); GeckoMediaPluginService(); - nsresult Init(); + void Init(); NS_DECL_THREADSAFE_ISUPPORTS NS_DECL_MOZIGECKOMEDIAPLUGINSERVICE @@ -111,8 +111,6 @@ class GeckoMediaPluginService MOZ_FINAL : public mozIGeckoMediaPluginService nsTArray> mAsyncShutdownPlugins; // GMP Thread only. nsCOMPtr mAsyncShutdownTimeout; // GMP Thread only. - - nsCOMPtr mStorageBaseDir; }; } // namespace gmp diff --git a/content/media/gmp/GMPStorageParent.cpp b/content/media/gmp/GMPStorageParent.cpp index 7db906402aa48..e54537d3c024b 100644 --- a/content/media/gmp/GMPStorageParent.cpp +++ b/content/media/gmp/GMPStorageParent.cpp @@ -8,7 +8,6 @@ #include "plhash.h" #include "nsDirectoryServiceUtils.h" #include "nsDirectoryServiceDefs.h" -#include "nsAppDirectoryServiceDefs.h" #include "GMPParent.h" #include "gmp-storage.h" #include "mozilla/unused.h" @@ -36,8 +35,26 @@ extern PRLogModuleInfo* GetGMPLog(); namespace gmp { -// We store the records in files in the profile dir. -// $profileDir/gmp/storage/$nodeId/ +class GetTempDirTask : public nsRunnable +{ +public: + NS_IMETHOD Run() { + MOZ_ASSERT(NS_IsMainThread()); + + nsCOMPtr tmpFile; + nsresult rv = NS_GetSpecialDirectory(NS_OS_TEMP_DIR, getter_AddRefs(tmpFile)); + if (NS_WARN_IF(NS_FAILED(rv))) { + return rv; + } + + tmpFile->GetPath(mPath); + return NS_OK; + } + + nsString mPath; +}; + +// We store the records in files in the system temp dir. static nsresult GetGMPStorageDir(nsIFile** aTempDir, const nsCString& aNodeId) { @@ -45,28 +62,22 @@ GetGMPStorageDir(nsIFile** aTempDir, const nsCString& aNodeId) return NS_ERROR_INVALID_ARG; } - nsCOMPtr mps = - do_GetService("@mozilla.org/gecko-media-plugin-service;1"); - if (NS_WARN_IF(!mps)) { - return NS_ERROR_FAILURE; - } + // Directory service is main thread only... + nsRefPtr task = new GetTempDirTask(); + nsCOMPtr mainThread = do_GetMainThread(); + mozilla::SyncRunnable::DispatchToThread(mainThread, task); nsCOMPtr tmpFile; - nsresult rv = mps->GetStorageDir(getter_AddRefs(tmpFile)); + nsresult rv = NS_NewLocalFile(task->mPath, false, getter_AddRefs(tmpFile)); if (NS_WARN_IF(NS_FAILED(rv))) { return rv; } - rv = tmpFile->AppendNative(NS_LITERAL_CSTRING("storage")); + rv = tmpFile->AppendNative(nsDependentCString("mozilla-gmp-storage")); if (NS_WARN_IF(NS_FAILED(rv))) { return rv; } - rv = tmpFile->Create(nsIFile::DIRECTORY_TYPE, 0700); - if (rv != NS_ERROR_FILE_ALREADY_EXISTS && NS_WARN_IF(NS_FAILED(rv))) { - return rv; - } - rv = tmpFile->AppendNative(aNodeId); if (NS_WARN_IF(NS_FAILED(rv))) { return rv; diff --git a/content/media/gmp/mozIGeckoMediaPluginService.idl b/content/media/gmp/mozIGeckoMediaPluginService.idl index 38c8448f34f01..a61735ce84e9e 100644 --- a/content/media/gmp/mozIGeckoMediaPluginService.idl +++ b/content/media/gmp/mozIGeckoMediaPluginService.idl @@ -6,7 +6,6 @@ #include "nsISupports.idl" #include "nsIThread.idl" #include "nsIPrincipal.idl" -#include "nsIFile.idl" %{C++ #include "nsTArray.h" @@ -26,7 +25,7 @@ class GMPVideoHost; [ptr] native GMPDecryptorProxy(GMPDecryptorProxy); [ptr] native GMPAudioDecoderProxy(GMPAudioDecoderProxy); -[scriptable, uuid(e5cde76d-f926-4b3f-84ff-62864c7a750a)] +[scriptable, uuid(3d811f9f-e1f8-48a5-a385-3657a641ee76)] interface mozIGeckoMediaPluginService : nsISupports { @@ -97,10 +96,4 @@ interface mozIGeckoMediaPluginService : nsISupports ACString getNodeId(in AString origin, in AString topLevelOrigin, in bool inPrivateBrowsingMode); - - /** - * Returns the directory to use as the base for storing data about GMPs. - */ - nsIFile getStorageDir(); - };