Commit de41be81 authored by Marshall Greenblatt's avatar Marshall Greenblatt

Move custom scheme registration to CefContentClient. This works around a...

Move custom scheme registration to CefContentClient. This works around a problem on Linux where the zygote process  has no CefContentRendererClient instance at the time that CefContentClient::AddAdditionalSchemes is executed (the zygote process is later forked to create new render processes).

git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@1271 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
parent ca28f7b6
......@@ -252,8 +252,7 @@ class CefPluginServiceFilter : public content::PluginServiceFilter {
CefContentBrowserClient::CefContentBrowserClient()
: browser_main_parts_(NULL),
next_browser_id_(0),
scheme_set_locked_(false) {
next_browser_id_(0) {
plugin_service_filter_.reset(new CefPluginServiceFilter);
content::PluginServiceImpl::GetInstance()->SetFilter(
plugin_service_filter_.get());
......@@ -428,8 +427,7 @@ bool CefContentBrowserClient::IsHandledURL(const GURL& url) {
if (scheme::IsInternalHandledScheme(scheme))
return true;
DCHECK(scheme_set_locked_);
return scheme_set_.find(scheme) != scheme_set_.end();
return CefContentClient::Get()->HasCustomScheme(scheme);
}
void CefContentBrowserClient::AppendExtraCommandLineSwitches(
......@@ -700,10 +698,7 @@ const wchar_t* CefContentBrowserClient::GetResourceDllName() {
}
#endif // defined(OS_WIN)
void CefContentBrowserClient::AddCustomScheme(const std::string& scheme) {
DCHECK(!scheme_set_locked_);
scheme_set_.insert(scheme);
void CefContentBrowserClient::RegisterCustomScheme(const std::string& scheme) {
// Register as a Web-safe scheme so that requests for the scheme from a
// render process will be allowed in resource_dispatcher_host_impl.cc
// ShouldServiceRequest.
......@@ -713,11 +708,6 @@ void CefContentBrowserClient::AddCustomScheme(const std::string& scheme) {
policy->RegisterWebSafeScheme(scheme);
}
void CefContentBrowserClient::LockCustomSchemes() {
DCHECK(!scheme_set_locked_);
scheme_set_locked_ = true;
}
void CefContentBrowserClient::set_last_create_window_params(
const LastCreateWindowParams& params) {
CEF_REQUIRE_IOT();
......
......@@ -113,9 +113,8 @@ class CefContentBrowserClient : public content::ContentBrowserClient {
const wchar_t* GetResourceDllName() OVERRIDE;
#endif
// Add a custom scheme registration.
void AddCustomScheme(const std::string& scheme);
void LockCustomSchemes();
// Perform browser process registration for the custom scheme.
void RegisterCustomScheme(const std::string& scheme);
// Store additional state from the ViewHostMsg_CreateWindow message that will
// be used when CanCreateWindow() is called.
......@@ -145,10 +144,6 @@ class CefContentBrowserClient : public content::ContentBrowserClient {
BrowserInfoList browser_info_list_;
int next_browser_id_;
typedef std::set<std::string> SchemeSet;
SchemeSet scheme_set_;
bool scheme_set_locked_;
// Only accessed on the IO thread.
LastCreateWindowParams last_create_window_params_;
};
......
......@@ -8,7 +8,6 @@
#include "libcef/browser/content_browser_client.h"
#include "libcef/common/scheme_registrar_impl.h"
#include "libcef/common/scheme_registration.h"
#include "libcef/renderer/content_renderer_client.h"
#include "base/command_line.h"
#include "base/logging.h"
......@@ -28,11 +27,11 @@ const char kInterposeLibraryPath[] =
} // namespace
CefContentClient::CefContentClient(CefRefPtr<CefApp> application)
: application_(application),
pack_loading_disabled_(false),
allow_pack_file_load_(false) {
allow_pack_file_load_(false),
scheme_info_list_locked_(false) {
DCHECK(!g_content_client);
g_content_client = this;
}
......@@ -49,6 +48,8 @@ CefContentClient* CefContentClient::Get() {
void CefContentClient::AddAdditionalSchemes(
std::vector<std::string>* standard_schemes,
std::vector<std::string>* savable_schemes) {
DCHECK(!scheme_info_list_locked_);
if (application_.get()) {
CefRefPtr<CefSchemeRegistrarImpl> schemeRegistrar(
new CefSchemeRegistrarImpl());
......@@ -60,12 +61,9 @@ void CefContentClient::AddAdditionalSchemes(
DCHECK(schemeRegistrar->VerifyRefCount());
}
scheme::AddInternalStandardSchemes(standard_schemes);
scheme::AddInternalSchemes(standard_schemes);
if (CefContentBrowserClient::Get())
CefContentBrowserClient::Get()->LockCustomSchemes();
if (CefContentRendererClient::Get())
CefContentRendererClient::Get()->LockCustomSchemes();
scheme_info_list_locked_ = true;
}
std::string CefContentClient::GetUserAgent() const {
......@@ -120,6 +118,35 @@ std::string CefContentClient::GetCarbonInterposePath() const {
}
#endif
void CefContentClient::AddCustomScheme(const SchemeInfo& scheme_info) {
DCHECK(!scheme_info_list_locked_);
scheme_info_list_.push_back(scheme_info);
if (CefContentBrowserClient::Get()) {
CefContentBrowserClient::Get()->RegisterCustomScheme(
scheme_info.scheme_name);
}
}
const CefContentClient::SchemeInfoList* CefContentClient::GetCustomSchemes() {
DCHECK(scheme_info_list_locked_);
return &scheme_info_list_;
}
bool CefContentClient::HasCustomScheme(const std::string& scheme_name) {
DCHECK(scheme_info_list_locked_);
if (scheme_info_list_.empty())
return false;
SchemeInfoList::const_iterator it = scheme_info_list_.begin();
for (; it != scheme_info_list_.end(); ++it) {
if (it->scheme_name == scheme_name)
return true;
}
return false;
}
base::FilePath CefContentClient::GetPathForResourcePack(
const base::FilePath& pack_path,
ui::ScaleFactor scale_factor) {
......
......@@ -6,6 +6,7 @@
#define CEF_LIBCEF_COMMON_CONTENT_CLIENT_H_
#pragma once
#include <list>
#include <string>
#include <vector>
......@@ -39,6 +40,19 @@ class CefContentClient : public content::ContentClient,
virtual std::string GetCarbonInterposePath() const OVERRIDE;
#endif
struct SchemeInfo {
std::string scheme_name;
bool is_standard;
bool is_local;
bool is_display_isolated;
};
typedef std::list<SchemeInfo> SchemeInfoList;
// Custom scheme registration.
void AddCustomScheme(const SchemeInfo& scheme_info);
const SchemeInfoList* GetCustomSchemes();
bool HasCustomScheme(const std::string& scheme_name);
CefRefPtr<CefApp> application() const { return application_; }
void set_pack_loading_disabled(bool val) { pack_loading_disabled_ = val; }
......@@ -70,6 +84,10 @@ class CefContentClient : public content::ContentClient,
CefRefPtr<CefApp> application_;
bool pack_loading_disabled_;
bool allow_pack_file_load_;
// Custom schemes handled by the client.
SchemeInfoList scheme_info_list_;
bool scheme_info_list_locked_;
};
#endif // CEF_LIBCEF_COMMON_CONTENT_CLIENT_H_
......@@ -6,8 +6,7 @@
#include <string>
#include "libcef/browser/content_browser_client.h"
#include "libcef/renderer/content_renderer_client.h"
#include "libcef/common/content_client.h"
#include "base/bind.h"
#include "base/logging.h"
......@@ -29,15 +28,9 @@ bool CefSchemeRegistrarImpl::AddCustomScheme(
if (is_standard)
standard_schemes_.push_back(scheme);
if (CefContentRendererClient::Get()) {
CefContentRendererClient::Get()->AddCustomScheme(scheme,
is_standard,
is_local,
is_display_isolated);
}
if (CefContentBrowserClient::Get())
CefContentBrowserClient::Get()->AddCustomScheme(scheme);
CefContentClient::SchemeInfo scheme_info = {
scheme, is_standard, is_local, is_display_isolated};
CefContentClient::Get()->AddCustomScheme(scheme_info);
return true;
}
......
......@@ -3,34 +3,23 @@
// can be found in the LICENSE file.
#include "libcef/common/scheme_registration.h"
#include "libcef/browser/content_browser_client.h"
#include "libcef/renderer/content_renderer_client.h"
#include "libcef/common/content_client.h"
#include "content/public/common/url_constants.h"
namespace scheme {
void AddInternalStandardSchemes(std::vector<std::string>* standard_schemes) {
static struct {
const char* name;
bool is_local;
bool is_display_isolated;
} schemes[] = {
{ chrome::kChromeUIScheme, true, true },
{ chrome::kChromeDevToolsScheme, true, false }
void AddInternalSchemes(std::vector<std::string>* standard_schemes) {
static CefContentClient::SchemeInfo schemes[] = {
{ chrome::kChromeUIScheme, true, true, true },
{ chrome::kChromeDevToolsScheme, true, true, false }
};
CefContentClient* client = CefContentClient::Get();
for (size_t i = 0; i < sizeof(schemes) / sizeof(schemes[0]); ++i) {
standard_schemes->push_back(schemes[i].name);
if (CefContentBrowserClient::Get())
CefContentBrowserClient::Get()->AddCustomScheme(schemes[i].name);
if (CefContentRendererClient::Get()) {
CefContentRendererClient::Get()->AddCustomScheme(
schemes[i].name, true, schemes[i].is_local,
schemes[i].is_display_isolated);
}
if (schemes[0].is_standard)
standard_schemes->push_back(schemes[i].scheme_name);
client->AddCustomScheme(schemes[i]);
}
}
......
......@@ -11,8 +11,8 @@
namespace scheme {
// Add internal standard schemes.
void AddInternalStandardSchemes(std::vector<std::string>* standard_schemes);
// Add internal schemes.
void AddInternalSchemes(std::vector<std::string>* standard_schemes);
// Returns true if the specified |scheme| is handled internally.
bool IsInternalHandledScheme(const std::string& scheme);
......
......@@ -130,16 +130,8 @@ class CefWebWorkerTaskRunner : public base::SequencedTaskRunner,
} // namespace
struct CefContentRendererClient::SchemeInfo {
std::string scheme_name;
bool is_standard;
bool is_local;
bool is_display_isolated;
};
CefContentRendererClient::CefContentRendererClient()
: scheme_info_list_locked_(false),
devtools_agent_count_(0),
: devtools_agent_count_(0),
uncaught_exception_stack_size_(0),
single_process_cleanup_complete_(false) {
}
......@@ -192,21 +184,6 @@ void CefContentRendererClient::OnBrowserDestroyed(CefBrowserImpl* browser) {
NOTREACHED();
}
void CefContentRendererClient::AddCustomScheme(
const std::string& scheme_name,
bool is_standard,
bool is_local,
bool is_display_isolated) {
DCHECK(!scheme_info_list_locked_);
SchemeInfo info = {scheme_name, is_standard, is_local, is_display_isolated};
scheme_info_list_.push_back(info);
}
void CefContentRendererClient::LockCustomSchemes() {
DCHECK(!scheme_info_list_locked_);
scheme_info_list_locked_ = true;
}
void CefContentRendererClient::WebKitInitialized() {
const CommandLine& command_line = *CommandLine::ForCurrentProcess();
......@@ -221,12 +198,13 @@ void CefContentRendererClient::WebKitInitialized() {
WebKit::WebRuntimeFeatures::enableMediaStream(
command_line.HasSwitch(switches::kEnableMediaStream));
DCHECK(scheme_info_list_locked_);
if (!scheme_info_list_.empty()) {
const CefContentClient::SchemeInfoList* schemes =
CefContentClient::Get()->GetCustomSchemes();
if (!schemes->empty()) {
// Register the custom schemes.
SchemeInfoList::const_iterator it = scheme_info_list_.begin();
for (; it != scheme_info_list_.end(); ++it) {
const SchemeInfo& info = *it;
CefContentClient::SchemeInfoList::const_iterator it = schemes->begin();
for (; it != schemes->end(); ++it) {
const CefContentClient::SchemeInfo& info = *it;
const WebKit::WebString& scheme =
WebKit::WebString::fromUTF8(info.scheme_name);
if (info.is_standard) {
......
......@@ -41,13 +41,6 @@ class CefContentRendererClient : public content::ContentRendererClient,
// Called from CefBrowserImpl::OnDestruct().
void OnBrowserDestroyed(CefBrowserImpl* browser);
// Add a custom scheme registration.
void AddCustomScheme(const std::string& scheme_name,
bool is_standard,
bool is_local,
bool is_display_isolated);
void LockCustomSchemes();
// Render thread task runner.
base::SequencedTaskRunner* render_task_runner() const {
return render_task_runner_.get();
......@@ -109,12 +102,6 @@ class CefContentRendererClient : public content::ContentRendererClient,
typedef std::map<content::RenderView*, CefRefPtr<CefBrowserImpl> > BrowserMap;
BrowserMap browsers_;
// Custom schemes that need to be registered with WebKit.
struct SchemeInfo;
typedef std::list<SchemeInfo> SchemeInfoList;
SchemeInfoList scheme_info_list_;
bool scheme_info_list_locked_;
// Cross-origin white list entries that need to be registered with WebKit.
typedef std::vector<Cef_CrossOriginWhiteListEntry_Params> CrossOriginList;
CrossOriginList cross_origin_whitelist_entries_;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment