/src/3rdparty/webkit/Source/WebCore/page/PageGroupLoadDeferrer.cpp

https://bitbucket.org/ultra_iter/qt-vtl · C++ · 86 lines · 51 code · 12 blank · 23 comment · 14 complexity · c6f97ce3d51e9b9759a35a95ef69b8fb MD5 · raw file

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