Skip to content

Commit

Permalink
[Win][MiniBrowser] Add a new BrowserWindow interface to abstract WK1 …
Browse files Browse the repository at this point in the history
…and WK2 BrowserWindow

https://bugs.webkit.org/show_bug.cgi?id=186421

Reviewed by Ryosuke Niwa.

This is the core patch to make MiniBrowser to support WK1 and WK2
windows (Bug 184770).

I will rename MiniBrowser class to WK1BrowserWindow in a follow-up
patch (Bug 184770 Comment 12).

* MiniBrowser/win/BrowserWindow.h: Added.
* MiniBrowser/win/MainWindow.cpp:
(MainWindow::WndProc):
* MiniBrowser/win/MainWindow.h:
(MainWindow::browserWindow const):
* MiniBrowser/win/MiniBrowser.cpp:
(MiniBrowser::create):
(MiniBrowser::navigateForwardOrBackward): Removed the unsed first argument hWnd.
(MiniBrowser::navigateToHistory): Ditto.
* MiniBrowser/win/MiniBrowser.h: Inherit BrowserWindow interface.
Make all other methods private and make delegates classes friends.
* MiniBrowser/win/PrintWebUIDelegate.cpp:
(PrintWebUIDelegate::createWebViewWithRequest):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@232616 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
[email protected] authored and [email protected] committed Jun 8, 2018
1 parent 565db14 commit 164a080
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 17 deletions.
27 changes: 27 additions & 0 deletions Tools/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,30 @@
2018-06-07 Fujii Hironori <[email protected]>

[Win][MiniBrowser] Add a new BrowserWindow interface to abstract WK1 and WK2 BrowserWindow
https://bugs.webkit.org/show_bug.cgi?id=186421

Reviewed by Ryosuke Niwa.

This is the core patch to make MiniBrowser to support WK1 and WK2
windows (Bug 184770).

I will rename MiniBrowser class to WK1BrowserWindow in a follow-up
patch (Bug 184770 Comment 12).

* MiniBrowser/win/BrowserWindow.h: Added.
* MiniBrowser/win/MainWindow.cpp:
(MainWindow::WndProc):
* MiniBrowser/win/MainWindow.h:
(MainWindow::browserWindow const):
* MiniBrowser/win/MiniBrowser.cpp:
(MiniBrowser::create):
(MiniBrowser::navigateForwardOrBackward): Removed the unsed first argument hWnd.
(MiniBrowser::navigateToHistory): Ditto.
* MiniBrowser/win/MiniBrowser.h: Inherit BrowserWindow interface.
Make all other methods private and make delegates classes friends.
* MiniBrowser/win/PrintWebUIDelegate.cpp:
(PrintWebUIDelegate::createWebViewWithRequest):

2018-06-07 Fujii Hironori <[email protected]>

[Win][MiniBrowser] MiniBrowser::updateDeviceScaleFactor should be a MainWindow's method
Expand Down
58 changes: 58 additions & 0 deletions Tools/MiniBrowser/win/BrowserWindow.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright (C) 2018 Sony Interactive Entertainment Inc.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#pragma once

#include <windows.h>
#include <wtf/RefCounted.h>

