Changeset 232333 in webkit


Ignore:
Timestamp:
May 30, 2018 8:31:15 PM (6 years ago)
Author:
Fujii Hironori
Message:

[Win][MiniBrowser] Move MainWindow related code from Common.cpp to MainWindow.cpp
https://bugs.webkit.org/show_bug.cgi?id=186079

Reviewed by Alex Christensen.

This is a sub task of Bug 184770.

This change is partial. I'm going to remove global variables
gMainWindow and gMiniBrowser and convert more functions to
MainWindow's methods in follow-up patches.

  • MiniBrowser/win/CMakeLists.txt: Added Common.cpp
  • MiniBrowser/win/Common.cpp:

(menuItemIsChecked): Moved to MainWindow.cpp.
(turnOffOtherUserAgents): Ditto.
(EditProc): Ditto.
(BackButtonProc): Ditto.
(ForwardButtonProc): Ditto.
(About): Ditto.
(Caches): Ditto.
(CustomUserAgent): Ditto.
(AuthDialogProc): Ditto.
(DisplayAuthDialog): Converted to MainWindow's method.
(ToggleMenuItem): Ditto.
(loadURL): Ditto.

  • MiniBrowser/win/Common.h:
  • MiniBrowser/win/MainWindow.cpp:

(MainWindow::init): Call SetFocus at the end of the construction.
(MainWindow::WndProc):
(menuItemIsChecked): Moved from Common.cpp.
(turnOffOtherUserAgents): Ditto.
(EditProc): Ditto.
(BackButtonProc): Ditto.
(ForwardButtonProc): Ditto.
(About): Ditto.
(Caches): Ditto.
(CustomUserAgent): Ditto.
(authDialogProc): Ditto.
(MainWindow::displayAuthDialog): Converted from a function of Common.cpp.
(MainWindow::toggleMenuItem): Ditto.
(MainWindow::loadURL): Ditto.

  • MiniBrowser/win/MainWindow.h: Added method declarations.
  • MiniBrowser/win/MiniBrowser.h: Added pragma once.
  • MiniBrowser/win/WinMain.cpp:

(wWinMain): Include Common.h instead of Common.cpp.

