void InspectorNodeFinder::searchUsingDOMTreeTraversal(Node* parentNode) { // Manual plain text search. for (auto node = parentNode; node; node = NodeTraversal::next(node, parentNode)) { switch (node->nodeType()) { case Node::TEXT_NODE: case Node::COMMENT_NODE: case Node::CDATA_SECTION_NODE: { if (node->nodeValue().findIgnoringCase(m_whitespaceTrimmedQuery) != notFound) m_results.add(node); break; } case Node::ELEMENT_NODE: { if (matchesElement(*toElement(node))) m_results.add(node); // Search inside frame elements. if (node->isFrameOwnerElement()) { HTMLFrameOwnerElement* frameOwner = toHTMLFrameOwnerElement(node); if (Document* document = frameOwner->contentDocument()) performSearch(document); } break; } default: break; } } }
static unsigned checkConnectedSubframeCountIsConsistent(Node& node) { unsigned count = 0; if (node.isElementNode()) { if (node.isFrameOwnerElement() && toHTMLFrameOwnerElement(node).contentFrame()) count++; if (ElementShadow* shadow = toElement(node).shadow()) { for (ShadowRoot* root = &shadow->youngestShadowRoot(); root; root = root->olderShadowRoot()) count += checkConnectedSubframeCountIsConsistent(*root); } } for (Node* child = node.firstChild(); child; child = child->nextSibling()) count += checkConnectedSubframeCountIsConsistent(*child); // If we undercount there's possibly a security bug since we'd leave frames // in subtrees outside the document. ASSERT(node.connectedSubframeCount() >= count); // If we overcount it's safe, but not optimal because it means we'll traverse // through the document in ChildFrameDisconnector looking for frames that have // already been disconnected. ASSERT(node.connectedSubframeCount() == count); return count; }
WebFrame* WebFrame::fromFrameOwnerElement(const WebElement& webElement) { Element* element = webElement; if (!element->isFrameOwnerElement()) return nullptr; return fromFrame(toHTMLFrameOwnerElement(element)->contentFrame()); }
WebFrame* WebFrame::fromFrameOwnerElement(const WebElement& webElement) { Element* element = PassRefPtrWillBeRawPtr<Element>(webElement).get(); if (!element->isFrameOwnerElement()) return nullptr; return fromFrame(toHTMLFrameOwnerElement(element)->contentFrame()); }
void Frame::disconnectOwnerElement() { if (m_owner) { if (m_owner->isLocal()) toHTMLFrameOwnerElement(m_owner)->clearContentFrame(); } m_owner = nullptr; }
void Fullscreen::didEnterFullscreenForElement(Element* element) { DCHECK(element); if (!document()->isActive()) return; if (m_fullScreenLayoutObject) m_fullScreenLayoutObject->unwrapLayoutObject(); m_currentFullScreenElement = element; // Create a placeholder block for a the full-screen element, to keep the page // from reflowing when the element is removed from the normal flow. Only do // this for a LayoutBox, as only a box will have a frameRect. The placeholder // will be created in setFullScreenLayoutObject() during layout. LayoutObject* layoutObject = m_currentFullScreenElement->layoutObject(); bool shouldCreatePlaceholder = layoutObject && layoutObject->isBox(); if (shouldCreatePlaceholder) { m_savedPlaceholderFrameRect = toLayoutBox(layoutObject)->frameRect(); m_savedPlaceholderComputedStyle = ComputedStyle::clone(layoutObject->styleRef()); } // TODO(alexmos): When |m_forCrossProcessDescendant| is true, some of // this layout work has already been done in another process, so it should // not be necessary to repeat it here. if (m_currentFullScreenElement != document()->documentElement()) LayoutFullScreen::wrapLayoutObject( layoutObject, layoutObject ? layoutObject->parent() : 0, document()); // When |m_forCrossProcessDescendant| is true, m_currentFullScreenElement // corresponds to the HTMLFrameOwnerElement for the out-of-process iframe // that contains the actual fullscreen element. Hence, it must also set // the ContainsFullScreenElement flag (so that it gains the // -webkit-full-screen-ancestor style). if (m_forCrossProcessDescendant) { DCHECK(m_currentFullScreenElement->isFrameOwnerElement()); DCHECK(toHTMLFrameOwnerElement(m_currentFullScreenElement) ->contentFrame() ->isRemoteFrame()); m_currentFullScreenElement->setContainsFullScreenElement(true); } m_currentFullScreenElement ->setContainsFullScreenElementOnAncestorsCrossingFrameBoundaries(true); document()->styleEngine().ensureFullscreenUAStyle(); m_currentFullScreenElement->pseudoStateChanged(CSSSelector::PseudoFullScreen); // FIXME: This should not call updateStyleAndLayoutTree. document()->updateStyleAndLayoutTree(); m_currentFullScreenElement->didBecomeFullscreenElement(); if (document()->frame()) document()->frame()->eventHandler().scheduleHoverStateUpdate(); m_eventQueueTimer.startOneShot(0, BLINK_FROM_HERE); }
void WebFrameSerializerImpl::openTagToString( Element* element, SerializeDomParam* param) { bool needSkip; StringBuilder result; // Do pre action for open tag. result.append(preActionBeforeSerializeOpenTag(element, param, &needSkip)); if (needSkip) return; // Add open tag result.append('<'); result.append(element->nodeName().lower()); // Find out if this element owns a frame. WebFrame* frame = nullptr; if (element->isFrameOwnerElement()) { frame = WebFrame::fromFrame( toHTMLFrameOwnerElement(element)->contentFrame()); } // Go through all attributes and serialize them. for (const auto& it : element->attributes()) { const QualifiedName& attrName = it.name(); String attrValue = it.value(); // Rewrite the attribute value if requested. if (element->hasLegalLinkAttribute(attrName)) { // For links start with "javascript:", we do not change it. if (!attrValue.startsWith("javascript:", TextCaseInsensitive)) { // Get the absolute link. KURL completeURL = param->document->completeURL(attrValue); // Check whether we have a local file to link to. WebString rewrittenLink; if (frame && m_delegate->rewriteFrameSource(frame, &rewrittenLink)) { attrValue = rewrittenLink; } else if (m_delegate->rewriteLink(completeURL, &rewrittenLink)) { attrValue = rewrittenLink; } else { attrValue = completeURL; } } } appendAttribute(result, param->isHTMLDocument, attrName.toString(), attrValue); } // Do post action for open tag. String addedContents = postActionAfterSerializeOpenTag(element, param); // Complete the open tag for element when it has child/children. if (element->hasChildren() || param->haveAddedContentsBeforeEnd) result.append('>'); // Append the added contents generate in post action of open tag. result.append(addedContents); // Save the result to data buffer. saveHTMLContentToBuffer(result.toString(), param); }
Widget* LayoutPart::widget() const { // Plugin widgets are stored in their DOM node. Element* element = toElement(node()); if (element && element->isFrameOwnerElement()) return toHTMLFrameOwnerElement(element)->ownedWidget(); return nullptr; }
Widget* RenderWidget::widget() const { // Plugin widgets are stored in their DOM node. This includes HTMLAppletElement. Element* element = toElement(node()); if (element && element->isFrameOwnerElement()) return toHTMLFrameOwnerElement(element)->ownedWidget(); return 0; }
PaintLayerCompositor* PaintLayerCompositor::frameContentsCompositor(LayoutPart* layoutObject) { if (!layoutObject->node()->isFrameOwnerElement()) return nullptr; HTMLFrameOwnerElement* element = toHTMLFrameOwnerElement(layoutObject->node()); if (Document* contentDocument = element->contentDocument()) { if (LayoutView* view = contentDocument->layoutView()) return view->compositor(); } return nullptr; }
void RemoteFrame::setRemotePlatformLayer(WebLayer* layer) { if (m_remotePlatformLayer) GraphicsLayer::unregisterContentsLayer(m_remotePlatformLayer); m_remotePlatformLayer = layer; if (m_remotePlatformLayer) GraphicsLayer::registerContentsLayer(layer); ASSERT(owner()); toHTMLFrameOwnerElement(owner())->setNeedsCompositingUpdate(); if (LayoutPart* layoutObject = ownerLayoutObject()) layoutObject->layer()->updateSelfPaintingLayer(); }
void LayoutPart::willBeDestroyed() { frameView()->removePart(this); if (AXObjectCache* cache = document().existingAXObjectCache()) { cache->childrenChanged(this->parent()); cache->remove(this); } Element* element = toElement(node()); if (element && element->isFrameOwnerElement()) toHTMLFrameOwnerElement(element)->setWidget(nullptr); LayoutReplaced::willBeDestroyed(); }
void ChildFrameDisconnector::collectFrameOwners(Node& root) { if (!root.connectedSubframeCount()) return; if (root.isHTMLElement() && root.isFrameOwnerElement()) m_frameOwners.append(&toHTMLFrameOwnerElement(root)); for (Node* child = root.firstChild(); child; child = child->nextSibling()) collectFrameOwners(*child); ElementShadow* shadow = root.isElementNode() ? toElement(root).shadow() : 0; if (shadow) collectFrameOwners(*shadow); }
void SerializerMarkupAccumulator::appendCustomAttributes(StringBuilder& out, const Element& element, Namespaces* namespaces) { if (!element.isFrameOwnerElement()) return; const HTMLFrameOwnerElement& frameOwner = toHTMLFrameOwnerElement(element); Frame* frame = frameOwner.contentFrame(); if (!frame) return; URL url = frame->document()->url(); if (url.isValid() && !url.isBlankURL()) return; // We need to give a fake location to blank frames so they can be referenced by the serialized frame. url = m_serializer.urlForBlankFrame(frame); appendAttribute(out, element, Attribute(frameOwnerURLAttributeName(frameOwner), url.string()), namespaces); }
void WebRemoteFrameImpl::setReplicatedOrigin(const WebSecurityOrigin& origin) const { ASSERT(frame()); frame()->securityContext()->setReplicatedOrigin(origin); // If the origin of a remote frame changed, the accessibility object for the owner // element now points to a different child. // // TODO(dmazzoni, dcheng): there's probably a better way to solve this. // Run SitePerProcessAccessibilityBrowserTest.TwoCrossSiteNavigations to // ensure an alternate fix works. http://crbug.com/566222 FrameOwner* owner = frame()->owner(); if (owner && owner->isLocal()) { HTMLElement* ownerElement = toHTMLFrameOwnerElement(owner); AXObjectCache* cache = ownerElement->document().existingAXObjectCache(); if (cache) cache->childrenChanged(ownerElement); } }
static LayoutVideo* findFullscreenVideoLayoutObject(Document& document) { // Recursively find the document that is in fullscreen. Element* fullscreenElement = Fullscreen::fullscreenElementFrom(document); Document* contentDocument = &document; while (fullscreenElement && fullscreenElement->isFrameOwnerElement()) { contentDocument = toHTMLFrameOwnerElement(fullscreenElement)->contentDocument(); if (!contentDocument) return nullptr; fullscreenElement = Fullscreen::fullscreenElementFrom(*contentDocument); } // Get the current fullscreen element from the document. fullscreenElement = Fullscreen::currentFullScreenElementFrom(*contentDocument); if (!isHTMLVideoElement(fullscreenElement)) return nullptr; LayoutObject* layoutObject = fullscreenElement->layoutObject(); if (!layoutObject) return nullptr; return toLayoutVideo(layoutObject); }
Element* TopDocumentRootScrollerController::findGlobalRootScrollerElement() { if (!topDocument()) return nullptr; DCHECK(topDocument()->rootScrollerController()); Element* element = topDocument()->rootScrollerController()->effectiveRootScroller(); while (element && element->isFrameOwnerElement()) { HTMLFrameOwnerElement* frameOwner = toHTMLFrameOwnerElement(element); DCHECK(frameOwner); Document* iframeDocument = frameOwner->contentDocument(); if (!iframeDocument) return element; DCHECK(iframeDocument->rootScrollerController()); element = iframeDocument->rootScrollerController()->effectiveRootScroller(); } return element; }
bool LayoutPart::requiresAcceleratedCompositing() const { // There are two general cases in which we can return true. First, if this is a plugin // LayoutObject and the plugin has a layer, then we need a layer. Second, if this is // a LayoutObject with a contentDocument and that document needs a layer, then we need // a layer. if (widget() && widget()->isPluginView() && toPluginView(widget())->platformLayer()) return true; if (!node() || !node()->isFrameOwnerElement()) return false; HTMLFrameOwnerElement* element = toHTMLFrameOwnerElement(node()); if (element->contentFrame() && element->contentFrame()->isRemoteFrame()) return true; if (Document* contentDocument = element->contentDocument()) { if (LayoutView* view = contentDocument->layoutView()) return view->usesCompositing(); } return false; }
static Node* nodeInsideFrame(Node* node) { if (node->isFrameOwnerElement()) return toHTMLFrameOwnerElement(node)->contentDocument(); return 0; }
void WebFrameSerializerImpl::openTagToString( Element* element, SerializeDomParam* param) { bool needSkip; StringBuilder result; // Do pre action for open tag. result.append(preActionBeforeSerializeOpenTag(element, param, &needSkip)); if (needSkip) return; // Add open tag result.append('<'); result.append(element->nodeName().lower()); // Find out if we need to do frame-specific link rewriting. WebFrame* frame = nullptr; if (element->isFrameOwnerElement()) { frame = WebFrame::fromFrame( toHTMLFrameOwnerElement(element)->contentFrame()); } WebString rewrittenFrameLink; bool shouldRewriteFrameSrc = frame && m_delegate->rewriteFrameSource(frame, &rewrittenFrameLink); bool didRewriteFrameSrc = false; // Go through all attributes and serialize them. for (const auto& it : element->attributes()) { const QualifiedName& attrName = it.name(); String attrValue = it.value(); // Skip srcdoc attribute if we will emit src attribute (for frames). if (shouldRewriteFrameSrc && attrName == HTMLNames::srcdocAttr) continue; // Rewrite the attribute value if requested. if (element->hasLegalLinkAttribute(attrName)) { // For links start with "javascript:", we do not change it. if (!attrValue.startsWith("javascript:", TextCaseInsensitive)) { // Get the absolute link. KURL completeURL = param->document->completeURL(attrValue); // Check whether we have a local file to link to. WebString rewrittenURL; if (shouldRewriteFrameSrc) { attrValue = rewrittenFrameLink; didRewriteFrameSrc = true; } else if (m_delegate->rewriteLink(completeURL, &rewrittenURL)) { attrValue = rewrittenURL; } else { attrValue = completeURL; } } } appendAttribute(result, param->isHTMLDocument, attrName.toString(), attrValue); } // For frames where link rewriting was requested, ensure that src attribute // is written even if the original document didn't have that attribute // (mainly needed for iframes with srcdoc, but with no src attribute). if (shouldRewriteFrameSrc && !didRewriteFrameSrc && isHTMLIFrameElement(element)) { appendAttribute( result, param->isHTMLDocument, HTMLNames::srcAttr.toString(), rewrittenFrameLink); } // Do post action for open tag. String addedContents = postActionAfterSerializeOpenTag(element, param); // Complete the open tag for element when it has child/children. if (element->hasChildren() || param->haveAddedContentsBeforeEnd) result.append('>'); // Append the added contents generate in post action of open tag. result.append(addedContents); // Save the result to data buffer. saveHTMLContentToBuffer(result.toString(), param); }
HTMLFrameOwnerElement* frameOwnerElement(FocusCandidate& candidate) { return candidate.isFrameOwnerElement() ? toHTMLFrameOwnerElement(candidate.visibleNode) : nullptr; };
PassRefPtr<LegacyWebArchive> LegacyWebArchive::create(const String& markupString, Frame* frame, const Vector<Node*>& nodes, FrameFilter* frameFilter) { ASSERT(frame); const ResourceResponse& response = frame->loader().documentLoader()->response(); URL responseURL = response.url(); // it's possible to have a response without a URL here // <rdar://problem/5454935> if (responseURL.isNull()) responseURL = URL(ParsedURLString, emptyString()); RefPtr<ArchiveResource> mainResource = ArchiveResource::create(utf8Buffer(markupString), responseURL, response.mimeType(), "UTF-8", frame->tree().uniqueName()); Vector<PassRefPtr<LegacyWebArchive>> subframeArchives; Vector<PassRefPtr<ArchiveResource>> subresources; HashSet<URL> uniqueSubresources; size_t nodesSize = nodes.size(); for (size_t i = 0; i < nodesSize; ++i) { Node& node = *nodes[i]; Frame* childFrame; if ((isHTMLFrameElement(node) || isHTMLIFrameElement(node) || isHTMLObjectElement(node)) && (childFrame = toHTMLFrameOwnerElement(node).contentFrame())) { if (frameFilter && !frameFilter->shouldIncludeSubframe(childFrame)) continue; RefPtr<LegacyWebArchive> subframeArchive = create(childFrame->document(), frameFilter); if (subframeArchive) subframeArchives.append(subframeArchive); else LOG_ERROR("Unabled to archive subframe %s", childFrame->tree().uniqueName().string().utf8().data()); } else { ListHashSet<URL> subresourceURLs; node.getSubresourceURLs(subresourceURLs); DocumentLoader* documentLoader = frame->loader().documentLoader(); ListHashSet<URL>::iterator iterEnd = subresourceURLs.end(); for (ListHashSet<URL>::iterator iter = subresourceURLs.begin(); iter != iterEnd; ++iter) { const URL& subresourceURL = *iter; if (uniqueSubresources.contains(subresourceURL)) continue; uniqueSubresources.add(subresourceURL); RefPtr<ArchiveResource> resource = documentLoader->subresource(subresourceURL); if (resource) { subresources.append(resource.release()); continue; } ResourceRequest request(subresourceURL); #if ENABLE(CACHE_PARTITIONING) request.setCachePartition(frame->document()->topOrigin()->cachePartition()); #endif CachedResource* cachedResource = memoryCache()->resourceForRequest(request); if (cachedResource) { ResourceBuffer* data = cachedResource->resourceBuffer(); resource = ArchiveResource::create(data ? data->sharedBuffer() : 0, subresourceURL, cachedResource->response()); if (resource) { subresources.append(resource.release()); continue; } } // FIXME: should do something better than spew to console here LOG_ERROR("Failed to archive subresource for %s", subresourceURL.string().utf8().data()); } } } // Add favicon if one exists for this page, if we are archiving the entire page. if (nodesSize && nodes[0]->isDocumentNode() && iconDatabase().isEnabled()) { const String& iconURL = iconDatabase().synchronousIconURLForPageURL(responseURL); if (!iconURL.isEmpty() && iconDatabase().synchronousIconDataKnownForIconURL(iconURL)) { if (Image* iconImage = iconDatabase().synchronousIconForPageURL(responseURL, IntSize(16, 16))) { if (RefPtr<ArchiveResource> resource = ArchiveResource::create(iconImage->data(), URL(ParsedURLString, iconURL), "image/x-icon", "", "")) subresources.append(resource.release()); } } } return create(mainResource.release(), subresources, subframeArchives); }
HTMLFrameOwnerElement* Frame::deprecatedLocalOwner() const { return m_owner && m_owner->isLocal() ? toHTMLFrameOwnerElement(m_owner) : nullptr; }