Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(602)

Unified Diff: third_party/WebKit/public/web/WebNode.h

Issue 1365203002: Make WebNode::to<Type>() (and toConst) casts contain type asserts. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove more bad casts in WebFrameTest. Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/public/web/WebNode.h
diff --git a/third_party/WebKit/public/web/WebNode.h b/third_party/WebKit/public/web/WebNode.h
index 3313073ea3c11b728ddc48e3be24d7e2df47f73b..90515a45e3dc455c6772f42403aff84935f360d1 100644
--- a/third_party/WebKit/public/web/WebNode.h
+++ b/third_party/WebKit/public/web/WebNode.h
@@ -75,24 +75,6 @@ public:
bool isNull() const { return m_private.isNull(); }
- enum NodeType {
- ElementNode = 1,
- AttributeNode = 2,
- TextNode = 3,
- CDataSectionNode = 4,
- // EntityReferenceNodes are impossible to create in Blink.
- // EntityNodes are impossible to create in Blink.
- ProcessingInstructionsNode = 7,
- CommentNode = 8,
- DocumentNode = 9,
- DocumentTypeNode = 10,
- DocumentFragmentNode = 11,
- // NotationNodes are impossible to create in Blink.
- // XPathNamespaceNodes are impossible to create in Blink.
- ShadowRootNode = 14
- };
-
- BLINK_EXPORT NodeType nodeType() const;
BLINK_EXPORT WebNode parentNode() const;
BLINK_EXPORT WebString nodeValue() const;
BLINK_EXPORT WebDocument document() const;
@@ -103,6 +85,7 @@ public:
BLINK_EXPORT bool hasChildNodes() const;
BLINK_EXPORT WebNodeList childNodes();
BLINK_EXPORT bool isLink() const;
+ BLINK_EXPORT bool isDocumentNode() const;
BLINK_EXPORT bool isCommentNode() const;
BLINK_EXPORT bool isTextNode() const;
BLINK_EXPORT bool isFocusable() const;
@@ -129,19 +112,8 @@ public:
BLINK_EXPORT bool isInsideFocusableElementOrARIAWidget() const;
BLINK_EXPORT WebAXObject accessibilityObject();
- template<typename T> T to()
- {
- T res;
- res.WebNode::assign(*this);
- return res;
- }
-
- template<typename T> const T toConst() const
- {
- T res;
- res.WebNode::assign(*this);
- return res;
- }
+ template<typename T> T to();
+ template<typename T> const T toConst() const;
#if BLINK_IMPLEMENTATION
WebNode(const PassRefPtrWillBeRawPtr<Node>&);
@@ -165,6 +137,28 @@ protected:
WebPrivatePtr<Node> m_private;
};
+#define DECLARE_WEB_NODE_TYPE_CASTS(type) \
+template<> \
+BLINK_EXPORT type WebNode::to<type>(); \
+template<> \
+BLINK_EXPORT const type WebNode::toConst<type>() const;
+
+#define DEFINE_WEB_NODE_TYPE_CASTS(type, predicate) \
dglazkov 2015/09/25 14:39:08 this guy should be only when BLINK_IMPLEMENTATION,
esprehn 2015/09/25 22:06:54 Yeah done.
+template<> \
+type WebNode::to<type>() { \
+ ASSERT_WITH_SECURITY_IMPLICATION(isNull() || (predicate)); \
+ type result; \
+ result.WebNode::assign(*this); \
+ return result; \
+} \
+template<> \
+const type WebNode::toConst<type>() const { \
+ ASSERT_WITH_SECURITY_IMPLICATION(isNull() || (predicate)); \
+ type result; \
+ result.WebNode::assign(*this); \
+ return result; \
+}
+
inline bool operator==(const WebNode& a, const WebNode& b)
{
return a.equals(b);

Powered by Google App Engine
This is Rietveld 408576698