1
0

CEF Changes

This commit is contained in:
Scott E. Graves
2017-03-18 14:07:45 -05:00
parent 2d1c098d92
commit 7bed11a276
10 changed files with 390 additions and 8 deletions

View File

@@ -7,7 +7,7 @@ mkdir depot_tools
wget --no-check-certificate https://bitbucket.org/chromiumembedded/cef/raw/master/tools/automate/automate-git.py || goto :ERROR
move /y automate-git.py automate\ || goto :ERROR
del /q depot_tools.zip > NUL
wget --no-check-certificate https://storage.googleapis.com/chrome-infra/depot_tools.zip || goto :ERROR
unzip -o -q -d depot_tools\ depot_tools.zip || goto :ERROR
del /q depot_tools.zip || goto :ERROR

View File

@@ -105,6 +105,14 @@ if (MSVC)
${CMAKE_CURRENT_SOURCE_DIR}/3rd_party/CEF/chromium_git/chromium/src/out/${CMAKE_BUILD_TYPE}_GN_x64/libGLESv2.dll.pdb
${CMAKE_CURRENT_SOURCE_DIR}/3rd_party/CEF/chromium_git/chromium/src/out/${CMAKE_BUILD_TYPE}_GN_x64/obj/cef/libcef_dll_wrapper_cc.pdb)
endif()
SET ( CMAKE_EXE_LINKER_FLAGS /MANIFEST:NO )
add_custom_command(
TARGET siadrive
POST_BUILD
COMMAND "mt.exe" -manifest \"${CMAKE_CURRENT_SOURCE_DIR}\\src\\siadrive\\siadrive.exe.manifest\" -outputresource:"$(TargetDir)$(TargetFileName)"
COMMENT "Adding manifest..."
)
endif()

View File

@@ -0,0 +1,8 @@
<html>
<head>
</head>
<body>
Suck it
</body>
</html>

0
htdocs/js/index.js Normal file
View File

View File

@@ -2,10 +2,29 @@
#define _SIADRIVEAPP_H
#include <siacommon.h>
#include <include/cef_app.h>
class CSiaDriveApp
NS_BEGIN(Sia)
class CSiaDriveApp :
public CefApp,
public CefBrowserProcessHandler
{
public:
CSiaDriveApp();
// CefApp methods:
virtual CefRefPtr<CefBrowserProcessHandler> GetBrowserProcessHandler() OVERRIDE
{
return this;
}
// CefBrowserProcessHandler methods:
virtual void OnContextInitialized() OVERRIDE;
private:
// Include the default reference counting implementation.
IMPLEMENT_REFCOUNTING(CSiaDriveApp);
};
NS_END(1)
#endif //_SIADRIVEAPP_H

View File

@@ -0,0 +1,75 @@
#ifndef _SIADRIVEHANDLER_H
#define _SIADRIVEHANDLER_H
#include <siacommon.h>
#include <include/cef_client.h>
#include <include/cef_load_handler.h>
#include <include/cef_life_span_handler.h>
#include <include/cef_display_handler.h>
NS_BEGIN(Sia)
class CSiaDriveHandler :
public CefClient,
public CefDisplayHandler,
public CefLifeSpanHandler,
public CefLoadHandler
{
public:
explicit CSiaDriveHandler(const bool& useViews);
~CSiaDriveHandler();
// Provide access to the single global instance of this object.
static CSiaDriveHandler* GetInstance();
// CefClient methods:
virtual CefRefPtr<CefDisplayHandler> GetDisplayHandler() OVERRIDE
{
return this;
}
virtual CefRefPtr<CefLifeSpanHandler> GetLifeSpanHandler() OVERRIDE
{
return this;
}
virtual CefRefPtr<CefLoadHandler> GetLoadHandler() OVERRIDE
{
return this;
}
// CefDisplayHandler methods:
virtual void OnTitleChange(CefRefPtr<CefBrowser> browser, const CefString& title) OVERRIDE;
// CefLifeSpanHandler methods:
virtual void OnAfterCreated(CefRefPtr<CefBrowser> browser) OVERRIDE;
virtual bool DoClose(CefRefPtr<CefBrowser> browser) OVERRIDE;
virtual void OnBeforeClose(CefRefPtr<CefBrowser> browser) OVERRIDE;
// CefLoadHandler methods:
virtual void OnLoadError(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, ErrorCode errorCode, const CefString& errorText, const CefString& failedUrl) OVERRIDE;
// Request that all existing browser windows close.
void CloseAllBrowsers(bool forceClose);
bool IsClosing() const { return _isClosing; }
private:
// Platform-specific implementation.
void PlatformTitleChange(CefRefPtr<CefBrowser> browser, const CefString& title);
// True if the application is using the Views framework.
const bool _useViews;
// List of existing browser windows. Only accessed on the CEF UI thread.
typedef std::list<CefRefPtr<CefBrowser> > BrowserList;
BrowserList _browserList;
bool _isClosing;
// Include the default reference counting implementation.
IMPLEMENT_REFCOUNTING(CSiaDriveHandler);
};
NS_END(1)
#endif //_SIADRIVEHANDLER_H

