mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-02-17 04:30:46 +01:00
cefclient: Move StringResourceMap to ClientHandler (see issue #2586)
Fixes a DCHECK when creating multiple windows in cefclient due to the creation of multiple StringResourceProvider objects.
This commit is contained in:
parent
329facfbdf
commit
aad4bf2464
@ -260,7 +260,7 @@ ClientHandler::ClientHandler(Delegate* delegate,
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
resource_manager_ = new CefResourceManager();
|
resource_manager_ = new CefResourceManager();
|
||||||
test_runner::SetupResourceManager(resource_manager_);
|
test_runner::SetupResourceManager(resource_manager_, &string_resource_map_);
|
||||||
|
|
||||||
// Read command line settings.
|
// Read command line settings.
|
||||||
CefRefPtr<CefCommandLine> command_line =
|
CefRefPtr<CefCommandLine> command_line =
|
||||||
@ -973,6 +973,17 @@ void ClientHandler::ShowSSLInformation(CefRefPtr<CefBrowser> browser) {
|
|||||||
MainContext::Get()->GetRootWindowManager()->CreateRootWindow(config);
|
MainContext::Get()->GetRootWindowManager()->CreateRootWindow(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ClientHandler::SetStringResource(const std::string& page,
|
||||||
|
const std::string& data) {
|
||||||
|
if (!CefCurrentlyOn(TID_IO)) {
|
||||||
|
CefPostTask(TID_IO, base::Bind(&ClientHandler::SetStringResource, this,
|
||||||
|
page, data));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
string_resource_map_[page] = data;
|
||||||
|
}
|
||||||
|
|
||||||
bool ClientHandler::CreatePopupWindow(CefRefPtr<CefBrowser> browser,
|
bool ClientHandler::CreatePopupWindow(CefRefPtr<CefBrowser> browser,
|
||||||
bool is_devtools,
|
bool is_devtools,
|
||||||
const CefPopupFeatures& popupFeatures,
|
const CefPopupFeatures& popupFeatures,
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
#include "include/wrapper/cef_message_router.h"
|
#include "include/wrapper/cef_message_router.h"
|
||||||
#include "include/wrapper/cef_resource_manager.h"
|
#include "include/wrapper/cef_resource_manager.h"
|
||||||
#include "tests/cefclient/browser/client_types.h"
|
#include "tests/cefclient/browser/client_types.h"
|
||||||
|
#include "tests/cefclient/browser/test_runner.h"
|
||||||
|
|
||||||
#if defined(OS_LINUX)
|
#if defined(OS_LINUX)
|
||||||
#include "tests/cefclient/browser/dialog_handler_gtk.h"
|
#include "tests/cefclient/browser/dialog_handler_gtk.h"
|
||||||
@ -293,6 +294,9 @@ class ClientHandler : public CefClient,
|
|||||||
// Show SSL information for the current site.
|
// Show SSL information for the current site.
|
||||||
void ShowSSLInformation(CefRefPtr<CefBrowser> browser);
|
void ShowSSLInformation(CefRefPtr<CefBrowser> browser);
|
||||||
|
|
||||||
|
// Set a string resource for loading via StringResourceProvider.
|
||||||
|
void SetStringResource(const std::string& page, const std::string& data);
|
||||||
|
|
||||||
// Returns the Delegate.
|
// Returns the Delegate.
|
||||||
Delegate* delegate() const { return delegate_; }
|
Delegate* delegate() const { return delegate_; }
|
||||||
|
|
||||||
@ -367,6 +371,10 @@ class ClientHandler : public CefClient,
|
|||||||
// Manages the registration and delivery of resources.
|
// Manages the registration and delivery of resources.
|
||||||
CefRefPtr<CefResourceManager> resource_manager_;
|
CefRefPtr<CefResourceManager> resource_manager_;
|
||||||
|
|
||||||
|
// Used to manage string resources in combination with StringResourceProvider.
|
||||||
|
// Only accessed on the IO thread.
|
||||||
|
test_runner::StringResourceMap string_resource_map_;
|
||||||
|
|
||||||
// MAIN THREAD MEMBERS
|
// MAIN THREAD MEMBERS
|
||||||
// The following members will only be accessed on the main thread. This will
|
// The following members will only be accessed on the main thread. This will
|
||||||
// be the same as the CEF UI thread except when using multi-threaded message
|
// be the same as the CEF UI thread except when using multi-threaded message
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
#include "include/wrapper/cef_closure_task.h"
|
#include "include/wrapper/cef_closure_task.h"
|
||||||
#include "include/wrapper/cef_stream_resource_handler.h"
|
#include "include/wrapper/cef_stream_resource_handler.h"
|
||||||
#include "tests/cefclient/browser/binding_test.h"
|
#include "tests/cefclient/browser/binding_test.h"
|
||||||
|
#include "tests/cefclient/browser/client_handler.h"
|
||||||
#include "tests/cefclient/browser/dialog_test.h"
|
#include "tests/cefclient/browser/dialog_test.h"
|
||||||
#include "tests/cefclient/browser/drm_test.h"
|
#include "tests/cefclient/browser/drm_test.h"
|
||||||
#include "tests/cefclient/browser/main_context.h"
|
#include "tests/cefclient/browser/main_context.h"
|
||||||
@ -43,27 +44,14 @@ const char kTestGetSourcePage[] = "get_source.html";
|
|||||||
const char kTestGetTextPage[] = "get_text.html";
|
const char kTestGetTextPage[] = "get_text.html";
|
||||||
const char kTestPluginInfoPage[] = "plugin_info.html";
|
const char kTestPluginInfoPage[] = "plugin_info.html";
|
||||||
|
|
||||||
// Map of page name to data.
|
|
||||||
typedef std::map<std::string, std::string> StringResourceMap;
|
|
||||||
StringResourceMap* g_string_resource_map = NULL;
|
|
||||||
|
|
||||||
void SetStringResource(const std::string& page, const std::string& data) {
|
|
||||||
if (!CefCurrentlyOn(TID_IO)) {
|
|
||||||
CefPostTask(TID_IO, base::Bind(SetStringResource, page, data));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (g_string_resource_map) {
|
|
||||||
(*g_string_resource_map)[page] = data;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set page data and navigate the browser. Used in combination with
|
// Set page data and navigate the browser. Used in combination with
|
||||||
// StringResourceProvider.
|
// StringResourceProvider.
|
||||||
void LoadStringResourcePage(CefRefPtr<CefBrowser> browser,
|
void LoadStringResourcePage(CefRefPtr<CefBrowser> browser,
|
||||||
const std::string& page,
|
const std::string& page,
|
||||||
const std::string& data) {
|
const std::string& data) {
|
||||||
SetStringResource(page, data);
|
CefRefPtr<CefClient> client = browser->GetHost()->GetClient();
|
||||||
|
ClientHandler* client_handler = static_cast<ClientHandler*>(client.get());
|
||||||
|
client_handler->SetStringResource(page, data);
|
||||||
browser->GetMainFrame()->LoadURL(kTestOrigin + page);
|
browser->GetMainFrame()->LoadURL(kTestOrigin + page);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -500,16 +488,12 @@ class RequestDumpResourceProvider : public CefResourceManager::Provider {
|
|||||||
// with LoadStringResourcePage().
|
// with LoadStringResourcePage().
|
||||||
class StringResourceProvider : public CefResourceManager::Provider {
|
class StringResourceProvider : public CefResourceManager::Provider {
|
||||||
public:
|
public:
|
||||||
explicit StringResourceProvider(const std::set<std::string>& pages)
|
StringResourceProvider(const std::set<std::string>& pages,
|
||||||
: pages_(pages) {
|
StringResourceMap* string_resource_map)
|
||||||
|
: pages_(pages), string_resource_map_(string_resource_map) {
|
||||||
DCHECK(!pages.empty());
|
DCHECK(!pages.empty());
|
||||||
|
|
||||||
DCHECK(!g_string_resource_map);
|
|
||||||
g_string_resource_map = &resource_map_;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ~StringResourceProvider() { g_string_resource_map = NULL; }
|
|
||||||
|
|
||||||
bool OnRequest(scoped_refptr<CefResourceManager::Request> request) OVERRIDE {
|
bool OnRequest(scoped_refptr<CefResourceManager::Request> request) OVERRIDE {
|
||||||
CEF_REQUIRE_IO_THREAD();
|
CEF_REQUIRE_IO_THREAD();
|
||||||
|
|
||||||
@ -526,8 +510,8 @@ class StringResourceProvider : public CefResourceManager::Provider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::string value;
|
std::string value;
|
||||||
StringResourceMap::const_iterator it = resource_map_.find(page);
|
StringResourceMap::const_iterator it = string_resource_map_->find(page);
|
||||||
if (it != resource_map_.end()) {
|
if (it != string_resource_map_->end()) {
|
||||||
value = it->second;
|
value = it->second;
|
||||||
} else {
|
} else {
|
||||||
value = "<html><body>No data available</body></html>";
|
value = "<html><body>No data available</body></html>";
|
||||||
@ -545,7 +529,7 @@ class StringResourceProvider : public CefResourceManager::Provider {
|
|||||||
const std::set<std::string> pages_;
|
const std::set<std::string> pages_;
|
||||||
|
|
||||||
// Only accessed on the IO thread.
|
// Only accessed on the IO thread.
|
||||||
StringResourceMap resource_map_;
|
StringResourceMap* string_resource_map_;
|
||||||
|
|
||||||
DISALLOW_COPY_AND_ASSIGN(StringResourceProvider);
|
DISALLOW_COPY_AND_ASSIGN(StringResourceProvider);
|
||||||
};
|
};
|
||||||
@ -810,10 +794,12 @@ std::string GetErrorString(cef_errorcode_t code) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetupResourceManager(CefRefPtr<CefResourceManager> resource_manager) {
|
void SetupResourceManager(CefRefPtr<CefResourceManager> resource_manager,
|
||||||
|
StringResourceMap* string_resource_map) {
|
||||||
if (!CefCurrentlyOn(TID_IO)) {
|
if (!CefCurrentlyOn(TID_IO)) {
|
||||||
// Execute on the browser IO thread.
|
// Execute on the browser IO thread.
|
||||||
CefPostTask(TID_IO, base::Bind(SetupResourceManager, resource_manager));
|
CefPostTask(TID_IO, base::Bind(SetupResourceManager, resource_manager,
|
||||||
|
string_resource_map));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -834,7 +820,8 @@ void SetupResourceManager(CefRefPtr<CefResourceManager> resource_manager) {
|
|||||||
string_pages.insert(kTestPluginInfoPage);
|
string_pages.insert(kTestPluginInfoPage);
|
||||||
|
|
||||||
// Add provider for string resources.
|
// Add provider for string resources.
|
||||||
resource_manager->AddProvider(new StringResourceProvider(string_pages), 0,
|
resource_manager->AddProvider(
|
||||||
|
new StringResourceProvider(string_pages, string_resource_map), 0,
|
||||||
std::string());
|
std::string());
|
||||||
|
|
||||||
// Add provider for bundled resource files.
|
// Add provider for bundled resource files.
|
||||||
|
@ -35,8 +35,11 @@ std::string GetDataURI(const std::string& data, const std::string& mime_type);
|
|||||||
// Returns the string representation of the specified error code.
|
// Returns the string representation of the specified error code.
|
||||||
std::string GetErrorString(cef_errorcode_t code);
|
std::string GetErrorString(cef_errorcode_t code);
|
||||||
|
|
||||||
|
typedef std::map<std::string, std::string> StringResourceMap;
|
||||||
|
|
||||||
// Set up the resource manager for tests.
|
// Set up the resource manager for tests.
|
||||||
void SetupResourceManager(CefRefPtr<CefResourceManager> resource_manager);
|
void SetupResourceManager(CefRefPtr<CefResourceManager> resource_manager,
|
||||||
|
StringResourceMap* string_resource_map);
|
||||||
|
|
||||||
// Show a JS alert message.
|
// Show a JS alert message.
|
||||||
void Alert(CefRefPtr<CefBrowser> browser, const std::string& message);
|
void Alert(CefRefPtr<CefBrowser> browser, const std::string& message);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user