OLD | NEW |
| (Empty) |
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 "core/page/ScopedPageLoadDeferrer.h" | |
22 | |
23 #include "core/dom/Document.h" | |
24 #include "core/loader/FrameLoader.h" | |
25 #include "core/page/Page.h" | |
26 #include "platform/heap/Handle.h" | |
27 #include "public/platform/Platform.h" | |
28 #include "public/platform/WebScheduler.h" | |
29 #include "wtf/StdLibExtras.h" | |
30 #include "wtf/Vector.h" | |
31 | |
32 namespace blink { | |
33 | |
34 namespace { | |
35 | |
36 unsigned s_deferralCount = 0; | |
37 | |
38 void setDefersLoading(bool isDeferred) { | |
39 // Make a copy of the collection. Undeferring loads can cause script to run, | |
40 // which would mutate ordinaryPages() in the middle of iteration. | |
41 HeapVector<Member<Page>> pages; | |
42 copyToVector(Page::ordinaryPages(), pages); | |
43 for (const auto& page : pages) | |
44 page->setDefersLoading(isDeferred); | |
45 } | |
46 | |
47 } // namespace | |
48 | |
49 ScopedPageLoadDeferrer::ScopedPageLoadDeferrer() { | |
50 if (++s_deferralCount > 1) | |
51 return; | |
52 | |
53 setDefersLoading(true); | |
54 Platform::current()->currentThread()->scheduler()->suspendTimerQueue(); | |
55 } | |
56 | |
57 ScopedPageLoadDeferrer::~ScopedPageLoadDeferrer() { | |
58 if (--s_deferralCount > 0) | |
59 return; | |
60 | |
61 setDefersLoading(false); | |
62 Platform::current()->currentThread()->scheduler()->resumeTimerQueue(); | |
63 } | |
64 | |
65 bool ScopedPageLoadDeferrer::isActive() { | |
66 return s_deferralCount > 0; | |
67 } | |
68 | |
69 } // namespace blink | |
OLD | NEW |