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