View File

@@ -5,13 +5,17 @@
#include <siacommon.h>
#include <siadriveapp.h>
#include <include/cef_app.h>
#include <include/cef_sandbox_win.h>
using namespace Sia;
using namespace Sia::Api;
// Entry point function for all processes.
int APIENTRY wWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow) {
int nCmdShow)
{
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);
@@ -35,10 +39,10 @@ int APIENTRY wWinMain(HINSTANCE hInstance,
// SimpleApp implements application-level callbacks for the browser process.
// It will create the first browser instance in OnContextInitialized() after
// CEF has initialized.
// CefRefPtr<CSiaDriveApp> app(new CSiaDriveApp);
CefRefPtr<CSiaDriveApp> app(new CSiaDriveApp);
// Initialize CEF.
//CefInitialize(mainArgs, settings, app.get(), sandboxInfo);
CefInitialize(mainArgs, settings, app.get(), nullptr);
// Run the CEF message loop. This will block until CefQuitMessageLoop() is
// called.

View File

@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!--The ID below indicates application support for Windows 8.1 -->
<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>
<!--The ID below indicates application support for Windows 10 -->
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
</application>
</compatibility>
<dependency>
<dependentAssembly>
<assemblyIdentity type="Win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="*" publicKeyToken="6595b64144ccf1df" language="*"></assemblyIdentity>
</dependentAssembly>
</dependency>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
<requestedExecutionLevel level="asInvoker" />
</requestedPrivileges>
</security>
</trustInfo>
</assembly>

View File

@@ -1,3 +1,98 @@
#include <siadriveapp.h>
#include "include/views/cef_browser_view.h"
#include "include/views/cef_window.h"
#include "include/wrapper/cef_helpers.h"
#include "siadrivehandler.h"
using namespace Sia::Api;
using namespace Sia;
// When using the Views framework this object provides the delegate
// implementation for the CefWindow that hosts the Views-based browser.
class SimpleWindowDelegate :
public CefWindowDelegate
{
public:
explicit SimpleWindowDelegate(CefRefPtr<CefBrowserView> browserView)
: _browserView(browserView)
{
}
void OnWindowCreated(CefRefPtr<CefWindow> window) OVERRIDE
{
// Add the browser view and show the window.
window->AddChildView(_browserView);
window->Show();
// Give keyboard focus to the browser view.
_browserView->RequestFocus();
}
void OnWindowDestroyed(CefRefPtr<CefWindow> window) OVERRIDE
{
_browserView = nullptr;
}
bool CanClose(CefRefPtr<CefWindow> window) OVERRIDE
{
// Allow the window to close if the browser says it's OK.
CefRefPtr<CefBrowser> browser = _browserView->GetBrowser();
return (browser) ? browser->GetHost()->TryCloseBrowser() : true;
}
private:
CefRefPtr<CefBrowserView> _browserView;
IMPLEMENT_REFCOUNTING(SimpleWindowDelegate);
DISALLOW_COPY_AND_ASSIGN(SimpleWindowDelegate);
};
CSiaDriveApp::CSiaDriveApp()
{
}
void CSiaDriveApp::OnContextInitialized()
{
CEF_REQUIRE_UI_THREAD();
CefRefPtr<CefCommandLine> commandLine = CefCommandLine::GetGlobalCommandLine();
#if defined(OS_WIN) || defined(OS_LINUX)
// Create the browser using the Views framework if "--use-views" is specified
// via the command-line. Otherwise, create the browser using the native
// platform framework. The Views framework is currently only supported on
// Windows and Linux.
const bool useViews = commandLine->HasSwitch("use-views");
#else
const bool useViews = false;
#endif
// SimpleHandler implements browser-level callbacks.
CefRefPtr<CSiaDriveHandler> handler(new CSiaDriveHandler(useViews));
// Specify CEF browser settings here.
CefBrowserSettings browserSettings;
std::string url = "https://www.google.com";
if (useViews)
{
// Create the BrowserView.
CefRefPtr<CefBrowserView> browserView = CefBrowserView::CreateBrowserView(handler, url, browserSettings, nullptr, nullptr);
// Create the Window. It will show itself after creation.
CefWindow::CreateTopLevelWindow(new SimpleWindowDelegate(browserView));
}
else
{
// Information used when creating the native window.
CefWindowInfo windowInfo;
#ifdef _WIN32
// On Windows we need to specify certain flags that will be passed to
// CreateWindowEx().
windowInfo.SetAsPopup(nullptr, "SiaDrive");
#endif
// Create the first browser window.
CefBrowserHost::CreateBrowser(windowInfo, handler, url, browserSettings, nullptr);
}
}

View File

@@ -0,0 +1,146 @@
#include <siadrivehandler.h>
#include <include/wrapper/cef_helpers.h>
#include <include/views/cef_browser_view.h>
#include <include/views/cef_window.h>
#include <include/cef_app.h>
#include <include/base/cef_bind.h>
#include <include/wrapper/cef_closure_task.h>
using namespace Sia;
CSiaDriveHandler* g_instance = nullptr;
CSiaDriveHandler::CSiaDriveHandler(const bool& useViews) :
_useViews(useViews),
_isClosing(false)
{
DCHECK(!g_instance);
g_instance = this;
}
CSiaDriveHandler::~CSiaDriveHandler()
{
g_instance = nullptr;
}
// static
CSiaDriveHandler* CSiaDriveHandler::GetInstance()
{
return g_instance;
}
void CSiaDriveHandler::OnTitleChange(CefRefPtr<CefBrowser> browser, const CefString& title)
{
CEF_REQUIRE_UI_THREAD();
if (_useViews)
{
// Set the title of the window using the Views framework.
CefRefPtr<CefBrowserView> browserView = CefBrowserView::GetForBrowser(browser);
if (browserView)
{
CefRefPtr<CefWindow> window = browserView->GetWindow();
if (window)
window->SetTitle(title);
}
}
else
{
// Set the title of the window using platform APIs.
PlatformTitleChange(browser, title);
}
}
void CSiaDriveHandler::OnAfterCreated(CefRefPtr<CefBrowser> browser)
{
CEF_REQUIRE_UI_THREAD();
// Add to the list of existing browsers.
_browserList.push_back(browser);
}
bool CSiaDriveHandler::DoClose(CefRefPtr<CefBrowser> browser)
{
CEF_REQUIRE_UI_THREAD();
// Closing the main window requires special handling. See the DoClose()
// documentation in the CEF header for a detailed destription of this
// process.
if (_browserList.size() == 1)
{
// Set a flag to indicate that the window close should be allowed.
_isClosing = true;
}
// Allow the close. For windowed browsers this will result in the OS close
// event being sent.
return false;
}
void CSiaDriveHandler::OnBeforeClose(CefRefPtr<CefBrowser> browser)
{
CEF_REQUIRE_UI_THREAD();
// Remove from the list of existing browsers.
BrowserList::iterator bit = _browserList.begin();
for (; bit != _browserList.end(); ++bit)
{
if ((*bit)->IsSame(browser))
{
_browserList.erase(bit);
break;
}
}
if (_browserList.empty())
{
// All browser windows have closed. Quit the application message loop.
CefQuitMessageLoop();
}
}
void CSiaDriveHandler::OnLoadError(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
ErrorCode errorCode,
const CefString& errorText,
const CefString& failedUrl)
{
CEF_REQUIRE_UI_THREAD();
// Don't display an error for downloaded files.
if (errorCode == ERR_ABORTED)
return;
// Display a load error message.
std::stringstream ss;
ss << "<html><body bgcolor=\"white\">"
"<h2>Failed to load URL " << std::string(failedUrl) <<
" with error " << std::string(errorText) << " (" << errorCode <<
").</h2></body></html>";
frame->LoadString(ss.str(), failedUrl);
}
void CSiaDriveHandler::CloseAllBrowsers(bool forceClose)
{
if (!CefCurrentlyOn(TID_UI))
{
// Execute on the UI thread.
CefPostTask(TID_UI, base::Bind(&CSiaDriveHandler::CloseAllBrowsers, this, forceClose));
return;
}
if (_browserList.empty())
return;
BrowserList::const_iterator it = _browserList.begin();
for (; it != _browserList.end(); ++it)
(*it)->GetHost()->CloseBrowser(forceClose);
}
#ifdef _WIN32
void CSiaDriveHandler::PlatformTitleChange(CefRefPtr<CefBrowser> browser, const CefString& title)
{
CefWindowHandle hwnd = browser->GetHost()->GetWindowHandle();
SetWindowText(hwnd, std::wstring(title).c_str());
}
#endif