+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
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);
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)))
// 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
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
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
-// {{NO_DEPENDENCIES}}
+//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by MiniBrowserLib.rc
//
#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
#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)
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*)