Commit 4432c41b authored by Abhijeet Kandalkar's avatar Abhijeet Kandalkar Committed by Commit Bot

Use new downcast helpers for t_p/blink/renderer/core/{html,loader,svg}

This CL uses new downcast helpers for DocumentAllNameCollection,
DocumentNameCollection and DocumentResource classes.

Bug: 891908
Change-Id: I1e10bc7fa908090cf13e4c271bac010b43d42bc0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1999964Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Commit-Queue: Abhijeet Kandalkar <abhijeet@igalia.com>
Cr-Commit-Position: refs/heads/master@{#733275}
parent c0ff80be
......@@ -6,6 +6,7 @@
#define THIRD_PARTY_BLINK_RENDERER_CORE_HTML_DOCUMENT_ALL_NAME_COLLECTION_H_
#include "third_party/blink/renderer/core/html/html_name_collection.h"
#include "third_party/blink/renderer/platform/wtf/casting.h"
namespace blink {
......@@ -21,11 +22,12 @@ class DocumentAllNameCollection final : public HTMLNameCollection {
bool ElementMatches(const Element&) const;
};
DEFINE_TYPE_CASTS(DocumentAllNameCollection,
LiveNodeListBase,
collection,
collection->GetType() == kDocumentAllNamedItems,
collection.GetType() == kDocumentAllNamedItems);
template <>
struct DowncastTraits<DocumentAllNameCollection> {
static bool AllowFrom(const LiveNodeListBase& collection) {
return collection.GetType() == kDocumentAllNamedItems;
}
};
} // namespace blink
......
......@@ -7,6 +7,7 @@
#include "third_party/blink/renderer/core/html/html_element.h"
#include "third_party/blink/renderer/core/html/html_name_collection.h"
#include "third_party/blink/renderer/platform/wtf/casting.h"
namespace blink {
......@@ -24,11 +25,12 @@ class DocumentNameCollection final : public HTMLNameCollection {
bool ElementMatches(const HTMLElement&) const;
};
DEFINE_TYPE_CASTS(DocumentNameCollection,
LiveNodeListBase,
collection,
collection->GetType() == kDocumentNamedItems,
collection.GetType() == kDocumentNamedItems);
template <>
struct DowncastTraits<DocumentNameCollection> {
static bool AllowFrom(const LiveNodeListBase& collection) {
return collection.GetType() == kDocumentNamedItems;
}
};
} // namespace blink
......
......@@ -213,9 +213,10 @@ static inline bool IsMatchingHTMLElement(const HTMLCollection& html_collection,
case kDocForms:
return element.HasTagName(html_names::kFormTag);
case kDocumentNamedItems:
return ToDocumentNameCollection(html_collection).ElementMatches(element);
return To<DocumentNameCollection>(html_collection)
.ElementMatches(element);
case kDocumentAllNamedItems:
return ToDocumentAllNameCollection(html_collection)
return To<DocumentAllNameCollection>(html_collection)
.ElementMatches(element);
case kTableTBodies:
return element.HasTagName(html_names::kTbodyTag);
......@@ -287,7 +288,7 @@ inline bool HTMLCollection::ElementMatches(const Element& element) const {
case kWindowNamedItems:
return To<WindowNameCollection>(*this).ElementMatches(element);
case kDocumentAllNamedItems:
return ToDocumentAllNameCollection(*this).ElementMatches(element);
return To<DocumentAllNameCollection>(*this).ElementMatches(element);
default:
break;
}
......
......@@ -41,7 +41,7 @@ DocumentResource* DocumentResource::FetchSVGDocument(FetchParameters& params,
network::mojom::RequestMode::kSameOrigin);
params.SetRequestContext(mojom::RequestContextType::IMAGE);
params.SetRequestDestination(network::mojom::RequestDestination::kImage);
return ToDocumentResource(
return To<DocumentResource>(
fetcher->RequestResource(params, SVGDocumentResourceFactory(), client));
}
......
......@@ -29,6 +29,7 @@
#include "third_party/blink/renderer/platform/loader/fetch/resource.h"
#include "third_party/blink/renderer/platform/loader/fetch/resource_client.h"
#include "third_party/blink/renderer/platform/loader/fetch/text_resource_decoder_options.h"
#include "third_party/blink/renderer/platform/wtf/casting.h"
namespace blink {
......@@ -75,11 +76,12 @@ class CORE_EXPORT DocumentResource final : public TextResource {
Member<Document> document_;
};
DEFINE_TYPE_CASTS(DocumentResource,
Resource,
resource,
resource->GetType() == ResourceType::kSVGDocument,
resource.GetType() == ResourceType::kSVGDocument);
template <>
struct DowncastTraits<DocumentResource> {
static bool AllowFrom(const Resource& resource) {
return resource.GetType() == ResourceType::kSVGDocument;
}
};
} // namespace blink
......
......@@ -319,7 +319,7 @@ Element* SVGUseElement::ResolveTargetElement() {
}
if (!ResourceIsValid())
return nullptr;
return ToDocumentResource(GetResource())
return To<DocumentResource>(GetResource())
->GetDocument()
->getElementById(element_identifier);
}
......@@ -628,7 +628,7 @@ bool SVGUseElement::ResourceIsValid() const {
// TODO(fs): Handle revalidations that return a new/different resource.
if (!resource->IsLoaded() && !resource->IsCacheValidator())
return false;
return ToDocumentResource(resource)->GetDocument();
return To<DocumentResource>(resource)->GetDocument();
}
} // namespace blink
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