mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-06-05 21:39:12 +02:00
chrome: cefclient: Add default handler for request tests (see issue #3444)
Support loading of request tests (e.g. http://tests/other_tests) inside default browsers created via "New window" and "New incognito window" commands.
This commit is contained in:
@ -237,6 +237,8 @@
|
|||||||
'tests/cefclient/browser/client_prefs.cc',
|
'tests/cefclient/browser/client_prefs.cc',
|
||||||
'tests/cefclient/browser/client_prefs.h',
|
'tests/cefclient/browser/client_prefs.h',
|
||||||
'tests/cefclient/browser/client_types.h',
|
'tests/cefclient/browser/client_types.h',
|
||||||
|
'tests/cefclient/browser/default_client_handler.cc',
|
||||||
|
'tests/cefclient/browser/default_client_handler.h',
|
||||||
'tests/cefclient/browser/dialog_test.cc',
|
'tests/cefclient/browser/dialog_test.cc',
|
||||||
'tests/cefclient/browser/dialog_test.h',
|
'tests/cefclient/browser/dialog_test.h',
|
||||||
'tests/cefclient/browser/image_cache.cc',
|
'tests/cefclient/browser/image_cache.cc',
|
||||||
|
@ -5,10 +5,12 @@
|
|||||||
#include "tests/cefclient/browser/client_browser.h"
|
#include "tests/cefclient/browser/client_browser.h"
|
||||||
#include "tests/cefclient/browser/main_context.h"
|
#include "tests/cefclient/browser/main_context.h"
|
||||||
|
|
||||||
|
#include "include/base/cef_logging.h"
|
||||||
#include "include/cef_command_line.h"
|
#include "include/cef_command_line.h"
|
||||||
#include "include/cef_crash_util.h"
|
#include "include/cef_crash_util.h"
|
||||||
#include "include/cef_file_util.h"
|
#include "include/cef_file_util.h"
|
||||||
#include "tests/cefclient/browser/client_prefs.h"
|
#include "tests/cefclient/browser/client_prefs.h"
|
||||||
|
#include "tests/cefclient/browser/default_client_handler.h"
|
||||||
#include "tests/shared/common/client_switches.h"
|
#include "tests/shared/common/client_switches.h"
|
||||||
|
|
||||||
namespace client {
|
namespace client {
|
||||||
@ -60,6 +62,14 @@ class ClientBrowserDelegate : public ClientAppBrowser::Delegate {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CefRefPtr<CefClient> GetDefaultClient(
|
||||||
|
CefRefPtr<ClientAppBrowser> app) override {
|
||||||
|
// Default client handler for unmanaged browser windows. Used with the
|
||||||
|
// Chrome runtime only.
|
||||||
|
LOG(INFO) << "Creating a chrome browser with the default client";
|
||||||
|
return new DefaultClientHandler();
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DISALLOW_COPY_AND_ASSIGN(ClientBrowserDelegate);
|
DISALLOW_COPY_AND_ASSIGN(ClientBrowserDelegate);
|
||||||
IMPLEMENT_REFCOUNTING(ClientBrowserDelegate);
|
IMPLEMENT_REFCOUNTING(ClientBrowserDelegate);
|
||||||
|
60
tests/cefclient/browser/default_client_handler.cc
Normal file
60
tests/cefclient/browser/default_client_handler.cc
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
// Copyright (c) 2023 The Chromium Embedded Framework 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 "tests/cefclient/browser/default_client_handler.h"
|
||||||
|
|
||||||
|
#include "tests/cefclient/browser/test_runner.h"
|
||||||
|
|
||||||
|
namespace client {
|
||||||
|
|
||||||
|
DefaultClientHandler::DefaultClientHandler() {
|
||||||
|
resource_manager_ = new CefResourceManager();
|
||||||
|
test_runner::SetupResourceManager(resource_manager_, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
CefRefPtr<CefResourceRequestHandler>
|
||||||
|
DefaultClientHandler::GetResourceRequestHandler(
|
||||||
|
CefRefPtr<CefBrowser> browser,
|
||||||
|
CefRefPtr<CefFrame> frame,
|
||||||
|
CefRefPtr<CefRequest> request,
|
||||||
|
bool is_navigation,
|
||||||
|
bool is_download,
|
||||||
|
const CefString& request_initiator,
|
||||||
|
bool& disable_default_handling) {
|
||||||
|
CEF_REQUIRE_IO_THREAD();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
cef_return_value_t DefaultClientHandler::OnBeforeResourceLoad(
|
||||||
|
CefRefPtr<CefBrowser> browser,
|
||||||
|
CefRefPtr<CefFrame> frame,
|
||||||
|
CefRefPtr<CefRequest> request,
|
||||||
|
CefRefPtr<CefCallback> callback) {
|
||||||
|
CEF_REQUIRE_IO_THREAD();
|
||||||
|
|
||||||
|
return resource_manager_->OnBeforeResourceLoad(browser, frame, request,
|
||||||
|
callback);
|
||||||
|
}
|
||||||
|
|
||||||
|
CefRefPtr<CefResourceHandler> DefaultClientHandler::GetResourceHandler(
|
||||||
|
CefRefPtr<CefBrowser> browser,
|
||||||
|
CefRefPtr<CefFrame> frame,
|
||||||
|
CefRefPtr<CefRequest> request) {
|
||||||
|
CEF_REQUIRE_IO_THREAD();
|
||||||
|
|
||||||
|
return resource_manager_->GetResourceHandler(browser, frame, request);
|
||||||
|
}
|
||||||
|
|
||||||
|
CefRefPtr<CefResponseFilter> DefaultClientHandler::GetResourceResponseFilter(
|
||||||
|
CefRefPtr<CefBrowser> browser,
|
||||||
|
CefRefPtr<CefFrame> frame,
|
||||||
|
CefRefPtr<CefRequest> request,
|
||||||
|
CefRefPtr<CefResponse> response) {
|
||||||
|
CEF_REQUIRE_IO_THREAD();
|
||||||
|
|
||||||
|
return test_runner::GetResourceResponseFilter(browser, frame, request,
|
||||||
|
response);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace client
|
61
tests/cefclient/browser/default_client_handler.h
Normal file
61
tests/cefclient/browser/default_client_handler.h
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
// Copyright (c) 2023 The Chromium Embedded Framework 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_TESTS_CEFCLIENT_BROWSER_DEFAULT_CLIENT_HANDLER_H_
|
||||||
|
#define CEF_TESTS_CEFCLIENT_BROWSER_DEFAULT_CLIENT_HANDLER_H_
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "include/cef_client.h"
|
||||||
|
#include "include/wrapper/cef_resource_manager.h"
|
||||||
|
|
||||||
|
namespace client {
|
||||||
|
|
||||||
|
// Default client handler for unmanaged browser windows. Used with the Chrome
|
||||||
|
// runtime only.
|
||||||
|
class DefaultClientHandler : public CefClient,
|
||||||
|
public CefRequestHandler,
|
||||||
|
public CefResourceRequestHandler {
|
||||||
|
public:
|
||||||
|
DefaultClientHandler();
|
||||||
|
|
||||||
|
// CefClient methods
|
||||||
|
CefRefPtr<CefRequestHandler> GetRequestHandler() override { return this; }
|
||||||
|
|
||||||
|
// CefRequestHandler methods
|
||||||
|
CefRefPtr<CefResourceRequestHandler> GetResourceRequestHandler(
|
||||||
|
CefRefPtr<CefBrowser> browser,
|
||||||
|
CefRefPtr<CefFrame> frame,
|
||||||
|
CefRefPtr<CefRequest> request,
|
||||||
|
bool is_navigation,
|
||||||
|
bool is_download,
|
||||||
|
const CefString& request_initiator,
|
||||||
|
bool& disable_default_handling) override;
|
||||||
|
|
||||||
|
// CefResourceRequestHandler methods
|
||||||
|
cef_return_value_t OnBeforeResourceLoad(
|
||||||
|
CefRefPtr<CefBrowser> browser,
|
||||||
|
CefRefPtr<CefFrame> frame,
|
||||||
|
CefRefPtr<CefRequest> request,
|
||||||
|
CefRefPtr<CefCallback> callback) override;
|
||||||
|
CefRefPtr<CefResourceHandler> GetResourceHandler(
|
||||||
|
CefRefPtr<CefBrowser> browser,
|
||||||
|
CefRefPtr<CefFrame> frame,
|
||||||
|
CefRefPtr<CefRequest> request) override;
|
||||||
|
CefRefPtr<CefResponseFilter> GetResourceResponseFilter(
|
||||||
|
CefRefPtr<CefBrowser> browser,
|
||||||
|
CefRefPtr<CefFrame> frame,
|
||||||
|
CefRefPtr<CefRequest> request,
|
||||||
|
CefRefPtr<CefResponse> response) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
// Manages the registration and delivery of resources.
|
||||||
|
CefRefPtr<CefResourceManager> resource_manager_;
|
||||||
|
|
||||||
|
IMPLEMENT_REFCOUNTING(DefaultClientHandler);
|
||||||
|
DISALLOW_COPY_AND_ASSIGN(DefaultClientHandler);
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace client
|
||||||
|
|
||||||
|
#endif // CEF_TESTS_CEFCLIENT_BROWSER_DEFAULT_CLIENT_HANDLER_H_
|
@ -772,10 +772,12 @@ void SetupResourceManager(CefRefPtr<CefResourceManager> resource_manager,
|
|||||||
string_pages.insert(kTestGetSourcePage);
|
string_pages.insert(kTestGetSourcePage);
|
||||||
string_pages.insert(kTestGetTextPage);
|
string_pages.insert(kTestGetTextPage);
|
||||||
|
|
||||||
// Add provider for string resources.
|
if (string_resource_map) {
|
||||||
resource_manager->AddProvider(
|
// Add provider for string resources.
|
||||||
new StringResourceProvider(string_pages, string_resource_map), 0,
|
resource_manager->AddProvider(
|
||||||
std::string());
|
new StringResourceProvider(string_pages, string_resource_map), 0,
|
||||||
|
std::string());
|
||||||
|
}
|
||||||
|
|
||||||
// Add provider for bundled resource files.
|
// Add provider for bundled resource files.
|
||||||
#if defined(OS_WIN)
|
#if defined(OS_WIN)
|
||||||
|
@ -92,24 +92,21 @@ void ClientAppBrowser::OnBeforeCommandLineProcessing(
|
|||||||
void ClientAppBrowser::OnRegisterCustomPreferences(
|
void ClientAppBrowser::OnRegisterCustomPreferences(
|
||||||
cef_preferences_type_t type,
|
cef_preferences_type_t type,
|
||||||
CefRawPtr<CefPreferenceRegistrar> registrar) {
|
CefRawPtr<CefPreferenceRegistrar> registrar) {
|
||||||
DelegateSet::iterator it = delegates_.begin();
|
for (auto& delegate : delegates_) {
|
||||||
for (; it != delegates_.end(); ++it) {
|
delegate->OnRegisterCustomPreferences(this, type, registrar);
|
||||||
(*it)->OnRegisterCustomPreferences(this, type, registrar);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClientAppBrowser::OnContextInitialized() {
|
void ClientAppBrowser::OnContextInitialized() {
|
||||||
DelegateSet::iterator it = delegates_.begin();
|
for (auto& delegate : delegates_) {
|
||||||
for (; it != delegates_.end(); ++it) {
|
delegate->OnContextInitialized(this);
|
||||||
(*it)->OnContextInitialized(this);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClientAppBrowser::OnBeforeChildProcessLaunch(
|
void ClientAppBrowser::OnBeforeChildProcessLaunch(
|
||||||
CefRefPtr<CefCommandLine> command_line) {
|
CefRefPtr<CefCommandLine> command_line) {
|
||||||
DelegateSet::iterator it = delegates_.begin();
|
for (auto& delegate : delegates_) {
|
||||||
for (; it != delegates_.end(); ++it) {
|
delegate->OnBeforeChildProcessLaunch(this, command_line);
|
||||||
(*it)->OnBeforeChildProcessLaunch(this, command_line);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -122,4 +119,13 @@ void ClientAppBrowser::OnScheduleMessagePumpWork(int64 delay) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CefRefPtr<CefClient> ClientAppBrowser::GetDefaultClient() {
|
||||||
|
for (auto& delegate : delegates_) {
|
||||||
|
if (auto client = delegate->GetDefaultClient(this)) {
|
||||||
|
return client;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace client
|
} // namespace client
|
||||||
|
@ -34,6 +34,11 @@ class ClientAppBrowser : public ClientApp, public CefBrowserProcessHandler {
|
|||||||
virtual void OnBeforeChildProcessLaunch(
|
virtual void OnBeforeChildProcessLaunch(
|
||||||
CefRefPtr<ClientAppBrowser> app,
|
CefRefPtr<ClientAppBrowser> app,
|
||||||
CefRefPtr<CefCommandLine> command_line) {}
|
CefRefPtr<CefCommandLine> command_line) {}
|
||||||
|
|
||||||
|
virtual CefRefPtr<CefClient> GetDefaultClient(
|
||||||
|
CefRefPtr<ClientAppBrowser> app) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::set<CefRefPtr<Delegate>> DelegateSet;
|
typedef std::set<CefRefPtr<Delegate>> DelegateSet;
|
||||||
@ -71,6 +76,7 @@ class ClientAppBrowser : public ClientApp, public CefBrowserProcessHandler {
|
|||||||
void OnBeforeChildProcessLaunch(
|
void OnBeforeChildProcessLaunch(
|
||||||
CefRefPtr<CefCommandLine> command_line) override;
|
CefRefPtr<CefCommandLine> command_line) override;
|
||||||
void OnScheduleMessagePumpWork(int64 delay) override;
|
void OnScheduleMessagePumpWork(int64 delay) override;
|
||||||
|
CefRefPtr<CefClient> GetDefaultClient() override;
|
||||||
|
|
||||||
// Set of supported Delegates.
|
// Set of supported Delegates.
|
||||||
DelegateSet delegates_;
|
DelegateSet delegates_;
|
||||||
|
Reference in New Issue
Block a user