1/*
2 * Copyright (C) 2006, 2007, 2009 Apple Inc. All rights reserved.
3 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19 */
20
21#include "config.h"
22#include "PageGroupLoadDeferrer.h"
23
24#include "Document.h"
25#include "DocumentParser.h"
26#include "Frame.h"
27#include "Page.h"
28#include "PageGroup.h"
29#include "ScriptRunner.h"
30
31namespace WebCore {
32
33PageGroupLoadDeferrer::PageGroupLoadDeferrer(Page& page, bool deferSelf)
34{
35 for (auto& otherPage : page.group().pages()) {
36 if ((deferSelf || otherPage != &page)) {
37 if (!otherPage->defersLoading()) {
38 m_deferredFrames.append(&otherPage->mainFrame());
39
40 // This code is not logically part of load deferring, but we do not want JS code executed beneath modal
41 // windows or sheets, which is exactly when PageGroupLoadDeferrer is used.
42 for (Frame* frame = &otherPage->mainFrame(); frame; frame = frame->tree().traverseNext())
43 frame->document()->suspendScheduledTasks(ReasonForSuspension::WillDeferLoading);
44 }
45 }
46 }
47
48 for (auto& deferredFrame : m_deferredFrames) {
49 if (Page* page = deferredFrame->page())
50 page->setDefersLoading(true);
51 }
52}
53
54PageGroupLoadDeferrer::~PageGroupLoadDeferrer()
55{
56 for (auto& deferredFrame : m_deferredFrames) {
57 if (Page* page = deferredFrame->page()) {
58 page->setDefersLoading(false);
59
60 for (Frame* frame = &page->mainFrame(); frame; frame = frame->tree().traverseNext())
61 frame->document()->resumeScheduledTasks(ReasonForSuspension::WillDeferLoading);
62 }
63 }
64}
65
66
67} // namespace WebCore
68