Commit 190dbb5c authored by kinuko@chromium.org's avatar kinuko@chromium.org

Do not return FileSystem contents if the profile is in incognito mode.

BUG=178304
TEST=FileSystem{,Dir}URLRequestJobTest.*
TEST=manual

Review URL: https://chromiumcodereview.appspot.com/23494028

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@221670 0039d316-1c4b-4281-b951-d872f2087c98
parent 4885b8e3
......@@ -120,6 +120,7 @@ FileSystemContext::FileSystemContext(
additional_backends_(additional_backends.Pass()),
external_mount_points_(external_mount_points),
partition_path_(partition_path),
is_incognito_(options.is_incognito()),
operation_runner_(new FileSystemOperationRunner(this)) {
RegisterBackend(sandbox_backend_.get());
RegisterBackend(isolated_backend_.get());
......@@ -349,6 +350,18 @@ void FileSystemContext::EnableTemporaryFileSystemInIncognito() {
}
#endif
bool FileSystemContext::CanServeURLRequest(const FileSystemURL& url) const {
if (!is_incognito_)
return true;
#if defined(OS_CHROMEOS) && defined(GOOGLE_CHROME_BUILD)
if (url.type() == kFileSystemTypeTemporary &&
sandbox_backend_->enable_temporary_file_system_in_incognito()) {
return true;
}
#endif
return false;
}
FileSystemContext::~FileSystemContext() {
}
......
......@@ -227,6 +227,10 @@ class WEBKIT_STORAGE_BROWSER_EXPORT FileSystemContext
return sandbox_delegate_.get();
}
// Returns true if the requested url is ok to be served.
// (E.g. this returns false if the context is created for incognito mode)
bool CanServeURLRequest(const FileSystemURL& url) const;
private:
typedef std::map<FileSystemType, FileSystemBackend*>
FileSystemBackendMap;
......@@ -308,6 +312,8 @@ class WEBKIT_STORAGE_BROWSER_EXPORT FileSystemContext
// The base path of the storage partition for this context.
const base::FilePath partition_path_;
bool is_incognito_;
scoped_ptr<FileSystemOperationRunner> operation_runner_;
DISALLOW_IMPLICIT_CONSTRUCTORS(FileSystemContext);
......
......@@ -23,6 +23,7 @@
#include "webkit/browser/fileapi/file_system_operation_runner.h"
#include "webkit/browser/fileapi/file_system_url.h"
#include "webkit/common/fileapi/directory_entry.h"
#include "webkit/common/fileapi/file_system_util.h"
using net::NetworkDelegate;
using net::URLRequest;
......@@ -80,6 +81,19 @@ void FileSystemDirURLRequestJob::StartAsync() {
if (!request_)
return;
url_ = file_system_context_->CrackURL(request_->url());
if (!file_system_context_->CanServeURLRequest(url_)) {
// In incognito mode the API is not usable and there should be no data.
if (url_.is_valid() && VirtualPath::IsRootPath(url_.virtual_path())) {
// Return an empty directory if the filesystem root is queried.
DidReadDirectory(base::PLATFORM_FILE_OK,
std::vector<DirectoryEntry>(),
false);
return;
}
NotifyDone(URLRequestStatus(URLRequestStatus::FAILED,
net::ERR_FILE_NOT_FOUND));
return;
}
file_system_context_->operation_runner()->ReadDirectory(
url_,
base::Bind(&FileSystemDirURLRequestJob::DidReadDirectory, this));
......
......@@ -78,12 +78,13 @@ class FileSystemDirURLRequestJobTest : public testing::Test {
ASSERT_EQ(base::PLATFORM_FILE_OK, result);
}
void TestRequestHelper(const GURL& url, bool run_to_completion) {
void TestRequestHelper(const GURL& url, bool run_to_completion,
FileSystemContext* file_system_context) {
delegate_.reset(new net::TestDelegate());
delegate_->set_quit_on_redirect(true);
request_.reset(empty_context_.CreateRequest(url, delegate_.get()));
job_ = new FileSystemDirURLRequestJob(
request_.get(), NULL, file_system_context_.get());
request_.get(), NULL, file_system_context);
request_->Start();
ASSERT_TRUE(request_->is_pending()); // verify that we're starting async
......@@ -92,11 +93,16 @@ class FileSystemDirURLRequestJobTest : public testing::Test {
}
void TestRequest(const GURL& url) {
TestRequestHelper(url, true);
TestRequestHelper(url, true, file_system_context_.get());
}
void TestRequestWithContext(const GURL& url,
FileSystemContext* file_system_context) {
TestRequestHelper(url, true, file_system_context);
}
void TestRequestNoRun(const GURL& url) {
TestRequestHelper(url, false);
TestRequestHelper(url, false, file_system_context_.get());
}
FileSystemURL CreateURL(const base::FilePath& file_path) {
......@@ -286,5 +292,28 @@ TEST_F(FileSystemDirURLRequestJobTest, Cancel) {
// If we get here, success! we didn't crash!
}
TEST_F(FileSystemDirURLRequestJobTest, Incognito) {
CreateDirectory("foo");
scoped_refptr<FileSystemContext> file_system_context =
CreateIncognitoFileSystemContextForTesting(NULL, temp_dir_.path());
TestRequestWithContext(CreateFileSystemURL("/"),
file_system_context.get());
ASSERT_FALSE(request_->is_pending());
ASSERT_TRUE(request_->status().is_success());
std::istringstream in(delegate_->data_received());
std::string line;
EXPECT_TRUE(std::getline(in, line));
EXPECT_FALSE(std::getline(in, line));
TestRequestWithContext(CreateFileSystemURL("foo"),
file_system_context.get());
ASSERT_FALSE(request_->is_pending());
ASSERT_FALSE(request_->status().is_success());
EXPECT_EQ(net::ERR_FILE_NOT_FOUND, request_->status().error());
}
} // namespace (anonymous)
} // namespace fileapi
......@@ -157,6 +157,11 @@ void FileSystemURLRequestJob::StartAsync() {
return;
DCHECK(!reader_.get());
url_ = file_system_context_->CrackURL(request_->url());
if (!file_system_context_->CanServeURLRequest(url_)) {
// In incognito mode the API is not usable and there should be no data.
NotifyFailed(net::ERR_FILE_NOT_FOUND);
return;
}
file_system_context_->operation_runner()->GetMetadata(
url_,
base::Bind(&FileSystemURLRequestJob::DidGetMetadata,
......
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
......@@ -29,6 +29,7 @@
#include "net/url_request/url_request_test_util.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "webkit/browser/fileapi/async_file_test_helper.h"
#include "webkit/browser/fileapi/external_mount_points.h"
#include "webkit/browser/fileapi/file_system_context.h"
#include "webkit/browser/fileapi/file_system_file_util.h"
#include "webkit/browser/fileapi/mock_file_system_context.h"
......@@ -91,7 +92,8 @@ class FileSystemURLRequestJobTest : public testing::Test {
void TestRequestHelper(const GURL& url,
const net::HttpRequestHeaders* headers,
bool run_to_completion) {
bool run_to_completion,
FileSystemContext* file_system_context) {
delegate_.reset(new net::TestDelegate());
// Make delegate_ exit the MessageLoop when the request is done.
delegate_->set_quit_on_complete(true);
......@@ -101,7 +103,7 @@ class FileSystemURLRequestJobTest : public testing::Test {
request_->SetExtraRequestHeaders(*headers);
ASSERT_TRUE(!job_);
job_ = new FileSystemURLRequestJob(
request_.get(), NULL, file_system_context_.get());
request_.get(), NULL, file_system_context);
pending_job_ = job_;
request_->Start();
......@@ -111,16 +113,21 @@ class FileSystemURLRequestJobTest : public testing::Test {
}
void TestRequest(const GURL& url) {
TestRequestHelper(url, NULL, true);
TestRequestHelper(url, NULL, true, file_system_context_.get());
}
void TestRequestWithContext(const GURL& url,
FileSystemContext* file_system_context) {
TestRequestHelper(url, NULL, true, file_system_context);
}
void TestRequestWithHeaders(const GURL& url,
const net::HttpRequestHeaders* headers) {
TestRequestHelper(url, headers, true);
TestRequestHelper(url, headers, true, file_system_context_.get());
}
void TestRequestNoRun(const GURL& url) {
TestRequestHelper(url, NULL, false);
TestRequestHelper(url, NULL, false, file_system_context_.get());
}
void CreateDirectory(const base::StringPiece& dir_name) {
......@@ -332,5 +339,26 @@ TEST_F(FileSystemURLRequestJobTest, GetMimeType) {
EXPECT_EQ(mime_type_direct, mime_type_from_job);
}
TEST_F(FileSystemURLRequestJobTest, Incognito) {
WriteFile("file", kTestFileData, arraysize(kTestFileData) - 1);
// Creates a new filesystem context for incognito mode.
scoped_refptr<FileSystemContext> file_system_context =
CreateIncognitoFileSystemContextForTesting(NULL, temp_dir_.path());
// The request should return NOT_FOUND error if it's in incognito mode.
TestRequestWithContext(CreateFileSystemURL("file"),
file_system_context.get());
ASSERT_FALSE(request_->is_pending());
EXPECT_TRUE(delegate_->request_failed());
EXPECT_EQ(net::ERR_FILE_NOT_FOUND, request_->status().error());
// Make sure it returns success with regular (non-incognito) context.
TestRequest(CreateFileSystemURL("file"));
ASSERT_FALSE(request_->is_pending());
EXPECT_EQ(kTestFileData, delegate_->data_received());
EXPECT_EQ(200, request_->GetResponseCode());
}
} // namespace
} // namespace fileapi
......@@ -39,4 +39,19 @@ FileSystemContext* CreateFileSystemContextWithAdditionalProvidersForTesting(
CreateAllowFileAccessOptions());
}
FileSystemContext* CreateIncognitoFileSystemContextForTesting(
quota::QuotaManagerProxy* quota_manager_proxy,
const base::FilePath& base_path) {
ScopedVector<FileSystemBackend> additional_providers;
return new FileSystemContext(
base::MessageLoopProxy::current().get(),
base::MessageLoopProxy::current().get(),
ExternalMountPoints::CreateRefCounted().get(),
make_scoped_refptr(new quota::MockSpecialStoragePolicy()).get(),
quota_manager_proxy,
additional_providers.Pass(),
base_path,
CreateIncognitoFileSystemOptions());
}
} // namespace fileapi
......@@ -29,6 +29,10 @@ FileSystemContext* CreateFileSystemContextWithAdditionalProvidersForTesting(
ScopedVector<FileSystemBackend> additional_providers,
const base::FilePath& base_path);
FileSystemContext* CreateIncognitoFileSystemContextForTesting(
quota::QuotaManagerProxy* quota_manager_proxy,
const base::FilePath& base_path);
} // namespace fileapi
#endif // WEBKIT_BROWSER_FILEAPI_MOCK_FILE_SYSTEM_CONTEXT_H_
......@@ -66,6 +66,10 @@ class WEBKIT_STORAGE_BROWSER_EXPORT SandboxFileSystemBackend
void set_enable_temporary_file_system_in_incognito(bool enable) {
enable_temporary_file_system_in_incognito_ = enable;
}
bool enable_temporary_file_system_in_incognito() const {
return enable_temporary_file_system_in_incognito_;
}
private:
SandboxFileSystemBackendDelegate* delegate_; // Not owned.
......
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