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 <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
486 RenderViewImpl::RenderViewImpl( | 486 RenderViewImpl::RenderViewImpl( |
487 gfx::NativeViewId parent_hwnd, | 487 gfx::NativeViewId parent_hwnd, |
488 int32 opener_id, | 488 int32 opener_id, |
489 const content::RendererPreferences& renderer_prefs, | 489 const content::RendererPreferences& renderer_prefs, |
490 const WebPreferences& webkit_prefs, | 490 const WebPreferences& webkit_prefs, |
491 SharedRenderViewCounter* counter, | 491 SharedRenderViewCounter* counter, |
492 int32 routing_id, | 492 int32 routing_id, |
493 int32 surface_id, | 493 int32 surface_id, |
494 int64 session_storage_namespace_id, | 494 int64 session_storage_namespace_id, |
495 const string16& frame_name, | 495 const string16& frame_name, |
| 496 const std::string& user_agent_override, |
496 bool is_renderer_created, | 497 bool is_renderer_created, |
497 bool swapped_out, | 498 bool swapped_out, |
498 int32 next_page_id, | 499 int32 next_page_id, |
499 const WebKit::WebScreenInfo& screen_info, | 500 const WebKit::WebScreenInfo& screen_info, |
500 content::GuestToEmbedderChannel* guest_to_embedder_channel, | 501 content::GuestToEmbedderChannel* guest_to_embedder_channel, |
501 AccessibilityMode accessibility_mode) | 502 AccessibilityMode accessibility_mode) |
502 : RenderWidget(WebKit::WebPopupTypeNone, screen_info, swapped_out), | 503 : RenderWidget(WebKit::WebPopupTypeNone, screen_info, swapped_out), |
503 webkit_preferences_(webkit_prefs), | 504 webkit_preferences_(webkit_prefs), |
504 send_content_state_immediately_(false), | 505 send_content_state_immediately_(false), |
505 enabled_bindings_(0), | 506 enabled_bindings_(0), |
506 send_preferred_size_changes_(false), | 507 send_preferred_size_changes_(false), |
| 508 user_agent_override_(user_agent_override), |
| 509 is_overriding_user_agent_(false), |
507 is_loading_(false), | 510 is_loading_(false), |
508 navigation_gesture_(NavigationGestureUnknown), | 511 navigation_gesture_(NavigationGestureUnknown), |
509 opened_by_user_gesture_(true), | 512 opened_by_user_gesture_(true), |
510 opener_suppressed_(false), | 513 opener_suppressed_(false), |
511 page_id_(-1), | 514 page_id_(-1), |
512 last_page_id_sent_to_browser_(-1), | 515 last_page_id_sent_to_browser_(-1), |
513 next_page_id_(next_page_id), | 516 next_page_id_(next_page_id), |
514 history_list_offset_(-1), | 517 history_list_offset_(-1), |
515 history_list_length_(0), | 518 history_list_length_(0), |
516 target_url_status_(TARGET_NONE), | 519 target_url_status_(TARGET_NONE), |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
705 RenderViewImpl* RenderViewImpl::Create( | 708 RenderViewImpl* RenderViewImpl::Create( |
706 gfx::NativeViewId parent_hwnd, | 709 gfx::NativeViewId parent_hwnd, |
707 int32 opener_id, | 710 int32 opener_id, |
708 const content::RendererPreferences& renderer_prefs, | 711 const content::RendererPreferences& renderer_prefs, |
709 const WebPreferences& webkit_prefs, | 712 const WebPreferences& webkit_prefs, |
710 SharedRenderViewCounter* counter, | 713 SharedRenderViewCounter* counter, |
711 int32 routing_id, | 714 int32 routing_id, |
712 int32 surface_id, | 715 int32 surface_id, |
713 int64 session_storage_namespace_id, | 716 int64 session_storage_namespace_id, |
714 const string16& frame_name, | 717 const string16& frame_name, |
| 718 const std::string& user_agent_override, |
715 bool is_renderer_created, | 719 bool is_renderer_created, |
716 bool swapped_out, | 720 bool swapped_out, |
717 int32 next_page_id, | 721 int32 next_page_id, |
718 const WebKit::WebScreenInfo& screen_info, | 722 const WebKit::WebScreenInfo& screen_info, |
719 content::GuestToEmbedderChannel* guest_to_embedder_channel, | 723 content::GuestToEmbedderChannel* guest_to_embedder_channel, |
720 AccessibilityMode accessibility_mode) { | 724 AccessibilityMode accessibility_mode) { |
721 DCHECK(routing_id != MSG_ROUTING_NONE); | 725 DCHECK(routing_id != MSG_ROUTING_NONE); |
722 return new RenderViewImpl( | 726 return new RenderViewImpl( |
723 parent_hwnd, | 727 parent_hwnd, |
724 opener_id, | 728 opener_id, |
725 renderer_prefs, | 729 renderer_prefs, |
726 webkit_prefs, | 730 webkit_prefs, |
727 counter, | 731 counter, |
728 routing_id, | 732 routing_id, |
729 surface_id, | 733 surface_id, |
730 session_storage_namespace_id, | 734 session_storage_namespace_id, |
731 frame_name, | 735 frame_name, |
| 736 user_agent_override, |
732 is_renderer_created, | 737 is_renderer_created, |
733 swapped_out, | 738 swapped_out, |
734 next_page_id, | 739 next_page_id, |
735 screen_info, | 740 screen_info, |
736 guest_to_embedder_channel, | 741 guest_to_embedder_channel, |
737 accessibility_mode); | 742 accessibility_mode); |
738 } | 743 } |
739 | 744 |
740 WebPeerConnectionHandler* RenderViewImpl::CreatePeerConnectionHandler( | 745 WebPeerConnectionHandler* RenderViewImpl::CreatePeerConnectionHandler( |
741 WebPeerConnectionHandlerClient* client) { | 746 WebPeerConnectionHandlerClient* client) { |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
846 IPC_MESSAGE_HANDLER(ViewMsg_PasteAndMatchStyle, OnPasteAndMatchStyle) | 851 IPC_MESSAGE_HANDLER(ViewMsg_PasteAndMatchStyle, OnPasteAndMatchStyle) |
847 IPC_MESSAGE_HANDLER(ViewMsg_Replace, OnReplace) | 852 IPC_MESSAGE_HANDLER(ViewMsg_Replace, OnReplace) |
848 IPC_MESSAGE_HANDLER(ViewMsg_Delete, OnDelete) | 853 IPC_MESSAGE_HANDLER(ViewMsg_Delete, OnDelete) |
849 IPC_MESSAGE_HANDLER(ViewMsg_SelectAll, OnSelectAll) | 854 IPC_MESSAGE_HANDLER(ViewMsg_SelectAll, OnSelectAll) |
850 IPC_MESSAGE_HANDLER(ViewMsg_SelectRange, OnSelectRange) | 855 IPC_MESSAGE_HANDLER(ViewMsg_SelectRange, OnSelectRange) |
851 IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt) | 856 IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt) |
852 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteEditCommand, OnExecuteEditCommand) | 857 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteEditCommand, OnExecuteEditCommand) |
853 IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind) | 858 IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind) |
854 IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding) | 859 IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding) |
855 IPC_MESSAGE_HANDLER(ViewMsg_FindReplyACK, OnFindReplyAck) | 860 IPC_MESSAGE_HANDLER(ViewMsg_FindReplyACK, OnFindReplyAck) |
| 861 IPC_MESSAGE_HANDLER(ViewMsg_SetUserAgentOverride, OnSetUserAgentOverride) |
856 IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom) | 862 IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom) |
857 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevel, OnSetZoomLevel) | 863 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevel, OnSetZoomLevel) |
858 IPC_MESSAGE_HANDLER(ViewMsg_ZoomFactor, OnZoomFactor) | 864 IPC_MESSAGE_HANDLER(ViewMsg_ZoomFactor, OnZoomFactor) |
859 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForLoadingURL, | 865 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForLoadingURL, |
860 OnSetZoomLevelForLoadingURL) | 866 OnSetZoomLevelForLoadingURL) |
861 IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding) | 867 IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding) |
862 IPC_MESSAGE_HANDLER(ViewMsg_ResetPageEncodingToDefault, | 868 IPC_MESSAGE_HANDLER(ViewMsg_ResetPageEncodingToDefault, |
863 OnResetPageEncodingToDefault) | 869 OnResetPageEncodingToDefault) |
864 IPC_MESSAGE_HANDLER(ViewMsg_ScriptEvalRequest, OnScriptEvalRequest) | 870 IPC_MESSAGE_HANDLER(ViewMsg_ScriptEvalRequest, OnScriptEvalRequest) |
865 IPC_MESSAGE_HANDLER(ViewMsg_PostMessageEvent, OnPostMessageEvent) | 871 IPC_MESSAGE_HANDLER(ViewMsg_PostMessageEvent, OnPostMessageEvent) |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
960 | 966 |
961 // If this is a stale back/forward (due to a recent navigation the browser | 967 // If this is a stale back/forward (due to a recent navigation the browser |
962 // didn't know about), ignore it. | 968 // didn't know about), ignore it. |
963 if (IsBackForwardToStaleEntry(params, is_reload)) | 969 if (IsBackForwardToStaleEntry(params, is_reload)) |
964 return; | 970 return; |
965 | 971 |
966 // Swap this renderer back in if necessary. | 972 // Swap this renderer back in if necessary. |
967 if (is_swapped_out_) | 973 if (is_swapped_out_) |
968 SetSwappedOut(false); | 974 SetSwappedOut(false); |
969 | 975 |
| 976 // Track whether we're using the user agent string override. |
| 977 is_overriding_user_agent_ = params.is_overriding_user_agent; |
| 978 |
970 history_list_offset_ = params.current_history_list_offset; | 979 history_list_offset_ = params.current_history_list_offset; |
971 history_list_length_ = params.current_history_list_length; | 980 history_list_length_ = params.current_history_list_length; |
972 if (history_list_length_ >= 0) | 981 if (history_list_length_ >= 0) |
973 history_page_ids_.resize(history_list_length_, -1); | 982 history_page_ids_.resize(history_list_length_, -1); |
974 if (params.pending_history_list_offset >= 0 && | 983 if (params.pending_history_list_offset >= 0 && |
975 params.pending_history_list_offset < history_list_length_) | 984 params.pending_history_list_offset < history_list_length_) |
976 history_page_ids_[params.pending_history_list_offset] = params.page_id; | 985 history_page_ids_[params.pending_history_list_offset] = params.page_id; |
977 | 986 |
978 content::GetContentClient()->SetActiveURL(params.url); | 987 content::GetContentClient()->SetActiveURL(params.url); |
979 | 988 |
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1392 original_request.httpHeaderField(WebString::fromUTF8("Referer"))), | 1401 original_request.httpHeaderField(WebString::fromUTF8("Referer"))), |
1393 GetReferrerPolicyFromRequest(frame, original_request)); | 1402 GetReferrerPolicyFromRequest(frame, original_request)); |
1394 } | 1403 } |
1395 | 1404 |
1396 string16 method = request.httpMethod(); | 1405 string16 method = request.httpMethod(); |
1397 if (EqualsASCII(method, "POST")) { | 1406 if (EqualsASCII(method, "POST")) { |
1398 params.is_post = true; | 1407 params.is_post = true; |
1399 params.post_id = ExtractPostId(item); | 1408 params.post_id = ExtractPostId(item); |
1400 } | 1409 } |
1401 | 1410 |
| 1411 // Send the user agent override back. |
| 1412 params.is_overriding_user_agent = is_overriding_user_agent_; |
| 1413 |
| 1414 // Track the URL of the original request. |
| 1415 params.original_request_url = original_request.url(); |
| 1416 |
1402 // Save some histogram data so we can compute the average memory used per | 1417 // Save some histogram data so we can compute the average memory used per |
1403 // page load of the glyphs. | 1418 // page load of the glyphs. |
1404 UMA_HISTOGRAM_COUNTS_10000("Memory.GlyphPagesPerLoad", | 1419 UMA_HISTOGRAM_COUNTS_10000("Memory.GlyphPagesPerLoad", |
1405 webkit_glue::GetGlyphPageCount()); | 1420 webkit_glue::GetGlyphPageCount()); |
1406 | 1421 |
1407 // This message needs to be sent before any of allowScripts(), | 1422 // This message needs to be sent before any of allowScripts(), |
1408 // allowImages(), allowPlugins() is called for the new page, so that when | 1423 // allowImages(), allowPlugins() is called for the new page, so that when |
1409 // these functions send a ViewHostMsg_ContentBlocked message, it arrives | 1424 // these functions send a ViewHostMsg_ContentBlocked message, it arrives |
1410 // after the ViewHostMsg_FrameNavigate message. | 1425 // after the ViewHostMsg_FrameNavigate message. |
1411 Send(new ViewHostMsg_FrameNavigate(routing_id_, params)); | 1426 Send(new ViewHostMsg_FrameNavigate(routing_id_, params)); |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1592 RenderViewImpl* view = RenderViewImpl::Create( | 1607 RenderViewImpl* view = RenderViewImpl::Create( |
1593 0, | 1608 0, |
1594 routing_id_, | 1609 routing_id_, |
1595 renderer_preferences_, | 1610 renderer_preferences_, |
1596 webkit_preferences_, | 1611 webkit_preferences_, |
1597 shared_popup_counter_, | 1612 shared_popup_counter_, |
1598 routing_id, | 1613 routing_id, |
1599 surface_id, | 1614 surface_id, |
1600 cloned_session_storage_namespace_id, | 1615 cloned_session_storage_namespace_id, |
1601 frame_name, | 1616 frame_name, |
| 1617 user_agent_override_, |
1602 true, | 1618 true, |
1603 false, | 1619 false, |
1604 1, | 1620 1, |
1605 screen_info_, | 1621 screen_info_, |
1606 guest_to_embedder_channel_, | 1622 guest_to_embedder_channel_, |
1607 accessibility_mode_); | 1623 accessibility_mode_); |
1608 view->opened_by_user_gesture_ = params.user_gesture; | 1624 view->opened_by_user_gesture_ = params.user_gesture; |
1609 | 1625 |
1610 // Record whether the creator frame is trying to suppress the opener field. | 1626 // Record whether the creator frame is trying to suppress the opener field. |
1611 view->opener_suppressed_ = params.opener_suppressed; | 1627 view->opener_suppressed_ = params.opener_suppressed; |
(...skipping 2017 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3629 | 3645 |
3630 Send(new ViewHostMsg_RouteMessageEvent(routing_id_, params)); | 3646 Send(new ViewHostMsg_RouteMessageEvent(routing_id_, params)); |
3631 return true; | 3647 return true; |
3632 } | 3648 } |
3633 | 3649 |
3634 void RenderViewImpl::willOpenSocketStream( | 3650 void RenderViewImpl::willOpenSocketStream( |
3635 WebSocketStreamHandle* handle) { | 3651 WebSocketStreamHandle* handle) { |
3636 SocketStreamHandleData::AddToHandle(handle, routing_id_); | 3652 SocketStreamHandleData::AddToHandle(handle, routing_id_); |
3637 } | 3653 } |
3638 | 3654 |
| 3655 bool RenderViewImpl::userAgent(const WebKit::WebURL& url, |
| 3656 WebKit::WebString* userAgent) { |
| 3657 if (!is_overriding_user_agent_ || user_agent_override_.empty()) |
| 3658 return false; |
| 3659 *userAgent = WebString::fromUTF8(user_agent_override_); |
| 3660 return true; |
| 3661 } |
| 3662 |
3639 // WebKit::WebPageSerializerClient implementation ------------------------------ | 3663 // WebKit::WebPageSerializerClient implementation ------------------------------ |
3640 | 3664 |
3641 void RenderViewImpl::didSerializeDataForFrame( | 3665 void RenderViewImpl::didSerializeDataForFrame( |
3642 const WebURL& frame_url, | 3666 const WebURL& frame_url, |
3643 const WebCString& data, | 3667 const WebCString& data, |
3644 WebPageSerializerClient::PageSerializationStatus status) { | 3668 WebPageSerializerClient::PageSerializationStatus status) { |
3645 Send(new ViewHostMsg_SendSerializedHtmlData( | 3669 Send(new ViewHostMsg_SendSerializedHtmlData( |
3646 routing_id(), | 3670 routing_id(), |
3647 frame_url, | 3671 frame_url, |
3648 data.data(), | 3672 data.data(), |
(...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4215 } | 4239 } |
4216 | 4240 |
4217 void RenderViewImpl::OnFindReplyAck() { | 4241 void RenderViewImpl::OnFindReplyAck() { |
4218 // Check if there is any queued up request waiting to be sent. | 4242 // Check if there is any queued up request waiting to be sent. |
4219 if (queued_find_reply_message_.get()) { | 4243 if (queued_find_reply_message_.get()) { |
4220 // Send the search result over to the browser process. | 4244 // Send the search result over to the browser process. |
4221 Send(queued_find_reply_message_.release()); | 4245 Send(queued_find_reply_message_.release()); |
4222 } | 4246 } |
4223 } | 4247 } |
4224 | 4248 |
| 4249 void RenderViewImpl::OnSetUserAgentOverride(const std::string& override) { |
| 4250 user_agent_override_ = override; |
| 4251 } |
| 4252 |
4225 void RenderViewImpl::OnZoom(content::PageZoom zoom) { | 4253 void RenderViewImpl::OnZoom(content::PageZoom zoom) { |
4226 if (!webview()) // Not sure if this can happen, but no harm in being safe. | 4254 if (!webview()) // Not sure if this can happen, but no harm in being safe. |
4227 return; | 4255 return; |
4228 | 4256 |
4229 webview()->hidePopups(); | 4257 webview()->hidePopups(); |
4230 | 4258 |
4231 double old_zoom_level = webview()->zoomLevel(); | 4259 double old_zoom_level = webview()->zoomLevel(); |
4232 double zoom_level; | 4260 double zoom_level; |
4233 if (zoom == content::PAGE_ZOOM_RESET) { | 4261 if (zoom == content::PAGE_ZOOM_RESET) { |
4234 zoom_level = 0; | 4262 zoom_level = 0; |
(...skipping 1237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5472 bool RenderViewImpl::WebWidgetHandlesCompositorScheduling() const { | 5500 bool RenderViewImpl::WebWidgetHandlesCompositorScheduling() const { |
5473 return !!RenderThreadImpl::current()->compositor_thread(); | 5501 return !!RenderThreadImpl::current()->compositor_thread(); |
5474 } | 5502 } |
5475 | 5503 |
5476 void RenderViewImpl::OnJavaBridgeInit() { | 5504 void RenderViewImpl::OnJavaBridgeInit() { |
5477 DCHECK(!java_bridge_dispatcher_); | 5505 DCHECK(!java_bridge_dispatcher_); |
5478 #if defined(ENABLE_JAVA_BRIDGE) | 5506 #if defined(ENABLE_JAVA_BRIDGE) |
5479 java_bridge_dispatcher_ = new JavaBridgeDispatcher(this); | 5507 java_bridge_dispatcher_ = new JavaBridgeDispatcher(this); |
5480 #endif | 5508 #endif |
5481 } | 5509 } |
OLD | NEW |