| Index: net/url_request/url_request_file_job.cc
|
| diff --git a/net/url_request/url_request_file_job.cc b/net/url_request/url_request_file_job.cc
|
| index 7a1599af9539aa55b77cdc836cebe72a17c5c9ab..0f4c4236653480819ad0a6446e2f7a49b1e6f271 100644
|
| --- a/net/url_request/url_request_file_job.cc
|
| +++ b/net/url_request/url_request_file_job.cc
|
| @@ -82,6 +82,17 @@ class URLRequestFileJob::AsyncResolver
|
| };
|
| #endif
|
|
|
| +URLRequestFileJob::URLRequestFileJob(URLRequest* request,
|
| + const FilePath& file_path)
|
| + : URLRequestJob(request),
|
| + file_path_(file_path),
|
| + ALLOW_THIS_IN_INITIALIZER_LIST(
|
| + io_callback_(this, &URLRequestFileJob::DidRead)),
|
| + is_directory_(false),
|
| + remaining_bytes_(0),
|
| + ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) {
|
| +}
|
| +
|
| // static
|
| URLRequestJob* URLRequestFileJob::Factory(URLRequest* request,
|
| const std::string& scheme) {
|
| @@ -111,22 +122,33 @@ URLRequestJob* URLRequestFileJob::Factory(URLRequest* request,
|
| return new URLRequestFileJob(request, file_path);
|
| }
|
|
|
| -URLRequestFileJob::URLRequestFileJob(URLRequest* request,
|
| - const FilePath& file_path)
|
| - : URLRequestJob(request),
|
| - file_path_(file_path),
|
| - ALLOW_THIS_IN_INITIALIZER_LIST(
|
| - io_callback_(this, &URLRequestFileJob::DidRead)),
|
| - is_directory_(false),
|
| - remaining_bytes_(0),
|
| - ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) {
|
| -}
|
| +#if defined(OS_CHROMEOS)
|
| +static const char* const kLocalAccessWhiteList[] = {
|
| + "/home/chronos/user/Downloads",
|
| + "/media",
|
| + "/mnt/partner_partition",
|
| + "/usr/share/chromeos-assets",
|
| + "/tmp",
|
| + "/var/log",
|
| +};
|
|
|
| -URLRequestFileJob::~URLRequestFileJob() {
|
| -#if defined(OS_WIN)
|
| - DCHECK(!async_resolver_);
|
| -#endif
|
| +// static
|
| +bool URLRequestFileJob::AccessDisabled(const FilePath& file_path) {
|
| + if (URLRequest::IsFileAccessAllowed()) { // for tests.
|
| + return false;
|
| + }
|
| +
|
| + for (size_t i = 0; i < arraysize(kLocalAccessWhiteList); ++i) {
|
| + const FilePath white_listed_path(kLocalAccessWhiteList[i]);
|
| + // FilePath::operator== should probably handle trailing seperators.
|
| + if (white_listed_path == file_path.StripTrailingSeparators() ||
|
| + white_listed_path.IsParent(file_path)) {
|
| + return false;
|
| + }
|
| + }
|
| + return true;
|
| }
|
| +#endif
|
|
|
| void URLRequestFileJob::Start() {
|
| #if defined(OS_WIN)
|
| @@ -204,6 +226,43 @@ bool URLRequestFileJob::ReadRawData(IOBuffer* dest, int dest_size,
|
| return false;
|
| }
|
|
|
| +bool URLRequestFileJob::IsRedirectResponse(GURL* location,
|
| + int* http_status_code) {
|
| + if (is_directory_) {
|
| + // This happens when we discovered the file is a directory, so needs a
|
| + // slash at the end of the path.
|
| + std::string new_path = request_->url().path();
|
| + new_path.push_back('/');
|
| + GURL::Replacements replacements;
|
| + replacements.SetPathStr(new_path);
|
| +
|
| + *location = request_->url().ReplaceComponents(replacements);
|
| + *http_status_code = 301; // simulate a permanent redirect
|
| + return true;
|
| + }
|
| +
|
| +#if defined(OS_WIN)
|
| + // Follow a Windows shortcut.
|
| + // We just resolve .lnk file, ignore others.
|
| + if (!LowerCaseEqualsASCII(file_path_.Extension(), ".lnk"))
|
| + return false;
|
| +
|
| + FilePath new_path = file_path_;
|
| + bool resolved;
|
| + resolved = file_util::ResolveShortcut(&new_path);
|
| +
|
| + // If shortcut is not resolved succesfully, do not redirect.
|
| + if (!resolved)
|
| + return false;
|
| +
|
| + *location = FilePathToFileURL(new_path);
|
| + *http_status_code = 301;
|
| + return true;
|
| +#else
|
| + return false;
|
| +#endif
|
| +}
|
| +
|
| bool URLRequestFileJob::GetContentEncodings(
|
| std::vector<Filter::FilterType>* encoding_types) {
|
| DCHECK(encoding_types->empty());
|
| @@ -245,6 +304,12 @@ void URLRequestFileJob::SetExtraRequestHeaders(
|
| }
|
| }
|
|
|
| +URLRequestFileJob::~URLRequestFileJob() {
|
| +#if defined(OS_WIN)
|
| + DCHECK(!async_resolver_);
|
| +#endif
|
| +}
|
| +
|
| void URLRequestFileJob::DidResolve(
|
| bool exists, const base::PlatformFileInfo& file_info) {
|
| #if defined(OS_WIN)
|
| @@ -323,69 +388,4 @@ void URLRequestFileJob::DidRead(int result) {
|
| NotifyReadComplete(result);
|
| }
|
|
|
| -bool URLRequestFileJob::IsRedirectResponse(GURL* location,
|
| - int* http_status_code) {
|
| - if (is_directory_) {
|
| - // This happens when we discovered the file is a directory, so needs a
|
| - // slash at the end of the path.
|
| - std::string new_path = request_->url().path();
|
| - new_path.push_back('/');
|
| - GURL::Replacements replacements;
|
| - replacements.SetPathStr(new_path);
|
| -
|
| - *location = request_->url().ReplaceComponents(replacements);
|
| - *http_status_code = 301; // simulate a permanent redirect
|
| - return true;
|
| - }
|
| -
|
| -#if defined(OS_WIN)
|
| - // Follow a Windows shortcut.
|
| - // We just resolve .lnk file, ignore others.
|
| - if (!LowerCaseEqualsASCII(file_path_.Extension(), ".lnk"))
|
| - return false;
|
| -
|
| - FilePath new_path = file_path_;
|
| - bool resolved;
|
| - resolved = file_util::ResolveShortcut(&new_path);
|
| -
|
| - // If shortcut is not resolved succesfully, do not redirect.
|
| - if (!resolved)
|
| - return false;
|
| -
|
| - *location = FilePathToFileURL(new_path);
|
| - *http_status_code = 301;
|
| - return true;
|
| -#else
|
| - return false;
|
| -#endif
|
| -}
|
| -
|
| -#if defined(OS_CHROMEOS)
|
| -static const char* const kLocalAccessWhiteList[] = {
|
| - "/home/chronos/user/Downloads",
|
| - "/media",
|
| - "/mnt/partner_partition",
|
| - "/usr/share/chromeos-assets",
|
| - "/tmp",
|
| - "/var/log",
|
| -};
|
| -
|
| -// static
|
| -bool URLRequestFileJob::AccessDisabled(const FilePath& file_path) {
|
| - if (URLRequest::IsFileAccessAllowed()) { // for tests.
|
| - return false;
|
| - }
|
| -
|
| - for (size_t i = 0; i < arraysize(kLocalAccessWhiteList); ++i) {
|
| - const FilePath white_listed_path(kLocalAccessWhiteList[i]);
|
| - // FilePath::operator== should probably handle trailing seperators.
|
| - if (white_listed_path == file_path.StripTrailingSeparators() ||
|
| - white_listed_path.IsParent(file_path)) {
|
| - return false;
|
| - }
|
| - }
|
| - return true;
|
| -}
|
| -#endif
|
| -
|
| } // namespace net
|
|
|