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 "core/page/ScopedPageLoadDeferrer.h" 23 24 #include "core/dom/Document.h" 25 #include "core/frame/LocalFrame.h" 26 #include "core/loader/FrameLoader.h" 27 #include "core/page/Page.h" 28 #include "wtf/HashSet.h" 29 30 namespace blink { 31 32 ScopedPageLoadDeferrer::ScopedPageLoadDeferrer(Page* exclusion) 33 { 34 const HashSet<Page*>& pages = Page::ordinaryPages(); 35 36 HashSet<Page*>::const_iterator end = pages.end(); 37 for (HashSet<Page*>::const_iterator it = pages.begin(); it != end; ++it) { 38 Page* page = *it; 39 if (page == exclusion || page->defersLoading()) 40 continue; 41 42 if (page->mainFrame()->isLocalFrame()) { 43 m_deferredFrames.append(page->deprecatedLocalMainFrame()); 44 45 // Ensure that we notify the client if the initial empty document is accessed before 46 // showing anything modal, to prevent spoofs while the modal window or sheet is visible. 47 page->deprecatedLocalMainFrame()->loader().notifyIfInitialDocumentAccessed(); 48 } 49 50 // This code is not logically part of load deferring, but we do not want JS code executed 51 // beneath modal windows or sheets, which is exactly when ScopedPageLoadDeferrer is used. 52 for (Frame* frame = page->mainFrame(); frame; frame = frame->tree().traverseNext()) { 53 if (frame->isLocalFrame()) 54 toLocalFrame(frame)->document()->suspendScheduledTasks(); 55 } 56 } 57 58 size_t count = m_deferredFrames.size(); 59 for (size_t i = 0; i < count; ++i) { 60 if (Page* page = m_deferredFrames[i]->page()) 61 page->setDefersLoading(true); 62 } 63 } 64 65 void ScopedPageLoadDeferrer::detach() 66 { 67 for (size_t i = 0; i < m_deferredFrames.size(); ++i) { 68 if (Page* page = m_deferredFrames[i]->page()) { 69 page->setDefersLoading(false); 70 71 for (Frame* frame = page->mainFrame(); frame; frame = frame->tree().traverseNext()) { 72 if (frame->isLocalFrame()) 73 toLocalFrame(frame)->document()->resumeScheduledTasks(); 74 } 75 } 76 } 77 } 78 79 #if ENABLE(OILPAN) 80 void ScopedPageLoadDeferrer::dispose() 81 { 82 detach(); 83 m_deferredFrames.clear(); 84 } 85 #endif 86 87 ScopedPageLoadDeferrer::~ScopedPageLoadDeferrer() 88 { 89 detach(); 90 } 91 92 void ScopedPageLoadDeferrer::trace(Visitor* visitor) 93 { 94 #if ENABLE(OILPAN) 95 visitor->trace(m_deferredFrames); 96 #endif 97 } 98 99 } // namespace blink 100