OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "config.h" |
| 6 #include "core/frame/Frame.h" |
| 7 |
| 8 #include "core/dom/DocumentType.h" |
| 9 #include "core/events/Event.h" |
| 10 #include "core/frame/DOMWindow.h" |
| 11 #include "core/frame/FrameDestructionObserver.h" |
| 12 #include "core/frame/FrameHost.h" |
| 13 #include "core/frame/Settings.h" |
| 14 #include "core/html/HTMLFrameElementBase.h" |
| 15 #include "core/inspector/InspectorInstrumentation.h" |
| 16 #include "core/loader/EmptyClients.h" |
| 17 #include "core/loader/FrameLoaderClient.h" |
| 18 #include "core/page/Chrome.h" |
| 19 #include "core/page/ChromeClient.h" |
| 20 #include "core/page/EventHandler.h" |
| 21 #include "core/page/FocusController.h" |
| 22 #include "core/page/Page.h" |
| 23 #include "core/rendering/RenderView.h" |
| 24 #include "public/platform/WebLayer.h" |
| 25 #include "wtf/PassOwnPtr.h" |
| 26 #include "wtf/RefCountedLeakCounter.h" |
| 27 |
| 28 namespace WebCore { |
| 29 |
| 30 using namespace HTMLNames; |
| 31 |
| 32 namespace { |
| 33 |
| 34 int64_t generateFrameID() |
| 35 { |
| 36 // Initialize to the current time to reduce the likelihood of generating |
| 37 // identifiers that overlap with those from past/future browser sessions. |
| 38 static int64_t next = static_cast<int64_t>(currentTime() * 1000000.0); |
| 39 return ++next; |
| 40 } |
| 41 |
| 42 } // namespace |
| 43 |
| 44 DEFINE_DEBUG_ONLY_GLOBAL(WTF::RefCountedLeakCounter, frameCounter, ("Frame")); |
| 45 |
| 46 Frame::Frame(PassRefPtr<FrameInit> frameInit) |
| 47 : m_frameInit(frameInit) |
| 48 , m_host(m_frameInit->frameHost()) |
| 49 , m_frameID(generateFrameID()) |
| 50 , m_remotePlatformLayer(0) |
| 51 { |
| 52 ASSERT(page()); |
| 53 |
| 54 #ifndef NDEBUG |
| 55 frameCounter.increment(); |
| 56 #endif |
| 57 } |
| 58 |
| 59 Frame::~Frame() |
| 60 { |
| 61 setDOMWindow(nullptr); |
| 62 |
| 63 // FIXME: We should not be doing all this work inside the destructor |
| 64 |
| 65 #ifndef NDEBUG |
| 66 frameCounter.decrement(); |
| 67 #endif |
| 68 |
| 69 HashSet<FrameDestructionObserver*>::iterator stop = m_destructionObservers.e
nd(); |
| 70 for (HashSet<FrameDestructionObserver*>::iterator it = m_destructionObserver
s.begin(); it != stop; ++it) |
| 71 (*it)->frameDestroyed(); |
| 72 } |
| 73 |
| 74 void Frame::addDestructionObserver(FrameDestructionObserver* observer) |
| 75 { |
| 76 m_destructionObservers.add(observer); |
| 77 } |
| 78 |
| 79 void Frame::removeDestructionObserver(FrameDestructionObserver* observer) |
| 80 { |
| 81 m_destructionObservers.remove(observer); |
| 82 } |
| 83 |
| 84 FrameHost* Frame::host() const |
| 85 { |
| 86 return m_host; |
| 87 } |
| 88 |
| 89 Page* Frame::page() const |
| 90 { |
| 91 if (m_host) |
| 92 return &m_host->page(); |
| 93 return 0; |
| 94 } |
| 95 |
| 96 Settings* Frame::settings() const |
| 97 { |
| 98 if (m_host) |
| 99 return &m_host->settings(); |
| 100 return 0; |
| 101 } |
| 102 |
| 103 void Frame::setDOMWindow(PassRefPtr<DOMWindow> domWindow) |
| 104 { |
| 105 if (m_domWindow) |
| 106 m_domWindow->reset(); |
| 107 m_domWindow = domWindow; |
| 108 } |
| 109 |
| 110 static ChromeClient& emptyChromeClient() |
| 111 { |
| 112 DEFINE_STATIC_LOCAL(EmptyChromeClient, client, ()); |
| 113 return client; |
| 114 } |
| 115 |
| 116 ChromeClient& Frame::chromeClient() const |
| 117 { |
| 118 if (Page* page = this->page()) |
| 119 return page->chrome().client(); |
| 120 return emptyChromeClient(); |
| 121 } |
| 122 |
| 123 Document* Frame::document() const |
| 124 { |
| 125 return m_domWindow ? m_domWindow->document() : 0; |
| 126 } |
| 127 |
| 128 RenderView* Frame::contentRenderer() const |
| 129 { |
| 130 return document() ? document()->renderView() : 0; |
| 131 } |
| 132 |
| 133 void Frame::willDetachFrameHost() |
| 134 { |
| 135 HashSet<FrameDestructionObserver*>::iterator stop = m_destructionObservers.e
nd(); |
| 136 for (HashSet<FrameDestructionObserver*>::iterator it = m_destructionObserver
s.begin(); it != stop; ++it) |
| 137 (*it)->willDetachFrameHost(); |
| 138 |
| 139 // FIXME: Page should take care of updating focus/scrolling instead of Frame
. |
| 140 // FIXME: It's unclear as to why this is called more than once, but it is, |
| 141 // so page() could be null. |
| 142 if (page() && page()->focusController().focusedFrame() == this) |
| 143 page()->focusController().setFocusedFrame(nullptr); |
| 144 } |
| 145 |
| 146 void Frame::detachFromFrameHost() |
| 147 { |
| 148 m_host = 0; |
| 149 } |
| 150 |
| 151 bool Frame::isMainFrame() const |
| 152 { |
| 153 Page* page = this->page(); |
| 154 return page && this == page->mainFrame(); |
| 155 } |
| 156 |
| 157 } // namespace WebCore |
OLD | NEW |