| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CONTENT_RENDERER_ANDROID_CONTENT_DETECTOR_H_ | 5 #ifndef CONTENT_RENDERER_ANDROID_CONTENT_DETECTOR_H_ |
| 6 #define CONTENT_RENDERER_ANDROID_CONTENT_DETECTOR_H_ | 6 #define CONTENT_RENDERER_ANDROID_CONTENT_DETECTOR_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "third_party/WebKit/public/web/WebRange.h" | 11 #include "third_party/WebKit/public/platform/WebURL.h" |
| 12 #include "url/gurl.h" | 12 #include "url/gurl.h" |
| 13 | 13 |
| 14 namespace blink { | 14 namespace blink { |
| 15 class WebHitTestResult; | 15 class WebHitTestResult; |
| 16 } | 16 } |
| 17 | 17 |
| 18 namespace content { | 18 namespace content { |
| 19 | 19 |
| 20 // Base class for text-based content detectors. | 20 // Base class for text-based content detectors. |
| 21 class ContentDetector { | 21 class ContentDetector { |
| 22 public: | 22 public: |
| 23 // Holds the content detection results. | |
| 24 struct Result { | |
| 25 Result(); | |
| 26 Result(const blink::WebRange& content_boundaries, | |
| 27 const std::string& text, | |
| 28 const GURL& intent_url); | |
| 29 Result(const Result& other); | |
| 30 ~Result(); | |
| 31 | |
| 32 bool valid; | |
| 33 blink::WebRange content_boundaries; | |
| 34 std::string text; // Processed text of the content. | |
| 35 GURL intent_url; // URL of the intent that should process this content. | |
| 36 }; | |
| 37 | |
| 38 virtual ~ContentDetector() {} | 23 virtual ~ContentDetector() {} |
| 39 | 24 |
| 40 // Returns a WebKit range delimiting the contents found around the tapped | 25 // Returns an intent URL for the content around the hit_test. |
| 41 // position. If no content is found a null range will be returned. | 26 // If no content is found, an empty URL will be returned. |
| 42 Result FindTappedContent(const blink::WebHitTestResult& hit_test); | 27 blink::WebURL FindTappedContent(const blink::WebHitTestResult& hit_test); |
| 43 | 28 |
| 44 protected: | 29 protected: |
| 45 ContentDetector() {} | 30 ContentDetector() {} |
| 46 | 31 |
| 47 // Parses the input string defined by the begin/end iterators returning true | 32 // Parses the input string defined by the begin/end iterators returning true |
| 48 // if the desired content is found. The start and end positions relative to | 33 // if the desired content is found. The start and end positions relative to |
| 49 // the input iterators are returned in start_pos and end_pos. | 34 // the input iterators are returned in start_pos and end_pos. |
| 50 // The end position is assumed to be non-inclusive. | 35 // The end position is assumed to be non-inclusive. |
| 51 virtual bool FindContent(const base::string16::const_iterator& begin, | 36 virtual bool FindContent(const base::string16::const_iterator& begin, |
| 52 const base::string16::const_iterator& end, | 37 const base::string16::const_iterator& end, |
| 53 size_t* start_pos, | 38 size_t* start_pos, |
| 54 size_t* end_pos, | 39 size_t* end_pos, |
| 55 std::string* content_text) = 0; | 40 std::string* content_text) = 0; |
| 56 | 41 |
| 57 // Returns the intent URL that should process the content, if any. | 42 // Returns the intent URL that should process the content, if any. |
| 58 virtual GURL GetIntentURL(const std::string& content_text) = 0; | 43 virtual GURL GetIntentURL(const std::string& content_text) = 0; |
| 59 | 44 |
| 60 // Returns the maximum length of text to be extracted around the tapped | 45 // Returns the maximum length of text to be extracted around the tapped |
| 61 // position in order to search for content. | 46 // position in order to search for content. |
| 62 virtual size_t GetMaximumContentLength() = 0; | 47 virtual size_t GetMaximumContentLength() = 0; |
| 63 | 48 |
| 64 blink::WebRange FindContentRange(const blink::WebHitTestResult& hit_test, | 49 bool FindContentRange(const blink::WebHitTestResult& hit_test, |
| 65 std::string* content_text); | 50 std::string* content_text); |
| 66 | 51 |
| 67 DISALLOW_COPY_AND_ASSIGN(ContentDetector); | 52 DISALLOW_COPY_AND_ASSIGN(ContentDetector); |
| 68 }; | 53 }; |
| 69 | 54 |
| 70 } // namespace content | 55 } // namespace content |
| 71 | 56 |
| 72 #endif // CONTENT_RENDERER_ANDROID_CONTENT_DETECTOR_H_ | 57 #endif // CONTENT_RENDERER_ANDROID_CONTENT_DETECTOR_H_ |
| OLD | NEW |