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

Side by Side Diff: chrome/browser/extensions/extension_protocols.cc

Issue 5384002: net: Remove typedef net::URLRequest URLRequest; (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review Created 10 years 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/extensions/extension_protocols.h" 5 #include "chrome/browser/extensions/extension_protocols.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "app/resource_bundle.h" 9 #include "app/resource_bundle.h"
10 #include "base/file_path.h" 10 #include "base/file_path.h"
(...skipping 16 matching lines...) Expand all
27 #include "net/base/mime_util.h" 27 #include "net/base/mime_util.h"
28 #include "net/base/net_errors.h" 28 #include "net/base/net_errors.h"
29 #include "net/url_request/url_request_error_job.h" 29 #include "net/url_request/url_request_error_job.h"
30 #include "net/url_request/url_request_file_job.h" 30 #include "net/url_request/url_request_file_job.h"
31 #include "net/url_request/url_request_simple_job.h" 31 #include "net/url_request/url_request_simple_job.h"
32 32
33 namespace { 33 namespace {
34 34
35 class URLRequestResourceBundleJob : public URLRequestSimpleJob { 35 class URLRequestResourceBundleJob : public URLRequestSimpleJob {
36 public: 36 public:
37 explicit URLRequestResourceBundleJob(URLRequest* request, 37 explicit URLRequestResourceBundleJob(net::URLRequest* request,
38 const FilePath& filename, int resource_id) 38 const FilePath& filename, int resource_id)
39 : URLRequestSimpleJob(request), 39 : URLRequestSimpleJob(request),
40 filename_(filename), 40 filename_(filename),
41 resource_id_(resource_id) { } 41 resource_id_(resource_id) { }
42 42
43 // URLRequestSimpleJob method. 43 // URLRequestSimpleJob method.
44 virtual bool GetData(std::string* mime_type, 44 virtual bool GetData(std::string* mime_type,
45 std::string* charset, 45 std::string* charset,
46 std::string* data) const { 46 std::string* data) const {
47 const ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 47 const ResourceBundle& rb = ResourceBundle::GetSharedInstance();
(...skipping 12 matching lines...) Expand all
60 virtual ~URLRequestResourceBundleJob() { } 60 virtual ~URLRequestResourceBundleJob() { }
61 61
62 // We need the filename of the resource to determine the mime type. 62 // We need the filename of the resource to determine the mime type.
63 FilePath filename_; 63 FilePath filename_;
64 64
65 // The resource bundle id to load. 65 // The resource bundle id to load.
66 int resource_id_; 66 int resource_id_;
67 }; 67 };
68 68
69 // Returns true if an chrome-extension:// resource should be allowed to load. 69 // Returns true if an chrome-extension:// resource should be allowed to load.
70 bool AllowExtensionResourceLoad(URLRequest* request, 70 bool AllowExtensionResourceLoad(net::URLRequest* request,
71 ChromeURLRequestContext* context, 71 ChromeURLRequestContext* context,
72 const std::string& scheme) { 72 const std::string& scheme) {
73 const ResourceDispatcherHostRequestInfo* info = 73 const ResourceDispatcherHostRequestInfo* info =
74 ResourceDispatcherHost::InfoForRequest(request); 74 ResourceDispatcherHost::InfoForRequest(request);
75 75
76 // We have seen crashes where info is NULL: crbug.com/52374. 76 // We have seen crashes where info is NULL: crbug.com/52374.
77 if (!info) { 77 if (!info) {
78 LOG(ERROR) << "Allowing load of " << request->url().spec() 78 LOG(ERROR) << "Allowing load of " << request->url().spec()
79 << "from unknown origin. Could not find user data for " 79 << "from unknown origin. Could not find user data for "
80 << "request."; 80 << "request.";
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 LOG(ERROR) << "Denying load of " << request->url().spec() << " from " 135 LOG(ERROR) << "Denying load of " << request->url().spec() << " from "
136 << origin_url.spec() << " because the extension does not have " 136 << origin_url.spec() << " because the extension does not have "
137 << "access to the requesting page."; 137 << "access to the requesting page.";
138 return false; 138 return false;
139 } 139 }
140 } 140 }
141 } 141 }
142 142
143 } // namespace 143 } // namespace
144 144
145 // Factory registered with URLRequest to create URLRequestJobs for extension:// 145 // Factory registered with net::URLRequest to create URLRequestJobs for
146 // URLs. 146 // extension:// URLs.
147 static URLRequestJob* CreateExtensionURLRequestJob(URLRequest* request, 147 static URLRequestJob* CreateExtensionURLRequestJob(net::URLRequest* request,
148 const std::string& scheme) { 148 const std::string& scheme) {
149 ChromeURLRequestContext* context = 149 ChromeURLRequestContext* context =
150 static_cast<ChromeURLRequestContext*>(request->context()); 150 static_cast<ChromeURLRequestContext*>(request->context());
151 151
152 // TODO(mpcomplete): better error code. 152 // TODO(mpcomplete): better error code.
153 if (!AllowExtensionResourceLoad(request, context, scheme)) 153 if (!AllowExtensionResourceLoad(request, context, scheme))
154 return new URLRequestErrorJob(request, net::ERR_ADDRESS_UNREACHABLE); 154 return new URLRequestErrorJob(request, net::ERR_ADDRESS_UNREACHABLE);
155 155
156 // chrome-extension://extension-id/resource/path.js 156 // chrome-extension://extension-id/resource/path.js
157 const std::string& extension_id = request->url().host(); 157 const std::string& extension_id = request->url().host();
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 FilePath resource_file_path; 194 FilePath resource_file_path;
195 { 195 {
196 // Getting the file path will touch the file system. Fixing 196 // Getting the file path will touch the file system. Fixing
197 // crbug.com/59849 would also fix this. Suppress the error for now. 197 // crbug.com/59849 would also fix this. Suppress the error for now.
198 base::ThreadRestrictions::ScopedAllowIO allow_io; 198 base::ThreadRestrictions::ScopedAllowIO allow_io;
199 resource_file_path = resource.GetFilePath(); 199 resource_file_path = resource.GetFilePath();
200 } 200 }
201 return new URLRequestFileJob(request, resource_file_path); 201 return new URLRequestFileJob(request, resource_file_path);
202 } 202 }
203 203
204 // Factory registered with URLRequest to create URLRequestJobs for 204 // Factory registered with net::URLRequest to create URLRequestJobs for
205 // chrome-user-script:/ URLs. 205 // chrome-user-script:/ URLs.
206 static URLRequestJob* CreateUserScriptURLRequestJob(URLRequest* request, 206 static URLRequestJob* CreateUserScriptURLRequestJob(net::URLRequest* request,
207 const std::string& scheme) { 207 const std::string& scheme) {
208 ChromeURLRequestContext* context = 208 ChromeURLRequestContext* context =
209 static_cast<ChromeURLRequestContext*>(request->context()); 209 static_cast<ChromeURLRequestContext*>(request->context());
210 210
211 // chrome-user-script:/user-script-name.user.js 211 // chrome-user-script:/user-script-name.user.js
212 FilePath directory_path = context->user_script_dir_path(); 212 FilePath directory_path = context->user_script_dir_path();
213 213
214 ExtensionResource resource(request->url().host(), directory_path, 214 ExtensionResource resource(request->url().host(), directory_path,
215 extension_file_util::ExtensionURLToRelativeFilePath(request->url())); 215 extension_file_util::ExtensionURLToRelativeFilePath(request->url()));
216 216
217 return new URLRequestFileJob(request, resource.GetFilePath()); 217 return new URLRequestFileJob(request, resource.GetFilePath());
218 } 218 }
219 219
220 void RegisterExtensionProtocols() { 220 void RegisterExtensionProtocols() {
221 URLRequest::RegisterProtocolFactory(chrome::kExtensionScheme, 221 net::URLRequest::RegisterProtocolFactory(chrome::kExtensionScheme,
222 &CreateExtensionURLRequestJob); 222 &CreateExtensionURLRequestJob);
223 URLRequest::RegisterProtocolFactory(chrome::kUserScriptScheme, 223 net::URLRequest::RegisterProtocolFactory(chrome::kUserScriptScheme,
224 &CreateUserScriptURLRequestJob); 224 &CreateUserScriptURLRequestJob);
225 } 225 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698