OLD | NEW |
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 Loading... |
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 Loading... |
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, |
207 DCHECK(extension_info_map_); | 210 bool use_blocking_api, |
| 211 const base::FilePath& profile_directory, |
| 212 base::FilePath* file_path) { |
| 213 // Get the profile associated with the renderer. |
| 214 Profile* profile = profile_manager_->GetProfileByPath(profile_directory); |
| 215 if (!profile) |
| 216 return false; |
| 217 |
| 218 scoped_refptr<extensions::InfoMap> extension_info_map = |
| 219 extensions::ExtensionSystem::Get(profile)->info_map(); |
| 220 DCHECK(extension_info_map); |
| 221 |
208 // Check that the URL is recognized by the extension system. | 222 // Check that the URL is recognized by the extension system. |
209 const extensions::Extension* extension = | 223 const extensions::Extension* extension = |
210 extension_info_map_->extensions().GetExtensionOrAppByURL(file_url); | 224 extension_info_map->extensions().GetExtensionOrAppByURL(file_url); |
211 if (!extension) | 225 if (!extension) |
212 return false; | 226 return false; |
213 | 227 |
214 // This is a short-cut which avoids calling a blocking file operation | 228 // 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 | 229 // (GetFilePath()), so that this can be called on the IO thread. It only |
216 // handles a subset of the urls. | 230 // handles a subset of the urls. |
217 if (!use_blocking_api) { | 231 if (!use_blocking_api) { |
218 if (file_url.SchemeIs(extensions::kExtensionScheme)) { | 232 if (file_url.SchemeIs(extensions::kExtensionScheme)) { |
219 std::string path = file_url.path(); | 233 std::string path = file_url.path(); |
220 base::TrimString(path, "/", &path); // Remove first slash | 234 base::TrimString(path, "/", &path); // Remove first slash |
221 *file_path = extension->path().AppendASCII(path); | 235 *file_path = extension->path().AppendASCII(path); |
222 return true; | 236 return true; |
223 } | 237 } |
224 return false; | 238 return false; |
225 } | 239 } |
226 | 240 |
227 std::string path = file_url.path(); | 241 std::string path = file_url.path(); |
228 extensions::ExtensionResource resource; | 242 extensions::ExtensionResource resource; |
229 | 243 |
230 if (SharedModuleInfo::IsImportedPath(path)) { | 244 if (SharedModuleInfo::IsImportedPath(path)) { |
231 // Check if this is a valid path that is imported for this extension. | 245 // Check if this is a valid path that is imported for this extension. |
232 std::string new_extension_id; | 246 std::string new_extension_id; |
233 std::string new_relative_path; | 247 std::string new_relative_path; |
234 SharedModuleInfo::ParseImportedPath(path, &new_extension_id, | 248 SharedModuleInfo::ParseImportedPath(path, &new_extension_id, |
235 &new_relative_path); | 249 &new_relative_path); |
236 const extensions::Extension* new_extension = | 250 const extensions::Extension* new_extension = |
237 extension_info_map_->extensions().GetByID(new_extension_id); | 251 extension_info_map->extensions().GetByID(new_extension_id); |
238 if (!new_extension) | 252 if (!new_extension) |
239 return false; | 253 return false; |
240 | 254 |
241 if (!SharedModuleInfo::ImportsExtensionById(extension, new_extension_id) || | 255 if (!SharedModuleInfo::ImportsExtensionById(extension, new_extension_id) || |
242 !SharedModuleInfo::IsExportAllowed(new_extension, new_relative_path)) { | 256 !SharedModuleInfo::IsExportAllowed(new_extension, new_relative_path)) { |
243 return false; | 257 return false; |
244 } | 258 } |
245 | 259 |
246 resource = new_extension->GetResource(new_relative_path); | 260 resource = new_extension->GetResource(new_relative_path); |
247 } else { | 261 } else { |
(...skipping 10 matching lines...) Expand all Loading... |
258 return false; | 272 return false; |
259 | 273 |
260 *file_path = resource_file_path; | 274 *file_path = resource_file_path; |
261 return true; | 275 return true; |
262 } | 276 } |
263 | 277 |
264 content::BrowserPpapiHost::OnKeepaliveCallback | 278 content::BrowserPpapiHost::OnKeepaliveCallback |
265 NaClBrowserDelegateImpl::GetOnKeepaliveCallback() { | 279 NaClBrowserDelegateImpl::GetOnKeepaliveCallback() { |
266 return base::Bind(&OnKeepalive); | 280 return base::Bind(&OnKeepalive); |
267 } | 281 } |
OLD | NEW |