diff options
author | davemoore@chromium.org <davemoore@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-04 20:01:45 +0000 |
---|---|---|
committer | davemoore@chromium.org <davemoore@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-04 20:01:45 +0000 |
commit | 56d83182c6d4c815aab837e82ccccc6103bc4b6a (patch) | |
tree | 34944feee64dfe06f287c1ab6a063144e4c3958f /net | |
parent | 42f4f8bc7eb5b3d7e5af6b066c13e70d39e60d5d (diff) | |
download | chromium_src-56d83182c6d4c815aab837e82ccccc6103bc4b6a.zip chromium_src-56d83182c6d4c815aab837e82ccccc6103bc4b6a.tar.gz chromium_src-56d83182c6d4c815aab837e82ccccc6103bc4b6a.tar.bz2 |
Intercept HTTP requests for documents that GView is capable of displaying (such
as pdf) and redirect the user to the appropriate URL for viewing.
Original patch by skrulx@gmail.com
http://codereview.chromium.org/174016
Review URL: http://codereview.chromium.org/199019
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@25496 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r-- | net/net.gyp | 2 | ||||
-rw-r--r-- | net/url_request/url_request_redirect_job.cc | 29 | ||||
-rw-r--r-- | net/url_request/url_request_redirect_job.h | 34 |
3 files changed, 65 insertions, 0 deletions
diff --git a/net/net.gyp b/net/net.gyp index 509f9ec..c7eaf8b 100644 --- a/net/net.gyp +++ b/net/net.gyp @@ -350,6 +350,8 @@ 'url_request/url_request_job_tracker.h', 'url_request/url_request_new_ftp_job.cc', 'url_request/url_request_new_ftp_job.h', + 'url_request/url_request_redirect_job.cc', + 'url_request/url_request_redirect_job.h', 'url_request/url_request_simple_job.cc', 'url_request/url_request_simple_job.h', 'url_request/url_request_status.h', diff --git a/net/url_request/url_request_redirect_job.cc b/net/url_request/url_request_redirect_job.cc new file mode 100644 index 0000000..d8a1a3e --- /dev/null +++ b/net/url_request/url_request_redirect_job.cc @@ -0,0 +1,29 @@ +// Copyright (c) 2006-2008 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/url_request_redirect_job.h" + +#include "base/message_loop.h" + +URLRequestRedirectJob::URLRequestRedirectJob(URLRequest* request, + GURL redirect_destination) + : URLRequestJob(request), redirect_destination_(redirect_destination) { +} + +void URLRequestRedirectJob::Start() { + MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod( + this, &URLRequestRedirectJob::StartAsync)); +} + +void URLRequestRedirectJob::StartAsync() { + NotifyHeadersComplete(); +} + +bool URLRequestRedirectJob::IsRedirectResponse(GURL* location, + int* http_status_code) { + *location = redirect_destination_; + *http_status_code = 302; + return true; +} + diff --git a/net/url_request/url_request_redirect_job.h b/net/url_request/url_request_redirect_job.h new file mode 100644 index 0000000..df35f8d --- /dev/null +++ b/net/url_request/url_request_redirect_job.h @@ -0,0 +1,34 @@ +// Copyright (c) 2006-2008 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_URL_REQUEST_REDIRECT_JOB_H_ +#define NET_URL_REQUEST_URL_REQUEST_REDIRECT_JOB_H_ + +#include <string> + +#include "net/url_request/url_request.h" +#include "net/url_request/url_request_job.h" +#include "googleurl/src/gurl.h" + +class GURL; + +// A URLRequestJob that will redirect the request to the specified +// URL. This is useful to restart a request at a different URL based +// on the result of another job. +class URLRequestRedirectJob : public URLRequestJob { + public: + // Constructs a job that redirects to the specified URL. + URLRequestRedirectJob(URLRequest* request, GURL redirect_destination); + + virtual void Start(); + bool IsRedirectResponse(GURL* location, int* http_status_code); + + private: + void StartAsync(); + + GURL redirect_destination_; +}; + +#endif // NET_URL_REQUEST_URL_REQUEST_REDIRECT_JOB_H_ + |