Commit d9cf42f6 authored by hirono's avatar hirono Committed by Commit bot

Add GetURLForBrowserTab method to the external file system backend.

The method will be called from FileSystemURLRequestJob class to redirect requests for the drive hosted documents.

BUG=367027
TEST=manually; Add the method call to FileSystemURLRequestJob and open FileSystemURL in browser tab.

Review URL: https://codereview.chromium.org/527773003

Cr-Commit-Position: refs/heads/master@{#293494}
parent f62dbf96
......@@ -7,6 +7,7 @@
#include "base/bind.h"
#include "base/files/file_path.h"
#include "base/memory/scoped_ptr.h"
#include "chrome/browser/chromeos/drive/file_system_interface.h"
#include "chrome/browser/chromeos/drive/file_system_util.h"
#include "chrome/browser/chromeos/drive/fileapi/async_file_util.h"
#include "chrome/browser/chromeos/drive/fileapi/fileapi_worker.h"
......@@ -22,6 +23,46 @@
using content::BrowserThread;
namespace drive {
namespace {
// Called on the UI thread after GetRedirectURLForContentsOnUIThread. Obtains
// the browser URL from |entry|. |callback| will be called on the IO thread.
void GetRedirectURLForContentsOnUIThreadWithResourceEntry(
const storage::URLCallback& callback,
FileError error,
scoped_ptr<ResourceEntry> entry) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
GURL url;
if (error == FILE_ERROR_OK && entry->has_file_specific_info() &&
entry->file_specific_info().is_hosted_document()) {
url = GURL(entry->file_specific_info().alternate_url());
}
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE, base::Bind(callback, url));
}
// Called on the UI thread after
// FileSystemBackendDelegate::GetRedirectURLForContents. Requestes to obtain
// ResourceEntry for the |url|.
void GetRedirectURLForContentsOnUIThread(
const storage::FileSystemURL& url,
const storage::URLCallback& callback) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
FileSystemInterface* const file_system =
fileapi_internal::GetFileSystemFromUrl(url);
if (!file_system) {
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE, base::Bind(callback, GURL()));
return;
}
const base::FilePath file_path = util::ExtractDrivePathFromFileSystemUrl(url);
file_system->GetResourceEntry(
file_path,
base::Bind(&GetRedirectURLForContentsOnUIThreadWithResourceEntry,
callback));
}
} // namespace
FileSystemBackendDelegate::FileSystemBackendDelegate()
: async_file_util_(new internal::AsyncFileUtil) {
......@@ -86,4 +127,14 @@ storage::WatcherManager* FileSystemBackendDelegate::GetWatcherManager(
return NULL;
}
void FileSystemBackendDelegate::GetRedirectURLForContents(
const storage::FileSystemURL& url,
const storage::URLCallback& callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
BrowserThread::PostTask(
BrowserThread::UI,
FROM_HERE,
base::Bind(&GetRedirectURLForContentsOnUIThread, url, callback));
}
} // namespace drive
......@@ -41,6 +41,9 @@ class FileSystemBackendDelegate : public chromeos::FileSystemBackendDelegate {
storage::FileSystemContext* context) OVERRIDE;
virtual storage::WatcherManager* GetWatcherManager(
const storage::FileSystemURL& url) OVERRIDE;
virtual void GetRedirectURLForContents(
const storage::FileSystemURL& url,
const storage::URLCallback& callback) OVERRIDE;
private:
scoped_ptr<storage::AsyncFileUtil> async_file_util_;
......
......@@ -69,5 +69,13 @@ storage::WatcherManager* BackendDelegate::GetWatcherManager(
return NULL;
}
void BackendDelegate::GetRedirectURLForContents(
const storage::FileSystemURL& url,
const storage::URLCallback& callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK_EQ(storage::kFileSystemTypeProvided, url.type());
callback.Run(GURL());
}
} // namespace file_system_provider
} // namespace chromeos
......@@ -43,6 +43,9 @@ class BackendDelegate : public chromeos::FileSystemBackendDelegate {
storage::FileSystemContext* context) OVERRIDE;
virtual storage::WatcherManager* GetWatcherManager(
const storage::FileSystemURL& url) OVERRIDE;
virtual void GetRedirectURLForContents(
const storage::FileSystemURL& url,
const storage::URLCallback& callback) OVERRIDE;
private:
scoped_ptr<storage::AsyncFileUtil> async_file_util_;
......
......@@ -387,4 +387,33 @@ bool FileSystemBackend::GetVirtualPath(
system_mount_points_->GetVirtualPath(filesystem_path, virtual_path);
}
void FileSystemBackend::GetRedirectURLForContents(
const storage::FileSystemURL& url,
const storage::URLCallback& callback) {
DCHECK(url.is_valid());
if (!IsAccessAllowed(url))
return callback.Run(GURL());
switch (url.type()) {
case storage::kFileSystemTypeDrive:
drive_delegate_->GetRedirectURLForContents(url, callback);
return;
case storage::kFileSystemTypeProvided:
file_system_provider_delegate_->GetRedirectURLForContents(url,
callback);
return;
case storage::kFileSystemTypeDeviceMediaAsFileStorage:
mtp_delegate_->GetRedirectURLForContents(url, callback);
return;
case storage::kFileSystemTypeNativeLocal:
case storage::kFileSystemTypeRestrictedNativeLocal:
callback.Run(GURL());
return;
default:
NOTREACHED();
}
callback.Run(GURL());
}
} // namespace chromeos
......@@ -131,6 +131,9 @@ class FileSystemBackend : public storage::ExternalFileSystemBackend {
const std::string& extension_id) OVERRIDE;
virtual bool GetVirtualPath(const base::FilePath& filesystem_path,
base::FilePath* virtual_path) OVERRIDE;
virtual void GetRedirectURLForContents(
const storage::FileSystemURL& url,
const storage::URLCallback& callback) OVERRIDE;
private:
scoped_refptr<storage::SpecialStoragePolicy> special_storage_policy_;
......
......@@ -6,9 +6,13 @@
#define CHROME_BROWSER_CHROMEOS_FILEAPI_FILE_SYSTEM_BACKEND_DELEGATE_H_
#include "base/basictypes.h"
#include "base/callback_forward.h"
#include "base/memory/scoped_ptr.h"
#include "webkit/browser/fileapi/file_system_backend.h"
#include "webkit/common/fileapi/file_system_types.h"
class GURL;
namespace base {
class Time;
} // namespace base
......@@ -22,10 +26,6 @@ class FileStreamWriter;
class WatcherManager;
} // namespace storage
namespace storage {
class FileStreamReader;
} // namespace storage
namespace chromeos {
// This is delegate interface to inject the implementation of the some methods
......@@ -55,6 +55,13 @@ class FileSystemBackendDelegate {
// stay valid until shutdown.
virtual storage::WatcherManager* GetWatcherManager(
const storage::FileSystemURL& url) = 0;
// Called from FileSystemBackend::GetRedirectURLForContents. Please ensure
// that the returned URL is secure to be opened in a browser tab, or referred
// from <img>, <video>, XMLHttpRequest, etc...
virtual void GetRedirectURLForContents(
const storage::FileSystemURL& url,
const storage::URLCallback& callback) = 0;
};
} // namespace chromeos
......
......@@ -56,4 +56,12 @@ storage::WatcherManager* MTPFileSystemBackendDelegate::GetWatcherManager(
return NULL;
}
void MTPFileSystemBackendDelegate::GetRedirectURLForContents(
const storage::FileSystemURL& url,
const storage::URLCallback& callback) {
DCHECK_EQ(storage::kFileSystemTypeDeviceMediaAsFileStorage, url.type());
callback.Run(GURL());
}
} // namespace chromeos
......@@ -47,6 +47,9 @@ class MTPFileSystemBackendDelegate : public FileSystemBackendDelegate {
storage::FileSystemContext* context) OVERRIDE;
virtual storage::WatcherManager* GetWatcherManager(
const storage::FileSystemURL& url) OVERRIDE;
virtual void GetRedirectURLForContents(
const storage::FileSystemURL& url,
const storage::URLCallback& callback) OVERRIDE;
private:
scoped_ptr<DeviceMediaAsyncFileUtil> device_media_async_file_util_;
......
......@@ -19,15 +19,12 @@
class GURL;
namespace storage {
class FileStreamReader;
}
namespace storage {
class AsyncFileUtil;
class CopyOrMoveFileValidatorFactory;
class FileSystemURL;
class FileStreamReader;
class FileStreamWriter;
class FileSystemContext;
class FileSystemFileUtil;
......@@ -35,6 +32,9 @@ class FileSystemOperation;
class FileSystemQuotaUtil;
class WatcherManager;
// Callback to take GURL.
typedef base::Callback<void(const GURL& url)> URLCallback;
// An interface for defining a file system backend.
//
// NOTE: when you implement a new FileSystemBackend for your own
......@@ -157,6 +157,11 @@ class ExternalFileSystemBackend : public FileSystemBackend {
// path is not exposed by this provider.
virtual bool GetVirtualPath(const base::FilePath& file_system_path,
base::FilePath* virtual_path) = 0;
// Gets a redirect URL for contents. e.g. Google Drive URL for hosted
// documents. Returns empty URL if the entry does not have the redirect URL.
virtual void GetRedirectURLForContents(
const storage::FileSystemURL& url,
const storage::URLCallback& callback) = 0;
};
} // namespace storage
......
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