| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/chromeos/gview_request_interceptor.h" | 5 #include "chrome/browser/chromeos/gview_request_interceptor.h" |
| 6 | 6 |
| 7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
| 8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
| 9 #include "chrome/browser/chrome_plugin_service_filter.h" | 9 #include "chrome/browser/chrome_plugin_service_filter.h" |
| 10 #include "chrome/common/chrome_paths.h" | 10 #include "chrome/common/chrome_paths.h" |
| 11 #include "chrome/common/url_constants.h" |
| 11 #include "content/browser/plugin_service.h" | 12 #include "content/browser/plugin_service.h" |
| 12 #include "content/browser/renderer_host/resource_dispatcher_host.h" | 13 #include "content/browser/renderer_host/resource_dispatcher_host.h" |
| 13 #include "content/browser/renderer_host/resource_dispatcher_host_request_info.h" | 14 #include "content/browser/renderer_host/resource_dispatcher_host_request_info.h" |
| 14 #include "googleurl/src/gurl.h" | 15 #include "googleurl/src/gurl.h" |
| 15 #include "net/base/escape.h" | 16 #include "net/base/escape.h" |
| 16 #include "net/base/load_flags.h" | 17 #include "net/base/load_flags.h" |
| 17 #include "net/url_request/url_request.h" | 18 #include "net/url_request/url_request.h" |
| 18 #include "net/url_request/url_request_redirect_job.h" | 19 #include "net/url_request/url_request_redirect_job.h" |
| 19 #include "webkit/plugins/webplugininfo.h" | 20 #include "webkit/plugins/webplugininfo.h" |
| 20 | 21 |
| 21 namespace chromeos { | 22 namespace chromeos { |
| 22 | 23 |
| 24 namespace { |
| 25 |
| 23 // The PDF mime type is treated special if the browser has a built-in | 26 // The PDF mime type is treated special if the browser has a built-in |
| 24 // PDF viewer plug-in installed - we want to intercept only if we're | 27 // PDF viewer plug-in installed - we want to intercept only if we're |
| 25 // told to. | 28 // told to. |
| 26 static const char kPdfMimeType[] = "application/pdf"; | 29 const char kPdfMimeType[] = "application/pdf"; |
| 27 | 30 |
| 28 // This is the list of mime types currently supported by the Google | 31 // This is the list of mime types currently supported by the Google |
| 29 // Document Viewer. | 32 // Document Viewer. |
| 30 static const char* const kSupportedMimeTypeList[] = { | 33 const char* const kSupportedMimeTypeList[] = { |
| 31 kPdfMimeType, | 34 kPdfMimeType, |
| 32 "application/vnd.ms-powerpoint" | 35 "application/vnd.ms-powerpoint" |
| 33 }; | 36 }; |
| 34 | 37 |
| 35 static const char kGViewUrlPrefix[] = "http://docs.google.com/gview?url="; | 38 const char kGViewUrlPrefix[] = "http://docs.google.com/gview?url="; |
| 39 |
| 40 } // namespace |
| 36 | 41 |
| 37 GViewRequestInterceptor::GViewRequestInterceptor() { | 42 GViewRequestInterceptor::GViewRequestInterceptor() { |
| 38 for (size_t i = 0; i < arraysize(kSupportedMimeTypeList); ++i) { | 43 for (size_t i = 0; i < arraysize(kSupportedMimeTypeList); ++i) { |
| 39 supported_mime_types_.insert(kSupportedMimeTypeList[i]); | 44 supported_mime_types_.insert(kSupportedMimeTypeList[i]); |
| 40 } | 45 } |
| 41 } | 46 } |
| 42 | 47 |
| 43 GViewRequestInterceptor::~GViewRequestInterceptor() { | 48 GViewRequestInterceptor::~GViewRequestInterceptor() { |
| 44 } | 49 } |
| 45 | 50 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 68 webkit::WebPluginInfo plugin; | 73 webkit::WebPluginInfo plugin; |
| 69 if (!PluginService::GetInstance()->GetPluginInfoByPath(pdf_path, &plugin)) { | 74 if (!PluginService::GetInstance()->GetPluginInfoByPath(pdf_path, &plugin)) { |
| 70 return false; | 75 return false; |
| 71 } | 76 } |
| 72 | 77 |
| 73 return ChromePluginServiceFilter::GetInstance()->ShouldUsePlugin( | 78 return ChromePluginServiceFilter::GetInstance()->ShouldUsePlugin( |
| 74 info->child_id(), info->route_id(), info->context(), | 79 info->child_id(), info->route_id(), info->context(), |
| 75 request->url(), GURL(), &plugin); | 80 request->url(), GURL(), &plugin); |
| 76 } | 81 } |
| 77 | 82 |
| 83 bool GViewRequestInterceptor::ShouldInterceptScheme( |
| 84 const std::string& scheme) const { |
| 85 return scheme == chrome::kHttpScheme; |
| 86 } |
| 87 |
| 78 net::URLRequestJob* GViewRequestInterceptor::MaybeInterceptResponse( | 88 net::URLRequestJob* GViewRequestInterceptor::MaybeInterceptResponse( |
| 79 net::URLRequest* request) const { | 89 net::URLRequest* request) const { |
| 80 // Do not intercept this request if it is a download. | 90 // Do not intercept this request if it is a download. |
| 81 if (request->load_flags() & net::LOAD_IS_DOWNLOAD) { | 91 if (request->load_flags() & net::LOAD_IS_DOWNLOAD) { |
| 82 return NULL; | 92 return NULL; |
| 83 } | 93 } |
| 84 | 94 |
| 85 std::string mime_type; | 95 std::string mime_type; |
| 86 request->GetMimeType(&mime_type); | 96 request->GetMimeType(&mime_type); |
| 97 |
| 98 if (request->method() != "GET" || |
| 99 !ShouldInterceptScheme(request->original_url().scheme())) { |
| 100 return NULL; |
| 101 } |
| 102 |
| 87 // If the local PDF viewing plug-in is installed and enabled, don't | 103 // If the local PDF viewing plug-in is installed and enabled, don't |
| 88 // redirect PDF files to Google Document Viewer. | 104 // redirect PDF files to Google Document Viewer. |
| 89 if (mime_type == kPdfMimeType && ShouldUsePdfPlugin(request)) | 105 if (mime_type == kPdfMimeType && ShouldUsePdfPlugin(request)) |
| 90 return NULL; | 106 return NULL; |
| 107 |
| 91 // If supported, build the URL to the Google Document Viewer | 108 // If supported, build the URL to the Google Document Viewer |
| 92 // including the origial document's URL, then create a new job that | 109 // including the origial document's URL, then create a new job that |
| 93 // will redirect the browser to this new URL. | 110 // will redirect the browser to this new URL. |
| 94 if (supported_mime_types_.count(mime_type) > 0) { | 111 if (supported_mime_types_.count(mime_type) > 0) { |
| 95 std::string url(kGViewUrlPrefix); | 112 std::string url(kGViewUrlPrefix); |
| 96 url += EscapePath(request->url().spec()); | 113 url += EscapePath(request->url().spec()); |
| 97 return new net::URLRequestRedirectJob(request, GURL(url)); | 114 return new net::URLRequestRedirectJob(request, GURL(url)); |
| 98 } | 115 } |
| 99 return NULL; | 116 return NULL; |
| 100 } | 117 } |
| 101 | 118 |
| 102 } // namespace chromeos | 119 } // namespace chromeos |
| OLD | NEW |