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
|
|
|
|
2014-07-15 00:18:51 +02:00
|
|
|
#include "include/base/cef_bind.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "include/cef_browser.h"
|
|
|
|
#include "include/cef_frame.h"
|
2015-04-09 16:59:34 +02:00
|
|
|
#include "include/cef_parser.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"
|
|
|
|
#include "tests/shared/common/client_switches.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,
|
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,
|
|
|
|
};
|
|
|
|
|
2015-01-31 01:55:56 +01:00
|
|
|
// Musr match the value in client_renderer.cc.
|
|
|
|
const char kFocusedNodeChangedMessage[] = "ClientRenderer.FocusedNodeChanged";
|
|
|
|
|
2015-02-11 19:15:04 +01:00
|
|
|
std::string GetTimeString(const CefTime& value) {
|
|
|
|
if (value.GetTimeT() == 0)
|
|
|
|
return "Unspecified";
|
|
|
|
|
|
|
|
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;
|
|
|
|
if (value.month >= 1 && value.month <= 12)
|
|
|
|
month = kMonths[value.month - 1];
|
|
|
|
else
|
|
|
|
month = "Invalid";
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string GetBinaryString(CefRefPtr<CefBinaryValue> value) {
|
|
|
|
if (!value.get())
|
|
|
|
return " ";
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
|
|
|
|
if (result.empty())
|
|
|
|
return " ";
|
|
|
|
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);
|
|
|
|
|
|
|
|
if (result.empty())
|
|
|
|
return " ";
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2015-02-11 19:15:04 +01:00
|
|
|
// Load a data: URI containing the error message.
|
|
|
|
void LoadErrorPage(CefRefPtr<CefFrame> frame,
|
|
|
|
const std::string& failed_url,
|
|
|
|
cef_errorcode_t error_code,
|
|
|
|
const std::string& other_info) {
|
|
|
|
std::stringstream ss;
|
|
|
|
ss << "<html><head><title>Page failed to load</title></head>"
|
|
|
|
"<body bgcolor=\"white\">"
|
|
|
|
"<h3>Page failed to load.</h3>"
|
2017-05-17 11:29:28 +02:00
|
|
|
"URL: <a href=\""
|
|
|
|
<< failed_url << "\">" << failed_url
|
|
|
|
<< "</a><br/>Error: " << test_runner::GetErrorString(error_code) << " ("
|
|
|
|
<< error_code << ")";
|
2015-02-11 19:15:04 +01:00
|
|
|
|
|
|
|
if (!other_info.empty())
|
|
|
|
ss << "<br/>" << other_info;
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
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,
|
|
|
|
CefRefPtr<CefImage> image) OVERRIDE {
|
2016-01-19 21:09:01 +01:00
|
|
|
if (image)
|
|
|
|
client_handler_->NotifyFavicon(image);
|
|
|
|
}
|
|
|
|
|
|
|
|
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,
|
|
|
|
const std::string& startup_url)
|
2017-05-17 11:29:28 +02:00
|
|
|
: is_osr_(is_osr),
|
|
|
|
startup_url_(startup_url),
|
|
|
|
download_favicon_images_(false),
|
|
|
|
delegate_(delegate),
|
|
|
|
browser_count_(0),
|
|
|
|
console_log_file_(MainContext::Get()->GetConsoleLogPath()),
|
|
|
|
first_console_message_(true),
|
2019-02-07 22:36:31 +01:00
|
|
|
focus_on_editable_field_(false),
|
|
|
|
initial_navigation_(true) {
|
2015-01-23 21:03:47 +01:00
|
|
|
DCHECK(!console_log_file_.empty());
|
|
|
|
|
2014-07-09 19:13:06 +02:00
|
|
|
#if defined(OS_LINUX)
|
2015-01-23 21:03:47 +01:00
|
|
|
// Provide the GTK-based dialog implementation on Linux.
|
2015-01-26 20:34:26 +01:00
|
|
|
dialog_handler_ = new ClientDialogHandlerGtk();
|
2014-07-09 19:13:06 +02:00
|
|
|
#endif
|
|
|
|
|
2015-05-23 03:57:31 +02:00
|
|
|
resource_manager_ = new CefResourceManager();
|
2019-10-18 15:30:53 +02:00
|
|
|
test_runner::SetupResourceManager(resource_manager_, &string_resource_map_);
|
2015-05-23 03:57:31 +02:00
|
|
|
|
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);
|
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.
|
|
|
|
MAIN_POST_CLOSURE(base::Bind(&ClientHandler::DetachDelegate, this));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
DCHECK(delegate_);
|
|
|
|
delegate_ = NULL;
|
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();
|
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
if (message_router_->OnProcessMessageReceived(browser, frame, source_process,
|
2014-01-28 00:31:03 +01:00
|
|
|
message)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-06-11 17:52:49 +02:00
|
|
|
// Check for messages from the client renderer.
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
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();
|
|
|
|
|
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.
|
|
|
|
if (model->GetCount() > 0)
|
2012-08-29 18:58:40 +02:00
|
|
|
model->AddSeparator();
|
2012-06-11 17:52:49 +02:00
|
|
|
|
2013-11-08 17:06:06 +01:00
|
|
|
// Add DevTools items to all context menus.
|
2012-06-11 17:52:49 +02:00
|
|
|
model->AddItem(CLIENT_ID_SHOW_DEVTOOLS, "&Show DevTools");
|
2013-11-08 17:06:06 +01:00
|
|
|
model->AddItem(CLIENT_ID_CLOSE_DEVTOOLS, "Close DevTools");
|
2014-10-11 02:12:01 +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");
|
|
|
|
}
|
|
|
|
|
2012-06-11 17:52:49 +02:00
|
|
|
// Test context menu features.
|
|
|
|
BuildTestMenu(model);
|
|
|
|
}
|
2017-02-25 06:03:31 +01:00
|
|
|
|
|
|
|
if (delegate_)
|
|
|
|
delegate_->OnBeforeContextMenu(model);
|
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;
|
2012-06-11 17:52:49 +02:00
|
|
|
default: // Allow default handling, if any.
|
|
|
|
return ExecuteTestMenu(command_id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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.
|
|
|
|
if (frame->IsMain())
|
2015-01-30 19:55:55 +01:00
|
|
|
NotifyAddress(url);
|
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);
|
|
|
|
|
2015-01-22 22:39:36 +01:00
|
|
|
if (first_console_message_) {
|
2015-01-23 20:09:34 +01:00
|
|
|
test_runner::Alert(
|
2015-01-22 22:39:36 +01:00
|
|
|
browser, "Console messages written to \"" + console_log_file_ + "\"");
|
|
|
|
first_console_message_ = false;
|
|
|
|
}
|
2012-06-11 17:52:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
2015-01-26 20:34:26 +01:00
|
|
|
// Return true to cancel the popup window.
|
2015-01-27 01:03:25 +01:00
|
|
|
return !CreatePopupWindow(browser, false, popupFeatures, windowInfo, client,
|
|
|
|
settings);
|
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();
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2015-01-26 20:34:26 +01:00
|
|
|
browser_count_++;
|
|
|
|
|
2014-02-10 19:53:56 +01:00
|
|
|
if (!message_router_) {
|
|
|
|
// Create the browser-side router for query handling.
|
|
|
|
CefMessageRouterConfig config;
|
|
|
|
message_router_ = CefMessageRouterBrowserSide::Create(config);
|
|
|
|
|
|
|
|
// Register handlers with the router.
|
2015-01-23 20:09:34 +01:00
|
|
|
test_runner::CreateMessageHandlers(message_handler_set_);
|
2014-02-10 19:53:56 +01:00
|
|
|
MessageHandlerSet::const_iterator it = message_handler_set_.begin();
|
|
|
|
for (; it != message_handler_set_.end(); ++it)
|
|
|
|
message_router_->AddHandler(*(it), false);
|
|
|
|
}
|
|
|
|
|
2013-04-05 19:05:37 +02:00
|
|
|
// Disable mouse cursor change if requested via the command-line flag.
|
2014-07-11 22:28:37 +02:00
|
|
|
if (mouse_cursor_change_disabled_)
|
2013-04-05 19:05:37 +02:00
|
|
|
browser->GetHost()->SetMouseCursorChangeDisabled(true);
|
|
|
|
|
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.
|
|
|
|
extension_util::AddInternalExtensionToResourceManager(extension,
|
|
|
|
resource_manager_);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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();
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2014-07-11 22:28:37 +02:00
|
|
|
if (--browser_count_ == 0) {
|
2014-01-28 00:31:03 +01:00
|
|
|
// Remove and delete message router handlers.
|
2017-05-17 11:29:28 +02:00
|
|
|
MessageHandlerSet::const_iterator it = message_handler_set_.begin();
|
2014-01-28 00:31:03 +01:00
|
|
|
for (; it != message_handler_set_.end(); ++it) {
|
|
|
|
message_router_->RemoveHandler(*(it));
|
|
|
|
delete *(it);
|
|
|
|
}
|
|
|
|
message_handler_set_.clear();
|
|
|
|
message_router_ = NULL;
|
2013-03-19 23:59:33 +01:00
|
|
|
}
|
2015-01-26 20:34:26 +01:00
|
|
|
|
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.
|
|
|
|
if (errorCode == ERR_ABORTED)
|
|
|
|
return;
|
|
|
|
|
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();
|
|
|
|
if (urlStr.find("spotify:") == 0)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-02-11 19:15:04 +01:00
|
|
|
// Load the error page.
|
|
|
|
LoadErrorPage(frame, failedUrl, errorCode, errorText);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2014-01-28 00:31:03 +01:00
|
|
|
bool ClientHandler::OnBeforeBrowse(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
CefRefPtr<CefRequest> request,
|
2018-04-27 17:11:53 +02:00
|
|
|
bool user_gesture,
|
2014-01-28 00:31:03 +01:00
|
|
|
bool is_redirect) {
|
2014-07-15 00:18:51 +02:00
|
|
|
CEF_REQUIRE_UI_THREAD();
|
|
|
|
|
2014-01-28 00:31:03 +01:00
|
|
|
message_router_->OnBeforeBrowse(browser, frame);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
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) {
|
2015-10-21 20:17:09 +02:00
|
|
|
if (target_disposition == WOD_NEW_BACKGROUND_TAB ||
|
|
|
|
target_disposition == 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.
|
2017-08-04 00:55:19 +02:00
|
|
|
RootWindowConfig config;
|
|
|
|
config.with_controls = true;
|
|
|
|
config.with_osr = is_osr();
|
|
|
|
config.url = target_url;
|
|
|
|
MainContext::Get()->GetRootWindowManager()->CreateRootWindow(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;
|
|
|
|
}
|
|
|
|
|
2012-09-28 00:52:15 +02:00
|
|
|
bool ClientHandler::OnQuotaRequest(CefRefPtr<CefBrowser> browser,
|
|
|
|
const CefString& origin_url,
|
|
|
|
int64 new_size,
|
2015-04-02 17:21:46 +02:00
|
|
|
CefRefPtr<CefRequestCallback> callback) {
|
2014-07-15 00:18:51 +02:00
|
|
|
CEF_REQUIRE_IO_THREAD();
|
|
|
|
|
2012-09-28 00:52:15 +02:00
|
|
|
static const int64 max_size = 1024 * 1024 * 20; // 20mb.
|
|
|
|
|
|
|
|
// Grant the quota request if the size is reasonable.
|
|
|
|
callback->Continue(new_size <= max_size);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
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,
|
|
|
|
CefRefPtr<CefRequestCallback> callback) {
|
2015-02-11 19:15:04 +01:00
|
|
|
CEF_REQUIRE_UI_THREAD();
|
|
|
|
|
2017-07-27 01:19:27 +02:00
|
|
|
if (cert_error == ERR_CERT_AUTHORITY_INVALID &&
|
|
|
|
request_url.ToString().find("https://www.magpcss.org/") == 0U) {
|
|
|
|
// Allow the CEF Forum to load. It has a self-signed certificate.
|
|
|
|
callback->Continue(true);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-09-02 12:01:33 +02:00
|
|
|
CefRefPtr<CefX509Certificate> cert = ssl_info->GetX509Certificate();
|
|
|
|
if (cert.get()) {
|
|
|
|
// Load the error page.
|
|
|
|
LoadErrorPage(browser->GetMainFrame(), request_url, 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()) {
|
|
|
|
callback->Select(NULL);
|
|
|
|
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,
|
|
|
|
TerminationStatus status) {
|
2014-07-15 00:18:51 +02:00
|
|
|
CEF_REQUIRE_UI_THREAD();
|
|
|
|
|
2014-01-28 00:31:03 +01:00
|
|
|
message_router_->OnRenderProcessTerminated(browser);
|
|
|
|
|
2015-01-26 20:34:26 +01:00
|
|
|
// Don't reload if there's no start URL, or if the crash URL was specified.
|
|
|
|
if (startup_url_.empty() || startup_url_ == "chrome://crash")
|
|
|
|
return;
|
|
|
|
|
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.
|
|
|
|
if (url.empty())
|
2014-07-01 00:30:29 +02:00
|
|
|
return;
|
|
|
|
|
2015-01-26 20:34:26 +01:00
|
|
|
std::string start_url = startup_url_;
|
2014-07-01 00:30:29 +02:00
|
|
|
|
2015-01-26 20:34:26 +01:00
|
|
|
// Convert URLs to lowercase for easier comparison.
|
|
|
|
std::transform(url.begin(), url.end(), url.begin(), tolower);
|
|
|
|
std::transform(start_url.begin(), start_url.end(), start_url.begin(),
|
|
|
|
tolower);
|
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.
|
|
|
|
if (url.find(start_url) == 0)
|
2014-07-01 00:30:29 +02:00
|
|
|
return;
|
|
|
|
|
2015-01-26 20:34:26 +01:00
|
|
|
frame->LoadURL(startup_url_);
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
2019-04-24 04:50:25 +02:00
|
|
|
cef_return_value_t ClientHandler::OnBeforeResourceLoad(
|
|
|
|
CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
CefRefPtr<CefRequest> request,
|
|
|
|
CefRefPtr<CefRequestCallback> callback) {
|
|
|
|
CEF_REQUIRE_IO_THREAD();
|
|
|
|
|
|
|
|
return resource_manager_->OnBeforeResourceLoad(browser, frame, request,
|
|
|
|
callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefResourceHandler> ClientHandler::GetResourceHandler(
|
|
|
|
CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
CefRefPtr<CefRequest> request) {
|
|
|
|
CEF_REQUIRE_IO_THREAD();
|
|
|
|
|
|
|
|
return resource_manager_->GetResourceHandler(browser, frame, request);
|
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefResponseFilter> ClientHandler::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);
|
|
|
|
}
|
|
|
|
|
|
|
|
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.
|
|
|
|
if (urlStr.find("spotify:") == 0)
|
|
|
|
allow_os_execution = true;
|
|
|
|
}
|
|
|
|
|
2015-01-26 20:34:26 +01:00
|
|
|
int ClientHandler::GetBrowserCount() const {
|
|
|
|
CEF_REQUIRE_UI_THREAD();
|
|
|
|
return browser_count_;
|
2014-07-15 00:18:51 +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.
|
|
|
|
CefPostTask(TID_UI, base::Bind(&ClientHandler::ShowDevTools, this, browser,
|
|
|
|
inspect_element_at));
|
|
|
|
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
|
|
|
|
2018-09-26 13:25:58 +02:00
|
|
|
MainContext::Get()->PopulateBrowserSettings(&settings);
|
|
|
|
|
2016-06-10 20:33:07 +02:00
|
|
|
CefRefPtr<CefBrowserHost> host = browser->GetHost();
|
|
|
|
|
|
|
|
// Test if the DevTools browser already exists.
|
|
|
|
bool has_devtools = host->HasDevTools();
|
|
|
|
if (!has_devtools) {
|
|
|
|
// Create a new RootWindow for the DevTools browser that will be created
|
|
|
|
// by ShowDevTools().
|
|
|
|
has_devtools = CreatePopupWindow(browser, true, CefPopupFeatures(),
|
|
|
|
windowInfo, client, settings);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (has_devtools) {
|
|
|
|
// 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);
|
2015-01-26 20:34:26 +01:00
|
|
|
}
|
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();
|
|
|
|
if (!nav)
|
|
|
|
return;
|
|
|
|
|
|
|
|
CefRefPtr<CefSSLStatus> ssl = nav->GetSSLStatus();
|
|
|
|
if (!ssl)
|
|
|
|
return;
|
|
|
|
|
|
|
|
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();
|
|
|
|
if (!port.empty())
|
|
|
|
ss << ":" << port.ToString();
|
|
|
|
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();
|
|
|
|
if (cert.get())
|
|
|
|
ss << GetCertificateInformation(cert, ssl->GetCertStatus());
|
|
|
|
|
|
|
|
ss << "</body></html>";
|
|
|
|
|
2017-08-04 00:55:19 +02:00
|
|
|
RootWindowConfig config;
|
|
|
|
config.with_controls = false;
|
|
|
|
config.with_osr = is_osr();
|
|
|
|
config.url = test_runner::GetDataURI(ss.str(), "text/html");
|
|
|
|
MainContext::Get()->GetRootWindowManager()->CreateRootWindow(config);
|
2016-09-02 12:01:33 +02:00
|
|
|
}
|
2015-01-30 19:55:55 +01:00
|
|
|
|
2019-10-18 15:30:53 +02:00
|
|
|
void ClientHandler::SetStringResource(const std::string& page,
|
|
|
|
const std::string& data) {
|
|
|
|
if (!CefCurrentlyOn(TID_IO)) {
|
|
|
|
CefPostTask(TID_IO, base::Bind(&ClientHandler::SetStringResource, this,
|
|
|
|
page, data));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
string_resource_map_[page] = data;
|
|
|
|
}
|
|
|
|
|
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.
|
|
|
|
MainContext::Get()->GetRootWindowManager()->CreateRootWindowAsPopup(
|
|
|
|
!is_devtools, is_osr(), popupFeatures, windowInfo, client, settings);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClientHandler::NotifyBrowserCreated(CefRefPtr<CefBrowser> browser) {
|
|
|
|
if (!CURRENTLY_ON_MAIN_THREAD()) {
|
|
|
|
// Execute this method on the main thread.
|
|
|
|
MAIN_POST_CLOSURE(
|
|
|
|
base::Bind(&ClientHandler::NotifyBrowserCreated, this, browser));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (delegate_)
|
|
|
|
delegate_->OnBrowserCreated(browser);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClientHandler::NotifyBrowserClosing(CefRefPtr<CefBrowser> browser) {
|
|
|
|
if (!CURRENTLY_ON_MAIN_THREAD()) {
|
|
|
|
// Execute this method on the main thread.
|
|
|
|
MAIN_POST_CLOSURE(
|
|
|
|
base::Bind(&ClientHandler::NotifyBrowserClosing, this, browser));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (delegate_)
|
|
|
|
delegate_->OnBrowserClosing(browser);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClientHandler::NotifyBrowserClosed(CefRefPtr<CefBrowser> browser) {
|
|
|
|
if (!CURRENTLY_ON_MAIN_THREAD()) {
|
|
|
|
// Execute this method on the main thread.
|
|
|
|
MAIN_POST_CLOSURE(
|
|
|
|
base::Bind(&ClientHandler::NotifyBrowserClosed, this, browser));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (delegate_)
|
|
|
|
delegate_->OnBrowserClosed(browser);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClientHandler::NotifyAddress(const CefString& url) {
|
|
|
|
if (!CURRENTLY_ON_MAIN_THREAD()) {
|
|
|
|
// Execute this method on the main thread.
|
2017-05-17 11:29:28 +02:00
|
|
|
MAIN_POST_CLOSURE(base::Bind(&ClientHandler::NotifyAddress, this, url));
|
2015-01-30 19:55:55 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (delegate_)
|
|
|
|
delegate_->OnSetAddress(url);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClientHandler::NotifyTitle(const CefString& title) {
|
|
|
|
if (!CURRENTLY_ON_MAIN_THREAD()) {
|
|
|
|
// Execute this method on the main thread.
|
2017-05-17 11:29:28 +02:00
|
|
|
MAIN_POST_CLOSURE(base::Bind(&ClientHandler::NotifyTitle, this, title));
|
2015-01-30 19:55:55 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (delegate_)
|
|
|
|
delegate_->OnSetTitle(title);
|
|
|
|
}
|
|
|
|
|
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.
|
2017-05-17 11:29:28 +02:00
|
|
|
MAIN_POST_CLOSURE(base::Bind(&ClientHandler::NotifyFavicon, this, image));
|
2016-01-19 21:09:01 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (delegate_)
|
|
|
|
delegate_->OnSetFavicon(image);
|
|
|
|
}
|
|
|
|
|
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(
|
|
|
|
base::Bind(&ClientHandler::NotifyFullscreen, this, fullscreen));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (delegate_)
|
|
|
|
delegate_->OnSetFullscreen(fullscreen);
|
|
|
|
}
|
|
|
|
|
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(
|
|
|
|
base::Bind(&ClientHandler::NotifyAutoResize, this, new_size));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (delegate_)
|
|
|
|
delegate_->OnAutoResize(new_size);
|
|
|
|
}
|
|
|
|
|
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.
|
2017-05-17 11:29:28 +02:00
|
|
|
MAIN_POST_CLOSURE(base::Bind(&ClientHandler::NotifyLoadingState, this,
|
|
|
|
isLoading, canGoBack, canGoForward));
|
2015-01-30 19:55:55 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (delegate_)
|
|
|
|
delegate_->OnSetLoadingState(isLoading, canGoBack, canGoForward);
|
|
|
|
}
|
|
|
|
|
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(
|
|
|
|
base::Bind(&ClientHandler::NotifyDraggableRegions, this, regions));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (delegate_)
|
|
|
|
delegate_->OnSetDraggableRegions(regions);
|
|
|
|
}
|
|
|
|
|
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.
|
2017-05-17 11:29:28 +02:00
|
|
|
MAIN_POST_CLOSURE(base::Bind(&ClientHandler::NotifyTakeFocus, this, next));
|
2017-02-17 00:19:43 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (delegate_)
|
|
|
|
delegate_->OnTakeFocus(next);
|
|
|
|
}
|
|
|
|
|
2012-04-19 22:31:46 +02:00
|
|
|
void ClientHandler::BuildTestMenu(CefRefPtr<CefMenuModel> model) {
|
|
|
|
if (model->GetCount() > 0)
|
2012-08-29 18:58:40 +02:00
|
|
|
model->AddSeparator();
|
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.
|
2014-07-11 22:28:37 +02:00
|
|
|
if (test_menu_state_.check_item)
|
2012-04-19 22:31:46 +02:00
|
|
|
submenu->SetChecked(CLIENT_ID_TESTMENU_CHECKITEM, true);
|
|
|
|
|
|
|
|
// 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);
|
2012-04-19 22:31:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ClientHandler::ExecuteTestMenu(int command_id) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Allow default handling to proceed.
|
|
|
|
return false;
|
|
|
|
}
|
2015-01-23 20:09:34 +01:00
|
|
|
|
|
|
|
} // namespace client
|