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

Issue 1365203002: Make WebNode::to<Type>() (and toConst) casts contain type asserts. (Closed)

Created:
5 years, 3 months ago by esprehn
Modified:
5 years, 2 months ago
CC:
chromium-reviews
Base URL:
https://chromium.googlesource.com/chromium/src.git@master
Target Ref:
refs/pending/heads/master
Project:
chromium
Visibility:
Public.

Description

Make WebNode::to<Type>() (and toConst) casts contain type asserts. Previously you could cast a WebNode to any subclass and then call invalid methods on it resulting in invalid address access. Instead we change the to<Type>() and toConst<Type>() casting methods to contain type checks just like the toFoo() casting methods inside Blink. This will catch the bad casts early by crashing on an ASSERT_WITH_SECURITY_IMPLICATION. These new asserts caught bad casts inside WebFrameTest where it was casting a WebElement(div) into a WebInputElement. It also caught one in the form_autofill_browsertest where it was casting a WebElement(textarea) to a WebInputElement. Finally I fixed a case of this I found inside form_autofill_util.cc's MatchLabelsAndFields method which converted correspondingControl() to a WebFormControlElement without checking if it was one first. This code was actually safe since it always checked isFormControlElement() on the WebFormControlElement afterwards, but doing that is super subtle. This also lets us remove the usage of nodeType() in the WebViewTest.cpp since now the to<WebElement>() calls contain asserts, and with that being the last usage of nodeType() we can remove WebNode::nodeType() completely. Committed: https://crrev.com/740cd24e4e3db9f160462f7bf861929b18e4861f Cr-Commit-Position: refs/heads/master@{#350944}

Patch Set 1 #

Patch Set 2 : fix typo. #

Patch Set 3 : moar. #

Patch Set 4 : Remove another bad cast. #

Patch Set 5 : types. #

Patch Set 6 : Remove more bad casts in WebFrameTest. #

Total comments: 4

Patch Set 7 : Add BLINK_IMPLEMENTATION guard. #

