Skip to content

Commit

Permalink
Updates to support latest CEF changes
Browse files Browse the repository at this point in the history
  • Loading branch information
cretz committed Nov 2, 2019
1 parent 1b4ed74 commit 2e3097b
Show file tree
Hide file tree
Showing 13 changed files with 86 additions and 61 deletions.
7 changes: 1 addition & 6 deletions src/browser_setting.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,7 @@ const QList<BrowserSetting> BrowserSetting::kSettings = {
BrowserSetting(
BrowserSetting::EnableNetSecurityExpiration,
"Enable Net Security Expiration?",
"Enable date-based expiration of built in network security information "
"(i.e. certificate transparency logs, HSTS preloading and pinning "
"information). Enabling this option improves network security but may "
"cause HTTPS load failures when using CEF binaries built more than 10 "
"weeks in the past. See https://www.certificate-transparency.org/ and "
"https://www.chromium.org/hsts for details."),
"DEPRECATED: No longer takes effect."),
BrowserSetting(
BrowserSetting::FileAccessFromFileUrls,
"File Access From File URLs?",
Expand Down
19 changes: 13 additions & 6 deletions src/browser_widget.cc
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,10 @@ BrowserWidget::BrowserWidget(const Cef& cef,
}

void BrowserWidget::LoadUrl(const QString &url) {
url_edit_->setText(url);
// If this starts with a data URI for text/html, we are going to be lazy
// and assume it's for an error page for now and not change the URL.
// TODO: Stop being lazy (and opening security holes) and show errors better
if (!url.startsWith("data:text/html;base64,")) url_edit_->setText(url);
cef_widg_->LoadUrl(url);
}

Expand Down Expand Up @@ -184,7 +187,7 @@ QString BrowserWidget::CurrentUrl() const {
// As a special case, if this URL is invalid, we use
// what's in the URL edit box
auto url = cef_widg_->CurrentUrl();
if (url == "data:text/html,chromewebdata") {
if (url.startsWith("data:text/html")) {
url = url_edit_->text();
}
return url;
Expand Down Expand Up @@ -529,7 +532,10 @@ void BrowserWidget::RecreateCefWidget(const QString& url,
}
});
connect(cef_widg_, &CefWidget::UrlChanged, [=](const QString& url) {
url_edit_->setText(url);
// If this starts with a data URI for text/html, we are going to be lazy
// and assume it's for an error page for now and not change the URL.
// TODO: Stop being lazy (and opening security holes) and show errors better
if (!url.startsWith("data:text/html;base64,")) url_edit_->setText(url);
});

if (widg_to_replace) {
Expand Down Expand Up @@ -684,18 +690,19 @@ void BrowserWidget::HandleContextMenuCommand(
}
}

void BrowserWidget::ShowError(const QString& failed_url,
void BrowserWidget::ShowError(const QString& /*failed_url*/,
const QString& error_text,
CefRefPtr<CefFrame> frame) {
if (!frame || frame->IsMain()) {
url_edit_->setStyleSheet("QLineEdit { background-color: pink; }");
number_of_load_completes_are_error_ = 2;
}
auto new_html =
QString("<html><body style=\"background-color: pink;\">"
QString("<html><head><title>(error)</title></head>"
"<body style=\"background-color: pink;\">"
"Error loading page: <strong>%1</strong>"
"</body></html>").arg(error_text);
cef_widg_->ShowStringPage(failed_url, new_html, frame);
cef_widg_->ShowStringPage(new_html, "text/html", frame);
}

void BrowserWidget::UpdateSslStatus(bool check_errored) {
Expand Down
6 changes: 0 additions & 6 deletions src/bubble.cc
Original file line number Diff line number Diff line change
Expand Up @@ -306,9 +306,6 @@ void Bubble::ApplyBrowserSettings(
void Bubble::ApplyBrowserSettings(
const QHash<BrowserSetting::SettingKey, bool>& source,
CefRequestContextSettings* target) {
if (source.value(BrowserSetting::EnableNetSecurityExpiration, false)) {
target->enable_net_security_expiration = 1;
}
if (source.value(BrowserSetting::PersistUserPreferences, false)) {
target->persist_user_preferences = 1;
}
Expand All @@ -317,9 +314,6 @@ void Bubble::ApplyBrowserSettings(
void Bubble::ApplyBrowserSettings(
const QHash<BrowserSetting::SettingKey, bool>& source,
CefSettings* target) {
if (source.value(BrowserSetting::EnableNetSecurityExpiration, false)) {
target->enable_net_security_expiration = 1;
}
if (source.value(BrowserSetting::PersistUserPreferences, false)) {
target->persist_user_preferences = 1;
}
Expand Down
1 change: 0 additions & 1 deletion src/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,6 @@ func copyResourcesWindows(qmakePath string, target string) error {
"natives_blob.bin",
"snapshot_blob.bin",
"v8_context_snapshot.bin",
"d3dcompiler_43.dll",
"d3dcompiler_47.dll",
"libEGL.dll",
"libGLESv2.dll",
Expand Down
2 changes: 1 addition & 1 deletion src/cef/cef.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class Cef {
uint64 current,
uint64 total)> download_progress_;

IMPLEMENT_REFCOUNTING(CallbackFullDownload)
IMPLEMENT_REFCOUNTING(CallbackFullDownload);
};

cef_main_args_t MainArgs(int argc, char* argv[]);
Expand Down
2 changes: 1 addition & 1 deletion src/cef/cef_app_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class CefAppHandler :
private:
CosmeticBlocker blocker_;

IMPLEMENT_REFCOUNTING(CefAppHandler)
IMPLEMENT_REFCOUNTING(CefAppHandler);
};

} // namespace doogie
Expand Down
1 change: 1 addition & 0 deletions src/cef/cef_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "include/cef_client.h"
#include "include/cef_file_util.h"
#include "include/cef_parser.h"
#include "include/cef_request_context_handler.h"
#include "include/cef_urlrequest.h"
#include "include/cef_xml_reader.h"
#include "include/cef_zip_reader.h"
Expand Down
38 changes: 25 additions & 13 deletions src/cef/cef_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ bool CefHandler::OnBeforePopup(
CefWindowInfo&,
CefRefPtr<CefClient>&,
CefBrowserSettings&,
CefRefPtr<CefDictionaryValue>&,
bool*) {
if (popup_as_page_open_) {
emit PageOpen(static_cast<WindowOpenType>(target_disposition),
Expand Down Expand Up @@ -207,17 +208,6 @@ void CefHandler::OnLoadError(CefRefPtr<CefBrowser> /*browser*/,
QString::fromStdString(failed_url.ToString()));
}

CefRequestHandler::ReturnValue CefHandler::OnBeforeResourceLoad(
CefRefPtr<CefBrowser> /*browser*/,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefRequest> request,
CefRefPtr<CefRequestCallback> /*callback*/) {
if (resource_load_callback_ && !resource_load_callback_(frame, request)) {
return RV_CANCEL;
}
return RV_CONTINUE;
}

bool CefHandler::OnBeforeBrowse(CefRefPtr<CefBrowser> /*browser*/,
CefRefPtr<CefFrame> /*frame*/,
CefRefPtr<CefRequest> /*request*/,
Expand Down Expand Up @@ -249,19 +239,41 @@ bool CefHandler::OnOpenURLFromTab(
return true;
}

CefRefPtr<CefResourceRequestHandler> CefHandler::GetResourceRequestHandler(
CefRefPtr<CefBrowser> /*browser*/,
CefRefPtr<CefFrame> /*frame*/,
CefRefPtr<CefRequest> /*request*/,
bool /*is_navigation*/,
bool /*is_download*/,
const CefString& /*request_initiator*/,
bool& /*disable_default_handling*/) {
return this;
}

bool CefHandler::GetAuthCredentials(CefRefPtr<CefBrowser> /*browser*/,
CefRefPtr<CefFrame> frame,
const CefString& origin_url,
bool is_proxy,
const CefString& host,
int port,
const CefString& realm,
const CefString& scheme,
CefRefPtr<CefAuthCallback> callback) {
emit AuthRequest(frame, is_proxy,
emit AuthRequest(QString::fromStdString(origin_url.ToString()), is_proxy,
QString::fromStdString(host.ToString()), port,
QString::fromStdString(realm.ToString()),
QString::fromStdString(scheme.ToString()), callback);
return true;
}

CefResourceRequestHandler::ReturnValue CefHandler::OnBeforeResourceLoad(
CefRefPtr<CefBrowser> /*browser*/,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefRequest> request,
CefRefPtr<CefRequestCallback> /*callback*/) {
if (resource_load_callback_ && !resource_load_callback_(frame, request)) {
return RV_CANCEL;
}
return RV_CONTINUE;
}

} // namespace doogie
42 changes: 27 additions & 15 deletions src/cef/cef_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ class CefHandler :
public CefKeyboardHandler,
public CefLifeSpanHandler,
public CefLoadHandler,
public CefRequestHandler {
public CefRequestHandler,
public CefResourceRequestHandler {
Q_OBJECT

public:
Expand Down Expand Up @@ -187,6 +188,7 @@ class CefHandler :
CefWindowInfo& windowInfo,
CefRefPtr<CefClient>& client,
CefBrowserSettings& settings, // NOLINT(runtime/references)
CefRefPtr<CefDictionaryValue>& extra_info,
bool* no_javascript_access) override;
bool DoClose(CefRefPtr<CefBrowser> browser) override;
void OnAfterCreated(CefRefPtr<CefBrowser> browser) override;
Expand All @@ -209,17 +211,6 @@ class CefHandler :
const CefString& failedUrl) override;

// Request handler overrides...
typedef std::function<bool(
CefRefPtr<CefFrame> frame,
CefRefPtr<CefRequest> request)> ResourceLoadCallback;
void SetResourceLoadCallback(ResourceLoadCallback callback) {
resource_load_callback_ = callback;
}
ReturnValue OnBeforeResourceLoad(
CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefRequest> request,
CefRefPtr<CefRequestCallback> callback) override;
bool OnBeforeBrowse(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefRequest> request,
Expand All @@ -236,15 +227,36 @@ class CefHandler :
const CefString& target_url,
CefRequestHandler::WindowOpenDisposition target_disposition,
bool user_gesture) override;
CefRefPtr<CefResourceRequestHandler> GetResourceRequestHandler(
CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefRequest> request,
bool is_navigation,
bool is_download,
const CefString& request_initiator,
bool& disable_default_handling) override;
bool GetAuthCredentials(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
const CefString& origin_url,
bool is_proxy,
const CefString& host,
int port,
const CefString& realm,
const CefString& scheme,
CefRefPtr<CefAuthCallback> callback) override;

// Resource request handler overrides...
typedef std::function<bool(
CefRefPtr<CefFrame> frame,
CefRefPtr<CefRequest> request)> ResourceLoadCallback;
void SetResourceLoadCallback(ResourceLoadCallback callback) {
resource_load_callback_ = callback;
}
ReturnValue OnBeforeResourceLoad(
CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefRequest> request,
CefRefPtr<CefRequestCallback> callback) override;

signals:
void PreContextMenu(CefRefPtr<CefContextMenuParams> params,
CefRefPtr<CefMenuModel> model);
Expand Down Expand Up @@ -288,7 +300,7 @@ class CefHandler :
CefRefPtr<CefSSLInfo> ssl_info,
CefRefPtr<CefRequestCallback> callback);
void PageOpen(WindowOpenType type, const QString& url, bool user_gesture);
void AuthRequest(CefRefPtr<CefFrame> frame,
void AuthRequest(const QString& origin_url,
bool is_proxy,
const QString& host,
int port,
Expand All @@ -305,7 +317,7 @@ class CefHandler :
PreKeyCallback pre_key_callback_ = nullptr;
ResourceLoadCallback resource_load_callback_ = nullptr;

IMPLEMENT_REFCOUNTING(CefHandler)
IMPLEMENT_REFCOUNTING(CefHandler);
};

} // namespace doogie
Expand Down
15 changes: 10 additions & 5 deletions src/cef/cef_widget.cc
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ CefWidget::CefWidget(const Cef& cef,
connect(handler_, &CefHandler::ShowBeforeUnloadDialog,
this, &CefWidget::ShowBeforeUnloadDialog);
connect(handler_, &CefHandler::AuthRequest,
[=](CefRefPtr<CefFrame>, bool, const QString&,
[=](const QString&, bool, const QString&,
int, const QString& realm, const QString&,
CefRefPtr<CefAuthCallback> callback) {
Util::RunOnMainThread([=]() { AuthRequest(realm, callback); });
Expand Down Expand Up @@ -107,13 +107,17 @@ void CefWidget::LoadUrl(const QString& url) {
}
}

void CefWidget::ShowStringPage(const QString& url,
const QString& contents,
void CefWidget::ShowStringPage(const QString& data,
const QString& mime_type,
CefRefPtr<CefFrame> frame) {
if (browser_) {
auto f = frame ? frame : browser_->GetMainFrame();
f->LoadString(CefString(contents.toStdString()),
CefString(url.toStdString()));
// Ref https://bitbucket.org/chromiumembedded/cef/issues/2586/loadstring-results-in-terminating-renderer
// We must use LoadURL with a data URL
std::string data_str = data.toStdString();
std::string base64 = CefURIEncode(CefBase64Encode(data_str.data(), data_str.size()), false).ToString();
std::string data_uri = "data:" + mime_type.toStdString() + ";base64," + base64;
f->LoadURL(data_uri);
}
}

Expand Down Expand Up @@ -356,6 +360,7 @@ void CefWidget::InitBrowser(const Bubble& bubble, const QString& url) {
handler_,
CefString(url.toStdString()),
settings,
CefDictionaryValue::Create(),
bubble.CreateCefRequestContext());
}

Expand Down
10 changes: 5 additions & 5 deletions src/cef/cef_widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ class CefWidget : public CefBaseWidget {
CefRefPtr<CefSSLStatus> CurrentSSLStatus() const;
void LoadUrl(const QString& url);
// No frame means main frame
void ShowStringPage(const QString& url,
const QString& contents,
void ShowStringPage(const QString& data,
const QString& mime_type,
CefRefPtr<CefFrame> frame = nullptr);
QString CurrentUrl() const;
bool HasDocument() const;
Expand Down Expand Up @@ -120,7 +120,7 @@ class CefWidget : public CefBaseWidget {
CefRefPtr<CefImage> image) override;
private:
QPointer<CefWidget> cef_widg_;
IMPLEMENT_REFCOUNTING(FaviconDownloadCallback)
IMPLEMENT_REFCOUNTING(FaviconDownloadCallback);
DISALLOW_COPY_AND_ASSIGN(FaviconDownloadCallback);
};

Expand All @@ -132,7 +132,7 @@ class CefWidget : public CefBaseWidget {

private:
std::vector<NavEntry> entries_;
IMPLEMENT_REFCOUNTING(NavEntryVisitor)
IMPLEMENT_REFCOUNTING(NavEntryVisitor);
};

class NavEntryCurrentSslVisitor : public CefNavigationEntryVisitor {
Expand All @@ -143,7 +143,7 @@ class CefWidget : public CefBaseWidget {

private:
CefRefPtr<CefSSLStatus> ssl_status_;
IMPLEMENT_REFCOUNTING(NavEntryCurrentSslVisitor)
IMPLEMENT_REFCOUNTING(NavEntryCurrentSslVisitor);
};

void InitBrowser(const Bubble& bubble, const QString& url);
Expand Down
2 changes: 1 addition & 1 deletion src/cosmetic_blocker.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class CosmeticBlocker {
CefString& exception) override;

private:
IMPLEMENT_REFCOUNTING(MutationCallback)
IMPLEMENT_REFCOUNTING(MutationCallback);
};
};

Expand Down
2 changes: 1 addition & 1 deletion src/url_edit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ void UrlEdit::HandleTextEdit(const QString& text) {
// doesn't change
autocomplete_->blockSignals(true);
autocomplete_->setCurrentRow(0);
autocomplete_->blockSignals(false);\
autocomplete_->blockSignals(false);

autocomplete_->move(mapToGlobal(rect().bottomLeft()));
autocomplete_->setFixedWidth(width());
Expand Down

0 comments on commit 2e3097b

Please sign in to comment.