Title: [232574] trunk/Tools
Revision
232574
Author
[email protected]
Date
2018-06-06 23:25:41 -0700 (Wed, 06 Jun 2018)

Log Message

[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.

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (232573 => 232574)


--- trunk/Tools/ChangeLog	2018-06-07 05:09:23 UTC (rev 232573)
+++ trunk/Tools/ChangeLog	2018-06-07 06:25:41 UTC (rev 232574)
@@ -1,3 +1,33 @@
+2018-06-06  Fujii Hironori  <[email protected]>
+
+        [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  <[email protected]>
 
         [Xcode] Opt out of the New Build System

Modified: trunk/Tools/MiniBrowser/win/Common.cpp (232573 => 232574)


--- trunk/Tools/MiniBrowser/win/Common.cpp	2018-06-07 05:09:23 UTC (rev 232573)
+++ trunk/Tools/MiniBrowser/win/Common.cpp	2018-06-07 06:25:41 UTC (rev 232574)
@@ -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,11 +119,52 @@
     }
 }
 
-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)
 {
-    return gMainWindow->displayAuthDialog(username, password);
+    AuthDialogData& data = "" 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)
+{
+    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)
 {
     usesLayeredWebView = false;

Modified: trunk/Tools/MiniBrowser/win/Common.h (232573 => 232574)


--- trunk/Tools/MiniBrowser/win/Common.h	2018-06-07 05:09:23 UTC (rev 232573)
+++ trunk/Tools/MiniBrowser/win/Common.h	2018-06-07 06:25:41 UTC (rev 232574)
@@ -33,8 +33,8 @@
 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;

Modified: trunk/Tools/MiniBrowser/win/MainWindow.cpp (232573 => 232574)


--- trunk/Tools/MiniBrowser/win/MainWindow.cpp	2018-06-07 05:09:23 UTC (rev 232573)
+++ trunk/Tools/MiniBrowser/win/MainWindow.cpp	2018-06-07 06:25:41 UTC (rev 232574)
@@ -383,56 +383,6 @@
     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)))

Modified: trunk/Tools/MiniBrowser/win/MainWindow.h (232573 => 232574)


--- trunk/Tools/MiniBrowser/win/MainWindow.h	2018-06-07 05:09:23 UTC (rev 232573)
+++ trunk/Tools/MiniBrowser/win/MainWindow.h	2018-06-07 06:25:41 UTC (rev 232574)
@@ -39,7 +39,6 @@
     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);

Modified: trunk/Tools/MiniBrowser/win/ResourceLoadDelegate.cpp (232573 => 232574)


--- trunk/Tools/MiniBrowser/win/ResourceLoadDelegate.cpp	2018-06-07 05:09:23 UTC (rev 232573)
+++ trunk/Tools/MiniBrowser/win/ResourceLoadDelegate.cpp	2018-06-07 06:25:41 UTC (rev 232574)
@@ -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 @@
         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;

Modified: trunk/Tools/MiniBrowser/win/WinMain.cpp (232573 => 232574)


--- trunk/Tools/MiniBrowser/win/WinMain.cpp	2018-06-07 05:09:23 UTC (rev 232573)
+++ trunk/Tools/MiniBrowser/win/WinMain.cpp	2018-06-07 06:25:41 UTC (rev 232574)
@@ -65,19 +65,19 @@
 
     ::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)
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to