Unfork chome code related to extensions and pepper plugins (issue #1947)

This commit is contained in:
Marshall Greenblatt 2016-08-04 15:37:53 +03:00
parent 98f59f47fd
commit 5444c389fd
21 changed files with 175 additions and 710 deletions

View File

@ -275,8 +275,6 @@ static_library("libcef_static") {
"libcef/browser/extensions/pdf_extension_util.h",
"libcef/browser/extensions/pdf_web_contents_helper_client.cc",
"libcef/browser/extensions/pdf_web_contents_helper_client.h",
"libcef/browser/extensions/url_request_util.cc",
"libcef/browser/extensions/url_request_util.h",
"libcef/browser/file_dialog_runner.h",
"libcef/browser/file_dialog_manager.cc",
"libcef/browser/file_dialog_manager.h",
@ -348,10 +346,6 @@ static_library("libcef_static") {
"libcef/browser/path_util_impl.cc",
"libcef/browser/pepper/browser_pepper_host_factory.cc",
"libcef/browser/pepper/browser_pepper_host_factory.h",
"libcef/browser/pepper/pepper_flash_browser_host.cc",
"libcef/browser/pepper/pepper_flash_browser_host.h",
"libcef/browser/pepper/pepper_isolated_file_system_message_filter.cc",
"libcef/browser/pepper/pepper_isolated_file_system_message_filter.h",
"libcef/browser/permissions/permission_context.cc",
"libcef/browser/permissions/permission_context.h",
"libcef/browser/permissions/permission_manager.cc",

View File

@ -1112,8 +1112,6 @@
'libcef/browser/extensions/pdf_extension_util.h',
'libcef/browser/extensions/pdf_web_contents_helper_client.cc',
'libcef/browser/extensions/pdf_web_contents_helper_client.h',
'libcef/browser/extensions/url_request_util.cc',
'libcef/browser/extensions/url_request_util.h',
'libcef/browser/file_dialog_runner.h',
'libcef/browser/file_dialog_manager.cc',
'libcef/browser/file_dialog_manager.h',
@ -1185,10 +1183,6 @@
'libcef/browser/path_util_impl.cc',
'libcef/browser/pepper/browser_pepper_host_factory.cc',
'libcef/browser/pepper/browser_pepper_host_factory.h',
'libcef/browser/pepper/pepper_flash_browser_host.cc',
'libcef/browser/pepper/pepper_flash_browser_host.h',
'libcef/browser/pepper/pepper_isolated_file_system_message_filter.cc',
'libcef/browser/pepper/pepper_isolated_file_system_message_filter.h',
'libcef/browser/permissions/permission_context.cc',
'libcef/browser/permissions/permission_context.h',
'libcef/browser/permissions/permission_manager.cc',

View File

@ -85,6 +85,9 @@ void CefBrowserContext::CreateProtocolHandlers(
void CefBrowserContext::Shutdown() {
CEF_REQUIRE_UIT();
// Send notifications to clean up objects associated with this Profile.
MaybeSendDestroyedNotification();
if (resource_context_.get()) {
// Destruction of the ResourceContext will trigger destruction of all
// associated URLRequests.

View File

@ -245,10 +245,8 @@ void CefBrowserContextImpl::Initialize() {
}
// Initialize preferences.
base::FilePath pref_path;
if (!cache_path_.empty() && settings_.persist_user_preferences)
pref_path = cache_path_.AppendASCII(browser_prefs::kUserPrefsFileName);
pref_service_ = browser_prefs::CreatePrefService(pref_path);
pref_service_ = browser_prefs::CreatePrefService(
this, cache_path_, !!settings_.persist_user_preferences);
// Initialize visited links management.
base::FilePath visited_link_path;

View File

@ -5,6 +5,7 @@
#include "libcef/browser/chrome_browser_process_stub.h"
#include "libcef/browser/browser_context_impl.h"
#include "libcef/browser/chrome_profile_manager_stub.h"
#include "libcef/browser/component_updater/cef_component_updater_configurator.h"
#include "libcef/browser/content_browser_client.h"
@ -37,11 +38,13 @@ ChromeBrowserProcessStub::ChromeBrowserProcessStub()
: initialized_(false),
shutdown_(false),
locale_("en-US") {
chrome::SetBrowserContextIncognitoHelper(this);
}
ChromeBrowserProcessStub::~ChromeBrowserProcessStub() {
DCHECK(!initialized_ || shutdown_);
g_browser_process = NULL;
chrome::SetBrowserContextIncognitoHelper(nullptr);
}
void ChromeBrowserProcessStub::Initialize() {
@ -355,3 +358,15 @@ memory::TabManager* ChromeBrowserProcessStub::GetTabManager() {
NOTIMPLEMENTED();
return NULL;
}
content::BrowserContext*
ChromeBrowserProcessStub::GetBrowserContextRedirectedInIncognito(
content::BrowserContext* context) {
return CefBrowserContextImpl::GetForContext(context).get();
}
content::BrowserContext*
ChromeBrowserProcessStub::GetBrowserContextOwnInstanceInIncognito(
content::BrowserContext* context) {
return GetBrowserContextRedirectedInIncognito(context);
}

View File

@ -14,6 +14,7 @@
#include "chrome/browser/browser_process.h"
#include "chrome/browser/extensions/event_router_forwarder.h"
#include "chrome/browser/profiles/incognito_helpers.h"
#include "base/compiler_specific.h"
namespace component_updater {
@ -30,7 +31,8 @@ class BackgroundModeManager {
DISALLOW_COPY_AND_ASSIGN(BackgroundModeManager);
};
class ChromeBrowserProcessStub : public BrowserProcess {
class ChromeBrowserProcessStub : public BrowserProcess,
public chrome::BrowserContextIncognitoHelper {
public:
ChromeBrowserProcessStub();
~ChromeBrowserProcessStub() override;
@ -110,6 +112,12 @@ class ChromeBrowserProcessStub : public BrowserProcess {
CachedDefaultWebClientState() override;
memory::TabManager* GetTabManager() override;
// BrowserContextIncognitoHelper implementation.
content::BrowserContext* GetBrowserContextRedirectedInIncognito(
content::BrowserContext* context) override;
content::BrowserContext* GetBrowserContextOwnInstanceInIncognito(
content::BrowserContext* context) override;
private:
bool initialized_;
bool shutdown_;

View File

@ -14,6 +14,14 @@ ChromeProfileManagerStub::ChromeProfileManagerStub()
ChromeProfileManagerStub::~ChromeProfileManagerStub() {
}
Profile* ChromeProfileManagerStub::GetProfile(
const base::FilePath& profile_dir) {
scoped_refptr<CefBrowserContextImpl> browser_context =
CefBrowserContextImpl::GetForCachePath(profile_dir);
DCHECK(browser_context);
return browser_context.get();
}
bool ChromeProfileManagerStub::IsValidProfile(const void* profile) {
if (!profile)
return false;

View File

@ -16,6 +16,7 @@ class ChromeProfileManagerStub : public ProfileManager {
ChromeProfileManagerStub();
~ChromeProfileManagerStub() override;
Profile* GetProfile(const base::FilePath& profile_dir) override;
bool IsValidProfile(const void* profile) override;
private:

View File

@ -4,6 +4,7 @@
#include "libcef/browser/extensions/browser_context_keyed_service_factories.h"
#include "chrome/browser/content_settings/cookie_settings_factory.h"
#include "chrome/browser/extensions/api/streams_private/streams_private_api.h"
#include "chrome/browser/ui/prefs/prefs_tab_helper.h"
#include "extensions/browser/renderer_startup_helper.h"
@ -12,6 +13,7 @@ namespace extensions {
namespace cef {
void EnsureBrowserContextKeyedServiceFactoriesBuilt() {
CookieSettingsFactory::GetInstance();
PrefsTabHelper::GetServiceInstance();
RendererStartupHelperFactory::GetInstance();
StreamsPrivateAPI::GetFactoryInstance();

View File

@ -13,10 +13,10 @@
#include "libcef/browser/extensions/extension_system_factory.h"
#include "libcef/browser/extensions/extension_web_contents_observer.h"
#include "libcef/browser/extensions/extensions_api_client.h"
#include "libcef/browser/extensions/url_request_util.h"
//#include "cef/libcef/browser/extensions/api/generated_api_registration.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/extensions/chrome_url_request_util.h"
#include "chrome/browser/extensions/event_router_forwarder.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_thread.h"
@ -104,7 +104,7 @@ CefExtensionsBrowserClient::MaybeCreateResourceBundleRequestJob(
const base::FilePath& directory_path,
const std::string& content_security_policy,
bool send_cors_header) {
return url_request_util::MaybeCreateURLRequestResourceBundleJob(
return chrome_url_request_util::MaybeCreateURLRequestResourceBundleJob(
request,
network_delegate,
directory_path,

View File

@ -1,166 +0,0 @@
// Copyright 2015 The Chromium Embedded Framework Authors.
// Portions copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "libcef/browser/extensions/url_request_util.h"
#include <string>
#include "base/files/file_path.h"
#include "base/memory/weak_ptr.h"
#include "base/path_service.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/task_runner_util.h"
#include "chrome/common/chrome_paths.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/resource_request_info.h"
#include "extensions/browser/component_extension_resource_manager.h"
#include "extensions/browser/extension_protocols.h"
#include "extensions/browser/extensions_browser_client.h"
#include "extensions/browser/info_map.h"
#include "extensions/browser/url_request_util.h"
#include "extensions/common/file_util.h"
#include "net/base/mime_util.h"
#include "net/base/net_errors.h"
#include "net/http/http_request_headers.h"
#include "net/http/http_response_headers.h"
#include "net/http/http_response_info.h"
#include "net/url_request/url_request.h"
#include "net/url_request/url_request_simple_job.h"
#include "ui/base/resource/resource_bundle.h"
using content::BrowserThread;
using content::ResourceType;
using extensions::ExtensionsBrowserClient;
namespace {
// A request for an extension resource in a Chrome .pak file. These are used
// by component extensions.
class URLRequestResourceBundleJob : public net::URLRequestSimpleJob {
public:
URLRequestResourceBundleJob(net::URLRequest* request,
net::NetworkDelegate* network_delegate,
const base::FilePath& filename,
int resource_id,
const std::string& content_security_policy,
bool send_cors_header)
: net::URLRequestSimpleJob(request, network_delegate),
filename_(filename),
resource_id_(resource_id),
weak_factory_(this) {
// Leave cache headers out of resource bundle requests.
response_info_.headers = extensions::BuildHttpHeaders(
content_security_policy, send_cors_header, base::Time());
}
// Overridden from URLRequestSimpleJob:
int GetRefCountedData(
std::string* mime_type,
std::string* charset,
scoped_refptr<base::RefCountedMemory>* data,
const net::CompletionCallback& callback) const override {
const ResourceBundle& rb = ResourceBundle::GetSharedInstance();
*data = rb.LoadDataResourceBytes(resource_id_);
// Add the Content-Length header now that we know the resource length.
response_info_.headers->AddHeader(
base::StringPrintf("%s: %s", net::HttpRequestHeaders::kContentLength,
base::UintToString((*data)->size()).c_str()));
std::string* read_mime_type = new std::string;
bool posted = base::PostTaskAndReplyWithResult(
BrowserThread::GetBlockingPool(), FROM_HERE,
base::Bind(&net::GetMimeTypeFromFile, filename_,
base::Unretained(read_mime_type)),
base::Bind(&URLRequestResourceBundleJob::OnMimeTypeRead,
weak_factory_.GetWeakPtr(), mime_type, charset, *data,
base::Owned(read_mime_type), callback));
DCHECK(posted);
return net::ERR_IO_PENDING;
}
void GetResponseInfo(net::HttpResponseInfo* info) override {
*info = response_info_;
}
private:
~URLRequestResourceBundleJob() override {}
void OnMimeTypeRead(std::string* out_mime_type,
std::string* charset,
scoped_refptr<base::RefCountedMemory> data,
std::string* read_mime_type,
const net::CompletionCallback& callback,
bool read_result) {
*out_mime_type = *read_mime_type;
if (base::StartsWith(*read_mime_type, "text/",
base::CompareCase::INSENSITIVE_ASCII)) {
// All of our HTML files should be UTF-8 and for other resource types
// (like images), charset doesn't matter.
DCHECK(base::IsStringUTF8(base::StringPiece(
reinterpret_cast<const char*>(data->front()), data->size())));
*charset = "utf-8";
}
int result = read_result ? net::OK : net::ERR_INVALID_URL;
callback.Run(result);
}
// We need the filename of the resource to determine the mime type.
base::FilePath filename_;
// The resource bundle id to load.
int resource_id_;
net::HttpResponseInfo response_info_;
mutable base::WeakPtrFactory<URLRequestResourceBundleJob> weak_factory_;
};
} // namespace
namespace extensions {
namespace url_request_util {
net::URLRequestJob* MaybeCreateURLRequestResourceBundleJob(
net::URLRequest* request,
net::NetworkDelegate* network_delegate,
const base::FilePath& directory_path,
const std::string& content_security_policy,
bool send_cors_header) {
base::FilePath resources_path;
base::FilePath relative_path;
// Try to load extension resources from chrome resource file if
// directory_path is a descendant of resources_path. This path structure is
// set up by CefExtensionSystem::ComponentExtensionInfo.
if (PathService::Get(chrome::DIR_RESOURCES, &resources_path) &&
// Since component extension resources are included in
// component_extension_resources.pak file in resources_path, calculate
// extension relative path against resources_path.
resources_path.AppendRelativePath(directory_path, &relative_path)) {
base::FilePath request_path =
extensions::file_util::ExtensionURLToRelativeFilePath(request->url());
int resource_id = 0;
if (ExtensionsBrowserClient::Get()
->GetComponentExtensionResourceManager()
->IsComponentExtensionResource(
directory_path, request_path, &resource_id)) {
relative_path = relative_path.Append(request_path);
relative_path = relative_path.NormalizePathSeparators();
return new URLRequestResourceBundleJob(request,
network_delegate,
relative_path,
resource_id,
content_security_policy,
send_cors_header);
}
}
return NULL;
}
} // namespace url_request_util
} // namespace extensions

View File

@ -1,42 +0,0 @@
// Copyright 2015 The Chromium Embedded Framework Authors.
// Portions copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CEF_LIBCEF_BROWSER_EXTENSIONS_URL_REQUEST_UTIL_H_
#define CEF_LIBCEF_BROWSER_EXTENSIONS_URL_REQUEST_UTIL_H_
#include <string>
namespace base {
class FilePath;
}
namespace net {
class NetworkDelegate;
class URLRequest;
class URLRequestJob;
}
namespace extensions {
class Extension;
class InfoMap;
// Utilities related to URLRequest jobs for extension resources. Based on
// chrome/browser/extensions/chrome_url_request_util.cc.
namespace url_request_util {
// Creates a URLRequestJob for loading component extension resources out of
// a CEF resource bundle. Returns NULL if the requested resource is not a
// component extension resource.
net::URLRequestJob* MaybeCreateURLRequestResourceBundleJob(
net::URLRequest* request,
net::NetworkDelegate* network_delegate,
const base::FilePath& directory_path,
const std::string& content_security_policy,
bool send_cors_header);
} // namespace url_request_util
} // namespace extensions
#endif // CEF_LIBCEF_BROWSER_EXTENSIONS_URL_REQUEST_UTIL_H_

View File

@ -4,12 +4,11 @@
#include "libcef/browser/pepper/browser_pepper_host_factory.h"
#include "libcef/browser/pepper/pepper_flash_browser_host.h"
#include "libcef/browser/pepper/pepper_isolated_file_system_message_filter.h"
#include "build/build_config.h"
#include "chrome/browser/renderer_host/pepper/pepper_flash_browser_host.h"
#include "chrome/browser/renderer_host/pepper/pepper_flash_clipboard_message_filter.h"
#include "chrome/browser/renderer_host/pepper/pepper_flash_drm_host.h"
#include "chrome/browser/renderer_host/pepper/pepper_isolated_file_system_message_filter.h"
#include "content/public/browser/browser_ppapi_host.h"
#include "ppapi/host/message_filter_host.h"
#include "ppapi/host/ppapi_host.h"
@ -44,7 +43,7 @@ std::unique_ptr<ResourceHost> CefBrowserPepperHostFactory::CreateResourceHost(
switch (message.type()) {
case PpapiHostMsg_Flash_Create::ID:
return std::unique_ptr<ResourceHost>(
new PepperFlashBrowserHost(host_, instance, resource));
new chrome::PepperFlashBrowserHost(host_, instance, resource));
case PpapiHostMsg_FlashClipboard_Create::ID: {
scoped_refptr<ResourceMessageFilter> clipboard_filter(
new chrome::PepperFlashClipboardMessageFilter);
@ -64,8 +63,8 @@ std::unique_ptr<ResourceHost> CefBrowserPepperHostFactory::CreateResourceHost(
// whitelisted apps which may not have access to the other private
// interfaces.
if (message.type() == PpapiHostMsg_IsolatedFileSystem_Create::ID) {
PepperIsolatedFileSystemMessageFilter* isolated_fs_filter =
PepperIsolatedFileSystemMessageFilter::Create(instance, host_);
chrome::PepperIsolatedFileSystemMessageFilter* isolated_fs_filter =
chrome::PepperIsolatedFileSystemMessageFilter::Create(instance, host_);
if (!isolated_fs_filter)
return std::unique_ptr<ResourceHost>();
return std::unique_ptr<ResourceHost>(

View File

@ -1,135 +0,0 @@
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "libcef/browser/pepper/pepper_flash_browser_host.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_ppapi_host.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/render_process_host.h"
#include "ipc/ipc_message_macros.h"
#include "ppapi/c/pp_errors.h"
#include "ppapi/c/private/ppb_flash.h"
#include "ppapi/host/dispatch_host_message.h"
#include "ppapi/proxy/ppapi_messages.h"
#include "ppapi/proxy/resource_message_params.h"
#include "ppapi/shared_impl/time_conversion.h"
#include "url/gurl.h"
#if defined(OS_WIN)
#include <windows.h>
#elif defined(OS_MACOSX)
#include <CoreServices/CoreServices.h>
#endif
using content::BrowserPpapiHost;
using content::BrowserThread;
using content::RenderProcessHost;
namespace {
// Returns true if the page identified by (|url|, |first_party_url|) is allowed
// to read cookies.
bool IsReadingCookieAllowed(const GURL& url,
const GURL& first_party_url) {
return true;
}
// Returns true if the cookie set by a page identified by |url| should be
// session only.
bool IsCookieSessionOnly(const GURL& url) {
return false;
}
} // namespace
PepperFlashBrowserHost::PepperFlashBrowserHost(BrowserPpapiHost* host,
PP_Instance instance,
PP_Resource resource)
: ResourceHost(host->GetPpapiHost(), instance, resource),
host_(host) {
int unused;
host->GetRenderFrameIDsForInstance(instance, &render_process_id_, &unused);
}
PepperFlashBrowserHost::~PepperFlashBrowserHost() {}
int32_t PepperFlashBrowserHost::OnResourceMessageReceived(
const IPC::Message& msg,
ppapi::host::HostMessageContext* context) {
PPAPI_BEGIN_MESSAGE_MAP(PepperFlashBrowserHost, msg)
PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_Flash_UpdateActivity,
OnUpdateActivity)
PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_Flash_GetLocalTimeZoneOffset,
OnGetLocalTimeZoneOffset)
PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(
PpapiHostMsg_Flash_GetLocalDataRestrictions, OnGetLocalDataRestrictions)
PPAPI_END_MESSAGE_MAP()
return PP_ERROR_FAILED;
}
int32_t PepperFlashBrowserHost::OnUpdateActivity(
ppapi::host::HostMessageContext* host_context) {
#if defined(OS_WIN)
// Reading then writing back the same value to the screensaver timeout system
// setting resets the countdown which prevents the screensaver from turning
// on "for a while". As long as the plugin pings us with this message faster
// than the screensaver timeout, it won't go on.
int value = 0;
if (SystemParametersInfo(SPI_GETSCREENSAVETIMEOUT, 0, &value, 0))
SystemParametersInfo(SPI_SETSCREENSAVETIMEOUT, value, NULL, 0);
#elif defined(OS_MACOSX)
UpdateSystemActivity(OverallAct);
#else
// TODO(brettw) implement this for other platforms.
#endif
return PP_OK;
}
int32_t PepperFlashBrowserHost::OnGetLocalTimeZoneOffset(
ppapi::host::HostMessageContext* host_context,
const base::Time& t) {
// The reason for this processing being in the browser process is that on
// Linux, the localtime calls require filesystem access prohibited by the
// sandbox.
host_context->reply_msg = PpapiPluginMsg_Flash_GetLocalTimeZoneOffsetReply(
ppapi::PPGetLocalTimeZoneOffset(t));
return PP_OK;
}
int32_t PepperFlashBrowserHost::OnGetLocalDataRestrictions(
ppapi::host::HostMessageContext* context) {
// Getting the Flash LSO settings requires using the CookieSettings which
// belong to the profile which lives on the UI thread. We lazily initialize
// |cookie_settings_| by grabbing the reference from the UI thread and then
// call |GetLocalDataRestrictions| with it.
GURL document_url = host_->GetDocumentURLForInstance(pp_instance());
GURL plugin_url = host_->GetPluginURLForInstance(pp_instance());
GetLocalDataRestrictions(context->MakeReplyMessageContext(),
document_url,
plugin_url);
return PP_OK_COMPLETIONPENDING;
}
void PepperFlashBrowserHost::GetLocalDataRestrictions(
ppapi::host::ReplyMessageContext reply_context,
const GURL& document_url,
const GURL& plugin_url) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
PP_FlashLSORestrictions restrictions = PP_FLASHLSORESTRICTIONS_NONE;
if (document_url.is_valid() && plugin_url.is_valid()) {
// TODO(cef): Determine how to properly handle these permissions. In Chrome
// they're handled via CookieSettings associated with a Profile.
if (!IsReadingCookieAllowed(document_url, plugin_url))
restrictions = PP_FLASHLSORESTRICTIONS_BLOCK;
else if (IsCookieSessionOnly(plugin_url))
restrictions = PP_FLASHLSORESTRICTIONS_IN_MEMORY;
}
SendReply(reply_context,
PpapiPluginMsg_Flash_GetLocalDataRestrictionsReply(
static_cast<int32_t>(restrictions)));
}

View File

@ -1,56 +0,0 @@
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CEF_LIBCEF_BROWSER_PEPPER_PEPPER_FLASH_BROWSER_HOST_H_
#define CEF_LIBCEF_BROWSER_PEPPER_PEPPER_FLASH_BROWSER_HOST_H_
#include <stdint.h>
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
#include "ppapi/host/host_message_context.h"
#include "ppapi/host/resource_host.h"
namespace base {
class Time;
}
namespace content {
class BrowserPpapiHost;
class ResourceContext;
}
class GURL;
class PepperFlashBrowserHost : public ppapi::host::ResourceHost {
public:
PepperFlashBrowserHost(content::BrowserPpapiHost* host,
PP_Instance instance,
PP_Resource resource);
~PepperFlashBrowserHost() override;
// ppapi::host::ResourceHost override.
int32_t OnResourceMessageReceived(
const IPC::Message& msg,
ppapi::host::HostMessageContext* context) override;
private:
int32_t OnUpdateActivity(ppapi::host::HostMessageContext* host_context);
int32_t OnGetLocalTimeZoneOffset(
ppapi::host::HostMessageContext* host_context,
const base::Time& t);
int32_t OnGetLocalDataRestrictions(ppapi::host::HostMessageContext* context);
void GetLocalDataRestrictions(ppapi::host::ReplyMessageContext reply_context,
const GURL& document_url,
const GURL& plugin_url);
content::BrowserPpapiHost* host_;
int render_process_id_;
DISALLOW_COPY_AND_ASSIGN(PepperFlashBrowserHost);
};
#endif // CEF_LIBCEF_BROWSER_PEPPER_PEPPER_FLASH_BROWSER_HOST_H_

View File

@ -1,194 +0,0 @@
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "libcef/browser/pepper/pepper_isolated_file_system_message_filter.h"
#include <stddef.h>
#include "libcef/browser/browser_context_impl.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pepper_permission_util.h"
#include "content/public/browser/browser_ppapi_host.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/child_process_security_policy.h"
#include "content/public/browser/render_view_host.h"
#if defined(ENABLE_EXTENSIONS)
#include "extensions/browser/extension_registry.h"
#include "extensions/common/constants.h"
#include "extensions/common/extension.h"
#include "extensions/common/extension_set.h"
#endif
#include "ppapi/c/pp_errors.h"
#include "ppapi/host/dispatch_host_message.h"
#include "ppapi/host/host_message_context.h"
#include "ppapi/host/ppapi_host.h"
#include "ppapi/proxy/ppapi_messages.h"
#include "ppapi/shared_impl/file_system_util.h"
#include "storage/browser/fileapi/isolated_context.h"
namespace {
const char* kPredefinedAllowedCrxFsOrigins[] = {
"6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see crbug.com/234789
"4EB74897CB187C7633357C2FE832E0AD6A44883A" // see crbug.com/234789
};
} // namespace
// static
PepperIsolatedFileSystemMessageFilter*
PepperIsolatedFileSystemMessageFilter::Create(PP_Instance instance,
content::BrowserPpapiHost* host) {
int render_process_id;
int unused_render_frame_id;
if (!host->GetRenderFrameIDsForInstance(
instance, &render_process_id, &unused_render_frame_id)) {
return NULL;
}
return new PepperIsolatedFileSystemMessageFilter(
render_process_id,
host->GetProfileDataDirectory(),
host->GetDocumentURLForInstance(instance),
host->GetPpapiHost());
}
PepperIsolatedFileSystemMessageFilter::PepperIsolatedFileSystemMessageFilter(
int render_process_id,
const base::FilePath& profile_directory,
const GURL& document_url,
ppapi::host::PpapiHost* ppapi_host)
: render_process_id_(render_process_id),
profile_directory_(profile_directory),
document_url_(document_url),
ppapi_host_(ppapi_host) {
for (size_t i = 0; i < arraysize(kPredefinedAllowedCrxFsOrigins); ++i)
allowed_crxfs_origins_.insert(kPredefinedAllowedCrxFsOrigins[i]);
}
PepperIsolatedFileSystemMessageFilter::
~PepperIsolatedFileSystemMessageFilter() {}
scoped_refptr<base::TaskRunner>
PepperIsolatedFileSystemMessageFilter::OverrideTaskRunnerForMessage(
const IPC::Message& msg) {
// In order to reach ExtensionSystem, we need to get ProfileManager first.
// ProfileManager lives in UI thread, so we need to do this in UI thread.
return content::BrowserThread::GetTaskRunnerForThread(
content::BrowserThread::UI);
}
int32_t PepperIsolatedFileSystemMessageFilter::OnResourceMessageReceived(
const IPC::Message& msg,
ppapi::host::HostMessageContext* context) {
PPAPI_BEGIN_MESSAGE_MAP(PepperIsolatedFileSystemMessageFilter, msg)
PPAPI_DISPATCH_HOST_RESOURCE_CALL(
PpapiHostMsg_IsolatedFileSystem_BrowserOpen,
OnOpenFileSystem)
PPAPI_END_MESSAGE_MAP()
return PP_ERROR_FAILED;
}
std::string PepperIsolatedFileSystemMessageFilter::CreateCrxFileSystem(
content::BrowserContext* profile) {
#if defined(ENABLE_EXTENSIONS)
const extensions::Extension* extension =
extensions::ExtensionRegistry::Get(profile)->enabled_extensions().GetByID(
document_url_.host());
if (!extension)
return std::string();
// First level directory for isolated filesystem to lookup.
std::string kFirstLevelDirectory("crxfs");
return storage::IsolatedContext::GetInstance()->RegisterFileSystemForPath(
storage::kFileSystemTypeNativeLocal,
std::string(),
extension->path(),
&kFirstLevelDirectory);
#else
return std::string();
#endif
}
int32_t PepperIsolatedFileSystemMessageFilter::OnOpenFileSystem(
ppapi::host::HostMessageContext* context,
PP_IsolatedFileSystemType_Private type) {
switch (type) {
case PP_ISOLATEDFILESYSTEMTYPE_PRIVATE_INVALID:
break;
case PP_ISOLATEDFILESYSTEMTYPE_PRIVATE_CRX:
return OpenCrxFileSystem(context);
case PP_ISOLATEDFILESYSTEMTYPE_PRIVATE_PLUGINPRIVATE:
return OpenPluginPrivateFileSystem(context);
}
NOTREACHED();
context->reply_msg =
PpapiPluginMsg_IsolatedFileSystem_BrowserOpenReply(std::string());
return PP_ERROR_FAILED;
}
int32_t PepperIsolatedFileSystemMessageFilter::OpenCrxFileSystem(
ppapi::host::HostMessageContext* context) {
#if defined(ENABLE_EXTENSIONS)
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
scoped_refptr<CefBrowserContextImpl> browser_context =
CefBrowserContextImpl::GetForCachePath(profile_directory_);
DCHECK(browser_context);
const extensions::ExtensionSet* extension_set = NULL;
if (browser_context) {
extension_set = &extensions::ExtensionRegistry::Get(browser_context.get())->
enabled_extensions();
}
if (!chrome::IsExtensionOrSharedModuleWhitelisted(
document_url_, extension_set, allowed_crxfs_origins_) &&
!chrome::IsHostAllowedByCommandLine(
document_url_, extension_set, switches::kAllowNaClCrxFsAPI)) {
LOG(ERROR) << "Host " << document_url_.host() << " cannot use CrxFs API.";
return PP_ERROR_NOACCESS;
}
// TODO(raymes): When we remove FileSystem from the renderer, we should create
// a pending PepperFileSystemBrowserHost here with the fsid and send the
// pending host ID back to the plugin.
const std::string fsid = CreateCrxFileSystem(browser_context.get());
if (fsid.empty()) {
context->reply_msg =
PpapiPluginMsg_IsolatedFileSystem_BrowserOpenReply(std::string());
return PP_ERROR_NOTSUPPORTED;
}
// Grant readonly access of isolated filesystem to renderer process.
content::ChildProcessSecurityPolicy* policy =
content::ChildProcessSecurityPolicy::GetInstance();
policy->GrantReadFileSystem(render_process_id_, fsid);
context->reply_msg = PpapiPluginMsg_IsolatedFileSystem_BrowserOpenReply(fsid);
return PP_OK;
#else
return PP_ERROR_NOTSUPPORTED;
#endif
}
int32_t PepperIsolatedFileSystemMessageFilter::OpenPluginPrivateFileSystem(
ppapi::host::HostMessageContext* context) {
DCHECK(ppapi_host_);
// Only plugins with private permission can open the filesystem.
if (!ppapi_host_->permissions().HasPermission(ppapi::PERMISSION_PRIVATE))
return PP_ERROR_NOACCESS;
const std::string& root_name = ppapi::IsolatedFileSystemTypeToRootName(
PP_ISOLATEDFILESYSTEMTYPE_PRIVATE_PLUGINPRIVATE);
const std::string& fsid =
storage::IsolatedContext::GetInstance()->RegisterFileSystemForVirtualPath(
storage::kFileSystemTypePluginPrivate, root_name, base::FilePath());
// Grant full access of isolated filesystem to renderer process.
content::ChildProcessSecurityPolicy* policy =
content::ChildProcessSecurityPolicy::GetInstance();
policy->GrantCreateReadWriteFileSystem(render_process_id_, fsid);
context->reply_msg = PpapiPluginMsg_IsolatedFileSystem_BrowserOpenReply(fsid);
return PP_OK;
}

View File

@ -1,79 +0,0 @@
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CEF_LIBCEF_BROWSER_PEPPER_PEPPER_ISOLATED_FILE_SYSTEM_MESSAGE_FILTER_H_
#define CEF_LIBCEF_BROWSER_PEPPER_PEPPER_ISOLATED_FILE_SYSTEM_MESSAGE_FILTER_H_
#include <stdint.h>
#include <set>
#include <string>
#include "base/files/file_path.h"
#include "base/macros.h"
#include "ppapi/c/pp_instance.h"
#include "ppapi/c/pp_resource.h"
#include "ppapi/c/private/ppb_isolated_file_system_private.h"
#include "ppapi/host/resource_host.h"
#include "ppapi/host/resource_message_filter.h"
#include "url/gurl.h"
namespace content {
class BrowserContext;
class BrowserPpapiHost;
}
namespace ppapi {
namespace host {
struct HostMessageContext;
} // namespace host
} // namespace ppapi
class PepperIsolatedFileSystemMessageFilter
: public ppapi::host::ResourceMessageFilter {
public:
static PepperIsolatedFileSystemMessageFilter* Create(
PP_Instance instance,
content::BrowserPpapiHost* host);
// ppapi::host::ResourceMessageFilter implementation.
scoped_refptr<base::TaskRunner> OverrideTaskRunnerForMessage(
const IPC::Message& msg) override;
int32_t OnResourceMessageReceived(
const IPC::Message& msg,
ppapi::host::HostMessageContext* context) override;
private:
PepperIsolatedFileSystemMessageFilter(int render_process_id,
const base::FilePath& profile_directory,
const GURL& document_url,
ppapi::host::PpapiHost* ppapi_host_);
~PepperIsolatedFileSystemMessageFilter() override;
// Returns filesystem id of isolated filesystem if valid, or empty string
// otherwise. This must run on the UI thread because ProfileManager only
// allows access on that thread.
std::string CreateCrxFileSystem(content::BrowserContext* profile);
int32_t OnOpenFileSystem(ppapi::host::HostMessageContext* context,
PP_IsolatedFileSystemType_Private type);
int32_t OpenCrxFileSystem(ppapi::host::HostMessageContext* context);
int32_t OpenPluginPrivateFileSystem(ppapi::host::HostMessageContext* context);
const int render_process_id_;
// Keep a copy from original thread.
const base::FilePath profile_directory_;
const GURL document_url_;
// Not owned by this object.
ppapi::host::PpapiHost* ppapi_host_;
// Set of origins that can use CrxFs private APIs from NaCl.
std::set<std::string> allowed_crxfs_origins_;
DISALLOW_COPY_AND_ASSIGN(PepperIsolatedFileSystemMessageFilter);
};
#endif // CEF_LIBCEF_BROWSER_PEPPER_PEPPER_ISOLATED_FILE_SYSTEM_MESSAGE_FILTER_H_

View File

@ -14,10 +14,14 @@
#include "base/strings/string_number_conversions.h"
#include "base/values.h"
#include "chrome/browser/prefs/command_line_pref_store.h"
#include "chrome/browser/supervised_user/supervised_user_pref_store.h"
#include "chrome/browser/supervised_user/supervised_user_settings_service.h"
#include "chrome/browser/supervised_user/supervised_user_settings_service_factory.h"
#include "chrome/browser/themes/theme_service.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
#include "chrome/grit/locale_settings.h"
#include "components/content_settings/core/browser/cookie_settings.h"
#include "components/content_settings/core/browser/host_content_settings_map.h"
#include "components/prefs/json_pref_store.h"
#include "components/prefs/pref_filter.h"
@ -86,7 +90,10 @@ void RegisterLocalizedValue(PrefRegistrySimple* registry,
const char kUserPrefsFileName[] = "UserPrefs.json";
std::unique_ptr<PrefService> CreatePrefService(const base::FilePath& pref_path) {
std::unique_ptr<PrefService> CreatePrefService(
Profile* profile,
const base::FilePath& cache_path,
bool persist_user_preferences) {
const base::CommandLine* command_line =
base::CommandLine::ForCurrentProcess();
@ -100,24 +107,53 @@ std::unique_ptr<PrefService> CreatePrefService(const base::FilePath& pref_path)
renderer_prefs::SetCommandLinePrefDefaults(command_line_pref_store.get());
factory.set_command_line_prefs(command_line_pref_store);
// True if preferences will be stored on disk.
const bool store_on_disk = !cache_path.empty() && persist_user_preferences;
scoped_refptr<base::SequencedTaskRunner> sequenced_task_runner;
if (store_on_disk) {
// Get sequenced task runner for making sure that file operations of
// this profile (defined by |cache_path|) are executed in expected order
// (what was previously assured by the FILE thread).
sequenced_task_runner = JsonPrefStore::GetTaskRunnerForFile(
cache_path, content::BrowserThread::GetBlockingPool());
}
// Used to store user preferences.
scoped_refptr<PersistentPrefStore> user_pref_store;
if (!pref_path.empty()) {
// Store preferences on disk.
scoped_refptr<base::SequencedTaskRunner> task_runner =
JsonPrefStore::GetTaskRunnerForFile(
pref_path,
content::BrowserThread::GetBlockingPool());
if (store_on_disk) {
const base::FilePath& pref_path =
cache_path.AppendASCII(browser_prefs::kUserPrefsFileName);
scoped_refptr<JsonPrefStore> json_pref_store =
new JsonPrefStore(pref_path, task_runner, std::unique_ptr<PrefFilter>());
new JsonPrefStore(pref_path, sequenced_task_runner,
std::unique_ptr<PrefFilter>());
factory.set_user_prefs(json_pref_store.get());
} else {
// Store preferences in memory.
scoped_refptr<TestingPrefStore> testing_pref_store = new TestingPrefStore();
testing_pref_store->SetInitializationCompleted();
factory.set_user_prefs(testing_pref_store.get());
}
#if defined(ENABLE_SUPERVISED_USERS)
// Used to store supervised user preferences.
SupervisedUserSettingsService* supervised_user_settings =
SupervisedUserSettingsServiceFactory::GetForProfile(profile);
if (store_on_disk) {
supervised_user_settings->Init(
cache_path, sequenced_task_runner.get(), false);
} else {
scoped_refptr<TestingPrefStore> testing_pref_store = new TestingPrefStore();
testing_pref_store->SetInitializationCompleted();
supervised_user_settings->Init(testing_pref_store);
}
scoped_refptr<PrefStore> supervised_user_prefs = make_scoped_refptr(
new SupervisedUserPrefStore(supervised_user_settings));
DCHECK(supervised_user_prefs->IsInitializationComplete());
factory.set_supervised_user_prefs(supervised_user_prefs);
#endif // ENABLE_SUPERVISED_USERS
// Registry that will be populated with all known preferences. Preferences
// are registered with default values that may be changed via a *PrefStore.
scoped_refptr<user_prefs::PrefRegistrySyncable> registry(
@ -131,6 +167,7 @@ std::unique_ptr<PrefService> CreatePrefService(const base::FilePath& pref_path)
CefURLRequestContextGetterImpl::RegisterPrefs(registry.get());
renderer_prefs::RegisterProfilePrefs(registry.get());
update_client::RegisterPrefs(registry.get());
content_settings::CookieSettings::RegisterProfilePrefs(registry.get());
// Print preferences.
registry->RegisterBooleanPref(prefs::kPrintingEnabled, true);

View File

@ -7,19 +7,23 @@
#include <memory>
class PrefService;
namespace base {
class FilePath;
}
class PrefService;
class Profile;
namespace browser_prefs {
// Name for the user prefs JSON file.
extern const char kUserPrefsFileName[];
// Create the PrefService used to manage pref registration and storage.
std::unique_ptr<PrefService> CreatePrefService(const base::FilePath& pref_path);
std::unique_ptr<PrefService> CreatePrefService(
Profile* profile,
const base::FilePath& cache_path,
bool persist_user_preferences);
} // namespace browser_prefs

View File

@ -275,6 +275,7 @@ patches = [
},
{
# Make some methods of ProfileManager virtual.
# Allow CEF to intercept GetBrowserContext*InIncognito functions.
'name': 'chrome_profile',
'path': '../',
},

View File

@ -1,7 +1,80 @@
diff --git chrome/browser/profiles/incognito_helpers.cc chrome/browser/profiles/incognito_helpers.cc
index 6155e96..2125a436 100644
--- chrome/browser/profiles/incognito_helpers.cc
+++ chrome/browser/profiles/incognito_helpers.cc
@@ -8,13 +8,35 @@
namespace chrome {
+namespace {
+BrowserContextIncognitoHelper* g_helper = nullptr;
+} // namespace
+
+void SetBrowserContextIncognitoHelper(BrowserContextIncognitoHelper* helper) {
+ g_helper = helper;
+}
+
content::BrowserContext* GetBrowserContextRedirectedInIncognito(
content::BrowserContext* context) {
+ if (g_helper) {
+ content::BrowserContext* new_context =
+ g_helper->GetBrowserContextRedirectedInIncognito(context);
+ if (new_context)
+ return new_context;
+ }
+
return static_cast<Profile*>(context)->GetOriginalProfile();
}
content::BrowserContext* GetBrowserContextOwnInstanceInIncognito(
content::BrowserContext* context) {
+ if (g_helper) {
+ content::BrowserContext* new_context =
+ g_helper->GetBrowserContextOwnInstanceInIncognito(context);
+ if (new_context)
+ return new_context;
+ }
+
return context;
}
diff --git chrome/browser/profiles/incognito_helpers.h chrome/browser/profiles/incognito_helpers.h
index 4b43013..169ca47 100644
--- chrome/browser/profiles/incognito_helpers.h
+++ chrome/browser/profiles/incognito_helpers.h
@@ -11,6 +11,19 @@ class BrowserContext;
namespace chrome {
+class BrowserContextIncognitoHelper {
+ public:
+ virtual content::BrowserContext* GetBrowserContextRedirectedInIncognito(
+ content::BrowserContext* context) = 0;
+ virtual content::BrowserContext* GetBrowserContextOwnInstanceInIncognito(
+ content::BrowserContext* context) = 0;
+ protected:
+ virtual ~BrowserContextIncognitoHelper() {}
+};
+
+// Allow CEF to hook the below methods.
+void SetBrowserContextIncognitoHelper(BrowserContextIncognitoHelper* helper);
+
// Returns the original browser context even for Incognito contexts.
content::BrowserContext* GetBrowserContextRedirectedInIncognito(
content::BrowserContext* context);
diff --git chrome/browser/profiles/profile_manager.h chrome/browser/profiles/profile_manager.h
index e3e742c..aabe932 100644
index e3e742c..fe8e855 100644
--- chrome/browser/profiles/profile_manager.h
+++ chrome/browser/profiles/profile_manager.h
@@ -89,7 +89,7 @@ class ProfileManager : public base::NonThreadSafe,
// acceptable. Returns null if creation of the new profile fails.
// TODO(bauerb): Migrate calls from other code to GetProfileByPath(), then
// make this method private.
- Profile* GetProfile(const base::FilePath& profile_dir);
+ virtual Profile* GetProfile(const base::FilePath& profile_dir);
// Returns total number of profiles available on this machine.
size_t GetNumberOfProfiles();
@@ -117,7 +117,7 @@ class ProfileManager : public base::NonThreadSafe,
// Returns true if the profile pointer is known to point to an existing