Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(303)

Side by Side Diff: chrome/browser/chromeos/gview_request_interceptor.cc

Issue 7019030: Remove ProtocolFactory/Interceptor uses in GViewRequestInterceptor (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix release. Created 9 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/memory/singleton.h"
9 #include "base/path_service.h" 8 #include "base/path_service.h"
10 #include "chrome/common/chrome_paths.h" 9 #include "chrome/common/chrome_paths.h"
11 #include "googleurl/src/gurl.h" 10 #include "googleurl/src/gurl.h"
12 #include "net/base/escape.h" 11 #include "net/base/escape.h"
13 #include "net/base/load_flags.h" 12 #include "net/base/load_flags.h"
14 #include "net/url_request/url_request.h" 13 #include "net/url_request/url_request.h"
15 #include "net/url_request/url_request_job.h"
16 #include "net/url_request/url_request_redirect_job.h" 14 #include "net/url_request/url_request_redirect_job.h"
17 #include "webkit/glue/plugins/plugin_list.h" 15 #include "webkit/glue/plugins/plugin_list.h"
18 16
19 namespace chromeos { 17 namespace chromeos {
20 18
21 // The PDF mime type is treated special if the browser has a built-in 19 // The PDF mime type is treated special if the browser has a built-in
22 // PDF viewer plug-in installed - we want to intercept only if we're 20 // PDF viewer plug-in installed - we want to intercept only if we're
23 // told to. 21 // told to.
24 static const char* const kPdfMimeType = "application/pdf"; 22 static const char kPdfMimeType[] = "application/pdf";
25 23
26 // This is the list of mime types currently supported by the Google 24 // This is the list of mime types currently supported by the Google
27 // Document Viewer. 25 // Document Viewer.
28 static const char* const supported_mime_type_list[] = { 26 static const char* const kSupportedMimeTypeList[] = {
29 kPdfMimeType, 27 kPdfMimeType,
30 "application/vnd.ms-powerpoint" 28 "application/vnd.ms-powerpoint"
31 }; 29 };
32 30
33 static const char* const kGViewUrlPrefix = "http://docs.google.com/gview?url="; 31 static const char kGViewUrlPrefix[] = "http://docs.google.com/gview?url=";
34 32
35 GViewRequestInterceptor::GViewRequestInterceptor() { 33 GViewRequestInterceptor::GViewRequestInterceptor() {
36 net::URLRequest::RegisterRequestInterceptor(this); 34 for (size_t i = 0; i < arraysize(kSupportedMimeTypeList); ++i) {
37 for (size_t i = 0; i < arraysize(supported_mime_type_list); ++i) { 35 supported_mime_types_.insert(kSupportedMimeTypeList[i]);
38 supported_mime_types_.insert(supported_mime_type_list[i]);
39 } 36 }
40 } 37 }
41 38
42 GViewRequestInterceptor::~GViewRequestInterceptor() { 39 GViewRequestInterceptor::~GViewRequestInterceptor() {
43 net::URLRequest::UnregisterRequestInterceptor(this);
44 } 40 }
45 41
46 net::URLRequestJob* GViewRequestInterceptor::MaybeIntercept( 42 net::URLRequestJob* GViewRequestInterceptor::MaybeIntercept(
47 net::URLRequest* request) { 43 net::URLRequest* request) const {
48 // Don't attempt to intercept here as we want to wait until the mime 44 // Don't attempt to intercept here as we want to wait until the mime
49 // type is fully determined. 45 // type is fully determined.
50 return NULL; 46 return NULL;
51 } 47 }
52 48
49 net::URLRequestJob* GViewRequestInterceptor::MaybeInterceptRedirect(
50 const GURL& location,
51 net::URLRequest* request) const {
52 return NULL;
53 }
54
53 net::URLRequestJob* GViewRequestInterceptor::MaybeInterceptResponse( 55 net::URLRequestJob* GViewRequestInterceptor::MaybeInterceptResponse(
54 net::URLRequest* request) { 56 net::URLRequest* request) const {
55 // Do not intercept this request if it is a download. 57 // Do not intercept this request if it is a download.
56 if (request->load_flags() & net::LOAD_IS_DOWNLOAD) { 58 if (request->load_flags() & net::LOAD_IS_DOWNLOAD) {
57 return NULL; 59 return NULL;
58 } 60 }
59 61
60 std::string mime_type; 62 std::string mime_type;
61 request->GetMimeType(&mime_type); 63 request->GetMimeType(&mime_type);
62 // If the local PDF viewing plug-in is installed and enabled, don't 64 // If the local PDF viewing plug-in is installed and enabled, don't
63 // redirect PDF files to Google Document Viewer. 65 // redirect PDF files to Google Document Viewer.
64 if (mime_type == kPdfMimeType) { 66 if (mime_type == kPdfMimeType) {
65 FilePath pdf_path; 67 FilePath pdf_path;
66 webkit::npapi::WebPluginInfo info; 68 webkit::npapi::WebPluginInfo info;
67 PathService::Get(chrome::FILE_PDF_PLUGIN, &pdf_path); 69 PathService::Get(chrome::FILE_PDF_PLUGIN, &pdf_path);
68 if (webkit::npapi::PluginList::Singleton()->GetPluginInfoByPath( 70 if (webkit::npapi::PluginList::Singleton()->GetPluginInfoByPath(
69 pdf_path, &info) && 71 pdf_path, &info) &&
70 webkit::npapi::IsPluginEnabled(info)) 72 webkit::npapi::IsPluginEnabled(info))
71 return NULL; 73 return NULL;
72 } 74 }
73 // If supported, build the URL to the Google Document Viewer 75 // If supported, build the URL to the Google Document Viewer
74 // including the origial document's URL, then create a new job that 76 // including the origial document's URL, then create a new job that
75 // will redirect the browser to this new URL. 77 // will redirect the browser to this new URL.
76 if (supported_mime_types_.count(mime_type) > 0) { 78 if (supported_mime_types_.count(mime_type) > 0) {
77 std::string url(kGViewUrlPrefix); 79 std::string url(kGViewUrlPrefix);
78 url += EscapePath(request->url().spec()); 80 url += EscapePath(request->url().spec());
79 return new net::URLRequestRedirectJob(request, GURL(url)); 81 return new net::URLRequestRedirectJob(request, GURL(url));
80 } 82 }
81 return NULL; 83 return NULL;
82 } 84 }
83 85
84 GViewRequestInterceptor* GViewRequestInterceptor::GetInstance() {
85 return Singleton<GViewRequestInterceptor>::get();
86 }
87
88 } // namespace chromeos 86 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/gview_request_interceptor.h ('k') | chrome/browser/chromeos/gview_request_interceptor_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698