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

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: Add BLINK_IMPLEMENTATION guard. 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
« no previous file with comments | « third_party/WebKit/public/web/WebLabelElement.h ('k') | third_party/WebKit/public/web/WebOptionElement.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..1010489a464e337a619ddd778d1cb68c17d488ec 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,27 +112,14 @@ 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>&);
WebNode& operator=(const PassRefPtrWillBeRawPtr<Node>&);
operator PassRefPtrWillBeRawPtr<Node>() const;
-#endif
-#if BLINK_IMPLEMENTATION
template<typename T> T* unwrap()
{
return static_cast<T*>(m_private.get());
@@ -165,6 +135,30 @@ 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;
+
+#if BLINK_IMPLEMENTATION
+#define DEFINE_WEB_NODE_TYPE_CASTS(type, predicate) \
+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; \
+}
+#endif
+
inline bool operator==(const WebNode& a, const WebNode& b)
{
return a.equals(b);
« no previous file with comments | « third_party/WebKit/public/web/WebLabelElement.h ('k') | third_party/WebKit/public/web/WebOptionElement.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698