summaryrefslogtreecommitdiffstats
path: root/net/url_request
diff options
context:
space:
mode:
Diffstat (limited to 'net/url_request')
-rw-r--r--net/url_request/url_request_file_dir_job.cc10
-rw-r--r--net/url_request/url_request_file_dir_job.h5
-rw-r--r--net/url_request/url_request_file_job.cc25
-rw-r--r--net/url_request/url_request_file_job.h3
4 files changed, 24 insertions, 19 deletions
diff --git a/net/url_request/url_request_file_dir_job.cc b/net/url_request/url_request_file_dir_job.cc
index 3685107..4f94a42 100644
--- a/net/url_request/url_request_file_dir_job.cc
+++ b/net/url_request/url_request_file_dir_job.cc
@@ -17,10 +17,9 @@
#endif
using std::string;
-using std::wstring;
URLRequestFileDirJob::URLRequestFileDirJob(URLRequest* request,
- const wstring& dir_path)
+ const FilePath& dir_path)
: URLRequestJob(request),
dir_path_(dir_path),
canceled_(false),
@@ -104,7 +103,12 @@ void URLRequestFileDirJob::OnListFile(
// We wait to write out the header until we get the first file, so that we
// can catch errors from DirectoryLister and show an error page.
if (!wrote_header_) {
- data_.append(net::GetDirectoryListingHeader(WideToUTF8(dir_path_)));
+#if defined(OS_WIN)
+ const std::string& title = WideToUTF8(dir_path_.value());
+#elif defined(OS_POSIX)
+ const std::string& title = dir_path_.value();
+#endif
+ data_.append(net::GetDirectoryListingHeader(title));
wrote_header_ = true;
}
diff --git a/net/url_request/url_request_file_dir_job.h b/net/url_request/url_request_file_dir_job.h
index afbb56b..657a587 100644
--- a/net/url_request/url_request_file_dir_job.h
+++ b/net/url_request/url_request_file_dir_job.h
@@ -5,6 +5,7 @@
#ifndef NET_URL_REQUEST_URL_REQUEST_FILE_DIR_JOB_H__
#define NET_URL_REQUEST_URL_REQUEST_FILE_DIR_JOB_H__
+#include "base/file_path.h"
#include "base/file_util.h"
#include "net/base/directory_lister.h"
#include "net/url_request/url_request_job.h"
@@ -13,7 +14,7 @@ class URLRequestFileDirJob
: public URLRequestJob,
public net::DirectoryLister::DirectoryListerDelegate {
public:
- URLRequestFileDirJob(URLRequest* request, const std::wstring& dir_path);
+ URLRequestFileDirJob(URLRequest* request, const FilePath& dir_path);
virtual ~URLRequestFileDirJob();
// URLRequestJob methods:
@@ -39,7 +40,7 @@ class URLRequestFileDirJob
bool FillReadBuffer(char *buf, int buf_size, int *bytes_read);
scoped_refptr<net::DirectoryLister> lister_;
- std::wstring dir_path_;
+ FilePath dir_path_;
std::string data_;
bool canceled_;
diff --git a/net/url_request/url_request_file_job.cc b/net/url_request/url_request_file_job.cc
index 5c823d8..3c37468 100644
--- a/net/url_request/url_request_file_job.cc
+++ b/net/url_request/url_request_file_job.cc
@@ -38,7 +38,7 @@ class URLRequestFileJob::AsyncResolver :
: owner_(owner), owner_loop_(MessageLoop::current()) {
}
- void Resolve(const std::wstring& file_path) {
+ void Resolve(const FilePath& file_path) {
file_util::FileInfo file_info;
bool exists = file_util::GetFileInfo(file_path, &file_info);
AutoLock locked(lock_);
@@ -71,9 +71,9 @@ class URLRequestFileJob::AsyncResolver :
// static
URLRequestJob* URLRequestFileJob::Factory(
URLRequest* request, const std::string& scheme) {
- std::wstring file_path;
+ FilePath file_path;
if (net::FileURLToFilePath(request->url(), &file_path)) {
- if (file_path[file_path.size() - 1] == file_util::kPathSeparator) {
+ if (file_util::DirectoryExists(file_path)) {
// Only directories have trailing slashes.
return new URLRequestFileDirJob(request, file_path);
}
@@ -102,7 +102,7 @@ URLRequestFileJob::~URLRequestFileJob() {
void URLRequestFileJob::Start() {
#if defined(OS_WIN)
// Resolve UNC paths on a background thread.
- if (!file_path_.compare(0, 2, L"\\\\")) {
+ if (!file_path_.value().compare(0, 2, L"\\\\")) {
DCHECK(!async_resolver_);
async_resolver_ = new AsyncResolver(this);
WorkerPool::PostTask(FROM_HERE, NewRunnableMethod(
@@ -154,7 +154,7 @@ bool URLRequestFileJob::ReadRawData(
bool URLRequestFileJob::GetMimeType(std::string* mime_type) {
DCHECK(request_);
- return net::GetMimeTypeFromFile(file_path_, mime_type);
+ return net::GetMimeTypeFromFile(file_path_.ToWStringHack(), mime_type);
}
void URLRequestFileJob::DidResolve(
@@ -176,7 +176,7 @@ void URLRequestFileJob::DidResolve(
int flags = base::PLATFORM_FILE_OPEN |
base::PLATFORM_FILE_READ |
base::PLATFORM_FILE_ASYNC;
- rv = stream_.Open(file_path_, flags);
+ rv = stream_.Open(file_path_.ToWStringHack(), flags);
}
if (rv == net::OK) {
@@ -214,16 +214,15 @@ bool URLRequestFileJob::IsRedirectResponse(
}
#if defined(OS_WIN)
- // Follow a Windows shortcut.
- size_t found;
- found = file_path_.find_last_of('.');
+ std::wstring extension =
+ file_util::GetFileExtensionFromPath(file_path_.value());
- // We just resolve .lnk file, ignor others.
- if (found == std::string::npos ||
- !LowerCaseEqualsASCII(file_path_.substr(found), ".lnk"))
+ // Follow a Windows shortcut.
+ // We just resolve .lnk file, ignore others.
+ if (!LowerCaseEqualsASCII(extension, "lnk"))
return false;
- std::wstring new_path = file_path_;
+ std::wstring new_path = file_path_.value();
bool resolved;
resolved = file_util::ResolveShortcut(&new_path);
diff --git a/net/url_request/url_request_file_job.h b/net/url_request/url_request_file_job.h
index 5d52850..e6c1850 100644
--- a/net/url_request/url_request_file_job.h
+++ b/net/url_request/url_request_file_job.h
@@ -5,6 +5,7 @@
#ifndef NET_URL_REQUEST_URL_REQUEST_FILE_JOB_H_
#define NET_URL_REQUEST_URL_REQUEST_FILE_JOB_H_
+#include "base/file_path.h"
#include "base/file_util.h"
#include "net/base/completion_callback.h"
#include "net/base/file_stream.h"
@@ -27,7 +28,7 @@ class URLRequestFileJob : public URLRequestJob {
protected:
// The OS-specific full path name of the file
- std::wstring file_path_;
+ FilePath file_path_;
private:
void DidResolve(bool exists, const file_util::FileInfo& file_info);