diff options
author | leandrogracia@chromium.org <leandrogracia@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-08-21 20:23:03 +0000 |
---|---|---|
committer | leandrogracia@chromium.org <leandrogracia@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-08-21 20:23:03 +0000 |
commit | 20657a834232667edf5618fe2416667b3e63c20b (patch) | |
tree | 2bf4a72e51571858f5428258674dd94c07abe525 /content/renderer | |
parent | 35e0c48c5d22e58e3e3b60060089493cf8fb9b22 (diff) | |
download | chromium_src-20657a834232667edf5618fe2416667b3e63c20b.zip chromium_src-20657a834232667edf5618fe2416667b3e63c20b.tar.gz chromium_src-20657a834232667edf5618fe2416667b3e63c20b.tar.bz2 |
[Android] Connect content detection to the renderer.
Now that the related APIs have landed in WebKit, we can finally connect the
different content detectors in content/renderer/android with the hit results
provided by WebKit and the IPC message to fire Android intents.
BUG=125390
Review URL: https://chromiumcodereview.appspot.com/10824400
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@152620 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/renderer')
-rw-r--r-- | content/renderer/render_view_impl.cc | 88 | ||||
-rw-r--r-- | content/renderer/render_view_impl.h | 33 |
2 files changed, 120 insertions, 1 deletions
diff --git a/content/renderer/render_view_impl.cc b/content/renderer/render_view_impl.cc index 5aae516..c8669bb 100644 --- a/content/renderer/render_view_impl.cc +++ b/content/renderer/render_view_impl.cc @@ -196,7 +196,13 @@ #include "webkit/plugins/ppapi/ppapi_webplugin_impl.h" #if defined(OS_ANDROID) +#include "content/common/android/device_info.h" +#include "content/renderer/android/address_detector.h" +#include "content/renderer/android/content_detector.h" +#include "content/renderer/android/email_detector.h" +#include "content/renderer/android/phone_number_detector.h" #include "content/renderer/media/stream_texture_factory_impl_android.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebHitTestResult.h" #include "webkit/media/android/webmediaplayer_android.h" #include "webkit/media/android/webmediaplayer_manager_android.h" #elif defined(OS_WIN) @@ -315,6 +321,15 @@ using webkit_glue::ResourceFetcher; using webkit_glue::WebPreferences; using webkit_glue::WebURLResponseExtraDataImpl; +#if defined(OS_ANDROID) +using content::AddressDetector; +using content::ContentDetector; +using content::EmailDetector; +using content::PhoneNumberDetector; +using WebKit::WebContentDetectionResult; +using WebKit::WebHitTestResult; +#endif + //----------------------------------------------------------------------------- typedef std::map<WebKit::WebView*, RenderViewImpl*> ViewMap; @@ -340,6 +355,12 @@ static const float kScalingIncrement = 0.1f; static const float kScalingIncrementForGesture = 0.01f; +#if defined(OS_ANDROID) +// Delay between tapping in content and launching the associated android intent. +// Used to allow users see what has been recognized as content. +static const size_t kContentIntentDelayMilliseconds = 700; +#endif + static RenderViewImpl* FromRoutingID(int32 routing_id) { return static_cast<RenderViewImpl*>( ChildThread::current()->ResolveRoute(routing_id)); @@ -550,6 +571,9 @@ RenderViewImpl::RenderViewImpl( renderer_accessibility_(NULL), java_bridge_dispatcher_(NULL), mouse_lock_dispatcher_(NULL), +#if defined(OS_ANDROID) + expected_content_intent_id_(0), +#endif session_storage_namespace_id_(session_storage_namespace_id), handling_select_range_(false), #if defined(OS_WIN) @@ -577,6 +601,23 @@ RenderViewImpl::RenderViewImpl( webwidget_ = WebView::create(this); webwidget_mouse_lock_target_.reset(new WebWidgetLockTarget(webwidget_)); + const CommandLine& command_line = *CommandLine::ForCurrentProcess(); + +#if defined(OS_ANDROID) + scoped_ptr<content::DeviceInfo> device_info(new content::DeviceInfo()); + + const std::string region_code = + command_line.HasSwitch(switches::kNetworkCountryIso) + ? command_line.GetSwitchValueASCII(switches::kNetworkCountryIso) + : device_info->GetNetworkCountryIso(); + content_detectors_.push_back(linked_ptr<ContentDetector>( + new AddressDetector())); + content_detectors_.push_back(linked_ptr<ContentDetector>( + new PhoneNumberDetector(region_code))); + content_detectors_.push_back(linked_ptr<ContentDetector>( + new EmailDetector())); +#endif + if (counter) { shared_popup_counter_ = counter; // Only count this if it isn't swapped out upon creation. @@ -642,7 +683,6 @@ RenderViewImpl::RenderViewImpl( new IdleUserDetector(this); - const CommandLine& command_line = *CommandLine::ForCurrentProcess(); if (command_line.HasSwitch(switches::kDomAutomationController)) enabled_bindings_ |= content::BINDINGS_POLICY_DOM_AUTOMATION; @@ -5730,6 +5770,52 @@ void RenderViewImpl::draggableRegionsChanged() { DraggableRegionsChanged(webview()->mainFrame())); } +#if defined(OS_ANDROID) +WebContentDetectionResult RenderViewImpl::detectContentAround( + const WebHitTestResult& touch_hit) { + DCHECK(!touch_hit.isNull()); + DCHECK(!touch_hit.node().isNull()); + DCHECK(touch_hit.node().isTextNode()); + + // Process the position with all the registered content detectors until + // a match is found. Priority is provided by their relative order. + for (ContentDetectorList::const_iterator it = content_detectors_.begin(); + it != content_detectors_.end(); ++it) { + ContentDetector::Result content = (*it)->FindTappedContent(touch_hit); + if (content.valid) { + return WebContentDetectionResult(content.content_boundaries, + UTF8ToUTF16(content.text), content.intent_url); + } + } + return WebContentDetectionResult(); +} + +void RenderViewImpl::scheduleContentIntent(const WebURL& intent) { + // Introduce a short delay so that the user can notice the content. + MessageLoop::current()->PostDelayedTask( + FROM_HERE, + base::Bind(&RenderViewImpl::LaunchAndroidContentIntent, AsWeakPtr(), + intent, expected_content_intent_id_), + base::TimeDelta::FromMilliseconds(kContentIntentDelayMilliseconds)); +} + +void RenderViewImpl::cancelScheduledContentIntents() { + ++expected_content_intent_id_; +} + +void RenderViewImpl::LaunchAndroidContentIntent(const GURL& intent, + size_t request_id) { + if (request_id != expected_content_intent_id_) + return; + + // Remove the content highlighting if any. + scheduleComposite(); + + if (!intent.is_empty()) + Send(new ViewHostMsg_StartContentIntent(routing_id_, intent)); +} +#endif + void RenderViewImpl::OnAsyncFileOpened( base::PlatformFileError error_code, IPC::PlatformFileForTransit file_for_transit, diff --git a/content/renderer/render_view_impl.h b/content/renderer/render_view_impl.h index 04490b9..a451a7b 100644 --- a/content/renderer/render_view_impl.h +++ b/content/renderer/render_view_impl.h @@ -53,6 +53,11 @@ #include "webkit/media/webmediaplayer_delegate.h" #include "webkit/plugins/npapi/webplugin_page_delegate.h" +#if defined(OS_ANDROID) +#include "content/renderer/android/content_detector.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebContentDetectionResult.h" +#endif + #if defined(COMPILER_MSVC) // RenderViewImpl is a diamond-shaped hierarchy, with WebWidgetClient at the // root. VS warns when we inherit the WebWidgetClient method implementations @@ -143,6 +148,9 @@ class WebDOMMessageEvent; class WebDataSource; class WebDragData; class WebGeolocationClient; +#if defined(OS_ANDROID) +class WebHitTestResult; +#endif class WebIconURL; class WebImage; class WebPeerConnection00Handler; @@ -505,6 +513,13 @@ class RenderViewImpl : public RenderWidget, virtual WebKit::WebUserMediaClient* userMediaClient(); virtual void draggableRegionsChanged(); +#if defined(OS_ANDROID) + virtual void scheduleContentIntent(const WebKit::WebURL& intent); + virtual void cancelScheduledContentIntents(); + virtual WebKit::WebContentDetectionResult detectContentAround( + const WebKit::WebHitTestResult& touch_hit); +#endif + // WebKit::WebFrameClient implementation ------------------------------------- virtual WebKit::WebPlugin* createPlugin( @@ -1082,6 +1097,11 @@ class RenderViewImpl : public RenderWidget, bool IsBackForwardToStaleEntry(const ViewMsg_Navigate_Params& params, bool is_reload); +#if defined(OS_ANDROID) + // Launch an Android content intent with the given URL. + void LaunchAndroidContentIntent(const GURL& intent_url, size_t request_id); +#endif + bool MaybeLoadAlternateErrorPage(WebKit::WebFrame* frame, const WebKit::WebURLError& error, bool replace); @@ -1343,6 +1363,19 @@ class RenderViewImpl : public RenderWidget, // Mouse Lock dispatcher attached to this view. MouseLockDispatcher* mouse_lock_dispatcher_; +#if defined(OS_ANDROID) + // Android Specific --------------------------------------------------------- + + // Expected id of the next content intent launched. Used to prevent scheduled + // intents to be launched if aborted. + size_t expected_content_intent_id_; + + // List of click-based content detectors. + typedef std::vector< linked_ptr<content::ContentDetector> > + ContentDetectorList; + ContentDetectorList content_detectors_; +#endif + // Misc ---------------------------------------------------------------------- // The current and pending file chooser completion objects. If the queue is |