initial import
[vuplus_webkit] / Source / WebCore / page / PageGroupLoadDeferrer.cpp
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 #include <wtf/HashSet.h>
31
32 namespace WebCore {
33
34 using namespace std;
35
36 PageGroupLoadDeferrer::PageGroupLoadDeferrer(Page* page, bool deferSelf)
37 {
38     const HashSet<Page*>& pages = page->group().pages();
39
40     HashSet<Page*>::const_iterator end = pages.end();
41     for (HashSet<Page*>::const_iterator it = pages.begin(); it != end; ++it) {
42         Page* otherPage = *it;
43         if ((deferSelf || otherPage != page)) {
44             if (!otherPage->defersLoading()) {
45                 m_deferredFrames.append(otherPage->mainFrame());
46
47                 // This code is not logically part of load deferring, but we do not want JS code executed beneath modal
48                 // windows or sheets, which is exactly when PageGroupLoadDeferrer is used.
49                 // NOTE: if PageGroupLoadDeferrer is ever used for tasks other than showing a modal window or sheet,
50                 // the constructor will need to take a ActiveDOMObject::ReasonForSuspension.
51                 for (Frame* frame = otherPage->mainFrame(); frame; frame = frame->tree()->traverseNext()) {
52                     frame->document()->suspendScriptedAnimationControllerCallbacks();
53                     frame->document()->suspendActiveDOMObjects(ActiveDOMObject::WillShowDialog);
54                     frame->document()->scriptRunner()->suspend();
55                     if (DocumentParser* parser = frame->document()->parser())
56                         parser->suspendScheduledTasks();
57                 }
58             }
59         }
60     }
61
62     size_t count = m_deferredFrames.size();
63     for (size_t i = 0; i < count; ++i)
64         if (Page* page = m_deferredFrames[i]->page())
65             page->setDefersLoading(true);
66 }
67
68 PageGroupLoadDeferrer::~PageGroupLoadDeferrer()
69 {
70     for (size_t i = 0; i < m_deferredFrames.size(); ++i) {
71         if (Page* page = m_deferredFrames[i]->page()) {
72             page->setDefersLoading(false);
73
74             for (Frame* frame = page->mainFrame(); frame; frame = frame->tree()->traverseNext()) {
75                 frame->document()->resumeActiveDOMObjects();
76                 frame->document()->resumeScriptedAnimationControllerCallbacks();
77                 frame->document()->scriptRunner()->resume();
78                 if (DocumentParser* parser = frame->document()->parser())
79                     parser->resumeScheduledTasks();
80             }
81         }
82     }
83 }
84
85
86 } // namespace WebCore