OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "base/singleton.h" | 9 #include "base/singleton.h" |
10 #include "chrome/common/chrome_paths.h" | 10 #include "chrome/common/chrome_paths.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 // This is the list of mime types currently supported by the Google | 26 // This is the list of mime types currently supported by the Google |
27 // Document Viewer. | 27 // Document Viewer. |
28 static const char* const supported_mime_type_list[] = { | 28 static const char* const supported_mime_type_list[] = { |
29 kPdfMimeType, | 29 kPdfMimeType, |
30 "application/vnd.ms-powerpoint" | 30 "application/vnd.ms-powerpoint" |
31 }; | 31 }; |
32 | 32 |
33 static const char* const kGViewUrlPrefix = "http://docs.google.com/gview?url="; | 33 static const char* const kGViewUrlPrefix = "http://docs.google.com/gview?url="; |
34 | 34 |
35 GViewRequestInterceptor::GViewRequestInterceptor() { | 35 GViewRequestInterceptor::GViewRequestInterceptor() { |
36 URLRequest::RegisterRequestInterceptor(this); | 36 net::URLRequest::RegisterRequestInterceptor(this); |
37 for (size_t i = 0; i < arraysize(supported_mime_type_list); ++i) { | 37 for (size_t i = 0; i < arraysize(supported_mime_type_list); ++i) { |
38 supported_mime_types_.insert(supported_mime_type_list[i]); | 38 supported_mime_types_.insert(supported_mime_type_list[i]); |
39 } | 39 } |
40 } | 40 } |
41 | 41 |
42 GViewRequestInterceptor::~GViewRequestInterceptor() { | 42 GViewRequestInterceptor::~GViewRequestInterceptor() { |
43 URLRequest::UnregisterRequestInterceptor(this); | 43 net::URLRequest::UnregisterRequestInterceptor(this); |
44 } | 44 } |
45 | 45 |
46 URLRequestJob* GViewRequestInterceptor::MaybeIntercept(URLRequest* request) { | 46 URLRequestJob* GViewRequestInterceptor::MaybeIntercept( |
| 47 net::URLRequest* request) { |
47 // Don't attempt to intercept here as we want to wait until the mime | 48 // Don't attempt to intercept here as we want to wait until the mime |
48 // type is fully determined. | 49 // type is fully determined. |
49 return NULL; | 50 return NULL; |
50 } | 51 } |
51 | 52 |
52 URLRequestJob* GViewRequestInterceptor::MaybeInterceptResponse( | 53 URLRequestJob* GViewRequestInterceptor::MaybeInterceptResponse( |
53 URLRequest* request) { | 54 net::URLRequest* request) { |
54 // Do not intercept this request if it is a download. | 55 // Do not intercept this request if it is a download. |
55 if (request->load_flags() & net::LOAD_IS_DOWNLOAD) { | 56 if (request->load_flags() & net::LOAD_IS_DOWNLOAD) { |
56 return NULL; | 57 return NULL; |
57 } | 58 } |
58 | 59 |
59 std::string mime_type; | 60 std::string mime_type; |
60 request->GetMimeType(&mime_type); | 61 request->GetMimeType(&mime_type); |
61 // If the local PDF viewing plug-in is installed and enabled, don't | 62 // If the local PDF viewing plug-in is installed and enabled, don't |
62 // redirect PDF files to Google Document Viewer. | 63 // redirect PDF files to Google Document Viewer. |
63 if (mime_type == kPdfMimeType) { | 64 if (mime_type == kPdfMimeType) { |
64 FilePath pdf_path; | 65 FilePath pdf_path; |
65 WebPluginInfo info; | 66 WebPluginInfo info; |
66 PathService::Get(chrome::FILE_PDF_PLUGIN, &pdf_path); | 67 PathService::Get(chrome::FILE_PDF_PLUGIN, &pdf_path); |
67 if (NPAPI::PluginList::Singleton()->GetPluginInfoByPath(pdf_path, &info) && | 68 if (NPAPI::PluginList::Singleton()->GetPluginInfoByPath(pdf_path, &info) && |
68 info.enabled) | 69 info.enabled) |
69 return NULL; | 70 return NULL; |
70 } | 71 } |
71 // If supported, build the URL to the Google Document Viewer | 72 // If supported, build the URL to the Google Document Viewer |
72 // including the origial document's URL, then create a new job that | 73 // including the origial document's URL, then create a new job that |
73 // will redirect the browser to this new URL. | 74 // will redirect the browser to this new URL. |
74 if (supported_mime_types_.count(mime_type) > 0) { | 75 if (supported_mime_types_.count(mime_type) > 0) { |
75 std::string url(kGViewUrlPrefix); | 76 std::string url(kGViewUrlPrefix); |
76 url += EscapePath(request->url().spec()); | 77 url += EscapePath(request->url().spec()); |
77 return new URLRequestRedirectJob(request, GURL(url)); | 78 return new URLRequestRedirectJob(request, GURL(url)); |
78 } | 79 } |
79 return NULL; | 80 return NULL; |
80 } | 81 } |
81 | 82 |
82 URLRequest::Interceptor* GViewRequestInterceptor::GetGViewRequestInterceptor() { | 83 net::URLRequest::Interceptor* |
| 84 GViewRequestInterceptor::GetGViewRequestInterceptor() { |
83 return Singleton<GViewRequestInterceptor>::get(); | 85 return Singleton<GViewRequestInterceptor>::get(); |
84 } | 86 } |
85 | 87 |
86 } // namespace chromeos | 88 } // namespace chromeos |
OLD | NEW |