Implemented custom scheme handling.

Closes #286.
This commit is contained in:
Oliver Hamlet
2014-09-21 12:52:50 +01:00
parent 01d60ce539
commit afa32ac2fb
5 changed files with 114 additions and 0 deletions
+1
View File
@@ -59,6 +59,7 @@ set (LOOT_GUI_SRC ${LOOT_SRC}
"${CMAKE_SOURCE_DIR}/src/gui/main_win.cpp"
"${CMAKE_SOURCE_DIR}/src/gui/handler.cpp"
"${CMAKE_SOURCE_DIR}/src/gui/app.cpp"
"${CMAKE_SOURCE_DIR}/src/gui/scheme.cpp"
"${CMAKE_SOURCE_DIR}/src/resource.rc")
set (LOOT_API_SRC ${LOOT_SRC}
+9
View File
@@ -24,6 +24,7 @@
#include "app.h"
#include "handler.h"
#include "scheme.h"
#include "../backend/error.h"
#include "../backend/globals.h"
@@ -64,6 +65,11 @@ namespace loot {
return this;
}
void LootApp::OnRegisterCustomSchemes(CefRefPtr<CefSchemeRegistrar> registrar) {
// Register "loot" as a standard scheme.
registrar->AddCustomScheme("loot", true, false, false);
}
void LootApp::OnContextInitialized() {
//Make sure this is running in the UI thread.
assert(CefCurrentlyOn(TID_UI));
@@ -79,6 +85,9 @@ namespace loot {
// Set the handler for browser-level callbacks.
CefRefPtr<LootHandler> handler(new LootHandler());
// Register the custom "loot" scheme handler.
CefRegisterSchemeHandlerFactory("loot", "l10n", new LootSchemeHandlerFactory());
// Specify CEF browser settings here.
CefBrowserSettings browser_settings;
+1
View File
@@ -43,6 +43,7 @@ namespace loot {
// Override CefApp methods.
virtual CefRefPtr<CefBrowserProcessHandler> GetBrowserProcessHandler() OVERRIDE;
virtual CefRefPtr<CefRenderProcessHandler> GetRenderProcessHandler() OVERRIDE;
virtual void OnRegisterCustomSchemes(CefRefPtr<CefSchemeRegistrar> registrar) OVERRIDE;
// Override CefBrowserProcessHandler methods.
virtual void OnContextInitialized() OVERRIDE;
+59
View File
@@ -0,0 +1,59 @@
/* LOOT
A load order optimisation tool for Oblivion, Skyrim, Fallout 3 and
Fallout: New Vegas.
Copyright (C) 2014 WrinklyNinja
This file is part of LOOT.
LOOT is free software: you can redistribute
it and/or modify it under the terms of the GNU General Public License
as published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
LOOT is distributed in the hope that it will
be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with LOOT. If not, see
<http://www.gnu.org/licenses/>.
*/
#include "scheme.h"
#include "../backend/globals.h"
#include <include/wrapper/cef_stream_resource_handler.h>
#include <string>
#include <boost/log/trivial.hpp>
using namespace std;
namespace loot {
///////////////////////////////
// LootSchemeHandlerFactory
///////////////////////////////
CefRefPtr<CefResourceHandler> LootSchemeHandlerFactory::Create(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
const CefString& scheme_name,
CefRefPtr<CefRequest> request) {
BOOST_LOG_TRIVIAL(trace) << "Handling custom scheme: " << string(request->GetURL());
// Get the file from the custom URL.
string file = (g_path_l10n / string(request->GetURL()).substr(12)).string();
// Load the file into a CEF stream.
CefRefPtr<CefStreamReader> stream = CefStreamReader::CreateForFile(file);
BOOST_LOG_TRIVIAL(trace) << "Loaded file: " << file;
CefResponse::HeaderMap headers;
headers.emplace("Access-Control-Allow-Origin", "*");
return new CefStreamResourceHandler(200, "OK", "application/octet-stream", headers, stream);
}
}
+44
View File
@@ -0,0 +1,44 @@
/* LOOT
A load order optimisation tool for Oblivion, Skyrim, Fallout 3 and
Fallout: New Vegas.
Copyright (C) 2014 WrinklyNinja
This file is part of LOOT.
LOOT is free software: you can redistribute
it and/or modify it under the terms of the GNU General Public License
as published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
LOOT is distributed in the hope that it will
be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with LOOT. If not, see
<http://www.gnu.org/licenses/>.
*/
#ifndef __LOOT_GUI_SCHEME_HANDLER__
#define __LOOT_GUI_SCHEME_HANDLER__
#include <include/cef_base.h>
#include <include/cef_scheme.h>
namespace loot {
class LootSchemeHandlerFactory : public CefSchemeHandlerFactory {
public:
virtual CefRefPtr<CefResourceHandler> Create(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
const CefString& scheme_name,
CefRefPtr<CefRequest> request)
OVERRIDE;
IMPLEMENT_REFCOUNTING(LootSchemeHandlerFactory);
};
}
#endif