Skip to content

Commit 19e0c1e

Browse files
authored
Merge pull request #1115 from LibertyGlobal/jgocol/ONEM-31242-upstream
Add configuration option to allow moving window to background when window.close is called
2 parents 07fdc07 + 50871b4 commit 19e0c1e

4 files changed

Lines changed: 85 additions & 8 deletions

File tree

Source/WTF/Scripts/Preferences/WebPreferences.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,19 @@ AllowMediaContentTypesRequiringHardwareSupportAsFallback:
120120
WebCore:
121121
default: false
122122

123+
AllowMoveToSuspendOnWindowClose:
124+
type: bool
125+
humanReadableName: "Allow move to suspend on window.close()"
126+
humanReadableDescription: "Allow to suspend browser instead of closing window on window.close()"
127+
condition: PLATFORM(WPE)
128+
defaultValue:
129+
WebKitLegacy:
130+
default: false
131+
WebKit:
132+
default: false
133+
WebCore:
134+
default: false
135+
123136
AllowMultiElementImplicitSubmission:
124137
type: bool
125138
webKitLegacyPreferenceKey: WebKitAllowMultiElementImplicitFormSubmissionPreferenceKey

Source/WebCore/page/DOMWindow.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,17 +1073,19 @@ void DOMWindow::close()
10731073
if (!frame->isMainFrame())
10741074
return;
10751075

1076-
if (!(page->openedByDOM() || page->backForward().count() <= 1 || frame->settings().allowScriptsToCloseWindows())) {
1077-
console()->addMessage(MessageSource::JS, MessageLevel::Warning, "Can't close the window since it was not opened by JavaScript"_s);
1078-
return;
1079-
}
1076+
if (!frame->settings().allowMoveToSuspendOnWindowClose()) {
1077+
if (!(page->openedByDOM() || page->backForward().count() <= 1 || frame->settings().allowScriptsToCloseWindows())) {
1078+
console()->addMessage(MessageSource::JS, MessageLevel::Warning, "Can't close the window since it was not opened by JavaScript"_s);
1079+
return;
1080+
}
10801081

1081-
if (!frame->loader().shouldClose())
1082-
return;
1082+
if (!frame->loader().shouldClose())
1083+
return;
10831084

1084-
ResourceLoadObserver::shared().updateCentralStatisticsStore([] { });
1085+
ResourceLoadObserver::shared().updateCentralStatisticsStore([] { });
10851086

1086-
page->setIsClosing();
1087+
page->setIsClosing();
1088+
}
10871089

