Diff
Modified: trunk/Tools/ChangeLog (248989 => 248990)
--- trunk/Tools/ChangeLog 2019-08-22 01:42:22 UTC (rev 248989)
+++ trunk/Tools/ChangeLog 2019-08-22 01:49:48 UTC (rev 248990)
@@ -1,3 +1,37 @@
+2019-08-21 Fujii Hironori <[email protected]>
+
+ [Win][MiniBrowser] Add a progress indicator to the main window
+ https://bugs.webkit.org/show_bug.cgi?id=200970
+
+ Reviewed by Alex Christensen.
+
+ * MiniBrowser/win/BrowserWindow.h: Added BrowserWindowClient class.
+ * MiniBrowser/win/MainWindow.cpp:
+ (MainWindow::init):
+ (MainWindow::resizeSubViews):
+ (MainWindow::progressChanged):
+ (MainWindow::progressFinished):
+ * MiniBrowser/win/MainWindow.h: Inherited BrowserWindowClient.
+ Added m_hProgressIndicator.
+ (MainWindow::hwnd const): Deleted.
+ (MainWindow::browserWindow const): Deleted.
+ (): Deleted.
+ * MiniBrowser/win/MiniBrowserWebHost.cpp:
+ (MiniBrowserWebHost::onNotify):
+ * MiniBrowser/win/MiniBrowserWebHost.h:
+ * MiniBrowser/win/WebKitBrowserWindow.cpp:
+ (WebKitBrowserWindow::create):
+ (WebKitBrowserWindow::WebKitBrowserWindow):
+ (WebKitBrowserWindow::didChangeIsLoading):
+ (WebKitBrowserWindow::didChangeEstimatedProgress):
+ (WebKitBrowserWindow::createNewPage):
+ * MiniBrowser/win/WebKitBrowserWindow.h:
+ * MiniBrowser/win/WebKitLegacyBrowserWindow.cpp:
+ (WebKitLegacyBrowserWindow::create):
+ (WebKitLegacyBrowserWindow::WebKitLegacyBrowserWindow):
+ (WebKitLegacyBrowserWindow::init):
+ * MiniBrowser/win/WebKitLegacyBrowserWindow.h:
+
2019-08-21 Ryan Haddad <[email protected]>
Unreviewed, rolling out r248970.
Modified: trunk/Tools/MiniBrowser/win/BrowserWindow.h (248989 => 248990)
--- trunk/Tools/MiniBrowser/win/BrowserWindow.h 2019-08-22 01:42:22 UTC (rev 248989)
+++ trunk/Tools/MiniBrowser/win/BrowserWindow.h 2019-08-22 01:49:48 UTC (rev 248990)
@@ -28,6 +28,12 @@
#include <windows.h>
#include <wtf/RefCounted.h>
+class BrowserWindowClient {
+public:
+ virtual void progressChanged(double) = 0;
+ virtual void progressFinished() = 0;
+};
+
class BrowserWindow : public RefCounted<BrowserWindow> {
public:
virtual ~BrowserWindow() { };
Modified: trunk/Tools/MiniBrowser/win/MainWindow.cpp (248989 => 248990)
--- trunk/Tools/MiniBrowser/win/MainWindow.cpp 2019-08-22 01:42:22 UTC (rev 248989)
+++ trunk/Tools/MiniBrowser/win/MainWindow.cpp 2019-08-22 01:49:48 UTC (rev 248990)
@@ -30,6 +30,7 @@
#include "MiniBrowserLibResource.h"
#include "WebKitLegacyBrowserWindow.h"
#include <CoreFoundation/CoreFoundation.h>
+#include <sstream>
#if ENABLE(WEBKIT)
#include "WebKitBrowserWindow.h"
@@ -115,16 +116,16 @@
EnableMenuItem(GetMenu(m_hMainWnd), IDM_NEW_WEBKIT_WINDOW, MF_GRAYED);
#endif
- float scaleFactor = WebCore::deviceScaleFactorForWindow(nullptr);
m_hBackButtonWnd = CreateWindow(L"BUTTON", L"<", WS_CHILD | WS_VISIBLE | BS_TEXT, 0, 0, 0, 0, m_hMainWnd, reinterpret_cast<HMENU>(IDM_HISTORY_BACKWARD), hInstance, 0);
m_hForwardButtonWnd = CreateWindow(L"BUTTON", L">", WS_CHILD | WS_VISIBLE | BS_TEXT, 0, 0, 0, 0, m_hMainWnd, reinterpret_cast<HMENU>(IDM_HISTORY_FORWARD), hInstance, 0);
m_hReloadButtonWnd = CreateWindow(L"BUTTON", L"↺", WS_CHILD | WS_VISIBLE | BS_TEXT, 0, 0, 0, 0, m_hMainWnd, reinterpret_cast<HMENU>(IDM_RELOAD), hInstance, 0);
m_hURLBarWnd = CreateWindow(L"EDIT", 0, WS_CHILD | WS_VISIBLE | WS_BORDER | ES_LEFT | ES_AUTOVSCROLL, 0, 0, 0, 0, m_hMainWnd, 0, hInstance, 0);
+ m_hProgressIndicator = CreateWindow(L"STATIC", 0, WS_CHILD | WS_VISIBLE | WS_BORDER | SS_CENTER | SS_CENTERIMAGE, 0, 0, 0, 0, m_hMainWnd, 0, hInstance, 0);
DefEditProc = reinterpret_cast<WNDPROC>(GetWindowLongPtr(m_hURLBarWnd, GWLP_WNDPROC));
SetWindowLongPtr(m_hURLBarWnd, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(EditProc));
- m_browserWindow = factory(m_hMainWnd, m_hURLBarWnd, usesLayeredWebView);
+ m_browserWindow = factory(*this, m_hMainWnd, m_hURLBarWnd, usesLayeredWebView);
if (!m_browserWindow)
return false;
HRESULT hr = m_browserWindow->init();
@@ -150,7 +151,8 @@
MoveWindow(m_hBackButtonWnd, 0, 0, width, height, TRUE);
MoveWindow(m_hForwardButtonWnd, width, 0, width, height, TRUE);
MoveWindow(m_hReloadButtonWnd, width * 2, 0, width, height, TRUE);
- MoveWindow(m_hURLBarWnd, width * 3, 0, rcClient.right - width * 3, height, TRUE);
+ MoveWindow(m_hURLBarWnd, width * 3, 0, rcClient.right - width * 5, height, TRUE);
+ MoveWindow(m_hProgressIndicator, rcClient.right - width * 2, 0, width * 2, height, TRUE);
if (m_browserWindow->usesLayeredWebView() || !m_browserWindow->hwnd())
return;
@@ -473,3 +475,15 @@
OUT_TT_ONLY_PRECIS, CLIP_DEFAULT_PRECIS, CLEARTYPE_QUALITY, FF_DONTCARE, L"Tahoma");
::SendMessage(m_hURLBarWnd, static_cast<UINT>(WM_SETFONT), reinterpret_cast<WPARAM>(m_hURLBarFont), TRUE);
}
+
+void MainWindow::progressChanged(double progress)
+{
+ std::wostringstream text;
+ text << static_cast<int>(progress * 100) << L'%';
+ SetWindowText(m_hProgressIndicator, text.str().c_str());
+}
+
+void MainWindow::progressFinished()
+{
+ SetWindowText(m_hProgressIndicator, L"");
+}
Modified: trunk/Tools/MiniBrowser/win/MainWindow.h (248989 => 248990)
--- trunk/Tools/MiniBrowser/win/MainWindow.h 2019-08-22 01:42:22 UTC (rev 248989)
+++ trunk/Tools/MiniBrowser/win/MainWindow.h 2019-08-22 01:49:48 UTC (rev 248990)
@@ -31,9 +31,9 @@
#include <string>
#include <wtf/RefPtr.h>
-class MainWindow : public RefCounted<MainWindow> {
+class MainWindow final : public RefCounted<MainWindow>, public BrowserWindowClient {
public:
- using BrowserWindowFactory = std::function<Ref<BrowserWindow>(HWND mainWnd, HWND urlBarWnd, bool usesLayeredWebView)>;
+ using BrowserWindowFactory = std::function<Ref<BrowserWindow>(BrowserWindowClient&, HWND mainWnd, HWND urlBarWnd, bool usesLayeredWebView)>;
static Ref<MainWindow> create();
@@ -59,11 +59,16 @@
void onURLBarEnter();
void updateDeviceScaleFactor();
+ // BrowserWindowClient
+ void progressChanged(double) final;
+ void progressFinished() final;
+
HWND m_hMainWnd { nullptr };
HWND m_hURLBarWnd { nullptr };
HWND m_hBackButtonWnd { nullptr };
HWND m_hForwardButtonWnd { nullptr };
HWND m_hReloadButtonWnd { nullptr };
+ HWND m_hProgressIndicator { nullptr };
HWND m_hCacheWnd { nullptr };
HGDIOBJ m_hURLBarFont { nullptr };
RefPtr<BrowserWindow> m_browserWindow;
Modified: trunk/Tools/MiniBrowser/win/MiniBrowserWebHost.cpp (248989 => 248990)
--- trunk/Tools/MiniBrowser/win/MiniBrowserWebHost.cpp 2019-08-22 01:42:22 UTC (rev 248989)
+++ trunk/Tools/MiniBrowser/win/MiniBrowserWebHost.cpp 2019-08-22 01:49:48 UTC (rev 248990)
@@ -166,3 +166,28 @@
return S_OK;
}
+
+HRESULT MiniBrowserWebHost::onNotify(_In_opt_ IWebNotification* notification)
+{
+ _bstr_t name;
+ HRESULT hr = notification->name(name.GetAddress());
+ if (FAILED(hr))
+ return hr;
+ if (name == _bstr_t(WebViewProgressEstimateChangedNotification)) {
+ IUnknownPtr object;
+ hr = notification->getObject(&object.GetInterfacePtr());
+ if (FAILED(hr))
+ return hr;
+ IWebViewPtr webView(object);
+ if (!webView)
+ return E_NOINTERFACE;
+ double progress;
+ hr = webView->estimatedProgress(&progress);
+ if (FAILED(hr))
+ return hr;
+ m_client->m_client.progressChanged(progress);
+ } else if (name == _bstr_t(WebViewProgressFinishedNotification))
+ m_client->m_client.progressFinished();
+
+ return S_OK;
+}
Modified: trunk/Tools/MiniBrowser/win/MiniBrowserWebHost.h (248989 => 248990)
--- trunk/Tools/MiniBrowser/win/MiniBrowserWebHost.h 2019-08-22 01:42:22 UTC (rev 248989)
+++ trunk/Tools/MiniBrowser/win/MiniBrowserWebHost.h 2019-08-22 01:49:48 UTC (rev 248990)
@@ -31,7 +31,7 @@
class WebKitLegacyBrowserWindow;
-class MiniBrowserWebHost : public IWebFrameLoadDelegate, public IWebFrameLoadDelegatePrivate {
+class MiniBrowserWebHost : public IWebFrameLoadDelegate, public IWebFrameLoadDelegatePrivate, public IWebNotificationObserver {
public:
MiniBrowserWebHost(WebKitLegacyBrowserWindow* client, HWND urlBar)
: m_client(client), m_hURLBarWnd(urlBar) { }
@@ -71,6 +71,9 @@
virtual HRESULT STDMETHODCALLTYPE didHandleOnloadEventsForFrame(_In_opt_ IWebView*, _In_opt_ IWebFrame*);
virtual HRESULT STDMETHODCALLTYPE didFirstVisuallyNonEmptyLayoutInFrame(_In_opt_ IWebView* sender, _In_opt_ IWebFrame*) { return S_OK; }
+ // IWebNotificationObserver
+ virtual HRESULT STDMETHODCALLTYPE onNotify(_In_opt_ IWebNotification*);
+
void loadURL(_bstr_t&);
protected:
Modified: trunk/Tools/MiniBrowser/win/WebKitBrowserWindow.cpp (248989 => 248990)
--- trunk/Tools/MiniBrowser/win/WebKitBrowserWindow.cpp 2019-08-22 01:42:22 UTC (rev 248989)
+++ trunk/Tools/MiniBrowser/win/WebKitBrowserWindow.cpp 2019-08-22 01:49:48 UTC (rev 248990)
@@ -104,7 +104,7 @@
return adoptWK(WKURLCreateWithUTF8CString(utf8.data()));
}
-Ref<BrowserWindow> WebKitBrowserWindow::create(HWND mainWnd, HWND urlBarWnd, bool)
+Ref<BrowserWindow> WebKitBrowserWindow::create(BrowserWindowClient& client, HWND mainWnd, HWND urlBarWnd, bool)
{
auto conf = adoptWK(WKPageConfigurationCreate());
@@ -121,11 +121,12 @@
auto context =adoptWK(WKContextCreateWithConfiguration(nullptr));
WKPageConfigurationSetContext(conf.get(), context.get());
- return adoptRef(*new WebKitBrowserWindow(conf.get(), mainWnd, urlBarWnd));
+ return adoptRef(*new WebKitBrowserWindow(client, conf.get(), mainWnd, urlBarWnd));
}
-WebKitBrowserWindow::WebKitBrowserWindow(WKPageConfigurationRef conf, HWND mainWnd, HWND urlBarWnd)
- : m_hMainWnd(mainWnd)
+WebKitBrowserWindow::WebKitBrowserWindow(BrowserWindowClient& client, WKPageConfigurationRef conf, HWND mainWnd, HWND urlBarWnd)
+ : m_client(client)
+ , m_hMainWnd(mainWnd)
, m_urlBarWnd(urlBarWnd)
{
RECT rect = { };
@@ -152,6 +153,8 @@
stateClient.base.version = 0;
stateClient.base.clientInfo = this;
stateClient.didChangeTitle = didChangeTitle;
+ stateClient.didChangeIsLoading = didChangeIsLoading;
+ stateClient.didChangeEstimatedProgress = didChangeEstimatedProgress;
WKPageSetPageStateClient(page, &stateClient.base);
updateProxySettings();
@@ -308,6 +311,20 @@
SetWindowText(thisWindow.m_hMainWnd, titleString.c_str());
}
+void WebKitBrowserWindow::didChangeIsLoading(const void* clientInfo)
+{
+ auto& thisWindow = toWebKitBrowserWindow(clientInfo);
+ auto page = WKViewGetPage(thisWindow.m_view.get());
+ thisWindow.m_client.progressFinished();
+}
+
+void WebKitBrowserWindow::didChangeEstimatedProgress(const void* clientInfo)
+{
+ auto& thisWindow = toWebKitBrowserWindow(clientInfo);
+ auto page = WKViewGetPage(thisWindow.m_view.get());
+ thisWindow.m_client.progressChanged(WKPageGetEstimatedProgress(page));
+}
+
void WebKitBrowserWindow::didCommitNavigation(WKPageRef page, WKNavigationRef navigation, WKTypeRef userData, const void* clientInfo)
{
auto& thisWindow = toWebKitBrowserWindow(clientInfo);
@@ -367,8 +384,8 @@
WKPageRef WebKitBrowserWindow::createNewPage(WKPageRef page, WKPageConfigurationRef configuration, WKNavigationActionRef navigationAction, WKWindowFeaturesRef windowFeatures, const void *clientInfo)
{
auto& newWindow = MainWindow::create().leakRef();
- auto factory = [configuration](HWND mainWnd, HWND urlBarWnd, bool) -> auto {
- return adoptRef(*new WebKitBrowserWindow(configuration, mainWnd, urlBarWnd));
+ auto factory = [configuration](BrowserWindowClient& client, HWND mainWnd, HWND urlBarWnd, bool) -> auto {
+ return adoptRef(*new WebKitBrowserWindow(client, configuration, mainWnd, urlBarWnd));
};
bool ok = newWindow.init(factory, hInst);
if (!ok)
Modified: trunk/Tools/MiniBrowser/win/WebKitBrowserWindow.h (248989 => 248990)
--- trunk/Tools/MiniBrowser/win/WebKitBrowserWindow.h 2019-08-22 01:42:22 UTC (rev 248989)
+++ trunk/Tools/MiniBrowser/win/WebKitBrowserWindow.h 2019-08-22 01:49:48 UTC (rev 248990)
@@ -33,10 +33,10 @@
class WebKitBrowserWindow : public BrowserWindow {
public:
- static Ref<BrowserWindow> create(HWND mainWnd, HWND urlBarWnd, bool useLayeredWebView = false);
+ static Ref<BrowserWindow> create(BrowserWindowClient&, HWND mainWnd, HWND urlBarWnd, bool useLayeredWebView = false);
private:
- WebKitBrowserWindow(WKPageConfigurationRef, HWND mainWnd, HWND urlBarWnd);
+ WebKitBrowserWindow(BrowserWindowClient&, WKPageConfigurationRef, HWND mainWnd, HWND urlBarWnd);
HRESULT init() override;
HWND hwnd() override;
@@ -66,11 +66,14 @@
bool canTrustServerCertificate(WKProtectionSpaceRef);
static void didChangeTitle(const void*);
+ static void didChangeIsLoading(const void*);
+ static void didChangeEstimatedProgress(const void*);
static void didCommitNavigation(WKPageRef, WKNavigationRef, WKTypeRef, const void*);
static void didReceiveAuthenticationChallenge(WKPageRef, WKAuthenticationChallengeRef, const void*);
static WKPageRef createNewPage(WKPageRef, WKPageConfigurationRef, WKNavigationActionRef, WKWindowFeaturesRef, const void *);
static void didNotHandleKeyEvent(WKPageRef, WKNativeEventPtr, const void*);
+ BrowserWindowClient& m_client;
WKRetainPtr<WKViewRef> m_view;
HWND m_hMainWnd { nullptr };
HWND m_urlBarWnd { nullptr };
Modified: trunk/Tools/MiniBrowser/win/WebKitLegacyBrowserWindow.cpp (248989 => 248990)
--- trunk/Tools/MiniBrowser/win/WebKitLegacyBrowserWindow.cpp 2019-08-22 01:42:22 UTC (rev 248989)
+++ trunk/Tools/MiniBrowser/win/WebKitLegacyBrowserWindow.cpp 2019-08-22 01:49:48 UTC (rev 248990)
@@ -58,14 +58,18 @@
static const int maxHistorySize = 10;
typedef _com_ptr_t<_com_IIID<IWebMutableURLRequest, &__uuidof(IWebMutableURLRequest)>> IWebMutableURLRequestPtr;
+typedef _com_ptr_t<_com_IIID<IWebNotificationObserver, &__uuidof(IWebNotificationObserver)>> IWebNotificationObserverPtr;
+typedef _com_ptr_t<_com_IIID<IWebNotificationCenter, &__uuidof(IWebNotificationCenter)>> IWebNotificationCenterPtr;
-Ref<BrowserWindow> WebKitLegacyBrowserWindow::create(HWND mainWnd, HWND urlBarWnd, bool useLayeredWebView)
+
+Ref<BrowserWindow> WebKitLegacyBrowserWindow::create(BrowserWindowClient& client, HWND mainWnd, HWND urlBarWnd, bool useLayeredWebView)
{
- return adoptRef(*new WebKitLegacyBrowserWindow(mainWnd, urlBarWnd, useLayeredWebView));
+ return adoptRef(*new WebKitLegacyBrowserWindow(client, mainWnd, urlBarWnd, useLayeredWebView));
}
-WebKitLegacyBrowserWindow::WebKitLegacyBrowserWindow(HWND mainWnd, HWND urlBarWnd, bool useLayeredWebView)
- : m_hMainWnd(mainWnd)
+WebKitLegacyBrowserWindow::WebKitLegacyBrowserWindow(BrowserWindowClient& client, HWND mainWnd, HWND urlBarWnd, bool useLayeredWebView)
+ : m_client(client)
+ , m_hMainWnd(mainWnd)
, m_hURLBarWnd(urlBarWnd)
, m_useLayeredWebView(useLayeredWebView)
{
@@ -106,6 +110,16 @@
if (FAILED(hr))
return hr;
+ IWebNotificationCenterPtr notificationCenter;
+ hr = WebKitCreateInstance(CLSID_WebNotificationCenter, 0, __uuidof(notificationCenter), reinterpret_cast<void**>(¬ificationCenter.GetInterfacePtr()));
+ if (FAILED(hr))
+ return hr;
+
+ IWebNotificationCenterPtr defaultNotificationCenter;
+ hr = notificationCenter->defaultCenter(&defaultNotificationCenter.GetInterfacePtr());
+ if (FAILED(hr))
+ return hr;
+
if (!seedInitialDefaultPreferences())
return E_FAIL;
@@ -125,6 +139,14 @@
if (FAILED(hr))
return hr;
+ hr = defaultNotificationCenter->addObserver(webHost, _bstr_t(WebViewProgressEstimateChangedNotification), nullptr);
+ if (FAILED(hr))
+ return hr;
+
+ hr = defaultNotificationCenter->addObserver(webHost, _bstr_t(WebViewProgressFinishedNotification), nullptr);
+ if (FAILED(hr))
+ return hr;
+
hr = setUIDelegate(new PrintWebUIDelegate(*this));
if (FAILED (hr))
return hr;
Modified: trunk/Tools/MiniBrowser/win/WebKitLegacyBrowserWindow.h (248989 => 248990)
--- trunk/Tools/MiniBrowser/win/WebKitLegacyBrowserWindow.h 2019-08-22 01:42:22 UTC (rev 248989)
+++ trunk/Tools/MiniBrowser/win/WebKitLegacyBrowserWindow.h 2019-08-22 01:49:48 UTC (rev 248990)
@@ -31,6 +31,7 @@
#include <vector>
#include <wtf/Ref.h>
+typedef _com_ptr_t<_com_IIID<IUnknown, &__uuidof(IUnknown)>> IUnknownPtr;
typedef _com_ptr_t<_com_IIID<IWebFrame, &__uuidof(IWebFrame)>> IWebFramePtr;
typedef _com_ptr_t<_com_IIID<IWebView, &__uuidof(IWebView)>> IWebViewPtr;
typedef _com_ptr_t<_com_IIID<IWebViewPrivate2, &__uuidof(IWebViewPrivate2)>> IWebViewPrivatePtr;
@@ -50,7 +51,7 @@
class WebKitLegacyBrowserWindow : public BrowserWindow {
public:
- static Ref<BrowserWindow> create(HWND mainWnd, HWND urlBarWnd, bool useLayeredWebView = false);
+ static Ref<BrowserWindow> create(BrowserWindowClient&, HWND mainWnd, HWND urlBarWnd, bool useLayeredWebView = false);
private:
friend class AccessibilityDelegate;
@@ -110,10 +111,11 @@
void updateStatistics(HWND dialog);
void setPreference(UINT menuID, bool enable);
- WebKitLegacyBrowserWindow(HWND mainWnd, HWND urlBarWnd, bool useLayeredWebView);
+ WebKitLegacyBrowserWindow(BrowserWindowClient&, HWND mainWnd, HWND urlBarWnd, bool useLayeredWebView);
void subclassForLayeredWindow();
bool setCacheFolder();
+ BrowserWindowClient& m_client;
std::vector<IWebHistoryItemPtr> m_historyItems;
IWebViewPtr m_webView;