From 55f03180a6de24c1ebc3c3c3002e6e0d09066524 Mon Sep 17 00:00:00 2001 From: Pavel Feldman Date: Tue, 5 May 2020 16:46:36 -0800 Subject: [PATCH] browser(webkit): install page group preferences to new pages --- browser_patches/webkit/BUILD_NUMBER | 2 +- browser_patches/webkit/patches/bootstrap.diff | 5 ++--- .../src/Tools/Playwright/win/MainWindow.cpp | 17 ++++------------- .../src/Tools/Playwright/win/MainWindow.h | 1 - .../Playwright/win/WebKitBrowserWindow.cpp | 2 ++ .../webkit/src/Tools/Playwright/win/WinMain.cpp | 5 ++++- 6 files changed, 13 insertions(+), 19 deletions(-) diff --git a/browser_patches/webkit/BUILD_NUMBER b/browser_patches/webkit/BUILD_NUMBER index 5cc3b964ed312..9e3410c093fe0 100644 --- a/browser_patches/webkit/BUILD_NUMBER +++ b/browser_patches/webkit/BUILD_NUMBER @@ -1 +1 @@ -1218 +1219 diff --git a/browser_patches/webkit/patches/bootstrap.diff b/browser_patches/webkit/patches/bootstrap.diff index 82888151aba65..75cd7e4411963 100644 --- a/browser_patches/webkit/patches/bootstrap.diff +++ b/browser_patches/webkit/patches/bootstrap.diff @@ -12636,10 +12636,10 @@ index 0000000000000000000000000000000000000000..30e6ae3bdc8c1695189885afae949071 +} // namespace WebKit diff --git a/Source/WebKit/UIProcess/win/InspectorPlaywrightAgentClientWin.cpp b/Source/WebKit/UIProcess/win/InspectorPlaywrightAgentClientWin.cpp new file mode 100644 -index 0000000000000000000000000000000000000000..544442b75afcba6e121ab202ad32dcdfaf923e2e +index 0000000000000000000000000000000000000000..9ea75b043513fe4c56b3af33d2082375971a75f7 --- /dev/null +++ b/Source/WebKit/UIProcess/win/InspectorPlaywrightAgentClientWin.cpp -@@ -0,0 +1,83 @@ +@@ -0,0 +1,82 @@ +/* + * Copyright (C) 2020 Microsoft Corporation. + * @@ -12695,7 +12695,6 @@ index 0000000000000000000000000000000000000000..544442b75afcba6e121ab202ad32dcdf +RefPtr InspectorPlaywrightAgentClientWin::createPage(WTF::String& error, const BrowserContext& context) +{ + auto conf = API::PageConfiguration::create(); -+ auto prefs = WebPreferences::create(String(), "WebKit2Automation.", "WebKit2Automation."); + conf->setProcessPool(context.processPool.get()); + conf->setWebsiteDataStore(context.dataStore.get()); + return toImpl(m_createPage(toAPI(&conf.get()))); diff --git a/browser_patches/webkit/src/Tools/Playwright/win/MainWindow.cpp b/browser_patches/webkit/src/Tools/Playwright/win/MainWindow.cpp index 1f2b465478b22..a8dc408782715 100644 --- a/browser_patches/webkit/src/Tools/Playwright/win/MainWindow.cpp +++ b/browser_patches/webkit/src/Tools/Playwright/win/MainWindow.cpp @@ -173,27 +173,18 @@ void MainWindow::rescaleToolbar() m_toolbarItemsWidth = rect.right; } -bool MainWindow::init(HINSTANCE hInstance, WKContextRef context, WKWebsiteDataStoreRef dataStore) +bool MainWindow::init(HINSTANCE hInstance, WKPageConfigurationRef conf) { - auto conf = adoptWK(WKPageConfigurationCreate()); + auto pageGroup = adoptWK(WKPageGroupCreateWithIdentifier(createWKString("WinPlaywright").get())); auto prefs = adoptWK(WKPreferencesCreate()); - auto pageGroup = adoptWK(WKPageGroupCreateWithIdentifier(createWKString("WinPlaywright").get())); - WKPageConfigurationSetPageGroup(conf.get(), pageGroup.get()); + WKPageConfigurationSetPageGroup(conf, pageGroup.get()); + WKPageConfigurationSetPreferences(conf, prefs.get()); WKPageGroupSetPreferences(pageGroup.get(), prefs.get()); WKPreferencesSetMediaCapabilitiesEnabled(prefs.get(), false); WKPreferencesSetDeveloperExtrasEnabled(prefs.get(), true); - WKPageConfigurationSetPreferences(conf.get(), prefs.get()); - - WKPageConfigurationSetContext(conf.get(), context); - WKPageConfigurationSetWebsiteDataStore(conf.get(), dataStore); - return init(hInstance, conf.get()); -} - -bool MainWindow::init(HINSTANCE hInstance, WKPageConfigurationRef conf) -{ m_configuration = conf; registerClass(hInstance); diff --git a/browser_patches/webkit/src/Tools/Playwright/win/MainWindow.h b/browser_patches/webkit/src/Tools/Playwright/win/MainWindow.h index 4c9bb23645957..95730f46be5c9 100644 --- a/browser_patches/webkit/src/Tools/Playwright/win/MainWindow.h +++ b/browser_patches/webkit/src/Tools/Playwright/win/MainWindow.h @@ -40,7 +40,6 @@ class MainWindow : public BrowserWindowClient { MainWindow(); ~MainWindow(); - bool init(HINSTANCE hInstance, WKContextRef, WKWebsiteDataStoreRef); bool init(HINSTANCE hInstance, WKPageConfigurationRef); void resizeSubViews(); diff --git a/browser_patches/webkit/src/Tools/Playwright/win/WebKitBrowserWindow.cpp b/browser_patches/webkit/src/Tools/Playwright/win/WebKitBrowserWindow.cpp index 97e736dd12133..60932f3a1abe3 100644 --- a/browser_patches/webkit/src/Tools/Playwright/win/WebKitBrowserWindow.cpp +++ b/browser_patches/webkit/src/Tools/Playwright/win/WebKitBrowserWindow.cpp @@ -340,6 +340,7 @@ void WebKitBrowserWindow::handleJavaScriptDialog(WKPageRef page, bool accept, WK WKPageRef WebKitBrowserWindow::createPageCallback(WKPageConfigurationRef configuration) { + // This comes from the Playwright agent, configuration is a pool+data pair. return WebKitBrowserWindow::createViewCallback(configuration, true); } @@ -357,6 +358,7 @@ WKPageRef WebKitBrowserWindow::createViewCallback(WKPageConfigurationRef configu WKPageRef WebKitBrowserWindow::createNewPage(WKPageRef, WKPageConfigurationRef configuration, WKNavigationActionRef, WKWindowFeaturesRef, const void*) { + // This comes from the client for popups, configuration is inherited from main page. // Retain popups as per API contract. WKRetainPtr newPage = createViewCallback(configuration, false); return newPage.leakRef(); diff --git a/browser_patches/webkit/src/Tools/Playwright/win/WinMain.cpp b/browser_patches/webkit/src/Tools/Playwright/win/WinMain.cpp index 2cf6cfe710acd..d90b5ad9ee871 100644 --- a/browser_patches/webkit/src/Tools/Playwright/win/WinMain.cpp +++ b/browser_patches/webkit/src/Tools/Playwright/win/WinMain.cpp @@ -110,7 +110,10 @@ int WINAPI wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, WKContextSetPrimaryDataStore(context.get(), dataStore.get()); auto* mainWindow = new MainWindow(); - HRESULT hr = mainWindow->init(hInst, context.get(), dataStore.get()); + auto conf = adoptWK(WKPageConfigurationCreate()); + WKPageConfigurationSetContext(conf.get(), context.get()); + WKPageConfigurationSetWebsiteDataStore(conf.get(), dataStore.get()); + HRESULT hr = mainWindow->init(hInst, conf.get()); if (FAILED(hr)) goto exit;