From de41be81b870f350e11d13a98e70154a416635bf Mon Sep 17 00:00:00 2001 From: Marshall Greenblatt Date: Tue, 4 Jun 2013 23:37:26 +0000 Subject: [PATCH] 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 --- libcef/browser/content_browser_client.cc | 16 ++------ libcef/browser/content_browser_client.h | 9 +---- libcef/common/content_client.cc | 43 ++++++++++++++++++---- libcef/common/content_client.h | 18 +++++++++ libcef/common/scheme_registrar_impl.cc | 15 ++------ libcef/common/scheme_registration.cc | 29 +++++---------- libcef/common/scheme_registration.h | 4 +- libcef/renderer/content_renderer_client.cc | 36 ++++-------------- libcef/renderer/content_renderer_client.h | 13 ------- 9 files changed, 80 insertions(+), 103 deletions(-) diff --git a/libcef/browser/content_browser_client.cc b/libcef/browser/content_browser_client.cc index c88094bc2..afec4101e 100644 --- a/libcef/browser/content_browser_client.cc +++ b/libcef/browser/content_browser_client.cc @@ -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(); diff --git a/libcef/browser/content_browser_client.h b/libcef/browser/content_browser_client.h index 2a62d3954..e42fc1d80 100644 --- a/libcef/browser/content_browser_client.h +++ b/libcef/browser/content_browser_client.h @@ -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 SchemeSet; - SchemeSet scheme_set_; - bool scheme_set_locked_; - // Only accessed on the IO thread. LastCreateWindowParams last_create_window_params_; }; diff --git a/libcef/common/content_client.cc b/libcef/common/content_client.cc index c4af8df65..5a9e473d7 100644 --- a/libcef/common/content_client.cc +++ b/libcef/common/content_client.cc @@ -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 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* standard_schemes, std::vector* savable_schemes) { + DCHECK(!scheme_info_list_locked_); + if (application_.get()) { CefRefPtr 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) { diff --git a/libcef/common/content_client.h b/libcef/common/content_client.h index 41c50657b..d535b82eb 100644 --- a/libcef/common/content_client.h +++ b/libcef/common/content_client.h @@ -6,6 +6,7 @@ #define CEF_LIBCEF_COMMON_CONTENT_CLIENT_H_ #pragma once +#include #include #include @@ -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 SchemeInfoList; + + // Custom scheme registration. + void AddCustomScheme(const SchemeInfo& scheme_info); + const SchemeInfoList* GetCustomSchemes(); + bool HasCustomScheme(const std::string& scheme_name); + CefRefPtr 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 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_ diff --git a/libcef/common/scheme_registrar_impl.cc b/libcef/common/scheme_registrar_impl.cc index a9fa288d1..c9ff116b9 100644 --- a/libcef/common/scheme_registrar_impl.cc +++ b/libcef/common/scheme_registrar_impl.cc @@ -6,8 +6,7 @@ #include -#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; } diff --git a/libcef/common/scheme_registration.cc b/libcef/common/scheme_registration.cc index 6329c5703..3656ab78a 100644 --- a/libcef/common/scheme_registration.cc +++ b/libcef/common/scheme_registration.cc @@ -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* 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* 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]); } } diff --git a/libcef/common/scheme_registration.h b/libcef/common/scheme_registration.h index ec85053bc..7252f24d8 100644 --- a/libcef/common/scheme_registration.h +++ b/libcef/common/scheme_registration.h @@ -11,8 +11,8 @@ namespace scheme { -// Add internal standard schemes. -void AddInternalStandardSchemes(std::vector* standard_schemes); +// Add internal schemes. +void AddInternalSchemes(std::vector* standard_schemes); // Returns true if the specified |scheme| is handled internally. bool IsInternalHandledScheme(const std::string& scheme); diff --git a/libcef/renderer/content_renderer_client.cc b/libcef/renderer/content_renderer_client.cc index 444c69644..b402b1595 100644 --- a/libcef/renderer/content_renderer_client.cc +++ b/libcef/renderer/content_renderer_client.cc @@ -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) { diff --git a/libcef/renderer/content_renderer_client.h b/libcef/renderer/content_renderer_client.h index 201ae0dd6..12e104486 100644 --- a/libcef/renderer/content_renderer_client.h +++ b/libcef/renderer/content_renderer_client.h @@ -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 > BrowserMap; BrowserMap browsers_; - // Custom schemes that need to be registered with WebKit. - struct SchemeInfo; - typedef std::list 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 CrossOriginList; CrossOriginList cross_origin_whitelist_entries_;