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_system.h" | 13 #include "chrome/browser/extensions/extension_system.h" |
13 #include "chrome/browser/nacl_host/nacl_infobar_delegate.h" | 14 #include "chrome/browser/nacl_host/nacl_infobar_delegate.h" |
| 15 #include "chrome/browser/profiles/profile.h" |
14 #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" |
15 #include "chrome/common/chrome_paths.h" | 17 #include "chrome/common/chrome_paths.h" |
16 #include "chrome/common/chrome_paths_internal.h" | 18 #include "chrome/common/chrome_paths_internal.h" |
17 #include "chrome/common/chrome_version_info.h" | 19 #include "chrome/common/chrome_version_info.h" |
18 #include "chrome/common/logging_chrome.h" | 20 #include "chrome/common/logging_chrome.h" |
19 #include "content/public/browser/browser_thread.h" | 21 #include "content/public/browser/browser_thread.h" |
| 22 #include "content/public/browser/render_view_host.h" |
| 23 #include "content/public/browser/site_instance.h" |
20 #include "extensions/browser/info_map.h" | 24 #include "extensions/browser/info_map.h" |
| 25 #include "extensions/browser/process_manager.h" |
21 #include "extensions/common/constants.h" | 26 #include "extensions/common/constants.h" |
22 #include "extensions/common/extension.h" | 27 #include "extensions/common/extension.h" |
23 #include "extensions/common/manifest_handlers/shared_module_info.h" | 28 #include "extensions/common/manifest_handlers/shared_module_info.h" |
24 #include "extensions/common/url_pattern.h" | 29 #include "extensions/common/url_pattern.h" |
25 #include "ppapi/c/private/ppb_nacl_private.h" | 30 #include "ppapi/c/private/ppb_nacl_private.h" |
26 | 31 |
27 using extensions::SharedModuleInfo; | 32 using extensions::SharedModuleInfo; |
28 | 33 |
| 34 namespace { |
| 35 |
| 36 // Handles an extension's NaCl process transitioning in or out of idle state by |
| 37 // relaying the state to the extension's process manager. |
| 38 // |
| 39 // A NaCl instance, when active (making PPAPI calls or receiving callbacks), |
| 40 // sends keepalive IPCs to the browser process BrowserPpapiHost at a throttled |
| 41 // rate. The content::BrowserPpapiHost passes context information up to the |
| 42 // chrome level NaClProcessHost where we use the instance's context to find the |
| 43 // associated extension process manager. |
| 44 // |
| 45 // There is a 1:many relationship for extension:nacl-embeds, but only a |
| 46 // 1:1 relationship for NaClProcessHost:PP_Instance. The content layer doesn't |
| 47 // rely on this knowledge because it routes messages for ppapi non-nacl |
| 48 // instances as well, though they won't have callbacks set. Here the 1:1 |
| 49 // assumption is made and DCHECKed. |
| 50 void OnKeepaliveOnUIThread( |
| 51 const content::BrowserPpapiHost::OnKeepaliveInstanceData& instance_data, |
| 52 const base::FilePath& profile_data_directory) { |
| 53 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 54 |
| 55 // Only one instance will exist for NaCl embeds, even when more than one |
| 56 // embed of the same plugin exists on the same page. |
| 57 DCHECK(instance_data.size() == 1); |
| 58 if (instance_data.size() < 1) |
| 59 return; |
| 60 |
| 61 content::RenderViewHost* render_view_host = content::RenderViewHost::FromID( |
| 62 instance_data[0].render_process_id, instance_data[0].render_view_id); |
| 63 if (!render_view_host) |
| 64 return; |
| 65 |
| 66 content::SiteInstance* site_instance = render_view_host->GetSiteInstance(); |
| 67 if (!site_instance) |
| 68 return; |
| 69 |
| 70 extensions::ExtensionSystem* extension_system = |
| 71 extensions::ExtensionSystem::GetForBrowserContext( |
| 72 site_instance->GetBrowserContext()); |
| 73 if (!extension_system) |
| 74 return; |
| 75 |
| 76 const ExtensionService* extension_service = |
| 77 extension_system->extension_service(); |
| 78 if (!extension_service) |
| 79 return; |
| 80 |
| 81 const extensions::Extension* extension = extension_service->GetExtensionById( |
| 82 instance_data[0].document_url.host(), false); |
| 83 if (!extension) |
| 84 return; |
| 85 |
| 86 extensions::ProcessManager* pm = extension_system->process_manager(); |
| 87 if (!pm) |
| 88 return; |
| 89 |
| 90 pm->KeepaliveImpulse(extension); |
| 91 } |
| 92 |
| 93 // Calls OnKeepaliveOnUIThread on UI thread. |
| 94 void OnKeepalive( |
| 95 const content::BrowserPpapiHost::OnKeepaliveInstanceData& instance_data, |
| 96 const base::FilePath& profile_data_directory) { |
| 97 DCHECK(!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 98 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, |
| 99 base::Bind(&OnKeepaliveOnUIThread, |
| 100 instance_data, |
| 101 profile_data_directory)); |
| 102 } |
| 103 |
| 104 } // namespace |
| 105 |
29 NaClBrowserDelegateImpl::NaClBrowserDelegateImpl( | 106 NaClBrowserDelegateImpl::NaClBrowserDelegateImpl( |
30 extensions::InfoMap* extension_info_map) | 107 extensions::InfoMap* extension_info_map) |
31 : extension_info_map_(extension_info_map), inverse_debug_patterns_(false) {} | 108 : extension_info_map_(extension_info_map), inverse_debug_patterns_(false) {} |
32 | 109 |
33 NaClBrowserDelegateImpl::~NaClBrowserDelegateImpl() { | 110 NaClBrowserDelegateImpl::~NaClBrowserDelegateImpl() { |
34 } | 111 } |
35 | 112 |
36 void NaClBrowserDelegateImpl::ShowNaClInfobar(int render_process_id, | 113 void NaClBrowserDelegateImpl::ShowNaClInfobar(int render_process_id, |
37 int render_view_id, | 114 int render_view_id, |
38 int error_id) { | 115 int error_id) { |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 return false; | 251 return false; |
175 | 252 |
176 // GetFilePath is a blocking function call. | 253 // GetFilePath is a blocking function call. |
177 const base::FilePath resource_file_path = resource.GetFilePath(); | 254 const base::FilePath resource_file_path = resource.GetFilePath(); |
178 if (resource_file_path.empty()) | 255 if (resource_file_path.empty()) |
179 return false; | 256 return false; |
180 | 257 |
181 *file_path = resource_file_path; | 258 *file_path = resource_file_path; |
182 return true; | 259 return true; |
183 } | 260 } |
| 261 |
| 262 content::BrowserPpapiHost::OnKeepaliveCallback |
| 263 NaClBrowserDelegateImpl::GetOnKeepaliveCallback() { |
| 264 return base::Bind(&OnKeepalive); |
| 265 } |
OLD | NEW |