diff options
author | John Reck <jreck@google.com> | 2012-05-24 19:56:29 -0700 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2012-05-24 19:56:29 -0700 |
commit | d09ecffa71debc80cfd0f2d6086c62a555f7aa96 (patch) | |
tree | 4c0c72d7e3037f700005d031c02100a9d26d8d2c /Source | |
parent | e0d7d53d0af7715347bc694de7b140773174149e (diff) | |
parent | 06d698b1f053f42cf2a6041fd1298f207d80a01e (diff) | |
download | external_webkit-d09ecffa71debc80cfd0f2d6086c62a555f7aa96.zip external_webkit-d09ecffa71debc80cfd0f2d6086c62a555f7aa96.tar.gz external_webkit-d09ecffa71debc80cfd0f2d6086c62a555f7aa96.tar.bz2 |
am 06d698b1: am 917ab176: Support content detection metatags
* commit '06d698b1f053f42cf2a6041fd1298f207d80a01e':
Support content detection metatags
Diffstat (limited to 'Source')
6 files changed, 49 insertions, 2 deletions
diff --git a/Source/WebKit/android/content/PhoneEmailDetector.cpp b/Source/WebKit/android/content/PhoneEmailDetector.cpp index d188c0b..ca97a71 100644 --- a/Source/WebKit/android/content/PhoneEmailDetector.cpp +++ b/Source/WebKit/android/content/PhoneEmailDetector.cpp @@ -31,6 +31,7 @@ #include "base/utf_string_conversions.h" #include "net/base/escape.h" #include "PhoneEmailDetector.h" +#include "Settings.h" #include "WebString.h" #define LOG_TAG "PhoneNumberDetector" @@ -56,18 +57,31 @@ PhoneEmailDetector::PhoneEmailDetector() { } +bool PhoneEmailDetector::IsEnabled(const WebKit::WebHitTestInfo& hit_test) +{ + WebCore::Settings* settings = GetSettings(hit_test); + if (!settings) + return false; + m_isPhoneDetectionEnabled = settings->formatDetectionTelephone(); + m_isEmailDetectionEnabled = settings->formatDetectionEmail(); + return m_isEmailDetectionEnabled || m_isPhoneDetectionEnabled; +} + bool PhoneEmailDetector::FindContent(const string16::const_iterator& begin, const string16::const_iterator& end, size_t* start_pos, size_t* end_pos) { FindReset(&m_findState); - m_foundResult = FindPartialNumber(begin, end - begin, &m_findState); + m_foundResult = FOUND_NONE; + if (m_isPhoneDetectionEnabled) + m_foundResult = FindPartialNumber(begin, end - begin, &m_findState); if (m_foundResult == FOUND_COMPLETE) m_prefix = kTelSchemaPrefix; else { FindReset(&m_findState); - m_foundResult = FindPartialEMail(begin, end - begin, &m_findState); + if (m_isEmailDetectionEnabled) + m_foundResult = FindPartialEMail(begin, end - begin, &m_findState); m_prefix = kEmailSchemaPrefix; } *start_pos = m_findState.mStartResult; diff --git a/Source/WebKit/android/content/PhoneEmailDetector.h b/Source/WebKit/android/content/PhoneEmailDetector.h index b61de62..74ff5b1 100644 --- a/Source/WebKit/android/content/PhoneEmailDetector.h +++ b/Source/WebKit/android/content/PhoneEmailDetector.h @@ -66,10 +66,16 @@ private: virtual size_t GetMaximumContentLength() { return NAVIGATION_MAX_PHONE_LENGTH * 4; } + virtual bool IsEnabled(const WebKit::WebHitTestInfo& hit_test) OVERRIDE; DISALLOW_COPY_AND_ASSIGN(PhoneEmailDetector); FindState m_findState; FoundState m_foundResult; const char* m_prefix; + // TODO: This shouldn't be done like this. PhoneEmailDetector should be + // refactored into two pieces and follow the IsEnabled style. This will + // only work because we always call IsEnabled before FindContent + bool m_isPhoneDetectionEnabled; + bool m_isEmailDetectionEnabled; }; diff --git a/Source/WebKit/android/content/address_detector.cpp b/Source/WebKit/android/content/address_detector.cpp index 8c9f230..f6657d9 100644 --- a/Source/WebKit/android/content/address_detector.cpp +++ b/Source/WebKit/android/content/address_detector.cpp @@ -40,6 +40,7 @@ #include "base/utf_string_conversions.h" #include "net/base/escape.h" +#include "Settings.h" #include "WebString.h" #include <wtf/HashSet.h> @@ -157,6 +158,11 @@ size_t AddressDetector::GetMaximumContentLength() { return kMaxAddressLength; } +bool AddressDetector::IsEnabled(const WebKit::WebHitTestInfo& hit_test) { + WebCore::Settings* settings = GetSettings(hit_test); + return settings && settings->formatDetectionAddress(); +} + bool AddressDetector::FindContent(const string16::const_iterator& begin, const string16::const_iterator& end, size_t* start_pos, size_t* end_pos) { HouseNumberParser house_number_parser; diff --git a/Source/WebKit/android/content/address_detector.h b/Source/WebKit/android/content/address_detector.h index be34375..6dc4ce8 100644 --- a/Source/WebKit/android/content/address_detector.h +++ b/Source/WebKit/android/content/address_detector.h @@ -60,6 +60,7 @@ class AddressDetector : public ContentDetector { virtual std::string GetContentText(const WebKit::WebRange& range) OVERRIDE; virtual GURL GetIntentURL(const std::string& content_text) OVERRIDE; virtual size_t GetMaximumContentLength() OVERRIDE; + virtual bool IsEnabled(const WebKit::WebHitTestInfo& hit_test) OVERRIDE; // Internal structs and classes. Required to be visible by the unit tests. struct Word { diff --git a/Source/WebKit/android/content/content_detector.cpp b/Source/WebKit/android/content/content_detector.cpp index b29a457..e423207 100644 --- a/Source/WebKit/android/content/content_detector.cpp +++ b/Source/WebKit/android/content/content_detector.cpp @@ -39,11 +39,18 @@ #include "public/android/WebDOMTextContentWalker.h" #include "public/android/WebHitTestInfo.h" +#include "Document.h" +#include "Node.h" +#include "Page.h" +#include "Settings.h" + using WebKit::WebDOMTextContentWalker; using WebKit::WebRange; ContentDetector::Result ContentDetector::FindTappedContent( const WebKit::WebHitTestInfo& hit_test) { + if (!IsEnabled(hit_test)) + return Result(); WebKit::WebRange range = FindContentRange(hit_test); if (range.isNull()) return Result(); @@ -84,3 +91,9 @@ WebRange ContentDetector::FindContentRange( return WebRange(); } + +WebCore::Settings* ContentDetector::GetSettings(const WebKit::WebHitTestInfo& hit_test) { + if (!hit_test.node() || !hit_test.node()->document()) + return 0; + return hit_test.node()->document()->page()->settings(); +} diff --git a/Source/WebKit/android/content/content_detector.h b/Source/WebKit/android/content/content_detector.h index 041cbc9..270928d 100644 --- a/Source/WebKit/android/content/content_detector.h +++ b/Source/WebKit/android/content/content_detector.h @@ -44,6 +44,10 @@ namespace WebKit { class WebHitTestInfo; } +namespace WebCore { +class Settings; +} + // Base class for text-based content detectors. class ContentDetector { public: @@ -82,6 +86,9 @@ class ContentDetector { size_t* start_pos, size_t* end_pos) = 0; + virtual bool IsEnabled(const WebKit::WebHitTestInfo& hit_test) = 0; + WebCore::Settings* GetSettings(const WebKit::WebHitTestInfo& hit_test); + // Extracts and processes the text of the detected content. virtual std::string GetContentText(const WebKit::WebRange& range) = 0; |