Skip to content
Permalink
Browse files
[Win][MiniBrowser] Remove gMainWindow global variable
https://bugs.webkit.org/show_bug.cgi?id=186378

Reviewed by Ryosuke Niwa.

I'm going to support multiple MainWindow in Bug 186263. It should
not be assumed that MainWindow has only one instance. gMainWindow
is used only in DisplayAuthDialog.

* MiniBrowser/win/Common.cpp:
(authDialogProc): Use DWLP_USER to store the dialog data.
(displayAuthDialog): Moved and renamed from
MainWindow::displayAuthDialog. Use DialogBoxParam instead of
DialogBox to pass a data pointer. Do not return S_OK if
DialogBoxParam returns -1. Take a HWND argument as the parent
window.
(DisplayAuthDialog): Deleted.
* MiniBrowser/win/Common.h:
* MiniBrowser/win/MainWindow.cpp:
(authDialogProc): Moved to Common.cpp.
(MainWindow::displayAuthDialog): Ditto.
* MiniBrowser/win/MainWindow.h:
* MiniBrowser/win/ResourceLoadDelegate.cpp:
(ResourceLoadDelegate::didReceiveAuthenticationChallenge):
* MiniBrowser/win/WinMain.cpp:
(wWinMain): Added a local variable mainWindow instead of using
gMainWindow.

Canonical link: https://commits.webkit.org/201749@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@232574 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
fujii committed Jun 7, 2018
1 parent 66f36d6 commit 5696bb68a4f4d83ad91c4032e091d24197f2d8ab
@@ -1,3 +1,33 @@
2018-06-06 Fujii Hironori <Hironori.Fujii@sony.com>

[Win][MiniBrowser] Remove gMainWindow global variable
https://bugs.webkit.org/show_bug.cgi?id=186378

Reviewed by Ryosuke Niwa.

I'm going to support multiple MainWindow in Bug 186263. It should
not be assumed that MainWindow has only one instance. gMainWindow
is used only in DisplayAuthDialog.

* MiniBrowser/win/Common.cpp:
(authDialogProc): Use DWLP_USER to store the dialog data.
(displayAuthDialog): Moved and renamed from
MainWindow::displayAuthDialog. Use DialogBoxParam instead of
DialogBox to pass a data pointer. Do not return S_OK if
DialogBoxParam returns -1. Take a HWND argument as the parent
window.
(DisplayAuthDialog): Deleted.
* MiniBrowser/win/Common.h:
* MiniBrowser/win/MainWindow.cpp:
(authDialogProc): Moved to Common.cpp.
(MainWindow::displayAuthDialog): Ditto.
* MiniBrowser/win/MainWindow.h:
* MiniBrowser/win/ResourceLoadDelegate.cpp:
(ResourceLoadDelegate::didReceiveAuthenticationChallenge):
* MiniBrowser/win/WinMain.cpp:
(wWinMain): Added a local variable mainWindow instead of using
gMainWindow.

2018-06-06 Dan Bernstein <mitz@apple.com>

[Xcode] Opt out of the New Build System
@@ -29,13 +29,14 @@
#include "stdafx.h"
#include "Common.h"

#include "MiniBrowserLibResource.h"
#include "MiniBrowserReplace.h"
#include <dbghelp.h>
#include <shlobj.h>
#include <wtf/StdLibExtras.h>

// Global Variables:
HINSTANCE hInst;
MainWindow* gMainWindow = nullptr;

// Support moving the transparent window
POINT s_windowPosition = { 100, 100 };
@@ -118,9 +119,50 @@ void createCrashReport(EXCEPTION_POINTERS* exceptionPointers)
}
}

HRESULT DisplayAuthDialog(std::wstring& username, std::wstring& password)
struct AuthDialogData {
std::wstring& username;
std::wstring& password;
};

static INT_PTR CALLBACK authDialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
AuthDialogData& data = *reinterpret_cast<AuthDialogData*>(GetWindowLongPtr(hDlg, DWLP_USER));
switch (message) {
case WM_INITDIALOG:
SetWindowLongPtr(hDlg, DWLP_USER, lParam);
return TRUE;

case WM_COMMAND: {
int wmId = LOWORD(wParam);
switch (wmId) {
case IDOK: {
TCHAR str[256];
int strLen = GetWindowText(GetDlgItem(hDlg, IDC_AUTH_USER), str, WTF_ARRAY_LENGTH(str)-1);
str[strLen] = 0;
data.username = str;

strLen = GetWindowText(GetDlgItem(hDlg, IDC_AUTH_PASSWORD), str, WTF_ARRAY_LENGTH(str)-1);
str[strLen] = 0;
data.password = str;

EndDialog(hDlg, true);
return TRUE;
}
case IDCANCEL:
EndDialog(hDlg, false);
return TRUE;
}
break;
}
}
return FALSE;
}

HRESULT displayAuthDialog(HWND hwnd, std::wstring& username, std::wstring& password)
{
return gMainWindow->displayAuthDialog(username, password);
AuthDialogData data { username, password };
auto result = DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_AUTH), hwnd, authDialogProc, reinterpret_cast<LPARAM>(&data));
return result > 0 ? S_OK : E_FAIL;
}

