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

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

Issue 2906010: Command line switch to disable GView PDF handling. (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: Remove command line flag, simplify. Created 10 years, 5 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
8 #include "base/path_service.h"
9 #include "chrome/common/chrome_paths.h"
7 #include "net/base/escape.h" 10 #include "net/base/escape.h"
8 #include "net/base/load_flags.h" 11 #include "net/base/load_flags.h"
9 #include "net/url_request/url_request_job.h" 12 #include "net/url_request/url_request_job.h"
10 #include "net/url_request/url_request.h" 13 #include "net/url_request/url_request.h"
11 #include "net/url_request/url_request_redirect_job.h" 14 #include "net/url_request/url_request_redirect_job.h"
12 #include "googleurl/src/gurl.h" 15 #include "googleurl/src/gurl.h"
16 #include "webkit/glue/plugins/plugin_list.h"
13 17
14 namespace chromeos { 18 namespace chromeos {
15 19
20 // The PDF mime type is treated special if the browser has a built-in
21 // PDF viewer plug-in installed - we want to intercept only if we're
22 // told to.
23 static const char* const kPdfMimeType = "application/pdf";
24
16 // This is the list of mime types currently supported by the Google 25 // This is the list of mime types currently supported by the Google
17 // Document Viewer. 26 // Document Viewer.
18 static const char* const supported_mime_type_list[] = { 27 static const char* const supported_mime_type_list[] = {
19 "application/pdf", 28 kPdfMimeType,
20 "application/vnd.ms-powerpoint" 29 "application/vnd.ms-powerpoint"
21 }; 30 };
22 31
23 static const char* const kGViewUrlPrefix = "http://docs.google.com/gview?url="; 32 static const char* const kGViewUrlPrefix = "http://docs.google.com/gview?url=";
24 33
25 GViewRequestInterceptor::GViewRequestInterceptor() { 34 GViewRequestInterceptor::GViewRequestInterceptor() {
26 URLRequest::RegisterRequestInterceptor(this); 35 URLRequest::RegisterRequestInterceptor(this);
27 for (size_t i = 0; i < arraysize(supported_mime_type_list); ++i) { 36 for (size_t i = 0; i < arraysize(supported_mime_type_list); ++i) {
28 supported_mime_types_.insert(supported_mime_type_list[i]); 37 supported_mime_types_.insert(supported_mime_type_list[i]);
29 } 38 }
(...skipping 11 matching lines...) Expand all
41 50
42 URLRequestJob* GViewRequestInterceptor::MaybeInterceptResponse( 51 URLRequestJob* GViewRequestInterceptor::MaybeInterceptResponse(
43 URLRequest* request) { 52 URLRequest* request) {
44 // Do not intercept this request if it is a download. 53 // Do not intercept this request if it is a download.
45 if (request->load_flags() & net::LOAD_IS_DOWNLOAD) { 54 if (request->load_flags() & net::LOAD_IS_DOWNLOAD) {
46 return NULL; 55 return NULL;
47 } 56 }
48 57
49 std::string mime_type; 58 std::string mime_type;
50 request->GetMimeType(&mime_type); 59 request->GetMimeType(&mime_type);
60 // If the local PDF viewing plug-in is installed and enabled, don't
61 // redirect PDF files to Google Document Viewer.
62 if (mime_type == kPdfMimeType) {
63 FilePath pdf_path;
64 WebPluginInfo info;
65 PathService::Get(chrome::FILE_PDF_PLUGIN, &pdf_path);
66 if (NPAPI::PluginList::Singleton()->GetPluginInfoByPath(pdf_path, &info) &&
67 info.enabled)
68 return NULL;
69 }
51 // If supported, build the URL to the Google Document Viewer 70 // If supported, build the URL to the Google Document Viewer
52 // including the origial document's URL, then create a new job that 71 // including the origial document's URL, then create a new job that
53 // will redirect the browser to this new URL. 72 // will redirect the browser to this new URL.
54 if (supported_mime_types_.count(mime_type) > 0) { 73 if (supported_mime_types_.count(mime_type) > 0) {
55 std::string url(kGViewUrlPrefix); 74 std::string url(kGViewUrlPrefix);
56 url += EscapePath(request->url().spec()); 75 url += EscapePath(request->url().spec());
57 return new URLRequestRedirectJob(request, GURL(url)); 76 return new URLRequestRedirectJob(request, GURL(url));
58 } 77 }
59 return NULL; 78 return NULL;
60 } 79 }
61 80
62 URLRequest::Interceptor* GViewRequestInterceptor::GetGViewRequestInterceptor() { 81 URLRequest::Interceptor* GViewRequestInterceptor::GetGViewRequestInterceptor() {
63 return Singleton<GViewRequestInterceptor>::get(); 82 return Singleton<GViewRequestInterceptor>::get();
64 } 83 }
65 84
66 } // namespace chromeos 85 } // namespace chromeos
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698