class BrowserWindow : public RefCounted<BrowserWindow> {
public:
virtual ~BrowserWindow() { };

virtual HRESULT init() = 0;
virtual HWND hwnd() = 0;

virtual HRESULT loadHTMLString(const BSTR&) = 0;
virtual HRESULT loadURL(const BSTR& passedURL) = 0;
virtual void navigateForwardOrBackward(UINT menuID) = 0;
virtual void navigateToHistory(UINT menuID) = 0;
virtual void setPreference(UINT menuID, bool enable) = 0;
virtual bool usesLayeredWebView() const { return false; }

virtual void print() = 0;
virtual void launchInspector() = 0;

virtual _bstr_t userAgent() = 0;
virtual void setUserAgent(UINT menuID) = 0;
virtual void setUserAgent(_bstr_t& customUAString) = 0;

virtual void showLayerTree() = 0;
virtual void updateStatistics(HWND dialog) = 0;

virtual void resetZoom() = 0;
virtual void zoomIn() = 0;
virtual void zoomOut() = 0;
};
4 changes: 2 additions & 2 deletions Tools/MiniBrowser/win/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ LRESULT CALLBACK MainWindow::WndProc(HWND hWnd, UINT message, WPARAM wParam, LPA
return DefWindowProc(hWnd, message, wParam, lParam);
}
if (wmId >= IDM_HISTORY_LINK0 && wmId <= IDM_HISTORY_LINK9) {
thisWindow->browserWindow()->navigateToHistory(hWnd, wmId);
thisWindow->browserWindow()->navigateToHistory(wmId);
break;
}
// Parse the menu selections:
Expand Down Expand Up @@ -191,7 +191,7 @@ LRESULT CALLBACK MainWindow::WndProc(HWND hWnd, UINT message, WPARAM wParam, LPA
break;
case IDM_HISTORY_BACKWARD:
case IDM_HISTORY_FORWARD:
thisWindow->browserWindow()->navigateForwardOrBackward(hWnd, wmId);
thisWindow->browserWindow()->navigateForwardOrBackward(wmId);
break;
case IDM_UA_OTHER:
DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_USER_AGENT), hWnd, customUserAgentDialogProc, reinterpret_cast<LPARAM>(thisWindow.get()));
Expand Down
4 changes: 2 additions & 2 deletions Tools/MiniBrowser/win/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class MainWindow : public RefCounted<MainWindow> {

void resizeSubViews();
HWND hwnd() const { return m_hMainWnd; }
MiniBrowser* browserWindow() const { return m_browserWindow.get(); }
BrowserWindow* browserWindow() const { return m_browserWindow.get(); }

void loadURL(BSTR url);

Expand All @@ -62,5 +62,5 @@ class MainWindow : public RefCounted<MainWindow> {
HWND m_hForwardButtonWnd { nullptr };
HWND m_hCacheWnd { nullptr };
HGDIOBJ m_hURLBarFont { nullptr };
RefPtr<MiniBrowser> m_browserWindow;
RefPtr<BrowserWindow> m_browserWindow;
};
6 changes: 3 additions & 3 deletions Tools/MiniBrowser/win/MiniBrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ static const int maxHistorySize = 10;

typedef _com_ptr_t<_com_IIID<IWebMutableURLRequest, &__uuidof(IWebMutableURLRequest)>> IWebMutableURLRequestPtr;

Ref<MiniBrowser> MiniBrowser::create(HWND mainWnd, HWND urlBarWnd, bool useLayeredWebView, bool pageLoadTesting)
Ref<BrowserWindow> MiniBrowser::create(HWND mainWnd, HWND urlBarWnd, bool useLayeredWebView, bool pageLoadTesting)
{
return adoptRef(*new MiniBrowser(mainWnd, urlBarWnd, useLayeredWebView, pageLoadTesting));
}
Expand Down Expand Up @@ -430,7 +430,7 @@ void MiniBrowser::launchInspector()
m_inspector->show();
}

void MiniBrowser::navigateForwardOrBackward(HWND hWnd, UINT menuID)
void MiniBrowser::navigateForwardOrBackward(UINT menuID)
{
if (!m_webView)
return;
Expand All @@ -442,7 +442,7 @@ void MiniBrowser::navigateForwardOrBackward(HWND hWnd, UINT menuID)
m_webView->goBack(&wentBackOrForward);
}

