Diff
Modified: trunk/Tools/ChangeLog (232576 => 232577)
--- trunk/Tools/ChangeLog 2018-06-07 07:05:55 UTC (rev 232576)
+++ trunk/Tools/ChangeLog 2018-06-07 07:32:00 UTC (rev 232577)
@@ -1,3 +1,72 @@
+2018-06-07 Fujii Hironori <[email protected]>
+
+ [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.
+
2018-06-06 Fujii Hironori <[email protected]>
[Win][MiniBrowser] Remove gMainWindow global variable
Modified: trunk/Tools/MiniBrowser/win/AccessibilityDelegate.cpp (232576 => 232577)
--- trunk/Tools/MiniBrowser/win/AccessibilityDelegate.cpp 2018-06-07 07:05:55 UTC (rev 232576)
+++ trunk/Tools/MiniBrowser/win/AccessibilityDelegate.cpp 2018-06-07 07:32:00 UTC (rev 232577)
@@ -26,6 +26,7 @@
#include "stdafx.h"
#include "AccessibilityDelegate.h"
+#include "MiniBrowser.h"
#include <WebKitLegacy/WebKitCOMAPI.h>
#include <commctrl.h>
#include <commdlg.h>
@@ -52,16 +53,12 @@
ULONG AccessibilityDelegate::AddRef()
{
- return ++m_refCount;
+ return m_client.AddRef();
}
ULONG AccessibilityDelegate::Release()
{
- ULONG newRef = --m_refCount;
- if (!newRef)
- delete this;
-
- return newRef;
+ return m_client.Release();
}
HRESULT AccessibilityDelegate::fireFrameLoadStartedEvents()
Modified: trunk/Tools/MiniBrowser/win/AccessibilityDelegate.h (232576 => 232577)
--- trunk/Tools/MiniBrowser/win/AccessibilityDelegate.h 2018-06-07 07:05:55 UTC (rev 232576)
+++ trunk/Tools/MiniBrowser/win/AccessibilityDelegate.h 2018-06-07 07:32:00 UTC (rev 232577)
@@ -28,9 +28,12 @@
#include <WebKitLegacy/WebKit.h>
+class MiniBrowser;
+
class AccessibilityDelegate : public IAccessibilityDelegate {
public:
- AccessibilityDelegate() { }
+ AccessibilityDelegate(MiniBrowser& client)
+ : m_client(client) { }
virtual HRESULT STDMETHODCALLTYPE QueryInterface(_In_ REFIID riid, _COM_Outptr_ void** ppvObject);
virtual ULONG STDMETHODCALLTYPE AddRef();
virtual ULONG STDMETHODCALLTYPE Release();
@@ -38,7 +41,7 @@
virtual HRESULT STDMETHODCALLTYPE fireFrameLoadStartedEvents();
virtual HRESULT STDMETHODCALLTYPE fireFrameLoadFinishedEvents();
private:
- int m_refCount { 1 };
+ MiniBrowser& m_client;
};
#endif
Modified: trunk/Tools/MiniBrowser/win/MainWindow.cpp (232576 => 232577)
--- trunk/Tools/MiniBrowser/win/MainWindow.cpp 2018-06-07 07:05:55 UTC (rev 232576)
+++ trunk/Tools/MiniBrowser/win/MainWindow.cpp 2018-06-07 07:32:00 UTC (rev 232577)
@@ -27,7 +27,6 @@
#include "MainWindow.h"
#include "Common.h"
-#include "MiniBrowser.h"
#include "MiniBrowserLibResource.h"
namespace WebCore {
@@ -42,6 +41,7 @@
static INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM);
std::wstring MainWindow::s_windowClass;
+size_t MainWindow::s_numInstances;
static std::wstring loadString(int id)
{
@@ -77,6 +77,21 @@
RegisterClassEx(&wcex);
}
+MainWindow::MainWindow()
+{
+ s_numInstances++;
+}
+
+MainWindow::~MainWindow()
+{
+ s_numInstances--;
+}
+
+Ref<MainWindow> MainWindow::create()
+{
+ return adoptRef(*new MainWindow());
+}
+
bool MainWindow::init(HINSTANCE hInstance, bool usesLayeredWebView, bool pageLoadTesting)
{
registerClass(hInstance);
@@ -97,7 +112,7 @@
DefEditProc = reinterpret_cast<WNDPROC>(GetWindowLongPtr(m_hURLBarWnd, GWLP_WNDPROC));
SetWindowLongPtr(m_hURLBarWnd, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(EditProc));
- m_browserWindow = std::make_unique<MiniBrowser>(m_hMainWnd, m_hURLBarWnd, usesLayeredWebView, pageLoadTesting);
+ m_browserWindow = MiniBrowser::create(m_hMainWnd, m_hURLBarWnd, usesLayeredWebView, pageLoadTesting);
if (!m_browserWindow)
return false;
HRESULT hr = m_browserWindow->init();
@@ -133,7 +148,7 @@
LRESULT CALLBACK MainWindow::WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
- MainWindow& thiz = *reinterpret_cast<MainWindow*>(GetWindowLongPtr(hWnd, GWLP_USERDATA));
+ RefPtr<MainWindow> thisWindow = reinterpret_cast<MainWindow*>(GetWindowLongPtr(hWnd, GWLP_USERDATA));
switch (message) {
case WM_CREATE:
SetWindowLongPtr(hWnd, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(reinterpret_cast<LPCREATESTRUCT>(lParam)->lpCreateParams));
@@ -149,13 +164,13 @@
return DefWindowProc(hWnd, message, wParam, lParam);
}
if (wmId >= IDM_HISTORY_LINK0 && wmId <= IDM_HISTORY_LINK9) {
- thiz.browserWindow()->navigateToHistory(hWnd, wmId);
+ thisWindow->browserWindow()->navigateToHistory(hWnd, wmId);
break;
}
// Parse the menu selections:
switch (wmId) {
case IDC_URL_BAR:
- thiz.onURLBarEnter();
+ thisWindow->onURLBarEnter();
break;
case IDM_ABOUT:
DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
@@ -164,43 +179,47 @@
DestroyWindow(hWnd);
break;
case IDM_PRINT:
- thiz.browserWindow()->print();
+ thisWindow->browserWindow()->print();
break;
case IDM_WEB_INSPECTOR:
- thiz.browserWindow()->launchInspector();
+ thisWindow->browserWindow()->launchInspector();
break;
case IDM_CACHES:
- if (!::IsWindow(thiz.m_hCacheWnd)) {
- thiz.m_hCacheWnd = CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_CACHES), hWnd, cachesDialogProc, reinterpret_cast<LPARAM>(&thiz));
- ::ShowWindow(thiz.m_hCacheWnd, SW_SHOW);
+ if (!::IsWindow(thisWindow->m_hCacheWnd)) {
+ thisWindow->m_hCacheWnd = CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_CACHES), hWnd, cachesDialogProc, reinterpret_cast<LPARAM>(thisWindow.get()));
+ ::ShowWindow(thisWindow->m_hCacheWnd, SW_SHOW);
}
break;
case IDM_HISTORY_BACKWARD:
case IDM_HISTORY_FORWARD:
- thiz.browserWindow()->navigateForwardOrBackward(hWnd, wmId);
+ thisWindow->browserWindow()->navigateForwardOrBackward(hWnd, wmId);
break;
case IDM_UA_OTHER:
- DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_USER_AGENT), hWnd, customUserAgentDialogProc, reinterpret_cast<LPARAM>(&thiz));
+ DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_USER_AGENT), hWnd, customUserAgentDialogProc, reinterpret_cast<LPARAM>(thisWindow.get()));
break;
case IDM_ACTUAL_SIZE:
- thiz.browserWindow()->resetZoom();
+ thisWindow->browserWindow()->resetZoom();
break;
case IDM_ZOOM_IN:
- thiz.browserWindow()->zoomIn();
+ thisWindow->browserWindow()->zoomIn();
break;
case IDM_ZOOM_OUT:
- thiz.browserWindow()->zoomOut();
+ thisWindow->browserWindow()->zoomOut();
break;
case IDM_SHOW_LAYER_TREE:
- thiz.browserWindow()->showLayerTree();
+ thisWindow->browserWindow()->showLayerTree();
break;
default:
- if (!thiz.toggleMenuItem(wmId))
+ if (!thisWindow->toggleMenuItem(wmId))
return DefWindowProc(hWnd, message, wParam, lParam);
}
}
break;
case WM_DESTROY:
+ SetWindowLongPtr(hWnd, GWLP_USERDATA, 0);
+ thisWindow->deref();
+ if (s_numInstances > 1)
+ return 0;
#if USE(CF)
CFRunLoopStop(CFRunLoopGetMain());
#endif
@@ -207,10 +226,10 @@
PostQuitMessage(0);
break;
case WM_SIZE:
- thiz.resizeSubViews();
+ thisWindow->resizeSubViews();
break;
case WM_DPICHANGED:
- thiz.browserWindow()->updateDeviceScaleFactor();
+ thisWindow->browserWindow()->updateDeviceScaleFactor();
return DefWindowProc(hWnd, message, wParam, lParam);
default:
return DefWindowProc(hWnd, message, wParam, lParam);
@@ -316,7 +335,7 @@
INT_PTR CALLBACK MainWindow::cachesDialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
- MainWindow& thiz = *reinterpret_cast<MainWindow*>(GetWindowLongPtr(hDlg, DWLP_USER));
+ MainWindow& thisWindow = *reinterpret_cast<MainWindow*>(GetWindowLongPtr(hDlg, DWLP_USER));
switch (message) {
case WM_INITDIALOG:
SetWindowLongPtr(hDlg, DWLP_USER, lParam);
@@ -327,7 +346,7 @@
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) {
::KillTimer(hDlg, IDT_UPDATE_STATS);
::DestroyWindow(hDlg);
- thiz.m_hCacheWnd = 0;
+ thisWindow.m_hCacheWnd = 0;
return (INT_PTR)TRUE;
}
break;
@@ -337,7 +356,7 @@
return (INT_PTR)TRUE;
case WM_PAINT:
- thiz.browserWindow()->updateStatistics(hDlg);
+ thisWindow.browserWindow()->updateStatistics(hDlg);
break;
}
@@ -346,14 +365,14 @@
INT_PTR CALLBACK MainWindow::customUserAgentDialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
- MainWindow& thiz = *reinterpret_cast<MainWindow*>(GetWindowLongPtr(hDlg, DWLP_USER));
+ MainWindow& thisWindow = *reinterpret_cast<MainWindow*>(GetWindowLongPtr(hDlg, DWLP_USER));
switch (message) {
case WM_INITDIALOG: {
- MainWindow& thiz = *reinterpret_cast<MainWindow*>(lParam);
+ MainWindow& thisWindow = *reinterpret_cast<MainWindow*>(lParam);
SetWindowLongPtr(hDlg, DWLP_USER, lParam);
HWND edit = ::GetDlgItem(hDlg, IDC_USER_AGENT_INPUT);
_bstr_t userAgent;
- userAgent = thiz.browserWindow()->userAgent();
+ userAgent = thisWindow.browserWindow()->userAgent();
::SetWindowText(edit, static_cast<LPCTSTR>(userAgent));
return (INT_PTR)TRUE;
@@ -369,8 +388,8 @@
_bstr_t bstr(buffer);
if (bstr.length()) {
- thiz.browserWindow()->setUserAgent(bstr);
- thiz.toggleMenuItem(IDM_UA_OTHER);
+ thisWindow.browserWindow()->setUserAgent(bstr);
+ thisWindow.toggleMenuItem(IDM_UA_OTHER);
}
}
Modified: trunk/Tools/MiniBrowser/win/MainWindow.h (232576 => 232577)
--- trunk/Tools/MiniBrowser/win/MainWindow.h 2018-06-07 07:05:55 UTC (rev 232576)
+++ trunk/Tools/MiniBrowser/win/MainWindow.h 2018-06-07 07:32:00 UTC (rev 232577)
@@ -25,13 +25,16 @@
#pragma once
+#include "MiniBrowser.h"
#include <memory>
#include <string>
+#include <wtf/RefPtr.h>
-class MiniBrowser;
+class MainWindow : public RefCounted<MainWindow> {
+public:
+ static Ref<MainWindow> create();
-class MainWindow {
-public:
+ ~MainWindow();
bool init(HINSTANCE hInstance, bool usesLayeredWebView = false, bool pageLoadTesting = false);
void resizeSubViews();
@@ -46,7 +49,9 @@
static INT_PTR CALLBACK cachesDialogProc(HWND, UINT, WPARAM, LPARAM);
static void registerClass(HINSTANCE hInstance);
static std::wstring s_windowClass;
+ static size_t s_numInstances;
+ MainWindow();
bool toggleMenuItem(UINT menuID);
void onURLBarEnter();
@@ -55,5 +60,5 @@
HWND m_hBackButtonWnd { nullptr };
HWND m_hForwardButtonWnd { nullptr };
HWND m_hCacheWnd { nullptr };
- std::unique_ptr<MiniBrowser> m_browserWindow;
+ RefPtr<MiniBrowser> m_browserWindow;
};
Modified: trunk/Tools/MiniBrowser/win/MiniBrowser.cpp (232576 => 232577)
--- trunk/Tools/MiniBrowser/win/MiniBrowser.cpp 2018-06-07 07:05:55 UTC (rev 232576)
+++ trunk/Tools/MiniBrowser/win/MiniBrowser.cpp 2018-06-07 07:32:00 UTC (rev 232577)
@@ -60,6 +60,11 @@
typedef _com_ptr_t<_com_IIID<IWebMutableURLRequest, &__uuidof(IWebMutableURLRequest)>> IWebMutableURLRequestPtr;
+Ref<MiniBrowser> MiniBrowser::create(HWND mainWnd, HWND urlBarWnd, bool useLayeredWebView, bool pageLoadTesting)
+{
+ return adoptRef(*new MiniBrowser(mainWnd, urlBarWnd, useLayeredWebView, pageLoadTesting));
+}
+
MiniBrowser::MiniBrowser(HWND mainWnd, HWND urlBarWnd, bool useLayeredWebView, bool pageLoadTesting)
: m_hMainWnd(mainWnd)
, m_hURLBarWnd(urlBarWnd)
@@ -68,6 +73,19 @@
{
}
+ULONG MiniBrowser::AddRef()
+{
+ ref();
+ return refCount();
+}
+
+ULONG MiniBrowser::Release()
+{
+ auto count = refCount();
+ deref();
+ return --count;
+}
+
HRESULT MiniBrowser::init()
{
updateDeviceScaleFactor();
@@ -111,11 +129,11 @@
if (FAILED(hr))
return hr;
- hr = setUIDelegate(new PrintWebUIDelegate());
+ hr = setUIDelegate(new PrintWebUIDelegate(*this));
if (FAILED (hr))
return hr;
- hr = setAccessibilityDelegate(new AccessibilityDelegate());
+ hr = setAccessibilityDelegate(new AccessibilityDelegate(*this));
if (FAILED (hr))
return hr;
@@ -124,7 +142,7 @@
return hr;
IWebDownloadDelegatePtr downloadDelegate;
- downloadDelegate.Attach(new WebDownloadDelegate());
+ downloadDelegate.Attach(new WebDownloadDelegate(*this));
hr = setDownloadDelegate(downloadDelegate);
if (FAILED(hr))
return hr;
Modified: trunk/Tools/MiniBrowser/win/MiniBrowser.h (232576 => 232577)
--- trunk/Tools/MiniBrowser/win/MiniBrowser.h 2018-06-07 07:05:55 UTC (rev 232576)
+++ trunk/Tools/MiniBrowser/win/MiniBrowser.h 2018-06-07 07:32:00 UTC (rev 232577)
@@ -29,6 +29,7 @@
#include <comip.h>
#include <memory>
#include <vector>
+#include <wtf/RefCounted.h>
typedef _com_ptr_t<_com_IIID<IWebFrame, &__uuidof(IWebFrame)>> IWebFramePtr;
typedef _com_ptr_t<_com_IIID<IWebView, &__uuidof(IWebView)>> IWebViewPtr;
@@ -47,10 +48,13 @@
typedef _com_ptr_t<_com_IIID<IWebDownloadDelegate, &__uuidof(IWebDownloadDelegate)>> IWebDownloadDelegatePtr;
typedef _com_ptr_t<_com_IIID<IWebFramePrivate, &__uuidof(IWebFramePrivate)>> IWebFramePrivatePtr;
-class MiniBrowser {
+class MiniBrowser : public RefCounted<MiniBrowser> {
public:
- MiniBrowser(HWND mainWnd, HWND urlBarWnd, bool useLayeredWebView = false, bool pageLoadTesting = false);
+ static Ref<MiniBrowser> create(HWND mainWnd, HWND urlBarWnd, bool useLayeredWebView = false, bool pageLoadTesting = false);
+ ULONG AddRef();
+ ULONG Release();
+
HRESULT init();
HRESULT prepareViews(HWND mainWnd, const RECT& clientRect);
@@ -107,6 +111,7 @@
void setPreference(UINT menuID, bool enable);
private:
+ MiniBrowser(HWND mainWnd, HWND urlBarWnd, bool useLayeredWebView, bool pageLoadTesting);
void subclassForLayeredWindow();
void generateFontForScaleFactor(float);
bool setCacheFolder();
Modified: trunk/Tools/MiniBrowser/win/MiniBrowserWebHost.cpp (232576 => 232577)
--- trunk/Tools/MiniBrowser/win/MiniBrowserWebHost.cpp 2018-06-07 07:05:55 UTC (rev 232576)
+++ trunk/Tools/MiniBrowser/win/MiniBrowserWebHost.cpp 2018-06-07 07:32:00 UTC (rev 232577)
@@ -130,16 +130,12 @@
ULONG MiniBrowserWebHost::AddRef()
{
- return ++m_refCount;
+ return m_client->AddRef();
}
ULONG MiniBrowserWebHost::Release()
{
- ULONG newRef = --m_refCount;
- if (!newRef)
- delete(this);
-
- return newRef;
+ return m_client->Release();
}
typedef _com_ptr_t<_com_IIID<IDOMDocument, &__uuidof(IDOMDocument)>> IDOMDocumentPtr;
Modified: trunk/Tools/MiniBrowser/win/MiniBrowserWebHost.h (232576 => 232577)
--- trunk/Tools/MiniBrowser/win/MiniBrowserWebHost.h 2018-06-07 07:05:55 UTC (rev 232576)
+++ trunk/Tools/MiniBrowser/win/MiniBrowserWebHost.h 2018-06-07 07:32:00 UTC (rev 232577)
@@ -80,6 +80,5 @@
HWND m_hURLBarWnd { 0 };
HGDIOBJ m_URLBarFont { 0 };
HGDIOBJ m_oldFont { 0 };
- ULONG m_refCount { 1 };
MiniBrowser* m_client { nullptr };
};
Modified: trunk/Tools/MiniBrowser/win/PrintWebUIDelegate.cpp (232576 => 232577)
--- trunk/Tools/MiniBrowser/win/PrintWebUIDelegate.cpp 2018-06-07 07:05:55 UTC (rev 232576)
+++ trunk/Tools/MiniBrowser/win/PrintWebUIDelegate.cpp 2018-06-07 07:32:00 UTC (rev 232577)
@@ -27,6 +27,8 @@
#include "stdafx.h"
#include "PrintWebUIDelegate.h"
+#include "Common.h"
+#include "MainWindow.h"
#if USE(CF)
#include <CoreFoundation/CoreFoundation.h>
#endif
@@ -61,27 +63,22 @@
if (!request)
return E_POINTER;
- TCHAR executablePath[MAX_PATH];
- DWORD length = ::GetModuleFileName(GetModuleHandle(0), executablePath, ARRAYSIZE(executablePath));
- if (!length)
+ auto& newWindow = MainWindow::create().leakRef();
+ bool ok = newWindow.init(hInst);
+ if (!ok)
return E_FAIL;
+ ShowWindow(newWindow.hwnd(), SW_SHOW);
- _bstr_t url;
- HRESULT hr = request->URL(&url.GetBSTR());
+ *newWebView = newWindow.browserWindow()->webView();
+ IWebFramePtr frame;
+ HRESULT hr;
+ hr = (*newWebView)->mainFrame(&frame.GetInterfacePtr());
if (FAILED(hr))
- return E_FAIL;
+ return hr;
+ hr = frame->loadRequest(request);
+ if (FAILED(hr))
+ return hr;
- if (!url)
- return S_OK;
-
- std::wstring command = std::wstring(L"\"") + executablePath + L"\" " + (const wchar_t*)url;
-
- PROCESS_INFORMATION processInformation;
- STARTUPINFOW startupInfo;
- memset(&startupInfo, 0, sizeof(startupInfo));
- if (!::CreateProcessW(0, (LPWSTR)command.c_str(), 0, 0, 0, 0, 0, 0, &startupInfo, &processInformation))
- return E_FAIL;
-
return S_OK;
}
@@ -151,16 +148,12 @@
ULONG PrintWebUIDelegate::AddRef()
{
- return ++m_refCount;
+ return m_client.AddRef();
}
ULONG PrintWebUIDelegate::Release()
{
- ULONG newRef = --m_refCount;
- if (!newRef)
- delete this;
-
- return newRef;
+ return m_client.Release();
}
typedef _com_ptr_t<_com_IIID<IWebFrame, &__uuidof(IWebFrame)>> IWebFramePtr;
Modified: trunk/Tools/MiniBrowser/win/PrintWebUIDelegate.h (232576 => 232577)
--- trunk/Tools/MiniBrowser/win/PrintWebUIDelegate.h 2018-06-07 07:05:55 UTC (rev 232576)
+++ trunk/Tools/MiniBrowser/win/PrintWebUIDelegate.h 2018-06-07 07:32:00 UTC (rev 232577)
@@ -29,9 +29,12 @@
#include <WebKitLegacy/WebKit.h>
+class MiniBrowser;
+
class PrintWebUIDelegate : public IWebUIDelegate {
public:
- PrintWebUIDelegate() { }
+ PrintWebUIDelegate(MiniBrowser& client)
+ : m_client(client) { }
// IUnknown
virtual HRESULT STDMETHODCALLTYPE QueryInterface(_In_ REFIID riid, _COM_Outptr_ void** ppvObject);
@@ -103,7 +106,7 @@
virtual HRESULT STDMETHODCALLTYPE paintCustomScrollCorner(_In_opt_ IWebView*, _In_ HDC, RECT) { return E_NOTIMPL; }
private:
- int m_refCount { 1 };
+ MiniBrowser& m_client;
HWND m_modalDialogParent { nullptr };
};
Modified: trunk/Tools/MiniBrowser/win/ResourceLoadDelegate.cpp (232576 => 232577)
--- trunk/Tools/MiniBrowser/win/ResourceLoadDelegate.cpp 2018-06-07 07:05:55 UTC (rev 232576)
+++ trunk/Tools/MiniBrowser/win/ResourceLoadDelegate.cpp 2018-06-07 07:32:00 UTC (rev 232577)
@@ -56,16 +56,12 @@
ULONG ResourceLoadDelegate::AddRef()
{
- return ++m_refCount;
+ return m_client->AddRef();
}
ULONG ResourceLoadDelegate::Release()
{
- ULONG newRef = --m_refCount;
- if (!newRef)
- delete this;
-
- return newRef;
+ return m_client->Release();
}
HRESULT ResourceLoadDelegate::identifierForInitialRequest(_In_opt_ IWebView*, _In_opt_ IWebURLRequest*, _In_opt_ IWebDataSource*, unsigned long identifier)
Modified: trunk/Tools/MiniBrowser/win/ResourceLoadDelegate.h (232576 => 232577)
--- trunk/Tools/MiniBrowser/win/ResourceLoadDelegate.h 2018-06-07 07:05:55 UTC (rev 232576)
+++ trunk/Tools/MiniBrowser/win/ResourceLoadDelegate.h 2018-06-07 07:32:00 UTC (rev 232577)
@@ -53,7 +53,6 @@
private:
MiniBrowser* m_client;
- int m_refCount { 1 };
};
#endif // ResourceLoadDelegate
Modified: trunk/Tools/MiniBrowser/win/WebDownloadDelegate.cpp (232576 => 232577)
--- trunk/Tools/MiniBrowser/win/WebDownloadDelegate.cpp 2018-06-07 07:05:55 UTC (rev 232576)
+++ trunk/Tools/MiniBrowser/win/WebDownloadDelegate.cpp 2018-06-07 07:32:00 UTC (rev 232577)
@@ -28,9 +28,11 @@
#include "stdafx.h"
#include "WebDownloadDelegate.h"
+#include "MiniBrowser.h"
#include <shlobj.h>
-WebDownloadDelegate::WebDownloadDelegate()
+WebDownloadDelegate::WebDownloadDelegate(MiniBrowser& client)
+ : m_client(client)
{
}
@@ -57,17 +59,12 @@
ULONG WebDownloadDelegate::AddRef()
{
- m_refCount++;
- return m_refCount;
+ return m_client.AddRef();
}
ULONG WebDownloadDelegate::Release()
{
- m_refCount--;
- int refCount = m_refCount;
- if (!refCount)
- delete this;
- return refCount;
+ return m_client.Release();
}
HRESULT WebDownloadDelegate::decideDestinationWithSuggestedFilename(_In_opt_ IWebDownload* download, _In_ BSTR filename)
Modified: trunk/Tools/MiniBrowser/win/WebDownloadDelegate.h (232576 => 232577)
--- trunk/Tools/MiniBrowser/win/WebDownloadDelegate.h 2018-06-07 07:05:55 UTC (rev 232576)
+++ trunk/Tools/MiniBrowser/win/WebDownloadDelegate.h 2018-06-07 07:32:00 UTC (rev 232577)
@@ -29,9 +29,11 @@
#include <WebKitLegacy/WebKit.h>
#include <WebKitLegacy/WebKitCOMAPI.h>
+class MiniBrowser;
+
class WebDownloadDelegate : public IWebDownloadDelegate {
public:
- WebDownloadDelegate();
+ WebDownloadDelegate(MiniBrowser& client);
virtual ~WebDownloadDelegate();
virtual HRESULT STDMETHODCALLTYPE QueryInterface(_In_ REFIID riid, _COM_Outptr_ void** ppvObject);
@@ -52,7 +54,7 @@
virtual HRESULT STDMETHODCALLTYPE didFinish(_In_opt_ IWebDownload*);
private:
- int m_refCount { 1 };
+ MiniBrowser& m_client;
};
#endif
Modified: trunk/Tools/MiniBrowser/win/WinMain.cpp (232576 => 232577)
--- trunk/Tools/MiniBrowser/win/WinMain.cpp 2018-06-07 07:05:55 UTC (rev 232576)
+++ trunk/Tools/MiniBrowser/win/WinMain.cpp 2018-06-07 07:32:00 UTC (rev 232577)
@@ -65,19 +65,19 @@
::SetProcessDPIAware();
- auto mainWindow = new MainWindow();
- HRESULT hr = mainWindow->init(hInst, usesLayeredWebView, pageLoadTesting);
+ auto& mainWindow = MainWindow::create().leakRef();
+ HRESULT hr = mainWindow.init(hInst, usesLayeredWebView, pageLoadTesting);
if (FAILED(hr))
goto exit;
- ShowWindow(mainWindow->hwnd(), nCmdShow);
+ ShowWindow(mainWindow.hwnd(), nCmdShow);
hAccelTable = LoadAccelerators(hInst, MAKEINTRESOURCE(IDC_MINIBROWSER));
if (requestedURL.length())
- mainWindow->loadURL(requestedURL.GetBSTR());
+ mainWindow.loadURL(requestedURL.GetBSTR());
else
- mainWindow->browserWindow()->loadHTMLString(_bstr_t(defaultHTML).GetBSTR());
+ mainWindow.browserWindow()->loadHTMLString(_bstr_t(defaultHTML).GetBSTR());
#pragma warning(disable:4509)