From be943b8d74a6301d154540088afc282402a8141d Mon Sep 17 00:00:00 2001 From: Tim Cooijmans Date: Fri, 19 Feb 2010 16:34:36 +0100 Subject: [PATCH] Make window_before_close_hook a coroutine hook. --- modules/window.js | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/modules/window.js b/modules/window.js index bee3342..5cb31e4 100644 --- a/modules/window.js +++ b/modules/window.js @@ -9,6 +9,7 @@ require("mode.js"); var define_window_local_hook = simple_local_hook_definer(); +var define_window_local_coroutine_hook = simple_local_coroutine_hook_definer(); define_hook("make_window_hook"); @@ -69,10 +70,16 @@ function make_window (initial_buffer_creator, tag) { var result = make_chrome_window(conkeror_chrome_uri, null); result.args = args; make_window_hook.run(result); - result._close = result.close; + var close = result.close; result.close = function () { - if (window_before_close_hook.run(result)) - result._close(); + function attempt_close () { + var res = yield window_before_close_hook.run(result); + if (res) { + close.call(result); + window_close_hook.run(result); + } + } + co_call(attempt_close()); }; return result; } @@ -181,22 +188,19 @@ function window_initialize (window) { delete window.args; // get rid of args }, 0); - window.addEventListener("close", window_close_maybe, true /* capture */); + window.addEventListener("close", + function (event) { + event.preventDefault(); + event.stopPropagation(); + this.close(); + }, + true /* capture */); } -define_window_local_hook("window_before_close_hook", RUN_HOOK_UNTIL_FAILURE); +define_window_local_coroutine_hook("window_before_close_hook", + RUN_HOOK_UNTIL_FAILURE); define_window_local_hook("window_close_hook", RUN_HOOK); -function window_close_maybe (event) { - var window = this; - - if (!window_before_close_hook.run(window)) { - event.preventDefault(); - event.stopPropagation(); - return; - } - window_close_hook.run(window); -} function define_global_window_mode (name, hook_name) { function install (window) { -- 2.11.4.GIT