OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 GViewRequestInterceptor::GViewRequestInterceptor() { | 44 GViewRequestInterceptor::GViewRequestInterceptor() { |
45 for (size_t i = 0; i < arraysize(kSupportedMimeTypeList); ++i) { | 45 for (size_t i = 0; i < arraysize(kSupportedMimeTypeList); ++i) { |
46 supported_mime_types_.insert(kSupportedMimeTypeList[i]); | 46 supported_mime_types_.insert(kSupportedMimeTypeList[i]); |
47 } | 47 } |
48 } | 48 } |
49 | 49 |
50 GViewRequestInterceptor::~GViewRequestInterceptor() { | 50 GViewRequestInterceptor::~GViewRequestInterceptor() { |
51 } | 51 } |
52 | 52 |
53 net::URLRequestJob* GViewRequestInterceptor::MaybeIntercept( | 53 net::URLRequestJob* GViewRequestInterceptor::MaybeIntercept( |
54 net::URLRequest* request) const { | 54 net::URLRequest* request, net::NetworkDelegate* network_delegate) const { |
55 // Don't attempt to intercept here as we want to wait until the mime | 55 // Don't attempt to intercept here as we want to wait until the mime |
56 // type is fully determined. | 56 // type is fully determined. |
57 return NULL; | 57 return NULL; |
58 } | 58 } |
59 | 59 |
60 net::URLRequestJob* GViewRequestInterceptor::MaybeInterceptRedirect( | 60 net::URLRequestJob* GViewRequestInterceptor::MaybeInterceptRedirect( |
61 const GURL& location, | 61 const GURL& location, |
62 net::URLRequest* request) const { | 62 net::URLRequest* request, |
| 63 net::NetworkDelegate* network_delegate) const { |
63 return NULL; | 64 return NULL; |
64 } | 65 } |
65 | 66 |
66 bool GViewRequestInterceptor::ShouldUsePdfPlugin( | 67 bool GViewRequestInterceptor::ShouldUsePdfPlugin( |
67 net::URLRequest* request) const { | 68 net::URLRequest* request) const { |
68 FilePath pdf_path; | 69 FilePath pdf_path; |
69 PathService::Get(chrome::FILE_PDF_PLUGIN, &pdf_path); | 70 PathService::Get(chrome::FILE_PDF_PLUGIN, &pdf_path); |
70 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); | 71 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); |
71 if (!info) | 72 if (!info) |
72 return false; | 73 return false; |
73 | 74 |
74 webkit::WebPluginInfo plugin; | 75 webkit::WebPluginInfo plugin; |
75 if (!PluginService::GetInstance()->GetPluginInfoByPath(pdf_path, &plugin)) { | 76 if (!PluginService::GetInstance()->GetPluginInfoByPath(pdf_path, &plugin)) { |
76 return false; | 77 return false; |
77 } | 78 } |
78 | 79 |
79 return ChromePluginServiceFilter::GetInstance()->ShouldUsePlugin( | 80 return ChromePluginServiceFilter::GetInstance()->ShouldUsePlugin( |
80 info->GetChildID(), info->GetRouteID(), info->GetContext(), | 81 info->GetChildID(), info->GetRouteID(), info->GetContext(), |
81 request->url(), GURL(), &plugin); | 82 request->url(), GURL(), &plugin); |
82 } | 83 } |
83 | 84 |
84 bool GViewRequestInterceptor::ShouldInterceptScheme( | 85 bool GViewRequestInterceptor::ShouldInterceptScheme( |
85 const std::string& scheme) const { | 86 const std::string& scheme) const { |
86 return scheme == chrome::kHttpScheme; | 87 return scheme == chrome::kHttpScheme; |
87 } | 88 } |
88 | 89 |
89 net::URLRequestJob* GViewRequestInterceptor::MaybeInterceptResponse( | 90 net::URLRequestJob* GViewRequestInterceptor::MaybeInterceptResponse( |
90 net::URLRequest* request) const { | 91 net::URLRequest* request, net::NetworkDelegate* network_delegate) const { |
91 // Do not intercept this request if it is a download. | 92 // Do not intercept this request if it is a download. |
92 if (request->load_flags() & net::LOAD_IS_DOWNLOAD) { | 93 if (request->load_flags() & net::LOAD_IS_DOWNLOAD) { |
93 return NULL; | 94 return NULL; |
94 } | 95 } |
95 | 96 |
96 std::string mime_type; | 97 std::string mime_type; |
97 request->GetMimeType(&mime_type); | 98 request->GetMimeType(&mime_type); |
98 | 99 |
99 if (request->method() != "GET" || | 100 if (request->method() != "GET" || |
100 !ShouldInterceptScheme(request->original_url().scheme())) { | 101 !ShouldInterceptScheme(request->original_url().scheme())) { |
101 return NULL; | 102 return NULL; |
102 } | 103 } |
103 | 104 |
104 // If the local PDF viewing plug-in is installed and enabled, don't | 105 // If the local PDF viewing plug-in is installed and enabled, don't |
105 // redirect PDF files to Google Document Viewer. | 106 // redirect PDF files to Google Document Viewer. |
106 if (mime_type == kPdfMimeType && ShouldUsePdfPlugin(request)) | 107 if (mime_type == kPdfMimeType && ShouldUsePdfPlugin(request)) |
107 return NULL; | 108 return NULL; |
108 | 109 |
109 // If supported, build the URL to the Google Document Viewer | 110 // If supported, build the URL to the Google Document Viewer |
110 // including the origial document's URL, then create a new job that | 111 // including the origial document's URL, then create a new job that |
111 // will redirect the browser to this new URL. | 112 // will redirect the browser to this new URL. |
112 if (supported_mime_types_.count(mime_type) > 0) { | 113 if (supported_mime_types_.count(mime_type) > 0) { |
113 std::string url(kGViewUrlPrefix); | 114 std::string url(kGViewUrlPrefix); |
114 url += net::EscapePath(request->url().spec()); | 115 url += net::EscapePath(request->url().spec()); |
115 return new net::URLRequestRedirectJob(request, GURL(url)); | 116 return new net::URLRequestRedirectJob(request, network_delegate, GURL(url)); |
116 } | 117 } |
117 return NULL; | 118 return NULL; |
118 } | 119 } |
119 | 120 |
120 } // namespace chromeos | 121 } // namespace chromeos |
OLD | NEW |