void MiniBrowser::navigateToHistory(HWND hWnd, UINT menuID)
void MiniBrowser::navigateToHistory(UINT menuID)
{
if (!m_webView)
return;
Expand Down
19 changes: 13 additions & 6 deletions Tools/MiniBrowser/win/MiniBrowser.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@
*/

#pragma once
#include "BrowserWindow.h"
#include "PageLoadTestClient.h"
#include <WebKitLegacy/WebKit.h>
#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;
Expand All @@ -48,9 +48,17 @@ typedef _com_ptr_t<_com_IIID<IWebResourceLoadDelegate, &__uuidof(IWebResourceLoa
typedef _com_ptr_t<_com_IIID<IWebDownloadDelegate, &__uuidof(IWebDownloadDelegate)>> IWebDownloadDelegatePtr;
typedef _com_ptr_t<_com_IIID<IWebFramePrivate, &__uuidof(IWebFramePrivate)>> IWebFramePrivatePtr;

class MiniBrowser : public RefCounted<MiniBrowser> {
class MiniBrowser : public BrowserWindow {
public:
static Ref<MiniBrowser> create(HWND mainWnd, HWND urlBarWnd, bool useLayeredWebView = false, bool pageLoadTesting = false);
static Ref<BrowserWindow> create(HWND mainWnd, HWND urlBarWnd, bool useLayeredWebView = false, bool pageLoadTesting = false);

private:
friend class AccessibilityDelegate;
friend class MiniBrowserWebHost;
friend class PrintWebUIDelegate;
friend class WebDownloadDelegate;
friend class ResourceLoadDelegate;
friend class PageLoadTestClient;

ULONG AddRef();
ULONG Release();
Expand All @@ -63,8 +71,8 @@ class MiniBrowser : public RefCounted<MiniBrowser> {

void showLastVisitedSites(IWebView&);
void launchInspector();
void navigateForwardOrBackward(HWND hWnd, UINT menuID);
void navigateToHistory(HWND hWnd, UINT menuID);
void navigateForwardOrBackward(UINT menuID);
void navigateToHistory(UINT menuID);
void exitProgram();
bool seedInitialDefaultPreferences();
bool setToDefaultPreferences();
Expand Down Expand Up @@ -106,7 +114,6 @@ class MiniBrowser : public RefCounted<MiniBrowser> {
void updateStatistics(HWND dialog);
void setPreference(UINT menuID, bool enable);

private:
MiniBrowser(HWND mainWnd, HWND urlBarWnd, bool useLayeredWebView, bool pageLoadTesting);
void subclassForLayeredWindow();
bool setCacheFolder();
Expand Down
11 changes: 7 additions & 4 deletions Tools/MiniBrowser/win/PrintWebUIDelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@

#include "Common.h"
#include "MainWindow.h"
#if USE(CF)
#include <CoreFoundation/CoreFoundation.h>
#endif
#include "MiniBrowser.h"
#include <WebCore/COMPtr.h>
#include <WebKitLegacy/WebKitCOMAPI.h>
#include <comip.h>
Expand All @@ -41,6 +39,10 @@
#include <shlwapi.h>
#include <wininet.h>

#if USE(CF)
#include <CoreFoundation/CoreFoundation.h>
#endif

static const int MARGIN = 20;

HRESULT PrintWebUIDelegate::runJavaScriptAlertPanelWithMessage(_In_opt_ IWebView*, _In_ BSTR message)
Expand Down Expand Up @@ -69,7 +71,8 @@ HRESULT PrintWebUIDelegate::createWebViewWithRequest(_In_opt_ IWebView*, _In_opt
return E_FAIL;
ShowWindow(newWindow.hwnd(), SW_SHOW);

*newWebView = newWindow.browserWindow()->webView();
auto& newBrowserWindow = *static_cast<MiniBrowser*>(newWindow.browserWindow());
*newWebView = newBrowserWindow.webView();
IWebFramePtr frame;
HRESULT hr;
hr = (*newWebView)->mainFrame(&frame.GetInterfacePtr());
Expand Down

0 comments on commit 164a080

Please sign in to comment.