#include "extensions/shell/browser/shell_nacl_browser_delegate.h"
#include <string>
#include "base/base_paths.h"
#include "base/command_line.h"
#include "base/logging.h"
#include "base/path_service.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "build/build_config.h"
#include "content/public/browser/browser_context.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_registry.h"
#include "extensions/browser/extension_system.h"
#include "extensions/browser/process_manager.h"
#include "extensions/common/constants.h"
#include "extensions/common/extension.h"
#include "extensions/common/url_pattern.h"
#include "extensions/shell/common/version.h"
#include "url/gurl.h"
using content::BrowserContext;
using content::BrowserThread;
using content::BrowserPpapiHost;
namespace extensions {
ShellNaClBrowserDelegate::ShellNaClBrowserDelegate(BrowserContext* context)
: browser_context_(context) {
DCHECK(browser_context_);
}
ShellNaClBrowserDelegate::~ShellNaClBrowserDelegate() {
}
void ShellNaClBrowserDelegate::ShowMissingArchInfobar(int render_process_id,
int render_frame_id) {
LOG(ERROR) << "Missing architecture for pid " << render_process_id;
}
bool ShellNaClBrowserDelegate::DialogsAreSuppressed() {
return false;
}
bool ShellNaClBrowserDelegate::GetCacheDirectory(base::FilePath* cache_dir) {
#if BUILDFLAG(IS_POSIX)
return base::PathService::Get(base::DIR_CACHE, cache_dir);
#elif BUILDFLAG(IS_WIN)
return base::PathService::Get(base::DIR_TEMP, cache_dir);
#endif
}
bool ShellNaClBrowserDelegate::GetPluginDirectory(base::FilePath* plugin_dir) {
return base::PathService::Get(base::DIR_MODULE, plugin_dir);
}
bool ShellNaClBrowserDelegate::GetPnaclDirectory(base::FilePath* pnacl_dir) {
base::FilePath plugin_dir;
if (!GetPluginDirectory(&plugin_dir))
return false;
*pnacl_dir = plugin_dir.Append(FILE_PATH_LITERAL("pnacl"));
return true;
}
bool ShellNaClBrowserDelegate::GetUserDirectory(base::FilePath* user_dir) {
base::FilePath path = browser_context_->GetPath();
if (!path.empty()) {
*user_dir = path;
return true;
}
return false;
}
std::string ShellNaClBrowserDelegate::GetVersionString() const {
return PRODUCT_VERSION " (" LAST_CHANGE ")";
}
ppapi::host::HostFactory* ShellNaClBrowserDelegate::CreatePpapiHostFactory(
content::BrowserPpapiHost* ppapi_host) {
return NULL;
}
void ShellNaClBrowserDelegate::SetDebugPatterns(
const std::string& debug_patterns) {
}
bool ShellNaClBrowserDelegate::URLMatchesDebugPatterns(
const GURL& manifest_url) {
return false;
}
NaClBrowserDelegate::MapUrlToLocalFilePathCallback
ShellNaClBrowserDelegate::GetMapUrlToLocalFilePathCallback(
const base::FilePath& profile_directory) {
auto extensions = std::make_unique<ExtensionSet>();
extensions->InsertAll(
ExtensionRegistry::Get(browser_context_)->enabled_extensions());
return base::BindRepeating(
[](const ExtensionSet* extensions, const GURL& file_url,
bool use_blocking_api, base::FilePath* file_path) {
const Extension* extension =
extensions->GetExtensionOrAppByURL(file_url);
if (!extension)
return false;
if (!use_blocking_api) {
if (file_url.SchemeIs(kExtensionScheme)
#if defined(OHOS_ARKWEB_EXTENSIONS)
|| file_url.SchemeIs(kArkwebExtensionScheme)
#endif
) {
std::string path = file_url.path();
base::TrimString(path, "/", &path);
*file_path = extension->path().AppendASCII(path);
return true;
}
return false;
}
ExtensionResource resource = extension->GetResource(file_url.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;
},
base::Owned(std::move(extensions)));
}
}