| 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 #include "content/renderer/render_view_impl.h" | 5 #include "content/renderer/render_view_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 #include "ui/gfx/native_widget_types.h" | 174 #include "ui/gfx/native_widget_types.h" |
| 175 #include "ui/latency/latency_info.h" | 175 #include "ui/latency/latency_info.h" |
| 176 #include "url/origin.h" | 176 #include "url/origin.h" |
| 177 #include "url/url_constants.h" | 177 #include "url/url_constants.h" |
| 178 #include "v8/include/v8.h" | 178 #include "v8/include/v8.h" |
| 179 | 179 |
| 180 #if defined(OS_ANDROID) | 180 #if defined(OS_ANDROID) |
| 181 #include <cpu-features.h> | 181 #include <cpu-features.h> |
| 182 | 182 |
| 183 #include "base/android/build_info.h" | 183 #include "base/android/build_info.h" |
| 184 #include "content/renderer/android/address_detector.h" | |
| 185 #include "content/renderer/android/content_detector.h" | |
| 186 #include "content/renderer/android/disambiguation_popup_helper.h" | 184 #include "content/renderer/android/disambiguation_popup_helper.h" |
| 187 #include "content/renderer/android/email_detector.h" | |
| 188 #include "content/renderer/android/phone_number_detector.h" | |
| 189 #include "ui/gfx/geometry/rect_f.h" | 185 #include "ui/gfx/geometry/rect_f.h" |
| 190 | 186 |
| 191 #elif defined(OS_MACOSX) | 187 #elif defined(OS_MACOSX) |
| 192 #include "skia/ext/skia_utils_mac.h" | 188 #include "skia/ext/skia_utils_mac.h" |
| 193 #endif | 189 #endif |
| 194 | 190 |
| 195 #if BUILDFLAG(ENABLE_PLUGINS) | 191 #if BUILDFLAG(ENABLE_PLUGINS) |
| 196 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" | 192 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" |
| 197 #include "content/renderer/pepper/pepper_plugin_registry.h" | 193 #include "content/renderer/pepper/pepper_plugin_registry.h" |
| 198 #endif | 194 #endif |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 // state and scroll position) to the browser. We delay sending changes to avoid | 273 // state and scroll position) to the browser. We delay sending changes to avoid |
| 278 // spamming the browser. | 274 // spamming the browser. |
| 279 // To avoid having tab/session restore require sending a message to get the | 275 // To avoid having tab/session restore require sending a message to get the |
| 280 // current content state during tab closing we use a shorter timeout for the | 276 // current content state during tab closing we use a shorter timeout for the |
| 281 // foreground renderer. This means there is a small window of time from which | 277 // foreground renderer. This means there is a small window of time from which |
| 282 // content state is modified and not sent to session restore, but this is | 278 // content state is modified and not sent to session restore, but this is |
| 283 // better than having to wake up all renderers during shutdown. | 279 // better than having to wake up all renderers during shutdown. |
| 284 const int kDelaySecondsForContentStateSyncHidden = 5; | 280 const int kDelaySecondsForContentStateSyncHidden = 5; |
| 285 const int kDelaySecondsForContentStateSync = 1; | 281 const int kDelaySecondsForContentStateSync = 1; |
| 286 | 282 |
| 287 #if defined(OS_ANDROID) | |
| 288 // Delay between tapping in content and launching the associated android intent. | |
| 289 // Used to allow users see what has been recognized as content. | |
| 290 const size_t kContentIntentDelayMilliseconds = 700; | |
| 291 #endif | |
| 292 | |
| 293 static RenderViewImpl* (*g_create_render_view_impl)( | 283 static RenderViewImpl* (*g_create_render_view_impl)( |
| 294 CompositorDependencies* compositor_deps, | 284 CompositorDependencies* compositor_deps, |
| 295 const mojom::CreateViewParams&) = nullptr; | 285 const mojom::CreateViewParams&) = nullptr; |
| 296 | 286 |
| 297 // static | 287 // static |
| 298 Referrer RenderViewImpl::GetReferrerFromRequest( | 288 Referrer RenderViewImpl::GetReferrerFromRequest( |
| 299 WebFrame* frame, | 289 WebFrame* frame, |
| 300 const WebURLRequest& request) { | 290 const WebURLRequest& request) { |
| 301 return Referrer( | 291 return Referrer( |
| 302 blink::WebStringToGURL(request.httpHeaderField( | 292 blink::WebStringToGURL(request.httpHeaderField( |
| (...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 594 #endif | 584 #endif |
| 595 browser_controls_shrink_blink_size_(false), | 585 browser_controls_shrink_blink_size_(false), |
| 596 top_controls_height_(0.f), | 586 top_controls_height_(0.f), |
| 597 webview_(nullptr), | 587 webview_(nullptr), |
| 598 has_scrolled_focused_editable_node_into_rect_(false), | 588 has_scrolled_focused_editable_node_into_rect_(false), |
| 599 page_zoom_level_(params.page_zoom_level), | 589 page_zoom_level_(params.page_zoom_level), |
| 600 main_render_frame_(nullptr), | 590 main_render_frame_(nullptr), |
| 601 frame_widget_(nullptr), | 591 frame_widget_(nullptr), |
| 602 speech_recognition_dispatcher_(NULL), | 592 speech_recognition_dispatcher_(NULL), |
| 603 #if defined(OS_ANDROID) | 593 #if defined(OS_ANDROID) |
| 604 expected_content_intent_id_(0), | |
| 605 was_created_by_renderer_(false), | 594 was_created_by_renderer_(false), |
| 606 #endif | 595 #endif |
| 607 enumeration_completion_id_(0), | 596 enumeration_completion_id_(0), |
| 608 session_storage_namespace_id_(params.session_storage_namespace_id), | 597 session_storage_namespace_id_(params.session_storage_namespace_id), |
| 609 weak_ptr_factory_(this) { | 598 weak_ptr_factory_(this) { |
| 610 GetWidget()->set_owner_delegate(this); | 599 GetWidget()->set_owner_delegate(this); |
| 611 } | 600 } |
| 612 | 601 |
| 613 void RenderViewImpl::Initialize( | 602 void RenderViewImpl::Initialize( |
| 614 const mojom::CreateViewParams& params, | 603 const mojom::CreateViewParams& params, |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 701 if (params.proxy_routing_id != MSG_ROUTING_NONE) { | 690 if (params.proxy_routing_id != MSG_ROUTING_NONE) { |
| 702 CHECK(params.swapped_out); | 691 CHECK(params.swapped_out); |
| 703 RenderFrameProxy::CreateFrameProxy(params.proxy_routing_id, GetRoutingID(), | 692 RenderFrameProxy::CreateFrameProxy(params.proxy_routing_id, GetRoutingID(), |
| 704 opener_frame, MSG_ROUTING_NONE, | 693 opener_frame, MSG_ROUTING_NONE, |
| 705 params.replicated_frame_state); | 694 params.replicated_frame_state); |
| 706 } | 695 } |
| 707 | 696 |
| 708 if (main_render_frame_) | 697 if (main_render_frame_) |
| 709 main_render_frame_->Initialize(); | 698 main_render_frame_->Initialize(); |
| 710 | 699 |
| 711 #if defined(OS_ANDROID) | |
| 712 content_detectors_.push_back(base::MakeUnique<AddressDetector>()); | |
| 713 const std::string& contry_iso = | |
| 714 params.renderer_preferences.network_contry_iso; | |
| 715 if (!contry_iso.empty()) { | |
| 716 content_detectors_.push_back( | |
| 717 base::MakeUnique<PhoneNumberDetector>(contry_iso)); | |
| 718 } | |
| 719 content_detectors_.push_back(base::MakeUnique<EmailDetector>()); | |
| 720 #endif | |
| 721 | |
| 722 // If this RenderView's creation was initiated by an opener page in this | 700 // If this RenderView's creation was initiated by an opener page in this |
| 723 // process, (e.g. window.open()), we won't be visible until we ask the opener, | 701 // process, (e.g. window.open()), we won't be visible until we ask the opener, |
| 724 // via show_callback, to make us visible. Otherwise, we went through a | 702 // via show_callback, to make us visible. Otherwise, we went through a |
| 725 // browser-initiated creation, and show() won't be called. | 703 // browser-initiated creation, and show() won't be called. |
| 726 if (!was_created_by_renderer) | 704 if (!was_created_by_renderer) |
| 727 did_show_ = true; | 705 did_show_ = true; |
| 728 | 706 |
| 729 // Set the main frame's name. Only needs to be done for WebLocalFrames, | 707 // Set the main frame's name. Only needs to be done for WebLocalFrames, |
| 730 // since the remote case was handled as part of SetReplicatedState on the | 708 // since the remote case was handled as part of SetReplicatedState on the |
| 731 // proxy above. | 709 // proxy above. |
| (...skipping 1689 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2421 | 2399 |
| 2422 auto* web_signals = webview()->pageImportanceSignals(); | 2400 auto* web_signals = webview()->pageImportanceSignals(); |
| 2423 | 2401 |
| 2424 PageImportanceSignals signals; | 2402 PageImportanceSignals signals; |
| 2425 signals.had_form_interaction = web_signals->hadFormInteraction(); | 2403 signals.had_form_interaction = web_signals->hadFormInteraction(); |
| 2426 | 2404 |
| 2427 main_render_frame_->Send(new FrameHostMsg_UpdatePageImportanceSignals( | 2405 main_render_frame_->Send(new FrameHostMsg_UpdatePageImportanceSignals( |
| 2428 main_render_frame_->GetRoutingID(), signals)); | 2406 main_render_frame_->GetRoutingID(), signals)); |
| 2429 } | 2407 } |
| 2430 | 2408 |
| 2431 // TODO(dglazkov): Remove this ifdef. The content detection code | |
| 2432 // should not be platform-specific. | |
| 2433 // See http://crbug.com/635214 for details. | |
| 2434 #if defined(OS_ANDROID) | 2409 #if defined(OS_ANDROID) |
| 2435 WebURL RenderViewImpl::detectContentIntentAt( | |
| 2436 const WebHitTestResult& touch_hit) { | |
| 2437 // TODO(twellington): Remove content detection entirely. It is | |
| 2438 // currently only enabled for tests. crbug.com/664307. | |
| 2439 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 2440 switches::kEnableContentIntentDetection)) { | |
| 2441 return WebURL(); | |
| 2442 } | |
| 2443 DCHECK(touch_hit.node().isTextNode()); | |
| 2444 | |
| 2445 // Process the position with all the registered content detectors until | |
| 2446 // a match is found. Priority is provided by their relative order. | |
| 2447 for (const auto& detector : content_detectors_) { | |
| 2448 WebURL intent = detector->FindTappedContent(touch_hit); | |
| 2449 if (intent.isValid()) { | |
| 2450 return intent; | |
| 2451 } | |
| 2452 } | |
| 2453 return WebURL(); | |
| 2454 } | |
| 2455 | |
| 2456 void RenderViewImpl::scheduleContentIntent(const WebURL& intent, | |
| 2457 bool is_main_frame) { | |
| 2458 // Introduce a short delay so that the user can notice the content. | |
| 2459 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | |
| 2460 FROM_HERE, base::Bind(&RenderViewImpl::LaunchAndroidContentIntent, | |
| 2461 weak_ptr_factory_.GetWeakPtr(), intent, | |
| 2462 expected_content_intent_id_, is_main_frame), | |
| 2463 base::TimeDelta::FromMilliseconds(kContentIntentDelayMilliseconds)); | |
| 2464 } | |
| 2465 | |
| 2466 void RenderViewImpl::cancelScheduledContentIntents() { | |
| 2467 ++expected_content_intent_id_; | |
| 2468 } | |
| 2469 | |
| 2470 void RenderViewImpl::LaunchAndroidContentIntent(const GURL& intent, | |
| 2471 size_t request_id, | |
| 2472 bool is_main_frame) { | |
| 2473 if (request_id != expected_content_intent_id_) | |
| 2474 return; | |
| 2475 | |
| 2476 // Remove the content highlighting if any. | |
| 2477 if (RenderWidgetCompositor* rwc = compositor()) | |
| 2478 rwc->setNeedsBeginFrame(); | |
| 2479 | |
| 2480 if (!intent.is_empty()) { | |
| 2481 Send(new ViewHostMsg_StartContentIntent(GetRoutingID(), intent, | |
| 2482 is_main_frame)); | |
| 2483 } | |
| 2484 } | |
| 2485 | |
| 2486 bool RenderViewImpl::openDateTimeChooser( | 2410 bool RenderViewImpl::openDateTimeChooser( |
| 2487 const blink::WebDateTimeChooserParams& params, | 2411 const blink::WebDateTimeChooserParams& params, |
| 2488 blink::WebDateTimeChooserCompletion* completion) { | 2412 blink::WebDateTimeChooserCompletion* completion) { |
| 2489 // JavaScript may try to open a date time chooser while one is already open. | 2413 // JavaScript may try to open a date time chooser while one is already open. |
| 2490 if (date_time_picker_client_) | 2414 if (date_time_picker_client_) |
| 2491 return false; | 2415 return false; |
| 2492 date_time_picker_client_.reset( | 2416 date_time_picker_client_.reset( |
| 2493 new RendererDateTimePicker(this, params, completion)); | 2417 new RendererDateTimePicker(this, params, completion)); |
| 2494 return date_time_picker_client_->Open(); | 2418 return date_time_picker_client_->Open(); |
| 2495 } | 2419 } |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2755 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 2679 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 2756 } | 2680 } |
| 2757 | 2681 |
| 2758 std::unique_ptr<InputEventAck> ack( | 2682 std::unique_ptr<InputEventAck> ack( |
| 2759 new InputEventAck(InputEventAckSource::MAIN_THREAD, input_event->type(), | 2683 new InputEventAck(InputEventAckSource::MAIN_THREAD, input_event->type(), |
| 2760 INPUT_EVENT_ACK_STATE_NOT_CONSUMED)); | 2684 INPUT_EVENT_ACK_STATE_NOT_CONSUMED)); |
| 2761 OnInputEventAck(std::move(ack)); | 2685 OnInputEventAck(std::move(ack)); |
| 2762 } | 2686 } |
| 2763 | 2687 |
| 2764 } // namespace content | 2688 } // namespace content |
| OLD | NEW |