PassRefPtr<WebFrame> InjectedBundleNodeHandle::htmlIFrameElementContentFrame()
{
    if (!m_node->hasTagName(iframeTag))
        return 0;

    Frame* frame = toHTMLIFrameElement(m_node.get())->contentFrame();
    if (!frame)
        return 0;

    WebFrameLoaderClient* webFrameLoaderClient = toWebFrameLoaderClient(frame->loader().client());
    return webFrameLoaderClient ? webFrameLoaderClient->webFrame() : 0;
}
示例#2
0
static v8::Handle<v8::Value> getNamedProperty(HTMLDocument* htmlDocument, const AtomicString& key, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
{
    if (!htmlDocument->hasNamedItem(key) && !htmlDocument->hasExtraNamedItem(key))
        return v8Undefined();

    RefPtr<HTMLCollection> items = htmlDocument->documentNamedItems(key);
    if (items->isEmpty())
        return v8Undefined();

    if (items->hasExactlyOneItem()) {
        Node* node = items->item(0);
        Frame* frame = 0;
        if (node->hasTagName(HTMLNames::iframeTag) && (frame = toHTMLIFrameElement(node)->contentFrame()))
            return toV8(frame->domWindow(), creationContext, isolate);
        return toV8(node, creationContext, isolate);
    }
    return toV8(items.release(), creationContext, isolate);
}
示例#3
0
Document& RenderingTest::setupChildIframe(const AtomicString& iframeElementId, const String& htmlContentOfIframe)
{

    HTMLIFrameElement& iframe = *toHTMLIFrameElement(document().getElementById(iframeElementId));
    m_frameLoaderClient = FrameLoaderClientWithParent::create(document().frame());
    m_subframe = LocalFrame::create(m_frameLoaderClient.get(), document().frame()->host(), &iframe);
    m_subframe->setView(FrameView::create(m_subframe.get(), IntSize(500, 500)));
    m_subframe->init();
    m_subframe->view()->setParentVisible(true);
    m_subframe->view()->setSelfVisible(true);
    static_cast<SingleChildFrameLoaderClient*>(document().frame()->client())->setChild(m_subframe.get());
    document().frame()->host()->incrementSubframeCount();
    Document& frameDocument = *iframe.contentDocument();

    frameDocument.setBaseURLOverride(KURL(ParsedURLString, "http://test.com"));
    frameDocument.body()->setInnerHTML(htmlContentOfIframe, ASSERT_NO_EXCEPTION);
    return frameDocument;
}
static v8::Local<v8::Value> getNamedProperty(HTMLDocument* htmlDocument, const AtomicString& key, v8::Local<v8::Object> creationContext, v8::Isolate* isolate)
{
    if (!htmlDocument->hasNamedItem(key) && !htmlDocument->hasExtraNamedItem(key))
        return v8Undefined();

    RefPtrWillBeRawPtr<DocumentNameCollection> items = htmlDocument->documentNamedItems(key);
    if (items->isEmpty())
        return v8Undefined();

    if (items->hasExactlyOneItem()) {
        HTMLElement* element = items->item(0);
        ASSERT(element);
        Frame* frame = isHTMLIFrameElement(*element) ? toHTMLIFrameElement(*element).contentFrame() : 0;
        if (frame)
            return toV8(frame->domWindow(), creationContext, isolate);
        return toV8(element, creationContext, isolate);
    }
    return toV8(PassRefPtrWillBeRawPtr<HTMLCollection>(items.release()), creationContext, isolate);
}
TEST_F(PrintContextFrameTest, WithScrolledSubframe)
{
    MockCanvas canvas;
    document().setBaseURLOverride(KURL(ParsedURLString, "http://a.com/"));
    setBodyInnerHTML("<style>::-webkit-scrollbar { display: none }</style>"
        "<iframe id='frame' src='http://b.com/' width='500' height='500'"
        " style='border-width: 5px; margin: 5px; position: absolute; top: 90px; left: 90px'></iframe>");

    HTMLIFrameElement& iframe = *toHTMLIFrameElement(document().getElementById("frame"));
    OwnPtrWillBeRawPtr<FrameLoaderClient> frameLoaderClient = FrameLoaderClientWithParent::create(document().frame());
    RefPtrWillBePersistent<LocalFrame> subframe = LocalFrame::create(frameLoaderClient.get(), document().frame()->host(), &iframe);
    subframe->setView(FrameView::create(subframe.get(), IntSize(500, 500)));
    subframe->init();
    static_cast<SingleChildFrameLoaderClient*>(document().frame()->client())->setChild(subframe.get());
    document().frame()->host()->incrementSubframeCount();

    Document& frameDocument = *iframe.contentDocument();
    frameDocument.setBaseURLOverride(KURL(ParsedURLString, "http://b.com/"));
    frameDocument.body()->setInnerHTML(
        absoluteBlockHtmlForLink(10, 10, 20, 20, "http://invisible.com")
        + absoluteBlockHtmlForLink(50, 60, 70, 80, "http://partly.visible.com")
        + absoluteBlockHtmlForLink(150, 160, 170, 180, "http://www.google.com")
        + absoluteBlockHtmlForLink(250, 260, 270, 280, "http://www.google.com#fragment")
        + absoluteBlockHtmlForLink(850, 860, 70, 80, "http://another.invisible.com"),
        ASSERT_NO_EXCEPTION);
    iframe.contentWindow()->scrollTo(100, 100);

    printSinglePage(canvas);

    const Vector<MockCanvas::Operation>& operations = canvas.recordedOperations();
    ASSERT_EQ(3u, operations.size());
    EXPECT_EQ(MockCanvas::DrawRect, operations[0].type);
    EXPECT_SKRECT_EQ(50, 60, 70, 80, operations[0].rect); // FIXME: the rect should be clipped.
    EXPECT_EQ(MockCanvas::DrawRect, operations[1].type);
    EXPECT_SKRECT_EQ(150, 160, 170, 180, operations[1].rect);
    EXPECT_EQ(MockCanvas::DrawRect, operations[2].type);
    EXPECT_SKRECT_EQ(250, 260, 270, 280, operations[2].rect);

    subframe->detach(FrameDetachType::Remove);
    static_cast<SingleChildFrameLoaderClient*>(document().frame()->client())->setChild(nullptr);
    document().frame()->host()->decrementSubframeCount();
}
Document& RenderingTest::setupChildIframe(const AtomicString& iframeElementId, const String& htmlContentOfIframe)
{
    // TODO(pdr): This should be refactored to share code with the actual setup
    // instead of partially duplicating it here (e.g., LocalFrame::createView).
    HTMLIFrameElement& iframe = *toHTMLIFrameElement(document().getElementById(iframeElementId));
    m_childFrameLoaderClient = FrameLoaderClientWithParent::create(document().frame());
    m_subframe = LocalFrame::create(m_childFrameLoaderClient.get(), document().frame()->host(), &iframe);
    m_subframe->setView(FrameView::create(m_subframe.get(), IntSize(500, 500)));
    m_subframe->init();
    m_subframe->view()->setParentVisible(true);
    m_subframe->view()->setSelfVisible(true);
    iframe.setWidget(m_subframe->view());
    static_cast<SingleChildFrameLoaderClient*>(document().frame()->client())->setChild(m_subframe.get());
    document().frame()->host()->incrementSubframeCount();
    Document& frameDocument = *iframe.contentDocument();

    frameDocument.setBaseURLOverride(KURL(ParsedURLString, "http://test.com"));
    frameDocument.body()->setInnerHTML(htmlContentOfIframe, ASSERT_NO_EXCEPTION);
    return frameDocument;
}