summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--android_webview/common/aw_hit_test_data.h6
-rw-r--r--android_webview/javatests/src/org/chromium/android_webview/test/WebKitHitTestTest.java48
-rw-r--r--android_webview/renderer/aw_render_view_ext.cc44
-rw-r--r--content/content_renderer.gypi4
-rw-r--r--content/public/renderer/android_content_detection_prefixes.cc13
-rw-r--r--content/public/renderer/android_content_detection_prefixes.h21
-rw-r--r--content/renderer/android/address_detector.cc6
-rw-r--r--content/renderer/android/email_detector.cc6
-rw-r--r--content/renderer/android/phone_number_detector.cc6
9 files changed, 134 insertions, 20 deletions
diff --git a/android_webview/common/aw_hit_test_data.h b/android_webview/common/aw_hit_test_data.h
index a05ea2e..845aeb5 100644
--- a/android_webview/common/aw_hit_test_data.h
+++ b/android_webview/common/aw_hit_test_data.h
@@ -25,8 +25,10 @@ struct AwHitTestData {
// their normal values for the respective type.
UNKNOWN_TYPE = 0,
- // Content detection types. Not used yet.
- // TODO(boliu): Hook up content detection.
+ // 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.
PHONE_TYPE = 2,
GEO_TYPE = 3,
EMAIL_TYPE = 4,
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 a71103a4..6ebab9f 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
@@ -164,6 +164,54 @@ public class WebKitHitTestTest extends AndroidWebViewTestBase {
* BUG=158284
*/
@FlakyTest
+ public void testSrcEmailType() throws Throwable {
+ String email = "foo@bar.com";
+ String prefix = "mailto:";
+ String page = fullPageLink(prefix + email, ANCHOR_TEXT);
+ setServerResponseAndLoad(page);
+ simulateTouchCenterOfWebViewOnUiThread();
+ assertTrue(pollForHitTestDataOnUiThread(HitTestResult.EMAIL_TYPE, email));
+ assertTrue(pollForHrefAndImageSrcOnUiThread(prefix+ email, ANCHOR_TEXT, null));
+ }
+
+ /*
+ * @SmallTest
+ * @Feature({"AndroidWebView", "WebKitHitTest"})
+ * BUG=158284
+ */
+ @FlakyTest
+ public void testSrcGeoType() throws Throwable {
+ String location = "Jilin";
+ String prefix = "geo:0,0?q=";
+ String page = fullPageLink(prefix + location, ANCHOR_TEXT);
+ setServerResponseAndLoad(page);
+ simulateTouchCenterOfWebViewOnUiThread();
+ assertTrue(pollForHitTestDataOnUiThread(HitTestResult.GEO_TYPE, location));
+ assertTrue(pollForHrefAndImageSrcOnUiThread(prefix + location, ANCHOR_TEXT, null));
+ }
+
+ /*
+ * @SmallTest
+ * @Feature({"AndroidWebView", "WebKitHitTest"})
+ * BUG=158284
+ */
+ @FlakyTest
+ public void testSrcPhoneType() throws Throwable {
+ String phone_num = "1234567890";
+ String prefix = "tel:";
+ String page = fullPageLink("tel:" + phone_num, ANCHOR_TEXT);
+ setServerResponseAndLoad(page);
+ simulateTouchCenterOfWebViewOnUiThread();
+ assertTrue(pollForHitTestDataOnUiThread(HitTestResult.PHONE_TYPE, phone_num));
+ assertTrue(pollForHrefAndImageSrcOnUiThread(prefix + phone_num, ANCHOR_TEXT, null));
+ }
+
+ /*
+ * @SmallTest
+ * @Feature({"AndroidWebView", "WebKitHitTest"})
+ * BUG=158284
+ */
+ @FlakyTest
public void testSrcImgeAnchorType() throws Throwable {
String relImageSrc = "/nonexistent.jpg";
String fullImageSrc = mWebServer.getResponseUrl(relImageSrc);
diff --git a/android_webview/renderer/aw_render_view_ext.cc b/android_webview/renderer/aw_render_view_ext.cc
index 3369379..f9fb960 100644
--- a/android_webview/renderer/aw_render_view_ext.cc
+++ b/android_webview/renderer/aw_render_view_ext.cc
@@ -4,10 +4,13 @@
#include "android_webview/renderer/aw_render_view_ext.h"
+#include <string>
+
#include "android_webview/common/aw_hit_test_data.h"
#include "android_webview/common/render_view_messages.h"
+#include "base/string_piece.h"
#include "content/public/common/url_constants.h"
-#include "content/public/common/url_constants.h"
+#include "content/public/renderer/android_content_detection_prefixes.h"
#include "content/public/renderer/document_state.h"
#include "content/public/renderer/render_view.h"
#include "third_party/WebKit/Source/Platform/chromium/public/WebSize.h"
@@ -24,6 +27,22 @@
namespace android_webview {
+namespace {
+
+bool RemovePrefixAndAssignIfMatches(const base::StringPiece& prefix,
+ const GURL& url,
+ std::string* dest) {
+ const base::StringPiece spec(url.spec());
+
+ if (spec.starts_with(prefix)) {
+ dest->assign(spec.begin() + prefix.length(), spec.end());
+ return true;
+ }
+ return false;
+}
+
+}
+
AwRenderViewExt::AwRenderViewExt(content::RenderView* render_view)
: content::RenderViewObserver(render_view) {
render_view->GetWebView()->setPermissionClient(this);
@@ -126,8 +145,25 @@ void AwRenderViewExt::OnDoHitTest(int view_x, int view_y) {
if (result.absoluteLinkURL().isValid() &&
!result.absoluteImageURL().isValid() &&
!is_javascript_scheme) {
- data.type = AwHitTestData::SRC_LINK_TYPE;
- data.extra_data_for_type = url.spec();
+ if (RemovePrefixAndAssignIfMatches(
+ content::kAddressPrefix,
+ url,
+ &data.extra_data_for_type)) {
+ data.type = AwHitTestData::GEO_TYPE;
+ } else if (RemovePrefixAndAssignIfMatches(
+ content::kPhoneNumberPrefix,
+ url,
+ &data.extra_data_for_type)) {
+ data.type = AwHitTestData::PHONE_TYPE;
+ } else if (RemovePrefixAndAssignIfMatches(
+ content::kEmailPrefix,
+ url,
+ &data.extra_data_for_type)) {
+ data.type = AwHitTestData::EMAIL_TYPE;
+ } else {
+ data.type = AwHitTestData::SRC_LINK_TYPE;
+ data.extra_data_for_type = url.spec();
+ }
} else if (result.absoluteLinkURL().isValid() &&
result.absoluteImageURL().isValid() &&
!is_javascript_scheme) {
@@ -140,8 +176,6 @@ void AwRenderViewExt::OnDoHitTest(int view_x, int view_y) {
} else if (result.isContentEditable()) {
data.type = AwHitTestData::EDIT_TEXT_TYPE;
DCHECK(data.extra_data_for_type.length() == 0);
- } else {
- // TODO(boliu): Do content detection here.
}
Send(new AwViewHostMsg_UpdateHitTestData(routing_id(), data));
diff --git a/content/content_renderer.gypi b/content/content_renderer.gypi
index b7b99d9..ff33b19 100644
--- a/content/content_renderer.gypi
+++ b/content/content_renderer.gypi
@@ -26,6 +26,8 @@
'..',
],
'sources': [
+ 'public/renderer/android_content_detection_prefixes.cc',
+ 'public/renderer/android_content_detection_prefixes.h',
'public/renderer/content_renderer_client.cc',
'public/renderer/content_renderer_client.h',
'public/renderer/context_menu_client.h',
@@ -34,6 +36,7 @@
'public/renderer/navigation_state.cc',
'public/renderer/navigation_state.h',
'public/renderer/password_form_conversion_utils.h',
+ 'public/renderer/renderer_ppapi_host.h',
'public/renderer/render_process_observer.cc',
'public/renderer/render_process_observer.h',
'public/renderer/render_thread.cc',
@@ -43,7 +46,6 @@
'public/renderer/render_view_observer.h',
'public/renderer/render_view_observer_tracker.h',
'public/renderer/render_view_visitor.h',
- 'public/renderer/renderer_ppapi_host.h',
'public/renderer/v8_value_converter.h',
'renderer/accessibility_node_serializer.cc',
'renderer/accessibility_node_serializer.h',
diff --git a/content/public/renderer/android_content_detection_prefixes.cc b/content/public/renderer/android_content_detection_prefixes.cc
new file mode 100644
index 0000000..45a4f6c
--- /dev/null
+++ b/content/public/renderer/android_content_detection_prefixes.cc
@@ -0,0 +1,13 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/public/renderer/android_content_detection_prefixes.h"
+
+namespace content {
+
+const char kAddressPrefix[] = "geo:0,0?q=";
+const char kEmailPrefix[] = "mailto:";
+const char kPhoneNumberPrefix[] = "tel:";
+
+} // namespace content
diff --git a/content/public/renderer/android_content_detection_prefixes.h b/content/public/renderer/android_content_detection_prefixes.h
new file mode 100644
index 0000000..76e397b
--- /dev/null
+++ b/content/public/renderer/android_content_detection_prefixes.h
@@ -0,0 +1,21 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CONTENT_PUBLIC_RENDERER_ANDROID_CONTENT_DETECTION_PREFIXES_H_
+#define CONTENT_PUBLIC_RENDERER_ANDROID_CONTENT_DETECTION_PREFIXES_H_
+
+#include "content/common/content_export.h"
+
+namespace content {
+
+// Android intent url prefixes for content detection.
+// Note that these do not work with GURL::SchemeIs.
+CONTENT_EXPORT extern const char kAddressPrefix[];
+CONTENT_EXPORT extern const char kEmailPrefix[];
+CONTENT_EXPORT extern const char kPhoneNumberPrefix[];
+
+} // namespace content
+
+#endif // CONTENT_PUBLIC_RENDERER_ANDROID_CONTENT_DETECTION_PREFIXES_H_
+
diff --git a/content/renderer/android/address_detector.cc b/content/renderer/android/address_detector.cc
index 1ea6fea..95f2f9a 100644
--- a/content/renderer/android/address_detector.cc
+++ b/content/renderer/android/address_detector.cc
@@ -9,13 +9,11 @@
#include "base/string_util.h"
#include "base/utf_string_conversions.h"
#include "content/common/android/address_parser.h"
+#include "content/public/renderer/android_content_detection_prefixes.h"
#include "net/base/escape.h"
namespace {
-// Prefix used for geographical address intent URIs.
-static const char kAddressSchemaPrefix[] = "geo:0,0?q=";
-
// Maximum text length to be searched for address detection.
static const size_t kMaxAddressLength = 250;
@@ -30,7 +28,7 @@ AddressDetector::~AddressDetector() {
}
GURL AddressDetector::GetIntentURL(const std::string& content_text) {
- return GURL(kAddressSchemaPrefix +
+ return GURL(kAddressPrefix +
net::EscapeQueryParamValue(content_text, true));
}
diff --git a/content/renderer/android/email_detector.cc b/content/renderer/android/email_detector.cc
index 65dd1ab..4eaa0d0 100644
--- a/content/renderer/android/email_detector.cc
+++ b/content/renderer/android/email_detector.cc
@@ -7,6 +7,7 @@
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "base/utf_string_conversions.h"
+#include "content/public/renderer/android_content_detection_prefixes.h"
#include "net/base/escape.h"
#include "unicode/regex.h"
@@ -15,9 +16,6 @@ namespace {
// Maximum length of an email address.
const size_t kMaximumEmailLength = 254;
-// Prefix used for email intent URIs.
-const char kEmailSchemaPrefix[] = "mailto:";
-
// Regex to match email addresses.
// This is more specific than RFC 2822 (uncommon special characters are
// disallowed) in order to avoid false positives.
@@ -40,7 +38,7 @@ GURL EmailDetector::GetIntentURL(const std::string& content_text) {
if (content_text.empty())
return GURL();
- return GURL(kEmailSchemaPrefix +
+ return GURL(kEmailPrefix +
net::EscapeQueryParamValue(content_text, true));
}
diff --git a/content/renderer/android/phone_number_detector.cc b/content/renderer/android/phone_number_detector.cc
index d037608..391eeda 100644
--- a/content/renderer/android/phone_number_detector.cc
+++ b/content/renderer/android/phone_number_detector.cc
@@ -8,6 +8,7 @@
#include "base/string_util.h"
#include "base/utf_string_conversions.h"
+#include "content/public/renderer/android_content_detection_prefixes.h"
#include "net/base/escape.h"
#include "third_party/libphonenumber/src/phonenumber_api.h"
#include "third_party/libphonenumber/src/phonenumbers/phonenumbermatch.h"
@@ -24,9 +25,6 @@ namespace {
// Maximum number of characters to look around for phone number detection.
const size_t kMaximumTelephoneLength = 20;
-// Prefix used for telephone number intent URIs.
-const char kPhoneNumberSchemaPrefix[] = "tel:";
-
} // anonymous namespace
namespace content {
@@ -52,7 +50,7 @@ GURL PhoneNumberDetector::GetIntentURL(const std::string& content_text) {
if (content_text.empty())
return GURL();
- return GURL(kPhoneNumberSchemaPrefix +
+ return GURL(kPhoneNumberPrefix +
net::EscapeQueryParamValue(content_text, true));
}