| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 | 38 |
| 39 namespace { | 39 namespace { |
| 40 | 40 |
| 41 // These are temporarily needed for testing non-sfi mode on ChromeOS without | 41 // These are temporarily needed for testing non-sfi mode on ChromeOS without |
| 42 // passing command-line arguments to Chrome. | 42 // passing command-line arguments to Chrome. |
| 43 const char* const kAllowedNonSfiOrigins[] = { | 43 const char* const kAllowedNonSfiOrigins[] = { |
| 44 "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see http://crbug.com/355141 | 44 "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see http://crbug.com/355141 |
| 45 "4EB74897CB187C7633357C2FE832E0AD6A44883A" // see http://crbug.com/355141 | 45 "4EB74897CB187C7633357C2FE832E0AD6A44883A" // see http://crbug.com/355141 |
| 46 }; | 46 }; |
| 47 | 47 |
| 48 // Handles an extension's NaCl process transitioning in or out of idle state by | |
| 49 // relaying the state to the extension's process manager. | |
| 50 // | |
| 51 // A NaCl instance, when active (making PPAPI calls or receiving callbacks), | |
| 52 // sends keepalive IPCs to the browser process BrowserPpapiHost at a throttled | |
| 53 // rate. The content::BrowserPpapiHost passes context information up to the | |
| 54 // chrome level NaClProcessHost where we use the instance's context to find the | |
| 55 // associated extension process manager. | |
| 56 // | |
| 57 // There is a 1:many relationship for extension:nacl-embeds, but only a | |
| 58 // 1:1 relationship for NaClProcessHost:PP_Instance. The content layer doesn't | |
| 59 // rely on this knowledge because it routes messages for ppapi non-nacl | |
| 60 // instances as well, though they won't have callbacks set. Here the 1:1 | |
| 61 // assumption is made and DCHECKed. | |
| 62 void OnKeepaliveOnUIThread( | |
| 63 const content::BrowserPpapiHost::OnKeepaliveInstanceData& instance_data, | |
| 64 const base::FilePath& profile_data_directory) { | |
| 65 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 66 | |
| 67 // Only one instance will exist for NaCl embeds, even when more than one | |
| 68 // embed of the same plugin exists on the same page. | |
| 69 DCHECK_EQ(1U, instance_data.size()); | |
| 70 if (instance_data.size() < 1) | |
| 71 return; | |
| 72 | |
| 73 #if BUILDFLAG(ENABLE_EXTENSIONS) | |
| 74 extensions::ProcessManager::OnKeepaliveFromPlugin( | |
| 75 instance_data[0].render_process_id, | |
| 76 instance_data[0].render_frame_id, | |
| 77 instance_data[0].document_url.host()); | |
| 78 #endif | |
| 79 } | |
| 80 | |
| 81 // Calls OnKeepaliveOnUIThread on UI thread. | |
| 82 void OnKeepalive( | |
| 83 const content::BrowserPpapiHost::OnKeepaliveInstanceData& instance_data, | |
| 84 const base::FilePath& profile_data_directory) { | |
| 85 DCHECK(!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | |
| 86 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, | |
| 87 base::Bind(&OnKeepaliveOnUIThread, | |
| 88 instance_data, | |
| 89 profile_data_directory)); | |
| 90 } | |
| 91 | |
| 92 } // namespace | 48 } // namespace |
| 93 | 49 |
| 94 NaClBrowserDelegateImpl::NaClBrowserDelegateImpl( | 50 NaClBrowserDelegateImpl::NaClBrowserDelegateImpl( |
| 95 ProfileManager* profile_manager) | 51 ProfileManager* profile_manager) |
| 96 : profile_manager_(profile_manager), inverse_debug_patterns_(false) { | 52 : profile_manager_(profile_manager), inverse_debug_patterns_(false) { |
| 97 DCHECK(profile_manager_); | 53 DCHECK(profile_manager_); |
| 98 for (size_t i = 0; i < arraysize(kAllowedNonSfiOrigins); ++i) { | 54 for (size_t i = 0; i < arraysize(kAllowedNonSfiOrigins); ++i) { |
| 99 allowed_nonsfi_origins_.insert(kAllowedNonSfiOrigins[i]); | 55 allowed_nonsfi_origins_.insert(kAllowedNonSfiOrigins[i]); |
| 100 } | 56 } |
| 101 } | 57 } |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 #if BUILDFLAG(ENABLE_EXTENSIONS) | 170 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 215 scoped_refptr<extensions::InfoMap> extension_info_map = | 171 scoped_refptr<extensions::InfoMap> extension_info_map = |
| 216 GetExtensionInfoMap(profile_directory); | 172 GetExtensionInfoMap(profile_directory); |
| 217 return extension_info_map->MapUrlToLocalFilePath( | 173 return extension_info_map->MapUrlToLocalFilePath( |
| 218 file_url, use_blocking_api, file_path); | 174 file_url, use_blocking_api, file_path); |
| 219 #else | 175 #else |
| 220 return false; | 176 return false; |
| 221 #endif | 177 #endif |
| 222 } | 178 } |
| 223 | 179 |
| 224 content::BrowserPpapiHost::OnKeepaliveCallback | |
| 225 NaClBrowserDelegateImpl::GetOnKeepaliveCallback() { | |
| 226 return base::Bind(&OnKeepalive); | |
| 227 } | |
| 228 | |
| 229 bool NaClBrowserDelegateImpl::IsNonSfiModeAllowed( | 180 bool NaClBrowserDelegateImpl::IsNonSfiModeAllowed( |
| 230 const base::FilePath& profile_directory, | 181 const base::FilePath& profile_directory, |
| 231 const GURL& manifest_url) { | 182 const GURL& manifest_url) { |
| 232 #if BUILDFLAG(ENABLE_EXTENSIONS) | 183 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 233 const extensions::ExtensionSet* extension_set = | 184 const extensions::ExtensionSet* extension_set = |
| 234 &GetExtensionInfoMap(profile_directory)->extensions(); | 185 &GetExtensionInfoMap(profile_directory)->extensions(); |
| 235 return chrome::IsExtensionOrSharedModuleWhitelisted( | 186 return chrome::IsExtensionOrSharedModuleWhitelisted( |
| 236 manifest_url, extension_set, allowed_nonsfi_origins_); | 187 manifest_url, extension_set, allowed_nonsfi_origins_); |
| 237 #else | 188 #else |
| 238 return false; | 189 return false; |
| 239 #endif | 190 #endif |
| 240 } | 191 } |
| 241 | 192 |
| 242 #if BUILDFLAG(ENABLE_EXTENSIONS) | 193 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 243 scoped_refptr<extensions::InfoMap> NaClBrowserDelegateImpl::GetExtensionInfoMap( | 194 scoped_refptr<extensions::InfoMap> NaClBrowserDelegateImpl::GetExtensionInfoMap( |
| 244 const base::FilePath& profile_directory) { | 195 const base::FilePath& profile_directory) { |
| 245 // Get the profile associated with the renderer. | 196 // Get the profile associated with the renderer. |
| 246 Profile* profile = profile_manager_->GetProfileByPath(profile_directory); | 197 Profile* profile = profile_manager_->GetProfileByPath(profile_directory); |
| 247 DCHECK(profile); | 198 DCHECK(profile); |
| 248 scoped_refptr<extensions::InfoMap> extension_info_map = | 199 scoped_refptr<extensions::InfoMap> extension_info_map = |
| 249 extensions::ExtensionSystem::Get(profile)->info_map(); | 200 extensions::ExtensionSystem::Get(profile)->info_map(); |
| 250 DCHECK(extension_info_map.get()); | 201 DCHECK(extension_info_map.get()); |
| 251 return extension_info_map; | 202 return extension_info_map; |
| 252 } | 203 } |
| 253 #endif | 204 #endif |
| OLD | NEW |