Commit 5c7ce932 authored by John Rummell's avatar John Rummell Committed by Commit Bot

Enable PluginPrivateFileSystem to be used in incognito mode

Now that FileStreamReader and FileStreamWriter work with
PluginPrivateFileSystem, enable incognito mode for
PluginPrivateFileSystem.

Also updates FileStreamReader to work with the PluginPrivateFileSystem
in incognito mode, as the ObfuscatedFileUtilMemoryDelegate is
different.

This adds 2 more browser tests that verify that encrypted media
can read and write files successfully in incognito mode (as it
uses the PluginPrivateFileSystem). Verified using inotifywait that
the test does not write anything to disk.

Bug: 958294,902021
Test: new browser_tests pass
Change-Id: I01914cdd866ff96867e7bebfeaea6ef827a5a9fd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1718985Reviewed-by: default avatarHiroki Nakagawa <nhiroki@chromium.org>
Reviewed-by: default avatarXiaohan Wang <xhwang@chromium.org>
Commit-Queue: John Rummell <jrummell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#682094}
parent 52bc9b90
......@@ -359,6 +359,30 @@ class ECKEncryptedMediaTest : public EncryptedMediaTestBase,
}
};
class ECKIncognitoEncryptedMediaTest : public EncryptedMediaTestBase {
public:
// We use special |key_system| names to do non-playback related tests,
// e.g. kExternalClearKeyFileIOTestKeySystem is used to test file IO.
void TestNonPlaybackCases(const std::string& key_system,
const std::string& expected_title) {
// Make sure the Clear Key CDM is properly registered in CdmRegistry.
EXPECT_TRUE(IsLibraryCdmRegistered(media::kClearKeyCdmGuid));
// Since we do not test playback, arbitrarily choose a test file and source
// type.
RunEncryptedMediaTest(kDefaultEmePlayer, "bear-a_enc-a.webm", key_system,
SrcType::SRC, kNoSessionToLoad, false,
PlayCount::ONCE, expected_title);
}
protected:
void SetUpCommandLine(base::CommandLine* command_line) override {
EncryptedMediaTestBase::SetUpCommandLine(command_line);
SetUpCommandLineForKeySystem(kExternalClearKeyKeySystem, command_line);
command_line->AppendSwitch(switches::kIncognito);
}
};
#endif // BUILDFLAG(ENABLE_LIBRARY_CDMS)
// Tests encrypted media playback with a combination of parameters:
......@@ -961,4 +985,23 @@ IN_PROC_BROWSER_TEST_P(ECKEncryptedMediaTest, CdmProxy) {
kExternalClearKeyCdmProxyKeySystem, SrcType::MSE);
}
// Incognito tests. Ideally we would run all above tests in incognito mode to
// ensure that everything works. However, that would add a lot of extra tests
// that aren't really testing anything different, as normal playback does not
// save anything to disk. Instead we are only running the tests that actually
// have the CDM do file access.
IN_PROC_BROWSER_TEST_F(ECKIncognitoEncryptedMediaTest, FileIO) {
// Try the FileIO test using the default CDM API while running in incognito.
TestNonPlaybackCases(kExternalClearKeyFileIOTestKeySystem, kUnitTestSuccess);
}
IN_PROC_BROWSER_TEST_F(ECKIncognitoEncryptedMediaTest, LoadSessionAfterClose) {
// Loading a session should work in incognito mode.
base::StringPairs query_params{{"keySystem", kExternalClearKeyKeySystem}};
RunEncryptedMediaTestPage("eme_load_session_after_close_test.html",
kExternalClearKeyKeySystem, query_params,
media::kEnded);
}
#endif // BUILDFLAG(ENABLE_LIBRARY_CDMS)
......@@ -9,6 +9,7 @@
#include <utility>
#include "base/memory/ptr_util.h"
#include "base/memory/weak_ptr.h"
#include "base/single_thread_task_runner.h"
#include "net/base/file_stream.h"
#include "net/base/io_buffer.h"
......@@ -16,6 +17,8 @@
#include "storage/browser/fileapi/file_system_context.h"
#include "storage/browser/fileapi/file_system_features.h"
#include "storage/browser/fileapi/file_system_operation_runner.h"
#include "storage/browser/fileapi/obfuscated_file_util_memory_delegate.h"
#include "storage/browser/fileapi/plugin_private_file_system_backend.h"
using storage::FileStreamReader;
......@@ -102,9 +105,20 @@ void FileSystemFileStreamReader::DidCreateSnapshot(
if (file_system_context_->is_incognito() &&
base::FeatureList::IsEnabled(features::kEnableFilesystemInIncognito)) {
base::WeakPtr<ObfuscatedFileUtilMemoryDelegate> memory_file_util_delegate;
if (url_.type() == kFileSystemTypePluginPrivate) {
auto* backend = static_cast<PluginPrivateFileSystemBackend*>(
file_system_context_->GetFileSystemBackend(
kFileSystemTypePluginPrivate));
memory_file_util_delegate =
backend->obfuscated_file_util_memory_delegate()->GetWeakPtr();
} else {
memory_file_util_delegate =
file_system_context_->sandbox_delegate()->memory_file_util_delegate();
}
file_reader_ = FileStreamReader::CreateForMemoryFile(
file_system_context_->sandbox_delegate()->memory_file_util_delegate(),
platform_path, initial_offset_, expected_modification_time_);
memory_file_util_delegate, platform_path, initial_offset_,
expected_modification_time_);
} else {
file_reader_ = FileStreamReader::CreateForLocalFile(
file_system_context_->default_file_task_runner(), platform_path,
......
......@@ -127,7 +127,7 @@ void PluginPrivateFileSystemBackend::OpenPrivateFileSystem(
const std::string& plugin_id,
OpenFileSystemMode mode,
StatusCallback callback) {
if (!CanHandleType(type) || file_system_options_.is_incognito()) {
if (!CanHandleType(type)) {
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE,
base::BindOnce(std::move(callback), base::File::FILE_ERROR_SECURITY));
......
......@@ -133,12 +133,12 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) PluginPrivateFileSystemBackend
int64_t* total_size,
base::Time* last_modified_time);
ObfuscatedFileUtilMemoryDelegate* obfuscated_file_util_memory_delegate();
private:
friend class content::PluginPrivateFileSystemBackendTest;
friend class SandboxFileStreamWriter;
ObfuscatedFileUtil* obfuscated_file_util();
ObfuscatedFileUtilMemoryDelegate* obfuscated_file_util_memory_delegate();
const base::FilePath& base_path() const { return base_path_; }
scoped_refptr<base::SequencedTaskRunner> file_task_runner_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment