2013-04-03 20:20:59 +02:00
|
|
|
// Copyright (c) 2013 The Chromium Embedded Framework Authors. All rights
|
2012-04-03 03:34:16 +02:00
|
|
|
// reserved. Use of this source code is governed by a BSD-style license that
|
|
|
|
// can be found in the LICENSE file.
|
|
|
|
|
2016-11-18 00:52:42 +01:00
|
|
|
#include "tests/cefclient/browser/client_handler.h"
|
2015-01-26 20:34:26 +01:00
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
#include <stdio.h>
|
2013-04-16 21:23:00 +02:00
|
|
|
#include <algorithm>
|
2015-02-11 19:15:04 +01:00
|
|
|
#include <iomanip>
|
2012-04-03 03:34:16 +02:00
|
|
|
#include <sstream>
|
|
|
|
#include <string>
|
2013-04-16 21:23:00 +02:00
|
|
|
|
2021-06-17 22:08:01 +02:00
|
|
|
#include "include/base/cef_callback.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "include/cef_browser.h"
|
2022-03-22 19:31:30 +01:00
|
|
|
#include "include/cef_command_ids.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "include/cef_frame.h"
|
2015-04-09 16:59:34 +02:00
|
|
|
#include "include/cef_parser.h"
|
2022-07-04 11:49:15 +02:00
|
|
|
#include "include/cef_shared_process_message_builder.h"
|
2016-09-02 12:01:33 +02:00
|
|
|
#include "include/cef_ssl_status.h"
|
|
|
|
#include "include/cef_x509_certificate.h"
|
2014-07-15 00:18:51 +02:00
|
|
|
#include "include/wrapper/cef_closure_task.h"
|
2016-11-18 00:52:42 +01:00
|
|
|
#include "tests/cefclient/browser/main_context.h"
|
|
|
|
#include "tests/cefclient/browser/root_window_manager.h"
|
|
|
|
#include "tests/cefclient/browser/test_runner.h"
|
2017-08-04 00:55:19 +02:00
|
|
|
#include "tests/shared/browser/extension_util.h"
|
2016-11-18 00:52:42 +01:00
|
|
|
#include "tests/shared/browser/resource_util.h"
|
2022-07-04 11:49:15 +02:00
|
|
|
#include "tests/shared/common/binary_value_utils.h"
|
2016-11-18 00:52:42 +01:00
|
|
|
#include "tests/shared/common/client_switches.h"
|
2022-08-02 22:30:37 +02:00
|
|
|
#include "tests/shared/common/string_util.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2015-01-23 20:09:34 +01:00
|
|
|
namespace client {
|
|
|
|
|
2015-01-22 22:39:36 +01:00
|
|
|
#if defined(OS_WIN)
|
|
|
|
#define NEWLINE "\r\n"
|
|
|
|
#else
|
|
|
|
#define NEWLINE "\n"
|
|
|
|
#endif
|
|
|
|
|
2013-04-03 20:20:59 +02:00
|
|
|
namespace {
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2012-04-19 22:31:46 +02:00
|
|
|
// Custom menu command Ids.
|
|
|
|
enum client_menu_ids {
|
2017-05-17 11:29:28 +02:00
|
|
|
CLIENT_ID_SHOW_DEVTOOLS = MENU_ID_USER_FIRST,
|
2013-11-08 17:06:06 +01:00
|
|
|
CLIENT_ID_CLOSE_DEVTOOLS,
|
2014-10-11 02:12:01 +02:00
|
|
|
CLIENT_ID_INSPECT_ELEMENT,
|
2016-09-02 12:01:33 +02:00
|
|
|
CLIENT_ID_SHOW_SSL_INFO,
|
2020-06-09 19:48:00 +02:00
|
|
|
CLIENT_ID_CURSOR_CHANGE_DISABLED,
|
2022-06-30 09:31:18 +02:00
|
|
|
CLIENT_ID_MEDIA_HANDLING_DISABLED,
|
2020-06-13 02:54:08 +02:00
|
|
|
CLIENT_ID_OFFLINE,
|
2012-04-19 22:31:46 +02:00
|
|
|
CLIENT_ID_TESTMENU_SUBMENU,
|
|
|
|
CLIENT_ID_TESTMENU_CHECKITEM,
|
|
|
|
CLIENT_ID_TESTMENU_RADIOITEM1,
|
|
|
|
CLIENT_ID_TESTMENU_RADIOITEM2,
|
|
|
|
CLIENT_ID_TESTMENU_RADIOITEM3,
|
2024-03-29 17:48:33 +01:00
|
|
|
|
|
|
|
// Chrome theme selection.
|
|
|
|
CLIENT_ID_TESTMENU_THEME,
|
|
|
|
CLIENT_ID_TESTMENU_THEME_MODE_SYSTEM,
|
|
|
|
CLIENT_ID_TESTMENU_THEME_MODE_LIGHT,
|
|
|
|
CLIENT_ID_TESTMENU_THEME_MODE_DARK,
|
|
|
|
CLIENT_ID_TESTMENU_THEME_MODE_FIRST = CLIENT_ID_TESTMENU_THEME_MODE_SYSTEM,
|
|
|
|
CLIENT_ID_TESTMENU_THEME_MODE_LAST = CLIENT_ID_TESTMENU_THEME_MODE_DARK,
|
|
|
|
CLIENT_ID_TESTMENU_THEME_COLOR_DEFAULT,
|
|
|
|
CLIENT_ID_TESTMENU_THEME_COLOR_RED,
|
|
|
|
CLIENT_ID_TESTMENU_THEME_COLOR_GREEN,
|
|
|
|
CLIENT_ID_TESTMENU_THEME_COLOR_BLUE,
|
|
|
|
CLIENT_ID_TESTMENU_THEME_COLOR_FIRST = CLIENT_ID_TESTMENU_THEME_COLOR_DEFAULT,
|
|
|
|
CLIENT_ID_TESTMENU_THEME_COLOR_LAST = CLIENT_ID_TESTMENU_THEME_COLOR_BLUE,
|
|
|
|
CLIENT_ID_TESTMENU_THEME_CUSTOM,
|
2012-04-19 22:31:46 +02:00
|
|
|
};
|
|
|
|
|
2024-03-29 17:48:33 +01:00
|
|
|
// Constants for Chrome theme colors.
|
|
|
|
constexpr cef_color_t kColorTransparent = 0;
|
|
|
|
constexpr cef_color_t kColorRed = CefColorSetARGB(255, 255, 0, 0);
|
|
|
|
constexpr cef_color_t kColorGreen = CefColorSetARGB(255, 0, 255, 0);
|
|
|
|
constexpr cef_color_t kColorBlue = CefColorSetARGB(255, 0, 0, 255);
|
|
|
|
|
2022-07-04 11:49:15 +02:00
|
|
|
// Must match the value in client_renderer.cc.
|
2015-01-31 01:55:56 +01:00
|
|
|
const char kFocusedNodeChangedMessage[] = "ClientRenderer.FocusedNodeChanged";
|
|
|
|
|
2015-02-11 19:15:04 +01:00
|
|
|
std::string GetTimeString(const CefTime& value) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (value.GetTimeT() == 0) {
|
2015-02-11 19:15:04 +01:00
|
|
|
return "Unspecified";
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-02-11 19:15:04 +01:00
|
|
|
|
|
|
|
static const char* kMonths[] = {
|
2017-05-17 11:29:28 +02:00
|
|
|
"January", "February", "March", "April", "May", "June",
|
|
|
|
"July", "August", "September", "October", "November", "December"};
|
2015-02-11 19:15:04 +01:00
|
|
|
std::string month;
|
2023-01-02 23:59:03 +01:00
|
|
|
if (value.month >= 1 && value.month <= 12) {
|
2015-02-11 19:15:04 +01:00
|
|
|
month = kMonths[value.month - 1];
|
2023-01-02 23:59:03 +01:00
|
|
|
} else {
|
2015-02-11 19:15:04 +01:00
|
|
|
month = "Invalid";
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-02-11 19:15:04 +01:00
|
|
|
|
|
|
|
std::stringstream ss;
|
2017-05-17 11:29:28 +02:00
|
|
|
ss << month << " " << value.day_of_month << ", " << value.year << " "
|
|
|
|
<< std::setfill('0') << std::setw(2) << value.hour << ":"
|
|
|
|
<< std::setfill('0') << std::setw(2) << value.minute << ":"
|
|
|
|
<< std::setfill('0') << std::setw(2) << value.second;
|
2015-02-11 19:15:04 +01:00
|
|
|
return ss.str();
|
|
|
|
}
|
|
|
|
|
2022-05-31 22:28:43 +02:00
|
|
|
std::string GetTimeString(const CefBaseTime& value) {
|
|
|
|
CefTime time;
|
|
|
|
if (cef_time_from_basetime(value, &time)) {
|
|
|
|
return GetTimeString(time);
|
|
|
|
} else {
|
|
|
|
return "Invalid";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-11 19:15:04 +01:00
|
|
|
std::string GetBinaryString(CefRefPtr<CefBinaryValue> value) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!value.get()) {
|
2015-02-11 19:15:04 +01:00
|
|
|
return " ";
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-02-11 19:15:04 +01:00
|
|
|
|
|
|
|
// Retrieve the value.
|
|
|
|
const size_t size = value->GetSize();
|
|
|
|
std::string src;
|
|
|
|
src.resize(size);
|
|
|
|
value->GetData(const_cast<char*>(src.data()), size, 0);
|
|
|
|
|
|
|
|
// Encode the value.
|
|
|
|
return CefBase64Encode(src.data(), src.size());
|
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
#define FLAG(flag) \
|
|
|
|
if (status & flag) { \
|
|
|
|
result += std::string(#flag) + "<br/>"; \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define VALUE(val, def) \
|
|
|
|
if (val == def) { \
|
|
|
|
return std::string(#def); \
|
|
|
|
}
|
2016-09-02 12:01:33 +02:00
|
|
|
|
2015-12-18 19:03:03 +01:00
|
|
|
std::string GetCertStatusString(cef_cert_status_t status) {
|
|
|
|
std::string result;
|
|
|
|
|
|
|
|
FLAG(CERT_STATUS_COMMON_NAME_INVALID);
|
|
|
|
FLAG(CERT_STATUS_DATE_INVALID);
|
|
|
|
FLAG(CERT_STATUS_AUTHORITY_INVALID);
|
|
|
|
FLAG(CERT_STATUS_NO_REVOCATION_MECHANISM);
|
|
|
|
FLAG(CERT_STATUS_UNABLE_TO_CHECK_REVOCATION);
|
|
|
|
FLAG(CERT_STATUS_REVOKED);
|
|
|
|
FLAG(CERT_STATUS_INVALID);
|
|
|
|
FLAG(CERT_STATUS_WEAK_SIGNATURE_ALGORITHM);
|
|
|
|
FLAG(CERT_STATUS_NON_UNIQUE_NAME);
|
|
|
|
FLAG(CERT_STATUS_WEAK_KEY);
|
|
|
|
FLAG(CERT_STATUS_PINNED_KEY_MISSING);
|
|
|
|
FLAG(CERT_STATUS_NAME_CONSTRAINT_VIOLATION);
|
|
|
|
FLAG(CERT_STATUS_VALIDITY_TOO_LONG);
|
|
|
|
FLAG(CERT_STATUS_IS_EV);
|
|
|
|
FLAG(CERT_STATUS_REV_CHECKING_ENABLED);
|
|
|
|
FLAG(CERT_STATUS_SHA1_SIGNATURE_PRESENT);
|
|
|
|
FLAG(CERT_STATUS_CT_COMPLIANCE_FAILED);
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (result.empty()) {
|
2015-12-18 19:03:03 +01:00
|
|
|
return " ";
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-12-18 19:03:03 +01:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-09-02 12:01:33 +02:00
|
|
|
std::string GetSSLVersionString(cef_ssl_version_t version) {
|
|
|
|
VALUE(version, SSL_CONNECTION_VERSION_UNKNOWN);
|
|
|
|
VALUE(version, SSL_CONNECTION_VERSION_SSL2);
|
|
|
|
VALUE(version, SSL_CONNECTION_VERSION_SSL3);
|
|
|
|
VALUE(version, SSL_CONNECTION_VERSION_TLS1);
|
|
|
|
VALUE(version, SSL_CONNECTION_VERSION_TLS1_1);
|
|
|
|
VALUE(version, SSL_CONNECTION_VERSION_TLS1_2);
|
2019-06-03 10:55:36 +02:00
|
|
|
VALUE(version, SSL_CONNECTION_VERSION_TLS1_3);
|
2016-09-02 12:01:33 +02:00
|
|
|
VALUE(version, SSL_CONNECTION_VERSION_QUIC);
|
|
|
|
return std::string();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string GetContentStatusString(cef_ssl_content_status_t status) {
|
|
|
|
std::string result;
|
|
|
|
|
|
|
|
VALUE(status, SSL_CONTENT_NORMAL_CONTENT);
|
|
|
|
FLAG(SSL_CONTENT_DISPLAYED_INSECURE_CONTENT);
|
|
|
|
FLAG(SSL_CONTENT_RAN_INSECURE_CONTENT);
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (result.empty()) {
|
2016-09-02 12:01:33 +02:00
|
|
|
return " ";
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-09-02 12:01:33 +02:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2015-02-11 19:15:04 +01:00
|
|
|
// Load a data: URI containing the error message.
|
2024-04-17 18:01:26 +02:00
|
|
|
// Only used with Alloy style.
|
2015-02-11 19:15:04 +01:00
|
|
|
void LoadErrorPage(CefRefPtr<CefFrame> frame,
|
2024-03-12 20:47:10 +01:00
|
|
|
const std::string& title,
|
2015-02-11 19:15:04 +01:00
|
|
|
const std::string& failed_url,
|
2024-03-12 20:47:10 +01:00
|
|
|
const std::string& error_string,
|
2015-02-11 19:15:04 +01:00
|
|
|
const std::string& other_info) {
|
2024-04-17 18:01:26 +02:00
|
|
|
if (MainContext::Get()->UseChromeBootstrap()) {
|
2024-03-12 20:47:10 +01:00
|
|
|
// Use default error pages with Chrome runtime.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-02-11 19:15:04 +01:00
|
|
|
std::stringstream ss;
|
2024-03-12 20:47:10 +01:00
|
|
|
ss << "<html><head><title>" << title
|
|
|
|
<< "</title></head><body bgcolor=\"white\"><h3>" << title
|
|
|
|
<< "</h3>URL: <a href=\"" << failed_url << "\">" << failed_url
|
|
|
|
<< "</a><br/>Error: " << error_string;
|
2015-02-11 19:15:04 +01:00
|
|
|
|
2024-03-12 20:47:10 +01:00
|
|
|
if (!other_info.empty() && other_info != error_string) {
|
2015-02-11 19:15:04 +01:00
|
|
|
ss << "<br/>" << other_info;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-02-11 19:15:04 +01:00
|
|
|
|
|
|
|
ss << "</body></html>";
|
|
|
|
frame->LoadURL(test_runner::GetDataURI(ss.str(), "text/html"));
|
|
|
|
}
|
|
|
|
|
2016-09-02 12:01:33 +02:00
|
|
|
// Return HTML string with information about a certificate.
|
|
|
|
std::string GetCertificateInformation(CefRefPtr<CefX509Certificate> cert,
|
2017-05-17 11:29:28 +02:00
|
|
|
cef_cert_status_t certstatus) {
|
2016-09-02 12:01:33 +02:00
|
|
|
CefRefPtr<CefX509CertPrincipal> subject = cert->GetSubject();
|
|
|
|
CefRefPtr<CefX509CertPrincipal> issuer = cert->GetIssuer();
|
|
|
|
|
|
|
|
// Build a table showing certificate information. Various types of invalid
|
|
|
|
// certificates can be tested using https://badssl.com/.
|
|
|
|
std::stringstream ss;
|
|
|
|
ss << "<h3>X.509 Certificate Information:</h3>"
|
|
|
|
"<table border=1><tr><th>Field</th><th>Value</th></tr>";
|
|
|
|
|
|
|
|
if (certstatus != CERT_STATUS_NONE) {
|
2017-05-17 11:29:28 +02:00
|
|
|
ss << "<tr><td>Status</td><td>" << GetCertStatusString(certstatus)
|
|
|
|
<< "</td></tr>";
|
|
|
|
}
|
|
|
|
|
|
|
|
ss << "<tr><td>Subject</td><td>"
|
|
|
|
<< (subject.get() ? subject->GetDisplayName().ToString() : " ")
|
|
|
|
<< "</td></tr>"
|
|
|
|
"<tr><td>Issuer</td><td>"
|
|
|
|
<< (issuer.get() ? issuer->GetDisplayName().ToString() : " ")
|
|
|
|
<< "</td></tr>"
|
|
|
|
"<tr><td>Serial #*</td><td>"
|
|
|
|
<< GetBinaryString(cert->GetSerialNumber()) << "</td></tr>"
|
|
|
|
<< "<tr><td>Valid Start</td><td>" << GetTimeString(cert->GetValidStart())
|
|
|
|
<< "</td></tr>"
|
|
|
|
"<tr><td>Valid Expiry</td><td>"
|
|
|
|
<< GetTimeString(cert->GetValidExpiry()) << "</td></tr>";
|
2016-09-02 12:01:33 +02:00
|
|
|
|
|
|
|
CefX509Certificate::IssuerChainBinaryList der_chain_list;
|
|
|
|
CefX509Certificate::IssuerChainBinaryList pem_chain_list;
|
|
|
|
cert->GetDEREncodedIssuerChain(der_chain_list);
|
|
|
|
cert->GetPEMEncodedIssuerChain(pem_chain_list);
|
|
|
|
DCHECK_EQ(der_chain_list.size(), pem_chain_list.size());
|
|
|
|
|
|
|
|
der_chain_list.insert(der_chain_list.begin(), cert->GetDEREncoded());
|
|
|
|
pem_chain_list.insert(pem_chain_list.begin(), cert->GetPEMEncoded());
|
|
|
|
|
|
|
|
for (size_t i = 0U; i < der_chain_list.size(); ++i) {
|
|
|
|
ss << "<tr><td>DER Encoded*</td>"
|
2017-05-17 11:29:28 +02:00
|
|
|
"<td style=\"max-width:800px;overflow:scroll;\">"
|
|
|
|
<< GetBinaryString(der_chain_list[i])
|
|
|
|
<< "</td></tr>"
|
2016-09-02 12:01:33 +02:00
|
|
|
"<tr><td>PEM Encoded*</td>"
|
2017-05-17 11:29:28 +02:00
|
|
|
"<td style=\"max-width:800px;overflow:scroll;\">"
|
|
|
|
<< GetBinaryString(pem_chain_list[i]) << "</td></tr>";
|
2016-09-02 12:01:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ss << "</table> * Displayed value is base64 encoded.";
|
|
|
|
return ss.str();
|
|
|
|
}
|
|
|
|
|
2022-07-04 11:49:15 +02:00
|
|
|
void OnTestProcessMessageReceived(
|
|
|
|
const CefRefPtr<CefFrame>& frame,
|
|
|
|
const CefRefPtr<CefProcessMessage>& process_message,
|
|
|
|
const bv_utils::TimePoint& finish_time) {
|
|
|
|
DCHECK(process_message->IsValid());
|
|
|
|
|
|
|
|
CefRefPtr<CefListValue> input_args = process_message->GetArgumentList();
|
|
|
|
DCHECK_EQ(input_args->GetSize(), 1U);
|
|
|
|
|
|
|
|
const auto renderer_msg =
|
|
|
|
bv_utils::GetRendererMsgFromBinary(input_args->GetBinary(0));
|
|
|
|
|
|
|
|
CefRefPtr<CefProcessMessage> response =
|
|
|
|
CefProcessMessage::Create(bv_utils::kTestSendProcessMessage);
|
|
|
|
CefRefPtr<CefListValue> args = response->GetArgumentList();
|
|
|
|
|
|
|
|
const auto message_size = std::max(input_args->GetBinary(0)->GetSize(),
|
|
|
|
sizeof(bv_utils::BrowserMessage));
|
|
|
|
std::vector<uint8_t> data(message_size);
|
|
|
|
|
|
|
|
const auto browser_msg =
|
|
|
|
reinterpret_cast<bv_utils::BrowserMessage*>(data.data());
|
|
|
|
browser_msg->test_id = renderer_msg.test_id;
|
|
|
|
browser_msg->duration = finish_time - renderer_msg.start_time;
|
|
|
|
browser_msg->start_time = bv_utils::Now();
|
|
|
|
|
|
|
|
args->SetBinary(0, bv_utils::CreateCefBinaryValue(data));
|
|
|
|
frame->SendProcessMessage(PID_RENDERER, response);
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnTestSMRProcessMessageReceived(
|
|
|
|
const CefRefPtr<CefFrame>& frame,
|
|
|
|
const CefRefPtr<CefProcessMessage>& process_message,
|
|
|
|
const bv_utils::TimePoint& finish_time) {
|
|
|
|
DCHECK(process_message->IsValid());
|
|
|
|
|
|
|
|
CefRefPtr<CefSharedMemoryRegion> region =
|
|
|
|
process_message->GetSharedMemoryRegion();
|
|
|
|
DCHECK_GE(region->Size(), sizeof(bv_utils::RendererMessage));
|
|
|
|
|
|
|
|
const auto renderer_msg =
|
|
|
|
static_cast<const bv_utils::RendererMessage*>(region->Memory());
|
|
|
|
const auto message_size =
|
|
|
|
std::max(region->Size(), sizeof(bv_utils::BrowserMessage));
|
2023-10-18 21:41:33 +02:00
|
|
|
|
|
|
|
std::vector<uint8_t> data(message_size);
|
|
|
|
const auto browser_msg =
|
|
|
|
reinterpret_cast<bv_utils::BrowserMessage*>(data.data());
|
|
|
|
browser_msg->test_id = renderer_msg->test_id;
|
|
|
|
browser_msg->duration = finish_time - renderer_msg->start_time;
|
|
|
|
browser_msg->start_time = bv_utils::Now();
|
2022-07-04 11:49:15 +02:00
|
|
|
|
|
|
|
auto builder = CefSharedProcessMessageBuilder::Create(
|
|
|
|
bv_utils::kTestSendSMRProcessMessage, message_size);
|
|
|
|
|
2023-10-18 21:41:33 +02:00
|
|
|
bv_utils::CopyDataIntoMemory(data, builder->Memory());
|
2022-07-04 11:49:15 +02:00
|
|
|
|
|
|
|
frame->SendProcessMessage(PID_RENDERER, builder->Build());
|
|
|
|
}
|
|
|
|
|
2023-03-07 00:21:57 +01:00
|
|
|
bool IsAllowedPageActionIcon(cef_chrome_page_action_icon_type_t icon_type) {
|
|
|
|
// Only the specified icons will be allowed.
|
|
|
|
switch (icon_type) {
|
|
|
|
case CEF_CPAIT_FIND:
|
|
|
|
case CEF_CPAIT_ZOOM:
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsAllowedToolbarButton(cef_chrome_toolbar_button_type_t button_type) {
|
|
|
|
// All configurable buttons will be disabled.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsAllowedAppMenuCommandId(int command_id) {
|
|
|
|
// Only the commands in this array will be allowed.
|
|
|
|
static const int kAllowedCommandIds[] = {
|
|
|
|
IDC_NEW_WINDOW,
|
|
|
|
IDC_NEW_INCOGNITO_WINDOW,
|
|
|
|
|
|
|
|
// Zoom buttons.
|
|
|
|
IDC_ZOOM_MENU,
|
|
|
|
IDC_ZOOM_PLUS,
|
|
|
|
IDC_ZOOM_NORMAL,
|
|
|
|
IDC_ZOOM_MINUS,
|
|
|
|
IDC_FULLSCREEN,
|
|
|
|
|
|
|
|
IDC_PRINT,
|
|
|
|
IDC_FIND,
|
2023-04-19 02:08:02 +02:00
|
|
|
IDC_FIND_NEXT,
|
|
|
|
IDC_FIND_PREVIOUS,
|
2023-03-07 00:21:57 +01:00
|
|
|
|
|
|
|
// "More tools" sub-menu and contents.
|
|
|
|
IDC_MORE_TOOLS_MENU,
|
|
|
|
IDC_CLEAR_BROWSING_DATA,
|
|
|
|
IDC_MANAGE_EXTENSIONS,
|
|
|
|
IDC_PERFORMANCE,
|
|
|
|
IDC_TASK_MANAGER,
|
|
|
|
IDC_DEV_TOOLS,
|
|
|
|
|
|
|
|
// Edit buttons.
|
|
|
|
IDC_EDIT_MENU,
|
|
|
|
IDC_CUT,
|
|
|
|
IDC_COPY,
|
|
|
|
IDC_PASTE,
|
|
|
|
|
|
|
|
IDC_OPTIONS,
|
|
|
|
IDC_EXIT,
|
|
|
|
};
|
2024-01-20 03:22:56 +01:00
|
|
|
for (int kAllowedCommandId : kAllowedCommandIds) {
|
|
|
|
if (command_id == kAllowedCommandId) {
|
2023-03-07 00:21:57 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsAllowedContextMenuCommandId(int command_id) {
|
|
|
|
// Allow commands added by web content.
|
|
|
|
if (command_id >= IDC_CONTENT_CONTEXT_CUSTOM_FIRST &&
|
|
|
|
command_id <= IDC_CONTENT_CONTEXT_CUSTOM_LAST) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Allow commands added by extensions.
|
|
|
|
if (command_id >= IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST &&
|
|
|
|
command_id <= IDC_EXTENSIONS_CONTEXT_CUSTOM_LAST) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Only the commands in this array will be allowed.
|
|
|
|
static const int kAllowedCommandIds[] = {
|
|
|
|
// Page navigation.
|
|
|
|
IDC_BACK,
|
|
|
|
IDC_FORWARD,
|
|
|
|
IDC_RELOAD,
|
|
|
|
IDC_RELOAD_BYPASSING_CACHE,
|
|
|
|
IDC_RELOAD_CLEARING_CACHE,
|
|
|
|
IDC_STOP,
|
|
|
|
|
|
|
|
// Printing.
|
|
|
|
IDC_PRINT,
|
|
|
|
|
|
|
|
// Edit controls.
|
|
|
|
IDC_CONTENT_CONTEXT_CUT,
|
|
|
|
IDC_CONTENT_CONTEXT_COPY,
|
|
|
|
IDC_CONTENT_CONTEXT_PASTE,
|
|
|
|
IDC_CONTENT_CONTEXT_PASTE_AND_MATCH_STYLE,
|
|
|
|
IDC_CONTENT_CONTEXT_DELETE,
|
|
|
|
IDC_CONTENT_CONTEXT_SELECTALL,
|
|
|
|
IDC_CONTENT_CONTEXT_UNDO,
|
|
|
|
IDC_CONTENT_CONTEXT_REDO,
|
|
|
|
};
|
2024-01-20 03:22:56 +01:00
|
|
|
for (int kAllowedCommandId : kAllowedCommandIds) {
|
|
|
|
if (command_id == kAllowedCommandId) {
|
2023-03-07 00:21:57 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FilterContextMenuModel(CefRefPtr<CefMenuModel> model) {
|
|
|
|
// Evaluate from the bottom to the top because we'll be removing menu items.
|
|
|
|
for (size_t x = model->GetCount(); x > 0; --x) {
|
|
|
|
const auto i = x - 1;
|
|
|
|
const auto type = model->GetTypeAt(i);
|
|
|
|
if (type == MENUITEMTYPE_SUBMENU) {
|
|
|
|
// Filter sub-menu and remove if empty.
|
|
|
|
auto sub_model = model->GetSubMenuAt(i);
|
|
|
|
FilterContextMenuModel(sub_model);
|
|
|
|
if (sub_model->GetCount() == 0) {
|
|
|
|
model->RemoveAt(i);
|
|
|
|
}
|
|
|
|
} else if (type == MENUITEMTYPE_SEPARATOR) {
|
|
|
|
// A separator shouldn't be the first or last element in the menu, and
|
|
|
|
// there shouldn't be multiple in a row.
|
|
|
|
if (i == 0 || i == model->GetCount() - 1 ||
|
|
|
|
model->GetTypeAt(i + 1) == MENUITEMTYPE_SEPARATOR) {
|
|
|
|
model->RemoveAt(i);
|
|
|
|
}
|
|
|
|
} else if (!IsAllowedContextMenuCommandId(model->GetCommandIdAt(i))) {
|
|
|
|
model->RemoveAt(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-03 20:20:59 +02:00
|
|
|
} // namespace
|
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
class ClientDownloadImageCallback : public CefDownloadImageCallback {
|
|
|
|
public:
|
2017-05-17 11:29:28 +02:00
|
|
|
explicit ClientDownloadImageCallback(CefRefPtr<ClientHandler> client_handler)
|
|
|
|
: client_handler_(client_handler) {}
|
2016-01-19 21:09:01 +01:00
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
void OnDownloadImageFinished(const CefString& image_url,
|
|
|
|
int http_status_code,
|
2021-06-17 21:43:06 +02:00
|
|
|
CefRefPtr<CefImage> image) override {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (image) {
|
2016-01-19 21:09:01 +01:00
|
|
|
client_handler_->NotifyFavicon(image);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
CefRefPtr<ClientHandler> client_handler_;
|
|
|
|
|
|
|
|
IMPLEMENT_REFCOUNTING(ClientDownloadImageCallback);
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(ClientDownloadImageCallback);
|
|
|
|
};
|
|
|
|
|
2015-01-30 19:55:55 +01:00
|
|
|
ClientHandler::ClientHandler(Delegate* delegate,
|
|
|
|
bool is_osr,
|
2022-03-22 19:31:30 +01:00
|
|
|
bool with_controls,
|
2015-01-30 19:55:55 +01:00
|
|
|
const std::string& startup_url)
|
2024-04-17 18:01:26 +02:00
|
|
|
: use_views_(delegate ? delegate->UseViews()
|
|
|
|
: MainContext::Get()->UseViewsGlobal()),
|
|
|
|
use_alloy_style_(delegate ? delegate->UseAlloyStyle()
|
|
|
|
: MainContext::Get()->UseAlloyStyleGlobal()),
|
|
|
|
is_osr_(is_osr),
|
2022-03-22 19:31:30 +01:00
|
|
|
with_controls_(with_controls),
|
2017-05-17 11:29:28 +02:00
|
|
|
startup_url_(startup_url),
|
|
|
|
delegate_(delegate),
|
2023-01-03 19:53:40 +01:00
|
|
|
console_log_file_(MainContext::Get()->GetConsoleLogPath()) {
|
2015-01-23 21:03:47 +01:00
|
|
|
DCHECK(!console_log_file_.empty());
|
|
|
|
|
2012-06-26 18:47:05 +02:00
|
|
|
// Read command line settings.
|
|
|
|
CefRefPtr<CefCommandLine> command_line =
|
|
|
|
CefCommandLine::GetGlobalCommandLine();
|
2014-07-11 22:28:37 +02:00
|
|
|
mouse_cursor_change_disabled_ =
|
2015-01-23 20:09:34 +01:00
|
|
|
command_line->HasSwitch(switches::kMouseCursorChangeDisabled);
|
2020-06-13 02:54:08 +02:00
|
|
|
offline_ = command_line->HasSwitch(switches::kOffline);
|
2023-03-07 00:21:57 +01:00
|
|
|
filter_chrome_commands_ =
|
|
|
|
command_line->HasSwitch(switches::kFilterChromeCommands);
|
2022-04-15 21:55:23 +02:00
|
|
|
|
|
|
|
#if defined(OS_LINUX)
|
2022-06-02 11:49:50 +02:00
|
|
|
// Optionally use the client-provided GTK dialogs.
|
|
|
|
const bool use_client_dialogs =
|
2022-04-15 21:55:23 +02:00
|
|
|
command_line->HasSwitch(switches::kUseClientDialogs);
|
|
|
|
|
2022-06-02 11:49:50 +02:00
|
|
|
// Determine if the client-provided GTK dialogs can/should be used.
|
|
|
|
bool require_client_dialogs = false;
|
|
|
|
bool support_client_dialogs = true;
|
|
|
|
|
|
|
|
if (command_line->HasSwitch(switches::kMultiThreadedMessageLoop)) {
|
|
|
|
// Default/internal GTK dialogs are not supported in combination with
|
|
|
|
// multi-threaded-message-loop because Chromium doesn't support GDK threads.
|
|
|
|
// This does not apply to the JS dialogs which use Views instead of GTK.
|
|
|
|
if (!use_client_dialogs) {
|
|
|
|
LOG(WARNING) << "Client dialogs must be used in combination with "
|
|
|
|
"multi-threaded-message-loop.";
|
|
|
|
}
|
|
|
|
require_client_dialogs = true;
|
2022-04-15 21:55:23 +02:00
|
|
|
}
|
|
|
|
|
2024-04-17 18:01:26 +02:00
|
|
|
if (use_views_) {
|
2022-06-02 11:49:50 +02:00
|
|
|
// Client-provided GTK dialogs cannot be used in combination with Views
|
|
|
|
// because the implementation of ClientDialogHandlerGtk requires a top-level
|
|
|
|
// GtkWindow.
|
|
|
|
if (use_client_dialogs) {
|
|
|
|
LOG(ERROR) << "Client dialogs cannot be used in combination with Views.";
|
|
|
|
}
|
|
|
|
support_client_dialogs = false;
|
2022-04-15 21:55:23 +02:00
|
|
|
}
|
|
|
|
|
2022-06-02 11:49:50 +02:00
|
|
|
if (support_client_dialogs) {
|
|
|
|
if (use_client_dialogs) {
|
|
|
|
js_dialog_handler_ = new ClientDialogHandlerGtk();
|
|
|
|
}
|
|
|
|
if (use_client_dialogs || require_client_dialogs) {
|
|
|
|
file_dialog_handler_ = js_dialog_handler_ ? js_dialog_handler_
|
|
|
|
: new ClientDialogHandlerGtk();
|
|
|
|
print_handler_ = new ClientPrintHandlerGtk();
|
|
|
|
}
|
2022-04-15 21:55:23 +02:00
|
|
|
}
|
|
|
|
#endif // defined(OS_LINUX)
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2015-01-30 19:55:55 +01:00
|
|
|
void ClientHandler::DetachDelegate() {
|
|
|
|
if (!CURRENTLY_ON_MAIN_THREAD()) {
|
|
|
|
// Execute this method on the main thread.
|
2021-06-19 21:54:45 +02:00
|
|
|
MAIN_POST_CLOSURE(base::BindOnce(&ClientHandler::DetachDelegate, this));
|
2015-01-30 19:55:55 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
DCHECK(delegate_);
|
2020-01-15 15:28:12 +01:00
|
|
|
delegate_ = nullptr;
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2012-06-11 22:03:49 +02:00
|
|
|
bool ClientHandler::OnProcessMessageReceived(
|
2012-04-12 22:21:50 +02:00
|
|
|
CefRefPtr<CefBrowser> browser,
|
2019-05-24 22:23:43 +02:00
|
|
|
CefRefPtr<CefFrame> frame,
|
2012-04-12 22:21:50 +02:00
|
|
|
CefProcessId source_process,
|
|
|
|
CefRefPtr<CefProcessMessage> message) {
|
2014-07-15 00:18:51 +02:00
|
|
|
CEF_REQUIRE_UI_THREAD();
|
|
|
|
|
2022-07-04 11:49:15 +02:00
|
|
|
const auto finish_time = bv_utils::Now();
|
|
|
|
|
2024-03-12 20:47:10 +01:00
|
|
|
if (BaseClientHandler::OnProcessMessageReceived(browser, frame,
|
|
|
|
source_process, message)) {
|
2014-01-28 00:31:03 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-06-11 17:52:49 +02:00
|
|
|
// Check for messages from the client renderer.
|
2022-07-04 11:49:15 +02:00
|
|
|
const std::string& message_name = message->GetName();
|
2015-01-31 01:55:56 +01:00
|
|
|
if (message_name == kFocusedNodeChangedMessage) {
|
2012-06-11 17:52:49 +02:00
|
|
|
// A message is sent from ClientRenderDelegate to tell us whether the
|
2014-07-11 22:28:37 +02:00
|
|
|
// currently focused DOM node is editable. Use of |focus_on_editable_field_|
|
2012-06-11 17:52:49 +02:00
|
|
|
// is redundant with CefKeyEvent.focus_on_editable_field in OnPreKeyEvent
|
|
|
|
// but is useful for demonstration purposes.
|
2014-07-11 22:28:37 +02:00
|
|
|
focus_on_editable_field_ = message->GetArgumentList()->GetBool(0);
|
2012-06-11 17:52:49 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-07-04 11:49:15 +02:00
|
|
|
if (message_name == bv_utils::kTestSendProcessMessage) {
|
|
|
|
OnTestProcessMessageReceived(frame, message, finish_time);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (message_name == bv_utils::kTestSendSMRProcessMessage) {
|
|
|
|
OnTestSMRProcessMessageReceived(frame, message, finish_time);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-01-28 00:31:03 +01:00
|
|
|
return false;
|
2012-04-12 22:21:50 +02:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2022-03-22 19:31:30 +01:00
|
|
|
bool ClientHandler::OnChromeCommand(CefRefPtr<CefBrowser> browser,
|
|
|
|
int command_id,
|
|
|
|
cef_window_open_disposition_t disposition) {
|
|
|
|
CEF_REQUIRE_UI_THREAD();
|
2024-04-17 18:01:26 +02:00
|
|
|
DCHECK(!use_alloy_style_);
|
2022-03-22 19:31:30 +01:00
|
|
|
|
2023-03-07 00:21:57 +01:00
|
|
|
const bool allowed = IsAllowedAppMenuCommandId(command_id) ||
|
|
|
|
IsAllowedContextMenuCommandId(command_id);
|
|
|
|
|
|
|
|
bool block = false;
|
|
|
|
if (filter_chrome_commands_) {
|
|
|
|
// Block all commands that aren't specifically allowed.
|
|
|
|
block = !allowed;
|
|
|
|
} else if (!with_controls_) {
|
|
|
|
// If controls are hidden, block all commands that don't target the current
|
|
|
|
// tab or aren't specifically allowed.
|
2023-11-14 18:16:43 +01:00
|
|
|
block = disposition != CEF_WOD_CURRENT_TAB || !allowed;
|
2023-03-07 00:21:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (block) {
|
2022-03-22 19:31:30 +01:00
|
|
|
LOG(INFO) << "Blocking command " << command_id << " with disposition "
|
|
|
|
<< disposition;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Default handling.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-03-07 00:21:57 +01:00
|
|
|
bool ClientHandler::IsChromeAppMenuItemVisible(CefRefPtr<CefBrowser> browser,
|
|
|
|
int command_id) {
|
|
|
|
CEF_REQUIRE_UI_THREAD();
|
2024-04-17 18:01:26 +02:00
|
|
|
DCHECK(!use_alloy_style_);
|
2023-03-07 00:21:57 +01:00
|
|
|
if (!filter_chrome_commands_) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return IsAllowedAppMenuCommandId(command_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ClientHandler::IsChromePageActionIconVisible(
|
|
|
|
cef_chrome_page_action_icon_type_t icon_type) {
|
|
|
|
CEF_REQUIRE_UI_THREAD();
|
2024-04-17 18:01:26 +02:00
|
|
|
DCHECK(!use_alloy_style_);
|
2023-03-07 00:21:57 +01:00
|
|
|
if (!filter_chrome_commands_) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return IsAllowedPageActionIcon(icon_type);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ClientHandler::IsChromeToolbarButtonVisible(
|
|
|
|
cef_chrome_toolbar_button_type_t button_type) {
|
|
|
|
CEF_REQUIRE_UI_THREAD();
|
2024-04-17 18:01:26 +02:00
|
|
|
DCHECK(!use_alloy_style_);
|
2023-03-07 00:21:57 +01:00
|
|
|
if (!filter_chrome_commands_) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return IsAllowedToolbarButton(button_type);
|
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
void ClientHandler::OnBeforeContextMenu(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
CefRefPtr<CefContextMenuParams> params,
|
|
|
|
CefRefPtr<CefMenuModel> model) {
|
2014-07-15 00:18:51 +02:00
|
|
|
CEF_REQUIRE_UI_THREAD();
|
|
|
|
|
2024-04-17 18:01:26 +02:00
|
|
|
if (!use_alloy_style_ && (!with_controls_ || filter_chrome_commands_)) {
|
2022-03-22 19:31:30 +01:00
|
|
|
// Remove all disallowed menu items.
|
2023-03-07 00:21:57 +01:00
|
|
|
FilterContextMenuModel(model);
|
2022-03-22 19:31:30 +01:00
|
|
|
}
|
|
|
|
|
2012-06-11 17:52:49 +02:00
|
|
|
if ((params->GetTypeFlags() & (CM_TYPEFLAG_PAGE | CM_TYPEFLAG_FRAME)) != 0) {
|
|
|
|
// Add a separator if the menu already has items.
|
2023-01-02 23:59:03 +01:00
|
|
|
if (model->GetCount() > 0) {
|
2012-08-29 18:58:40 +02:00
|
|
|
model->AddSeparator();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-06-11 17:52:49 +02:00
|
|
|
|
2023-11-14 18:16:43 +01:00
|
|
|
// Add DevTools items to all context menus.
|
|
|
|
model->AddItem(CLIENT_ID_SHOW_DEVTOOLS, "&Show DevTools");
|
|
|
|
model->AddItem(CLIENT_ID_CLOSE_DEVTOOLS, "Close DevTools");
|
|
|
|
|
2024-04-17 18:01:26 +02:00
|
|
|
if (use_alloy_style_) {
|
|
|
|
// Chrome style already gives us an "Inspect" menu item.
|
2021-04-09 01:15:51 +02:00
|
|
|
model->AddSeparator();
|
|
|
|
model->AddItem(CLIENT_ID_INSPECT_ELEMENT, "Inspect Element");
|
|
|
|
}
|
2012-06-11 17:52:49 +02:00
|
|
|
|
2016-09-02 12:01:33 +02:00
|
|
|
if (HasSSLInformation(browser)) {
|
|
|
|
model->AddSeparator();
|
|
|
|
model->AddItem(CLIENT_ID_SHOW_SSL_INFO, "Show SSL information");
|
|
|
|
}
|
|
|
|
|
2024-04-17 18:01:26 +02:00
|
|
|
if (use_alloy_style_) {
|
2021-04-09 01:15:51 +02:00
|
|
|
// TODO(chrome-runtime): Add support for this.
|
|
|
|
model->AddSeparator();
|
|
|
|
model->AddCheckItem(CLIENT_ID_CURSOR_CHANGE_DISABLED,
|
|
|
|
"Cursor change disabled");
|
2023-01-02 23:59:03 +01:00
|
|
|
if (mouse_cursor_change_disabled_) {
|
2021-04-09 01:15:51 +02:00
|
|
|
model->SetChecked(CLIENT_ID_CURSOR_CHANGE_DISABLED, true);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2022-06-30 09:31:18 +02:00
|
|
|
|
|
|
|
model->AddSeparator();
|
|
|
|
model->AddCheckItem(CLIENT_ID_MEDIA_HANDLING_DISABLED,
|
|
|
|
"Media handling disabled");
|
2023-01-02 23:59:03 +01:00
|
|
|
if (media_handling_disabled_) {
|
2022-06-30 09:31:18 +02:00
|
|
|
model->SetChecked(CLIENT_ID_MEDIA_HANDLING_DISABLED, true);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2021-04-09 01:15:51 +02:00
|
|
|
}
|
2020-06-09 19:48:00 +02:00
|
|
|
|
2020-06-13 02:54:08 +02:00
|
|
|
model->AddSeparator();
|
2021-04-09 01:15:51 +02:00
|
|
|
model->AddCheckItem(CLIENT_ID_OFFLINE, "Offline mode");
|
2023-01-02 23:59:03 +01:00
|
|
|
if (offline_) {
|
2020-06-13 02:54:08 +02:00
|
|
|
model->SetChecked(CLIENT_ID_OFFLINE, true);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2020-06-13 02:54:08 +02:00
|
|
|
|
2012-06-11 17:52:49 +02:00
|
|
|
// Test context menu features.
|
2024-03-29 17:48:33 +01:00
|
|
|
BuildTestMenu(browser, model);
|
2012-06-11 17:52:49 +02:00
|
|
|
}
|
2017-02-25 06:03:31 +01:00
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (delegate_) {
|
2017-02-25 06:03:31 +01:00
|
|
|
delegate_->OnBeforeContextMenu(model);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-06-11 17:52:49 +02:00
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
bool ClientHandler::OnContextMenuCommand(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
CefRefPtr<CefContextMenuParams> params,
|
|
|
|
int command_id,
|
|
|
|
EventFlags event_flags) {
|
2014-07-15 00:18:51 +02:00
|
|
|
CEF_REQUIRE_UI_THREAD();
|
|
|
|
|
2012-06-11 17:52:49 +02:00
|
|
|
switch (command_id) {
|
|
|
|
case CLIENT_ID_SHOW_DEVTOOLS:
|
2014-10-11 02:12:01 +02:00
|
|
|
ShowDevTools(browser, CefPoint());
|
2012-06-11 17:52:49 +02:00
|
|
|
return true;
|
2013-11-08 17:06:06 +01:00
|
|
|
case CLIENT_ID_CLOSE_DEVTOOLS:
|
|
|
|
CloseDevTools(browser);
|
|
|
|
return true;
|
2014-10-11 02:12:01 +02:00
|
|
|
case CLIENT_ID_INSPECT_ELEMENT:
|
|
|
|
ShowDevTools(browser, CefPoint(params->GetXCoord(), params->GetYCoord()));
|
|
|
|
return true;
|
2016-09-02 12:01:33 +02:00
|
|
|
case CLIENT_ID_SHOW_SSL_INFO:
|
|
|
|
ShowSSLInformation(browser);
|
|
|
|
return true;
|
2020-06-09 19:48:00 +02:00
|
|
|
case CLIENT_ID_CURSOR_CHANGE_DISABLED:
|
2020-10-28 17:30:54 +01:00
|
|
|
mouse_cursor_change_disabled_ = !mouse_cursor_change_disabled_;
|
2020-06-09 19:48:00 +02:00
|
|
|
return true;
|
2022-06-30 09:31:18 +02:00
|
|
|
case CLIENT_ID_MEDIA_HANDLING_DISABLED:
|
|
|
|
media_handling_disabled_ = !media_handling_disabled_;
|
|
|
|
return true;
|
2020-06-13 02:54:08 +02:00
|
|
|
case CLIENT_ID_OFFLINE:
|
|
|
|
offline_ = !offline_;
|
|
|
|
SetOfflineState(browser, offline_);
|
|
|
|
return true;
|
2012-06-11 17:52:49 +02:00
|
|
|
default: // Allow default handling, if any.
|
2024-03-29 17:48:33 +01:00
|
|
|
return ExecuteTestMenu(browser, command_id);
|
2012-06-11 17:52:49 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-26 20:34:26 +01:00
|
|
|
void ClientHandler::OnAddressChange(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
const CefString& url) {
|
|
|
|
CEF_REQUIRE_UI_THREAD();
|
|
|
|
|
|
|
|
// Only update the address for the main (top-level) frame.
|
2023-01-02 23:59:03 +01:00
|
|
|
if (frame->IsMain()) {
|
2015-01-30 19:55:55 +01:00
|
|
|
NotifyAddress(url);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-01-26 20:34:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ClientHandler::OnTitleChange(CefRefPtr<CefBrowser> browser,
|
|
|
|
const CefString& title) {
|
|
|
|
CEF_REQUIRE_UI_THREAD();
|
|
|
|
|
2015-01-30 19:55:55 +01:00
|
|
|
NotifyTitle(title);
|
2015-01-26 20:34:26 +01:00
|
|
|
}
|
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
void ClientHandler::OnFaviconURLChange(
|
|
|
|
CefRefPtr<CefBrowser> browser,
|
|
|
|
const std::vector<CefString>& icon_urls) {
|
|
|
|
CEF_REQUIRE_UI_THREAD();
|
|
|
|
|
|
|
|
if (!icon_urls.empty() && download_favicon_images_) {
|
|
|
|
browser->GetHost()->DownloadImage(icon_urls[0], true, 16, false,
|
|
|
|
new ClientDownloadImageCallback(this));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-05 00:33:24 +02:00
|
|
|
void ClientHandler::OnFullscreenModeChange(CefRefPtr<CefBrowser> browser,
|
|
|
|
bool fullscreen) {
|
|
|
|
CEF_REQUIRE_UI_THREAD();
|
|
|
|
|
|
|
|
NotifyFullscreen(fullscreen);
|
|
|
|
}
|
|
|
|
|
2012-06-11 17:52:49 +02:00
|
|
|
bool ClientHandler::OnConsoleMessage(CefRefPtr<CefBrowser> browser,
|
2017-12-18 21:05:38 +01:00
|
|
|
cef_log_severity_t level,
|
2012-06-11 17:52:49 +02:00
|
|
|
const CefString& message,
|
|
|
|
const CefString& source,
|
|
|
|
int line) {
|
2014-07-11 22:10:05 +02:00
|
|
|
CEF_REQUIRE_UI_THREAD();
|
2012-06-11 17:52:49 +02:00
|
|
|
|
2015-01-22 22:39:36 +01:00
|
|
|
FILE* file = fopen(console_log_file_.c_str(), "a");
|
2012-06-11 17:52:49 +02:00
|
|
|
if (file) {
|
|
|
|
std::stringstream ss;
|
2017-12-18 21:05:38 +01:00
|
|
|
ss << "Level: ";
|
|
|
|
switch (level) {
|
|
|
|
case LOGSEVERITY_DEBUG:
|
|
|
|
ss << "Debug" << NEWLINE;
|
|
|
|
break;
|
|
|
|
case LOGSEVERITY_INFO:
|
|
|
|
ss << "Info" << NEWLINE;
|
|
|
|
break;
|
|
|
|
case LOGSEVERITY_WARNING:
|
|
|
|
ss << "Warn" << NEWLINE;
|
|
|
|
break;
|
|
|
|
case LOGSEVERITY_ERROR:
|
|
|
|
ss << "Error" << NEWLINE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NOTREACHED();
|
|
|
|
break;
|
|
|
|
}
|
2017-05-17 11:29:28 +02:00
|
|
|
ss << "Message: " << message.ToString() << NEWLINE
|
|
|
|
<< "Source: " << source.ToString() << NEWLINE << "Line: " << line
|
|
|
|
<< NEWLINE << "-----------------------" << NEWLINE;
|
2012-06-11 17:52:49 +02:00
|
|
|
fputs(ss.str().c_str(), file);
|
|
|
|
fclose(file);
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-08-04 00:55:19 +02:00
|
|
|
bool ClientHandler::OnAutoResize(CefRefPtr<CefBrowser> browser,
|
|
|
|
const CefSize& new_size) {
|
|
|
|
CEF_REQUIRE_UI_THREAD();
|
|
|
|
|
|
|
|
NotifyAutoResize(new_size);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-10-28 17:30:54 +01:00
|
|
|
bool ClientHandler::OnCursorChange(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefCursorHandle cursor,
|
|
|
|
cef_cursor_type_t type,
|
|
|
|
const CefCursorInfo& custom_cursor_info) {
|
|
|
|
CEF_REQUIRE_UI_THREAD();
|
|
|
|
|
|
|
|
// Return true to disable default handling of cursor changes.
|
|
|
|
return mouse_cursor_change_disabled_;
|
|
|
|
}
|
|
|
|
|
2022-03-22 22:40:28 +01:00
|
|
|
bool ClientHandler::CanDownload(CefRefPtr<CefBrowser> browser,
|
|
|
|
const CefString& url,
|
|
|
|
const CefString& request_method) {
|
|
|
|
CEF_REQUIRE_UI_THREAD();
|
|
|
|
|
|
|
|
if (!with_controls_) {
|
|
|
|
// Block the download.
|
|
|
|
LOG(INFO) << "Blocking download";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Allow the download.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-06-28 19:21:18 +02:00
|
|
|
void ClientHandler::OnBeforeDownload(
|
|
|
|
CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefDownloadItem> download_item,
|
|
|
|
const CefString& suggested_name,
|
|
|
|
CefRefPtr<CefBeforeDownloadCallback> callback) {
|
2014-07-11 22:10:05 +02:00
|
|
|
CEF_REQUIRE_UI_THREAD();
|
2014-07-15 00:18:51 +02:00
|
|
|
|
2012-06-28 19:21:18 +02:00
|
|
|
// Continue the download and show the "Save As" dialog.
|
2015-01-23 20:09:34 +01:00
|
|
|
callback->Continue(MainContext::Get()->GetDownloadPath(suggested_name), true);
|
2012-06-28 19:21:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ClientHandler::OnDownloadUpdated(
|
|
|
|
CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefDownloadItem> download_item,
|
|
|
|
CefRefPtr<CefDownloadItemCallback> callback) {
|
2014-07-11 22:10:05 +02:00
|
|
|
CEF_REQUIRE_UI_THREAD();
|
2014-07-15 00:18:51 +02:00
|
|
|
|
2012-06-28 19:21:18 +02:00
|
|
|
if (download_item->IsComplete()) {
|
2017-05-17 11:29:28 +02:00
|
|
|
test_runner::Alert(browser, "File \"" +
|
|
|
|
download_item->GetFullPath().ToString() +
|
|
|
|
"\" downloaded successfully.");
|
2012-06-28 19:21:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-24 17:45:58 +02:00
|
|
|
bool ClientHandler::OnDragEnter(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefDragData> dragData,
|
2014-07-01 00:30:29 +02:00
|
|
|
CefDragHandler::DragOperationsMask mask) {
|
2014-07-11 22:10:05 +02:00
|
|
|
CEF_REQUIRE_UI_THREAD();
|
2013-06-24 17:45:58 +02:00
|
|
|
|
2016-08-19 13:58:22 +02:00
|
|
|
// Forbid dragging of URLs and files.
|
|
|
|
if ((mask & DRAG_OPERATION_LINK) && !dragData->IsFragment()) {
|
2017-05-17 11:29:28 +02:00
|
|
|
test_runner::Alert(browser, "cefclient blocks dragging of URLs and files");
|
2013-06-24 17:45:58 +02:00
|
|
|
return true;
|
2016-08-19 13:58:22 +02:00
|
|
|
}
|
2013-06-24 17:45:58 +02:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-04-24 15:48:32 +02:00
|
|
|
void ClientHandler::OnDraggableRegionsChanged(
|
|
|
|
CefRefPtr<CefBrowser> browser,
|
2019-05-24 22:23:43 +02:00
|
|
|
CefRefPtr<CefFrame> frame,
|
2015-04-24 15:48:32 +02:00
|
|
|
const std::vector<CefDraggableRegion>& regions) {
|
|
|
|
CEF_REQUIRE_UI_THREAD();
|
|
|
|
|
|
|
|
NotifyDraggableRegions(regions);
|
|
|
|
}
|
|
|
|
|
2017-02-17 00:19:43 +01:00
|
|
|
void ClientHandler::OnTakeFocus(CefRefPtr<CefBrowser> browser, bool next) {
|
|
|
|
CEF_REQUIRE_UI_THREAD();
|
|
|
|
|
|
|
|
NotifyTakeFocus(next);
|
|
|
|
}
|
|
|
|
|
2019-02-07 22:36:31 +01:00
|
|
|
bool ClientHandler::OnSetFocus(CefRefPtr<CefBrowser> browser,
|
|
|
|
FocusSource source) {
|
|
|
|
CEF_REQUIRE_UI_THREAD();
|
|
|
|
|
|
|
|
if (initial_navigation_) {
|
|
|
|
CefRefPtr<CefCommandLine> command_line =
|
|
|
|
CefCommandLine::GetGlobalCommandLine();
|
|
|
|
if (command_line->HasSwitch(switches::kNoActivate)) {
|
|
|
|
// Don't give focus to the browser on creation.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-06-11 17:52:49 +02:00
|
|
|
bool ClientHandler::OnPreKeyEvent(CefRefPtr<CefBrowser> browser,
|
|
|
|
const CefKeyEvent& event,
|
|
|
|
CefEventHandle os_event,
|
|
|
|
bool* is_keyboard_shortcut) {
|
2014-07-15 00:18:51 +02:00
|
|
|
CEF_REQUIRE_UI_THREAD();
|
|
|
|
|
2022-01-14 18:15:24 +01:00
|
|
|
/*
|
2012-06-11 17:52:49 +02:00
|
|
|
if (!event.focus_on_editable_field && event.windows_key_code == 0x20) {
|
|
|
|
// Special handling for the space character when an input element does not
|
|
|
|
// have focus. Handling the event in OnPreKeyEvent() keeps the event from
|
|
|
|
// being processed in the renderer. If we instead handled the event in the
|
|
|
|
// OnKeyEvent() method the space key would cause the window to scroll in
|
|
|
|
// addition to showing the alert box.
|
2015-01-26 20:34:26 +01:00
|
|
|
if (event.type == KEYEVENT_RAWKEYDOWN)
|
|
|
|
test_runner::Alert(browser, "You pressed the space bar!");
|
2012-06-11 17:52:49 +02:00
|
|
|
return true;
|
|
|
|
}
|
2022-01-14 18:15:24 +01:00
|
|
|
*/
|
2012-06-11 17:52:49 +02:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-03-09 21:22:31 +01:00
|
|
|
bool ClientHandler::OnBeforePopup(
|
|
|
|
CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
const CefString& target_url,
|
|
|
|
const CefString& target_frame_name,
|
|
|
|
CefLifeSpanHandler::WindowOpenDisposition target_disposition,
|
|
|
|
bool user_gesture,
|
|
|
|
const CefPopupFeatures& popupFeatures,
|
|
|
|
CefWindowInfo& windowInfo,
|
|
|
|
CefRefPtr<CefClient>& client,
|
|
|
|
CefBrowserSettings& settings,
|
2019-03-19 10:42:54 +01:00
|
|
|
CefRefPtr<CefDictionaryValue>& extra_info,
|
2015-03-09 21:22:31 +01:00
|
|
|
bool* no_javascript_access) {
|
2017-05-31 17:33:30 +02:00
|
|
|
CEF_REQUIRE_UI_THREAD();
|
2014-07-15 00:18:51 +02:00
|
|
|
|
2023-11-14 18:16:43 +01:00
|
|
|
if (target_disposition == CEF_WOD_NEW_PICTURE_IN_PICTURE) {
|
2023-02-09 19:15:15 +01:00
|
|
|
// Use default handling for document picture-in-picture popups.
|
|
|
|
client = nullptr;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-11-14 18:16:43 +01:00
|
|
|
// Potentially create a new RootWindow for the popup browser that will be
|
|
|
|
// created asynchronously.
|
|
|
|
CreatePopupWindow(browser, /*is_devtools=*/false, popupFeatures, windowInfo,
|
|
|
|
client, settings);
|
|
|
|
|
|
|
|
// Allow popup creation.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClientHandler::OnBeforeDevToolsPopup(
|
|
|
|
CefRefPtr<CefBrowser> browser,
|
|
|
|
CefWindowInfo& windowInfo,
|
|
|
|
CefRefPtr<CefClient>& client,
|
|
|
|
CefBrowserSettings& settings,
|
|
|
|
CefRefPtr<CefDictionaryValue>& extra_info,
|
|
|
|
bool* use_default_window) {
|
|
|
|
CEF_REQUIRE_UI_THREAD();
|
|
|
|
|
|
|
|
// Potentially create a new RootWindow for the DevTools popup browser that
|
|
|
|
// will be created immediately after this method returns.
|
|
|
|
if (!CreatePopupWindow(browser, /*is_devtools=*/true, CefPopupFeatures(),
|
|
|
|
windowInfo, client, settings)) {
|
|
|
|
*use_default_window = true;
|
|
|
|
}
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
void ClientHandler::OnAfterCreated(CefRefPtr<CefBrowser> browser) {
|
2014-07-11 22:10:05 +02:00
|
|
|
CEF_REQUIRE_UI_THREAD();
|
2024-04-17 18:01:26 +02:00
|
|
|
|
|
|
|
// Sanity-check the configured runtime style.
|
|
|
|
CHECK_EQ(
|
|
|
|
use_alloy_style_ ? CEF_RUNTIME_STYLE_ALLOY : CEF_RUNTIME_STYLE_CHROME,
|
|
|
|
browser->GetHost()->GetRuntimeStyle());
|
|
|
|
|
2024-03-12 20:47:10 +01:00
|
|
|
BaseClientHandler::OnAfterCreated(browser);
|
2014-02-10 19:53:56 +01:00
|
|
|
|
2020-06-13 02:54:08 +02:00
|
|
|
// Set offline mode if requested via the command-line flag.
|
2023-01-02 23:59:03 +01:00
|
|
|
if (offline_) {
|
2020-06-13 02:54:08 +02:00
|
|
|
SetOfflineState(browser, true);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2020-06-13 02:54:08 +02:00
|
|
|
|
2017-08-04 00:55:19 +02:00
|
|
|
if (browser->GetHost()->GetExtension()) {
|
|
|
|
// Browsers hosting extension apps should auto-resize.
|
|
|
|
browser->GetHost()->SetAutoResizeEnabled(true, CefSize(20, 20),
|
|
|
|
CefSize(1000, 1000));
|
|
|
|
|
|
|
|
CefRefPtr<CefExtension> extension = browser->GetHost()->GetExtension();
|
|
|
|
if (extension_util::IsInternalExtension(extension->GetPath())) {
|
|
|
|
// Register the internal handler for extension resources.
|
2024-03-12 20:47:10 +01:00
|
|
|
extension_util::AddInternalExtensionToResourceManager(
|
|
|
|
extension, GetResourceManager());
|
2017-08-04 00:55:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-30 19:55:55 +01:00
|
|
|
NotifyBrowserCreated(browser);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ClientHandler::DoClose(CefRefPtr<CefBrowser> browser) {
|
2014-07-11 22:10:05 +02:00
|
|
|
CEF_REQUIRE_UI_THREAD();
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2015-01-30 19:55:55 +01:00
|
|
|
NotifyBrowserClosing(browser);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2013-03-19 23:59:33 +01:00
|
|
|
// Allow the close. For windowed browsers this will result in the OS close
|
|
|
|
// event being sent.
|
2012-04-03 03:34:16 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClientHandler::OnBeforeClose(CefRefPtr<CefBrowser> browser) {
|
2014-07-11 22:10:05 +02:00
|
|
|
CEF_REQUIRE_UI_THREAD();
|
2024-03-12 20:47:10 +01:00
|
|
|
BaseClientHandler::OnBeforeClose(browser);
|
2015-01-30 19:55:55 +01:00
|
|
|
NotifyBrowserClosed(browser);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2013-09-12 22:34:18 +02:00
|
|
|
void ClientHandler::OnLoadingStateChange(CefRefPtr<CefBrowser> browser,
|
|
|
|
bool isLoading,
|
|
|
|
bool canGoBack,
|
|
|
|
bool canGoForward) {
|
2014-07-11 22:10:05 +02:00
|
|
|
CEF_REQUIRE_UI_THREAD();
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2019-02-07 22:36:31 +01:00
|
|
|
if (!isLoading && initial_navigation_) {
|
|
|
|
initial_navigation_ = false;
|
|
|
|
}
|
|
|
|
|
2015-01-30 19:55:55 +01:00
|
|
|
NotifyLoadingState(isLoading, canGoBack, canGoForward);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ClientHandler::OnLoadError(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
ErrorCode errorCode,
|
|
|
|
const CefString& errorText,
|
|
|
|
const CefString& failedUrl) {
|
2014-07-11 22:10:05 +02:00
|
|
|
CEF_REQUIRE_UI_THREAD();
|
2012-04-11 20:00:55 +02:00
|
|
|
|
2012-06-11 19:35:23 +02:00
|
|
|
// Don't display an error for downloaded files.
|
2023-01-02 23:59:03 +01:00
|
|
|
if (errorCode == ERR_ABORTED) {
|
2012-06-11 19:35:23 +02:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-06-11 19:35:23 +02:00
|
|
|
|
2012-06-25 23:21:27 +02:00
|
|
|
// Don't display an error for external protocols that we allow the OS to
|
|
|
|
// handle. See OnProtocolExecution().
|
|
|
|
if (errorCode == ERR_UNKNOWN_URL_SCHEME) {
|
|
|
|
std::string urlStr = frame->GetURL();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (urlStr.find("spotify:") == 0) {
|
2012-06-25 23:21:27 +02:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-06-25 23:21:27 +02:00
|
|
|
}
|
|
|
|
|
2024-04-17 18:01:26 +02:00
|
|
|
if (use_alloy_style_) {
|
|
|
|
// Load the error page.
|
|
|
|
LoadErrorPage(frame, "Page failed to load", failedUrl,
|
|
|
|
test_runner::GetErrorString(errorCode), errorText);
|
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2022-06-30 09:31:18 +02:00
|
|
|
bool ClientHandler::OnRequestMediaAccessPermission(
|
|
|
|
CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
2022-07-07 12:01:24 +02:00
|
|
|
const CefString& requesting_origin,
|
2023-06-01 16:06:15 +02:00
|
|
|
uint32_t requested_permissions,
|
2022-06-30 09:31:18 +02:00
|
|
|
CefRefPtr<CefMediaAccessCallback> callback) {
|
|
|
|
callback->Continue(media_handling_disabled_ ? CEF_MEDIA_PERMISSION_NONE
|
|
|
|
: requested_permissions);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-03-09 21:22:31 +01:00
|
|
|
bool ClientHandler::OnOpenURLFromTab(
|
|
|
|
CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
const CefString& target_url,
|
|
|
|
CefRequestHandler::WindowOpenDisposition target_disposition,
|
|
|
|
bool user_gesture) {
|
2023-11-14 18:16:43 +01:00
|
|
|
if (target_disposition == CEF_WOD_NEW_BACKGROUND_TAB ||
|
|
|
|
target_disposition == CEF_WOD_NEW_FOREGROUND_TAB) {
|
2015-03-09 21:22:31 +01:00
|
|
|
// Handle middle-click and ctrl + left-click by opening the URL in a new
|
|
|
|
// browser window.
|
2021-06-19 21:54:45 +02:00
|
|
|
auto config = std::make_unique<RootWindowConfig>();
|
2022-03-22 19:31:30 +01:00
|
|
|
config->with_controls = with_controls_;
|
|
|
|
config->with_osr = is_osr_;
|
2021-06-19 21:54:45 +02:00
|
|
|
config->url = target_url;
|
|
|
|
MainContext::Get()->GetRootWindowManager()->CreateRootWindow(
|
|
|
|
std::move(config));
|
2015-03-09 21:22:31 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Open the URL in the current browser window.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-04-24 04:50:25 +02:00
|
|
|
CefRefPtr<CefResourceRequestHandler> ClientHandler::GetResourceRequestHandler(
|
2017-05-17 11:29:28 +02:00
|
|
|
CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
CefRefPtr<CefRequest> request,
|
2019-04-24 04:50:25 +02:00
|
|
|
bool is_navigation,
|
|
|
|
bool is_download,
|
|
|
|
const CefString& request_initiator,
|
|
|
|
bool& disable_default_handling) {
|
2014-07-15 00:18:51 +02:00
|
|
|
CEF_REQUIRE_IO_THREAD();
|
2019-04-24 04:50:25 +02:00
|
|
|
return this;
|
2015-12-05 03:58:56 +01:00
|
|
|
}
|
|
|
|
|
2019-07-12 22:44:43 +02:00
|
|
|
bool ClientHandler::GetAuthCredentials(CefRefPtr<CefBrowser> browser,
|
|
|
|
const CefString& origin_url,
|
|
|
|
bool isProxy,
|
|
|
|
const CefString& host,
|
|
|
|
int port,
|
|
|
|
const CefString& realm,
|
|
|
|
const CefString& scheme,
|
|
|
|
CefRefPtr<CefAuthCallback> callback) {
|
|
|
|
CEF_REQUIRE_IO_THREAD();
|
|
|
|
|
|
|
|
// Used for testing authentication with a proxy server.
|
|
|
|
// For example, CCProxy on Windows.
|
|
|
|
if (isProxy) {
|
|
|
|
callback->Continue("guest", "guest");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Used for testing authentication with https://jigsaw.w3.org/HTTP/.
|
|
|
|
if (host == "jigsaw.w3.org") {
|
|
|
|
callback->Continue("guest", "guest");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
bool ClientHandler::OnCertificateError(CefRefPtr<CefBrowser> browser,
|
|
|
|
ErrorCode cert_error,
|
|
|
|
const CefString& request_url,
|
|
|
|
CefRefPtr<CefSSLInfo> ssl_info,
|
2021-09-27 11:09:45 +02:00
|
|
|
CefRefPtr<CefCallback> callback) {
|
2015-02-11 19:15:04 +01:00
|
|
|
CEF_REQUIRE_UI_THREAD();
|
|
|
|
|
2022-08-09 21:43:00 +02:00
|
|
|
if (cert_error == ERR_CERT_COMMON_NAME_INVALID &&
|
|
|
|
request_url.ToString().find("https://www.magpcss.com/") == 0U) {
|
|
|
|
// Allow magpcss.com to load despite having a certificate common name of
|
|
|
|
// magpcss.org.
|
2021-09-27 11:09:45 +02:00
|
|
|
callback->Continue();
|
2017-07-27 01:19:27 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2024-04-17 18:01:26 +02:00
|
|
|
if (use_alloy_style_) {
|
|
|
|
if (auto cert = ssl_info->GetX509Certificate()) {
|
|
|
|
// Load the error page.
|
|
|
|
LoadErrorPage(browser->GetMainFrame(), "SSL certificate error",
|
|
|
|
request_url, test_runner::GetErrorString(cert_error),
|
|
|
|
GetCertificateInformation(cert, ssl_info->GetCertStatus()));
|
|
|
|
}
|
2015-12-18 19:03:03 +01:00
|
|
|
}
|
|
|
|
|
2015-02-11 19:15:04 +01:00
|
|
|
return false; // Cancel the request.
|
|
|
|
}
|
|
|
|
|
2016-10-27 19:57:12 +02:00
|
|
|
bool ClientHandler::OnSelectClientCertificate(
|
|
|
|
CefRefPtr<CefBrowser> browser,
|
|
|
|
bool isProxy,
|
|
|
|
const CefString& host,
|
|
|
|
int port,
|
2016-10-27 21:44:31 +02:00
|
|
|
const X509CertificateList& certificates,
|
2016-10-27 19:57:12 +02:00
|
|
|
CefRefPtr<CefSelectClientCertificateCallback> callback) {
|
|
|
|
CEF_REQUIRE_UI_THREAD();
|
|
|
|
|
|
|
|
CefRefPtr<CefCommandLine> command_line =
|
|
|
|
CefCommandLine::GetGlobalCommandLine();
|
|
|
|
if (!command_line->HasSwitch(switches::kSslClientCertificate)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::string& cert_name =
|
|
|
|
command_line->GetSwitchValue(switches::kSslClientCertificate);
|
|
|
|
|
|
|
|
if (cert_name.empty()) {
|
2020-01-15 15:28:12 +01:00
|
|
|
callback->Select(nullptr);
|
2016-10-27 19:57:12 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
std::vector<CefRefPtr<CefX509Certificate>>::const_iterator it =
|
2016-10-27 19:57:12 +02:00
|
|
|
certificates.begin();
|
|
|
|
for (; it != certificates.end(); ++it) {
|
|
|
|
CefString subject((*it)->GetSubject()->GetDisplayName());
|
|
|
|
if (subject == cert_name) {
|
|
|
|
callback->Select(*it);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-09-12 22:34:18 +02:00
|
|
|
void ClientHandler::OnRenderProcessTerminated(CefRefPtr<CefBrowser> browser,
|
2024-03-12 20:47:10 +01:00
|
|
|
TerminationStatus status,
|
|
|
|
int error_code,
|
|
|
|
const CefString& error_string) {
|
2014-07-15 00:18:51 +02:00
|
|
|
CEF_REQUIRE_UI_THREAD();
|
2024-03-12 20:47:10 +01:00
|
|
|
BaseClientHandler::OnRenderProcessTerminated(browser, status, error_code,
|
|
|
|
error_string);
|
2014-01-28 00:31:03 +01:00
|
|
|
|
2015-01-26 20:34:26 +01:00
|
|
|
// Don't reload if there's no start URL, or if the crash URL was specified.
|
2023-01-02 23:59:03 +01:00
|
|
|
if (startup_url_.empty() || startup_url_ == "chrome://crash") {
|
2015-01-26 20:34:26 +01:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-01-26 20:34:26 +01:00
|
|
|
|
2013-09-12 22:34:18 +02:00
|
|
|
CefRefPtr<CefFrame> frame = browser->GetMainFrame();
|
|
|
|
std::string url = frame->GetURL();
|
2014-07-01 00:30:29 +02:00
|
|
|
|
2015-01-26 20:34:26 +01:00
|
|
|
// Don't reload if the termination occurred before any URL had successfully
|
|
|
|
// loaded.
|
2023-01-02 23:59:03 +01:00
|
|
|
if (url.empty()) {
|
2014-07-01 00:30:29 +02:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2014-07-01 00:30:29 +02:00
|
|
|
|
2015-01-26 20:34:26 +01:00
|
|
|
// Convert URLs to lowercase for easier comparison.
|
2022-08-02 22:30:37 +02:00
|
|
|
url = AsciiStrToLower(url);
|
|
|
|
const std::string& start_url = AsciiStrToLower(startup_url_);
|
2014-07-01 00:30:29 +02:00
|
|
|
|
2015-01-26 20:34:26 +01:00
|
|
|
// Don't reload the URL that just resulted in termination.
|
2023-01-02 23:59:03 +01:00
|
|
|
if (url.find(start_url) == 0) {
|
2024-04-17 18:01:26 +02:00
|
|
|
if (use_alloy_style_) {
|
|
|
|
LoadErrorPage(frame, "Render process terminated", frame->GetURL(),
|
|
|
|
test_runner::GetErrorString(status) + " (" +
|
|
|
|
error_string.ToString() + ")",
|
|
|
|
std::string());
|
|
|
|
}
|
2014-07-01 00:30:29 +02:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2014-07-01 00:30:29 +02:00
|
|
|
|
2015-01-26 20:34:26 +01:00
|
|
|
frame->LoadURL(startup_url_);
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
2020-06-13 02:54:08 +02:00
|
|
|
void ClientHandler::OnDocumentAvailableInMainFrame(
|
|
|
|
CefRefPtr<CefBrowser> browser) {
|
|
|
|
CEF_REQUIRE_UI_THREAD();
|
|
|
|
|
|
|
|
// Restore offline mode after main frame navigation. Otherwise, offline state
|
|
|
|
// (e.g. `navigator.onLine`) might be wrong in the renderer process.
|
2023-01-02 23:59:03 +01:00
|
|
|
if (offline_) {
|
2020-06-13 02:54:08 +02:00
|
|
|
SetOfflineState(browser, true);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2020-06-13 02:54:08 +02:00
|
|
|
}
|
|
|
|
|
2019-04-24 04:50:25 +02:00
|
|
|
void ClientHandler::OnProtocolExecution(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
CefRefPtr<CefRequest> request,
|
|
|
|
bool& allow_os_execution) {
|
|
|
|
CEF_REQUIRE_IO_THREAD();
|
|
|
|
|
|
|
|
std::string urlStr = request->GetURL();
|
|
|
|
|
|
|
|
// Allow OS execution of Spotify URIs.
|
2023-01-02 23:59:03 +01:00
|
|
|
if (urlStr.find("spotify:") == 0) {
|
2019-04-24 04:50:25 +02:00
|
|
|
allow_os_execution = true;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2019-04-24 04:50:25 +02:00
|
|
|
}
|
|
|
|
|
2014-10-11 02:12:01 +02:00
|
|
|
void ClientHandler::ShowDevTools(CefRefPtr<CefBrowser> browser,
|
|
|
|
const CefPoint& inspect_element_at) {
|
2016-06-10 20:33:07 +02:00
|
|
|
if (!CefCurrentlyOn(TID_UI)) {
|
|
|
|
// Execute this method on the UI thread.
|
2021-06-19 21:54:45 +02:00
|
|
|
CefPostTask(TID_UI, base::BindOnce(&ClientHandler::ShowDevTools, this,
|
|
|
|
browser, inspect_element_at));
|
2016-06-10 20:33:07 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-11-08 17:06:06 +01:00
|
|
|
CefWindowInfo windowInfo;
|
2015-01-26 20:34:26 +01:00
|
|
|
CefRefPtr<CefClient> client;
|
2013-11-08 17:06:06 +01:00
|
|
|
CefBrowserSettings settings;
|
2012-06-26 18:47:05 +02:00
|
|
|
|
2016-06-10 20:33:07 +02:00
|
|
|
CefRefPtr<CefBrowserHost> host = browser->GetHost();
|
|
|
|
|
|
|
|
// Test if the DevTools browser already exists.
|
2024-04-17 18:01:26 +02:00
|
|
|
if (use_alloy_style_ && !host->HasDevTools() &&
|
|
|
|
!MainContext::Get()->UseChromeBootstrap()) {
|
2023-11-14 18:16:43 +01:00
|
|
|
// Potentially create a new RootWindow for the DevTools browser that will be
|
|
|
|
// created by ShowDevTools(). For Chrome runtime this occurs in
|
|
|
|
// OnBeforeDevToolsPopup instead.
|
|
|
|
CreatePopupWindow(browser, /*is_devtools=*/true, CefPopupFeatures(),
|
|
|
|
windowInfo, client, settings);
|
2016-06-10 20:33:07 +02:00
|
|
|
}
|
|
|
|
|
2023-11-14 18:16:43 +01:00
|
|
|
// Create the DevTools browser if it doesn't already exist.
|
|
|
|
// Otherwise, focus the existing DevTools browser and inspect the element
|
|
|
|
// at |inspect_element_at| if non-empty.
|
|
|
|
host->ShowDevTools(windowInfo, client, settings, inspect_element_at);
|
2013-11-08 17:06:06 +01:00
|
|
|
}
|
2012-06-26 18:47:05 +02:00
|
|
|
|
2013-11-08 17:06:06 +01:00
|
|
|
void ClientHandler::CloseDevTools(CefRefPtr<CefBrowser> browser) {
|
|
|
|
browser->GetHost()->CloseDevTools();
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
2012-04-12 22:21:50 +02:00
|
|
|
|
2016-09-02 12:01:33 +02:00
|
|
|
bool ClientHandler::HasSSLInformation(CefRefPtr<CefBrowser> browser) {
|
|
|
|
CefRefPtr<CefNavigationEntry> nav =
|
|
|
|
browser->GetHost()->GetVisibleNavigationEntry();
|
|
|
|
|
|
|
|
return (nav && nav->GetSSLStatus() &&
|
|
|
|
nav->GetSSLStatus()->IsSecureConnection());
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClientHandler::ShowSSLInformation(CefRefPtr<CefBrowser> browser) {
|
|
|
|
std::stringstream ss;
|
|
|
|
CefRefPtr<CefNavigationEntry> nav =
|
|
|
|
browser->GetHost()->GetVisibleNavigationEntry();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!nav) {
|
2016-09-02 12:01:33 +02:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-09-02 12:01:33 +02:00
|
|
|
|
|
|
|
CefRefPtr<CefSSLStatus> ssl = nav->GetSSLStatus();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!ssl) {
|
2016-09-02 12:01:33 +02:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-09-02 12:01:33 +02:00
|
|
|
|
|
|
|
ss << "<html><head><title>SSL Information</title></head>"
|
|
|
|
"<body bgcolor=\"white\">"
|
2017-05-17 11:29:28 +02:00
|
|
|
"<h3>SSL Connection</h3>"
|
|
|
|
<< "<table border=1><tr><th>Field</th><th>Value</th></tr>";
|
2016-09-02 12:01:33 +02:00
|
|
|
|
|
|
|
CefURLParts urlparts;
|
|
|
|
if (CefParseURL(nav->GetURL(), urlparts)) {
|
|
|
|
CefString port(&urlparts.port);
|
|
|
|
ss << "<tr><td>Server</td><td>" << CefString(&urlparts.host).ToString();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!port.empty()) {
|
2016-09-02 12:01:33 +02:00
|
|
|
ss << ":" << port.ToString();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-09-02 12:01:33 +02:00
|
|
|
ss << "</td></tr>";
|
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
ss << "<tr><td>SSL Version</td><td>"
|
|
|
|
<< GetSSLVersionString(ssl->GetSSLVersion()) << "</td></tr>";
|
|
|
|
ss << "<tr><td>Content Status</td><td>"
|
|
|
|
<< GetContentStatusString(ssl->GetContentStatus()) << "</td></tr>";
|
2016-09-02 12:01:33 +02:00
|
|
|
|
|
|
|
ss << "</table>";
|
|
|
|
|
|
|
|
CefRefPtr<CefX509Certificate> cert = ssl->GetX509Certificate();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (cert.get()) {
|
2016-09-02 12:01:33 +02:00
|
|
|
ss << GetCertificateInformation(cert, ssl->GetCertStatus());
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-09-02 12:01:33 +02:00
|
|
|
|
|
|
|
ss << "</body></html>";
|
|
|
|
|
2021-06-19 21:54:45 +02:00
|
|
|
auto config = std::make_unique<RootWindowConfig>();
|
|
|
|
config->with_controls = false;
|
2022-03-22 19:31:30 +01:00
|
|
|
config->with_osr = is_osr_;
|
2021-06-19 21:54:45 +02:00
|
|
|
config->url = test_runner::GetDataURI(ss.str(), "text/html");
|
|
|
|
MainContext::Get()->GetRootWindowManager()->CreateRootWindow(
|
|
|
|
std::move(config));
|
2016-09-02 12:01:33 +02:00
|
|
|
}
|
2015-01-30 19:55:55 +01:00
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
bool ClientHandler::CreatePopupWindow(CefRefPtr<CefBrowser> browser,
|
|
|
|
bool is_devtools,
|
|
|
|
const CefPopupFeatures& popupFeatures,
|
|
|
|
CefWindowInfo& windowInfo,
|
|
|
|
CefRefPtr<CefClient>& client,
|
|
|
|
CefBrowserSettings& settings) {
|
2017-05-31 17:33:30 +02:00
|
|
|
CEF_REQUIRE_UI_THREAD();
|
2015-01-30 19:55:55 +01:00
|
|
|
|
|
|
|
// The popup browser will be parented to a new native window.
|
|
|
|
// Don't show URL bar and navigation buttons on DevTools windows.
|
2023-11-14 18:16:43 +01:00
|
|
|
// May return nullptr if UseDefaultPopup() returns true.
|
|
|
|
return !!MainContext::Get()->GetRootWindowManager()->CreateRootWindowAsPopup(
|
2024-04-17 18:01:26 +02:00
|
|
|
use_views_, use_alloy_style_, with_controls_ && !is_devtools, is_osr_,
|
|
|
|
is_devtools, popupFeatures, windowInfo, client, settings);
|
2015-01-30 19:55:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ClientHandler::NotifyBrowserCreated(CefRefPtr<CefBrowser> browser) {
|
|
|
|
if (!CURRENTLY_ON_MAIN_THREAD()) {
|
|
|
|
// Execute this method on the main thread.
|
|
|
|
MAIN_POST_CLOSURE(
|
2021-06-19 21:54:45 +02:00
|
|
|
base::BindOnce(&ClientHandler::NotifyBrowserCreated, this, browser));
|
2015-01-30 19:55:55 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (delegate_) {
|
2015-01-30 19:55:55 +01:00
|
|
|
delegate_->OnBrowserCreated(browser);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-01-30 19:55:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ClientHandler::NotifyBrowserClosing(CefRefPtr<CefBrowser> browser) {
|
|
|
|
if (!CURRENTLY_ON_MAIN_THREAD()) {
|
|
|
|
// Execute this method on the main thread.
|
|
|
|
MAIN_POST_CLOSURE(
|
2021-06-19 21:54:45 +02:00
|
|
|
base::BindOnce(&ClientHandler::NotifyBrowserClosing, this, browser));
|
2015-01-30 19:55:55 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (delegate_) {
|
2015-01-30 19:55:55 +01:00
|
|
|
delegate_->OnBrowserClosing(browser);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-01-30 19:55:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ClientHandler::NotifyBrowserClosed(CefRefPtr<CefBrowser> browser) {
|
|
|
|
if (!CURRENTLY_ON_MAIN_THREAD()) {
|
|
|
|
// Execute this method on the main thread.
|
|
|
|
MAIN_POST_CLOSURE(
|
2021-06-19 21:54:45 +02:00
|
|
|
base::BindOnce(&ClientHandler::NotifyBrowserClosed, this, browser));
|
2015-01-30 19:55:55 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (delegate_) {
|
2015-01-30 19:55:55 +01:00
|
|
|
delegate_->OnBrowserClosed(browser);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-01-30 19:55:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ClientHandler::NotifyAddress(const CefString& url) {
|
|
|
|
if (!CURRENTLY_ON_MAIN_THREAD()) {
|
|
|
|
// Execute this method on the main thread.
|
2021-06-19 21:54:45 +02:00
|
|
|
MAIN_POST_CLOSURE(base::BindOnce(&ClientHandler::NotifyAddress, this, url));
|
2015-01-30 19:55:55 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (delegate_) {
|
2015-01-30 19:55:55 +01:00
|
|
|
delegate_->OnSetAddress(url);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-01-30 19:55:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ClientHandler::NotifyTitle(const CefString& title) {
|
|
|
|
if (!CURRENTLY_ON_MAIN_THREAD()) {
|
|
|
|
// Execute this method on the main thread.
|
2021-06-19 21:54:45 +02:00
|
|
|
MAIN_POST_CLOSURE(base::BindOnce(&ClientHandler::NotifyTitle, this, title));
|
2015-01-30 19:55:55 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (delegate_) {
|
2015-01-30 19:55:55 +01:00
|
|
|
delegate_->OnSetTitle(title);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-01-30 19:55:55 +01:00
|
|
|
}
|
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
void ClientHandler::NotifyFavicon(CefRefPtr<CefImage> image) {
|
|
|
|
if (!CURRENTLY_ON_MAIN_THREAD()) {
|
|
|
|
// Execute this method on the main thread.
|
2021-06-19 21:54:45 +02:00
|
|
|
MAIN_POST_CLOSURE(
|
|
|
|
base::BindOnce(&ClientHandler::NotifyFavicon, this, image));
|
2016-01-19 21:09:01 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (delegate_) {
|
2016-01-19 21:09:01 +01:00
|
|
|
delegate_->OnSetFavicon(image);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
2015-06-05 00:33:24 +02:00
|
|
|
void ClientHandler::NotifyFullscreen(bool fullscreen) {
|
|
|
|
if (!CURRENTLY_ON_MAIN_THREAD()) {
|
|
|
|
// Execute this method on the main thread.
|
|
|
|
MAIN_POST_CLOSURE(
|
2021-06-19 21:54:45 +02:00
|
|
|
base::BindOnce(&ClientHandler::NotifyFullscreen, this, fullscreen));
|
2015-06-05 00:33:24 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (delegate_) {
|
2015-06-05 00:33:24 +02:00
|
|
|
delegate_->OnSetFullscreen(fullscreen);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-06-05 00:33:24 +02:00
|
|
|
}
|
|
|
|
|
2017-08-04 00:55:19 +02:00
|
|
|
void ClientHandler::NotifyAutoResize(const CefSize& new_size) {
|
|
|
|
if (!CURRENTLY_ON_MAIN_THREAD()) {
|
|
|
|
// Execute this method on the main thread.
|
|
|
|
MAIN_POST_CLOSURE(
|
2021-06-19 21:54:45 +02:00
|
|
|
base::BindOnce(&ClientHandler::NotifyAutoResize, this, new_size));
|
2017-08-04 00:55:19 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (delegate_) {
|
2017-08-04 00:55:19 +02:00
|
|
|
delegate_->OnAutoResize(new_size);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2017-08-04 00:55:19 +02:00
|
|
|
}
|
|
|
|
|
2015-01-30 19:55:55 +01:00
|
|
|
void ClientHandler::NotifyLoadingState(bool isLoading,
|
|
|
|
bool canGoBack,
|
|
|
|
bool canGoForward) {
|
|
|
|
if (!CURRENTLY_ON_MAIN_THREAD()) {
|
|
|
|
// Execute this method on the main thread.
|
2021-06-19 21:54:45 +02:00
|
|
|
MAIN_POST_CLOSURE(base::BindOnce(&ClientHandler::NotifyLoadingState, this,
|
|
|
|
isLoading, canGoBack, canGoForward));
|
2015-01-30 19:55:55 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (delegate_) {
|
2015-01-30 19:55:55 +01:00
|
|
|
delegate_->OnSetLoadingState(isLoading, canGoBack, canGoForward);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-01-30 19:55:55 +01:00
|
|
|
}
|
|
|
|
|
2015-04-24 15:48:32 +02:00
|
|
|
void ClientHandler::NotifyDraggableRegions(
|
|
|
|
const std::vector<CefDraggableRegion>& regions) {
|
|
|
|
if (!CURRENTLY_ON_MAIN_THREAD()) {
|
|
|
|
// Execute this method on the main thread.
|
|
|
|
MAIN_POST_CLOSURE(
|
2021-06-19 21:54:45 +02:00
|
|
|
base::BindOnce(&ClientHandler::NotifyDraggableRegions, this, regions));
|
2015-04-24 15:48:32 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (delegate_) {
|
2015-04-24 15:48:32 +02:00
|
|
|
delegate_->OnSetDraggableRegions(regions);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-04-24 15:48:32 +02:00
|
|
|
}
|
|
|
|
|
2017-02-17 00:19:43 +01:00
|
|
|
void ClientHandler::NotifyTakeFocus(bool next) {
|
|
|
|
if (!CURRENTLY_ON_MAIN_THREAD()) {
|
|
|
|
// Execute this method on the main thread.
|
2021-06-19 21:54:45 +02:00
|
|
|
MAIN_POST_CLOSURE(
|
|
|
|
base::BindOnce(&ClientHandler::NotifyTakeFocus, this, next));
|
2017-02-17 00:19:43 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (delegate_) {
|
2017-02-17 00:19:43 +01:00
|
|
|
delegate_->OnTakeFocus(next);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2017-02-17 00:19:43 +01:00
|
|
|
}
|
|
|
|
|
2024-03-29 17:48:33 +01:00
|
|
|
void ClientHandler::BuildTestMenu(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefMenuModel> model) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (model->GetCount() > 0) {
|
2012-08-29 18:58:40 +02:00
|
|
|
model->AddSeparator();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-19 22:31:46 +02:00
|
|
|
|
|
|
|
// Build the sub menu.
|
|
|
|
CefRefPtr<CefMenuModel> submenu =
|
|
|
|
model->AddSubMenu(CLIENT_ID_TESTMENU_SUBMENU, "Context Menu Test");
|
|
|
|
submenu->AddCheckItem(CLIENT_ID_TESTMENU_CHECKITEM, "Check Item");
|
|
|
|
submenu->AddRadioItem(CLIENT_ID_TESTMENU_RADIOITEM1, "Radio Item 1", 0);
|
|
|
|
submenu->AddRadioItem(CLIENT_ID_TESTMENU_RADIOITEM2, "Radio Item 2", 0);
|
|
|
|
submenu->AddRadioItem(CLIENT_ID_TESTMENU_RADIOITEM3, "Radio Item 3", 0);
|
|
|
|
|
|
|
|
// Check the check item.
|
2023-01-02 23:59:03 +01:00
|
|
|
if (test_menu_state_.check_item) {
|
2012-04-19 22:31:46 +02:00
|
|
|
submenu->SetChecked(CLIENT_ID_TESTMENU_CHECKITEM, true);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-19 22:31:46 +02:00
|
|
|
|
|
|
|
// Check the selected radio item.
|
|
|
|
submenu->SetChecked(
|
2014-07-11 22:28:37 +02:00
|
|
|
CLIENT_ID_TESTMENU_RADIOITEM1 + test_menu_state_.radio_item, true);
|
2024-03-29 17:48:33 +01:00
|
|
|
|
|
|
|
// Build the theme sub menu.
|
|
|
|
CefRefPtr<CefMenuModel> theme_menu =
|
|
|
|
model->AddSubMenu(CLIENT_ID_TESTMENU_THEME, "Theme");
|
|
|
|
theme_menu->AddRadioItem(CLIENT_ID_TESTMENU_THEME_MODE_SYSTEM, "System", 1);
|
|
|
|
theme_menu->AddRadioItem(CLIENT_ID_TESTMENU_THEME_MODE_LIGHT, "Light", 1);
|
|
|
|
theme_menu->AddRadioItem(CLIENT_ID_TESTMENU_THEME_MODE_DARK, "Dark", 1);
|
|
|
|
theme_menu->AddSeparator();
|
|
|
|
theme_menu->AddRadioItem(CLIENT_ID_TESTMENU_THEME_COLOR_DEFAULT, "Default",
|
|
|
|
2);
|
|
|
|
theme_menu->AddRadioItem(CLIENT_ID_TESTMENU_THEME_COLOR_RED, "Red", 2);
|
|
|
|
theme_menu->AddRadioItem(CLIENT_ID_TESTMENU_THEME_COLOR_GREEN, "Green", 2);
|
|
|
|
theme_menu->AddRadioItem(CLIENT_ID_TESTMENU_THEME_COLOR_BLUE, "Blue", 2);
|
|
|
|
|
2024-04-17 18:01:26 +02:00
|
|
|
if (!use_alloy_style_) {
|
2024-03-29 17:48:33 +01:00
|
|
|
theme_menu->AddSeparator();
|
|
|
|
theme_menu->AddItem(CLIENT_ID_TESTMENU_THEME_CUSTOM, "Custom...");
|
|
|
|
}
|
|
|
|
|
|
|
|
auto request_context = browser->GetHost()->GetRequestContext();
|
|
|
|
|
|
|
|
int checked_mode_item = -1;
|
|
|
|
switch (request_context->GetChromeColorSchemeMode()) {
|
|
|
|
case CEF_COLOR_VARIANT_SYSTEM:
|
|
|
|
checked_mode_item = CLIENT_ID_TESTMENU_THEME_MODE_SYSTEM;
|
|
|
|
break;
|
|
|
|
case CEF_COLOR_VARIANT_LIGHT:
|
|
|
|
checked_mode_item = CLIENT_ID_TESTMENU_THEME_MODE_LIGHT;
|
|
|
|
break;
|
|
|
|
case CEF_COLOR_VARIANT_DARK:
|
|
|
|
checked_mode_item = CLIENT_ID_TESTMENU_THEME_MODE_DARK;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NOTREACHED();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
int checked_color_item = -1;
|
|
|
|
const cef_color_t color = request_context->GetChromeColorSchemeColor();
|
|
|
|
if (color == kColorTransparent) {
|
|
|
|
checked_color_item = CLIENT_ID_TESTMENU_THEME_COLOR_DEFAULT;
|
|
|
|
} else if (color == kColorRed) {
|
|
|
|
checked_color_item = CLIENT_ID_TESTMENU_THEME_COLOR_RED;
|
|
|
|
} else if (color == kColorGreen) {
|
|
|
|
checked_color_item = CLIENT_ID_TESTMENU_THEME_COLOR_GREEN;
|
|
|
|
} else if (color == kColorBlue) {
|
|
|
|
checked_color_item = CLIENT_ID_TESTMENU_THEME_COLOR_BLUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check the selected radio item, if any.
|
|
|
|
if (checked_mode_item != -1) {
|
|
|
|
theme_menu->SetChecked(checked_mode_item, true);
|
|
|
|
|
|
|
|
// Update the selected item.
|
|
|
|
test_menu_state_.chrome_theme_mode_item =
|
|
|
|
checked_mode_item - CLIENT_ID_TESTMENU_THEME_MODE_FIRST;
|
|
|
|
}
|
|
|
|
if (checked_color_item != -1) {
|
|
|
|
theme_menu->SetChecked(checked_color_item, true);
|
|
|
|
|
|
|
|
// Update the selected item.
|
|
|
|
test_menu_state_.chrome_theme_color_item =
|
|
|
|
checked_color_item - CLIENT_ID_TESTMENU_THEME_COLOR_FIRST;
|
|
|
|
}
|
2012-04-19 22:31:46 +02:00
|
|
|
}
|
|
|
|
|
2024-03-29 17:48:33 +01:00
|
|
|
bool ClientHandler::ExecuteTestMenu(CefRefPtr<CefBrowser> browser,
|
|
|
|
int command_id) {
|
2012-04-19 22:31:46 +02:00
|
|
|
if (command_id == CLIENT_ID_TESTMENU_CHECKITEM) {
|
|
|
|
// Toggle the check item.
|
2014-07-11 22:28:37 +02:00
|
|
|
test_menu_state_.check_item ^= 1;
|
2012-04-19 22:31:46 +02:00
|
|
|
return true;
|
|
|
|
} else if (command_id >= CLIENT_ID_TESTMENU_RADIOITEM1 &&
|
|
|
|
command_id <= CLIENT_ID_TESTMENU_RADIOITEM3) {
|
|
|
|
// Store the selected radio item.
|
2014-07-11 22:28:37 +02:00
|
|
|
test_menu_state_.radio_item = (command_id - CLIENT_ID_TESTMENU_RADIOITEM1);
|
2012-04-19 22:31:46 +02:00
|
|
|
return true;
|
2024-03-29 17:48:33 +01:00
|
|
|
} else if (command_id >= CLIENT_ID_TESTMENU_THEME_MODE_FIRST &&
|
|
|
|
command_id <= CLIENT_ID_TESTMENU_THEME_COLOR_LAST) {
|
|
|
|
int selected_mode_item = test_menu_state_.chrome_theme_mode_item;
|
|
|
|
if (command_id >= CLIENT_ID_TESTMENU_THEME_MODE_FIRST &&
|
|
|
|
command_id <= CLIENT_ID_TESTMENU_THEME_MODE_LAST) {
|
|
|
|
selected_mode_item = command_id - CLIENT_ID_TESTMENU_THEME_MODE_FIRST;
|
|
|
|
if (selected_mode_item != test_menu_state_.chrome_theme_mode_item) {
|
|
|
|
// Update the selected item.
|
|
|
|
test_menu_state_.chrome_theme_mode_item = selected_mode_item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int selected_color_item = test_menu_state_.chrome_theme_color_item;
|
|
|
|
if (command_id >= CLIENT_ID_TESTMENU_THEME_COLOR_FIRST &&
|
|
|
|
command_id <= CLIENT_ID_TESTMENU_THEME_COLOR_LAST) {
|
|
|
|
selected_color_item = command_id - CLIENT_ID_TESTMENU_THEME_COLOR_FIRST;
|
|
|
|
if (selected_color_item != test_menu_state_.chrome_theme_color_item) {
|
|
|
|
// Udpate the selected item.
|
|
|
|
test_menu_state_.chrome_theme_color_item = selected_color_item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Don't change the color mode unless a selection has been made.
|
|
|
|
cef_color_variant_t variant = CEF_COLOR_VARIANT_TONAL_SPOT;
|
|
|
|
if (selected_mode_item != -1) {
|
|
|
|
switch (CLIENT_ID_TESTMENU_THEME_MODE_FIRST + selected_mode_item) {
|
|
|
|
case CLIENT_ID_TESTMENU_THEME_MODE_SYSTEM:
|
|
|
|
variant = CEF_COLOR_VARIANT_SYSTEM;
|
|
|
|
break;
|
|
|
|
case CLIENT_ID_TESTMENU_THEME_MODE_LIGHT:
|
|
|
|
variant = CEF_COLOR_VARIANT_LIGHT;
|
|
|
|
break;
|
|
|
|
case CLIENT_ID_TESTMENU_THEME_MODE_DARK:
|
|
|
|
variant = CEF_COLOR_VARIANT_DARK;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Don't change the user color unless a selection has been made.
|
|
|
|
cef_color_t color = kColorTransparent;
|
|
|
|
if (selected_color_item != -1) {
|
|
|
|
switch (CLIENT_ID_TESTMENU_THEME_COLOR_FIRST + selected_color_item) {
|
|
|
|
case CLIENT_ID_TESTMENU_THEME_COLOR_RED:
|
|
|
|
color = kColorRed;
|
|
|
|
break;
|
|
|
|
case CLIENT_ID_TESTMENU_THEME_COLOR_GREEN:
|
|
|
|
color = kColorGreen;
|
|
|
|
break;
|
|
|
|
case CLIENT_ID_TESTMENU_THEME_COLOR_BLUE:
|
|
|
|
color = kColorBlue;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
browser->GetHost()->GetRequestContext()->SetChromeColorScheme(variant,
|
|
|
|
color);
|
|
|
|
return true;
|
|
|
|
} else if (command_id == CLIENT_ID_TESTMENU_THEME_CUSTOM) {
|
|
|
|
browser->GetMainFrame()->LoadURL("chrome://settings/manageProfile");
|
|
|
|
return true;
|
2012-04-19 22:31:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Allow default handling to proceed.
|
|
|
|
return false;
|
|
|
|
}
|
2015-01-23 20:09:34 +01:00
|
|
|
|
2020-06-13 02:54:08 +02:00
|
|
|
void ClientHandler::SetOfflineState(CefRefPtr<CefBrowser> browser,
|
|
|
|
bool offline) {
|
|
|
|
// See DevTools protocol docs for message format specification.
|
|
|
|
CefRefPtr<CefDictionaryValue> params = CefDictionaryValue::Create();
|
|
|
|
params->SetBool("offline", offline);
|
|
|
|
params->SetDouble("latency", 0);
|
|
|
|
params->SetDouble("downloadThroughput", 0);
|
|
|
|
params->SetDouble("uploadThroughput", 0);
|
|
|
|
browser->GetHost()->ExecuteDevToolsMethod(
|
|
|
|
/*message_id=*/0, "Network.emulateNetworkConditions", params);
|
|
|
|
}
|
|
|
|
|
2015-01-23 20:09:34 +01:00
|
|
|
} // namespace client
|