Commit 2c871c9e authored by dglazkov@chromium.org's avatar dglazkov@chromium.org

Make HTMLImportTreeNode own the whole import tree.

Since the lifetimes of HTMLImportTreeNode and all of its
descendants are inextricably linked, it makes sense for
all ownership responsibilities to be transfered from
HTMLImportsController to HTMLImportTreeNode.

No functional changes, refactoring.

R=morrita
BUG=

Review URL: https://codereview.chromium.org/305723004

git-svn-id: svn://svn.chromium.org/blink/trunk@175162 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent c96587a6
......@@ -56,7 +56,7 @@ class KURL;
// * The HTMLImportTreeRoot is owned HTMLImportsController, which is owned by the master
// document as a DocumentSupplement.
//
// * The non-root nodes are HTMLImportChild. They are also owned by HTMLImportsController.
// * The non-root nodes are HTMLImportChild. They are all owned by HTMLImporTreeRoot.
// LinkStyle is wired into HTMLImportChild by implementing HTMLImportChildClient interface
//
// * Both HTMLImportTreeRoot and HTMLImportChild are derived from HTMLImport superclass
......@@ -66,6 +66,8 @@ class KURL;
// HTMLImportsController also owns all loaders in the tree and manages their lifetime through it.
// One assumption is that the tree is append-only and nodes are never inserted in the middle of the tree nor removed.
//
// Full diagram is here:
// https://docs.google.com/drawings/d/1jFQrO0IupWrlykTNzQ3Nv2SdiBiSz4UE9-V3-vDgBb0/
//
// # Import Sharing and HTMLImportLoader
//
......
......@@ -8,6 +8,7 @@
#include "core/dom/Document.h"
#include "core/dom/StyleEngine.h"
#include "core/frame/LocalFrame.h"
#include "core/html/imports/HTMLImportChild.h"
namespace WebCore {
......@@ -24,6 +25,13 @@ HTMLImportTreeRoot::HTMLImportTreeRoot(Document* document)
recalcTreeState(this); // This recomputes initial state.
}
HTMLImportTreeRoot::~HTMLImportTreeRoot()
{
for (size_t i = 0; i < m_imports.size(); ++i)
m_imports[i]->importDestroyed();
m_imports.clear();
}
Document* HTMLImportTreeRoot::document() const
{
return m_document;
......@@ -56,6 +64,23 @@ void HTMLImportTreeRoot::scheduleRecalcState()
m_recalcTimer.startOneShot(0, FROM_HERE);
}
HTMLImportChild* HTMLImportTreeRoot::add(PassOwnPtr<HTMLImportChild> child)
{
m_imports.append(child);
return m_imports.last().get();
}
HTMLImportChild* HTMLImportTreeRoot::find(const KURL& url) const
{
for (size_t i = 0; i < m_imports.size(); ++i) {
HTMLImportChild* candidate = m_imports[i].get();
if (equalIgnoringFragmentIdentifier(candidate->url(), url))
return candidate;
}
return 0;
}
void HTMLImportTreeRoot::recalcTimerFired(Timer<HTMLImportTreeRoot>*)
{
ASSERT(m_document);
......
......@@ -11,10 +11,14 @@
namespace WebCore {
class HTMLImportChild;
class HTMLImportTreeRoot : public HTMLImport {
public:
static PassOwnPtr<HTMLImportTreeRoot> create(Document*);
virtual ~HTMLImportTreeRoot();
// HTMLImport
virtual Document* document() const OVERRIDE;
virtual bool isDone() const OVERRIDE;
......@@ -23,6 +27,9 @@ public:
void scheduleRecalcState();
HTMLImportChild* add(PassOwnPtr<HTMLImportChild>);
HTMLImportChild* find(const KURL&) const;
private:
explicit HTMLImportTreeRoot(Document*);
......@@ -30,6 +37,10 @@ private:
Document* m_document;
Timer<HTMLImportTreeRoot> m_recalcTimer;
// List of import which has been loaded or being loaded.
typedef Vector<OwnPtr<HTMLImportChild> > ImportList;
ImportList m_imports;
};
DEFINE_TYPE_CASTS(HTMLImportTreeRoot, HTMLImport, import, import->isRoot(), import.isRoot());
......
......@@ -62,9 +62,7 @@ HTMLImportsController::~HTMLImportsController()
void HTMLImportsController::clear()
{
for (size_t i = 0; i < m_imports.size(); ++i)
m_imports[i]->importDestroyed();
m_imports.clear();
m_root.clear();
for (size_t i = 0; i < m_loaders.size(); ++i)
m_loaders[i]->importDestroyed();
......@@ -94,8 +92,7 @@ HTMLImportChild* HTMLImportsController::createChild(const KURL& url, HTMLImportL
child->setClient(client);
parent->appendImport(child.get());
loader->addImport(child.get());
m_imports.append(child.release());
return m_imports.last().get();
return root()->add(child.release());
}
HTMLImportChild* HTMLImportsController::load(HTMLImport* parent, HTMLImportChildClient* client, FetchRequest request)
......@@ -103,7 +100,7 @@ HTMLImportChild* HTMLImportsController::load(HTMLImport* parent, HTMLImportChild
ASSERT(!request.url().isEmpty() && request.url().isValid());
ASSERT(parent == root() || toHTMLImportChild(parent)->loader()->isFirstImport(toHTMLImportChild(parent)));
if (HTMLImportChild* childToShareWith = findLinkFor(request.url())) {
if (HTMLImportChild* childToShareWith = root()->find(request.url())) {
HTMLImportLoader* loader = childToShareWith->loader();
ASSERT(loader);
HTMLImportChild* child = createChild(request.url(), loader, parent, client);
......@@ -134,17 +131,6 @@ void HTMLImportsController::showSecurityErrorMessage(const String& message)
m_master->addConsoleMessage(JSMessageSource, ErrorMessageLevel, message);
}
HTMLImportChild* HTMLImportsController::findLinkFor(const KURL& url) const
{
for (size_t i = 0; i < m_imports.size(); ++i) {
HTMLImportChild* candidate = m_imports[i].get();
if (equalIgnoringFragmentIdentifier(candidate->url(), url) && candidate->loader())
return candidate;
}
return 0;
}
SecurityOrigin* HTMLImportsController::securityOrigin() const
{
return m_master->securityOrigin();
......
......@@ -73,15 +73,12 @@ public:
LocalFrame* frame() const;
Document* master() const { return m_master; }
HTMLImportLoader* createLoader();
size_t loaderCount() const { return m_loaders.size(); }
HTMLImportLoader* loaderAt(size_t i) const { return m_loaders[i].get(); }
HTMLImportLoader* loaderFor(const Document&) const;
HTMLImportChild* findLinkFor(const KURL&) const;
private:
HTMLImportChild* createChild(const KURL&, HTMLImportLoader*, HTMLImport* parent, HTMLImportChildClient*);
void clear();
......@@ -90,10 +87,6 @@ private:
OwnPtr<HTMLImportTreeRoot> m_root;
// List of import which has been loaded or being loaded.
typedef Vector<OwnPtr<HTMLImportChild> > ImportList;
ImportList m_imports;
typedef Vector<OwnPtr<HTMLImportLoader> > LoaderList;
LoaderList m_loaders;
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment