summaryrefslogtreecommitdiffstats
path: root/net/url_request/url_request_job_manager.cc
diff options
context:
space:
mode:
authorwillchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-14 06:17:07 +0000
committerwillchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-14 06:17:07 +0000
commita8c1e745a571a498a6727858d81631c903672d31 (patch)
treeaba124f89b8d9a2765bfcca677c3d4482f15f710 /net/url_request/url_request_job_manager.cc
parent1332c24d517e472758aae7e25301752561da6bc5 (diff)
downloadchromium_src-a8c1e745a571a498a6727858d81631c903672d31.zip
chromium_src-a8c1e745a571a498a6727858d81631c903672d31.tar.gz
chromium_src-a8c1e745a571a498a6727858d81631c903672d31.tar.bz2
Create a URLRequestJobFactory to replace the URLRequest globals.
URLRequest::Interceptor and URLRequest::ProtocolFactory are globally registered. This causes a variety of problems. This provides a method for replacing them. It used to be the case that we used net::URLRequest::IsHandledProtocol()/net::URLRequest::IsHandledURL() to see if the request would be handled by Chrome, or deferred to an external protocol handler. This required that URLRequest be aware of all protocol handlers. We instead provide ProfileIOData::IsHandledProtocol(), which checks to see if there are any Chrome registered protocol handlers, and if not, checks the default ones in net::URLRequest. Note this doesn't work for custom handlers (registerProtocolHandler) because they are dynamic and profile-specific. We would have to add a member function to ProfileIOData and not use a global. This is problematic since we check ProfileIOData::IsHandledProtocol in the RenderViewContextMenu, which runs on the UI thread, whereas ProfileIOData lives on the IO thread. RenderViewContextMenu is using also using it synchronously, which makes it a pain to support. So, we don't support custom handlers in ProfileIOData::IsHandledProtocol(). This means that "save as" won't work for custom handlers. Seems ok for now. This also fixes the multiprofile/incognito bugs where if a profile registers a custom handler, and then a different profile / an incognito profile registers the same custom handler and then unregisters it, which globally unregisters it, so the original profile is now broken. By removing the use of the globals, we fix this. Also fixes a bunch of style guide violations in the ProtocolHandler/ProtocolHandlerRegistry code. This changelist replaces two existing URLRequest::ProtocolFactory uses: chrome-extension/user-script and custom handlers. Also improve the tests in ResourceDispatcherHost so we don't have to do as many NULL checks. Change the MockResourceContext to create a TestURLRequestContext. BUG=81979 TEST=none Review URL: http://codereview.chromium.org/6960006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@85376 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/url_request/url_request_job_manager.cc')
-rw-r--r--net/url_request/url_request_job_manager.cc32
1 files changed, 31 insertions, 1 deletions
diff --git a/net/url_request/url_request_job_manager.cc b/net/url_request/url_request_job_manager.cc
index 06891b4..dc6af79 100644
--- a/net/url_request/url_request_job_manager.cc
+++ b/net/url_request/url_request_job_manager.cc
@@ -11,12 +11,15 @@
#include "base/string_util.h"
#include "net/base/load_flags.h"
#include "net/base/net_errors.h"
+#include "net/base/network_delegate.h"
#include "net/url_request/url_request_about_job.h"
+#include "net/url_request/url_request_context.h"
#include "net/url_request/url_request_data_job.h"
#include "net/url_request/url_request_error_job.h"
#include "net/url_request/url_request_file_job.h"
#include "net/url_request/url_request_ftp_job.h"
#include "net/url_request/url_request_http_job.h"
+#include "net/url_request/url_request_job_factory.h"
namespace net {
@@ -55,15 +58,33 @@ URLRequestJob* URLRequestJobManager::CreateJob(
return new URLRequestErrorJob(request, ERR_INVALID_URL);
// We do this here to avoid asking interceptors about unsupported schemes.
+ const URLRequestJobFactory* job_factory = NULL;
+ if (request->context())
+ job_factory = request->context()->job_factory();
+
const std::string& scheme = request->url().scheme(); // already lowercase
- if (!SupportsScheme(scheme))
+ if (job_factory) {
+ if (!job_factory->IsHandledProtocol(scheme)) {
+ return new URLRequestErrorJob(request, ERR_UNKNOWN_URL_SCHEME);
+ }
+ } else if (!SupportsScheme(scheme)) {
return new URLRequestErrorJob(request, ERR_UNKNOWN_URL_SCHEME);
+ }
// THREAD-SAFETY NOTICE:
// We do not need to acquire the lock here since we are only reading our
// data structures. They should only be modified on the current thread.
// See if the request should be intercepted.
+ //
+
+ if (job_factory) {
+ URLRequestJob* job = job_factory->MaybeCreateJobWithInterceptor(request);
+ if (job)
+ return job;
+ }
+
+ // TODO(willchan): Remove this in favor of URLRequestJobFactory::Interceptor.
if (!(request->load_flags() & LOAD_DISABLE_INTERCEPT)) {
InterceptorList::const_iterator i;
for (i = interceptors_.begin(); i != interceptors_.end(); ++i) {
@@ -73,6 +94,15 @@ URLRequestJob* URLRequestJobManager::CreateJob(
}
}
+ if (job_factory) {
+ URLRequestJob* job =
+ job_factory->MaybeCreateJobWithProtocolHandler(scheme, request);
+ if (job)
+ return job;
+ }
+
+ // TODO(willchan): Remove this in favor of
+ // URLRequestJobFactory::ProtocolHandler.
// See if the request should be handled by a registered protocol factory.
// If the registered factory returns null, then we want to fall-back to the
// built-in protocol factory.