참고소스 수정본
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
set(Playwright_PRIVATE_INCLUDE_DIRECTORIES
|
||||
${CMAKE_BINARY_DIR}
|
||||
${WebCore_PRIVATE_FRAMEWORK_HEADERS_DIR}
|
||||
)
|
||||
|
||||
set(Playwright_SOURCES
|
||||
Common.cpp
|
||||
MainWindow.cpp
|
||||
PlaywrightLib.rc
|
||||
WebKitBrowserWindow.cpp
|
||||
WinMain.cpp
|
||||
stdafx.cpp
|
||||
)
|
||||
|
||||
set(Playwright_PRIVATE_DEFINITIONS _UNICODE)
|
||||
set(Playwright_PRIVATE_LIBRARIES
|
||||
WebKit::WTF
|
||||
comctl32
|
||||
shlwapi
|
||||
user32
|
||||
)
|
||||
|
||||
list(APPEND Playwright_PRIVATE_DEFINITIONS ENABLE_WEBKIT)
|
||||
list(APPEND Playwright_SOURCES
|
||||
WebKitBrowserWindow.cpp
|
||||
)
|
||||
list(APPEND Playwright_PRIVATE_LIBRARIES
|
||||
WebKit::WebKit
|
||||
)
|
||||
|
||||
WEBKIT_EXECUTABLE_DECLARE(Playwright)
|
||||
WEBKIT_EXECUTABLE(Playwright)
|
||||
|
||||
set_target_properties(Playwright PROPERTIES WIN32_EXECUTABLE ON)
|
||||
if (${WTF_PLATFORM_WIN_CAIRO})
|
||||
target_compile_definitions(Playwright PRIVATE WIN_CAIRO)
|
||||
endif ()
|
||||
@@ -0,0 +1,264 @@
|
||||
/*
|
||||
* Copyright (C) 2006, 2008, 2013-2015 Apple Inc. All rights reserved.
|
||||
* Copyright (C) 2009, 2011 Brent Fulgham. All rights reserved.
|
||||
* Copyright (C) 2009, 2010, 2011 Appcelerator, Inc. All rights reserved.
|
||||
* Copyright (C) 2013 Alex Christensen. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "Common.h"
|
||||
|
||||
#include "DialogHelper.h"
|
||||
#include "PlaywrightLibResource.h"
|
||||
#include "PlaywrightReplace.h"
|
||||
#include <dbghelp.h>
|
||||
#include <shlobj.h>
|
||||
#include <wtf/StdLibExtras.h>
|
||||
#include <vector>
|
||||
|
||||
// Global Variables:
|
||||
HINSTANCE hInst;
|
||||
|
||||
// Support moving the transparent window
|
||||
POINT s_windowPosition = { 100, 100 };
|
||||
SIZE s_windowSize = { 500, 200 };
|
||||
|
||||
bool s_headless;
|
||||
|
||||
namespace WebCore {
|
||||
float deviceScaleFactorForWindow(HWND);
|
||||
}
|
||||
|
||||
void computeFullDesktopFrame()
|
||||
{
|
||||
RECT desktop;
|
||||
if (!::SystemParametersInfo(SPI_GETWORKAREA, 0, static_cast<void*>(&desktop), 0))
|
||||
return;
|
||||
|
||||
float scaleFactor = WebCore::deviceScaleFactorForWindow(nullptr);
|
||||
|
||||
s_windowPosition.x = 0;
|
||||
s_windowPosition.y = 0;
|
||||
s_windowSize.cx = scaleFactor * (desktop.right - desktop.left);
|
||||
s_windowSize.cy = scaleFactor * (desktop.bottom - desktop.top);
|
||||
}
|
||||
|
||||
bool getAppDataFolder(_bstr_t& directory)
|
||||
{
|
||||
wchar_t appDataDirectory[MAX_PATH];
|
||||
if (FAILED(SHGetFolderPathW(0, CSIDL_LOCAL_APPDATA | CSIDL_FLAG_CREATE, 0, 0, appDataDirectory)))
|
||||
return false;
|
||||
|
||||
wchar_t executablePath[MAX_PATH];
|
||||
if (!::GetModuleFileNameW(0, executablePath, MAX_PATH))
|
||||
return false;
|
||||
|
||||
::PathRemoveExtensionW(executablePath);
|
||||
|
||||
directory = _bstr_t(appDataDirectory) + L"\\" + ::PathFindFileNameW(executablePath);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void createCrashReport(EXCEPTION_POINTERS* exceptionPointers)
|
||||
{
|
||||
_bstr_t directory;
|
||||
|
||||
if (!getAppDataFolder(directory))
|
||||
return;
|
||||
|
||||
if (::SHCreateDirectoryEx(0, directory, 0) != ERROR_SUCCESS
|
||||
&& ::GetLastError() != ERROR_FILE_EXISTS
|
||||
&& ::GetLastError() != ERROR_ALREADY_EXISTS)
|
||||
return;
|
||||
|
||||
std::wstring fileName = std::wstring(static_cast<const wchar_t*>(directory)) + L"\\CrashReport.dmp";
|
||||
HANDLE miniDumpFile = ::CreateFile(fileName.c_str(), GENERIC_WRITE, 0, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
|
||||
|
||||
if (miniDumpFile && miniDumpFile != INVALID_HANDLE_VALUE) {
|
||||
|
||||
MINIDUMP_EXCEPTION_INFORMATION mdei;
|
||||
mdei.ThreadId = ::GetCurrentThreadId();
|
||||
mdei.ExceptionPointers = exceptionPointers;
|
||||
mdei.ClientPointers = 0;
|
||||
|
||||
#ifdef _DEBUG
|
||||
MINIDUMP_TYPE dumpType = MiniDumpWithFullMemory;
|
||||
#else
|
||||
MINIDUMP_TYPE dumpType = MiniDumpNormal;
|
||||
#endif
|
||||
|
||||
::MiniDumpWriteDump(::GetCurrentProcess(), ::GetCurrentProcessId(), miniDumpFile, dumpType, &mdei, 0, 0);
|
||||
::CloseHandle(miniDumpFile);
|
||||
processCrashReport(fileName.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
std::optional<Credential> askCredential(HWND hwnd, const std::wstring& realm)
|
||||
{
|
||||
struct AuthDialog : public Dialog {
|
||||
std::wstring realm;
|
||||
Credential credential;
|
||||
|
||||
protected:
|
||||
void setup()
|
||||
{
|
||||
setText(IDC_REALM_TEXT, realm);
|
||||
}
|
||||
|
||||
void ok() final
|
||||
{
|
||||
credential.username = getText(IDC_AUTH_USER);
|
||||
credential.password = getText(IDC_AUTH_PASSWORD);
|
||||
}
|
||||
};
|
||||
|
||||
AuthDialog dialog;
|
||||
dialog.realm = realm;
|
||||
|
||||
if (dialog.run(hInst, hwnd, IDD_AUTH))
|
||||
return dialog.credential;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
bool askServerTrustEvaluation(HWND hwnd, const std::wstring& text)
|
||||
{
|
||||
class ServerTrustEvaluationDialog : public Dialog {
|
||||
public:
|
||||
ServerTrustEvaluationDialog(const std::wstring& text)
|
||||
: m_text { text }
|
||||
{
|
||||
SendMessage(GetDlgItem(this->hDlg(), IDC_SERVER_TRUST_TEXT), WM_SETFONT, (WPARAM)GetStockObject(ANSI_FIXED_FONT), TRUE);
|
||||
}
|
||||
|
||||
protected:
|
||||
std::wstring m_text;
|
||||
|
||||
void setup()
|
||||
{
|
||||
setText(IDC_SERVER_TRUST_TEXT, m_text);
|
||||
}
|
||||
|
||||
void ok() final
|
||||
{
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
ServerTrustEvaluationDialog dialog { text };
|
||||
return dialog.run(hInst, hwnd, IDD_SERVER_TRUST);
|
||||
}
|
||||
|
||||
CommandLineOptions parseCommandLine()
|
||||
{
|
||||
CommandLineOptions options;
|
||||
|
||||
int argc = 0;
|
||||
WCHAR** argv = CommandLineToArgvW(GetCommandLineW(), &argc);
|
||||
for (int i = 1; i < argc; ++i) {
|
||||
if (!wcsicmp(argv[i], L"--desktop"))
|
||||
options.useFullDesktop = true;
|
||||
else if (!wcsicmp(argv[i], L"--inspector-pipe"))
|
||||
options.inspectorPipe = true;
|
||||
else if (!wcsncmp(argv[i], L"--user-data-dir=", 16))
|
||||
options.userDataDir = argv[i] + 16;
|
||||
else if (!wcsncmp(argv[i], L"--curl-proxy=", 13))
|
||||
options.curloptProxy = argv[i] + 13;
|
||||
else if (!wcsncmp(argv[i], L"--curl-noproxy=", 15))
|
||||
options.curloptNoproxy = argv[i] + 15;
|
||||
else if (!wcsicmp(argv[i], L"--headless"))
|
||||
options.headless = true;
|
||||
else if (!wcsicmp(argv[i], L"--no-startup-window"))
|
||||
options.noStartupWindow = true;
|
||||
else if (!wcsicmp(argv[i], L"--disable-accelerated-compositing"))
|
||||
options.disableAcceleratedCompositing = true;
|
||||
else if (!options.requestedURL)
|
||||
options.requestedURL = argv[i];
|
||||
}
|
||||
|
||||
return options;
|
||||
}
|
||||
|
||||
std::wstring replaceString(std::wstring src, const std::wstring& oldValue, const std::wstring& newValue)
|
||||
{
|
||||
if (src.empty() || oldValue.empty())
|
||||
return src;
|
||||
|
||||
size_t pos = 0;
|
||||
while ((pos = src.find(oldValue, pos)) != src.npos) {
|
||||
src.replace(pos, oldValue.length(), newValue);
|
||||
pos += newValue.length();
|
||||
}
|
||||
|
||||
return src;
|
||||
}
|
||||
|
||||
std::wstring createString(WKStringRef wkString)
|
||||
{
|
||||
size_t maxSize = WKStringGetLength(wkString);
|
||||
|
||||
std::vector<WKChar> wkCharBuffer(maxSize);
|
||||
size_t actualLength = WKStringGetCharacters(wkString, wkCharBuffer.data(), maxSize);
|
||||
return std::wstring(wkCharBuffer.data(), actualLength);
|
||||
}
|
||||
|
||||
std::wstring createString(WKURLRef wkURL)
|
||||
{
|
||||
if (!wkURL)
|
||||
return { };
|
||||
WKRetainPtr<WKStringRef> url = adoptWK(WKURLCopyString(wkURL));
|
||||
return createString(url.get());
|
||||
}
|
||||
|
||||
std::string createUTF8String(const wchar_t* src, size_t srcLength)
|
||||
{
|
||||
int length = WideCharToMultiByte(CP_UTF8, 0, src, srcLength, 0, 0, nullptr, nullptr);
|
||||
std::vector<char> buffer(length);
|
||||
size_t actualLength = WideCharToMultiByte(CP_UTF8, 0, src, srcLength, buffer.data(), length, nullptr, nullptr);
|
||||
return { buffer.data(), actualLength };
|
||||
}
|
||||
|
||||
WKRetainPtr<WKStringRef> createWKString(_bstr_t str)
|
||||
{
|
||||
auto utf8 = createUTF8String(str, str.length());
|
||||
return adoptWK(WKStringCreateWithUTF8CString(utf8.data()));
|
||||
}
|
||||
|
||||
WKRetainPtr<WKStringRef> createWKString(const std::wstring& str)
|
||||
{
|
||||
auto utf8 = createUTF8String(str.c_str(), str.length());
|
||||
return adoptWK(WKStringCreateWithUTF8CString(utf8.data()));
|
||||
}
|
||||
|
||||
WKRetainPtr<WKURLRef> createWKURL(_bstr_t str)
|
||||
{
|
||||
auto utf8 = createUTF8String(str, str.length());
|
||||
return adoptWK(WKURLCreateWithUTF8CString(utf8.data()));
|
||||
}
|
||||
|
||||
WKRetainPtr<WKURLRef> createWKURL(const std::wstring& str)
|
||||
{
|
||||
auto utf8 = createUTF8String(str.c_str(), str.length());
|
||||
return adoptWK(WKURLCreateWithUTF8CString(utf8.data()));
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Copyright (C) 2018 Sony Interactive Entertainment Inc.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "stdafx.h"
|
||||
#include <optional>
|
||||
#include <WebKit/WKRetainPtr.h>
|
||||
#include <WebKit/WKString.h>
|
||||
#include <WebKit/WKURL.h>
|
||||
|
||||
struct CommandLineOptions {
|
||||
bool useFullDesktop { };
|
||||
bool inspectorPipe { };
|
||||
bool headless { };
|
||||
bool noStartupWindow { };
|
||||
bool disableAcceleratedCompositing { };
|
||||
_bstr_t requestedURL;
|
||||
_bstr_t userDataDir;
|
||||
_bstr_t curloptProxy;
|
||||
_bstr_t curloptNoproxy;
|
||||
|
||||
CommandLineOptions()
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
struct Credential {
|
||||
std::wstring username;
|
||||
std::wstring password;
|
||||
};
|
||||
|
||||
void computeFullDesktopFrame();
|
||||
bool getAppDataFolder(_bstr_t& directory);
|
||||
CommandLineOptions parseCommandLine();
|
||||
void createCrashReport(EXCEPTION_POINTERS*);
|
||||
std::optional<Credential> askCredential(HWND, const std::wstring& realm);
|
||||
|
||||
bool askServerTrustEvaluation(HWND, const std::wstring& text);
|
||||
std::wstring replaceString(std::wstring src, const std::wstring& oldValue, const std::wstring& newValue);
|
||||
|
||||
extern HINSTANCE hInst;
|
||||
extern POINT s_windowPosition;
|
||||
extern SIZE s_windowSize;
|
||||
extern bool s_headless;
|
||||
|
||||
std::wstring createString(WKStringRef wkString);
|
||||
std::wstring createString(WKURLRef wkURL);
|
||||
std::string createUTF8String(const wchar_t* src, size_t srcLength);
|
||||
WKRetainPtr<WKStringRef> createWKString(_bstr_t str);
|
||||
WKRetainPtr<WKStringRef> createWKString(const std::wstring& str);
|
||||
WKRetainPtr<WKURLRef> createWKURL(_bstr_t str);
|
||||
WKRetainPtr<WKURLRef> createWKURL(const std::wstring& str);
|
||||
@@ -0,0 +1,153 @@
|
||||
/*
|
||||
* Copyright (C) 2018 Sony Interactive Entertainment Inc.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "stdafx.h"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
class Dialog {
|
||||
public:
|
||||
bool run(HINSTANCE hInst, HWND hwnd, int dialogId)
|
||||
{
|
||||
auto result = DialogBoxParam(hInst, MAKEINTRESOURCE(dialogId), hwnd, doalogProc, reinterpret_cast<LPARAM>(this));
|
||||
return (result > 0);
|
||||
}
|
||||
|
||||
static INT_PTR CALLBACK doalogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
if (message == WM_INITDIALOG)
|
||||
SetWindowLongPtr(hDlg, DWLP_USER, lParam);
|
||||
else
|
||||
lParam = GetWindowLongPtr(hDlg, DWLP_USER);
|
||||
|
||||
auto* dialog = reinterpret_cast<Dialog*>(lParam);
|
||||
return dialog->handle(hDlg, message, wParam);
|
||||
}
|
||||
|
||||
protected:
|
||||
INT_PTR handle(HWND hDlg, UINT message, WPARAM wParam)
|
||||
{
|
||||
switch (message) {
|
||||
case WM_INITDIALOG: {
|
||||
m_hDlg = hDlg;
|
||||
setup();
|
||||
update();
|
||||
return TRUE;
|
||||
}
|
||||
case WM_COMMAND:
|
||||
int wmId = LOWORD(wParam);
|
||||
switch (wmId) {
|
||||
case IDOK:
|
||||
ok();
|
||||
close(true);
|
||||
return TRUE;
|
||||
case IDCANCEL:
|
||||
cancel();
|
||||
close(false);
|
||||
return TRUE;
|
||||
default:
|
||||
auto handled = command(wmId);
|
||||
update();
|
||||
return handled;
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
virtual void setup() { }
|
||||
virtual void update() { updateOkButton(validate()); }
|
||||
virtual bool validate() { return true; }
|
||||
virtual void updateOkButton(bool isValid) { setEnabled(IDOK, isValid); }
|
||||
virtual bool command(int wmId) { return false; }
|
||||
virtual void ok() { }
|
||||
virtual void cancel() { }
|
||||
|
||||
void close(bool success) { EndDialog(m_hDlg, success); }
|
||||
|
||||
HWND hDlg() { return m_hDlg; }
|
||||
|
||||
HWND item(int itemId) { return GetDlgItem(m_hDlg, itemId); }
|
||||
|
||||
void setEnabled(int itemId, bool enabled)
|
||||
{
|
||||
EnableWindow(item(itemId), enabled);
|
||||
}
|
||||
|
||||
void setText(int itemId, const std::wstring& str)
|
||||
{
|
||||
SetDlgItemText(m_hDlg, itemId, _bstr_t(str.c_str()));
|
||||
}
|
||||
|
||||
std::wstring getText(int itemId)
|
||||
{
|
||||
auto length = getTextLength(itemId);
|
||||
std::vector<TCHAR> buffer(length + 1, 0);
|
||||
GetWindowText(item(itemId), buffer.data(), length + 1);
|
||||
return std::wstring { buffer.data() };
|
||||
}
|
||||
|
||||
int getTextLength(int itemId)
|
||||
{
|
||||
return GetWindowTextLength(item(itemId));
|
||||
}
|
||||
|
||||
class RadioGroup {
|
||||
public:
|
||||
RadioGroup(Dialog& dialog, int first, int last)
|
||||
: m_dialog(dialog)
|
||||
, m_first(first)
|
||||
, m_last(last)
|
||||
{
|
||||
}
|
||||
|
||||
void set(int item)
|
||||
{
|
||||
CheckRadioButton(m_dialog.hDlg(), m_first, m_last, item);
|
||||
}
|
||||
|
||||
int get()
|
||||
{
|
||||
for (int id = m_first; id <= m_last; id++) {
|
||||
if (IsDlgButtonChecked(m_dialog.hDlg(), id) == BST_CHECKED)
|
||||
return id;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
private:
|
||||
Dialog& m_dialog;
|
||||
int m_first;
|
||||
int m_last;
|
||||
};
|
||||
|
||||
RadioGroup radioGroup(int first, int last)
|
||||
{
|
||||
return RadioGroup(*this, first, last);
|
||||
}
|
||||
|
||||
HWND m_hDlg { };
|
||||
};
|
||||
@@ -0,0 +1,464 @@
|
||||
/*
|
||||
* Copyright (C) 2018 Sony Interactive Entertainment Inc.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "Common.h"
|
||||
#include "MainWindow.h"
|
||||
#include "PlaywrightLibResource.h"
|
||||
#include "WebKitBrowserWindow.h"
|
||||
#include <WebKit/WKPreferencesRefPrivate.h>
|
||||
#include <sstream>
|
||||
|
||||
namespace WebCore {
|
||||
float deviceScaleFactorForWindow(HWND);
|
||||
}
|
||||
|
||||
static const wchar_t* kPlaywrightRegistryKey = L"Software\\WebKit\\Playwright";
|
||||
|
||||
static constexpr int kToolbarImageSize = 24;
|
||||
static constexpr int kToolbarURLBarIndex = 3;
|
||||
|
||||
static WNDPROC DefEditProc = nullptr;
|
||||
|
||||
static LRESULT CALLBACK EditProc(HWND, UINT, WPARAM, LPARAM);
|
||||
static INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM);
|
||||
|
||||
std::wstring MainWindow::s_windowClass;
|
||||
size_t MainWindow::s_numInstances;
|
||||
|
||||
bool MainWindow::s_controlledRemotely = false;
|
||||
bool MainWindow::s_disableAcceleratedCompositing = false;
|
||||
|
||||
void MainWindow::configure(bool controlledRemotely, bool disableAcceleratedCompositing) {
|
||||
s_controlledRemotely = controlledRemotely;
|
||||
s_disableAcceleratedCompositing = disableAcceleratedCompositing;
|
||||
}
|
||||
|
||||
static std::wstring loadString(int id)
|
||||
{
|
||||
constexpr size_t length = 100;
|
||||
wchar_t buff[length];
|
||||
LoadString(hInst, id, buff, length);
|
||||
return buff;
|
||||
}
|
||||
|
||||
void MainWindow::registerClass(HINSTANCE hInstance)
|
||||
{
|
||||
static bool initialized = false;
|
||||
if (initialized)
|
||||
return;
|
||||
initialized = true;
|
||||
|
||||
s_windowClass = loadString(IDC_PLAYWRIGHT);
|
||||
|
||||
WNDCLASSEX wcex;
|
||||
wcex.cbSize = sizeof(WNDCLASSEX);
|
||||
wcex.style = CS_HREDRAW | CS_VREDRAW;
|
||||
wcex.lpfnWndProc = WndProc;
|
||||
wcex.cbClsExtra = 0;
|
||||
wcex.cbWndExtra = 0;
|
||||
wcex.hInstance = hInstance;
|
||||
wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_PLAYWRIGHT));
|
||||
wcex.hCursor = LoadCursor(0, IDC_ARROW);
|
||||
wcex.hbrBackground = 0;
|
||||
wcex.lpszMenuName = MAKEINTRESOURCE(IDC_PLAYWRIGHT);
|
||||
wcex.lpszClassName = s_windowClass.c_str();
|
||||
wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_PLAYWRIGHT));
|
||||
|
||||
RegisterClassEx(&wcex);
|
||||
}
|
||||
|
||||
bool MainWindow::isInstance(HWND hwnd)
|
||||
{
|
||||
wchar_t buff[64];
|
||||
if (!GetClassName(hwnd, buff, _countof(buff)))
|
||||
return false;
|
||||
return s_windowClass == buff;
|
||||
}
|
||||
|
||||
MainWindow::MainWindow()
|
||||
{
|
||||
s_numInstances++;
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
{
|
||||
s_numInstances--;
|
||||
}
|
||||
|
||||
void MainWindow::createToolbar(HINSTANCE hInstance)
|
||||
{
|
||||
m_hToolbarWnd = CreateWindowEx(0, TOOLBARCLASSNAME, nullptr,
|
||||
WS_CHILD | WS_BORDER | TBSTYLE_FLAT | TBSTYLE_LIST | TBSTYLE_TOOLTIPS, 0, 0, 0, 0,
|
||||
m_hMainWnd, nullptr, hInstance, nullptr);
|
||||
|
||||
if (!m_hToolbarWnd)
|
||||
return;
|
||||
|
||||
const int ImageListID = 0;
|
||||
|
||||
HIMAGELIST hImageList;
|
||||
hImageList = ImageList_LoadImage(hInstance, MAKEINTRESOURCE(IDB_TOOLBAR), kToolbarImageSize, 0, CLR_DEFAULT, IMAGE_BITMAP, 0);
|
||||
|
||||
SendMessage(m_hToolbarWnd, TB_SETIMAGELIST, ImageListID, reinterpret_cast<LPARAM>(hImageList));
|
||||
SendMessage(m_hToolbarWnd, TB_SETEXTENDEDSTYLE, 0, TBSTYLE_EX_MIXEDBUTTONS);
|
||||
|
||||
const DWORD buttonStyles = BTNS_AUTOSIZE;
|
||||
|
||||
TBBUTTON tbButtons[] = {
|
||||
{ MAKELONG(0, ImageListID), IDM_HISTORY_BACKWARD, TBSTATE_ENABLED, buttonStyles, { }, 0, (INT_PTR)L"Back" },
|
||||
{ MAKELONG(1, ImageListID), IDM_HISTORY_FORWARD, TBSTATE_ENABLED, buttonStyles, { }, 0, (INT_PTR)L"Forward"},
|
||||
{ MAKELONG(2, ImageListID), IDM_RELOAD, TBSTATE_ENABLED, buttonStyles, { }, 0, (INT_PTR)L"Reload"},
|
||||
{ 0, 0, TBSTATE_ENABLED, BTNS_SEP, { }, 0, 0}, // URL bar
|
||||
};
|
||||
|
||||
SendMessage(m_hToolbarWnd, TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0);
|
||||
SendMessage(m_hToolbarWnd, TB_ADDBUTTONS, _countof(tbButtons), reinterpret_cast<LPARAM>(&tbButtons));
|
||||
ShowWindow(m_hToolbarWnd, true);
|
||||
|
||||
m_hURLBarWnd = CreateWindow(L"EDIT", 0, WS_CHILD | WS_VISIBLE | WS_BORDER | ES_LEFT | ES_AUTOHSCROLL, 0, 0, 0, 0, m_hToolbarWnd, 0, hInstance, 0);
|
||||
|
||||
DefEditProc = reinterpret_cast<WNDPROC>(GetWindowLongPtr(m_hURLBarWnd, GWLP_WNDPROC));
|
||||
SetWindowLongPtr(m_hURLBarWnd, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(EditProc));
|
||||
}
|
||||
|
||||
void MainWindow::resizeToolbar(int parentWidth)
|
||||
{
|
||||
TBBUTTONINFO info { sizeof(TBBUTTONINFO), TBIF_BYINDEX | TBIF_SIZE };
|
||||
info.cx = parentWidth - m_toolbarItemsWidth;
|
||||
SendMessage(m_hToolbarWnd, TB_SETBUTTONINFO, kToolbarURLBarIndex, reinterpret_cast<LPARAM>(&info));
|
||||
SendMessage(m_hToolbarWnd, TB_AUTOSIZE, 0, 0);
|
||||
|
||||
RECT rect;
|
||||
SendMessage(m_hToolbarWnd, TB_GETITEMRECT, kToolbarURLBarIndex, reinterpret_cast<LPARAM>(&rect));
|
||||
MoveWindow(m_hURLBarWnd, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, true);
|
||||
}
|
||||
|
||||
void MainWindow::rescaleToolbar()
|
||||
{
|
||||
const float scaleFactor = WebCore::deviceScaleFactorForWindow(m_hMainWnd);
|
||||
const int scaledImageSize = kToolbarImageSize * scaleFactor;
|
||||
|
||||
TBBUTTONINFO info { sizeof(TBBUTTONINFO), TBIF_BYINDEX | TBIF_SIZE };
|
||||
|
||||
info.cx = 0;
|
||||
SendMessage(m_hToolbarWnd, TB_SETBUTTONINFO, kToolbarURLBarIndex, reinterpret_cast<LPARAM>(&info));
|
||||
SendMessage(m_hToolbarWnd, TB_AUTOSIZE, 0, 0);
|
||||
|
||||
int numItems = SendMessage(m_hToolbarWnd, TB_BUTTONCOUNT, 0, 0);
|
||||
|
||||
RECT rect;
|
||||
SendMessage(m_hToolbarWnd, TB_GETITEMRECT, numItems-1, reinterpret_cast<LPARAM>(&rect));
|
||||
m_toolbarItemsWidth = rect.right;
|
||||
}
|
||||
|
||||
bool MainWindow::init(HINSTANCE hInstance, WKPageConfigurationRef conf)
|
||||
{
|
||||
auto prefs = adoptWK(WKPreferencesCreate());
|
||||
|
||||
WKPageConfigurationSetPreferences(conf, prefs.get());
|
||||
WKPreferencesSetMediaCapabilitiesEnabled(prefs.get(), false);
|
||||
WKPreferencesSetDeveloperExtrasEnabled(prefs.get(), true);
|
||||
if (s_disableAcceleratedCompositing)
|
||||
WKPreferencesSetAcceleratedCompositingEnabled(prefs.get(), false);
|
||||
|
||||
m_configuration = conf;
|
||||
|
||||
registerClass(hInstance);
|
||||
|
||||
auto title = loadString(IDS_APP_TITLE);
|
||||
|
||||
m_hMainWnd = CreateWindowExW(s_headless ? WS_EX_NOACTIVATE : 0, s_windowClass.c_str(), title.c_str(),
|
||||
WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, 0, 0, hInstance, this);
|
||||
|
||||
if (!m_hMainWnd)
|
||||
return false;
|
||||
|
||||
if (!s_headless) {
|
||||
createToolbar(hInstance);
|
||||
if (!m_hToolbarWnd)
|
||||
return false;
|
||||
}
|
||||
|
||||
m_browserWindow.reset(new WebKitBrowserWindow(*this, m_hMainWnd, conf));
|
||||
|
||||
updateDeviceScaleFactor();
|
||||
resizeSubViews();
|
||||
|
||||
if (s_headless) {
|
||||
auto menu = GetMenu(m_hMainWnd);
|
||||
SetMenu(m_hMainWnd, NULL);
|
||||
DestroyMenu(menu);
|
||||
} else {
|
||||
SetFocus(m_hURLBarWnd);
|
||||
ShowWindow(m_hMainWnd, SW_SHOW);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void MainWindow::resizeSubViews()
|
||||
{
|
||||
RECT rcClient;
|
||||
GetClientRect(m_hMainWnd, &rcClient);
|
||||
if (s_headless) {
|
||||
MoveWindow(m_browserWindow->hwnd(), 0, 0, rcClient.right, rcClient.bottom, true);
|
||||
return;
|
||||
}
|
||||
|
||||
resizeToolbar(rcClient.right);
|
||||
|
||||
RECT rect;
|
||||
GetWindowRect(m_hToolbarWnd, &rect);
|
||||
POINT toolbarBottom = { 0, rect.bottom };
|
||||
ScreenToClient(m_hMainWnd, &toolbarBottom);
|
||||
auto height = toolbarBottom.y;
|
||||
MoveWindow(m_browserWindow->hwnd(), 0, height, rcClient.right, rcClient.bottom - height, true);
|
||||
}
|
||||
|
||||
LRESULT CALLBACK MainWindow::WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
LRESULT result = 0;
|
||||
MainWindow* thisWindow = reinterpret_cast<MainWindow*>(GetWindowLongPtr(hWnd, GWLP_USERDATA));
|
||||
if (!thisWindow && message != WM_CREATE)
|
||||
return DefWindowProc(hWnd, message, wParam, lParam);
|
||||
|
||||
switch (message) {
|
||||
case WM_ACTIVATE:
|
||||
switch (LOWORD(wParam)) {
|
||||
case WA_ACTIVE:
|
||||
case WA_CLICKACTIVE:
|
||||
SetFocus(thisWindow->browserWindow()->hwnd());
|
||||
}
|
||||
break;
|
||||
case WM_CREATE:
|
||||
SetWindowLongPtr(hWnd, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(reinterpret_cast<LPCREATESTRUCT>(lParam)->lpCreateParams));
|
||||
break;
|
||||
case WM_APPCOMMAND: {
|
||||
auto cmd = GET_APPCOMMAND_LPARAM(lParam);
|
||||
switch (cmd) {
|
||||
case APPCOMMAND_BROWSER_BACKWARD:
|
||||
thisWindow->browserWindow()->navigateForwardOrBackward(false);
|
||||
result = 1;
|
||||
break;
|
||||
case APPCOMMAND_BROWSER_FORWARD:
|
||||
thisWindow->browserWindow()->navigateForwardOrBackward(true);
|
||||
result = 1;
|
||||
break;
|
||||
case APPCOMMAND_BROWSER_REFRESH:
|
||||
thisWindow->browserWindow()->reload();
|
||||
result = 1;
|
||||
break;
|
||||
case APPCOMMAND_BROWSER_STOP:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case WM_COMMAND: {
|
||||
int wmId = LOWORD(wParam);
|
||||
int wmEvent = HIWORD(wParam);
|
||||
switch (wmEvent) {
|
||||
case 0: // Menu or BN_CLICKED
|
||||
case 1: // Accelerator
|
||||
break;
|
||||
default:
|
||||
return DefWindowProc(hWnd, message, wParam, lParam);
|
||||
}
|
||||
// Parse the menu selections:
|
||||
switch (wmId) {
|
||||
case IDC_URL_BAR:
|
||||
thisWindow->onURLBarEnter();
|
||||
break;
|
||||
case IDM_NEW_WINDOW: {
|
||||
auto* newWindow = new MainWindow();
|
||||
newWindow->init(hInst, thisWindow->m_configuration.get());
|
||||
break;
|
||||
}
|
||||
case IDM_CLOSE_WINDOW:
|
||||
PostMessage(hWnd, WM_CLOSE, 0, 0);
|
||||
break;
|
||||
case IDM_ABOUT:
|
||||
DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
|
||||
break;
|
||||
case IDM_WEB_INSPECTOR:
|
||||
thisWindow->browserWindow()->launchInspector();
|
||||
break;
|
||||
case IDM_HISTORY_BACKWARD:
|
||||
case IDM_HISTORY_FORWARD:
|
||||
thisWindow->browserWindow()->navigateForwardOrBackward(wmId == IDM_HISTORY_FORWARD);
|
||||
break;
|
||||
case IDM_ACTUAL_SIZE:
|
||||
thisWindow->browserWindow()->resetZoom();
|
||||
break;
|
||||
case IDM_RELOAD:
|
||||
thisWindow->browserWindow()->reload();
|
||||
break;
|
||||
case IDM_ZOOM_IN:
|
||||
thisWindow->browserWindow()->zoomIn();
|
||||
break;
|
||||
case IDM_ZOOM_OUT:
|
||||
thisWindow->browserWindow()->zoomOut();
|
||||
break;
|
||||
default:
|
||||
if (!thisWindow->toggleMenuItem(wmId))
|
||||
return DefWindowProc(hWnd, message, wParam, lParam);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case WM_NCDESTROY:
|
||||
SetWindowLongPtr(hWnd, GWLP_USERDATA, 0);
|
||||
delete thisWindow;
|
||||
if (s_controlledRemotely || s_numInstances > 0)
|
||||
return 0;
|
||||
PostQuitMessage(0);
|
||||
break;
|
||||
case WM_SIZE:
|
||||
thisWindow->resizeSubViews();
|
||||
break;
|
||||
case WM_DPICHANGED: {
|
||||
thisWindow->updateDeviceScaleFactor();
|
||||
auto& rect = *reinterpret_cast<RECT*>(lParam);
|
||||
SetWindowPos(hWnd, nullptr, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, SWP_NOZORDER | SWP_NOACTIVATE);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
return DefWindowProc(hWnd, message, wParam, lParam);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static bool menuItemIsChecked(const MENUITEMINFO& info)
|
||||
{
|
||||
return info.fState & MFS_CHECKED;
|
||||
}
|
||||
|
||||
bool MainWindow::toggleMenuItem(UINT menuID)
|
||||
{
|
||||
if (s_headless)
|
||||
return (INT_PTR)FALSE;
|
||||
|
||||
HMENU menu = ::GetMenu(hwnd());
|
||||
|
||||
MENUITEMINFO info = { };
|
||||
info.cbSize = sizeof(info);
|
||||
info.fMask = MIIM_STATE;
|
||||
|
||||
if (!::GetMenuItemInfo(menu, menuID, FALSE, &info))
|
||||
return false;
|
||||
|
||||
BOOL newState = !menuItemIsChecked(info);
|
||||
info.fState = (newState) ? MFS_CHECKED : MFS_UNCHECKED;
|
||||
::SetMenuItemInfo(menu, menuID, FALSE, &info);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
LRESULT CALLBACK EditProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
switch (message) {
|
||||
case WM_SETFOCUS:
|
||||
PostMessage(hWnd, EM_SETSEL, 0, -1);
|
||||
break;
|
||||
case WM_CHAR:
|
||||
if (wParam == 13) {
|
||||
// Enter Key
|
||||
::PostMessage(GetParent(hWnd), static_cast<UINT>(WM_COMMAND), MAKELPARAM(IDC_URL_BAR, 0), 0);
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return CallWindowProc(DefEditProc, hWnd, message, wParam, lParam);
|
||||
}
|
||||
|
||||
// Message handler for about box.
|
||||
INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
UNREFERENCED_PARAMETER(lParam);
|
||||
switch (message) {
|
||||
case WM_INITDIALOG:
|
||||
return (INT_PTR)TRUE;
|
||||
|
||||
case WM_COMMAND:
|
||||
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) {
|
||||
EndDialog(hDlg, LOWORD(wParam));
|
||||
return (INT_PTR)TRUE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return (INT_PTR)FALSE;
|
||||
}
|
||||
|
||||
void MainWindow::loadURL(std::wstring url)
|
||||
{
|
||||
if (::PathFileExists(url.c_str()) || ::PathIsUNC(url.c_str())) {
|
||||
wchar_t fileURL[INTERNET_MAX_URL_LENGTH];
|
||||
DWORD fileURLLength = _countof(fileURL);
|
||||
|
||||
if (SUCCEEDED(::UrlCreateFromPath(url.c_str(), fileURL, &fileURLLength, 0)))
|
||||
url = fileURL;
|
||||
}
|
||||
if (url.find(L"://") == url.npos && url.find(L"about:blank") == url.npos)
|
||||
url = L"http://" + url;
|
||||
|
||||
if (FAILED(m_browserWindow->loadURL(_bstr_t(url.c_str()))))
|
||||
return;
|
||||
|
||||
if (!s_headless)
|
||||
SetFocus(m_browserWindow->hwnd());
|
||||
}
|
||||
|
||||
void MainWindow::onURLBarEnter()
|
||||
{
|
||||
if (s_headless)
|
||||
return;
|
||||
wchar_t url[INTERNET_MAX_URL_LENGTH];
|
||||
GetWindowText(m_hURLBarWnd, url, INTERNET_MAX_URL_LENGTH);
|
||||
loadURL(url);
|
||||
}
|
||||
|
||||
void MainWindow::updateDeviceScaleFactor()
|
||||
{
|
||||
if (s_headless)
|
||||
return;
|
||||
if (m_hURLBarFont)
|
||||
::DeleteObject(m_hURLBarFont);
|
||||
|
||||
rescaleToolbar();
|
||||
|
||||
RECT rect;
|
||||
GetClientRect(m_hToolbarWnd, &rect);
|
||||
int fontHeight = 20;
|
||||
|
||||
m_hURLBarFont = ::CreateFont(fontHeight, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, DEFAULT_CHARSET,
|
||||
OUT_TT_ONLY_PRECIS, CLIP_DEFAULT_PRECIS, CLEARTYPE_QUALITY, FF_DONTCARE, L"Tahoma");
|
||||
::SendMessage(m_hURLBarWnd, static_cast<UINT>(WM_SETFONT), reinterpret_cast<WPARAM>(m_hURLBarFont), TRUE);
|
||||
}
|
||||
|
||||
void MainWindow::activeURLChanged(std::wstring url)
|
||||
{
|
||||
if (s_headless)
|
||||
return;
|
||||
SetWindowText(m_hURLBarWnd, url.c_str());
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* Copyright (C) 2018 Sony Interactive Entertainment Inc.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "WebKitBrowserWindow.h"
|
||||
|
||||
#include <WebKit/WKBase.h>
|
||||
#include <WebKit/WKRetainPtr.h>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
class MainWindow : public BrowserWindowClient {
|
||||
public:
|
||||
static void configure(bool controlledRemotely, bool disableAcceleratedCompositing);
|
||||
|
||||
MainWindow();
|
||||
|
||||
~MainWindow();
|
||||
bool init(HINSTANCE hInstance, WKPageConfigurationRef);
|
||||
|
||||
void resizeSubViews();
|
||||
HWND hwnd() const { return m_hMainWnd; }
|
||||
WebKitBrowserWindow* browserWindow() const { return m_browserWindow.get(); }
|
||||
|
||||
void loadURL(std::wstring);
|
||||
|
||||
static bool isInstance(HWND);
|
||||
|
||||
private:
|
||||
static LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
|
||||
static void registerClass(HINSTANCE hInstance);
|
||||
static std::wstring s_windowClass;
|
||||
static size_t s_numInstances;
|
||||
static bool s_controlledRemotely;
|
||||
static bool s_disableAcceleratedCompositing;
|
||||
|
||||
bool toggleMenuItem(UINT menuID);
|
||||
void onURLBarEnter();
|
||||
void updateDeviceScaleFactor();
|
||||
|
||||
void createToolbar(HINSTANCE);
|
||||
void resizeToolbar(int);
|
||||
void rescaleToolbar();
|
||||
|
||||
// BrowserWindowClient
|
||||
void activeURLChanged(std::wstring) final;
|
||||
|
||||
HWND m_hMainWnd { nullptr };
|
||||
HWND m_hToolbarWnd { nullptr };
|
||||
HWND m_hURLBarWnd { nullptr };
|
||||
HWND m_hProgressIndicator { nullptr };
|
||||
HWND m_hCacheWnd { nullptr };
|
||||
HGDIOBJ m_hURLBarFont { nullptr };
|
||||
// WKPageConfigurationRef retains page and WebKitBrowserWindow retains page via view
|
||||
// make sure view is deleted after the page.
|
||||
std::unique_ptr<WebKitBrowserWindow> m_browserWindow;
|
||||
WKRetainPtr<WKPageConfigurationRef> m_configuration;
|
||||
int m_toolbarItemsWidth { };
|
||||
};
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 111 KiB |
@@ -0,0 +1,354 @@
|
||||
// Microsoft Visual C++ generated resource script.
|
||||
//
|
||||
#include "PlaywrightLibResource.h"
|
||||
|
||||
#define APSTUDIO_READONLY_SYMBOLS
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Generated from the TEXTINCLUDE 2 resource.
|
||||
//
|
||||
#define APSTUDIO_HIDDEN_SYMBOLS
|
||||
#include "windows.h"
|
||||
#undef APSTUDIO_HIDDEN_SYMBOLS
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#undef APSTUDIO_READONLY_SYMBOLS
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// English (United States) resources
|
||||
|
||||
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
|
||||
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
|
||||
#pragma code_page(1252)
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Icon
|
||||
//
|
||||
|
||||
// Icon with lowest ID value placed first to ensure application icon
|
||||
// remains consistent on all systems.
|
||||
IDI_PLAYWRIGHT ICON "Playwright.ico"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Menu
|
||||
//
|
||||
|
||||
IDC_PLAYWRIGHT MENU
|
||||
BEGIN
|
||||
POPUP "&File"
|
||||
BEGIN
|
||||
MENUITEM "New Window\tCtrl-N" IDM_NEW_WINDOW
|
||||
MENUITEM "Close\tCtrl-W", IDM_CLOSE_WINDOW
|
||||
END
|
||||
POPUP "&View"
|
||||
BEGIN
|
||||
MENUITEM "Actual Size\tCtrl+0", IDM_ACTUAL_SIZE
|
||||
MENUITEM "Zoom In\tCtrl++", IDM_ZOOM_IN
|
||||
MENUITEM "Zoom Out\tCtrl+-", IDM_ZOOM_OUT
|
||||
MENUITEM "Invert Colors", IDM_INVERT_COLORS
|
||||
END
|
||||
POPUP "&History"
|
||||
BEGIN
|
||||
MENUITEM "Reload\tCtrl-R", IDM_RELOAD
|
||||
MENUITEM "Back", IDM_HISTORY_BACKWARD
|
||||
MENUITEM "Forward", IDM_HISTORY_FORWARD
|
||||
END
|
||||
POPUP "D&evelop"
|
||||
BEGIN
|
||||
MENUITEM "Show Web Inspector", IDM_WEB_INSPECTOR
|
||||
END
|
||||
POPUP "&Help"
|
||||
BEGIN
|
||||
MENUITEM "&About ...", IDM_ABOUT
|
||||
END
|
||||
END
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Accelerator
|
||||
//
|
||||
|
||||
IDC_PLAYWRIGHT ACCELERATORS
|
||||
BEGIN
|
||||
"/", IDM_ABOUT, ASCII, ALT, NOINVERT
|
||||
"0", IDM_ACTUAL_SIZE, VIRTKEY, CONTROL, NOINVERT
|
||||
"?", IDM_ABOUT, ASCII, ALT, NOINVERT
|
||||
"R", IDM_RELOAD, VIRTKEY, CONTROL, NOINVERT
|
||||
"N", IDM_NEW_WINDOW, VIRTKEY, CONTROL, NOINVERT
|
||||
VK_ADD, IDM_ZOOM_IN, VIRTKEY, CONTROL, NOINVERT
|
||||
VK_OEM_MINUS, IDM_ZOOM_OUT, VIRTKEY, CONTROL, NOINVERT
|
||||
VK_OEM_PLUS, IDM_ZOOM_IN, VIRTKEY, CONTROL, NOINVERT
|
||||
VK_SUBTRACT, IDM_ZOOM_OUT, VIRTKEY, CONTROL, NOINVERT
|
||||
END
|
||||
|
||||
IDR_ACCELERATORS_PRE ACCELERATORS
|
||||
BEGIN
|
||||
"W", IDM_CLOSE_WINDOW, VIRTKEY, CONTROL, NOINVERT
|
||||
END
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Dialog
|
||||
//
|
||||
|
||||
IDD_ABOUTBOX DIALOGEX 22, 17, 230, 41
|
||||
STYLE DS_SETFONT | DS_MODALFRAME | WS_CAPTION | WS_SYSMENU
|
||||
CAPTION "About"
|
||||
FONT 8, "MS Shell Dlg", 0, 0, 0x0
|
||||
BEGIN
|
||||
ICON IDI_PLAYWRIGHT,IDC_MYICON,14,9,20,20
|
||||
LTEXT "Playwright Version 1.1",IDC_STATIC,49,10,119,8
|
||||
LTEXT "Copyright (C) 2015-2019",IDC_STATIC,49,20,119,8
|
||||
DEFPUSHBUTTON "OK",IDOK,186,10,30,11,WS_GROUP
|
||||
END
|
||||
|
||||
IDD_CACHES DIALOGEX 0, 0, 401, 456
|
||||
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
|
||||
CAPTION "Dialog"
|
||||
FONT 8, "MS Shell Dlg", 400, 0, 0x1
|
||||
BEGIN
|
||||
DEFPUSHBUTTON "OK",IDOK,287,435,50,14
|
||||
PUSHBUTTON "Cancel",IDCANCEL,344,435,50,14
|
||||
GROUPBOX "FastMalloc",IDC_STATIC,208,14,186,67
|
||||
GROUPBOX "WebCore Cache",IDC_STATIC,17,83,376,105
|
||||
GROUPBOX "JavaScript Heap",IDC_STATIC,18,193,376,168
|
||||
GROUPBOX "Site Icon Database",IDC_STATIC,18,366,142,65
|
||||
GROUPBOX "Font and Glyph Caches",IDC_STATIC,168,366,226,66
|
||||
GROUPBOX "CFURLCache",IDC_STATIC,7,14,197,67
|
||||
PUSHBUTTON "Empty URLCache",IDC_EMPTY_URL_CACHE,131,63,69,14,WS_DISABLED
|
||||
PUSHBUTTON "Return Free Memory",IDC_RETURN_FREE_MEMORY,308,63,76,14,WS_DISABLED
|
||||
PUSHBUTTON "Empty WebCore Cache",IDC_EMPTY_WEBCORE_CACHE,21,170,83,14,WS_DISABLED
|
||||
CONTROL "Disable WebCore Cache",IDC_CHECK1,"Button",BS_AUTOCHECKBOX | WS_DISABLED | WS_TABSTOP,119,172,93,10
|
||||
PUSHBUTTON "Garbage Collect JavaScript Objects",IDC_GC_JSC,253,343,135,14,WS_DISABLED
|
||||
RTEXT "Reserved VM",IDC_STATIC,212,26,67,9
|
||||
RTEXT "0",IDC_RESERVED_VM,290,26,94,8
|
||||
RTEXT "Committed VM",IDC_STATIC,211,39,67,8
|
||||
RTEXT "0",IDC_COMMITTED_VM,290,39,94,8
|
||||
RTEXT "Free List Bytes",IDC_STATIC,211,52,67,8
|
||||
RTEXT "0",IDC_FREE_LIST_BYTES,290,52,94,8
|
||||
RTEXT "Images",IDC_STATIC,37,106,24,8
|
||||
RTEXT "CSS",IDC_STATIC,47,116,14,8
|
||||
RTEXT "XSL",IDC_STATIC,49,126,12,8
|
||||
RTEXT "JavaScript",IDC_STATIC,27,135,34,8
|
||||
RTEXT "Total",IDC_STATIC,43,146,17,8
|
||||
LTEXT "Objects",IDC_STATIC,111,96,26,8
|
||||
LTEXT "Bytes",IDC_STATIC,175,96,19,8
|
||||
LTEXT "Live",IDC_STATIC,232,96,14,8
|
||||
LTEXT "Decoded",IDC_STATIC,284,96,29,8
|
||||
LTEXT "Purgeable",IDC_STATIC,351,96,33,8
|
||||
RTEXT "0",IDC_IMAGES_OBJECT_COUNT,100,106,32,8
|
||||
RTEXT "0",IDC_CSS_OBJECT_COUNT,100,116,32,8
|
||||
RTEXT "0",IDC_XSL_OBJECT_COUNT,100,126,32,8
|
||||
RTEXT "0",IDC_JSC_OBJECT_COUNT,100,135,32,8
|
||||
RTEXT "0",IDC_TOTAL_OBJECT_COUNT,100,146,32,8
|
||||
RTEXT "0",IDC_IMAGES_BYTES,162,106,32,8
|
||||
RTEXT "0",IDC_CSS_BYTES,162,116,32,8
|
||||
RTEXT "0",IDC_XSL_BYTES,162,126,32,8
|
||||
RTEXT "0",IDC_JSC_BYTES,162,135,32,8
|
||||
RTEXT "0",IDC_TOTAL_BYTES,162,146,32,8
|
||||
RTEXT "0",IDC_IMAGES_LIVE_COUNT,221,106,32,8
|
||||
RTEXT "0",IDC_CSS_LIVE_COUNT,221,116,32,8
|
||||
RTEXT "0",IDC_XSL_LIVE_COUNT,221,126,32,8
|
||||
RTEXT "0",IDC_JSC_LIVE_COUNT,221,135,32,8
|
||||
RTEXT "0",IDC_TOTAL_LIVE_COUNT,221,146,32,8
|
||||
RTEXT "0",IDC_IMAGES_DECODED_COUNT,284,106,32,8
|
||||
RTEXT "0",IDC_CSS_DECODED_COUNT,284,116,32,8
|
||||
RTEXT "0",IDC_XSL_DECODED_COUNT,284,126,32,8
|
||||
RTEXT "0",IDC_JSC_DECODED_COUNT,284,135,32,8
|
||||
RTEXT "0",IDC_TOTAL_DECODED,284,146,32,8
|
||||
RTEXT "0",IDC_IMAGES_PURGEABLE_COUNT,354,106,32,8
|
||||
RTEXT "0",IDC_CSS_PURGEABLE_COUNT,354,116,32,8
|
||||
RTEXT "0",IDC_XSL_PURGEABLE_COUNT,354,126,32,8
|
||||
RTEXT "0",IDC_JSC_PURGEABLE_COUNT,354,135,32,8
|
||||
RTEXT "0",IDC_TOTAL_PURGEABLE,354,146,32,8
|
||||
RTEXT "Total Objects",IDC_STATIC,63,207,44,8
|
||||
RTEXT "Global Objects",IDC_STATIC,56,217,51,8
|
||||
RTEXT "Protected Objects",IDC_STATIC,48,227,59,8
|
||||
RTEXT "0",IDC_TOTAL_JSC_HEAP_OBJECTS,127,207,56,8
|
||||
RTEXT "0",IDC_GLOBAL_JSC_HEAP_OBJECTS,127,217,56,8
|
||||
RTEXT "0",IDC_PROTECTED_JSC_HEAP_OBJECTS,127,227,56,8
|
||||
RTEXT "Size",IDC_STATIC56,223,207,14,8
|
||||
RTEXT "Free",IDC_STATIC57,222,217,16,8
|
||||
RTEXT "0",IDC_JSC_HEAP_SIZE,270,207,56,8
|
||||
RTEXT "0",IDC_JSC_HEAP_FREE,270,217,56,8
|
||||
PUSHBUTTON "Purge Inactive Font Data",IDC_BUTTON5,293,415,95,14,WS_DISABLED
|
||||
LTEXT "Total Font Data Objects",IDC_STATIC,208,379,78,8
|
||||
LTEXT "Inactive Font Data Objects",IDC_STATIC,198,390,88,8
|
||||
LTEXT "Glyph Pages",IDC_STATIC,246,402,40,8
|
||||
RTEXT "0",IDC_TOTAL_FONT_OBJECTS,329,379,56,8
|
||||
RTEXT "0",IDC_INACTIVE_FONT_OBJECTS,329,390,56,8
|
||||
RTEXT "0",IDC_GLYPH_PAGES,329,402,56,8
|
||||
LTEXT "Page URL Mappings",IDC_STATIC,33,380,64,8
|
||||
LTEXT "Retained Page URLs",IDC_STATIC,31,390,66,8
|
||||
LTEXT "Site Icon Records",IDC_STATIC,40,400,57,8
|
||||
LTEXT "Site Icons with Data",IDC_STATIC,32,410,65,8
|
||||
RTEXT "0",IDC_PAGE_URL_MAPPINGS,101,380,52,8
|
||||
RTEXT "0",IDC_RETAINED_PAGE_URLS,101,390,52,8
|
||||
RTEXT "0",IDC_SITE_ICON_RECORDS,101,400,52,8
|
||||
RTEXT "0",IDC_SITE_ICONS_WITH_DATA,101,410,52,8
|
||||
END
|
||||
|
||||
IDD_AUTH DIALOGEX 0, 0, 231, 119
|
||||
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
|
||||
CAPTION "Authentication Required"
|
||||
FONT 8, "MS Shell Dlg", 400, 0, 0x1
|
||||
BEGIN
|
||||
DEFPUSHBUTTON "Sign In",IDOK,116,98,50,14
|
||||
PUSHBUTTON "Cancel",IDCANCEL,174,98,50,14
|
||||
LTEXT "Realm",IDC_REALM_TEXT,67,21,157,8
|
||||
RTEXT "User Name:",IDC_STATIC,7,41,57,8
|
||||
EDITTEXT IDC_AUTH_USER,67,39,157,14,ES_AUTOHSCROLL
|
||||
RTEXT "Password:",IDC_STATIC,7,66,57,8
|
||||
EDITTEXT IDC_AUTH_PASSWORD,67,64,157,14,ES_PASSWORD | ES_AUTOHSCROLL
|
||||
END
|
||||
|
||||
IDD_PROXY DIALOGEX 0, 0, 310, 176
|
||||
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
|
||||
CAPTION "Proxy Configuration"
|
||||
FONT 8, "MS Shell Dlg", 400, 0, 0x1
|
||||
BEGIN
|
||||
DEFPUSHBUTTON "OK",IDOK,199,155,50,14
|
||||
PUSHBUTTON "Cancel",IDCANCEL,253,155,50,14
|
||||
CONTROL "Use system default proxy configuration.",IDC_PROXY_DEFAULT,
|
||||
"Button",BS_AUTORADIOBUTTON | WS_GROUP,22,15,226,10
|
||||
CONTROL "Use custom proxy configuration:",IDC_PROXY_CUSTOM,
|
||||
"Button",BS_AUTORADIOBUTTON,22,33,226,10
|
||||
CONTROL "Don't use proxy.",IDC_PROXY_DISABLE,"Button",BS_AUTORADIOBUTTON,22,117,226,10
|
||||
EDITTEXT IDC_PROXY_URL,76,52,193,14,ES_AUTOHSCROLL
|
||||
EDITTEXT IDC_PROXY_EXCLUDE,76,85,193,14,ES_AUTOHSCROLL
|
||||
LTEXT "URL:",IDC_STATIC,30,55,43,8,0,WS_EX_RIGHT
|
||||
LTEXT "Excude list:",IDC_STATIC,30,88,43,8,0,WS_EX_RIGHT
|
||||
LTEXT "Example: http://192.168.0.2:8000",IDC_STATIC,80,68,194,8
|
||||
LTEXT "Comma separated hostnames.",IDC_STATIC,80,101,194,8
|
||||
END
|
||||
|
||||
IDD_SERVER_TRUST DIALOGEX 0, 0, 319, 184
|
||||
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
|
||||
CAPTION "Server Trust Evaluation Request"
|
||||
FONT 8, "MS Shell Dlg", 400, 0, 0x1
|
||||
BEGIN
|
||||
DEFPUSHBUTTON "Yes",IDOK,197,163,50,14
|
||||
PUSHBUTTON "No",IDCANCEL,262,163,50,14
|
||||
LTEXT "Certificate information",IDC_STATIC,7,7,294,17
|
||||
EDITTEXT IDC_SERVER_TRUST_TEXT,7,24,305,130,ES_MULTILINE | ES_READONLY | WS_VSCROLL | WS_HSCROLL | NOT WS_TABSTOP
|
||||
END
|
||||
|
||||
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// TEXTINCLUDE
|
||||
//
|
||||
|
||||
1 TEXTINCLUDE
|
||||
BEGIN
|
||||
"PlaywrightLibResource.h\0"
|
||||
END
|
||||
|
||||
2 TEXTINCLUDE
|
||||
BEGIN
|
||||
"#define APSTUDIO_HIDDEN_SYMBOLS\r\n"
|
||||
"#include ""windows.h""\r\n"
|
||||
"#undef APSTUDIO_HIDDEN_SYMBOLS\r\n"
|
||||
"\0"
|
||||
END
|
||||
|
||||
3 TEXTINCLUDE
|
||||
BEGIN
|
||||
"\r\n"
|
||||
"\0"
|
||||
END
|
||||
|
||||
#endif // APSTUDIO_INVOKED
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// DESIGNINFO
|
||||
//
|
||||
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
GUIDELINES DESIGNINFO
|
||||
BEGIN
|
||||
IDD_ABOUTBOX, DIALOG
|
||||
BEGIN
|
||||
END
|
||||
|
||||
IDD_CACHES, DIALOG
|
||||
BEGIN
|
||||
LEFTMARGIN, 7
|
||||
RIGHTMARGIN, 394
|
||||
TOPMARGIN, 7
|
||||
BOTTOMMARGIN, 449
|
||||
END
|
||||
|
||||
IDD_AUTH, DIALOG
|
||||
BEGIN
|
||||
LEFTMARGIN, 7
|
||||
RIGHTMARGIN, 224
|
||||
VERTGUIDE, 64
|
||||
VERTGUIDE, 67
|
||||
TOPMARGIN, 7
|
||||
BOTTOMMARGIN, 92
|
||||
HORZGUIDE, 25
|
||||
HORZGUIDE, 50
|
||||
END
|
||||
|
||||
IDD_PROXY, DIALOG
|
||||
BEGIN
|
||||
LEFTMARGIN, 7
|
||||
RIGHTMARGIN, 303
|
||||
VERTGUIDE, 22
|
||||
TOPMARGIN, 7
|
||||
BOTTOMMARGIN, 169
|
||||
END
|
||||
|
||||
IDD_SERVER_TRUST, DIALOG
|
||||
BEGIN
|
||||
LEFTMARGIN, 7
|
||||
RIGHTMARGIN, 312
|
||||
TOPMARGIN, 7
|
||||
BOTTOMMARGIN, 177
|
||||
END
|
||||
END
|
||||
#endif // APSTUDIO_INVOKED
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Bitmap
|
||||
//
|
||||
|
||||
IDB_TOOLBAR BITMAP "toolbar.bmp"
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// String Table
|
||||
//
|
||||
|
||||
STRINGTABLE
|
||||
BEGIN
|
||||
IDS_APP_TITLE "Playwright"
|
||||
IDC_PLAYWRIGHT "Playwright"
|
||||
END
|
||||
|
||||
#endif // English (United States) resources
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
#ifndef APSTUDIO_INVOKED
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Generated from the TEXTINCLUDE 3 resource.
|
||||
//
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#endif // not APSTUDIO_INVOKED
|
||||
|
||||
@@ -0,0 +1,115 @@
|
||||
//{{NO_DEPENDENCIES}}
|
||||
// Microsoft Visual C++ generated include file.
|
||||
// Used by PlaywrightLib.rc
|
||||
//
|
||||
#define IDC_MYICON 2
|
||||
#define IDD_PLAYWRIGHT_DIALOG 102
|
||||
#define IDS_APP_TITLE 103
|
||||
#define IDD_ABOUTBOX 103
|
||||
#define IDM_ABOUT 104
|
||||
#define IDI_PLAYWRIGHT 107
|
||||
#define IDC_PLAYWRIGHT 109
|
||||
#define IDM_WEB_INSPECTOR 120
|
||||
#define IDM_INVERT_COLORS 125
|
||||
#define IDR_MAINFRAME 128
|
||||
#define IDD_CACHES 129
|
||||
#define IDM_HISTORY_BACKWARD 130
|
||||
#define IDD_USER_AGENT 130
|
||||
#define IDM_HISTORY_FORWARD 131
|
||||
#define IDM_HISTORY_LINK0 150
|
||||
#define IDM_HISTORY_LINK1 151
|
||||
#define IDM_HISTORY_LINK2 152
|
||||
#define IDM_HISTORY_LINK3 153
|
||||
#define IDM_HISTORY_LINK4 154
|
||||
#define IDM_HISTORY_LINK5 155
|
||||
#define IDM_HISTORY_LINK6 156
|
||||
#define IDM_HISTORY_LINK7 157
|
||||
#define IDM_HISTORY_LINK8 158
|
||||
#define IDM_HISTORY_LINK9 159
|
||||
#define IDT_UPDATE_STATS 160
|
||||
#define IDM_ACTUAL_SIZE 172
|
||||
#define IDM_ZOOM_IN 173
|
||||
#define IDM_ZOOM_OUT 174
|
||||
#define IDD_AUTH 176
|
||||
#define IDD_PROXY 178
|
||||
#define IDD_SERVER_TRUST 179
|
||||
#define IDR_ACCELERATORS_PRE 180
|
||||
#define IDB_TOOLBAR 181
|
||||
#define IDC_EMPTY_URL_CACHE 1000
|
||||
#define IDC_RETURN_FREE_MEMORY 1001
|
||||
#define IDC_EMPTY_WEBCORE_CACHE 1002
|
||||
#define IDC_CHECK1 1003
|
||||
#define IDC_HEAP_OBJECTS 1005
|
||||
#define IDC_GC_JSC 1006
|
||||
#define IDC_RESERVED_VM 1007
|
||||
#define IDC_COMMITTED_VM 1008
|
||||
#define IDC_FREE_LIST_BYTES 1009
|
||||
#define IDC_IMAGES_OBJECT_COUNT 1011
|
||||
#define IDC_CSS_OBJECT_COUNT 1012
|
||||
#define IDC_XSL_OBJECT_COUNT 1013
|
||||
#define IDC_JSC_OBJECT_COUNT 1014
|
||||
#define IDC_TOTAL_OBJECT_COUNT 1015
|
||||
#define IDC_IMAGES_BYTES 1016
|
||||
#define IDC_CSS_BYTES 1017
|
||||
#define IDC_XSL_BYTES 1018
|
||||
#define IDC_JSC_BYTES 1019
|
||||
#define IDC_TOTAL_BYTES 1020
|
||||
#define IDC_IMAGES_LIVE_COUNT 1021
|
||||
#define IDC_CSS_LIVE_COUNT 1022
|
||||
#define IDC_XSL_LIVE_COUNT 1023
|
||||
#define IDC_JSC_LIVE_COUNT 1024
|
||||
#define IDC_TOTAL_LIVE_COUNT 1025
|
||||
#define IDC_IMAGES_DECODED_COUNT 1026
|
||||
#define IDC_CSS_DECODED_COUNT 1027
|
||||
#define IDC_XSL_DECODED_COUNT 1028
|
||||
#define IDC_JSC_DECODED_COUNT 1029
|
||||
#define IDC_TOTAL_DECODED 1030
|
||||
#define IDC_IMAGES_PURGEABLE_COUNT 1031
|
||||
#define IDC_CSS_PURGEABLE_COUNT 1032
|
||||
#define IDC_XSL_PURGEABLE_COUNT 1033
|
||||
#define IDC_JSC_PURGEABLE_COUNT 1034
|
||||
#define IDC_TOTAL_PURGEABLE 1035
|
||||
#define IDC_TOTAL_JSC_HEAP_OBJECTS 1036
|
||||
#define IDC_GLOBAL_JSC_HEAP_OBJECTS 1037
|
||||
#define IDC_PROTECTED_JSC_HEAP_OBJECTS 1038
|
||||
#define IDC_STATIC56 1039
|
||||
#define IDC_STATIC57 1040
|
||||
#define IDC_JSC_HEAP_SIZE 1041
|
||||
#define IDC_JSC_HEAP_FREE 1042
|
||||
#define IDC_BUTTON5 1043
|
||||
#define IDC_TOTAL_FONT_OBJECTS 1044
|
||||
#define IDC_Message 1044
|
||||
#define IDC_INACTIVE_FONT_OBJECTS 1045
|
||||
#define IDC_GLYPH_PAGES 1046
|
||||
#define IDC_PAGE_URL_MAPPINGS 1047
|
||||
#define IDC_RETAINED_PAGE_URLS 1048
|
||||
#define IDC_SITE_ICON_RECORDS 1049
|
||||
#define IDC_TOTAL_FONT_OBJECTS5 1050
|
||||
#define IDC_SITE_ICONS_WITH_DATA 1051
|
||||
#define IDC_USER_AGENT_INPUT 1052
|
||||
#define IDC_AUTH_USER 1053
|
||||
#define IDC_AUTH_PASSWORD 1054
|
||||
#define IDC_URL_BAR 1055
|
||||
#define IDC_REALM_TEXT 1056
|
||||
#define IDC_PROXY_URL 1057
|
||||
#define IDC_PROXY_DEFAULT 1058
|
||||
#define IDC_PROXY_CUSTOM 1059
|
||||
#define IDC_PROXY_EXCLUDE 1060
|
||||
#define IDC_PROXY_DISABLE 1061
|
||||
#define IDC_SERVER_TRUST_TEXT 1062
|
||||
#define IDM_NEW_WINDOW 32776
|
||||
#define IDM_RELOAD 32779
|
||||
#define IDM_CLOSE_WINDOW 32780
|
||||
#define IDC_STATIC -1
|
||||
|
||||
// Next default values for new objects
|
||||
//
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
#ifndef APSTUDIO_READONLY_SYMBOLS
|
||||
#define _APS_NO_MFC 1
|
||||
#define _APS_NEXT_RESOURCE_VALUE 182
|
||||
#define _APS_NEXT_COMMAND_VALUE 32783
|
||||
#define _APS_NEXT_CONTROL_VALUE 1063
|
||||
#define _APS_NEXT_SYMED_VALUE 110
|
||||
#endif
|
||||
#endif
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Alex Christensen. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
// This file is to make it easier for users to manage changes to the internals of Playwright
|
||||
|
||||
static void processCrashReport(const wchar_t* fileName) { ::MessageBox(0, fileName, L"Crash Report", MB_OK); }
|
||||
@@ -0,0 +1,20 @@
|
||||
//{{NO_DEPENDENCIES}}
|
||||
// Microsoft Visual C++ generated include file.
|
||||
// Used by PlaywrightLauncher.rc
|
||||
//
|
||||
#define IDD_PLAYWRIGHT_DIALOG 102
|
||||
#define IDI_PLAYWRIGHT 107
|
||||
#define IDR_MAINFRAME 128
|
||||
#define IDC_STATIC -1
|
||||
|
||||
// Next default values for new objects
|
||||
//
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
#ifndef APSTUDIO_READONLY_SYMBOLS
|
||||
#define _APS_NO_MFC 1
|
||||
#define _APS_NEXT_RESOURCE_VALUE 129
|
||||
#define _APS_NEXT_COMMAND_VALUE 32771
|
||||
#define _APS_NEXT_CONTROL_VALUE 1000
|
||||
#define _APS_NEXT_SYMED_VALUE 110
|
||||
#endif
|
||||
#endif
|
||||
@@ -0,0 +1,416 @@
|
||||
/*
|
||||
* Copyright (C) 2018 Sony Interactive Entertainment Inc.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include "stdafx.h"
|
||||
#include "Common.h"
|
||||
#include "MainWindow.h"
|
||||
#include "PlaywrightLibResource.h"
|
||||
#include "WebKitBrowserWindow.h"
|
||||
#include <WebCore/GDIUtilities.h>
|
||||
#include <WebKit/WKAuthenticationChallenge.h>
|
||||
#include <WebKit/WKAuthenticationDecisionListener.h>
|
||||
#include <WebKit/WKCertificateInfoCurl.h>
|
||||
#include <WebKit/WKCredential.h>
|
||||
#include <WebKit/WKFramePolicyListener.h>
|
||||
#include <WebKit/WKInspector.h>
|
||||
#include <WebKit/WKPagePrivate.h>
|
||||
#include <WebKit/WKProtectionSpace.h>
|
||||
#include <WebKit/WKProtectionSpaceCurl.h>
|
||||
#include <WebKit/WKWebsiteDataStoreRef.h>
|
||||
#include <WebKit/WKWebsiteDataStoreRefCurl.h>
|
||||
#include <vector>
|
||||
|
||||
std::wstring createPEMString(WKProtectionSpaceRef protectionSpace)
|
||||
{
|
||||
auto chain = adoptWK(WKProtectionSpaceCopyCertificateChain(protectionSpace));
|
||||
|
||||
std::wstring pems;
|
||||
|
||||
for (size_t i = 0; i < WKArrayGetSize(chain.get()); i++) {
|
||||
auto item = WKArrayGetItemAtIndex(chain.get(), i);
|
||||
assert(WKGetTypeID(item) == WKDataGetTypeID());
|
||||
auto certificate = static_cast<WKDataRef>(item);
|
||||
auto size = WKDataGetSize(certificate);
|
||||
auto data = WKDataGetBytes(certificate);
|
||||
|
||||
for (size_t i = 0; i < size; i++)
|
||||
pems.push_back(data[i]);
|
||||
}
|
||||
|
||||
return replaceString(pems, L"\n", L"\r\n");
|
||||
}
|
||||
|
||||
WebKitBrowserWindow::WebKitBrowserWindow(BrowserWindowClient& client, HWND mainWnd, WKPageConfigurationRef conf)
|
||||
: m_client(client)
|
||||
, m_hMainWnd(mainWnd)
|
||||
{
|
||||
RECT rect = { };
|
||||
m_view = adoptWK(WKViewCreate(rect, conf, mainWnd));
|
||||
WKViewSetIsInWindow(m_view.get(), true);
|
||||
|
||||
auto page = WKViewGetPage(m_view.get());
|
||||
|
||||
WKPageNavigationClientV0 navigationClient = { };
|
||||
navigationClient.base.version = 0;
|
||||
navigationClient.base.clientInfo = this;
|
||||
navigationClient.didReceiveAuthenticationChallenge = didReceiveAuthenticationChallenge;
|
||||
WKPageSetPageNavigationClient(page, &navigationClient.base);
|
||||
|
||||
WKPageUIClientV14 uiClient = { };
|
||||
uiClient.base.version = 14;
|
||||
uiClient.base.clientInfo = this;
|
||||
uiClient.createNewPage = createNewPage;
|
||||
uiClient.didNotHandleKeyEvent = didNotHandleKeyEvent;
|
||||
uiClient.close = closeWindow;
|
||||
uiClient.runJavaScriptAlert = runJavaScriptAlert;
|
||||
uiClient.runJavaScriptConfirm = runJavaScriptConfirm;
|
||||
uiClient.runJavaScriptPrompt = runJavaScriptPrompt;
|
||||
uiClient.runBeforeUnloadConfirmPanel = runBeforeUnloadConfirmPanel;
|
||||
uiClient.handleJavaScriptDialog = handleJavaScriptDialog;
|
||||
uiClient.getWindowFrame = getWindowFrame;
|
||||
WKPageSetPageUIClient(page, &uiClient.base);
|
||||
|
||||
WKPageStateClientV0 stateClient = { };
|
||||
stateClient.base.version = 0;
|
||||
stateClient.base.clientInfo = this;
|
||||
stateClient.didChangeTitle = didChangeTitle;
|
||||
stateClient.didChangeIsLoading = didChangeIsLoading;
|
||||
stateClient.didChangeActiveURL = didChangeActiveURL;
|
||||
WKPageSetPageStateClient(page, &stateClient.base);
|
||||
|
||||
WKPagePolicyClientV1 policyClient = { };
|
||||
policyClient.base.version = 1;
|
||||
policyClient.base.clientInfo = this;
|
||||
policyClient.decidePolicyForResponse = decidePolicyForResponse;
|
||||
policyClient.decidePolicyForNavigationAction = decidePolicyForNavigationAction;
|
||||
WKPageSetPagePolicyClient(page, &policyClient.base);
|
||||
|
||||
WKPageSetControlledByAutomation(page, true);
|
||||
resetZoom();
|
||||
}
|
||||
|
||||
WebKitBrowserWindow::~WebKitBrowserWindow()
|
||||
{
|
||||
if (m_alertDialog) {
|
||||
WKRelease(m_alertDialog);
|
||||
m_alertDialog = NULL;
|
||||
}
|
||||
|
||||
if (m_confirmDialog) {
|
||||
WKRelease(m_confirmDialog);
|
||||
m_confirmDialog = NULL;
|
||||
}
|
||||
|
||||
if (m_promptDialog) {
|
||||
WKRelease(m_promptDialog);
|
||||
m_promptDialog = NULL;
|
||||
}
|
||||
|
||||
if (m_beforeUnloadDialog) {
|
||||
WKRelease(m_beforeUnloadDialog);
|
||||
m_beforeUnloadDialog = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
HWND WebKitBrowserWindow::hwnd()
|
||||
{
|
||||
return WKViewGetWindow(m_view.get());
|
||||
}
|
||||
|
||||
HRESULT WebKitBrowserWindow::loadURL(const BSTR& url)
|
||||
{
|
||||
auto page = WKViewGetPage(m_view.get());
|
||||
WKPageLoadURL(page, createWKURL(_bstr_t(url)).get());
|
||||
return true;
|
||||
}
|
||||
|
||||
void WebKitBrowserWindow::reload()
|
||||
{
|
||||
auto page = WKViewGetPage(m_view.get());
|
||||
WKPageReload(page);
|
||||
}
|
||||
|
||||
void WebKitBrowserWindow::navigateForwardOrBackward(bool forward)
|
||||
{
|
||||
auto page = WKViewGetPage(m_view.get());
|
||||
if (forward)
|
||||
WKPageGoForward(page);
|
||||
else
|
||||
WKPageGoBack(page);
|
||||
}
|
||||
|
||||
void WebKitBrowserWindow::launchInspector()
|
||||
{
|
||||
auto page = WKViewGetPage(m_view.get());
|
||||
auto inspector = WKPageGetInspector(page);
|
||||
WKInspectorShow(inspector);
|
||||
}
|
||||
|
||||
void WebKitBrowserWindow::setUserAgent(_bstr_t& customUAString)
|
||||
{
|
||||
auto page = WKViewGetPage(m_view.get());
|
||||
auto ua = createWKString(customUAString);
|
||||
WKPageSetCustomUserAgent(page, ua.get());
|
||||
}
|
||||
|
||||
_bstr_t WebKitBrowserWindow::userAgent()
|
||||
{
|
||||
auto page = WKViewGetPage(m_view.get());
|
||||
auto ua = adoptWK(WKPageCopyUserAgent(page));
|
||||
return createString(ua.get()).c_str();
|
||||
}
|
||||
|
||||
void WebKitBrowserWindow::resetZoom()
|
||||
{
|
||||
auto page = WKViewGetPage(m_view.get());
|
||||
WKPageSetPageZoomFactor(page, WebCore::deviceScaleFactorForWindow(hwnd()));
|
||||
}
|
||||
|
||||
void WebKitBrowserWindow::zoomIn()
|
||||
{
|
||||
auto page = WKViewGetPage(m_view.get());
|
||||
double s = WKPageGetPageZoomFactor(page);
|
||||
WKPageSetPageZoomFactor(page, s * 1.25);
|
||||
}
|
||||
|
||||
void WebKitBrowserWindow::zoomOut()
|
||||
{
|
||||
auto page = WKViewGetPage(m_view.get());
|
||||
double s = WKPageGetPageZoomFactor(page);
|
||||
WKPageSetPageZoomFactor(page, s * 0.8);
|
||||
}
|
||||
|
||||
static WebKitBrowserWindow& toWebKitBrowserWindow(const void *clientInfo)
|
||||
{
|
||||
return *const_cast<WebKitBrowserWindow*>(static_cast<const WebKitBrowserWindow*>(clientInfo));
|
||||
}
|
||||
|
||||
void WebKitBrowserWindow::didChangeTitle(const void* clientInfo)
|
||||
{
|
||||
auto& thisWindow = toWebKitBrowserWindow(clientInfo);
|
||||
auto page = WKViewGetPage(thisWindow.m_view.get());
|
||||
WKRetainPtr<WKStringRef> title = adoptWK(WKPageCopyTitle(page));
|
||||
std::wstring titleString = createString(title.get()) + L" [WebKit]";
|
||||
SetWindowText(thisWindow.m_hMainWnd, titleString.c_str());
|
||||
}
|
||||
|
||||
void WebKitBrowserWindow::didChangeIsLoading(const void* clientInfo)
|
||||
{
|
||||
auto& thisWindow = toWebKitBrowserWindow(clientInfo);
|
||||
}
|
||||
|
||||
void WebKitBrowserWindow::didChangeActiveURL(const void* clientInfo)
|
||||
{
|
||||
auto& thisWindow = toWebKitBrowserWindow(clientInfo);
|
||||
auto page = WKViewGetPage(thisWindow.m_view.get());
|
||||
WKRetainPtr<WKURLRef> url = adoptWK(WKPageCopyActiveURL(page));
|
||||
thisWindow.m_client.activeURLChanged(createString(url.get()));
|
||||
}
|
||||
|
||||
void WebKitBrowserWindow::didReceiveAuthenticationChallenge(WKPageRef page, WKAuthenticationChallengeRef challenge, const void* clientInfo)
|
||||
{
|
||||
auto& thisWindow = toWebKitBrowserWindow(clientInfo);
|
||||
auto protectionSpace = WKAuthenticationChallengeGetProtectionSpace(challenge);
|
||||
auto decisionListener = WKAuthenticationChallengeGetDecisionListener(challenge);
|
||||
auto authenticationScheme = WKProtectionSpaceGetAuthenticationScheme(protectionSpace);
|
||||
|
||||
if (authenticationScheme == kWKProtectionSpaceAuthenticationSchemeServerTrustEvaluationRequested) {
|
||||
if (thisWindow.canTrustServerCertificate(protectionSpace)) {
|
||||
WKRetainPtr<WKStringRef> username = createWKString("accept server trust");
|
||||
WKRetainPtr<WKStringRef> password = createWKString("");
|
||||
WKRetainPtr<WKCredentialRef> wkCredential = adoptWK(WKCredentialCreate(username.get(), password.get(), kWKCredentialPersistenceForSession));
|
||||
WKAuthenticationDecisionListenerUseCredential(decisionListener, wkCredential.get());
|
||||
return;
|
||||
}
|
||||
} else if (!s_headless) {
|
||||
WKRetainPtr<WKStringRef> realm(WKProtectionSpaceCopyRealm(protectionSpace));
|
||||
|
||||
if (auto credential = askCredential(thisWindow.hwnd(), createString(realm.get()))) {
|
||||
WKRetainPtr<WKStringRef> username = createWKString(credential->username);
|
||||
WKRetainPtr<WKStringRef> password = createWKString(credential->password);
|
||||
WKRetainPtr<WKCredentialRef> wkCredential = adoptWK(WKCredentialCreate(username.get(), password.get(), kWKCredentialPersistenceForSession));
|
||||
WKAuthenticationDecisionListenerUseCredential(decisionListener, wkCredential.get());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
WKAuthenticationDecisionListenerUseCredential(decisionListener, nullptr);
|
||||
}
|
||||
|
||||
bool WebKitBrowserWindow::canTrustServerCertificate(WKProtectionSpaceRef protectionSpace)
|
||||
{
|
||||
auto host = createString(adoptWK(WKProtectionSpaceCopyHost(protectionSpace)).get());
|
||||
auto verificationError = WKProtectionSpaceGetCertificateVerificationError(protectionSpace);
|
||||
auto description = createString(adoptWK(WKProtectionSpaceCopyCertificateVerificationErrorDescription(protectionSpace)).get());
|
||||
auto pem = createPEMString(protectionSpace);
|
||||
|
||||
auto it = m_acceptedServerTrustCerts.find(host);
|
||||
if (it != m_acceptedServerTrustCerts.end() && it->second == pem)
|
||||
return true;
|
||||
|
||||
std::wstring textString = L"[HOST] " + host + L"\r\n";
|
||||
textString.append(L"[ERROR] " + std::to_wstring(verificationError) + L"\r\n");
|
||||
textString.append(L"[DESCRIPTION] " + description + L"\r\n");
|
||||
textString.append(pem);
|
||||
|
||||
if (s_headless)
|
||||
return false;
|
||||
|
||||
if (askServerTrustEvaluation(hwnd(), textString)) {
|
||||
m_acceptedServerTrustCerts.emplace(host, pem);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void WebKitBrowserWindow::closeWindow(WKPageRef page, const void* clientInfo)
|
||||
{
|
||||
auto& thisWindow = toWebKitBrowserWindow(clientInfo);
|
||||
PostMessage(thisWindow.m_hMainWnd, WM_CLOSE, 0, 0);
|
||||
}
|
||||
|
||||
void WebKitBrowserWindow::runJavaScriptAlert(WKPageRef page, WKStringRef alertText, WKFrameRef frame, WKSecurityOriginRef securityOrigin, WKPageRunJavaScriptAlertResultListenerRef listener, const void *clientInfo)
|
||||
{
|
||||
auto& thisWindow = toWebKitBrowserWindow(clientInfo);
|
||||
WKRetain(listener);
|
||||
thisWindow.m_alertDialog = listener;
|
||||
}
|
||||
|
||||
void WebKitBrowserWindow::runJavaScriptConfirm(WKPageRef page, WKStringRef message, WKFrameRef frame, WKSecurityOriginRef securityOrigin, WKPageRunJavaScriptConfirmResultListenerRef listener, const void *clientInfo)
|
||||
{
|
||||
auto& thisWindow = toWebKitBrowserWindow(clientInfo);
|
||||
WKRetain(listener);
|
||||
thisWindow.m_confirmDialog = listener;
|
||||
}
|
||||
|
||||
void WebKitBrowserWindow::runJavaScriptPrompt(WKPageRef page, WKStringRef message, WKStringRef defaultValue, WKFrameRef frame, WKSecurityOriginRef securityOrigin, WKPageRunJavaScriptPromptResultListenerRef listener, const void *clientInfo)
|
||||
{
|
||||
auto& thisWindow = toWebKitBrowserWindow(clientInfo);
|
||||
WKRetain(listener);
|
||||
thisWindow.m_promptDialog = listener;
|
||||
}
|
||||
|
||||
void WebKitBrowserWindow::runBeforeUnloadConfirmPanel(WKPageRef page, WKStringRef message, WKFrameRef frame, WKPageRunBeforeUnloadConfirmPanelResultListenerRef listener, const void *clientInfo)
|
||||
{
|
||||
auto& thisWindow = toWebKitBrowserWindow(clientInfo);
|
||||
WKRetain(listener);
|
||||
thisWindow.m_beforeUnloadDialog = listener;
|
||||
}
|
||||
|
||||
void WebKitBrowserWindow::handleJavaScriptDialog(WKPageRef page, bool accept, WKStringRef value, const void *clientInfo)
|
||||
{
|
||||
auto& thisWindow = toWebKitBrowserWindow(clientInfo);
|
||||
if (thisWindow.m_alertDialog) {
|
||||
WKPageRunJavaScriptAlertResultListenerCall(thisWindow.m_alertDialog);
|
||||
WKRelease(thisWindow.m_alertDialog);
|
||||
thisWindow.m_alertDialog = NULL;
|
||||
}
|
||||
|
||||
if (thisWindow.m_confirmDialog) {
|
||||
WKPageRunJavaScriptConfirmResultListenerCall(thisWindow.m_confirmDialog, accept);
|
||||
WKRelease(thisWindow.m_confirmDialog);
|
||||
thisWindow.m_confirmDialog = NULL;
|
||||
}
|
||||
|
||||
if (thisWindow.m_promptDialog) {
|
||||
WKPageRunJavaScriptPromptResultListenerCall(thisWindow.m_promptDialog, accept ? value : NULL);
|
||||
WKRelease(thisWindow.m_promptDialog);
|
||||
thisWindow.m_promptDialog = NULL;
|
||||
}
|
||||
|
||||
if (thisWindow.m_beforeUnloadDialog) {
|
||||
WKPageRunBeforeUnloadConfirmPanelResultListenerCall(thisWindow.m_beforeUnloadDialog, accept);
|
||||
WKRelease(thisWindow.m_beforeUnloadDialog);
|
||||
thisWindow.m_beforeUnloadDialog = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
WKRect WebKitBrowserWindow::getWindowFrame(WKPageRef page, const void *clientInfo) {
|
||||
auto& thisWindow = toWebKitBrowserWindow(clientInfo);
|
||||
WKRect wkFrame { };
|
||||
RECT r;
|
||||
if (::GetWindowRect(thisWindow.m_hMainWnd, &r)) {
|
||||
wkFrame.origin.x = r.left;
|
||||
wkFrame.origin.y = r.top;
|
||||
wkFrame.size.width = r.right - r.left;
|
||||
wkFrame.size.height = r.bottom - r.top;
|
||||
}
|
||||
return wkFrame;
|
||||
}
|
||||
|
||||
WKPageRef WebKitBrowserWindow::createPageCallback(WKPageConfigurationRef configuration)
|
||||
{
|
||||
// This comes from the Playwright agent, configuration is a pool+data pair.
|
||||
return WebKitBrowserWindow::createViewCallback(configuration, true);
|
||||
}
|
||||
|
||||
WKPageRef WebKitBrowserWindow::createViewCallback(WKPageConfigurationRef configuration, bool navigate)
|
||||
{
|
||||
auto* newWindow = new MainWindow();
|
||||
bool ok = newWindow->init(hInst, configuration);
|
||||
if (navigate)
|
||||
newWindow->browserWindow()->loadURL(_bstr_t("about:blank").GetBSTR());
|
||||
|
||||
auto* newBrowserWindow = newWindow->browserWindow();
|
||||
return WKViewGetPage(newBrowserWindow->m_view.get());
|
||||
}
|
||||
|
||||
|
||||
WKPageRef WebKitBrowserWindow::createNewPage(WKPageRef, WKPageConfigurationRef configuration, WKNavigationActionRef, WKWindowFeaturesRef, const void*)
|
||||
{
|
||||
// This comes from the client for popups, configuration is inherited from main page.
|
||||
// Retain popups as per API contract.
|
||||
WKRetainPtr<WKPageRef> newPage = createViewCallback(configuration, false);
|
||||
return newPage.leakRef();
|
||||
}
|
||||
|
||||
void WebKitBrowserWindow::didNotHandleKeyEvent(WKPageRef, WKNativeEventPtr event, const void* clientInfo)
|
||||
{
|
||||
auto& thisWindow = toWebKitBrowserWindow(clientInfo);
|
||||
PostMessage(thisWindow.m_hMainWnd, event->message, event->wParam, event->lParam);
|
||||
}
|
||||
|
||||
void WebKitBrowserWindow::decidePolicyForNavigationAction(WKPageRef page, WKFrameRef frame, WKFrameNavigationType navigationType, WKEventModifiers modifiers, WKEventMouseButton mouseButton, WKFrameRef originatingFrame, WKURLRequestRef request, WKFramePolicyListenerRef listener, WKTypeRef userData, const void* clientInfo)
|
||||
{
|
||||
WebKitBrowserWindow* browserWindow = reinterpret_cast<WebKitBrowserWindow*>(const_cast<void*>(clientInfo));
|
||||
if (navigationType == kWKFrameNavigationTypeLinkClicked &&
|
||||
mouseButton == kWKEventMouseButtonLeftButton &&
|
||||
(modifiers & (kWKEventModifiersShiftKey | kWKEventModifiersControlKey)) != 0) {
|
||||
WKRetainPtr<WKPageRef> newPage = createViewCallback(WKPageCopyPageConfiguration(page), false);
|
||||
WKPageLoadURLRequest(newPage.get(), request);
|
||||
WKFramePolicyListenerIgnore(listener);
|
||||
return;
|
||||
}
|
||||
WKFramePolicyListenerUse(listener);
|
||||
}
|
||||
|
||||
void WebKitBrowserWindow::decidePolicyForResponse(WKPageRef page, WKFrameRef frame, WKURLResponseRef response, WKURLRequestRef request, bool canShowMIMEType, WKFramePolicyListenerRef listener, WKTypeRef userData, const void* clientInfo)
|
||||
{
|
||||
// Safari renders resources without content-type as text.
|
||||
if (WKURLResponseIsAttachment(response) || (!WKStringIsEmpty(WKURLResponseCopyMIMEType(response)) && !canShowMIMEType))
|
||||
WKFramePolicyListenerDownload(listener);
|
||||
else
|
||||
WKFramePolicyListenerUse(listener);
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* Copyright (C) 2018 Sony Interactive Entertainment Inc.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "Common.h"
|
||||
#include <WebKit/WKBase.h>
|
||||
#include <WebKit/WebKit2_C.h>
|
||||
#include <unordered_map>
|
||||
|
||||
class BrowserWindowClient {
|
||||
public:
|
||||
virtual void activeURLChanged(std::wstring) = 0;
|
||||
};
|
||||
|
||||
class WebKitBrowserWindow {
|
||||
public:
|
||||
static WKPageRef createPageCallback(WKPageConfigurationRef);
|
||||
WebKitBrowserWindow(BrowserWindowClient&, HWND mainWnd, WKPageConfigurationRef);
|
||||
~WebKitBrowserWindow();
|
||||
|
||||
HRESULT loadURL(const BSTR& url);
|
||||
void reload();
|
||||
void navigateForwardOrBackward(bool forward);
|
||||
void launchInspector();
|
||||
|
||||
_bstr_t userAgent();
|
||||
void setUserAgent(_bstr_t&);
|
||||
|
||||
void resetZoom();
|
||||
void zoomIn();
|
||||
void zoomOut();
|
||||
|
||||
bool canTrustServerCertificate(WKProtectionSpaceRef);
|
||||
HWND hwnd();
|
||||
|
||||
private:
|
||||
static WKPageRef createViewCallback(WKPageConfigurationRef, bool navigate);
|
||||
|
||||
static void didChangeTitle(const void*);
|
||||
static void didChangeIsLoading(const void*);
|
||||
static void didChangeEstimatedProgress(const void*);
|
||||
static void didChangeActiveURL(const void*);
|
||||
static void didReceiveAuthenticationChallenge(WKPageRef, WKAuthenticationChallengeRef, const void*);
|
||||
static WKPageRef createNewPage(WKPageRef, WKPageConfigurationRef, WKNavigationActionRef, WKWindowFeaturesRef, const void *);
|
||||
static void closeWindow(WKPageRef, const void*);
|
||||
static void runJavaScriptAlert(WKPageRef page, WKStringRef alertText, WKFrameRef frame, WKSecurityOriginRef securityOrigin, WKPageRunJavaScriptAlertResultListenerRef listener, const void *clientInfo);
|
||||
static void runJavaScriptConfirm(WKPageRef page, WKStringRef message, WKFrameRef frame, WKSecurityOriginRef securityOrigin, WKPageRunJavaScriptConfirmResultListenerRef listener, const void *clientInfo);
|
||||
static void runJavaScriptPrompt(WKPageRef page, WKStringRef message, WKStringRef defaultValue, WKFrameRef frame, WKSecurityOriginRef securityOrigin, WKPageRunJavaScriptPromptResultListenerRef listener, const void *clientInfo);
|
||||
static void runBeforeUnloadConfirmPanel(WKPageRef page, WKStringRef message, WKFrameRef frame, WKPageRunBeforeUnloadConfirmPanelResultListenerRef listener, const void *clientInfo);
|
||||
static void handleJavaScriptDialog(WKPageRef page, bool accept, WKStringRef value, const void *clientInfo);
|
||||
static WKRect getWindowFrame(WKPageRef page, const void *clientInfo);
|
||||
static void didNotHandleKeyEvent(WKPageRef, WKNativeEventPtr, const void*);
|
||||
static void decidePolicyForNavigationAction(WKPageRef, WKFrameRef, WKFrameNavigationType, WKEventModifiers, WKEventMouseButton, WKFrameRef, WKURLRequestRef, WKFramePolicyListenerRef, WKTypeRef, const void* clientInfo);
|
||||
static void decidePolicyForResponse(WKPageRef, WKFrameRef, WKURLResponseRef, WKURLRequestRef, bool, WKFramePolicyListenerRef, WKTypeRef, const void*);
|
||||
|
||||
BrowserWindowClient& m_client;
|
||||
WKRetainPtr<WKViewRef> m_view;
|
||||
HWND m_hMainWnd { nullptr };
|
||||
std::unordered_map<std::wstring, std::wstring> m_acceptedServerTrustCerts;
|
||||
WKPageRunJavaScriptAlertResultListenerRef m_alertDialog = { };
|
||||
WKPageRunJavaScriptConfirmResultListenerRef m_confirmDialog = { };
|
||||
WKPageRunJavaScriptPromptResultListenerRef m_promptDialog = { };
|
||||
WKPageRunBeforeUnloadConfirmPanelResultListenerRef m_beforeUnloadDialog = { };
|
||||
};
|
||||
@@ -0,0 +1,168 @@
|
||||
/*
|
||||
* Copyright (C) 2006, 2008, 2013-2015 Apple Inc. All rights reserved.
|
||||
* Copyright (C) 2009, 2011 Brent Fulgham. All rights reserved.
|
||||
* Copyright (C) 2009, 2010, 2011 Appcelerator, Inc. All rights reserved.
|
||||
* Copyright (C) 2013 Alex Christensen. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#pragma warning(disable: 4091)
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "Common.h"
|
||||
#include "MainWindow.h"
|
||||
#include "PlaywrightLibResource.h"
|
||||
#include "PlaywrightReplace.h"
|
||||
#include <WebKit/WKContext.h>
|
||||
#include <WebKit/WKWebsiteDataStoreConfigurationRef.h>
|
||||
#include <WebKit/WKWebsiteDataStoreRef.h>
|
||||
#include <WebKit/WKWebsiteDataStoreRefCurl.h>
|
||||
#include <wtf/win/SoftLinking.h>
|
||||
#include "WebKitBrowserWindow.h"
|
||||
#include <wtf/MainThread.h>
|
||||
#include <WebKit/WKInspector.h>
|
||||
|
||||
SOFT_LINK_LIBRARY(user32);
|
||||
SOFT_LINK_OPTIONAL(user32, SetProcessDpiAwarenessContext, BOOL, STDAPICALLTYPE, (DPI_AWARENESS_CONTEXT));
|
||||
|
||||
CommandLineOptions g_options;
|
||||
|
||||
static WKRetainPtr<WKStringRef> toWK(const std::string& string)
|
||||
{
|
||||
return adoptWK(WKStringCreateWithUTF8CString(string.c_str()));
|
||||
}
|
||||
|
||||
static std::string toUTF8String(const wchar_t* src, size_t srcLength)
|
||||
{
|
||||
int length = WideCharToMultiByte(CP_UTF8, 0, src, srcLength, 0, 0, nullptr, nullptr);
|
||||
std::vector<char> buffer(length);
|
||||
size_t actualLength = WideCharToMultiByte(CP_UTF8, 0, src, srcLength, buffer.data(), length, nullptr, nullptr);
|
||||
return { buffer.data(), actualLength };
|
||||
}
|
||||
|
||||
static void configureDataStore(WKWebsiteDataStoreRef dataStore) {
|
||||
if (g_options.curloptProxy.length()) {
|
||||
auto curloptProxy = createWKURL(g_options.curloptProxy);
|
||||
auto curloptNoproxy = createWKString(g_options.curloptNoproxy);
|
||||
WKWebsiteDataStoreEnableCustomNetworkProxySettings(dataStore, curloptProxy.get(), curloptNoproxy.get());
|
||||
}
|
||||
}
|
||||
|
||||
int WINAPI wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPWSTR lpstrCmdLine, _In_ int nCmdShow)
|
||||
{
|
||||
hInst = hInstance;
|
||||
#ifdef _CRTDBG_MAP_ALLOC
|
||||
_CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR);
|
||||
_CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE);
|
||||
#endif
|
||||
|
||||
MSG msg { };
|
||||
HACCEL hAccelTable, hPreAccelTable;
|
||||
|
||||
INITCOMMONCONTROLSEX InitCtrlEx;
|
||||
|
||||
InitCtrlEx.dwSize = sizeof(INITCOMMONCONTROLSEX);
|
||||
InitCtrlEx.dwICC = 0x00004000; // ICC_STANDARD_CLASSES;
|
||||
InitCommonControlsEx(&InitCtrlEx);
|
||||
|
||||
g_options = parseCommandLine();
|
||||
if (g_options.inspectorPipe) {
|
||||
WKInspectorInitializeRemoteInspectorPipe(
|
||||
configureDataStore,
|
||||
WebKitBrowserWindow::createPageCallback,
|
||||
[]() { PostQuitMessage(0); });
|
||||
}
|
||||
|
||||
if (g_options.useFullDesktop)
|
||||
computeFullDesktopFrame();
|
||||
|
||||
// Init COM
|
||||
OleInitialize(nullptr);
|
||||
|
||||
if (SetProcessDpiAwarenessContextPtr())
|
||||
SetProcessDpiAwarenessContextPtr()(DPI_AWARENESS_CONTEXT_UNAWARE);
|
||||
|
||||
s_headless = g_options.headless;
|
||||
MainWindow::configure(g_options.inspectorPipe, g_options.disableAcceleratedCompositing);
|
||||
|
||||
if (!g_options.noStartupWindow) {
|
||||
auto configuration = adoptWK(WKWebsiteDataStoreConfigurationCreate());
|
||||
if (g_options.userDataDir.length()) {
|
||||
std::string profileFolder = toUTF8String(g_options.userDataDir, g_options.userDataDir.length());
|
||||
WKWebsiteDataStoreConfigurationSetNetworkCacheDirectory(configuration.get(), toWK(profileFolder + "\\Cache").get());
|
||||
WKWebsiteDataStoreConfigurationSetCacheStorageDirectory(configuration.get(), toWK(profileFolder + "\\CacheStorage").get());
|
||||
WKWebsiteDataStoreConfigurationSetIndexedDBDatabaseDirectory(configuration.get(), toWK(profileFolder + "\\Databases" + "\\IndexedDB").get());
|
||||
WKWebsiteDataStoreConfigurationSetLocalStorageDirectory(configuration.get(), toWK(profileFolder + "\\LocalStorage").get());
|
||||
WKWebsiteDataStoreConfigurationSetWebSQLDatabaseDirectory(configuration.get(), toWK(profileFolder + "\\Databases" + "\\WebSQL").get());
|
||||
WKWebsiteDataStoreConfigurationSetMediaKeysStorageDirectory(configuration.get(), toWK(profileFolder + "\\MediaKeys").get());
|
||||
WKWebsiteDataStoreConfigurationSetResourceLoadStatisticsDirectory(configuration.get(), toWK(profileFolder + "\\ResourceLoadStatistics").get());
|
||||
WKWebsiteDataStoreConfigurationSetServiceWorkerRegistrationDirectory(configuration.get(), toWK(profileFolder + "\\ServiceWorkers").get());
|
||||
}
|
||||
auto context = adoptWK(WKContextCreateWithConfiguration(nullptr));
|
||||
auto dataStore = adoptWK(WKWebsiteDataStoreCreateWithConfiguration(configuration.get()));
|
||||
configureDataStore(dataStore.get());
|
||||
|
||||
auto* mainWindow = new MainWindow();
|
||||
auto conf = adoptWK(WKPageConfigurationCreate());
|
||||
WKPageConfigurationSetContext(conf.get(), context.get());
|
||||
WKPageConfigurationSetWebsiteDataStore(conf.get(), dataStore.get());
|
||||
HRESULT hr = mainWindow->init(hInst, conf.get());
|
||||
if (FAILED(hr))
|
||||
goto exit;
|
||||
|
||||
if (g_options.requestedURL.length())
|
||||
mainWindow->loadURL(g_options.requestedURL.GetBSTR());
|
||||
else
|
||||
mainWindow->loadURL(L"about:blank");
|
||||
}
|
||||
|
||||
hAccelTable = LoadAccelerators(hInst, MAKEINTRESOURCE(IDC_PLAYWRIGHT));
|
||||
hPreAccelTable = LoadAccelerators(hInst, MAKEINTRESOURCE(IDR_ACCELERATORS_PRE));
|
||||
|
||||
#pragma warning(disable:4509)
|
||||
|
||||
// Main message loop:
|
||||
__try {
|
||||
while (GetMessage(&msg, nullptr, 0, 0)) {
|
||||
if (TranslateAccelerator(msg.hwnd, hPreAccelTable, &msg))
|
||||
continue;
|
||||
bool processed = false;
|
||||
if (MainWindow::isInstance(msg.hwnd))
|
||||
processed = TranslateAccelerator(msg.hwnd, hAccelTable, &msg);
|
||||
if (!processed) {
|
||||
TranslateMessage(&msg);
|
||||
DispatchMessage(&msg);
|
||||
}
|
||||
}
|
||||
} __except(createCrashReport(GetExceptionInformation()), EXCEPTION_EXECUTE_HANDLER) { }
|
||||
|
||||
exit:
|
||||
#ifdef _CRTDBG_MAP_ALLOC
|
||||
_CrtDumpMemoryLeaks();
|
||||
#endif
|
||||
|
||||
// Shut down COM.
|
||||
OleUninitialize();
|
||||
|
||||
return static_cast<int>(msg.wParam);
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
//{{NO_DEPENDENCIES}}
|
||||
// Microsoft Visual C++ generated include file.
|
||||
// Used by WinLauncher.rc
|
||||
//
|
||||
#define IDC_MYICON 2
|
||||
#define IDD_WINLAUNCHER_DIALOG 102
|
||||
#define IDS_APP_TITLE 103
|
||||
#define IDD_ABOUTBOX 103
|
||||
#define IDM_ABOUT 104
|
||||
#define IDI_WINLAUNCHER 107
|
||||
#define IDC_WINLAUNCHER 109
|
||||
#define IDR_MAINFRAME 128
|
||||
#define IDC_STATIC -1
|
||||
|
||||
// Next default values for new objects
|
||||
//
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
#ifndef APSTUDIO_READONLY_SYMBOLS
|
||||
#define _APS_NO_MFC 1
|
||||
#define _APS_NEXT_RESOURCE_VALUE 129
|
||||
#define _APS_NEXT_COMMAND_VALUE 32771
|
||||
#define _APS_NEXT_CONTROL_VALUE 1000
|
||||
#define _APS_NEXT_SYMED_VALUE 110
|
||||
#endif
|
||||
#endif
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright (C) 2006 Apple Inc. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
// stdafx.cpp : source file that includes just the standard includes
|
||||
// Spinneret.pch will be the pre-compiled header
|
||||
// stdafx.obj will contain the pre-compiled type information
|
||||
|
||||
#include "stdafx.h"
|
||||
|
||||
// TODO: reference any additional headers you need in STDAFX.H
|
||||
// and not in this file
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright (C) 2006 Apple Inc. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
// stdafx.h : include file for standard system include files,
|
||||
// or project specific include files that are used frequently, but
|
||||
// are changed infrequently
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#if defined(HAVE_CONFIG_H) && HAVE_CONFIG_H && defined(BUILDING_WITH_CMAKE)
|
||||
#include "cmakeconfig.h"
|
||||
#endif
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
|
||||
|
||||
// Needed for limit defines, like INTMAX_MAX, which is used by the std C++ library
|
||||
#ifndef __STDC_LIMIT_MACROS
|
||||
#define __STDC_LIMIT_MACROS
|
||||
#endif
|
||||
|
||||
#include <assert.h>
|
||||
#include <comdef.h>
|
||||
#include <comip.h>
|
||||
#include <commctrl.h>
|
||||
#include <commdlg.h>
|
||||
#include <comutil.h>
|
||||
#include <malloc.h>
|
||||
#include <memory.h>
|
||||
#include <objbase.h>
|
||||
#include <shellapi.h>
|
||||
#include <shlwapi.h>
|
||||
#include <stdlib.h>
|
||||
#include <string>
|
||||
#include <tchar.h>
|
||||
#include <windows.h>
|
||||
#include <wininet.h>
|
||||
#include <wtf/Platform.h>
|
||||
|
||||
#include <JavaScriptCore/JSExportMacros.h>
|
||||
#include <WebCore/PlatformExportMacros.h>
|
||||
|
||||
#if 0
|
||||
// Visual Studio Leak Detection
|
||||
// <http://msdn2.microsoft.com/en-US/library/e5ewb1h3.aspx>
|
||||
#if defined(_MSC_VER) && defined(_DEBUG)
|
||||
#define _CRTDBG_MAP_ALLOC
|
||||
#include <stdlib.h>
|
||||
#include <crtdbg.h>
|
||||
#endif
|
||||
#endif
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 982 B |
Reference in New Issue
Block a user