Skip to content

Commit 648ac50

Browse files
committed
Add chrome.enable_downloads option (#221)
1 parent aea2597 commit 648ac50

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

src/client_handler.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,20 @@ CefRefPtr<CefBrowser> ClientHandler::FindBrowserByXid(::Window xid) {
4747
return NULL;
4848
}
4949

50+
void ClientHandler::OnBeforeDownload(
51+
CefRefPtr<CefBrowser> browser,
52+
CefRefPtr<CefDownloadItem> download_item,
53+
const CefString& suggested_name,
54+
CefRefPtr<CefBeforeDownloadCallback> callback) {
55+
bool enable_downloads = (*get_app_settings())["chrome"]["enable_downloads"];
56+
if (enable_downloads) {
57+
LOG(INFO) << "About to download a file: " << suggested_name.ToString();
58+
callback->Continue(suggested_name, true);
59+
} else {
60+
LOG(INFO) << "Tried to download a file, but downloads are disabled";
61+
}
62+
}
63+
5064
void ClientHandler::OnAfterCreated(CefRefPtr<CefBrowser> browser) {
5165
CEF_REQUIRE_UI_THREAD();
5266
// Add to the list of existing browsers.

src/client_handler.h

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
class ClientHandler : public CefClient,
1313
public CefDisplayHandler,
14+
public CefDownloadHandler,
1415
public CefLifeSpanHandler,
1516
public CefLoadHandler,
1617
public CefRequestHandler
@@ -31,7 +32,10 @@ class ClientHandler : public CefClient,
3132
CefRefPtr<CefDisplayHandler> GetDisplayHandler() override {
3233
return this;
3334
}
34-
CefRefPtr<CefJSDialogHandler> GetJSDialogHandler() {
35+
CefRefPtr<CefDownloadHandler> GetDownloadHandler() override {
36+
return this;
37+
}
38+
CefRefPtr<CefJSDialogHandler> GetJSDialogHandler() override {
3539
return dialog_handler_;
3640
}
3741
CefRefPtr<CefLifeSpanHandler> GetLifeSpanHandler() override {
@@ -44,6 +48,13 @@ class ClientHandler : public CefClient,
4448
return this;
4549
}
4650

51+
// CefDownloadHandler
52+
virtual void OnBeforeDownload(
53+
CefRefPtr<CefBrowser> browser,
54+
CefRefPtr<CefDownloadItem> download_item,
55+
const CefString& suggested_name,
56+
CefRefPtr<CefBeforeDownloadCallback> callback) override;
57+
4758
// CefLifeSpanHandler
4859
virtual void OnAfterCreated(CefRefPtr<CefBrowser> browser) override;
4960
virtual void OnBeforeClose(CefRefPtr<CefBrowser> browser) override;
@@ -52,7 +63,8 @@ class ClientHandler : public CefClient,
5263
virtual bool OnQuotaRequest(CefRefPtr<CefBrowser> browser,
5364
const CefString& origin_url,
5465
int64 new_size,
55-
CefRefPtr<CefRequestCallback> callback);
66+
CefRefPtr<CefRequestCallback> callback)
67+
override;
5668

5769
private:
5870
// List of existing browser windows. Only accessed on the CEF UI thread.

0 commit comments

Comments
 (0)