This source file includes following definitions.
- generateFrameID
- m_remotePlatformLayer
- addDestructionObserver
- removeDestructionObserver
- host
- page
- settings
- setDOMWindow
- emptyChromeClient
- chromeClient
- document
- contentRenderer
- ownerRenderer
- willDetachFrameHost
- detachFromFrameHost
- isMainFrame
- disconnectOwnerElement
#include "config.h"
#include "core/frame/Frame.h"
#include "core/dom/DocumentType.h"
#include "core/events/Event.h"
#include "core/frame/DOMWindow.h"
#include "core/frame/FrameDestructionObserver.h"
#include "core/frame/FrameHost.h"
#include "core/frame/Settings.h"
#include "core/html/HTMLFrameElementBase.h"
#include "core/inspector/InspectorInstrumentation.h"
#include "core/loader/EmptyClients.h"
#include "core/loader/FrameLoaderClient.h"
#include "core/page/Chrome.h"
#include "core/page/ChromeClient.h"
#include "core/page/EventHandler.h"
#include "core/page/FocusController.h"
#include "core/page/Page.h"
#include "core/rendering/RenderPart.h"
#include "core/rendering/RenderView.h"
#include "public/platform/WebLayer.h"
#include "wtf/PassOwnPtr.h"
#include "wtf/RefCountedLeakCounter.h"
namespace WebCore {
using namespace HTMLNames;
namespace {
int64_t generateFrameID()
{
static int64_t next = static_cast<int64_t>(currentTime() * 1000000.0);
return ++next;
}
}
DEFINE_DEBUG_ONLY_GLOBAL(WTF::RefCountedLeakCounter, frameCounter, ("Frame"));
Frame::Frame(FrameHost* host, HTMLFrameOwnerElement* ownerElement)
: m_host(host)
, m_ownerElement(ownerElement)
, m_frameID(generateFrameID())
, m_remotePlatformLayer(0)
{
ASSERT(page());
#ifndef NDEBUG
frameCounter.increment();
#endif
if (this->ownerElement()) {
page()->incrementSubframeCount();
this->ownerElement()->setContentFrame(*this);
}
}
Frame::~Frame()
{
disconnectOwnerElement();
setDOMWindow(nullptr);
#ifndef NDEBUG
frameCounter.decrement();
#endif
HashSet<FrameDestructionObserver*>::iterator stop = m_destructionObservers.end();
for (HashSet<FrameDestructionObserver*>::iterator it = m_destructionObservers.begin(); it != stop; ++it)
(*it)->frameDestroyed();
}
void Frame::addDestructionObserver(FrameDestructionObserver* observer)
{
m_destructionObservers.add(observer);
}
void Frame::removeDestructionObserver(FrameDestructionObserver* observer)
{
m_destructionObservers.remove(observer);
}
FrameHost* Frame::host() const
{
return m_host;
}
Page* Frame::page() const
{
if (m_host)
return &m_host->page();
return 0;
}
Settings* Frame::settings() const
{
if (m_host)
return &m_host->settings();
return 0;
}
void Frame::setDOMWindow(PassRefPtrWillBeRawPtr<DOMWindow> domWindow)
{
if (m_domWindow)
m_domWindow->reset();
m_domWindow = domWindow;
}
static ChromeClient& emptyChromeClient()
{
DEFINE_STATIC_LOCAL(EmptyChromeClient, client, ());
return client;
}
ChromeClient& Frame::chromeClient() const
{
if (Page* page = this->page())
return page->chrome().client();
return emptyChromeClient();
}
Document* Frame::document() const
{
return m_domWindow ? m_domWindow->document() : 0;
}
RenderView* Frame::contentRenderer() const
{
return document() ? document()->renderView() : 0;
}
RenderPart* Frame::ownerRenderer() const
{
if (!ownerElement())
return 0;
RenderObject* object = ownerElement()->renderer();
if (!object)
return 0;
if (!object->isRenderPart())
return 0;
return toRenderPart(object);
}
void Frame::willDetachFrameHost()
{
HashSet<FrameDestructionObserver*>::iterator stop = m_destructionObservers.end();
for (HashSet<FrameDestructionObserver*>::iterator it = m_destructionObservers.begin(); it != stop; ++it)
(*it)->willDetachFrameHost();
if (page() && page()->focusController().focusedFrame() == this)
page()->focusController().setFocusedFrame(nullptr);
}
void Frame::detachFromFrameHost()
{
m_host = 0;
}
bool Frame::isMainFrame() const
{
Page* page = this->page();
return page && this == page->mainFrame();
}
void Frame::disconnectOwnerElement()
{
if (ownerElement()) {
if (Document* doc = document())
doc->topDocument().clearAXObjectCache();
ownerElement()->clearContentFrame();
if (page())
page()->decrementSubframeCount();
}
m_ownerElement = 0;
}
}