From 2174bb60634a18710ada1b3da24ee460b0319f64 Mon Sep 17 00:00:00 2001 From: Oliver Hamlet Date: Sat, 12 Mar 2016 10:42:58 +0000 Subject: [PATCH] Block HTTP/HTTPS resource requests At least one Polymer element sends a HTTPS request for the Roboto font files to Google Fonts, but this is unnecessary as they are bundled with LOOT. Blocking the requests speeds up LOOT's initialisation time significantly on slow Internet connections, and reduces font pop-in. --- src/gui/loot_handler.cpp | 10 ++++++++++ src/gui/loot_handler.h | 15 ++++++++++----- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/gui/loot_handler.cpp b/src/gui/loot_handler.cpp index f0d50eda..dd4fbb77 100644 --- a/src/gui/loot_handler.cpp +++ b/src/gui/loot_handler.cpp @@ -254,6 +254,16 @@ namespace loot { return true; } + CefRequestHandler::ReturnValue LootHandler::OnBeforeResourceLoad(CefRefPtr browser, + CefRefPtr frame, + CefRefPtr request, + CefRefPtr callback) { + if (boost::starts_with(request->GetURL().ToString(), "http")) + return RV_CANCEL; + + return RV_CONTINUE; + } + void LootHandler::CloseAllBrowsers(bool force_close) { if (!CefCurrentlyOn(TID_UI)) { // Execute on the UI thread. diff --git a/src/gui/loot_handler.h b/src/gui/loot_handler.h index 0ce0a13b..3e47bde3 100644 --- a/src/gui/loot_handler.h +++ b/src/gui/loot_handler.h @@ -68,14 +68,19 @@ namespace loot { // CefRequestHandler methods //-------------------------- - virtual CefRefPtr GetRequestHandler() OVERRIDE{ + virtual CefRefPtr GetRequestHandler() OVERRIDE { return this; } - virtual bool OnBeforeBrowse(CefRefPtr< CefBrowser > browser, - CefRefPtr< CefFrame > frame, - CefRefPtr< CefRequest > request, - bool is_redirect) OVERRIDE; + virtual bool OnBeforeBrowse(CefRefPtr< CefBrowser > browser, + CefRefPtr< CefFrame > frame, + CefRefPtr< CefRequest > request, + bool is_redirect) OVERRIDE; + + virtual CefRequestHandler::ReturnValue OnBeforeResourceLoad(CefRefPtr browser, + CefRefPtr frame, + CefRefPtr request, + CefRefPtr callback) OVERRIDE; // Request that all existing browser windows close. void CloseAllBrowsers(bool force_close);