This source file includes following definitions.
- OnKeepaliveOnUIThread
- OnKeepalive
- inverse_debug_patterns_
- ShowMissingArchInfobar
- DialogsAreSuppressed
- GetCacheDirectory
- GetPluginDirectory
- GetPnaclDirectory
- GetUserDirectory
- GetVersionString
- CreatePpapiHostFactory
- SetDebugPatterns
- URLMatchesDebugPatterns
- MapUrlToLocalFilePath
- GetOnKeepaliveCallback
#include "chrome/browser/nacl_host/nacl_browser_delegate_impl.h"
#include "base/path_service.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/component_updater/pnacl/pnacl_component_installer.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/nacl_host/nacl_infobar_delegate.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/renderer_host/pepper/chrome_browser_pepper_host_factory.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_paths_internal.h"
#include "chrome/common/chrome_version_info.h"
#include "chrome/common/logging_chrome.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/site_instance.h"
#include "extensions/browser/extension_system.h"
#include "extensions/browser/info_map.h"
#include "extensions/browser/process_manager.h"
#include "extensions/common/constants.h"
#include "extensions/common/extension.h"
#include "extensions/common/manifest_handlers/shared_module_info.h"
#include "extensions/common/url_pattern.h"
#include "ppapi/c/private/ppb_nacl_private.h"
using extensions::SharedModuleInfo;
namespace {
void OnKeepaliveOnUIThread(
const content::BrowserPpapiHost::OnKeepaliveInstanceData& instance_data,
const base::FilePath& profile_data_directory) {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
DCHECK(instance_data.size() == 1);
if (instance_data.size() < 1)
return;
content::RenderFrameHost* render_frame_host =
content::RenderFrameHost::FromID(
instance_data[0].render_process_id, instance_data[0].render_frame_id);
if (!render_frame_host)
return;
content::SiteInstance* site_instance = render_frame_host->GetSiteInstance();
if (!site_instance)
return;
extensions::ExtensionSystem* extension_system =
extensions::ExtensionSystem::Get(site_instance->GetBrowserContext());
if (!extension_system)
return;
const ExtensionService* extension_service =
extension_system->extension_service();
if (!extension_service)
return;
const extensions::Extension* extension = extension_service->GetExtensionById(
instance_data[0].document_url.host(), false);
if (!extension)
return;
extensions::ProcessManager* pm = extension_system->process_manager();
if (!pm)
return;
pm->KeepaliveImpulse(extension);
}
void OnKeepalive(
const content::BrowserPpapiHost::OnKeepaliveInstanceData& instance_data,
const base::FilePath& profile_data_directory) {
DCHECK(!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
base::Bind(&OnKeepaliveOnUIThread,
instance_data,
profile_data_directory));
}
}
NaClBrowserDelegateImpl::NaClBrowserDelegateImpl(
extensions::InfoMap* extension_info_map)
: extension_info_map_(extension_info_map), inverse_debug_patterns_(false) {}
NaClBrowserDelegateImpl::~NaClBrowserDelegateImpl() {
}
void NaClBrowserDelegateImpl::ShowMissingArchInfobar(int render_process_id,
int render_view_id) {
content::BrowserThread::PostTask(
content::BrowserThread::UI, FROM_HERE,
base::Bind(&NaClInfoBarDelegate::Create, render_process_id,
render_view_id));
}
bool NaClBrowserDelegateImpl::DialogsAreSuppressed() {
return logging::DialogsAreSuppressed();
}
bool NaClBrowserDelegateImpl::GetCacheDirectory(base::FilePath* cache_dir) {
base::FilePath user_data_dir;
if (!PathService::Get(chrome::DIR_USER_DATA, &user_data_dir))
return false;
chrome::GetUserCacheDirectory(user_data_dir, cache_dir);
return true;
}
bool NaClBrowserDelegateImpl::GetPluginDirectory(base::FilePath* plugin_dir) {
return PathService::Get(chrome::DIR_INTERNAL_PLUGINS, plugin_dir);
}
bool NaClBrowserDelegateImpl::GetPnaclDirectory(base::FilePath* pnacl_dir) {
return PathService::Get(chrome::DIR_PNACL_COMPONENT, pnacl_dir);
}
bool NaClBrowserDelegateImpl::GetUserDirectory(base::FilePath* user_dir) {
return PathService::Get(chrome::DIR_USER_DATA, user_dir);
}
std::string NaClBrowserDelegateImpl::GetVersionString() const {
return chrome::VersionInfo().CreateVersionString();
}
ppapi::host::HostFactory* NaClBrowserDelegateImpl::CreatePpapiHostFactory(
content::BrowserPpapiHost* ppapi_host) {
return new chrome::ChromeBrowserPepperHostFactory(ppapi_host);
}
void NaClBrowserDelegateImpl::SetDebugPatterns(std::string debug_patterns) {
if (!debug_patterns.empty() && debug_patterns[0] == '!') {
inverse_debug_patterns_ = true;
debug_patterns.erase(0, 1);
}
if (debug_patterns.empty()) {
return;
}
std::vector<std::string> patterns;
base::SplitString(debug_patterns, ',', &patterns);
for (std::vector<std::string>::iterator iter = patterns.begin();
iter != patterns.end(); ++iter) {
URLPattern pattern(URLPattern::SCHEME_ALL);
if (pattern.Parse(*iter) == URLPattern::PARSE_SUCCESS) {
pattern.SetValidSchemes(URLPattern::SCHEME_ALL);
debug_patterns_.push_back(pattern);
}
}
}
bool NaClBrowserDelegateImpl::URLMatchesDebugPatterns(
const GURL& manifest_url) {
if (debug_patterns_.empty()) {
return true;
}
bool matches = false;
for (std::vector<URLPattern>::iterator iter = debug_patterns_.begin();
iter != debug_patterns_.end(); ++iter) {
if (iter->MatchesURL(manifest_url)) {
matches = true;
break;
}
}
if (inverse_debug_patterns_) {
return !matches;
} else {
return matches;
}
}
bool NaClBrowserDelegateImpl::MapUrlToLocalFilePath(
const GURL& file_url, bool use_blocking_api, base::FilePath* file_path) {
DCHECK(extension_info_map_);
const extensions::Extension* extension =
extension_info_map_->extensions().GetExtensionOrAppByURL(file_url);
if (!extension)
return false;
if (!use_blocking_api) {
if (file_url.SchemeIs(extensions::kExtensionScheme)) {
std::string path = file_url.path();
base::TrimString(path, "/", &path);
*file_path = extension->path().AppendASCII(path);
return true;
}
return false;
}
std::string path = file_url.path();
extensions::ExtensionResource resource;
if (SharedModuleInfo::IsImportedPath(path)) {
std::string new_extension_id;
std::string new_relative_path;
SharedModuleInfo::ParseImportedPath(path, &new_extension_id,
&new_relative_path);
const extensions::Extension* new_extension =
extension_info_map_->extensions().GetByID(new_extension_id);
if (!new_extension)
return false;
if (!SharedModuleInfo::ImportsExtensionById(extension, new_extension_id) ||
!SharedModuleInfo::IsExportAllowed(new_extension, new_relative_path)) {
return false;
}
resource = new_extension->GetResource(new_relative_path);
} else {
resource = extension->GetResource(path);
}
if (resource.empty())
return false;
const base::FilePath resource_file_path = resource.GetFilePath();
if (resource_file_path.empty())
return false;
*file_path = resource_file_path;
return true;
}
content::BrowserPpapiHost::OnKeepaliveCallback
NaClBrowserDelegateImpl::GetOnKeepaliveCallback() {
return base::Bind(&OnKeepalive);
}