10881090
document()->eventLoop().queueTask(TaskSource::DOMManipulation, [this, protectedThis = Ref { *this }] {
10891091
if (auto* page = this->page())

Source/WebKit/UIProcess/API/glib/WebKitSettings.cpp

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ enum {
177177
PROP_ALLOW_RUNNING_OF_INSECURE_CONTENT,
178178
PROP_ALLOW_DISPLAY_OF_INSECURE_CONTENT,
179179
PROP_ALLOW_SCRIPTS_TO_CLOSE_WINDOWS,
180+
PROP_ALLOW_MOVE_TO_SUSPEND_ON_WINDOW_CLOSE,
180181
PROP_ENABLE_DIRECTORY_UPLOAD,
181182
N_PROPERTIES,
182183
};
@@ -423,6 +424,9 @@ ALLOW_DEPRECATED_DECLARATIONS_END
423424
case PROP_ALLOW_SCRIPTS_TO_CLOSE_WINDOWS:
424425
webkit_settings_set_allow_scripts_to_close_windows(settings, g_value_get_boolean(value));
425426
break;
427+
case PROP_ALLOW_MOVE_TO_SUSPEND_ON_WINDOW_CLOSE:
428+
webkit_settings_set_allow_move_to_suspend_on_window_close(settings, g_value_get_boolean(value));
429+
break;
426430
case PROP_ENABLE_DIRECTORY_UPLOAD:
427431
webkit_settings_set_enable_directory_upload(settings, g_value_get_boolean(value));
428432
break;
@@ -642,6 +646,9 @@ ALLOW_DEPRECATED_DECLARATIONS_END
642646
case PROP_ALLOW_SCRIPTS_TO_CLOSE_WINDOWS:
643647
g_value_set_boolean(value, webkit_settings_get_allow_scripts_to_close_windows(settings));
644648
break;
649+
case PROP_ALLOW_MOVE_TO_SUSPEND_ON_WINDOW_CLOSE:
650+
g_value_set_boolean(value, webkit_settings_get_allow_move_to_suspend_on_window_close(settings));
651+
break;
645652
case PROP_ENABLE_DIRECTORY_UPLOAD:
646653
g_value_set_boolean(value, webkit_settings_get_enable_directory_upload(settings));
647654
break;
@@ -1699,6 +1706,19 @@ static void webkit_settings_class_init(WebKitSettingsClass* klass)
16991706
FALSE,
17001707
readWriteConstructParamFlags);
17011708

1709+
/**
1710+
* WebKitSettings:allow-move-to-suspend-on-window-close:
1711+
*
1712+
* Allow browser to move to suspend on window close.
1713+
*
1714+
*/
1715+
sObjProperties[PROP_ALLOW_MOVE_TO_SUSPEND_ON_WINDOW_CLOSE] = g_param_spec_boolean(
1716+
"allow-scripts-to-close-windows",
1717+
_("Allow move to suspend on window.close()"),
1718+
_("Allow to suspend browser instead of closing window on window.close()"),
1719+
FALSE,
1720+
readWriteConstructParamFlags);
1721+
17021722
/**
17031723
* WebKitSettings:enable-directory-upload:
17041724
*
@@ -4260,6 +4280,42 @@ webkit_settings_set_allow_scripts_to_close_windows(WebKitSettings *settings, gbo
42604280
g_object_notify(G_OBJECT(settings), "allow-scripts-to-close-windows");
42614281
}
42624282

4283+
/**
4284+
* webkit_settings_get_allow_move_to_suspend_on_window_close:
4285+
* @settings: a #WebKitSettings
4286+
*
4287+
* Get the #WebKitSettings:allow-move-to-suspend-on-window-close property.
4288+
*
4289+
* Returns: %TRUE If browser can be suspended on window close.
4290+
*/
4291+
gboolean webkit_settings_get_allow_move_to_suspend_on_window_close (WebKitSettings *settings)
4292+
{
4293+
g_return_val_if_fail(WEBKIT_IS_SETTINGS(settings), FALSE);
4294+
4295+
return settings->priv->preferences->allowMoveToSuspendOnWindowClose();
4296+
}
4297+
4298+
/**
4299+
* webkit_settings_set_allow_move_to_suspend_on_window_close
4300+
* @settings: a #WebKitSettings
4301+
* @allowed: Value to be set
4302+
*
4303+
* Set the #WebKitSettings:allow-move-to-suspend-on-window-close property.
4304+
*/
4305+
WEBKIT_API void
4306+
webkit_settings_set_allow_move_to_suspend_on_window_close(WebKitSettings *settings, gboolean allowed)
4307+
{
4308+
g_return_if_fail(WEBKIT_IS_SETTINGS(settings));
4309+
4310+
WebKitSettingsPrivate* priv = settings->priv;
4311+
bool currentValue = priv->preferences->allowMoveToSuspendOnWindowClose();
4312+
if (currentValue == allowed)
4313+
return;
4314+
4315+
priv->preferences->setAllowMoveToSuspendOnWindowClose(allowed);
4316+
g_object_notify(G_OBJECT(settings), "allow-move-to-suspend-on-window-close");
4317+
}
4318+
42634319
/**
42644320
* webkit_settings_get_enable_directory_upload:
42654321
* @settings: a #WebKitSettings

Source/WebKit/UIProcess/API/wpe/WebKitSettings.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,12 @@ webkit_settings_get_allow_scripts_to_close_windows (WebKitSettings
513513
WEBKIT_API void
514514
webkit_settings_set_allow_scripts_to_close_windows (WebKitSettings *settings,
515515
gboolean allowed);
516+
WEBKIT_API gboolean
517+
webkit_settings_get_allow_move_to_suspend_on_window_close (WebKitSettings *settings);
518+
519+
WEBKIT_API void
520+
webkit_settings_set_allow_move_to_suspend_on_window_close (WebKitSettings *settings,
521+
gboolean allowed);
516522

517523
WEBKIT_API gboolean
518524
webkit_settings_get_enable_directory_upload (WebKitSettings *settings);

0 commit comments

Comments
 (0)