[Win] Implement Authentication dialog in MiniBrowser
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 24 Jul 2017 18:34:58 +0000 (18:34 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 24 Jul 2017 18:34:58 +0000 (18:34 +0000)
https://bugs.webkit.org/show_bug.cgi?id=174662

Patch by Basuke Suzuki <Basuke.Suzuki@sony.com> on 2017-07-24
Reviewed by Alex Christensen.

* MiniBrowser/win/Common.cpp:
(CustomUserAgent):
(DisplayAuthDialog):
(AuthDialogProc):
* MiniBrowser/win/MiniBrowserLib.rc:
* MiniBrowser/win/MiniBrowserLibResource.h:
* MiniBrowser/win/ResourceLoadDelegate.cpp:
(ResourceLoadDelegate::didReceiveAuthenticationChallenge):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@219830 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Tools/ChangeLog
Tools/MiniBrowser/win/Common.cpp
Tools/MiniBrowser/win/MiniBrowserLib.rc
Tools/MiniBrowser/win/MiniBrowserLibResource.h
Tools/MiniBrowser/win/ResourceLoadDelegate.cpp

index 3755eece2923b0e9e26115183223d9034e144ac0..21c62754e0584772f9fd0c4427158ad3bb2c34fd 100644 (file)
@@ -1,3 +1,19 @@
+2017-07-24  Basuke Suzuki  <Basuke.Suzuki@sony.com>
+
+        [Win] Implement Authentication dialog in MiniBrowser
+        https://bugs.webkit.org/show_bug.cgi?id=174662
+
+        Reviewed by Alex Christensen.
+
+        * MiniBrowser/win/Common.cpp:
+        (CustomUserAgent):
+        (DisplayAuthDialog):
+        (AuthDialogProc):
+        * MiniBrowser/win/MiniBrowserLib.rc:
+        * MiniBrowser/win/MiniBrowserLibResource.h:
+        * MiniBrowser/win/ResourceLoadDelegate.cpp:
+        (ResourceLoadDelegate::didReceiveAuthenticationChallenge):
+
 2017-07-24  Jonathan Bedard  <jbedard@apple.com>
 
         Handle case where line_numbers is None instead of an array of line numbers
index e6f1413e0019ee74705e6e307ff8a64de4d848dd..1b71a76b28fe43d0ea474c44eee48466d5595757 100644 (file)
@@ -102,6 +102,7 @@ LRESULT CALLBACK BackButtonProc(HWND, UINT, WPARAM, LPARAM);
 LRESULT CALLBACK ForwardButtonProc(HWND, UINT, WPARAM, LPARAM);
 LRESULT CALLBACK ReloadButtonProc(HWND, UINT, WPARAM, LPARAM);
 INT_PTR CALLBACK Caches(HWND, UINT, WPARAM, LPARAM);
+INT_PTR CALLBACK AuthDialogProc(HWND, UINT, WPARAM, LPARAM);
 
 static void loadURL(BSTR urlBStr);
 static void updateStatistics(HWND hDlg);
@@ -664,6 +665,56 @@ INT_PTR CALLBACK CustomUserAgent(HWND hDlg, UINT message, WPARAM wParam, LPARAM
     return (INT_PTR)FALSE;
 }
 
+HRESULT DisplayAuthDialog(std::wstring& username, std::wstring& password)
+{
+    auto result = DialogBox(hInst, MAKEINTRESOURCE(IDD_AUTH), hMainWnd, 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;
+}
+
+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;
+}
+
 static void loadURL(BSTR passedURL)
 {
     if (FAILED(gMiniBrowser->loadURL(passedURL)))
index f701b4c478c268a6acd00c55180f5891638bb915..9af7bde32faaedfaf65c3f7989ac743ce34026cc 100644 (file)
@@ -29,8 +29,10 @@ LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
 // Icon with lowest ID value placed first to ensure application icon\r
 // remains consistent on all systems.\r
 IDI_MINIBROWSER         ICON                    "MiniBrowser.ico"\r
+\r
 IDI_SMALL               ICON                    "small.ico"\r
 \r
+\r
 /////////////////////////////////////////////////////////////////////////////\r
 //\r
 // Menu\r
@@ -240,6 +242,19 @@ BEGIN
     PUSHBUTTON      "Cancel",IDCANCEL,252,155,50,14\r
 END\r
 \r
+IDD_AUTH DIALOGEX 0, 0, 231, 99\r
+STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU\r
+CAPTION "Authentication Required"\r
+FONT 8, "MS Shell Dlg", 400, 0, 0x1\r
+BEGIN\r
+    DEFPUSHBUTTON   "Sign In",IDOK,116,78,50,14\r
+    PUSHBUTTON      "Cancel",IDCANCEL,174,78,50,14\r
+    RTEXT           "User Name:",IDC_STATIC,7,21,57,8\r
+    EDITTEXT        IDC_AUTH_USER,67,19,157,14,ES_AUTOHSCROLL\r
+    RTEXT           "Password:",IDC_STATIC,7,46,57,8\r
+    EDITTEXT        IDC_AUTH_PASSWORD,67,44,157,14,ES_PASSWORD | ES_AUTOHSCROLL\r
+END\r
+\r
 \r
 #ifdef APSTUDIO_INVOKED\r
 /////////////////////////////////////////////////////////////////////////////\r
@@ -296,6 +311,18 @@ BEGIN
         TOPMARGIN, 7\r
         BOTTOMMARGIN, 169\r
     END\r
+\r
+    IDD_AUTH, DIALOG\r
+    BEGIN\r
+        LEFTMARGIN, 7\r
+        RIGHTMARGIN, 224\r
+        VERTGUIDE, 64\r
+        VERTGUIDE, 67\r
+        TOPMARGIN, 7\r
+        BOTTOMMARGIN, 92\r
+        HORZGUIDE, 25\r
+        HORZGUIDE, 50\r
+    END\r
 END\r
 #endif    // APSTUDIO_INVOKED\r
 \r
index 425344743f4e15e12ee82dc14c4d5daf651babe9..7afca780062f166903ba6179ee24e4481d7f1d23 100644 (file)
@@ -1,4 +1,4 @@
-// {{NO_DEPENDENCIES}}
+//{{NO_DEPENDENCIES}}
 // Microsoft Visual C++ generated include file.
 // Used by MiniBrowserLib.rc
 //
@@ -53,6 +53,7 @@
 #define IDM_ZOOM_IN                     172
 #define IDM_ZOOM_OUT                    173
 #define IDM_SHOW_LAYER_TREE             174
+#define IDD_AUTH                        174
 #define IDM_DEBUG_INFO_LAYER            175
 #define IDC_EMPTY_URL_CACHE             1000
 #define IDC_RETURN_FREE_MEMORY          1001
 #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_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        174
+#define _APS_NEXT_RESOURCE_VALUE        175
 #define _APS_NEXT_COMMAND_VALUE         32776
-#define _APS_NEXT_CONTROL_VALUE         1053
+#define _APS_NEXT_CONTROL_VALUE         1054
 #define _APS_NEXT_SYMED_VALUE           110
 #endif
 #endif
index e72f3fe0f20d0586d9002c6c42af991cc7b8ec6c..5d17ddd3461d5457415b1d16e3d49741af3d0fa4 100644 (file)
 #include "stdafx.h"
 #include "ResourceLoadDelegate.h"
 
-#include "PageLoadTestClient.h"
 #include "MiniBrowser.h"
+#include "PageLoadTestClient.h"
+#include <COMPtr.h>
 #include <WebKit/WebKitCOMAPI.h>
 #include <comip.h>
 #include <commctrl.h>
 #include <commdlg.h>
 #include <objbase.h>
 #include <shlwapi.h>
+#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)
@@ -83,9 +87,23 @@ HRESULT ResourceLoadDelegate::willSendRequest(_In_opt_ IWebView*, unsigned long,
     return E_NOTIMPL;
 }
 
-HRESULT ResourceLoadDelegate::didReceiveAuthenticationChallenge(_In_opt_ IWebView*, unsigned long, _In_opt_ IWebURLAuthenticationChallenge*, _In_opt_ IWebDataSource*)
+HRESULT ResourceLoadDelegate::didReceiveAuthenticationChallenge(_In_opt_ IWebView*, unsigned long, _In_opt_ IWebURLAuthenticationChallenge* challenge, _In_opt_ IWebDataSource*)
 {
-    return E_NOTIMPL;
+    COMPtr<IWebURLAuthenticationChallengeSender> sender;
+    if (!challenge || FAILED(challenge->sender(&sender)))
+        return E_FAIL;
+
+    std::wstring username, password;
+    if (DisplayAuthDialog(username, password) != S_OK)
+        return E_FAIL;
+
+    COMPtr<IWebURLCredential> credential;
+    if (FAILED(WebKitCreateInstance(CLSID_WebURLCredential, 0, IID_IWebURLCredential, (void**)&credential)))
+        return E_FAIL;
+    credential->initWithUser(_bstr_t(username.c_str()), _bstr_t(password.c_str()), WebURLCredentialPersistenceForSession);
+
+    sender->useCredential(credential.get(), challenge);
+    return S_OK;
 }
 
 HRESULT ResourceLoadDelegate::didCancelAuthenticationChallenge(_In_opt_ IWebView*, unsigned long, _In_opt_ IWebURLAuthenticationChallenge*, _In_opt_ IWebDataSource*)