flutter_flutter/engine/core/html/HTMLIFrameElement.cpp
Adam Barth 6f3a5a1496 Move the call to mojo::View::Embed to HTMLIFrameElement
This CL prepares us to expose the imported and exported service providers to
JavaScript. We can't quite do that yet becaues the API on mojo::View isn't
ready for us. However, we can get started by moving the call to Embed into
HTMLIFrameElement.

R=eseidel@chromium.org

Review URL: https://codereview.chromium.org/793393003
2015-01-21 10:49:24 -08:00

78 lines
2.0 KiB
C++

// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "sky/engine/config.h"
#include "sky/engine/core/html/HTMLIFrameElement.h"
#include "gen/sky/core/HTMLNames.h"
#include "sky/engine/core/frame/LocalFrame.h"
#include "sky/engine/core/html/parser/HTMLParserIdioms.h"
#include "sky/engine/core/loader/FrameLoaderClient.h"
#include "sky/engine/core/rendering/RenderIFrame.h"
namespace blink {
PassRefPtr<HTMLIFrameElement> HTMLIFrameElement::create(Document& document)
{
return adoptRef(new HTMLIFrameElement(document));
}
HTMLIFrameElement::HTMLIFrameElement(Document& document)
: HTMLElement(HTMLNames::iframeTag, document),
m_contentView(nullptr)
{
}
HTMLIFrameElement::~HTMLIFrameElement()
{
if (m_contentView)
m_contentView->RemoveObserver(this);
}
void HTMLIFrameElement::insertedInto(ContainerNode* insertionPoint)
{
HTMLElement::insertedInto(insertionPoint);
if (insertionPoint->inDocument())
createView();
}
void HTMLIFrameElement::removedFrom(ContainerNode* insertionPoint)
{
HTMLElement::removedFrom(insertionPoint);
if (m_contentView)
m_contentView->Destroy();
}
RenderObject* HTMLIFrameElement::createRenderer(RenderStyle* style)
{
return new RenderIFrame(this);
}
void HTMLIFrameElement::OnViewDestroyed(mojo::View* view)
{
DCHECK_EQ(view, m_contentView);
m_contentView = nullptr;
}
void HTMLIFrameElement::createView()
{
String urlString = stripLeadingAndTrailingHTMLSpaces(getAttribute(HTMLNames::srcAttr));
if (urlString.isEmpty())
urlString = blankURL().string();
LocalFrame* parentFrame = document().frame();
if (!parentFrame)
return;
KURL url = document().completeURL(urlString);
m_contentView = parentFrame->loaderClient()->createChildFrame();
if (!m_contentView)
return;
m_contentView->Embed(mojo::String::From(url.string().utf8().data()));
m_contentView->AddObserver(this);
}
}