Changeset 232333 in webkit
- Timestamp:
- May 30, 2018 8:31:15 PM (6 years ago)
- Location:
- trunk/Tools
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Tools/ChangeLog
r232323 r232333 1 2018-05-30 Fujii Hironori <Hironori.Fujii@sony.com> 2 3 [Win][MiniBrowser] Move MainWindow related code from Common.cpp to MainWindow.cpp 4 https://bugs.webkit.org/show_bug.cgi?id=186079 5 6 Reviewed by Alex Christensen. 7 8 This is a sub task of Bug 184770. 9 10 This change is partial. I'm going to remove global variables 11 gMainWindow and gMiniBrowser and convert more functions to 12 MainWindow's methods in follow-up patches. 13 14 * MiniBrowser/win/CMakeLists.txt: Added Common.cpp 15 * MiniBrowser/win/Common.cpp: 16 (menuItemIsChecked): Moved to MainWindow.cpp. 17 (turnOffOtherUserAgents): Ditto. 18 (EditProc): Ditto. 19 (BackButtonProc): Ditto. 20 (ForwardButtonProc): Ditto. 21 (About): Ditto. 22 (Caches): Ditto. 23 (CustomUserAgent): Ditto. 24 (AuthDialogProc): Ditto. 25 (DisplayAuthDialog): Converted to MainWindow's method. 26 (ToggleMenuItem): Ditto. 27 (loadURL): Ditto. 28 * MiniBrowser/win/Common.h: 29 * MiniBrowser/win/MainWindow.cpp: 30 (MainWindow::init): Call SetFocus at the end of the construction. 31 (MainWindow::WndProc): 32 (menuItemIsChecked): Moved from Common.cpp. 33 (turnOffOtherUserAgents): Ditto. 34 (EditProc): Ditto. 35 (BackButtonProc): Ditto. 36 (ForwardButtonProc): Ditto. 37 (About): Ditto. 38 (Caches): Ditto. 39 (CustomUserAgent): Ditto. 40 (authDialogProc): Ditto. 41 (MainWindow::displayAuthDialog): Converted from a function of Common.cpp. 42 (MainWindow::toggleMenuItem): Ditto. 43 (MainWindow::loadURL): Ditto. 44 * MiniBrowser/win/MainWindow.h: Added method declarations. 45 * MiniBrowser/win/MiniBrowser.h: Added pragma once. 46 * MiniBrowser/win/WinMain.cpp: 47 (wWinMain): Include Common.h instead of Common.cpp. 48 1 49 2018-05-30 Brady Eidson <beidson@apple.com> 2 50 -
trunk/Tools/MiniBrowser/win/CMakeLists.txt
r232234 r232333 8 8 set(MiniBrowser_SOURCES 9 9 AccessibilityDelegate.cpp 10 Common.cpp 10 11 DOMDefaultImpl.cpp 11 12 MainWindow.cpp -
trunk/Tools/MiniBrowser/win/Common.cpp
r232270 r232333 27 27 */ 28 28 29 #include " DOMDefaultImpl.h"30 #include " MainWindow.h"31 #include "MiniBrowser.h" 29 #include "stdafx.h" 30 #include "Common.h" 31 32 32 #include "MiniBrowserReplace.h" 33 #include <WebKitLegacy/WebKitCOMAPI.h>34 35 #if USE(CF)36 #include <CoreFoundation/CFRunLoop.h>37 #endif38 39 #include <cassert>40 #include <comip.h>41 #include <commctrl.h>42 #include <commdlg.h>43 #include <comutil.h>44 33 #include <dbghelp.h> 45 #include <memory>46 #include <objbase.h>47 #include <shellapi.h>48 34 #include <shlobj.h> 49 #include <shlwapi.h>50 #include <string>51 #include <vector>52 #include <wininet.h>53 54 #ifndef WM_DPICHANGED55 #define WM_DPICHANGED 0x02E056 #endif57 35 58 36 // Global Variables: 59 37 HINSTANCE hInst; 60 HWND hCacheWnd;61 WNDPROC DefEditProc = nullptr;62 WNDPROC DefButtonProc = nullptr;63 64 38 MainWindow* gMainWindow = nullptr; 65 39 MiniBrowser* gMiniBrowser = nullptr; … … 69 43 SIZE s_windowSize = { 500, 200 }; 70 44 71 // Forward declarations of functions included in this code module:72 INT_PTR CALLBACK AuthDialogProc(HWND, UINT, WPARAM, LPARAM);73 74 static void loadURL(BSTR urlBStr);75 76 45 namespace WebCore { 77 46 float deviceScaleFactorForWindow(HWND); 78 47 } 79 48 80 staticvoid computeFullDesktopFrame()49 void computeFullDesktopFrame() 81 50 { 82 51 RECT desktop; … … 151 120 } 152 121 153 static bool menuItemIsChecked(const MENUITEMINFO& info)122 HRESULT DisplayAuthDialog(std::wstring& username, std::wstring& password) 154 123 { 155 return info.fState & MFS_CHECKED;124 return gMainWindow->displayAuthDialog(username, password); 156 125 } 157 126 158 static void turnOffOtherUserAgents(HMENU menu) 159 { 160 MENUITEMINFO info; 161 ::memset(&info, 0x00, sizeof(info)); 162 info.cbSize = sizeof(info); 163 info.fMask = MIIM_STATE; 164 165 // Must unset the other menu items: 166 for (UINT menuToClear = IDM_UA_DEFAULT; menuToClear <= IDM_UA_OTHER; ++menuToClear) { 167 if (!::GetMenuItemInfo(menu, menuToClear, FALSE, &info)) 168 continue; 169 if (!menuItemIsChecked(info)) 170 continue; 171 172 info.fState = MFS_UNCHECKED; 173 ::SetMenuItemInfo(menu, menuToClear, FALSE, &info); 174 } 175 } 176 177 bool ToggleMenuItem(HWND hWnd, UINT menuID) 178 { 179 if (!gMiniBrowser) 180 return false; 181 182 HMENU menu = ::GetMenu(hWnd); 183 184 switch (menuID) { 185 case IDM_UA_DEFAULT: 186 case IDM_UA_SAFARI_8_0: 187 case IDM_UA_SAFARI_IOS_8_IPHONE: 188 case IDM_UA_SAFARI_IOS_8_IPAD: 189 case IDM_UA_IE_11: 190 case IDM_UA_CHROME_MAC: 191 case IDM_UA_CHROME_WIN: 192 case IDM_UA_FIREFOX_MAC: 193 case IDM_UA_FIREFOX_WIN: 194 gMiniBrowser->setUserAgent(menuID); 195 turnOffOtherUserAgents(menu); 196 break; 197 case IDM_UA_OTHER: 198 // The actual user agent string will be set by the custom user agent dialog 199 turnOffOtherUserAgents(menu); 200 break; 201 } 202 203 MENUITEMINFO info = { }; 204 info.cbSize = sizeof(info); 205 info.fMask = MIIM_STATE; 206 207 if (!::GetMenuItemInfo(menu, menuID, FALSE, &info)) 208 return false; 209 210 BOOL newState = !menuItemIsChecked(info); 211 info.fState = (newState) ? MFS_CHECKED : MFS_UNCHECKED; 212 ::SetMenuItemInfo(menu, menuID, FALSE, &info); 213 214 gMiniBrowser->setPreference(menuID, newState); 215 216 return true; 217 } 218 219 LRESULT CALLBACK EditProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) 220 { 221 switch (message) { 222 case WM_CHAR: 223 if (wParam == 13) { // Enter Key 224 wchar_t strPtr[INTERNET_MAX_URL_LENGTH]; 225 *((LPWORD)strPtr) = INTERNET_MAX_URL_LENGTH; 226 int strLen = SendMessage(hDlg, EM_GETLINE, 0, (LPARAM)strPtr); 227 228 strPtr[strLen] = 0; 229 _bstr_t bstr(strPtr); 230 loadURL(bstr.GetBSTR()); 231 232 return 0; 233 } 234 default: 235 return CallWindowProc(DefEditProc, hDlg, message, wParam, lParam); 236 } 237 } 238 239 LRESULT CALLBACK BackButtonProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) 240 { 241 switch (message) { 242 case WM_LBUTTONUP: 243 gMiniBrowser->goBack(); 244 default: 245 return CallWindowProc(DefButtonProc, hDlg, message, wParam, lParam); 246 } 247 } 248 249 LRESULT CALLBACK ForwardButtonProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) 250 { 251 switch (message) { 252 case WM_LBUTTONUP: 253 gMiniBrowser->goForward(); 254 default: 255 return CallWindowProc(DefButtonProc, hDlg, message, wParam, lParam); 256 } 257 } 258 259 // Message handler for about box. 260 INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) 261 { 262 UNREFERENCED_PARAMETER(lParam); 263 switch (message) { 264 case WM_INITDIALOG: 265 return (INT_PTR)TRUE; 266 267 case WM_COMMAND: 268 if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) { 269 EndDialog(hDlg, LOWORD(wParam)); 270 return (INT_PTR)TRUE; 271 } 272 break; 273 } 274 return (INT_PTR)FALSE; 275 } 276 277 INT_PTR CALLBACK Caches(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) 278 { 279 UNREFERENCED_PARAMETER(lParam); 280 switch (message) { 281 case WM_INITDIALOG: 282 ::SetTimer(hDlg, IDT_UPDATE_STATS, 1000, nullptr); 283 return (INT_PTR)TRUE; 284 285 case WM_COMMAND: 286 if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) { 287 ::KillTimer(hDlg, IDT_UPDATE_STATS); 288 ::DestroyWindow(hDlg); 289 hCacheWnd = 0; 290 return (INT_PTR)TRUE; 291 } 292 break; 293 294 case IDT_UPDATE_STATS: 295 ::InvalidateRect(hDlg, nullptr, FALSE); 296 return (INT_PTR)TRUE; 297 298 case WM_PAINT: 299 gMiniBrowser->updateStatistics(hDlg); 300 break; 301 } 302 303 return (INT_PTR)FALSE; 304 } 305 306 INT_PTR CALLBACK CustomUserAgent(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) 307 { 308 UNREFERENCED_PARAMETER(lParam); 309 switch (message) { 310 case WM_INITDIALOG: { 311 HWND edit = ::GetDlgItem(hDlg, IDC_USER_AGENT_INPUT); 312 _bstr_t userAgent; 313 if (gMiniBrowser) 314 userAgent = gMiniBrowser->userAgent(); 315 316 ::SetWindowText(edit, static_cast<LPCTSTR>(userAgent)); 317 return (INT_PTR)TRUE; 318 } 319 320 case WM_COMMAND: 321 if (LOWORD(wParam) == IDOK) { 322 HWND edit = ::GetDlgItem(hDlg, IDC_USER_AGENT_INPUT); 323 324 TCHAR buffer[1024]; 325 int strLen = ::GetWindowText(edit, buffer, 1024); 326 buffer[strLen] = 0; 327 328 _bstr_t bstr(buffer); 329 if (bstr.length()) { 330 gMiniBrowser->setUserAgent(bstr); 331 ::PostMessage(gMainWindow->hwnd(), static_cast<UINT>(WM_COMMAND), MAKELPARAM(IDM_UA_OTHER, 1), 0); 332 } 333 } 334 335 if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) { 336 ::EndDialog(hDlg, LOWORD(wParam)); 337 return (INT_PTR)TRUE; 338 } 339 break; 340 } 341 return (INT_PTR)FALSE; 342 } 343 344 HRESULT DisplayAuthDialog(std::wstring& username, std::wstring& password) 345 { 346 auto result = DialogBox(hInst, MAKEINTRESOURCE(IDD_AUTH), gMainWindow->hwnd(), AuthDialogProc); 347 if (!result) 348 return E_FAIL; 349 350 auto pair = reinterpret_cast<std::pair<std::wstring, std::wstring>*>(result); 351 username = pair->first; 352 password = pair->second; 353 delete pair; 354 355 return S_OK; 356 } 357 358 INT_PTR CALLBACK AuthDialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) 359 { 360 switch (message) { 361 case WM_INITDIALOG: { 362 HWND edit = ::GetDlgItem(hDlg, IDC_AUTH_USER); 363 ::SetWindowText(edit, static_cast<LPCTSTR>(L"")); 364 365 edit = ::GetDlgItem(hDlg, IDC_AUTH_PASSWORD); 366 ::SetWindowText(edit, static_cast<LPCTSTR>(L"")); 367 return (INT_PTR)TRUE; 368 } 369 370 case WM_COMMAND: 371 if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) { 372 INT_PTR result { }; 373 374 if (LOWORD(wParam) == IDOK) { 375 TCHAR user[256]; 376 int strLen = ::GetWindowText(::GetDlgItem(hDlg, IDC_AUTH_USER), user, 256); 377 user[strLen] = 0; 378 379 TCHAR pass[256]; 380 strLen = ::GetWindowText(::GetDlgItem(hDlg, IDC_AUTH_PASSWORD), pass, 256); 381 pass[strLen] = 0; 382 383 result = reinterpret_cast<INT_PTR>(new std::pair<std::wstring, std::wstring>(user, pass)); 384 } 385 386 ::EndDialog(hDlg, result); 387 return (INT_PTR)TRUE; 388 } 389 break; 390 } 391 return (INT_PTR)FALSE; 392 } 393 394 static void loadURL(BSTR passedURL) 395 { 396 if (FAILED(gMiniBrowser->loadURL(passedURL))) 397 return; 398 399 SetFocus(gMiniBrowser->hwnd()); 400 } 401 402 static void parseCommandLine(bool& usesLayeredWebView, bool& useFullDesktop, bool& pageLoadTesting, _bstr_t& requestedURL) 127 void parseCommandLine(bool& usesLayeredWebView, bool& useFullDesktop, bool& pageLoadTesting, _bstr_t& requestedURL) 403 128 { 404 129 usesLayeredWebView = false; -
trunk/Tools/MiniBrowser/win/Common.h
r231707 r232333 26 26 #pragma once 27 27 28 #include "stdafx.h" 29 #include "MainWindow.h" 30 #include "MiniBrowser.h" 31 32 void computeFullDesktopFrame(); 28 33 bool getAppDataFolder(_bstr_t& directory); 34 void parseCommandLine(bool& usesLayeredWebView, bool& useFullDesktop, bool& pageLoadTesting, _bstr_t& requestedURL); 35 void createCrashReport(EXCEPTION_POINTERS*); 29 36 37 extern HINSTANCE hInst; 38 extern MainWindow* gMainWindow; 39 extern MiniBrowser* gMiniBrowser; 30 40 extern POINT s_windowPosition; 31 41 extern SIZE s_windowSize; -
trunk/Tools/MiniBrowser/win/MainWindow.cpp
r232270 r232333 26 26 #include "stdafx.h" 27 27 #include "MainWindow.h" 28 29 #include "Common.h" 28 30 #include "MiniBrowser.h" 29 31 #include "MiniBrowserLibResource.h" … … 35 37 static constexpr int controlButtonWidth = 24; 36 38 37 extern MainWindow* gMainWindow; 38 extern MiniBrowser* gMiniBrowser; 39 extern WNDPROC DefEditProc; 40 extern WNDPROC DefButtonProc; 41 extern HINSTANCE hInst; 42 extern HWND hCacheWnd; 43 44 LRESULT CALLBACK EditProc(HWND, UINT, WPARAM, LPARAM); 45 LRESULT CALLBACK BackButtonProc(HWND, UINT, WPARAM, LPARAM); 46 LRESULT CALLBACK ForwardButtonProc(HWND, UINT, WPARAM, LPARAM); 47 LRESULT CALLBACK ReloadButtonProc(HWND, UINT, WPARAM, LPARAM); 48 INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM); 49 INT_PTR CALLBACK CustomUserAgent(HWND, UINT, WPARAM, LPARAM); 50 INT_PTR CALLBACK Caches(HWND, UINT, WPARAM, LPARAM); 51 INT_PTR CALLBACK AuthDialogProc(HWND, UINT, WPARAM, LPARAM); 52 bool ToggleMenuItem(HWND hWnd, UINT menuID); 39 static HWND hCacheWnd; 40 static WNDPROC DefEditProc = nullptr; 41 static WNDPROC DefButtonProc = nullptr; 42 43 static LRESULT CALLBACK EditProc(HWND, UINT, WPARAM, LPARAM); 44 static LRESULT CALLBACK BackButtonProc(HWND, UINT, WPARAM, LPARAM); 45 static LRESULT CALLBACK ForwardButtonProc(HWND, UINT, WPARAM, LPARAM); 46 static LRESULT CALLBACK ReloadButtonProc(HWND, UINT, WPARAM, LPARAM); 47 static INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM); 48 static INT_PTR CALLBACK CustomUserAgent(HWND, UINT, WPARAM, LPARAM); 49 static INT_PTR CALLBACK Caches(HWND, UINT, WPARAM, LPARAM); 53 50 54 51 std::wstring MainWindow::s_windowClass; … … 111 108 SetWindowLongPtr(m_hForwardButtonWnd, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(ForwardButtonProc)); 112 109 113 SetFocus(m_hURLBarWnd);114 115 110 m_browserWindow = std::make_unique<MiniBrowser>(m_hMainWnd, m_hURLBarWnd, usesLayeredWebView, pageLoadTesting); 116 111 if (!m_browserWindow) … … 121 116 122 117 resizeSubViews(); 118 SetFocus(m_hURLBarWnd); 123 119 return true; 124 120 } … … 185 181 case IDM_UA_OTHER: 186 182 if (wmEvent) 187 ToggleMenuItem(hWnd,wmId);183 gMainWindow->toggleMenuItem(wmId); 188 184 else 189 185 DialogBox(hInst, MAKEINTRESOURCE(IDD_USER_AGENT), hWnd, CustomUserAgent); … … 206 202 break; 207 203 default: 208 if (! ToggleMenuItem(hWnd,wmId))204 if (!gMainWindow->toggleMenuItem(wmId)) 209 205 return DefWindowProc(hWnd, message, wParam, lParam); 210 206 } … … 233 229 return 0; 234 230 } 231 232 static bool menuItemIsChecked(const MENUITEMINFO& info) 233 { 234 return info.fState & MFS_CHECKED; 235 } 236 237 static void turnOffOtherUserAgents(HMENU menu) 238 { 239 MENUITEMINFO info; 240 ::memset(&info, 0x00, sizeof(info)); 241 info.cbSize = sizeof(info); 242 info.fMask = MIIM_STATE; 243 244 // Must unset the other menu items: 245 for (UINT menuToClear = IDM_UA_DEFAULT; menuToClear <= IDM_UA_OTHER; ++menuToClear) { 246 if (!::GetMenuItemInfo(menu, menuToClear, FALSE, &info)) 247 continue; 248 if (!menuItemIsChecked(info)) 249 continue; 250 251 info.fState = MFS_UNCHECKED; 252 ::SetMenuItemInfo(menu, menuToClear, FALSE, &info); 253 } 254 } 255 256 bool MainWindow::toggleMenuItem(UINT menuID) 257 { 258 HMENU menu = ::GetMenu(hwnd()); 259 260 switch (menuID) { 261 case IDM_UA_DEFAULT: 262 case IDM_UA_SAFARI_8_0: 263 case IDM_UA_SAFARI_IOS_8_IPHONE: 264 case IDM_UA_SAFARI_IOS_8_IPAD: 265 case IDM_UA_IE_11: 266 case IDM_UA_CHROME_MAC: 267 case IDM_UA_CHROME_WIN: 268 case IDM_UA_FIREFOX_MAC: 269 case IDM_UA_FIREFOX_WIN: 270 m_browserWindow->setUserAgent(menuID); 271 turnOffOtherUserAgents(menu); 272 break; 273 case IDM_UA_OTHER: 274 // The actual user agent string will be set by the custom user agent dialog 275 turnOffOtherUserAgents(menu); 276 break; 277 } 278 279 MENUITEMINFO info = { }; 280 info.cbSize = sizeof(info); 281 info.fMask = MIIM_STATE; 282 283 if (!::GetMenuItemInfo(menu, menuID, FALSE, &info)) 284 return false; 285 286 BOOL newState = !menuItemIsChecked(info); 287 info.fState = (newState) ? MFS_CHECKED : MFS_UNCHECKED; 288 ::SetMenuItemInfo(menu, menuID, FALSE, &info); 289 290 m_browserWindow->setPreference(menuID, newState); 291 292 return true; 293 } 294 295 LRESULT CALLBACK EditProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) 296 { 297 switch (message) { 298 case WM_CHAR: 299 if (wParam == 13) { 300 // Enter Key 301 wchar_t strPtr[INTERNET_MAX_URL_LENGTH]; 302 *((LPWORD)strPtr) = INTERNET_MAX_URL_LENGTH; 303 int strLen = SendMessage(hDlg, EM_GETLINE, 0, (LPARAM)strPtr); 304 305 strPtr[strLen] = 0; 306 _bstr_t bstr(strPtr); 307 gMainWindow->loadURL(bstr.GetBSTR()); 308 309 return 0; 310 } 311 default: 312 return CallWindowProc(DefEditProc, hDlg, message, wParam, lParam); 313 } 314 } 315 316 LRESULT CALLBACK BackButtonProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) 317 { 318 switch (message) { 319 case WM_LBUTTONUP: 320 gMiniBrowser->goBack(); 321 default: 322 return CallWindowProc(DefButtonProc, hDlg, message, wParam, lParam); 323 } 324 } 325 326 LRESULT CALLBACK ForwardButtonProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) 327 { 328 switch (message) { 329 case WM_LBUTTONUP: 330 gMiniBrowser->goForward(); 331 default: 332 return CallWindowProc(DefButtonProc, hDlg, message, wParam, lParam); 333 } 334 } 335 336 // Message handler for about box. 337 INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) 338 { 339 UNREFERENCED_PARAMETER(lParam); 340 switch (message) { 341 case WM_INITDIALOG: 342 return (INT_PTR)TRUE; 343 344 case WM_COMMAND: 345 if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) { 346 EndDialog(hDlg, LOWORD(wParam)); 347 return (INT_PTR)TRUE; 348 } 349 break; 350 } 351 return (INT_PTR)FALSE; 352 } 353 354 INT_PTR CALLBACK Caches(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) 355 { 356 UNREFERENCED_PARAMETER(lParam); 357 switch (message) { 358 case WM_INITDIALOG: 359 ::SetTimer(hDlg, IDT_UPDATE_STATS, 1000, nullptr); 360 return (INT_PTR)TRUE; 361 362 case WM_COMMAND: 363 if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) { 364 ::KillTimer(hDlg, IDT_UPDATE_STATS); 365 ::DestroyWindow(hDlg); 366 hCacheWnd = 0; 367 return (INT_PTR)TRUE; 368 } 369 break; 370 371 case IDT_UPDATE_STATS: 372 ::InvalidateRect(hDlg, nullptr, FALSE); 373 return (INT_PTR)TRUE; 374 375 case WM_PAINT: 376 gMiniBrowser->updateStatistics(hDlg); 377 break; 378 } 379 380 return (INT_PTR)FALSE; 381 } 382 383 INT_PTR CALLBACK CustomUserAgent(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) 384 { 385 UNREFERENCED_PARAMETER(lParam); 386 switch (message) { 387 case WM_INITDIALOG: { 388 HWND edit = ::GetDlgItem(hDlg, IDC_USER_AGENT_INPUT); 389 _bstr_t userAgent; 390 if (gMiniBrowser) 391 userAgent = gMiniBrowser->userAgent(); 392 393 ::SetWindowText(edit, static_cast<LPCTSTR>(userAgent)); 394 return (INT_PTR)TRUE; 395 } 396 397 case WM_COMMAND: 398 if (LOWORD(wParam) == IDOK) { 399 HWND edit = ::GetDlgItem(hDlg, IDC_USER_AGENT_INPUT); 400 401 TCHAR buffer[1024]; 402 int strLen = ::GetWindowText(edit, buffer, 1024); 403 buffer[strLen] = 0; 404 405 _bstr_t bstr(buffer); 406 if (bstr.length()) { 407 gMiniBrowser->setUserAgent(bstr); 408 ::PostMessage(gMainWindow->hwnd(), static_cast<UINT>(WM_COMMAND), MAKELPARAM(IDM_UA_OTHER, 1), 0); 409 } 410 } 411 412 if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) { 413 ::EndDialog(hDlg, LOWORD(wParam)); 414 return (INT_PTR)TRUE; 415 } 416 break; 417 } 418 return (INT_PTR)FALSE; 419 } 420 421 static INT_PTR CALLBACK authDialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) 422 { 423 switch (message) { 424 case WM_INITDIALOG: { 425 HWND edit = ::GetDlgItem(hDlg, IDC_AUTH_USER); 426 ::SetWindowText(edit, static_cast<LPCTSTR>(L"")); 427 428 edit = ::GetDlgItem(hDlg, IDC_AUTH_PASSWORD); 429 ::SetWindowText(edit, static_cast<LPCTSTR>(L"")); 430 return (INT_PTR)TRUE; 431 } 432 433 case WM_COMMAND: 434 if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) { 435 INT_PTR result { }; 436 437 if (LOWORD(wParam) == IDOK) { 438 TCHAR user[256]; 439 int strLen = ::GetWindowText(::GetDlgItem(hDlg, IDC_AUTH_USER), user, 256); 440 user[strLen] = 0; 441 442 TCHAR pass[256]; 443 strLen = ::GetWindowText(::GetDlgItem(hDlg, IDC_AUTH_PASSWORD), pass, 256); 444 pass[strLen] = 0; 445 446 result = reinterpret_cast<INT_PTR>(new std::pair<std::wstring, std::wstring>(user, pass)); 447 } 448 449 ::EndDialog(hDlg, result); 450 return (INT_PTR)TRUE; 451 } 452 break; 453 } 454 return (INT_PTR)FALSE; 455 } 456 457 HRESULT MainWindow::displayAuthDialog(std::wstring& username, std::wstring& password) 458 { 459 auto result = DialogBox(hInst, MAKEINTRESOURCE(IDD_AUTH), hwnd(), authDialogProc); 460 if (!result) 461 return E_FAIL; 462 463 auto pair = reinterpret_cast<std::pair<std::wstring, std::wstring>*>(result); 464 username = pair->first; 465 password = pair->second; 466 delete pair; 467 468 return S_OK; 469 } 470 471 void MainWindow::loadURL(BSTR url) 472 { 473 if (FAILED(m_browserWindow->loadURL(url))) 474 return; 475 476 SetFocus(m_browserWindow->hwnd()); 477 } -
trunk/Tools/MiniBrowser/win/MainWindow.h
r232234 r232333 38 38 HWND hwnd() const { return m_hMainWnd; } 39 39 MiniBrowser* browserWindow() const { return m_browserWindow.get(); } 40 41 void loadURL(BSTR url); 42 HRESULT displayAuthDialog(std::wstring& username, std::wstring& password); 40 43 41 44 private: … … 43 46 static void registerClass(HINSTANCE hInstance); 44 47 static std::wstring s_windowClass; 48 49 bool toggleMenuItem(UINT menuID); 45 50 46 51 HWND m_hMainWnd { nullptr }; -
trunk/Tools/MiniBrowser/win/MiniBrowser.h
r232270 r232333 24 24 */ 25 25 26 #pragma once 26 27 #include "PageLoadTestClient.h" 27 28 #include <WebKitLegacy/WebKit.h> -
trunk/Tools/MiniBrowser/win/WinMain.cpp
r232234 r232333 30 30 31 31 #include "stdafx.h" 32 #include "Common.h" 32 33 #include "MiniBrowserLibResource.h" 33 #include "Common.cpp" 34 #include "MiniBrowserReplace.h" 35 #include <WebKitLegacy/WebKitCOMAPI.h> 34 36 35 37 int WINAPI wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPWSTR lpstrCmdLine, _In_ int nCmdShow) … … 75 77 76 78 if (requestedURL.length()) 77 loadURL(requestedURL.GetBSTR());79 gMainWindow->loadURL(requestedURL.GetBSTR()); 78 80 else 79 81 gMiniBrowser->loadHTMLString(_bstr_t(defaultHTML).GetBSTR());
Note: See TracChangeset
for help on using the changeset viewer.