forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replaced static URLRequestFileJob factory with non-static protocol ha…
…ndler for File jobs This is a refactor and shouldn't have any visible behavioral change. BUG=crbug.com/142945 TEST=browser_tests --single_process --gtest_filter=FullscreenControllerTest.FullscreenFileURL Review URL: https://chromiumcodereview.appspot.com/10700117 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@152381 0039d316-1c4b-4281-b951-d872f2087c98
- Loading branch information
shalev@chromium.org
committed
Aug 20, 2012
1 parent
37cfa2a
commit 65dcdc5
Showing
14 changed files
with
181 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Copyright (c) 2012 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. | ||
|
||
#include "net/url_request/file_protocol_handler.h" | ||
|
||
#include "base/logging.h" | ||
#include "net/base/net_errors.h" | ||
#include "net/base/net_util.h" | ||
#include "net/url_request/url_request_error_job.h" | ||
#include "net/url_request/url_request_file_dir_job.h" | ||
#include "net/url_request/url_request_file_job.h" | ||
|
||
namespace net { | ||
|
||
FileProtocolHandler::FileProtocolHandler( | ||
NetworkDelegate* network_delegate) | ||
: network_delegate_(network_delegate) { | ||
} | ||
|
||
URLRequestJob* FileProtocolHandler::MaybeCreateJob(URLRequest* request) const { | ||
FilePath file_path; | ||
const bool is_file = FileURLToFilePath(request->url(), &file_path); | ||
|
||
// Check file access permissions. | ||
if (!network_delegate_ || | ||
!network_delegate_->CanAccessFile(*request, file_path)) { | ||
return new URLRequestErrorJob(request, ERR_ACCESS_DENIED); | ||
} | ||
|
||
// We need to decide whether to create URLRequestFileJob for file access or | ||
// URLRequestFileDirJob for directory access. To avoid accessing the | ||
// filesystem, we only look at the path string here. | ||
// The code in the URLRequestFileJob::Start() method discovers that a path, | ||
// which doesn't end with a slash, should really be treated as a directory, | ||
// and it then redirects to the URLRequestFileDirJob. | ||
if (is_file && | ||
file_util::EndsWithSeparator(file_path) && | ||
file_path.IsAbsolute()) { | ||
return new URLRequestFileDirJob(request, file_path); | ||
} | ||
|
||
// Use a regular file request job for all non-directories (including invalid | ||
// file names). | ||
return new URLRequestFileJob(request, file_path, network_delegate_); | ||
} | ||
|
||
} // namespace net |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright (c) 2012 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. | ||
|
||
#ifndef NET_URL_REQUEST_FILE_PROTOCOL_HANDLER_H_ | ||
#define NET_URL_REQUEST_FILE_PROTOCOL_HANDLER_H_ | ||
|
||
#include "base/basictypes.h" | ||
#include "base/compiler_specific.h" | ||
#include "net/url_request/url_request_job_factory.h" | ||
|
||
namespace net { | ||
|
||
class NetworkDelegate; | ||
class URLRequestJob; | ||
|
||
// Implements a ProtocolHandler for File jobs. If |network_delegate_| is NULL, | ||
// then all file requests will fail with ERR_ACCESS_DENIED. | ||
class NET_EXPORT FileProtocolHandler : | ||
public URLRequestJobFactory::ProtocolHandler { | ||
public: | ||
explicit FileProtocolHandler(NetworkDelegate* network_delegate); | ||
virtual URLRequestJob* MaybeCreateJob(URLRequest* request) const OVERRIDE; | ||
|
||
private: | ||
NetworkDelegate* network_delegate_; | ||
|
||
DISALLOW_COPY_AND_ASSIGN(FileProtocolHandler); | ||
}; | ||
|
||
} // namespace net | ||
|
||
#endif // NET_URL_REQUEST_FILE_PROTOCOL_HANDLER_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.