Unified diffs Side-by-side diffs Delta from patch set Stats (+116 lines, -80 lines) Patch
M chrome/renderer/autofill/form_autofill_browsertest.cc View 1 2 3 4 2 chunks +25 lines, -1 line 0 comments Download
M components/autofill/content/renderer/form_autofill_util.cc View 1 2 2 chunks +7 lines, -8 lines 0 comments Download
M third_party/WebKit/Source/web/AssertMatchingEnums.cpp View 1 2 1 chunk +0 lines, -10 lines 0 comments Download
M third_party/WebKit/Source/web/WebDocument.cpp View 1 chunk +2 lines, -0 lines 0 comments Download
M third_party/WebKit/Source/web/WebDocumentType.cpp View 1 chunk +2 lines, -0 lines 0 comments Download
M third_party/WebKit/Source/web/WebElement.cpp View 1 chunk +2 lines, -0 lines 0 comments Download
M third_party/WebKit/Source/web/WebFormControlElement.cpp View 1 1 chunk +2 lines, -0 lines 0 comments Download
M third_party/WebKit/Source/web/WebFormElement.cpp View 1 chunk +2 lines, -0 lines 0 comments Download
M third_party/WebKit/Source/web/WebInputElement.cpp View 1 chunk +2 lines, -0 lines 0 comments Download
M third_party/WebKit/Source/web/WebLabelElement.cpp View 1 chunk +2 lines, -0 lines 0 comments Download
M third_party/WebKit/Source/web/WebNode.cpp View 1 2 2 chunks +5 lines, -5 lines 0 comments Download
M third_party/WebKit/Source/web/WebOptionElement.cpp View 1 chunk +2 lines, -0 lines 0 comments Download
M third_party/WebKit/Source/web/WebPluginDocument.cpp View 1 2 1 chunk +2 lines, -0 lines 0 comments Download
M third_party/WebKit/Source/web/WebSelectElement.cpp View 1 chunk +2 lines, -0 lines 0 comments Download
M third_party/WebKit/Source/web/WebTextAreaElement.cpp View 1 chunk +2 lines, -0 lines 0 comments Download
M third_party/WebKit/Source/web/tests/WebFrameTest.cpp View 1 2 3 4 5 4 chunks +0 lines, -4 lines 0 comments Download
M third_party/WebKit/Source/web/tests/WebViewTest.cpp View 1 2 5 chunks +0 lines, -11 lines 0 comments Download
M third_party/WebKit/public/web/WebDocument.h View 1 chunk +2 lines, -0 lines 0 comments Download
M third_party/WebKit/public/web/WebDocumentType.h View 2 chunks +3 lines, -1 line 0 comments Download
M third_party/WebKit/public/web/WebElement.h View 1 chunk +2 lines, -0 lines 0 comments Download
M third_party/WebKit/public/web/WebFormControlElement.h View 1 chunk +2 lines, -0 lines 0 comments Download
M third_party/WebKit/public/web/WebFormElement.h View 2 chunks +3 lines, -1 line 0 comments Download
M third_party/WebKit/public/web/WebInputElement.h View 2 chunks +3 lines, -1 line 0 comments Download
M third_party/WebKit/public/web/WebLabelElement.h View 2 chunks +3 lines, -1 line 0 comments Download
M third_party/WebKit/public/web/WebNode.h View 1 2 3 4 5 6 4 chunks +27 lines, -33 lines 0 comments Download
M third_party/WebKit/public/web/WebOptionElement.h View 2 chunks +3 lines, -1 line 0 comments Download
M third_party/WebKit/public/web/WebPluginDocument.h View 2 chunks +3 lines, -1 line 0 comments Download
M third_party/WebKit/public/web/WebSelectElement.h View 2 chunks +3 lines, -1 line 0 comments Download
M third_party/WebKit/public/web/WebTextAreaElement.h View 2 chunks +3 lines, -1 line 0 comments Download

Messages

