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:
parent
80cfb3c97c
commit
13f2282754
|
@ -237,6 +237,8 @@
|
|||
'tests/cefclient/browser/client_prefs.cc',
|
||||
'tests/cefclient/browser/client_prefs.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.h',
|
||||
'tests/cefclient/browser/image_cache.cc',
|
||||
|
|
|
@ -5,10 +5,12 @@
|
|||
#include "tests/cefclient/browser/client_browser.h"
|
||||
#include "tests/cefclient/browser/main_context.h"
|
||||
|
||||
#include "include/base/cef_logging.h"
|
||||
#include "include/cef_command_line.h"
|
||||
#include "include/cef_crash_util.h"
|
||||
#include "include/cef_file_util.h"
|
||||
#include "tests/cefclient/browser/client_prefs.h"
|
||||
#include "tests/cefclient/browser/default_client_handler.h"
|
||||
#include "tests/shared/common/client_switches.h"
|
||||
|
||||
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:
|
||||
DISALLOW_COPY_AND_ASSIGN(ClientBrowserDelegate);
|
||||
IMPLEMENT_REFCOUNTING(ClientBrowserDelegate);
|
||||
|
|
|
@ -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
|
|
@ -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(kTestGetTextPage);
|
||||
|
||||
// Add provider for string resources.
|
||||
resource_manager->AddProvider(
|
||||
new StringResourceProvider(string_pages, string_resource_map), 0,
|
||||
std::string());
|
||||
if (string_resource_map) {
|
||||
// Add provider for string resources.
|
||||
resource_manager->AddProvider(
|
||||
new StringResourceProvider(string_pages, string_resource_map), 0,
|
||||
std::string());
|
||||
}
|
||||
|
||||
// Add provider for bundled resource files.
|
||||
#if defined(OS_WIN)
|
||||
|
|
|
@ -92,24 +92,21 @@ void ClientAppBrowser::OnBeforeCommandLineProcessing(
|
|||
void ClientAppBrowser::OnRegisterCustomPreferences(
|
||||
cef_preferences_type_t type,
|
||||
CefRawPtr<CefPreferenceRegistrar> registrar) {
|
||||
DelegateSet::iterator it = delegates_.begin();
|
||||
for (; it != delegates_.end(); ++it) {
|
||||
(*it)->OnRegisterCustomPreferences(this, type, registrar);
|
||||
for (auto& delegate : delegates_) {
|
||||
delegate->OnRegisterCustomPreferences(this, type, registrar);
|
||||
}
|
||||
}
|
||||
|
||||
void ClientAppBrowser::OnContextInitialized() {
|
||||
DelegateSet::iterator it = delegates_.begin();
|
||||
for (; it != delegates_.end(); ++it) {
|
||||
(*it)->OnContextInitialized(this);
|
||||
for (auto& delegate : delegates_) {
|
||||
delegate->OnContextInitialized(this);
|
||||
}
|
||||
}
|
||||
|
||||
void ClientAppBrowser::OnBeforeChildProcessLaunch(
|
||||
CefRefPtr<CefCommandLine> command_line) {
|
||||
DelegateSet::iterator it = delegates_.begin();
|
||||
for (; it != delegates_.end(); ++it) {
|
||||
(*it)->OnBeforeChildProcessLaunch(this, command_line);
|
||||
for (auto& delegate : delegates_) {
|
||||
delegate->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
|
||||
|
|
|
@ -34,6 +34,11 @@ class ClientAppBrowser : public ClientApp, public CefBrowserProcessHandler {
|
|||
virtual void OnBeforeChildProcessLaunch(
|
||||
CefRefPtr<ClientAppBrowser> app,
|
||||
CefRefPtr<CefCommandLine> command_line) {}
|
||||
|
||||
virtual CefRefPtr<CefClient> GetDefaultClient(
|
||||
CefRefPtr<ClientAppBrowser> app) {
|
||||
return nullptr;
|
||||
}
|
||||
};
|
||||
|
||||
typedef std::set<CefRefPtr<Delegate>> DelegateSet;
|
||||
|
@ -71,6 +76,7 @@ class ClientAppBrowser : public ClientApp, public CefBrowserProcessHandler {
|
|||
void OnBeforeChildProcessLaunch(
|
||||
CefRefPtr<CefCommandLine> command_line) override;
|
||||
void OnScheduleMessagePumpWork(int64 delay) override;
|
||||
CefRefPtr<CefClient> GetDefaultClient() override;
|
||||
|
||||
// Set of supported Delegates.
|
||||
DelegateSet delegates_;
|
||||
|
|
Loading…
Reference in New Issue