OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2006, 2007, 2009 Apple Inc. All rights reserved. | 2 * Copyright (C) 2006, 2007, 2009 Apple Inc. All rights reserved. |
3 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) | 3 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) |
4 * | 4 * |
5 * This library is free software; you can redistribute it and/or | 5 * This library is free software; you can redistribute it and/or |
6 * modify it under the terms of the GNU Library General Public | 6 * modify it under the terms of the GNU Library General Public |
7 * License as published by the Free Software Foundation; either | 7 * License as published by the Free Software Foundation; either |
8 * version 2 of the License, or (at your option) any later version. | 8 * version 2 of the License, or (at your option) any later version. |
9 * | 9 * |
10 * This library is distributed in the hope that it will be useful, | 10 * This library is distributed in the hope that it will be useful, |
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 * Library General Public License for more details. | 13 * Library General Public License for more details. |
14 * | 14 * |
15 * You should have received a copy of the GNU Library General Public License | 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 | 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, | 17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
18 * Boston, MA 02110-1301, USA. | 18 * Boston, MA 02110-1301, USA. |
19 */ | 19 */ |
20 | 20 |
21 #include "core/page/ScopedPageLoadDeferrer.h" | 21 #include "core/page/ScopedPageLoadDeferrer.h" |
22 | 22 |
23 #include "core/dom/Document.h" | 23 #include "core/dom/Document.h" |
24 #include "core/frame/LocalFrame.h" | |
25 #include "core/loader/FrameLoader.h" | 24 #include "core/loader/FrameLoader.h" |
26 #include "core/page/Page.h" | 25 #include "core/page/Page.h" |
26 #include "platform/heap/Handle.h" | |
27 #include "public/platform/Platform.h" | 27 #include "public/platform/Platform.h" |
28 #include "public/platform/WebScheduler.h" | 28 #include "public/platform/WebScheduler.h" |
29 #include "wtf/HashSet.h" | 29 #include "wtf/StdLibExtras.h" |
30 #include "wtf/Vector.h" | |
30 | 31 |
31 namespace blink { | 32 namespace blink { |
32 | 33 |
33 ScopedPageLoadDeferrer::ScopedPageLoadDeferrer(Page* exclusion) | 34 namespace { |
35 | |
36 unsigned s_deferralCount = 0; | |
37 | |
38 void setDefersLoading(bool isDeferred) | |
34 { | 39 { |
35 for (Page* page : Page::ordinaryPages()) { | 40 for (const auto& page : Page::ordinaryPages()) |
36 if (page == exclusion || page->defersLoading()) | 41 page->setDefersLoading(isDeferred); |
37 continue; | 42 } |
38 m_deferredPages.append(page); | 43 |
39 } | 44 } // namespace |
45 | |
46 ScopedPageLoadDeferrer::ScopedPageLoadDeferrer() | |
47 { | |
48 if (++s_deferralCount > 1) | |
49 return; | |
40 | 50 |
41 setDefersLoading(true); | 51 setDefersLoading(true); |
42 Platform::current()->currentThread()->scheduler()->suspendTimerQueue(); | 52 Platform::current()->currentThread()->scheduler()->suspendTimerQueue(); |
43 } | 53 } |
44 | 54 |
45 ScopedPageLoadDeferrer::~ScopedPageLoadDeferrer() | 55 ScopedPageLoadDeferrer::~ScopedPageLoadDeferrer() |
46 { | 56 { |
47 setDefersLoading(false); | 57 if (--s_deferralCount == 0) { |
Nate Chapin
2016/07/27 17:30:47
Nit: it bothers my sense of aesthetics that the co
dcheng
2016/07/28 01:23:28
Done.
| |
48 Platform::current()->currentThread()->scheduler()->resumeTimerQueue(); | 58 setDefersLoading(false); |
59 Platform::current()->currentThread()->scheduler()->resumeTimerQueue(); | |
60 } | |
49 } | 61 } |
50 | 62 |
51 void ScopedPageLoadDeferrer::setDefersLoading(bool isDeferred) | 63 bool ScopedPageLoadDeferrer::isActive() |
52 { | 64 { |
53 | 65 return s_deferralCount > 0; |
54 for (const auto& page : m_deferredPages) | |
55 page->setDefersLoading(isDeferred); | |
56 } | 66 } |
57 | 67 |
58 } // namespace blink | 68 } // namespace blink |
OLD | NEW |