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

Side by Side Diff: chrome/browser/nacl_host/nacl_browser_delegate_impl.cc

Issue 277463003: Use a proper profile in NaClBrowserDelegateImpl::MapUrlToLocalFilePath (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 7 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/nacl_host/nacl_browser_delegate_impl.h" 5 #include "chrome/browser/nacl_host/nacl_browser_delegate_impl.h"
6 6
7 #include "base/path_service.h" 7 #include "base/path_service.h"
8 #include "base/strings/string_split.h" 8 #include "base/strings/string_split.h"
9 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "chrome/browser/browser_process.h" 10 #include "chrome/browser/browser_process.h"
11 #include "chrome/browser/component_updater/pnacl/pnacl_component_installer.h" 11 #include "chrome/browser/component_updater/pnacl/pnacl_component_installer.h"
12 #include "chrome/browser/extensions/extension_service.h" 12 #include "chrome/browser/extensions/extension_service.h"
13 #include "chrome/browser/nacl_host/nacl_infobar_delegate.h" 13 #include "chrome/browser/nacl_host/nacl_infobar_delegate.h"
14 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/profiles/profile_manager.h"
15 #include "chrome/browser/renderer_host/pepper/chrome_browser_pepper_host_factory .h" 16 #include "chrome/browser/renderer_host/pepper/chrome_browser_pepper_host_factory .h"
16 #include "chrome/common/chrome_paths.h" 17 #include "chrome/common/chrome_paths.h"
17 #include "chrome/common/chrome_paths_internal.h" 18 #include "chrome/common/chrome_paths_internal.h"
18 #include "chrome/common/chrome_version_info.h" 19 #include "chrome/common/chrome_version_info.h"
19 #include "chrome/common/logging_chrome.h" 20 #include "chrome/common/logging_chrome.h"
20 #include "content/public/browser/browser_thread.h" 21 #include "content/public/browser/browser_thread.h"
21 #include "content/public/browser/render_frame_host.h" 22 #include "content/public/browser/render_frame_host.h"
22 #include "content/public/browser/site_instance.h" 23 #include "content/public/browser/site_instance.h"
23 #include "extensions/browser/extension_system.h" 24 #include "extensions/browser/extension_system.h"
24 #include "extensions/browser/info_map.h" 25 #include "extensions/browser/info_map.h"
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 DCHECK(!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 98 DCHECK(!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
98 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, 99 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
99 base::Bind(&OnKeepaliveOnUIThread, 100 base::Bind(&OnKeepaliveOnUIThread,
100 instance_data, 101 instance_data,
101 profile_data_directory)); 102 profile_data_directory));
102 } 103 }
103 104
104 } // namespace 105 } // namespace
105 106
106 NaClBrowserDelegateImpl::NaClBrowserDelegateImpl( 107 NaClBrowserDelegateImpl::NaClBrowserDelegateImpl(
107 extensions::InfoMap* extension_info_map) 108 ProfileManager* profile_manager)
108 : extension_info_map_(extension_info_map), inverse_debug_patterns_(false) {} 109 : profile_manager_(profile_manager), inverse_debug_patterns_(false) {
110 DCHECK(profile_manager_);
111 }
109 112
110 NaClBrowserDelegateImpl::~NaClBrowserDelegateImpl() { 113 NaClBrowserDelegateImpl::~NaClBrowserDelegateImpl() {
111 } 114 }
112 115
113 void NaClBrowserDelegateImpl::ShowMissingArchInfobar(int render_process_id, 116 void NaClBrowserDelegateImpl::ShowMissingArchInfobar(int render_process_id,
114 int render_view_id) { 117 int render_view_id) {
115 content::BrowserThread::PostTask( 118 content::BrowserThread::PostTask(
116 content::BrowserThread::UI, FROM_HERE, 119 content::BrowserThread::UI, FROM_HERE,
117 base::Bind(&NaClInfoBarDelegate::Create, render_process_id, 120 base::Bind(&NaClInfoBarDelegate::Create, render_process_id,
118 render_view_id)); 121 render_view_id));
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 if (inverse_debug_patterns_) { 199 if (inverse_debug_patterns_) {
197 return !matches; 200 return !matches;
198 } else { 201 } else {
199 return matches; 202 return matches;
200 } 203 }
201 } 204 }
202 205
203 // This function is security sensitive. Be sure to check with a security 206 // This function is security sensitive. Be sure to check with a security
204 // person before you modify it. 207 // person before you modify it.
205 bool NaClBrowserDelegateImpl::MapUrlToLocalFilePath( 208 bool NaClBrowserDelegateImpl::MapUrlToLocalFilePath(
206 const GURL& file_url, bool use_blocking_api, base::FilePath* file_path) { 209 const GURL& file_url, bool use_blocking_api,
207 DCHECK(extension_info_map_); 210 const base::FilePath& profile_directory, base::FilePath* file_path) {
jochen (gone - plz use gerrit) 2014/05/08 07:04:13 please clang-format this
Yusuke Sato 2014/05/08 16:28:01 Done.
211 // Get the profile associated with the renderer.
212 Profile* profile = profile_manager_->GetProfileByPath(profile_directory);
213 if (!profile)
214 return false;
215
216 scoped_refptr<extensions::InfoMap> extension_info_map =
217 extensions::ExtensionSystem::Get(profile)->info_map();
218 DCHECK(extension_info_map);
219
208 // Check that the URL is recognized by the extension system. 220 // Check that the URL is recognized by the extension system.
209 const extensions::Extension* extension = 221 const extensions::Extension* extension =
210 extension_info_map_->extensions().GetExtensionOrAppByURL(file_url); 222 extension_info_map->extensions().GetExtensionOrAppByURL(file_url);
211 if (!extension) 223 if (!extension)
212 return false; 224 return false;
213 225
214 // This is a short-cut which avoids calling a blocking file operation 226 // This is a short-cut which avoids calling a blocking file operation
215 // (GetFilePath()), so that this can be called on the IO thread. It only 227 // (GetFilePath()), so that this can be called on the IO thread. It only
216 // handles a subset of the urls. 228 // handles a subset of the urls.
217 if (!use_blocking_api) { 229 if (!use_blocking_api) {
218 if (file_url.SchemeIs(extensions::kExtensionScheme)) { 230 if (file_url.SchemeIs(extensions::kExtensionScheme)) {
219 std::string path = file_url.path(); 231 std::string path = file_url.path();
220 base::TrimString(path, "/", &path); // Remove first slash 232 base::TrimString(path, "/", &path); // Remove first slash
221 *file_path = extension->path().AppendASCII(path); 233 *file_path = extension->path().AppendASCII(path);
222 return true; 234 return true;
223 } 235 }
224 return false; 236 return false;
225 } 237 }
226 238
227 std::string path = file_url.path(); 239 std::string path = file_url.path();
228 extensions::ExtensionResource resource; 240 extensions::ExtensionResource resource;
229 241
230 if (SharedModuleInfo::IsImportedPath(path)) { 242 if (SharedModuleInfo::IsImportedPath(path)) {
231 // Check if this is a valid path that is imported for this extension. 243 // Check if this is a valid path that is imported for this extension.
232 std::string new_extension_id; 244 std::string new_extension_id;
233 std::string new_relative_path; 245 std::string new_relative_path;
234 SharedModuleInfo::ParseImportedPath(path, &new_extension_id, 246 SharedModuleInfo::ParseImportedPath(path, &new_extension_id,
235 &new_relative_path); 247 &new_relative_path);
236 const extensions::Extension* new_extension = 248 const extensions::Extension* new_extension =
237 extension_info_map_->extensions().GetByID(new_extension_id); 249 extension_info_map->extensions().GetByID(new_extension_id);
238 if (!new_extension) 250 if (!new_extension)
239 return false; 251 return false;
240 252
241 if (!SharedModuleInfo::ImportsExtensionById(extension, new_extension_id) || 253 if (!SharedModuleInfo::ImportsExtensionById(extension, new_extension_id) ||
242 !SharedModuleInfo::IsExportAllowed(new_extension, new_relative_path)) { 254 !SharedModuleInfo::IsExportAllowed(new_extension, new_relative_path)) {
243 return false; 255 return false;
244 } 256 }
245 257
246 resource = new_extension->GetResource(new_relative_path); 258 resource = new_extension->GetResource(new_relative_path);
247 } else { 259 } else {
(...skipping 10 matching lines...) Expand all
258 return false; 270 return false;
259 271
260 *file_path = resource_file_path; 272 *file_path = resource_file_path;
261 return true; 273 return true;
262 } 274 }
263 275
264 content::BrowserPpapiHost::OnKeepaliveCallback 276 content::BrowserPpapiHost::OnKeepaliveCallback
265 NaClBrowserDelegateImpl::GetOnKeepaliveCallback() { 277 NaClBrowserDelegateImpl::GetOnKeepaliveCallback() {
266 return base::Bind(&OnKeepalive); 278 return base::Bind(&OnKeepalive);
267 } 279 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698