Changeset 232577 in webkit


Ignore:
Timestamp:
Jun 7, 2018 12:32:00 AM (6 years ago)
Author:
Fujii Hironori
Message:

[Win][MiniBrowser] Support multiple windows properly
https://bugs.webkit.org/show_bug.cgi?id=186263

Reviewed by Ryosuke Niwa.

The current implementation of
PrintWebUIDelegate::createWebViewWithRequest is wrong. It is using
CreateProcess to open a new window, and doesn't return the new
instance of IWebView. As the result, for example, window.close
doesn't work as expected.

In this change, a new MainWindow is created and return the
IWebView in PrintWebUIDelegate::createWebViewWithRequest.

In addition to it, this change unifies the lifetime of MiniBrowser
and its delegates AccessibilityDelegate, PrintWebUIDelegate,
ResourceLoadDelegate and WebDownloadDelegate in order to keep
MiniBrowser alive as long as the delegates live. Because the
window of webview keeps references of such delegates and accesses
those after MiniBrowser destruction.

  • MiniBrowser/win/MainWindow.h: Added s_numInstances class member

to count the number of instance to close the application. Do not
use unique_ptr for m_browserWindow because it has ref count now.

  • MiniBrowser/win/MainWindow.cpp:

(MainWindow::MainWindow): Increment s_numInstances.
(MainWindow::~MainWindow): Decrement s_numInstances.
(MainWindow::create):
(MainWindow::init):
(MainWindow::WndProc): Rename thiz to thisWindow. Keep this
instance alive during this function by using RefPtr<MainWindow>.
Deref the MainWindow instance on WM_DESTROY. Quit the application
when the last MainWindow is closed.
(MainWindow::cachesDialogProc): Rename thiz to thisWindow.
(MainWindow::customUserAgentDialogProc): Ditto.

  • MiniBrowser/win/MiniBrowser.h: Added declarations AddRef and Release.
  • MiniBrowser/win/MiniBrowser.cpp:

(MiniBrowser::create):
(MiniBrowser::AddRef):
(MiniBrowser::Release):
(MiniBrowser::init): Passes this to the constructors of delegates.

  • MiniBrowser/win/AccessibilityDelegate.cpp:

(AccessibilityDelegate::AddRef): Delegate to MiniBrowser.
(AccessibilityDelegate::Release): Ditto.

  • MiniBrowser/win/AccessibilityDelegate.h: Removed m_refCount.

(AccessibilityDelegate::AccessibilityDelegate):

  • MiniBrowser/win/MiniBrowserWebHost.cpp:

(MiniBrowserWebHost::AddRef): Delegate to MiniBrowser.
(MiniBrowserWebHost::Release): Ditto.

  • MiniBrowser/win/MiniBrowserWebHost.h: Removed m_refCount.
  • MiniBrowser/win/PrintWebUIDelegate.cpp:

(PrintWebUIDelegate::createWebViewWithRequest): Create a new
MainWindow and return the IWebView.
(PrintWebUIDelegate::AddRef): Delegate to MiniBrowser.
(PrintWebUIDelegate::Release): Ditto.

  • MiniBrowser/win/PrintWebUIDelegate.h: Removed m_refCount.

(PrintWebUIDelegate::PrintWebUIDelegate):

  • MiniBrowser/win/ResourceLoadDelegate.cpp:

(ResourceLoadDelegate::AddRef): Delegate to MiniBrowser.
(ResourceLoadDelegate::Release): Ditto.

  • MiniBrowser/win/ResourceLoadDelegate.h: Removed m_refCount.
  • MiniBrowser/win/WebDownloadDelegate.cpp:

(WebDownloadDelegate::WebDownloadDelegate):
(WebDownloadDelegate::AddRef): Delegate to MiniBrowser.
(WebDownloadDelegate::Release): Ditto.

  • MiniBrowser/win/WebDownloadDelegate.h: Removed m_refCount.