Total messages: 32 (14 generated)
commit-bot: I haz the power
Dry run: CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/patch-status/1365203002/1 View timeline at https://chromium-cq-status.appspot.com/patch-timeline/1365203002/1
5 years, 3 months ago (2015-09-25 00:54:51 UTC) #2
commit-bot: I haz the power
Dry run: Try jobs failed on following builders: android_chromium_gn_compile_rel on tryserver.chromium.linux (JOB_FAILED, http://build.chromium.org/p/tryserver.chromium.linux/builders/android_chromium_gn_compile_rel/builds/136874) linux_chromium_compile_dbg_32_ng on ...
5 years, 3 months ago (2015-09-25 01:11:00 UTC) #4
commit-bot: I haz the power
Dry run: CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/patch-status/1365203002/40001 View timeline at https://chromium-cq-status.appspot.com/patch-timeline/1365203002/40001
5 years, 3 months ago (2015-09-25 02:36:43 UTC) #8
commit-bot: I haz the power
Dry run: Try jobs failed on following builders: mac_chromium_rel_ng on tryserver.chromium.mac (JOB_FAILED, http://build.chromium.org/p/tryserver.chromium.mac/builders/mac_chromium_rel_ng/builds/118075)
5 years, 3 months ago (2015-09-25 03:17:49 UTC) #10
commit-bot: I haz the power
Dry run: CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/patch-status/1365203002/60001 View timeline at https://chromium-cq-status.appspot.com/patch-timeline/1365203002/60001
5 years, 3 months ago (2015-09-25 03:37:17 UTC) #12
commit-bot: I haz the power
Dry run: CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/patch-status/1365203002/80001 View timeline at https://chromium-cq-status.appspot.com/patch-timeline/1365203002/80001
5 years, 3 months ago (2015-09-25 03:43:16 UTC) #15
commit-bot: I haz the power
Dry run: CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/patch-status/1365203002/100001 View timeline at https://chromium-cq-status.appspot.com/patch-timeline/1365203002/100001
5 years, 2 months ago (2015-09-25 04:08:56 UTC) #17
commit-bot: I haz the power
Dry run: This issue passed the CQ dry run.
5 years, 2 months ago (2015-09-25 05:28:06 UTC) #19
esprehn
5 years, 2 months ago (2015-09-25 05:59:31 UTC) #21
Ilya Sherman
https://codereview.chromium.org/1365203002/diff/100001/chrome/renderer/autofill/form_autofill_browsertest.cc File chrome/renderer/autofill/form_autofill_browsertest.cc (right): https://codereview.chromium.org/1365203002/diff/100001/chrome/renderer/autofill/form_autofill_browsertest.cc#newcode2006 chrome/renderer/autofill/form_autofill_browsertest.cc:2006: TEST_F(FormAutofillTest, WebFormElementConsiderNonControlLabelableElements) { Sorry, what is this test testing? ...
5 years, 2 months ago (2015-09-25 06:18:23 UTC) #22
esprehn
https://codereview.chromium.org/1365203002/diff/100001/chrome/renderer/autofill/form_autofill_browsertest.cc File chrome/renderer/autofill/form_autofill_browsertest.cc (right): https://codereview.chromium.org/1365203002/diff/100001/chrome/renderer/autofill/form_autofill_browsertest.cc#newcode2006 chrome/renderer/autofill/form_autofill_browsertest.cc:2006: TEST_F(FormAutofillTest, WebFormElementConsiderNonControlLabelableElements) { On 2015/09/25 at 06:18:23, Ilya Sherman ...
5 years, 2 months ago (2015-09-25 08:30:38 UTC) #23
dglazkov
https://codereview.chromium.org/1365203002/diff/100001/third_party/WebKit/public/web/WebNode.h File third_party/WebKit/public/web/WebNode.h (right): https://codereview.chromium.org/1365203002/diff/100001/third_party/WebKit/public/web/WebNode.h#newcode146 third_party/WebKit/public/web/WebNode.h:146: #define DEFINE_WEB_NODE_TYPE_CASTS(type, predicate) \ this guy should be only ...
5 years, 2 months ago (2015-09-25 14:39:08 UTC) #24
Evan Stade
autofill lgtm
5 years, 2 months ago (2015-09-25 17:14:38 UTC) #25
esprehn
https://codereview.chromium.org/1365203002/diff/100001/third_party/WebKit/public/web/WebNode.h File third_party/WebKit/public/web/WebNode.h (right): https://codereview.chromium.org/1365203002/diff/100001/third_party/WebKit/public/web/WebNode.h#newcode146 third_party/WebKit/public/web/WebNode.h:146: #define DEFINE_WEB_NODE_TYPE_CASTS(type, predicate) \ On 2015/09/25 at 14:39:08, dglazkov ...
5 years, 2 months ago (2015-09-25 22:06:54 UTC) #26
dglazkov
lgtm
5 years, 2 months ago (2015-09-25 22:07:14 UTC) #27
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/patch-status/1365203002/120001 View timeline at https://chromium-cq-status.appspot.com/patch-timeline/1365203002/120001
5 years, 2 months ago (2015-09-25 22:11:48 UTC) #30
commit-bot: I haz the power
Committed patchset #7 (id:120001)
5 years, 2 months ago (2015-09-25 23:27:23 UTC) #31
commit-bot: I haz the power
5 years, 2 months ago (2015-09-25 23:28:05 UTC) #32
Message was sent while issue was closed.
Patchset 7 (id:??) landed as
https://crrev.com/740cd24e4e3db9f160462f7bf861929b18e4861f
Cr-Commit-Position: refs/heads/master@{#350944}

Powered by Google App Engine
This is Rietveld 408576698