Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(441)

Side by Side Diff: third_party/WebKit/Source/core/page/ScopedPageLoadDeferrer.cpp

Issue 2174263002: Defer loads in new pages/frames if ScopedPageLoadDeferral is active (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Make the unfortunate hack slightly less ugly. Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 {
57 if (--s_deferralCount > 0)
58 return;
59
47 setDefersLoading(false); 60 setDefersLoading(false);
48 Platform::current()->currentThread()->scheduler()->resumeTimerQueue(); 61 Platform::current()->currentThread()->scheduler()->resumeTimerQueue();
49 } 62 }
50 63
51 void ScopedPageLoadDeferrer::setDefersLoading(bool isDeferred) 64 bool ScopedPageLoadDeferrer::isActive()
52 { 65 {
53 66 return s_deferralCount > 0;
54 for (const auto& page : m_deferredPages)
55 page->setDefersLoading(isDeferred);
56 } 67 }
57 68
58 } // namespace blink 69 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/page/ScopedPageLoadDeferrer.h ('k') | third_party/WebKit/Source/web/tests/WebViewTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698