summaryrefslogtreecommitdiffstats
path: root/chrome/browser/chromeos/gview_request_interceptor.cc
diff options
context:
space:
mode:
authordavemoore@chromium.org <davemoore@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-04 20:01:45 +0000
committerdavemoore@chromium.org <davemoore@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-04 20:01:45 +0000
commit56d83182c6d4c815aab837e82ccccc6103bc4b6a (patch)
tree34944feee64dfe06f287c1ab6a063144e4c3958f /chrome/browser/chromeos/gview_request_interceptor.cc
parent42f4f8bc7eb5b3d7e5af6b066c13e70d39e60d5d (diff)
downloadchromium_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 'chrome/browser/chromeos/gview_request_interceptor.cc')
-rw-r--r--chrome/browser/chromeos/gview_request_interceptor.cc63
1 files changed, 63 insertions, 0 deletions
diff --git a/chrome/browser/chromeos/gview_request_interceptor.cc b/chrome/browser/chromeos/gview_request_interceptor.cc
new file mode 100644
index 0000000..735424b
--- /dev/null
+++ b/chrome/browser/chromeos/gview_request_interceptor.cc
@@ -0,0 +1,63 @@
+// Copyright (c) 2009 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 "chrome/browser/chromeos/gview_request_interceptor.h"
+
+#include "net/base/escape.h"
+#include "net/base/load_flags.h"
+#include "net/url_request/url_request_job.h"
+#include "net/url_request/url_request.h"
+#include "net/url_request/url_request_redirect_job.h"
+#include "googleurl/src/gurl.h"
+
+// This is the list of mime types currently supported by the Google
+// Document Viewer.
+static const char* const supported_mime_type_list[] = {
+ "application/pdf",
+ "application/vnd.ms-powerpoint"
+};
+
+static const char* const kGViewUrlPrefix = "http://docs.google.com/gview?url=";
+
+GViewRequestInterceptor::GViewRequestInterceptor() {
+ URLRequest::RegisterRequestInterceptor(this);
+ for (size_t i = 0; i < arraysize(supported_mime_type_list); ++i) {
+ supported_mime_types_.insert(supported_mime_type_list[i]);
+ }
+}
+
+GViewRequestInterceptor::~GViewRequestInterceptor() {
+ URLRequest::UnregisterRequestInterceptor(this);
+}
+
+URLRequestJob* GViewRequestInterceptor::MaybeIntercept(URLRequest* request) {
+ // Don't attempt to intercept here as we want to wait until the mime
+ // type is fully determined.
+ return NULL;
+}
+
+URLRequestJob* GViewRequestInterceptor::MaybeInterceptResponse(
+ URLRequest* request) {
+ // Do not intercept this request if it is a download.
+ if (request->load_flags() & net::LOAD_IS_DOWNLOAD) {
+ return NULL;
+ }
+
+ std::string mime_type;
+ request->GetMimeType(&mime_type);
+ // If supported, build the URL to the Google Document Viewer
+ // including the origial document's URL, then create a new job that
+ // will redirect the browser to this new URL.
+ if (supported_mime_types_.count(mime_type) > 0) {
+ std::string url(kGViewUrlPrefix);
+ url += EscapePath(request->url().spec());
+ return new URLRequestRedirectJob(request, GURL(url));
+ }
+ return NULL;
+}
+
+URLRequest::Interceptor* GViewRequestInterceptor::GetGViewRequestInterceptor() {
+ return Singleton<GViewRequestInterceptor>::get();
+}
+