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

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

Issue 16805: Move Contains() method to file_utils, stop relying on in extensions_protocol (Closed)
Patch Set: Review feedback Created 11 years, 11 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
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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_protocol.h" 5 #include "chrome/browser/extensions/extension_protocol.h"
6 6
7 #include "base/string_util.h" 7 #include "base/string_util.h"
8 #include "chrome/browser/net/chrome_url_request_context.h" 8 #include "chrome/browser/net/chrome_url_request_context.h"
9 #include "googleurl/src/url_util.h" 9 #include "googleurl/src/url_util.h"
10 #include "net/base/net_util.h" 10 #include "net/base/net_util.h"
(...skipping 22 matching lines...) Expand all
33 replacements.SetPathStr(new_path); 33 replacements.SetPathStr(new_path);
34 GURL file_url = extension_url.ReplaceComponents(replacements); 34 GURL file_url = extension_url.ReplaceComponents(replacements);
35 if (!file_url.is_valid()) 35 if (!file_url.is_valid())
36 return FilePath(); 36 return FilePath();
37 37
38 // Convert the result back to a FilePath. 38 // Convert the result back to a FilePath.
39 FilePath ret_val; 39 FilePath ret_val;
40 if (!net::FileURLToFilePath(file_url, &ret_val)) 40 if (!net::FileURLToFilePath(file_url, &ret_val))
41 return FilePath(); 41 return FilePath();
42 42
43 if (!file_util::AbsolutePath(&ret_val))
44 return FilePath();
45
46 // Double-check that the path we ended up with is actually inside the 43 // Double-check that the path we ended up with is actually inside the
47 // extension root. 44 // extension root. We can do this with a simple prefix match because:
48 if (!extension_path.Contains(ret_val)) 45 // a) We control the prefix on both sides, and they should match.
46 // b) GURL normalizes things like "../" and "//" before it gets to us.
47 if (ret_val.value().find(extension_path.value() +
48 FilePath::kSeparators[0]) != 0)
49 return FilePath(); 49 return FilePath();
50 50
51 return ret_val; 51 return ret_val;
52 } 52 }
53 53
54 // Factory registered with URLRequest to create URLRequestJobs for extension:// 54 // Factory registered with URLRequest to create URLRequestJobs for extension://
55 // URLs. 55 // URLs.
56 static URLRequestJob* CreateExtensionURLRequestJob(URLRequest* request, 56 static URLRequestJob* CreateExtensionURLRequestJob(URLRequest* request,
57 const std::string& scheme) { 57 const std::string& scheme) {
58 ChromeURLRequestContext* context = 58 ChromeURLRequestContext* context =
(...skipping 28 matching lines...) Expand all
87 void RegisterExtensionProtocols() { 87 void RegisterExtensionProtocols() {
88 // Being a standard scheme allows us to resolve relative paths. This is used 88 // Being a standard scheme allows us to resolve relative paths. This is used
89 // by extensions, but not by standalone user scripts. 89 // by extensions, but not by standalone user scripts.
90 url_util::AddStandardScheme(kExtensionURLScheme); 90 url_util::AddStandardScheme(kExtensionURLScheme);
91 91
92 URLRequest::RegisterProtocolFactory(kExtensionURLScheme, 92 URLRequest::RegisterProtocolFactory(kExtensionURLScheme,
93 &CreateExtensionURLRequestJob); 93 &CreateExtensionURLRequestJob);
94 URLRequest::RegisterProtocolFactory(kUserScriptURLScheme, 94 URLRequest::RegisterProtocolFactory(kUserScriptURLScheme,
95 &CreateUserScriptURLRequestJob); 95 &CreateUserScriptURLRequestJob);
96 } 96 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698