2828#include < sstream>
2929#include < string>
3030
31- #include < boost/algorithm/string.hpp>
32- #include < boost/filesystem.hpp>
33- #include < boost/log/trivial.hpp>
3431#include < include/cef_app.h>
3532#include < include/views/cef_browser_view.h>
3633#include < include/views/cef_window.h>
34+ #include < boost/algorithm/string.hpp>
35+ #include < boost/filesystem.hpp>
36+ #include < boost/log/trivial.hpp>
3737
38- #include " gui/state/loot_paths.h"
39- #include " gui/helpers.h"
4038#include " gui/cef/loot_scheme_handler_factory.h"
4139#include " gui/cef/query/query_handler.h"
40+ #include " gui/helpers.h"
41+ #include " gui/state/loot_paths.h"
4242
4343namespace loot {
4444LootHandler::LootHandler (LootState& lootState) : lootState_(lootState) {}
4545
4646// CefClient methods
4747// ------------------
4848
49- CefRefPtr<CefDisplayHandler> LootHandler::GetDisplayHandler () {
50- return this ;
51- }
49+ CefRefPtr<CefDisplayHandler> LootHandler::GetDisplayHandler () { return this ; }
5250
53- CefRefPtr<CefLifeSpanHandler> LootHandler::GetLifeSpanHandler () {
54- return this ;
55- }
51+ CefRefPtr<CefLifeSpanHandler> LootHandler::GetLifeSpanHandler () { return this ; }
5652
57- CefRefPtr<CefLoadHandler> LootHandler::GetLoadHandler () {
58- return this ;
59- }
53+ CefRefPtr<CefLoadHandler> LootHandler::GetLoadHandler () { return this ; }
6054
61- bool LootHandler::OnProcessMessageReceived (CefRefPtr<CefBrowser> browser,
62- CefProcessId source_process,
63- CefRefPtr<CefProcessMessage> message) {
64- return browser_side_router_->OnProcessMessageReceived (browser, source_process, message);
55+ bool LootHandler::OnProcessMessageReceived (
56+ CefRefPtr<CefBrowser> browser,
57+ CefProcessId source_process,
58+ CefRefPtr<CefProcessMessage> message) {
59+ return browser_side_router_->OnProcessMessageReceived (
60+ browser, source_process, message);
6561}
6662
6763// CefLifeSpanHandler methods
@@ -85,26 +81,30 @@ bool LootHandler::DoClose(CefRefPtr<CefBrowser> browser) {
8581
8682 // Check if unapplied changes exist.
8783 if (lootState_.hasUnappliedChanges ()) {
88- browser->GetMainFrame ()->ExecuteJavaScript (" onQuit();" , browser->GetMainFrame ()->GetURL (), 0 );
84+ browser->GetMainFrame ()->ExecuteJavaScript (
85+ " onQuit();" , browser->GetMainFrame ()->GetURL (), 0 );
8986 return true ;
9087 }
9188
9289 auto browserView = CefBrowserView::GetForBrowser (browser);
9390 if (browserView == nullptr ) {
94- BOOST_LOG_TRIVIAL (error) << " Failed to save LOOT's settings, browser view is null" ;
91+ BOOST_LOG_TRIVIAL (error)
92+ << " Failed to save LOOT's settings, browser view is null" ;
9593 return false ;
9694 }
9795
9896 auto window = browserView->GetWindow ();
9997 if (window == nullptr ) {
100- BOOST_LOG_TRIVIAL (error) << " Failed to save LOOT's settings, window is null" ;
98+ BOOST_LOG_TRIVIAL (error)
99+ << " Failed to save LOOT's settings, window is null" ;
101100 return false ;
102101 }
103102
104103 LootSettings::WindowPosition position;
105104 position.maximised = window->IsMaximized ();
106105
107- // Un-maximise the window so that the non-maximised size and position are recorded.
106+ // Un-maximise the window so that the non-maximised size and position are
107+ // recorded.
108108 window->Restore ();
109109
110110 CefRect windowBounds = window->GetBoundsInScreen ();
@@ -116,9 +116,9 @@ bool LootHandler::DoClose(CefRefPtr<CefBrowser> browser) {
116116
117117 try {
118118 lootState_.save (LootPaths::getSettingsPath ());
119- }
120- catch (std::exception &e) {
121- BOOST_LOG_TRIVIAL (error) << " Failed to save LOOT's settings. Error: " << e.what ();
119+ } catch (std::exception& e) {
120+ BOOST_LOG_TRIVIAL (error)
121+ << " Failed to save LOOT's settings. Error: " << e.what ();
122122 }
123123
124124 // Allow the close. For windowed browsers this will result in the OS close
@@ -133,15 +133,17 @@ void LootHandler::OnBeforeClose(CefRefPtr<CefBrowser> browser) {
133133 browser_side_router_->OnBeforeClose (browser);
134134
135135 // Remove from the list of existing browsers.
136- for (BrowserList::iterator bit = browser_list_.begin (); bit != browser_list_.end (); ++bit) {
136+ for (BrowserList::iterator bit = browser_list_.begin ();
137+ bit != browser_list_.end ();
138+ ++bit) {
137139 if ((*bit)->IsSame (browser)) {
138140 browser_list_.erase (bit);
139141 break ;
140142 }
141143 }
142144
143145 if (browser_list_.empty ()) {
144- // All browser windows have closed. Quit the application message loop.
146+ // All browser windows have closed. Quit the application message loop.
145147 CefQuitMessageLoop ();
146148 }
147149}
@@ -160,50 +162,55 @@ void LootHandler::OnLoadError(CefRefPtr<CefBrowser> browser,
160162 if (errorCode == ERR_ABORTED)
161163 return ;
162164
163- // Display a load error message.
165+ // Display a load error message.
164166 std::stringstream ss;
165167 ss << " <html><body bgcolor=\" white\" >"
166- << " <h2>Failed to load URL " << std::string (failedUrl)
167- << " with error " << std::string (errorText) << " (" << errorCode
168- << " ).</h2></body></html>" ;
168+ << " <h2>Failed to load URL " << std::string (failedUrl) << " with error "
169+ << std::string (errorText) << " (" << errorCode << " ).</h2></body></html>" ;
169170
170171 frame->LoadString (ss.str (), failedUrl);
171172}
172173
173174// CefRequestHandler methods
174175// --------------------------
175176
176- CefRefPtr<CefRequestHandler> LootHandler::GetRequestHandler () {
177- return this ;
178- }
177+ CefRefPtr<CefRequestHandler> LootHandler::GetRequestHandler () { return this ; }
179178
180- bool LootHandler::OnBeforeBrowse (CefRefPtr< CefBrowser > browser,
181- CefRefPtr< CefFrame > frame,
182- CefRefPtr< CefRequest > request,
179+ bool LootHandler::OnBeforeBrowse (CefRefPtr<CefBrowser> browser,
180+ CefRefPtr<CefFrame> frame,
181+ CefRefPtr<CefRequest> request,
183182 bool is_redirect) {
184- BOOST_LOG_TRIVIAL (trace) << " Attempting to open link: " << request->GetURL ().ToString ();
183+ BOOST_LOG_TRIVIAL (trace) << " Attempting to open link: "
184+ << request->GetURL ().ToString ();
185185
186186 const std::string url = request->GetURL ().ToString ();
187187 if (boost::starts_with (url, " http://loot/" )) {
188- BOOST_LOG_TRIVIAL (trace) << " Link is to LOOT page, allowing CEF's default handling." ;
188+ BOOST_LOG_TRIVIAL (trace)
189+ << " Link is to LOOT page, allowing CEF's default handling." ;
189190 return false ;
190191 } else if (boost::starts_with (url, " http://localhost:" )) {
191- BOOST_LOG_TRIVIAL (warning) << " Link is to a page on localhost, if this isn't happening while running tests, something has gone wrong" ;
192+ BOOST_LOG_TRIVIAL (warning) << " Link is to a page on localhost, if this "
193+ " isn't happening while running tests, "
194+ " something has gone wrong" ;
192195 return false ;
193196 }
194197
195198 BOOST_LOG_TRIVIAL (info) << " Opening link in Windows' default handler." ;
196- OpenInDefaultApplication (boost::filesystem::path (request->GetURL ().ToString ()));
199+ OpenInDefaultApplication (
200+ boost::filesystem::path (request->GetURL ().ToString ()));
197201
198202 return true ;
199203}
200204
201- CefRequestHandler::ReturnValue LootHandler::OnBeforeResourceLoad (CefRefPtr<CefBrowser> browser,
202- CefRefPtr<CefFrame> frame,
203- CefRefPtr<CefRequest> request,
204- CefRefPtr<CefRequestCallback> callback) {
205- if (boost::starts_with (request->GetURL ().ToString (), " https://fonts.googleapis.com" )) {
206- BOOST_LOG_TRIVIAL (warning) << " Blocking load of resource at " << request->GetURL ().ToString ();
205+ CefRequestHandler::ReturnValue LootHandler::OnBeforeResourceLoad (
206+ CefRefPtr<CefBrowser> browser,
207+ CefRefPtr<CefFrame> frame,
208+ CefRefPtr<CefRequest> request,
209+ CefRefPtr<CefRequestCallback> callback) {
210+ if (boost::starts_with (request->GetURL ().ToString (),
211+ " https://fonts.googleapis.com" )) {
212+ BOOST_LOG_TRIVIAL (warning)
213+ << " Blocking load of resource at " << request->GetURL ().ToString ();
207214 return RV_CANCEL;
208215 }
209216
0 commit comments