Location:
trunk/Tools
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r232323 r232333  
     12018-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
    1492018-05-30  Brady Eidson  <beidson@apple.com>
    250
  • trunk/Tools/MiniBrowser/win/CMakeLists.txt

    r232234 r232333  
    88set(MiniBrowser_SOURCES
    99    AccessibilityDelegate.cpp
     10    Common.cpp
    1011    DOMDefaultImpl.cpp
    1112    MainWindow.cpp
  • trunk/Tools/MiniBrowser/win/Common.cpp

    r232270 r232333  
    2727 */
    2828
    29 #include "DOMDefaultImpl.h"
    30 #include "MainWindow.h"
    31 #include "MiniBrowser.h"
     29#include "stdafx.h"
     30#include "Common.h"
     31
    3232#include "MiniBrowserReplace.h"
    33 #include <WebKitLegacy/WebKitCOMAPI.h>
    34 
    35 #if USE(CF)
    36 #include <CoreFoundation/CFRunLoop.h>
    37 #endif
    38 
    39 #include <cassert>
    40 #include <comip.h>
    41 #include <commctrl.h>
    42 #include <commdlg.h>
    43 #include <comutil.h>
    4433#include <dbghelp.h>
    45 #include <memory>
    46 #include <objbase.h>
    47 #include <shellapi.h>
    4834#include <shlobj.h>
    49 #include <shlwapi.h>
    50 #include <string>
    51 #include <vector>
    52 #include <wininet.h>
    53 
    54 #ifndef WM_DPICHANGED
    55 #define WM_DPICHANGED 0x02E0
    56 #endif
    5735
    5836// Global Variables:
    5937HINSTANCE hInst;
    60 HWND hCacheWnd;
    61 WNDPROC DefEditProc = nullptr;
    62 WNDPROC DefButtonProc = nullptr;
    63 
    6438MainWindow* gMainWindow = nullptr;
    6539MiniBrowser* gMiniBrowser = nullptr;
     
    6943SIZE s_windowSize = { 500, 200 };
    7044
    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 
    7645namespace WebCore {
    7746float deviceScaleFactorForWindow(HWND);
    7847}
    7948
    80 static void computeFullDesktopFrame()
     49void computeFullDesktopFrame()
    8150{
    8251    RECT desktop;
     
    151120}
    152121
    153 static bool menuItemIsChecked(const MENUITEMINFO& info)
     122HRESULT DisplayAuthDialog(std::wstring& username, std::wstring& password)
    154123{
    155     return info.fState & MFS_CHECKED;
     124    return gMainWindow->displayAuthDialog(username, password);
    156125}
    157126
    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)
     127void parseCommandLine(bool& usesLayeredWebView, bool& useFullDesktop, bool& pageLoadTesting, _bstr_t& requestedURL)
    403128{
    404129    usesLayeredWebView = false;
  • trunk/Tools/MiniBrowser/win/Common.h

    r231707 r232333  
    2626#pragma once
    2727
     28#include "stdafx.h"
     29#include "MainWindow.h"
     30#include "MiniBrowser.h"
     31
     32void computeFullDesktopFrame();
    2833bool getAppDataFolder(_bstr_t& directory);
     34void parseCommandLine(bool& usesLayeredWebView, bool& useFullDesktop, bool& pageLoadTesting, _bstr_t& requestedURL);
     35void createCrashReport(EXCEPTION_POINTERS*);
    2936
     37extern HINSTANCE hInst;
     38extern MainWindow* gMainWindow;
     39extern MiniBrowser* gMiniBrowser;
    3040extern POINT s_windowPosition;
    3141extern SIZE s_windowSize;
  • trunk/Tools/MiniBrowser/win/MainWindow.cpp

    r232270 r232333  
    2626#include "stdafx.h"
    2727#include "MainWindow.h"
     28
     29#include "Common.h"
    2830#include "MiniBrowser.h"
    2931#include "MiniBrowserLibResource.h"
     
    3537static constexpr int controlButtonWidth = 24;
    3638
    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);
     39static HWND hCacheWnd;
     40static WNDPROC DefEditProc = nullptr;
     41static WNDPROC DefButtonProc = nullptr;
     42
     43static LRESULT CALLBACK EditProc(HWND, UINT, WPARAM, LPARAM);
     44static LRESULT CALLBACK BackButtonProc(HWND, UINT, WPARAM, LPARAM);
     45static LRESULT CALLBACK ForwardButtonProc(HWND, UINT, WPARAM, LPARAM);
     46static LRESULT CALLBACK ReloadButtonProc(HWND, UINT, WPARAM, LPARAM);
     47static INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM);
     48static INT_PTR CALLBACK CustomUserAgent(HWND, UINT, WPARAM, LPARAM);
     49static INT_PTR CALLBACK Caches(HWND, UINT, WPARAM, LPARAM);
    5350
    5451std::wstring MainWindow::s_windowClass;
     
    111108    SetWindowLongPtr(m_hForwardButtonWnd, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(ForwardButtonProc));
    112109
    113     SetFocus(m_hURLBarWnd);
    114 
    115110    m_browserWindow = std::make_unique<MiniBrowser>(m_hMainWnd, m_hURLBarWnd, usesLayeredWebView, pageLoadTesting);
    116111    if (!m_browserWindow)
     
    121116
    122117    resizeSubViews();
     118    SetFocus(m_hURLBarWnd);
    123119    return true;
    124120}
     
    185181        case IDM_UA_OTHER:
    186182            if (wmEvent)
    187                 ToggleMenuItem(hWnd, wmId);
     183                gMainWindow->toggleMenuItem(wmId);
    188184            else
    189185                DialogBox(hInst, MAKEINTRESOURCE(IDD_USER_AGENT), hWnd, CustomUserAgent);
     
    206202            break;
    207203        default:
    208             if (!ToggleMenuItem(hWnd, wmId))
     204            if (!gMainWindow->toggleMenuItem(wmId))
    209205                return DefWindowProc(hWnd, message, wParam, lParam);
    210206        }
     
    233229    return 0;
    234230}
     231
     232static bool menuItemIsChecked(const MENUITEMINFO& info)
     233{
     234    return info.fState & MFS_CHECKED;
     235}
     236
     237static 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
     256bool 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
     295LRESULT 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
     316LRESULT 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
     326LRESULT 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.
     337INT_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
     354INT_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
     383INT_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
     421static 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
     457HRESULT 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
     471void 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  
    3838    HWND hwnd() const { return m_hMainWnd; }
    3939    MiniBrowser* browserWindow() const { return m_browserWindow.get(); }
     40
     41    void loadURL(BSTR url);
     42    HRESULT displayAuthDialog(std::wstring& username, std::wstring& password);
    4043   
    4144private:
     
    4346    static void registerClass(HINSTANCE hInstance);
    4447    static std::wstring s_windowClass;
     48
     49    bool toggleMenuItem(UINT menuID);
    4550
    4651    HWND m_hMainWnd { nullptr };
  • trunk/Tools/MiniBrowser/win/MiniBrowser.h

    r232270 r232333  
    2424 */
    2525
     26#pragma once
    2627#include "PageLoadTestClient.h"
    2728#include <WebKitLegacy/WebKit.h>
  • trunk/Tools/MiniBrowser/win/WinMain.cpp

    r232234 r232333  
    3030
    3131#include "stdafx.h"
     32#include "Common.h"
    3233#include "MiniBrowserLibResource.h"
    33 #include "Common.cpp"
     34#include "MiniBrowserReplace.h"
     35#include <WebKitLegacy/WebKitCOMAPI.h>
    3436
    3537int WINAPI wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPWSTR lpstrCmdLine, _In_ int nCmdShow)
     
    7577
    7678    if (requestedURL.length())
    77         loadURL(requestedURL.GetBSTR());
     79        gMainWindow->loadURL(requestedURL.GetBSTR());
    7880    else
    7981        gMiniBrowser->loadHTMLString(_bstr_t(defaultHTML).GetBSTR());
Note: See TracChangeset for help on using the changeset viewer.