diff options
author | boliu@chromium.org <boliu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-18 18:18:44 +0000 |
---|---|---|
committer | boliu@chromium.org <boliu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-18 18:18:44 +0000 |
commit | bab5f452b9c8795e061d1858010ddf37c96bee48 (patch) | |
tree | 378fce56be62eb90a22cf0d7949e22a9054c9ebb /android_webview | |
parent | 46c70476a023039426d5b2f7cb12020790a8b44b (diff) | |
download | chromium_src-bab5f452b9c8795e061d1858010ddf37c96bee48.zip chromium_src-bab5f452b9c8795e061d1858010ddf37c96bee48.tar.gz chromium_src-bab5f452b9c8795e061d1858010ddf37c96bee48.tar.bz2 |
aw: Limit full url href hittest to only anchor type
This limits the fix for crrev.com/r223298 to anchor type, and
re-implement it and test it properly.
BUG=323989
Review URL: https://codereview.chromium.org/92903003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@241601 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'android_webview')
4 files changed, 21 insertions, 13 deletions
diff --git a/android_webview/common/aw_hit_test_data.h b/android_webview/common/aw_hit_test_data.h index d72bcf7..ee600f5 100644 --- a/android_webview/common/aw_hit_test_data.h +++ b/android_webview/common/aw_hit_test_data.h @@ -21,14 +21,15 @@ struct AwHitTestData { // |extra_data_for_type| will be empty. All other values should be emtpy // except the special case described below. // For special case of invalid or javascript scheme url that would - // otherwise be type an LINK type, |href|, |anchor_text|, |img_src| contain + // otherwise be type an LINK type, |href| will contain the javascript + // string in the href attribute, and |anchor_text|i and |img_src| contain // their normal values for the respective type. UNKNOWN_TYPE = 0, // Special case urls for SRC_LINK_TYPE below. Each type corresponds to a // different prefix in content url_constants. |extra_data_for_type| will - // contain the url but with the prefix removed. Other fields are the same - // as SRC_LINK_TYPE. + // contain the url but with the prefix removed. |href| will contain the + // exact href attribute string. Other fields are the same as SRC_LINK_TYPE. PHONE_TYPE = 2, GEO_TYPE = 3, EMAIL_TYPE = 4, @@ -39,22 +40,22 @@ struct AwHitTestData { IMAGE_TYPE = 5, // Hit on a link with valid and non-javascript url and without embedded - // image. |extra_data_for_type| is the valid absolute url of the link. - // |href| will contain the exact href attribute string. |anchor_text| will - // contain the anchor text if the link is an anchor tag. |img_src| will be - // empty. + // image. |extra_data_for_type| and |href| will be the valid absolute url + // of the link. |anchor_text| will contain the anchor text if the link is + // an anchor tag. |img_src| will be empty. // Note 1: If the link url is invalid or javascript scheme, then the type // will be UNKNOWN_TYPE. // Note 2: Note that this matches SRC_ANCHOR_TYPE in the public WebView // Java API, but the actual tag can be something other than <a>, such as // <link> or <area>. + // Note 3: |href| is not the raw attribute string, but the absolute link + // url. SRC_LINK_TYPE = 7, // Same as SRC_LINK_TYPE except the link contains an image. |img_src| and // |extra_data_for_type| will contain the absolute valid url of the image - // source. |href| will contain the (possibly invalid or javascript-scheme) - // link href attribute. |anchor_text| will be empty. - // Both notes from SRC_LINK_TYPE apply. + // source. |href| will be the valid absolute url of the link. |anchor_text| + // will be empty. All notes from SRC_LINK_TYPE apply. SRC_IMAGE_LINK_TYPE = 8, // Hit on an editable text input element. All other values will be empty. diff --git a/android_webview/java/src/org/chromium/android_webview/AwContents.java b/android_webview/java/src/org/chromium/android_webview/AwContents.java index 5b8fd9a..8605762 100644 --- a/android_webview/java/src/org/chromium/android_webview/AwContents.java +++ b/android_webview/java/src/org/chromium/android_webview/AwContents.java @@ -1350,7 +1350,7 @@ public class AwContents { // In order to maintain compatibility with the old WebView's implementation, // the absolute (full) url is passed in the |url| field, not only the href attribute. // Note: HitTestData could be cleaned up at this point. See http://crbug.com/290992. - data.putString("url", mPossiblyStaleHitTestData.hitTestResultExtraData); + data.putString("url", mPossiblyStaleHitTestData.href); data.putString("title", mPossiblyStaleHitTestData.anchorText); data.putString("src", mPossiblyStaleHitTestData.imgSrc); msg.setData(data); diff --git a/android_webview/javatests/src/org/chromium/android_webview/test/WebKitHitTestTest.java b/android_webview/javatests/src/org/chromium/android_webview/test/WebKitHitTestTest.java index 45c4aff..3998d72 100644 --- a/android_webview/javatests/src/org/chromium/android_webview/test/WebKitHitTestTest.java +++ b/android_webview/javatests/src/org/chromium/android_webview/test/WebKitHitTestTest.java @@ -18,6 +18,9 @@ import org.chromium.net.test.util.TestWebServer; import java.util.concurrent.Callable; +/** + * Test for getHitTestResult, requestFocusNodeHref, and requestImageRef methods + */ public class WebKitHitTestTest extends AwTestBase { private TestAwContentsClient mContentsClient; private AwTestContainerView mTestView; @@ -153,7 +156,7 @@ public class WebKitHitTestTest extends AwTestBase { simulateInput(byTouch); assertTrue(pollForHitTestDataOnUiThread( HitTestResult.SRC_ANCHOR_TYPE, fullpath)); - assertTrue(pollForHrefAndImageSrcOnUiThread(null, ANCHOR_TEXT, null)); + assertTrue(pollForHrefAndImageSrcOnUiThread(fullpath, ANCHOR_TEXT, null)); } @SmallTest @@ -176,7 +179,7 @@ public class WebKitHitTestTest extends AwTestBase { simulateInput(byTouch); assertTrue(pollForHitTestDataOnUiThread( HitTestResult.SRC_ANCHOR_TYPE, fullpath)); - assertTrue(pollForHrefAndImageSrcOnUiThread(relpath, ANCHOR_TEXT, null)); + assertTrue(pollForHrefAndImageSrcOnUiThread(fullpath, ANCHOR_TEXT, null)); } @SmallTest diff --git a/android_webview/renderer/aw_render_view_ext.cc b/android_webview/renderer/aw_render_view_ext.cc index b96776d..4865bf3 100644 --- a/android_webview/renderer/aw_render_view_ext.cc +++ b/android_webview/renderer/aw_render_view_ext.cc @@ -99,6 +99,8 @@ void DistinguishAndAssignSrcLinkType(const GURL& url, AwHitTestData* data) { } else { data->type = AwHitTestData::SRC_LINK_TYPE; data->extra_data_for_type = url.possibly_invalid_spec(); + if (!data->extra_data_for_type.empty()) + data->href = UTF8ToUTF16(data->extra_data_for_type); } } @@ -123,6 +125,8 @@ void PopulateHitTestData(const GURL& absolute_link_url, } else if (has_link_url && has_image_url && !is_javascript_scheme) { data->type = AwHitTestData::SRC_IMAGE_LINK_TYPE; data->extra_data_for_type = data->img_src.possibly_invalid_spec(); + if (absolute_link_url.is_valid()) + data->href = UTF8ToUTF16(absolute_link_url.possibly_invalid_spec()); } else if (!has_link_url && has_image_url) { data->type = AwHitTestData::IMAGE_TYPE; data->extra_data_for_type = data->img_src.possibly_invalid_spec(); |