void parseCommandLine(bool& usesLayeredWebView, bool& useFullDesktop, bool& pageLoadTesting, _bstr_t& requestedURL)
@@ -33,8 +33,8 @@ void computeFullDesktopFrame();
bool getAppDataFolder(_bstr_t& directory);
void parseCommandLine(bool& usesLayeredWebView, bool& useFullDesktop, bool& pageLoadTesting, _bstr_t& requestedURL);
void createCrashReport(EXCEPTION_POINTERS*);
HRESULT displayAuthDialog(HWND, std::wstring& username, std::wstring& password);

extern HINSTANCE hInst;
extern MainWindow* gMainWindow;
extern POINT s_windowPosition;
extern SIZE s_windowSize;
@@ -383,56 +383,6 @@ INT_PTR CALLBACK MainWindow::customUserAgentDialogProc(HWND hDlg, UINT message,
return (INT_PTR)FALSE;
}

static INT_PTR CALLBACK authDialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message) {
case WM_INITDIALOG: {
HWND edit = ::GetDlgItem(hDlg, IDC_AUTH_USER);
::SetWindowText(edit, static_cast<LPCTSTR>(L""));

edit = ::GetDlgItem(hDlg, IDC_AUTH_PASSWORD);
::SetWindowText(edit, static_cast<LPCTSTR>(L""));
return (INT_PTR)TRUE;
}

case WM_COMMAND:
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) {
INT_PTR result { };

if (LOWORD(wParam) == IDOK) {
TCHAR user[256];
int strLen = ::GetWindowText(::GetDlgItem(hDlg, IDC_AUTH_USER), user, 256);
user[strLen] = 0;

TCHAR pass[256];
strLen = ::GetWindowText(::GetDlgItem(hDlg, IDC_AUTH_PASSWORD), pass, 256);
pass[strLen] = 0;

result = reinterpret_cast<INT_PTR>(new std::pair<std::wstring, std::wstring>(user, pass));
}

::EndDialog(hDlg, result);
return (INT_PTR)TRUE;
}
break;
}
return (INT_PTR)FALSE;
}

HRESULT MainWindow::displayAuthDialog(std::wstring& username, std::wstring& password)
{
auto result = DialogBox(hInst, MAKEINTRESOURCE(IDD_AUTH), hwnd(), authDialogProc);
if (!result)
return E_FAIL;

auto pair = reinterpret_cast<std::pair<std::wstring, std::wstring>*>(result);
username = pair->first;
password = pair->second;
delete pair;

return S_OK;
}

void MainWindow::loadURL(BSTR url)
{
if (FAILED(m_browserWindow->loadURL(url)))
@@ -39,7 +39,6 @@ class MainWindow {
MiniBrowser* browserWindow() const { return m_browserWindow.get(); }

void loadURL(BSTR url);
HRESULT displayAuthDialog(std::wstring& username, std::wstring& password);

private:
static LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
@@ -25,6 +25,7 @@
#include "stdafx.h"
#include "ResourceLoadDelegate.h"

#include "Common.h"
#include "MiniBrowser.h"
#include "PageLoadTestClient.h"
#include <WebCore/COMPtr.h>
@@ -37,8 +38,6 @@
#include <string>
#include <wininet.h>

extern HRESULT DisplayAuthDialog(std::wstring& username, std::wstring& password);

HRESULT ResourceLoadDelegate::QueryInterface(_In_ REFIID riid, _COM_Outptr_ void** ppvObject)
{
if (!ppvObject)
@@ -94,7 +93,7 @@ HRESULT ResourceLoadDelegate::didReceiveAuthenticationChallenge(_In_opt_ IWebVie
return E_FAIL;

std::wstring username, password;
if (DisplayAuthDialog(username, password) != S_OK)
if (displayAuthDialog(m_client->hwnd(), username, password) != S_OK)
return E_FAIL;

COMPtr<IWebURLCredential> credential;
@@ -65,19 +65,19 @@ int WINAPI wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance,

::SetProcessDPIAware();

gMainWindow = new MainWindow();
HRESULT hr = gMainWindow->init(hInst, usesLayeredWebView, pageLoadTesting);
auto mainWindow = new MainWindow();
HRESULT hr = mainWindow->init(hInst, usesLayeredWebView, pageLoadTesting);
if (FAILED(hr))
goto exit;

ShowWindow(gMainWindow->hwnd(), nCmdShow);
ShowWindow(mainWindow->hwnd(), nCmdShow);

hAccelTable = LoadAccelerators(hInst, MAKEINTRESOURCE(IDC_MINIBROWSER));

if (requestedURL.length())
gMainWindow->loadURL(requestedURL.GetBSTR());
mainWindow->loadURL(requestedURL.GetBSTR());
else
gMainWindow->browserWindow()->loadHTMLString(_bstr_t(defaultHTML).GetBSTR());
mainWindow->browserWindow()->loadHTMLString(_bstr_t(defaultHTML).GetBSTR());

#pragma warning(disable:4509)

0 comments on commit 5696bb6

Please sign in to comment.