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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 #include "content/common/input_messages.h" | 53 #include "content/common/input_messages.h" |
54 #include "content/common/page_messages.h" | 54 #include "content/common/page_messages.h" |
55 #include "content/common/render_message_filter.mojom.h" | 55 #include "content/common/render_message_filter.mojom.h" |
56 #include "content/common/view_messages.h" | 56 #include "content/common/view_messages.h" |
57 #include "content/public/common/associated_interface_provider.h" | 57 #include "content/public/common/associated_interface_provider.h" |
58 #include "content/public/common/bindings_policy.h" | 58 #include "content/public/common/bindings_policy.h" |
59 #include "content/public/common/browser_side_navigation_policy.h" | 59 #include "content/public/common/browser_side_navigation_policy.h" |
60 #include "content/public/common/content_client.h" | 60 #include "content/public/common/content_client.h" |
61 #include "content/public/common/content_constants.h" | 61 #include "content/public/common/content_constants.h" |
62 #include "content/public/common/content_switches.h" | 62 #include "content/public/common/content_switches.h" |
63 #include "content/public/common/favicon_url.h" | |
64 #include "content/public/common/page_importance_signals.h" | 63 #include "content/public/common/page_importance_signals.h" |
65 #include "content/public/common/page_state.h" | 64 #include "content/public/common/page_state.h" |
66 #include "content/public/common/page_zoom.h" | 65 #include "content/public/common/page_zoom.h" |
67 #include "content/public/common/three_d_api_types.h" | 66 #include "content/public/common/three_d_api_types.h" |
68 #include "content/public/common/url_constants.h" | 67 #include "content/public/common/url_constants.h" |
69 #include "content/public/common/web_preferences.h" | 68 #include "content/public/common/web_preferences.h" |
70 #include "content/public/renderer/content_renderer_client.h" | 69 #include "content/public/renderer/content_renderer_client.h" |
71 #include "content/public/renderer/document_state.h" | 70 #include "content/public/renderer/document_state.h" |
72 #include "content/public/renderer/navigation_state.h" | 71 #include "content/public/renderer/navigation_state.h" |
73 #include "content/public/renderer/render_view_observer.h" | 72 #include "content/public/renderer/render_view_observer.h" |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 using blink::WebElement; | 211 using blink::WebElement; |
213 using blink::WebFileChooserCompletion; | 212 using blink::WebFileChooserCompletion; |
214 using blink::WebFormControlElement; | 213 using blink::WebFormControlElement; |
215 using blink::WebFormElement; | 214 using blink::WebFormElement; |
216 using blink::WebFrame; | 215 using blink::WebFrame; |
217 using blink::WebFrameContentDumper; | 216 using blink::WebFrameContentDumper; |
218 using blink::WebGestureEvent; | 217 using blink::WebGestureEvent; |
219 using blink::WebHistoryItem; | 218 using blink::WebHistoryItem; |
220 using blink::WebHTTPBody; | 219 using blink::WebHTTPBody; |
221 using blink::WebHitTestResult; | 220 using blink::WebHitTestResult; |
222 using blink::WebIconURL; | |
223 using blink::WebImage; | 221 using blink::WebImage; |
224 using blink::WebInputElement; | 222 using blink::WebInputElement; |
225 using blink::WebInputEvent; | 223 using blink::WebInputEvent; |
226 using blink::WebLocalFrame; | 224 using blink::WebLocalFrame; |
227 using blink::WebMediaPlayerAction; | 225 using blink::WebMediaPlayerAction; |
228 using blink::WebMouseEvent; | 226 using blink::WebMouseEvent; |
229 using blink::WebNavigationPolicy; | 227 using blink::WebNavigationPolicy; |
230 using blink::WebNavigationType; | 228 using blink::WebNavigationType; |
231 using blink::WebNode; | 229 using blink::WebNode; |
232 using blink::WebPluginAction; | 230 using blink::WebPluginAction; |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
339 *base::CommandLine::ForCurrentProcess(); | 337 *base::CommandLine::ForCurrentProcess(); |
340 if (command_line.HasSwitch(switches::kDisablePreferCompositingToLCDText)) | 338 if (command_line.HasSwitch(switches::kDisablePreferCompositingToLCDText)) |
341 return false; | 339 return false; |
342 if (command_line.HasSwitch(switches::kEnablePreferCompositingToLCDText)) | 340 if (command_line.HasSwitch(switches::kEnablePreferCompositingToLCDText)) |
343 return true; | 341 return true; |
344 if (!compositor_deps->IsLcdTextEnabled()) | 342 if (!compositor_deps->IsLcdTextEnabled()) |
345 return true; | 343 return true; |
346 return DeviceScaleEnsuresTextQuality(device_scale_factor); | 344 return DeviceScaleEnsuresTextQuality(device_scale_factor); |
347 } | 345 } |
348 | 346 |
349 static FaviconURL::IconType ToFaviconType(blink::WebIconURL::Type type) { | |
350 switch (type) { | |
351 case blink::WebIconURL::kTypeFavicon: | |
352 return FaviconURL::FAVICON; | |
353 case blink::WebIconURL::kTypeTouch: | |
354 return FaviconURL::TOUCH_ICON; | |
355 case blink::WebIconURL::kTypeTouchPrecomposed: | |
356 return FaviconURL::TOUCH_PRECOMPOSED_ICON; | |
357 case blink::WebIconURL::kTypeInvalid: | |
358 return FaviconURL::INVALID_ICON; | |
359 } | |
360 return FaviconURL::INVALID_ICON; | |
361 } | |
362 | |
363 static void ConvertToFaviconSizes( | |
364 const blink::WebVector<blink::WebSize>& web_sizes, | |
365 std::vector<gfx::Size>* sizes) { | |
366 DCHECK(sizes->empty()); | |
367 sizes->reserve(web_sizes.size()); | |
368 for (size_t i = 0; i < web_sizes.size(); ++i) | |
369 sizes->push_back(gfx::Size(web_sizes[i])); | |
370 } | |
371 | |
372 /////////////////////////////////////////////////////////////////////////////// | 347 /////////////////////////////////////////////////////////////////////////////// |
373 | 348 |
374 namespace { | 349 namespace { |
375 | 350 |
376 typedef void (*SetFontFamilyWrapper)(blink::WebSettings*, | 351 typedef void (*SetFontFamilyWrapper)(blink::WebSettings*, |
377 const base::string16&, | 352 const base::string16&, |
378 UScriptCode); | 353 UScriptCode); |
379 | 354 |
380 void SetStandardFontFamilyWrapper(WebSettings* settings, | 355 void SetStandardFontFamilyWrapper(WebSettings* settings, |
381 const base::string16& font, | 356 const base::string16& font, |
(...skipping 1174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1556 frames_in_progress_++; | 1531 frames_in_progress_++; |
1557 } | 1532 } |
1558 | 1533 |
1559 void RenderViewImpl::FrameDidStopLoading(WebFrame* frame) { | 1534 void RenderViewImpl::FrameDidStopLoading(WebFrame* frame) { |
1560 // TODO(japhet): This should be a DCHECK, but the pdf plugin sometimes | 1535 // TODO(japhet): This should be a DCHECK, but the pdf plugin sometimes |
1561 // calls DidStopLoading() without a matching DidStartLoading(). | 1536 // calls DidStopLoading() without a matching DidStartLoading(). |
1562 if (frames_in_progress_ == 0) | 1537 if (frames_in_progress_ == 0) |
1563 return; | 1538 return; |
1564 frames_in_progress_--; | 1539 frames_in_progress_--; |
1565 if (frames_in_progress_ == 0) { | 1540 if (frames_in_progress_ == 0) { |
1566 DidStopLoadingIcons(); | |
1567 for (auto& observer : observers_) | 1541 for (auto& observer : observers_) |
1568 observer.DidStopLoading(); | 1542 observer.DidStopLoading(); |
1569 } | 1543 } |
1570 } | 1544 } |
1571 | 1545 |
1572 void RenderViewImpl::AttachWebFrameWidget(blink::WebFrameWidget* frame_widget) { | 1546 void RenderViewImpl::AttachWebFrameWidget(blink::WebFrameWidget* frame_widget) { |
1573 // The previous WebFrameWidget must already be detached by CloseForFrame(). | 1547 // The previous WebFrameWidget must already be detached by CloseForFrame(). |
1574 DCHECK(!frame_widget_); | 1548 DCHECK(!frame_widget_); |
1575 frame_widget_ = frame_widget; | 1549 frame_widget_ = frame_widget; |
1576 } | 1550 } |
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1915 const blink::WebElement& element) { | 1889 const blink::WebElement& element) { |
1916 blink::WebRect bounding_box_in_window = element.BoundsInViewport(); | 1890 blink::WebRect bounding_box_in_window = element.BoundsInViewport(); |
1917 ConvertViewportToWindowViaWidget(&bounding_box_in_window); | 1891 ConvertViewportToWindowViaWidget(&bounding_box_in_window); |
1918 return gfx::RectF(bounding_box_in_window); | 1892 return gfx::RectF(bounding_box_in_window); |
1919 } | 1893 } |
1920 | 1894 |
1921 bool RenderViewImpl::HasAddedInputHandler() const { | 1895 bool RenderViewImpl::HasAddedInputHandler() const { |
1922 return has_added_input_handler_; | 1896 return has_added_input_handler_; |
1923 } | 1897 } |
1924 | 1898 |
1925 void RenderViewImpl::didChangeIcon(WebLocalFrame* frame, | |
1926 WebIconURL::Type icon_type) { | |
1927 if (frame->Parent()) | |
1928 return; | |
1929 | |
1930 WebVector<WebIconURL> icon_urls = frame->IconURLs(icon_type); | |
1931 std::vector<FaviconURL> urls; | |
1932 for (size_t i = 0; i < icon_urls.size(); i++) { | |
1933 std::vector<gfx::Size> sizes; | |
1934 ConvertToFaviconSizes(icon_urls[i].Sizes(), &sizes); | |
1935 urls.push_back(FaviconURL(icon_urls[i].GetIconURL(), | |
1936 ToFaviconType(icon_urls[i].IconType()), sizes)); | |
1937 } | |
1938 SendUpdateFaviconURL(urls); | |
1939 } | |
1940 | |
1941 void RenderViewImpl::CheckPreferredSize() { | 1899 void RenderViewImpl::CheckPreferredSize() { |
1942 // We don't always want to send the change messages over IPC, only if we've | 1900 // We don't always want to send the change messages over IPC, only if we've |
1943 // been put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode| | 1901 // been put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode| |
1944 // message. | 1902 // message. |
1945 if (!send_preferred_size_changes_ || !webview()) | 1903 if (!send_preferred_size_changes_ || !webview()) |
1946 return; | 1904 return; |
1947 | 1905 |
1948 gfx::Size size = webview()->ContentsPreferredMinimumSize(); | 1906 gfx::Size size = webview()->ContentsPreferredMinimumSize(); |
1949 if (size == preferred_size_) | 1907 if (size == preferred_size_) |
1950 return; | 1908 return; |
(...skipping 640 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2591 webview()->ResolveTapDisambiguation(timestamp_seconds, tap_viewport_offset, | 2549 webview()->ResolveTapDisambiguation(timestamp_seconds, tap_viewport_offset, |
2592 is_long_press); | 2550 is_long_press); |
2593 } | 2551 } |
2594 | 2552 |
2595 void RenderViewImpl::DidCommitCompositorFrame() { | 2553 void RenderViewImpl::DidCommitCompositorFrame() { |
2596 RenderWidget::DidCommitCompositorFrame(); | 2554 RenderWidget::DidCommitCompositorFrame(); |
2597 for (auto& observer : observers_) | 2555 for (auto& observer : observers_) |
2598 observer.DidCommitCompositorFrame(); | 2556 observer.DidCommitCompositorFrame(); |
2599 } | 2557 } |
2600 | 2558 |
2601 void RenderViewImpl::SendUpdateFaviconURL(const std::vector<FaviconURL>& urls) { | |
2602 if (!urls.empty()) | |
2603 Send(new ViewHostMsg_UpdateFaviconURL(GetRoutingID(), urls)); | |
2604 } | |
2605 | |
2606 void RenderViewImpl::DidStopLoadingIcons() { | |
2607 int icon_types = WebIconURL::kTypeFavicon | | |
2608 WebIconURL::kTypeTouchPrecomposed | WebIconURL::kTypeTouch; | |
2609 | |
2610 // Favicons matter only for the top-level frame. If it is a WebRemoteFrame, | |
2611 // just return early. | |
2612 if (webview()->MainFrame()->IsWebRemoteFrame()) | |
2613 return; | |
2614 | |
2615 WebVector<WebIconURL> icon_urls = | |
2616 webview()->MainFrame()->IconURLs(icon_types); | |
2617 | |
2618 std::vector<FaviconURL> urls; | |
2619 for (size_t i = 0; i < icon_urls.size(); i++) { | |
2620 WebURL url = icon_urls[i].GetIconURL(); | |
2621 std::vector<gfx::Size> sizes; | |
2622 ConvertToFaviconSizes(icon_urls[i].Sizes(), &sizes); | |
2623 if (!url.IsEmpty()) | |
2624 urls.push_back( | |
2625 FaviconURL(url, ToFaviconType(icon_urls[i].IconType()), sizes)); | |
2626 } | |
2627 SendUpdateFaviconURL(urls); | |
2628 } | |
2629 | |
2630 void RenderViewImpl::UpdateWebViewWithDeviceScaleFactor() { | 2559 void RenderViewImpl::UpdateWebViewWithDeviceScaleFactor() { |
2631 if (!webview()) | 2560 if (!webview()) |
2632 return; | 2561 return; |
2633 if (IsUseZoomForDSFEnabled()) { | 2562 if (IsUseZoomForDSFEnabled()) { |
2634 webview()->SetZoomFactorForDeviceScaleFactor(device_scale_factor_); | 2563 webview()->SetZoomFactorForDeviceScaleFactor(device_scale_factor_); |
2635 } else { | 2564 } else { |
2636 webview()->SetDeviceScaleFactor(device_scale_factor_); | 2565 webview()->SetDeviceScaleFactor(device_scale_factor_); |
2637 } | 2566 } |
2638 webview()->GetSettings()->SetPreferCompositingToLCDTextEnabled( | 2567 webview()->GetSettings()->SetPreferCompositingToLCDTextEnabled( |
2639 PreferCompositingToLCDText(compositor_deps_, device_scale_factor_)); | 2568 PreferCompositingToLCDText(compositor_deps_, device_scale_factor_)); |
(...skipping 23 matching lines...) Expand all Loading... |
2663 input_event.GetCoalescedEventsPointers(), latency_info, | 2592 input_event.GetCoalescedEventsPointers(), latency_info, |
2664 dispatch_type); | 2593 dispatch_type); |
2665 return INPUT_EVENT_ACK_STATE_NOT_CONSUMED; | 2594 return INPUT_EVENT_ACK_STATE_NOT_CONSUMED; |
2666 } | 2595 } |
2667 idle_user_detector_->ActivityDetected(); | 2596 idle_user_detector_->ActivityDetected(); |
2668 return RenderWidget::HandleInputEvent(input_event, latency_info, | 2597 return RenderWidget::HandleInputEvent(input_event, latency_info, |
2669 dispatch_type); | 2598 dispatch_type); |
2670 } | 2599 } |
2671 | 2600 |
2672 } // namespace content | 2601 } // namespace content |
OLD | NEW |