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
This commit is contained in:
Marshall Greenblatt
2013-06-04 23:37:26 +00:00
parent ca28f7b67d
commit de41be81b8
9 changed files with 80 additions and 103 deletions

View File

@@ -252,8 +252,7 @@ class CefPluginServiceFilter : public content::PluginServiceFilter {
CefContentBrowserClient::CefContentBrowserClient() CefContentBrowserClient::CefContentBrowserClient()
: browser_main_parts_(NULL), : browser_main_parts_(NULL),
next_browser_id_(0), next_browser_id_(0) {
scheme_set_locked_(false) {
plugin_service_filter_.reset(new CefPluginServiceFilter); plugin_service_filter_.reset(new CefPluginServiceFilter);
content::PluginServiceImpl::GetInstance()->SetFilter( content::PluginServiceImpl::GetInstance()->SetFilter(
plugin_service_filter_.get()); plugin_service_filter_.get());
@@ -428,8 +427,7 @@ bool CefContentBrowserClient::IsHandledURL(const GURL& url) {
if (scheme::IsInternalHandledScheme(scheme)) if (scheme::IsInternalHandledScheme(scheme))
return true; return true;
DCHECK(scheme_set_locked_); return CefContentClient::Get()->HasCustomScheme(scheme);
return scheme_set_.find(scheme) != scheme_set_.end();
} }
void CefContentBrowserClient::AppendExtraCommandLineSwitches( void CefContentBrowserClient::AppendExtraCommandLineSwitches(
@@ -700,10 +698,7 @@ const wchar_t* CefContentBrowserClient::GetResourceDllName() {
} }
#endif // defined(OS_WIN) #endif // defined(OS_WIN)
void CefContentBrowserClient::AddCustomScheme(const std::string& scheme) { void CefContentBrowserClient::RegisterCustomScheme(const std::string& scheme) {
DCHECK(!scheme_set_locked_);
scheme_set_.insert(scheme);
// Register as a Web-safe scheme so that requests for the scheme from a // 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 // render process will be allowed in resource_dispatcher_host_impl.cc
// ShouldServiceRequest. // ShouldServiceRequest.
@@ -713,11 +708,6 @@ void CefContentBrowserClient::AddCustomScheme(const std::string& scheme) {
policy->RegisterWebSafeScheme(scheme); policy->RegisterWebSafeScheme(scheme);
} }
void CefContentBrowserClient::LockCustomSchemes() {
DCHECK(!scheme_set_locked_);
scheme_set_locked_ = true;
}
void CefContentBrowserClient::set_last_create_window_params( void CefContentBrowserClient::set_last_create_window_params(
const LastCreateWindowParams& params) { const LastCreateWindowParams& params) {
CEF_REQUIRE_IOT(); CEF_REQUIRE_IOT();

View File

@@ -113,9 +113,8 @@ class CefContentBrowserClient : public content::ContentBrowserClient {
const wchar_t* GetResourceDllName() OVERRIDE; const wchar_t* GetResourceDllName() OVERRIDE;
#endif #endif
// Add a custom scheme registration. // Perform browser process registration for the custom scheme.
void AddCustomScheme(const std::string& scheme); void RegisterCustomScheme(const std::string& scheme);
void LockCustomSchemes();
// Store additional state from the ViewHostMsg_CreateWindow message that will // Store additional state from the ViewHostMsg_CreateWindow message that will
// be used when CanCreateWindow() is called. // be used when CanCreateWindow() is called.
@@ -145,10 +144,6 @@ class CefContentBrowserClient : public content::ContentBrowserClient {
BrowserInfoList browser_info_list_; BrowserInfoList browser_info_list_;
int next_browser_id_; int next_browser_id_;
typedef std::set<std::string> SchemeSet;
SchemeSet scheme_set_;
bool scheme_set_locked_;
// Only accessed on the IO thread. // Only accessed on the IO thread.
LastCreateWindowParams last_create_window_params_; LastCreateWindowParams last_create_window_params_;
}; };

View File

@@ -8,7 +8,6 @@
#include "libcef/browser/content_browser_client.h" #include "libcef/browser/content_browser_client.h"
#include "libcef/common/scheme_registrar_impl.h" #include "libcef/common/scheme_registrar_impl.h"
#include "libcef/common/scheme_registration.h" #include "libcef/common/scheme_registration.h"
#include "libcef/renderer/content_renderer_client.h"
#include "base/command_line.h" #include "base/command_line.h"
#include "base/logging.h" #include "base/logging.h"
@@ -28,11 +27,11 @@ const char kInterposeLibraryPath[] =
} // namespace } // namespace
CefContentClient::CefContentClient(CefRefPtr<CefApp> application) CefContentClient::CefContentClient(CefRefPtr<CefApp> application)
: application_(application), : application_(application),
pack_loading_disabled_(false), pack_loading_disabled_(false),
allow_pack_file_load_(false) { allow_pack_file_load_(false),
scheme_info_list_locked_(false) {
DCHECK(!g_content_client); DCHECK(!g_content_client);
g_content_client = this; g_content_client = this;
} }
@@ -49,6 +48,8 @@ CefContentClient* CefContentClient::Get() {
void CefContentClient::AddAdditionalSchemes( void CefContentClient::AddAdditionalSchemes(
std::vector<std::string>* standard_schemes, std::vector<std::string>* standard_schemes,
std::vector<std::string>* savable_schemes) { std::vector<std::string>* savable_schemes) {
DCHECK(!scheme_info_list_locked_);
if (application_.get()) { if (application_.get()) {
CefRefPtr<CefSchemeRegistrarImpl> schemeRegistrar( CefRefPtr<CefSchemeRegistrarImpl> schemeRegistrar(
new CefSchemeRegistrarImpl()); new CefSchemeRegistrarImpl());
@@ -60,12 +61,9 @@ void CefContentClient::AddAdditionalSchemes(
DCHECK(schemeRegistrar->VerifyRefCount()); DCHECK(schemeRegistrar->VerifyRefCount());
} }
scheme::AddInternalStandardSchemes(standard_schemes); scheme::AddInternalSchemes(standard_schemes);
if (CefContentBrowserClient::Get()) scheme_info_list_locked_ = true;
CefContentBrowserClient::Get()->LockCustomSchemes();
if (CefContentRendererClient::Get())
CefContentRendererClient::Get()->LockCustomSchemes();
} }
std::string CefContentClient::GetUserAgent() const { std::string CefContentClient::GetUserAgent() const {
@@ -120,6 +118,35 @@ std::string CefContentClient::GetCarbonInterposePath() const {
} }
#endif #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( base::FilePath CefContentClient::GetPathForResourcePack(
const base::FilePath& pack_path, const base::FilePath& pack_path,
ui::ScaleFactor scale_factor) { ui::ScaleFactor scale_factor) {

View File

@@ -6,6 +6,7 @@
#define CEF_LIBCEF_COMMON_CONTENT_CLIENT_H_ #define CEF_LIBCEF_COMMON_CONTENT_CLIENT_H_
#pragma once #pragma once
#include <list>
#include <string> #include <string>
#include <vector> #include <vector>
@@ -39,6 +40,19 @@ class CefContentClient : public content::ContentClient,
virtual std::string GetCarbonInterposePath() const OVERRIDE; virtual std::string GetCarbonInterposePath() const OVERRIDE;
#endif #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_; } CefRefPtr<CefApp> application() const { return application_; }
void set_pack_loading_disabled(bool val) { pack_loading_disabled_ = val; } void set_pack_loading_disabled(bool val) { pack_loading_disabled_ = val; }
@@ -70,6 +84,10 @@ class CefContentClient : public content::ContentClient,
CefRefPtr<CefApp> application_; CefRefPtr<CefApp> application_;
bool pack_loading_disabled_; bool pack_loading_disabled_;
bool allow_pack_file_load_; 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_ #endif // CEF_LIBCEF_COMMON_CONTENT_CLIENT_H_

View File

@@ -6,8 +6,7 @@
#include <string> #include <string>
#include "libcef/browser/content_browser_client.h" #include "libcef/common/content_client.h"
#include "libcef/renderer/content_renderer_client.h"
#include "base/bind.h" #include "base/bind.h"
#include "base/logging.h" #include "base/logging.h"
@@ -29,15 +28,9 @@ bool CefSchemeRegistrarImpl::AddCustomScheme(
if (is_standard) if (is_standard)
standard_schemes_.push_back(scheme); standard_schemes_.push_back(scheme);
if (CefContentRendererClient::Get()) { CefContentClient::SchemeInfo scheme_info = {
CefContentRendererClient::Get()->AddCustomScheme(scheme, scheme, is_standard, is_local, is_display_isolated};
is_standard, CefContentClient::Get()->AddCustomScheme(scheme_info);
is_local,
is_display_isolated);
}
if (CefContentBrowserClient::Get())
CefContentBrowserClient::Get()->AddCustomScheme(scheme);
return true; return true;
} }

View File

@@ -3,34 +3,23 @@
// can be found in the LICENSE file. // can be found in the LICENSE file.
#include "libcef/common/scheme_registration.h" #include "libcef/common/scheme_registration.h"
#include "libcef/browser/content_browser_client.h" #include "libcef/common/content_client.h"
#include "libcef/renderer/content_renderer_client.h"
#include "content/public/common/url_constants.h" #include "content/public/common/url_constants.h"
namespace scheme { namespace scheme {
void AddInternalStandardSchemes(std::vector<std::string>* standard_schemes) { void AddInternalSchemes(std::vector<std::string>* standard_schemes) {
static struct { static CefContentClient::SchemeInfo schemes[] = {
const char* name; { chrome::kChromeUIScheme, true, true, true },
bool is_local; { chrome::kChromeDevToolsScheme, true, true, false }
bool is_display_isolated;
} schemes[] = {
{ chrome::kChromeUIScheme, true, true },
{ chrome::kChromeDevToolsScheme, true, false }
}; };
CefContentClient* client = CefContentClient::Get();
for (size_t i = 0; i < sizeof(schemes) / sizeof(schemes[0]); ++i) { for (size_t i = 0; i < sizeof(schemes) / sizeof(schemes[0]); ++i) {
standard_schemes->push_back(schemes[i].name); if (schemes[0].is_standard)
standard_schemes->push_back(schemes[i].scheme_name);
if (CefContentBrowserClient::Get()) client->AddCustomScheme(schemes[i]);
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);
}
} }
} }

View File

@@ -11,8 +11,8 @@
namespace scheme { namespace scheme {
// Add internal standard schemes. // Add internal schemes.
void AddInternalStandardSchemes(std::vector<std::string>* standard_schemes); void AddInternalSchemes(std::vector<std::string>* standard_schemes);
// Returns true if the specified |scheme| is handled internally. // Returns true if the specified |scheme| is handled internally.
bool IsInternalHandledScheme(const std::string& scheme); bool IsInternalHandledScheme(const std::string& scheme);

View File

@@ -130,16 +130,8 @@ class CefWebWorkerTaskRunner : public base::SequencedTaskRunner,
} // namespace } // namespace
struct CefContentRendererClient::SchemeInfo {
std::string scheme_name;
bool is_standard;
bool is_local;
bool is_display_isolated;
};
CefContentRendererClient::CefContentRendererClient() CefContentRendererClient::CefContentRendererClient()
: scheme_info_list_locked_(false), : devtools_agent_count_(0),
devtools_agent_count_(0),
uncaught_exception_stack_size_(0), uncaught_exception_stack_size_(0),
single_process_cleanup_complete_(false) { single_process_cleanup_complete_(false) {
} }
@@ -192,21 +184,6 @@ void CefContentRendererClient::OnBrowserDestroyed(CefBrowserImpl* browser) {
NOTREACHED(); 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() { void CefContentRendererClient::WebKitInitialized() {
const CommandLine& command_line = *CommandLine::ForCurrentProcess(); const CommandLine& command_line = *CommandLine::ForCurrentProcess();
@@ -221,12 +198,13 @@ void CefContentRendererClient::WebKitInitialized() {
WebKit::WebRuntimeFeatures::enableMediaStream( WebKit::WebRuntimeFeatures::enableMediaStream(
command_line.HasSwitch(switches::kEnableMediaStream)); command_line.HasSwitch(switches::kEnableMediaStream));
DCHECK(scheme_info_list_locked_); const CefContentClient::SchemeInfoList* schemes =
if (!scheme_info_list_.empty()) { CefContentClient::Get()->GetCustomSchemes();
if (!schemes->empty()) {
// Register the custom schemes. // Register the custom schemes.
SchemeInfoList::const_iterator it = scheme_info_list_.begin(); CefContentClient::SchemeInfoList::const_iterator it = schemes->begin();
for (; it != scheme_info_list_.end(); ++it) { for (; it != schemes->end(); ++it) {
const SchemeInfo& info = *it; const CefContentClient::SchemeInfo& info = *it;
const WebKit::WebString& scheme = const WebKit::WebString& scheme =
WebKit::WebString::fromUTF8(info.scheme_name); WebKit::WebString::fromUTF8(info.scheme_name);
if (info.is_standard) { if (info.is_standard) {

View File

@@ -41,13 +41,6 @@ class CefContentRendererClient : public content::ContentRendererClient,
// Called from CefBrowserImpl::OnDestruct(). // Called from CefBrowserImpl::OnDestruct().
void OnBrowserDestroyed(CefBrowserImpl* browser); 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. // Render thread task runner.
base::SequencedTaskRunner* render_task_runner() const { base::SequencedTaskRunner* render_task_runner() const {
return render_task_runner_.get(); return render_task_runner_.get();
@@ -109,12 +102,6 @@ class CefContentRendererClient : public content::ContentRendererClient,
typedef std::map<content::RenderView*, CefRefPtr<CefBrowserImpl> > BrowserMap; typedef std::map<content::RenderView*, CefRefPtr<CefBrowserImpl> > BrowserMap;
BrowserMap browsers_; 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. // Cross-origin white list entries that need to be registered with WebKit.
typedef std::vector<Cef_CrossOriginWhiteListEntry_Params> CrossOriginList; typedef std::vector<Cef_CrossOriginWhiteListEntry_Params> CrossOriginList;
CrossOriginList cross_origin_whitelist_entries_; CrossOriginList cross_origin_whitelist_entries_;