Location:
trunk/Tools
Files:
16 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r232574 r232577  
     12018-06-07  Fujii Hironori  <Hironori.Fujii@sony.com>
     2
     3        [Win][MiniBrowser] Support multiple windows properly
     4        https://bugs.webkit.org/show_bug.cgi?id=186263
     5
     6        Reviewed by Ryosuke Niwa.
     7
     8        The current implementation of
     9        PrintWebUIDelegate::createWebViewWithRequest is wrong. It is using
     10        CreateProcess to open a new window, and doesn't return the new
     11        instance of IWebView. As the result, for example, window.close
     12        doesn't work as expected.
     13
     14        In this change, a new MainWindow is created and return the
     15        IWebView in PrintWebUIDelegate::createWebViewWithRequest.
     16
     17        In addition to it, this change unifies the lifetime of MiniBrowser
     18        and its delegates AccessibilityDelegate, PrintWebUIDelegate,
     19        ResourceLoadDelegate and WebDownloadDelegate in order to keep
     20        MiniBrowser alive as long as the delegates live. Because the
     21        window of webview keeps references of such delegates and accesses
     22        those after MiniBrowser destruction.
     23
     24        * MiniBrowser/win/MainWindow.h: Added s_numInstances class member
     25        to count the number of instance to close the application. Do not
     26        use unique_ptr for m_browserWindow because it has ref count now.
     27        * MiniBrowser/win/MainWindow.cpp:
     28        (MainWindow::MainWindow): Increment s_numInstances.
     29        (MainWindow::~MainWindow): Decrement s_numInstances.
     30        (MainWindow::create):
     31        (MainWindow::init):
     32        (MainWindow::WndProc): Rename thiz to thisWindow. Keep this
     33        instance alive during this function by using RefPtr<MainWindow>.
     34        Deref the MainWindow instance on WM_DESTROY. Quit the application
     35        when the last MainWindow is closed.
     36        (MainWindow::cachesDialogProc): Rename thiz to thisWindow.
     37        (MainWindow::customUserAgentDialogProc): Ditto.
     38        * MiniBrowser/win/MiniBrowser.h: Added declarations AddRef and Release.
     39        * MiniBrowser/win/MiniBrowser.cpp:
     40        (MiniBrowser::create):
     41        (MiniBrowser::AddRef):
     42        (MiniBrowser::Release):
     43        (MiniBrowser::init): Passes this to the constructors of delegates.
     44        * MiniBrowser/win/AccessibilityDelegate.cpp:
     45        (AccessibilityDelegate::AddRef): Delegate to MiniBrowser.
     46        (AccessibilityDelegate::Release): Ditto.
     47        * MiniBrowser/win/AccessibilityDelegate.h: Removed m_refCount.
     48        (AccessibilityDelegate::AccessibilityDelegate):
     49        * MiniBrowser/win/MiniBrowserWebHost.cpp:
     50        (MiniBrowserWebHost::AddRef): Delegate to MiniBrowser.
     51        (MiniBrowserWebHost::Release): Ditto.
     52        * MiniBrowser/win/MiniBrowserWebHost.h: Removed m_refCount.
     53        * MiniBrowser/win/PrintWebUIDelegate.cpp:
     54        (PrintWebUIDelegate::createWebViewWithRequest): Create a new
     55        MainWindow and return the IWebView.
     56        (PrintWebUIDelegate::AddRef): Delegate to MiniBrowser.
     57        (PrintWebUIDelegate::Release): Ditto.
     58        * MiniBrowser/win/PrintWebUIDelegate.h: Removed m_refCount.
     59        (PrintWebUIDelegate::PrintWebUIDelegate):
     60        * MiniBrowser/win/ResourceLoadDelegate.cpp:
     61        (ResourceLoadDelegate::AddRef): Delegate to MiniBrowser.
     62        (ResourceLoadDelegate::Release): Ditto.
     63        * MiniBrowser/win/ResourceLoadDelegate.h: Removed m_refCount.
     64        * MiniBrowser/win/WebDownloadDelegate.cpp:
     65        (WebDownloadDelegate::WebDownloadDelegate):
     66        (WebDownloadDelegate::AddRef): Delegate to MiniBrowser.
     67        (WebDownloadDelegate::Release): Ditto.
     68        * MiniBrowser/win/WebDownloadDelegate.h: Removed m_refCount.
     69
    1702018-06-06  Fujii Hironori  <Hironori.Fujii@sony.com>
    271
  • trunk/Tools/MiniBrowser/win/AccessibilityDelegate.cpp

    r222194 r232577  
    2727#include "AccessibilityDelegate.h"
    2828
     29#include "MiniBrowser.h"
    2930#include <WebKitLegacy/WebKitCOMAPI.h>
    3031#include <commctrl.h>
     
    5354ULONG AccessibilityDelegate::AddRef()
    5455{
    55     return ++m_refCount;
     56    return m_client.AddRef();
    5657}
    5758
    5859ULONG AccessibilityDelegate::Release()
    5960{
    60     ULONG newRef = --m_refCount;
    61     if (!newRef)
    62         delete this;
    63 
    64     return newRef;
     61    return m_client.Release();
    6562}
    6663
  • trunk/Tools/MiniBrowser/win/AccessibilityDelegate.h

    r222194 r232577  
    2929#include <WebKitLegacy/WebKit.h>
    3030
     31class MiniBrowser;
     32
    3133class AccessibilityDelegate : public IAccessibilityDelegate {
    3234public:
    33     AccessibilityDelegate() { }
     35    AccessibilityDelegate(MiniBrowser& client)
     36        : m_client(client) { }
    3437    virtual HRESULT STDMETHODCALLTYPE QueryInterface(_In_ REFIID riid, _COM_Outptr_ void** ppvObject);
    3538    virtual ULONG STDMETHODCALLTYPE AddRef();
     
    3942    virtual HRESULT STDMETHODCALLTYPE fireFrameLoadFinishedEvents();
    4043private:
    41     int m_refCount { 1 };
     44    MiniBrowser& m_client;
    4245};
    4346
  • trunk/Tools/MiniBrowser/win/MainWindow.cpp

    r232574 r232577  
    2828
    2929#include "Common.h"
    30 #include "MiniBrowser.h"
    3130#include "MiniBrowserLibResource.h"
    3231
     
    4342
    4443std::wstring MainWindow::s_windowClass;
     44size_t MainWindow::s_numInstances;
    4545
    4646static std::wstring loadString(int id)
     
    7878}
    7979
     80MainWindow::MainWindow()
     81{
     82    s_numInstances++;
     83}
     84
     85MainWindow::~MainWindow()
     86{
     87    s_numInstances--;
     88}
     89
     90Ref<MainWindow> MainWindow::create()
     91{
     92    return adoptRef(*new MainWindow());
     93}
     94
    8095bool MainWindow::init(HINSTANCE hInstance, bool usesLayeredWebView, bool pageLoadTesting)
    8196{
     
    98113    SetWindowLongPtr(m_hURLBarWnd, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(EditProc));
    99114
    100     m_browserWindow = std::make_unique<MiniBrowser>(m_hMainWnd, m_hURLBarWnd, usesLayeredWebView, pageLoadTesting);
     115    m_browserWindow = MiniBrowser::create(m_hMainWnd, m_hURLBarWnd, usesLayeredWebView, pageLoadTesting);
    101116    if (!m_browserWindow)
    102117        return false;
     
    134149LRESULT CALLBACK MainWindow::WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
    135150{
    136     MainWindow& thiz = *reinterpret_cast<MainWindow*>(GetWindowLongPtr(hWnd, GWLP_USERDATA));
     151    RefPtr<MainWindow> thisWindow = reinterpret_cast<MainWindow*>(GetWindowLongPtr(hWnd, GWLP_USERDATA));
    137152    switch (message) {
    138153    case WM_CREATE:
     
    150165        }
    151166        if (wmId >= IDM_HISTORY_LINK0 && wmId <= IDM_HISTORY_LINK9) {
    152             thiz.browserWindow()->navigateToHistory(hWnd, wmId);
     167            thisWindow->browserWindow()->navigateToHistory(hWnd, wmId);
    153168            break;
    154169        }
     
    156171        switch (wmId) {
    157172        case IDC_URL_BAR:
    158             thiz.onURLBarEnter();
     173            thisWindow->onURLBarEnter();
    159174            break;
    160175        case IDM_ABOUT:
     
    165180            break;
    166181        case IDM_PRINT:
    167             thiz.browserWindow()->print();
     182            thisWindow->browserWindow()->print();
    168183            break;
    169184        case IDM_WEB_INSPECTOR:
    170             thiz.browserWindow()->launchInspector();
     185            thisWindow->browserWindow()->launchInspector();
    171186            break;
    172187        case IDM_CACHES:
    173             if (!::IsWindow(thiz.m_hCacheWnd)) {
    174                 thiz.m_hCacheWnd = CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_CACHES), hWnd, cachesDialogProc, reinterpret_cast<LPARAM>(&thiz));
    175                 ::ShowWindow(thiz.m_hCacheWnd, SW_SHOW);
     188            if (!::IsWindow(thisWindow->m_hCacheWnd)) {
     189                thisWindow->m_hCacheWnd = CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_CACHES), hWnd, cachesDialogProc, reinterpret_cast<LPARAM>(thisWindow.get()));
     190                ::ShowWindow(thisWindow->m_hCacheWnd, SW_SHOW);
    176191            }
    177192            break;
    178193        case IDM_HISTORY_BACKWARD:
    179194        case IDM_HISTORY_FORWARD:
    180             thiz.browserWindow()->navigateForwardOrBackward(hWnd, wmId);
     195            thisWindow->browserWindow()->navigateForwardOrBackward(hWnd, wmId);
    181196            break;
    182197        case IDM_UA_OTHER:
    183             DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_USER_AGENT), hWnd, customUserAgentDialogProc, reinterpret_cast<LPARAM>(&thiz));
     198            DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_USER_AGENT), hWnd, customUserAgentDialogProc, reinterpret_cast<LPARAM>(thisWindow.get()));
    184199            break;
    185200        case IDM_ACTUAL_SIZE:
    186             thiz.browserWindow()->resetZoom();
     201            thisWindow->browserWindow()->resetZoom();
    187202            break;
    188203        case IDM_ZOOM_IN:
    189             thiz.browserWindow()->zoomIn();
     204            thisWindow->browserWindow()->zoomIn();
    190205            break;
    191206        case IDM_ZOOM_OUT:
    192             thiz.browserWindow()->zoomOut();
     207            thisWindow->browserWindow()->zoomOut();
    193208            break;
    194209        case IDM_SHOW_LAYER_TREE:
    195             thiz.browserWindow()->showLayerTree();
     210            thisWindow->browserWindow()->showLayerTree();
    196211            break;
    197212        default:
    198             if (!thiz.toggleMenuItem(wmId))
     213            if (!thisWindow->toggleMenuItem(wmId))
    199214                return DefWindowProc(hWnd, message, wParam, lParam);
    200215        }
     
    202217        break;
    203218    case WM_DESTROY:
     219        SetWindowLongPtr(hWnd, GWLP_USERDATA, 0);
     220        thisWindow->deref();
     221        if (s_numInstances > 1)
     222            return 0;
    204223#if USE(CF)
    205224        CFRunLoopStop(CFRunLoopGetMain());
     
    208227        break;
    209228    case WM_SIZE:
    210         thiz.resizeSubViews();
     229        thisWindow->resizeSubViews();
    211230        break;
    212231    case WM_DPICHANGED:
    213         thiz.browserWindow()->updateDeviceScaleFactor();
     232        thisWindow->browserWindow()->updateDeviceScaleFactor();
    214233        return DefWindowProc(hWnd, message, wParam, lParam);
    215234    default:
     
    317336INT_PTR CALLBACK MainWindow::cachesDialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
    318337{
    319     MainWindow& thiz = *reinterpret_cast<MainWindow*>(GetWindowLongPtr(hDlg, DWLP_USER));
     338    MainWindow& thisWindow = *reinterpret_cast<MainWindow*>(GetWindowLongPtr(hDlg, DWLP_USER));
    320339    switch (message) {
    321340    case WM_INITDIALOG:
     
    328347            ::KillTimer(hDlg, IDT_UPDATE_STATS);
    329348            ::DestroyWindow(hDlg);
    330             thiz.m_hCacheWnd = 0;
     349            thisWindow.m_hCacheWnd = 0;
    331350            return (INT_PTR)TRUE;
    332351        }
     
    338357
    339358    case WM_PAINT:
    340         thiz.browserWindow()->updateStatistics(hDlg);
     359        thisWindow.browserWindow()->updateStatistics(hDlg);
    341360        break;
    342361    }
     
    347366INT_PTR CALLBACK MainWindow::customUserAgentDialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
    348367{
    349     MainWindow& thiz = *reinterpret_cast<MainWindow*>(GetWindowLongPtr(hDlg, DWLP_USER));
     368    MainWindow& thisWindow = *reinterpret_cast<MainWindow*>(GetWindowLongPtr(hDlg, DWLP_USER));
    350369    switch (message) {
    351370    case WM_INITDIALOG: {
    352         MainWindow& thiz = *reinterpret_cast<MainWindow*>(lParam);
     371        MainWindow& thisWindow = *reinterpret_cast<MainWindow*>(lParam);
    353372        SetWindowLongPtr(hDlg, DWLP_USER, lParam);
    354373        HWND edit = ::GetDlgItem(hDlg, IDC_USER_AGENT_INPUT);
    355374        _bstr_t userAgent;
    356         userAgent = thiz.browserWindow()->userAgent();
     375        userAgent = thisWindow.browserWindow()->userAgent();
    357376
    358377        ::SetWindowText(edit, static_cast<LPCTSTR>(userAgent));
     
    370389            _bstr_t bstr(buffer);
    371390            if (bstr.length()) {
    372                 thiz.browserWindow()->setUserAgent(bstr);
    373                 thiz.toggleMenuItem(IDM_UA_OTHER);
     391                thisWindow.browserWindow()->setUserAgent(bstr);
     392                thisWindow.toggleMenuItem(IDM_UA_OTHER);
    374393            }
    375394        }
  • trunk/Tools/MiniBrowser/win/MainWindow.h

    r232574 r232577  
    2626#pragma once
    2727
     28#include "MiniBrowser.h"
    2829#include <memory>
    2930#include <string>
     31#include <wtf/RefPtr.h>
    3032
    31 class MiniBrowser;
     33class MainWindow : public RefCounted<MainWindow> {
     34public:
     35    static Ref<MainWindow> create();
    3236
    33 class MainWindow {
    34 public:
     37    ~MainWindow();
    3538    bool init(HINSTANCE hInstance, bool usesLayeredWebView = false, bool pageLoadTesting = false);
    3639
     
    4750    static void registerClass(HINSTANCE hInstance);
    4851    static std::wstring s_windowClass;
     52    static size_t s_numInstances;
    4953
     54    MainWindow();
    5055    bool toggleMenuItem(UINT menuID);
    5156    void onURLBarEnter();
     
    5661    HWND m_hForwardButtonWnd { nullptr };
    5762    HWND m_hCacheWnd { nullptr };
    58     std::unique_ptr<MiniBrowser> m_browserWindow;
     63    RefPtr<MiniBrowser> m_browserWindow;
    5964};
  • trunk/Tools/MiniBrowser/win/MiniBrowser.cpp

    r232270 r232577  
    6161typedef _com_ptr_t<_com_IIID<IWebMutableURLRequest, &__uuidof(IWebMutableURLRequest)>> IWebMutableURLRequestPtr;
    6262
     63Ref<MiniBrowser> MiniBrowser::create(HWND mainWnd, HWND urlBarWnd, bool useLayeredWebView, bool pageLoadTesting)
     64{
     65    return adoptRef(*new MiniBrowser(mainWnd, urlBarWnd, useLayeredWebView, pageLoadTesting));
     66}
     67
    6368MiniBrowser::MiniBrowser(HWND mainWnd, HWND urlBarWnd, bool useLayeredWebView, bool pageLoadTesting)
    6469    : m_hMainWnd(mainWnd)
     
    6974}
    7075
     76ULONG MiniBrowser::AddRef()
     77{
     78    ref();
     79    return refCount();
     80}
     81
     82ULONG MiniBrowser::Release()
     83{
     84    auto count = refCount();
     85    deref();
     86    return --count;
     87}
     88
    7189HRESULT MiniBrowser::init()
    7290{
     
    112130        return hr;
    113131
    114     hr = setUIDelegate(new PrintWebUIDelegate());
     132    hr = setUIDelegate(new PrintWebUIDelegate(*this));
    115133    if (FAILED (hr))
    116134        return hr;
    117135
    118     hr = setAccessibilityDelegate(new AccessibilityDelegate());
     136    hr = setAccessibilityDelegate(new AccessibilityDelegate(*this));
    119137    if (FAILED (hr))
    120138        return hr;
     
    125143
    126144    IWebDownloadDelegatePtr downloadDelegate;
    127     downloadDelegate.Attach(new WebDownloadDelegate());
     145    downloadDelegate.Attach(new WebDownloadDelegate(*this));
    128146    hr = setDownloadDelegate(downloadDelegate);
    129147    if (FAILED(hr))
  • trunk/Tools/MiniBrowser/win/MiniBrowser.h

    r232333 r232577  
    3030#include <memory>
    3131#include <vector>
     32#include <wtf/RefCounted.h>
    3233
    3334typedef _com_ptr_t<_com_IIID<IWebFrame, &__uuidof(IWebFrame)>> IWebFramePtr;
     
    4849typedef _com_ptr_t<_com_IIID<IWebFramePrivate, &__uuidof(IWebFramePrivate)>> IWebFramePrivatePtr;
    4950
    50 class MiniBrowser {
     51class MiniBrowser : public RefCounted<MiniBrowser> {
    5152public:
    52     MiniBrowser(HWND mainWnd, HWND urlBarWnd, bool useLayeredWebView = false, bool pageLoadTesting = false);
     53    static Ref<MiniBrowser> create(HWND mainWnd, HWND urlBarWnd, bool useLayeredWebView = false, bool pageLoadTesting = false);
     54
     55    ULONG AddRef();
     56    ULONG Release();
    5357
    5458    HRESULT init();
     
    108112
    109113private:
     114    MiniBrowser(HWND mainWnd, HWND urlBarWnd, bool useLayeredWebView, bool pageLoadTesting);
    110115    void subclassForLayeredWindow();
    111116    void generateFontForScaleFactor(float);
  • trunk/Tools/MiniBrowser/win/MiniBrowserWebHost.cpp

    r232270 r232577  
    131131ULONG MiniBrowserWebHost::AddRef()
    132132{
    133     return ++m_refCount;
     133    return m_client->AddRef();
    134134}
    135135
    136136ULONG MiniBrowserWebHost::Release()
    137137{
    138     ULONG newRef = --m_refCount;
    139     if (!newRef)
    140         delete(this);
    141 
    142     return newRef;
     138    return m_client->Release();
    143139}
    144140
  • trunk/Tools/MiniBrowser/win/MiniBrowserWebHost.h

    r222194 r232577  
    8181    HGDIOBJ m_URLBarFont { 0 };
    8282    HGDIOBJ m_oldFont { 0 };
    83     ULONG m_refCount { 1 };
    8483    MiniBrowser* m_client { nullptr };
    8584};
  • trunk/Tools/MiniBrowser/win/PrintWebUIDelegate.cpp

    r222194 r232577  
    2828#include "PrintWebUIDelegate.h"
    2929
     30#include "Common.h"
     31#include "MainWindow.h"
    3032#if USE(CF)
    3133#include <CoreFoundation/CoreFoundation.h>
     
    6264        return E_POINTER;
    6365
    64     TCHAR executablePath[MAX_PATH];
    65     DWORD length = ::GetModuleFileName(GetModuleHandle(0), executablePath, ARRAYSIZE(executablePath));
    66     if (!length)
    67         return E_FAIL;
    68 
    69     _bstr_t url;
    70     HRESULT hr = request->URL(&url.GetBSTR());
    71     if (FAILED(hr))
    72         return E_FAIL;
    73 
    74     if (!url)
    75         return S_OK;
    76 
    77     std::wstring command = std::wstring(L"\"") + executablePath + L"\" " + (const wchar_t*)url;
    78 
    79     PROCESS_INFORMATION processInformation;
    80     STARTUPINFOW startupInfo;
    81     memset(&startupInfo, 0, sizeof(startupInfo));
    82     if (!::CreateProcessW(0, (LPWSTR)command.c_str(), 0, 0, 0, 0, 0, 0, &startupInfo, &processInformation))
    83         return E_FAIL;
     66    auto& newWindow = MainWindow::create().leakRef();
     67    bool ok = newWindow.init(hInst);
     68    if (!ok)
     69        return E_FAIL;
     70    ShowWindow(newWindow.hwnd(), SW_SHOW);
     71
     72    *newWebView = newWindow.browserWindow()->webView();
     73    IWebFramePtr frame;
     74    HRESULT hr;
     75    hr = (*newWebView)->mainFrame(&frame.GetInterfacePtr());
     76    if (FAILED(hr))
     77        return hr;
     78    hr = frame->loadRequest(request);
     79    if (FAILED(hr))
     80        return hr;
    8481
    8582    return S_OK;
     
    152149ULONG PrintWebUIDelegate::AddRef()
    153150{
    154     return ++m_refCount;
     151    return m_client.AddRef();
    155152}
    156153
    157154ULONG PrintWebUIDelegate::Release()
    158155{
    159     ULONG newRef = --m_refCount;
    160     if (!newRef)
    161         delete this;
    162 
    163     return newRef;
     156    return m_client.Release();
    164157}
    165158
  • trunk/Tools/MiniBrowser/win/PrintWebUIDelegate.h

    r222194 r232577  
    3030#include <WebKitLegacy/WebKit.h>
    3131
     32class MiniBrowser;
     33
    3234class PrintWebUIDelegate : public IWebUIDelegate {
    3335public:
    34     PrintWebUIDelegate() { }
     36    PrintWebUIDelegate(MiniBrowser& client)
     37        : m_client(client) { }
    3538
    3639    // IUnknown
     
    104107
    105108private:
    106     int m_refCount { 1 };
     109    MiniBrowser& m_client;
    107110    HWND m_modalDialogParent { nullptr };
    108111};
  • trunk/Tools/MiniBrowser/win/ResourceLoadDelegate.cpp

    r232574 r232577  
    5757ULONG ResourceLoadDelegate::AddRef()
    5858{
    59     return ++m_refCount;
     59    return m_client->AddRef();
    6060}
    6161
    6262ULONG ResourceLoadDelegate::Release()
    6363{
    64     ULONG newRef = --m_refCount;
    65     if (!newRef)
    66         delete this;
    67 
    68     return newRef;
     64    return m_client->Release();
    6965}
    7066
  • trunk/Tools/MiniBrowser/win/ResourceLoadDelegate.h

    r222194 r232577  
    5454private:
    5555    MiniBrowser* m_client;
    56     int m_refCount { 1 };
    5756};
    5857
  • trunk/Tools/MiniBrowser/win/WebDownloadDelegate.cpp

    r204892 r232577  
    2929#include "WebDownloadDelegate.h"
    3030
     31#include "MiniBrowser.h"
    3132#include <shlobj.h>
    3233
    33 WebDownloadDelegate::WebDownloadDelegate()
     34WebDownloadDelegate::WebDownloadDelegate(MiniBrowser& client)
     35    : m_client(client)
    3436{
    3537}
     
    5860ULONG WebDownloadDelegate::AddRef()
    5961{
    60     m_refCount++;
    61     return m_refCount;
     62    return m_client.AddRef();
    6263}
    6364
    6465ULONG WebDownloadDelegate::Release()
    6566{
    66     m_refCount--;
    67     int refCount = m_refCount;
    68     if (!refCount)
    69         delete this;
    70     return refCount;
     67    return m_client.Release();
    7168}
    7269
  • trunk/Tools/MiniBrowser/win/WebDownloadDelegate.h

    r222194 r232577  
    3030#include <WebKitLegacy/WebKitCOMAPI.h>
    3131
     32class MiniBrowser;
     33
    3234class WebDownloadDelegate : public IWebDownloadDelegate {
    3335public:
    34     WebDownloadDelegate();
     36    WebDownloadDelegate(MiniBrowser& client);
    3537    virtual ~WebDownloadDelegate();
    3638
     
    5355
    5456private:
    55     int m_refCount { 1 };
     57    MiniBrowser& m_client;
    5658};
    5759
  • trunk/Tools/MiniBrowser/win/WinMain.cpp

    r232574 r232577  
    6666    ::SetProcessDPIAware();
    6767
    68     auto mainWindow = new MainWindow();
    69     HRESULT hr = mainWindow->init(hInst, usesLayeredWebView, pageLoadTesting);
     68    auto& mainWindow = MainWindow::create().leakRef();
     69    HRESULT hr = mainWindow.init(hInst, usesLayeredWebView, pageLoadTesting);
    7070    if (FAILED(hr))
    7171        goto exit;
    7272
    73     ShowWindow(mainWindow->hwnd(), nCmdShow);
     73    ShowWindow(mainWindow.hwnd(), nCmdShow);
    7474
    7575    hAccelTable = LoadAccelerators(hInst, MAKEINTRESOURCE(IDC_MINIBROWSER));
    7676
    7777    if (requestedURL.length())
    78         mainWindow->loadURL(requestedURL.GetBSTR());
     78        mainWindow.loadURL(requestedURL.GetBSTR());
    7979    else
    80         mainWindow->browserWindow()->loadHTMLString(_bstr_t(defaultHTML).GetBSTR());
     80        mainWindow.browserWindow()->loadHTMLString(_bstr_t(defaultHTML).GetBSTR());
    8181
    8282#pragma warning(disable:4509)
Note: See TracChangeset for help on using the changeset viewer.