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

Unified Diff: Source/core/frame/Frame.cpp

Issue 183713002: Add Frame and RemoteFrame classes. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Added RemoteFrame Created 6 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: Source/core/frame/Frame.cpp
diff --git a/Source/core/frame/Frame.cpp b/Source/core/frame/Frame.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..1bce84097a3fd1145063f033d9cd17e4435589ab
--- /dev/null
+++ b/Source/core/frame/Frame.cpp
@@ -0,0 +1,157 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
eseidel 2014/03/04 01:33:00 We can't re-license existing code. Please copy th
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#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/RenderView.h"
+#include "public/platform/WebLayer.h"
+#include "wtf/PassOwnPtr.h"
+#include "wtf/RefCountedLeakCounter.h"
+
+namespace WebCore {
+
+using namespace HTMLNames;
+
+namespace {
+
+int64_t generateFrameID()
+{
+ // Initialize to the current time to reduce the likelihood of generating
+ // identifiers that overlap with those from past/future browser sessions.
+ static int64_t next = static_cast<int64_t>(currentTime() * 1000000.0);
+ return ++next;
+}
+
+} // namespace
+
+DEFINE_DEBUG_ONLY_GLOBAL(WTF::RefCountedLeakCounter, frameCounter, ("Frame"));
+
+Frame::Frame(PassRefPtr<FrameInit> frameInit)
+ : m_frameInit(frameInit)
+ , m_host(m_frameInit->frameHost())
+ , m_frameID(generateFrameID())
+ , m_remotePlatformLayer(0)
+{
+ ASSERT(page());
+
+#ifndef NDEBUG
+ frameCounter.increment();
+#endif
+}
+
+Frame::~Frame()
+{
+ setDOMWindow(nullptr);
+
+ // FIXME: We should not be doing all this work inside the destructor
+
+#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(PassRefPtr<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;
+}
+
+void Frame::willDetachFrameHost()
+{
+ HashSet<FrameDestructionObserver*>::iterator stop = m_destructionObservers.end();
+ for (HashSet<FrameDestructionObserver*>::iterator it = m_destructionObservers.begin(); it != stop; ++it)
+ (*it)->willDetachFrameHost();
+
+ // FIXME: Page should take care of updating focus/scrolling instead of Frame.
+ // FIXME: It's unclear as to why this is called more than once, but it is,
+ // so page() could be null.
+ 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();
+}
+
+} // namespace WebCore

Powered by Google App Engine
This is Rietveld 408576698