Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_frame_impl.h" | 5 #include "content/renderer/render_frame_impl.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
| (...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 357 if (!opener) | 357 if (!opener) |
| 358 return true; | 358 return true; |
| 359 | 359 |
| 360 if (url.GetOrigin() != GURL(opener->document().url()).GetOrigin()) | 360 if (url.GetOrigin() != GURL(opener->document().url()).GetOrigin()) |
| 361 return true; | 361 return true; |
| 362 } | 362 } |
| 363 return false; | 363 return false; |
| 364 } | 364 } |
| 365 | 365 |
| 366 WebURLRequest CreateURLRequestForNavigation( | 366 WebURLRequest CreateURLRequestForNavigation( |
| 367 const CommonNavigationParams& params, | 367 const CommonNavigationParams& common_params, |
| 368 const RequestNavigationParams& request_params, | |
| 368 scoped_ptr<StreamOverrideParameters> stream_override, | 369 scoped_ptr<StreamOverrideParameters> stream_override, |
| 369 bool is_view_source_mode_enabled) { | 370 bool is_view_source_mode_enabled) { |
| 370 WebURLRequest request(params.url); | 371 WebURLRequest request(common_params.url); |
| 371 if (is_view_source_mode_enabled) | 372 if (is_view_source_mode_enabled) |
| 372 request.setCachePolicy(WebURLRequest::ReturnCacheDataElseLoad); | 373 request.setCachePolicy(WebURLRequest::ReturnCacheDataElseLoad); |
| 373 | 374 |
| 374 if (params.referrer.url.is_valid()) { | 375 if (common_params.referrer.url.is_valid()) { |
| 375 WebString web_referrer = WebSecurityPolicy::generateReferrerHeader( | 376 WebString web_referrer = WebSecurityPolicy::generateReferrerHeader( |
| 376 params.referrer.policy, | 377 common_params.referrer.policy, |
| 377 params.url, | 378 common_params.url, |
| 378 WebString::fromUTF8(params.referrer.url.spec())); | 379 WebString::fromUTF8(common_params.referrer.url.spec())); |
| 379 if (!web_referrer.isEmpty()) | 380 if (!web_referrer.isEmpty()) |
| 380 request.setHTTPReferrer(web_referrer, params.referrer.policy); | 381 request.setHTTPReferrer(web_referrer, common_params.referrer.policy); |
| 382 } | |
| 383 | |
| 384 if (!request_params.extra_headers.empty()) { | |
| 385 for (net::HttpUtil::HeadersIterator i(request_params.extra_headers.begin(), | |
| 386 request_params.extra_headers.end(), | |
| 387 "\n"); | |
| 388 i.GetNext();) { | |
| 389 request.addHTTPHeaderField(WebString::fromUTF8(i.name()), | |
| 390 WebString::fromUTF8(i.values())); | |
| 391 } | |
| 392 } | |
| 393 | |
| 394 if (request_params.is_post) { | |
| 395 request.setHTTPMethod(WebString::fromUTF8("POST")); | |
| 396 | |
| 397 // Set post data. | |
| 398 WebHTTPBody http_body; | |
| 399 http_body.initialize(); | |
| 400 const char* data = NULL; | |
| 401 if (request_params.browser_initiated_post_data.size()) { | |
| 402 data = reinterpret_cast<const char*>( | |
| 403 &request_params.browser_initiated_post_data.front()); | |
| 404 } | |
| 405 http_body.appendData( | |
| 406 WebData(data, request_params.browser_initiated_post_data.size())); | |
|
carlosk
2014/10/08 14:28:55
Shouldn't this line be moved inside the previous "
clamy
2014/10/10 02:33:11
I think I'll keep it as the code originally was.
| |
| 407 request.setHTTPBody(http_body); | |
| 381 } | 408 } |
| 382 | 409 |
| 383 RequestExtraData* extra_data = new RequestExtraData(); | 410 RequestExtraData* extra_data = new RequestExtraData(); |
| 384 extra_data->set_stream_override(stream_override.Pass()); | 411 extra_data->set_stream_override(stream_override.Pass()); |
| 385 request.setExtraData(extra_data); | 412 request.setExtraData(extra_data); |
| 386 return request; | 413 return request; |
| 387 } | 414 } |
| 388 | 415 |
| 389 void UpdateFrameNavigationTiming(WebFrame* frame, | 416 void UpdateFrameNavigationTiming(WebFrame* frame, |
| 390 base::TimeTicks browser_navigation_start, | 417 base::TimeTicks browser_navigation_start, |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 403 browser_navigation_start, renderer_navigation_start); | 430 browser_navigation_start, renderer_navigation_start); |
| 404 double navigation_start_seconds = | 431 double navigation_start_seconds = |
| 405 (navigation_start - base::TimeTicks()).InSecondsF(); | 432 (navigation_start - base::TimeTicks()).InSecondsF(); |
| 406 frame->provisionalDataSource()->setNavigationStartTime( | 433 frame->provisionalDataSource()->setNavigationStartTime( |
| 407 navigation_start_seconds); | 434 navigation_start_seconds); |
| 408 // TODO(clamy): We need to provide additional timing values for the | 435 // TODO(clamy): We need to provide additional timing values for the |
| 409 // Navigation Timing API to work with browser-side navigations. | 436 // Navigation Timing API to work with browser-side navigations. |
| 410 } | 437 } |
| 411 } | 438 } |
| 412 | 439 |
| 440 // PlzNavigate | |
| 441 FrameHostMsg_BeginNavigation_Params MakeBeginNavigationParams( | |
| 442 const blink::WebURLRequest& request) { | |
| 443 FrameHostMsg_BeginNavigation_Params params; | |
| 444 params.method = request.httpMethod().latin1(); | |
|
nasko
2014/10/08 17:40:32
Is latin1() the usual encoding to use?
clamy
2014/10/10 02:33:11
It is the one used by WebURLLoaderImpl to get the
| |
| 445 params.headers = GetWebURLRequestHeaders(request); | |
| 446 params.load_flags = GetLoadFlagsForWebURLRequest(request); | |
| 447 // TODO(clamy): fill the http body. | |
| 448 params.has_user_gesture = request.hasUserGesture(); | |
| 449 return params; | |
| 450 } | |
| 451 | |
| 452 // PlzNavigate | |
| 453 CommonNavigationParams MakeCommonNavigationParams( | |
| 454 const blink::WebURLRequest& request) { | |
| 455 const RequestExtraData kEmptyData; | |
|
carlosk
2014/10/08 14:28:55
nit: you could declare this const member as static
clamy
2014/10/10 02:33:11
The use of static variables for non POD data is fo
carlosk
2014/10/10 08:44:09
Acknowledged.
In fact for this specific case -- f
| |
| 456 const RequestExtraData* extra_data = | |
| 457 static_cast<RequestExtraData*>(request.extraData()); | |
| 458 if (!extra_data) | |
| 459 extra_data = &kEmptyData; | |
| 460 CommonNavigationParams params; | |
| 461 params.url = request.url(); | |
| 462 params.referrer = Referrer( | |
| 463 GURL(request.httpHeaderField(WebString::fromUTF8("Referer")).latin1()), | |
| 464 request.referrerPolicy()); | |
| 465 params.transition = extra_data->transition_type(); | |
| 466 return params; | |
| 467 } | |
| 468 | |
| 413 } // namespace | 469 } // namespace |
| 414 | 470 |
| 415 static RenderFrameImpl* (*g_create_render_frame_impl)(RenderViewImpl*, int32) = | 471 static RenderFrameImpl* (*g_create_render_frame_impl)(RenderViewImpl*, int32) = |
| 416 NULL; | 472 NULL; |
| 417 | 473 |
| 418 // static | 474 // static |
| 419 RenderFrameImpl* RenderFrameImpl::Create(RenderViewImpl* render_view, | 475 RenderFrameImpl* RenderFrameImpl::Create(RenderViewImpl* render_view, |
| 420 int32 routing_id) { | 476 int32 routing_id) { |
| 421 DCHECK(routing_id != MSG_ROUTING_NONE); | 477 DCHECK(routing_id != MSG_ROUTING_NONE); |
| 422 | 478 |
| (...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 840 IPC_MESSAGE_HANDLER(FrameMsg_SetupTransitionView, OnSetupTransitionView) | 896 IPC_MESSAGE_HANDLER(FrameMsg_SetupTransitionView, OnSetupTransitionView) |
| 841 IPC_MESSAGE_HANDLER(FrameMsg_BeginExitTransition, OnBeginExitTransition) | 897 IPC_MESSAGE_HANDLER(FrameMsg_BeginExitTransition, OnBeginExitTransition) |
| 842 IPC_MESSAGE_HANDLER(FrameMsg_Reload, OnReload) | 898 IPC_MESSAGE_HANDLER(FrameMsg_Reload, OnReload) |
| 843 IPC_MESSAGE_HANDLER(FrameMsg_TextSurroundingSelectionRequest, | 899 IPC_MESSAGE_HANDLER(FrameMsg_TextSurroundingSelectionRequest, |
| 844 OnTextSurroundingSelectionRequest) | 900 OnTextSurroundingSelectionRequest) |
| 845 IPC_MESSAGE_HANDLER(FrameMsg_AddStyleSheetByURL, | 901 IPC_MESSAGE_HANDLER(FrameMsg_AddStyleSheetByURL, |
| 846 OnAddStyleSheetByURL) | 902 OnAddStyleSheetByURL) |
| 847 IPC_MESSAGE_HANDLER(FrameMsg_SetAccessibilityMode, | 903 IPC_MESSAGE_HANDLER(FrameMsg_SetAccessibilityMode, |
| 848 OnSetAccessibilityMode) | 904 OnSetAccessibilityMode) |
| 849 IPC_MESSAGE_HANDLER(FrameMsg_DisownOpener, OnDisownOpener) | 905 IPC_MESSAGE_HANDLER(FrameMsg_DisownOpener, OnDisownOpener) |
| 906 IPC_MESSAGE_HANDLER(FrameMsg_RequestNavigation, OnRequestNavigation) | |
| 850 IPC_MESSAGE_HANDLER(FrameMsg_CommitNavigation, OnCommitNavigation) | 907 IPC_MESSAGE_HANDLER(FrameMsg_CommitNavigation, OnCommitNavigation) |
| 851 #if defined(OS_ANDROID) | 908 #if defined(OS_ANDROID) |
| 852 IPC_MESSAGE_HANDLER(FrameMsg_SelectPopupMenuItems, OnSelectPopupMenuItems) | 909 IPC_MESSAGE_HANDLER(FrameMsg_SelectPopupMenuItems, OnSelectPopupMenuItems) |
| 853 #elif defined(OS_MACOSX) | 910 #elif defined(OS_MACOSX) |
| 854 IPC_MESSAGE_HANDLER(FrameMsg_SelectPopupMenuItem, OnSelectPopupMenuItem) | 911 IPC_MESSAGE_HANDLER(FrameMsg_SelectPopupMenuItem, OnSelectPopupMenuItem) |
| 855 IPC_MESSAGE_HANDLER(InputMsg_CopyToFindPboard, OnCopyToFindPboard) | 912 IPC_MESSAGE_HANDLER(InputMsg_CopyToFindPboard, OnCopyToFindPboard) |
| 856 #endif | 913 #endif |
| 857 IPC_END_MESSAGE_MAP() | 914 IPC_END_MESSAGE_MAP() |
| 858 | 915 |
| 859 return handled; | 916 return handled; |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 951 WebString::fromUTF8(charset), | 1008 WebString::fromUTF8(charset), |
| 952 params.base_url_for_data_url, | 1009 params.base_url_for_data_url, |
| 953 params.history_url_for_data_url, | 1010 params.history_url_for_data_url, |
| 954 false); | 1011 false); |
| 955 } else { | 1012 } else { |
| 956 CHECK(false) << "Invalid URL passed: " | 1013 CHECK(false) << "Invalid URL passed: " |
| 957 << params.common_params.url.possibly_invalid_spec(); | 1014 << params.common_params.url.possibly_invalid_spec(); |
| 958 } | 1015 } |
| 959 } else { | 1016 } else { |
| 960 // Navigate to the given URL. | 1017 // Navigate to the given URL. |
| 961 WebURLRequest request = CreateURLRequestForNavigation( | 1018 WebURLRequest request = |
| 962 params.common_params, scoped_ptr<StreamOverrideParameters>(), | 1019 CreateURLRequestForNavigation(params.common_params, |
| 963 frame->isViewSourceModeEnabled()); | 1020 params.request_params, |
| 1021 scoped_ptr<StreamOverrideParameters>(), | |
| 1022 frame->isViewSourceModeEnabled()); | |
| 964 | 1023 |
| 965 // A session history navigation should have been accompanied by state. | 1024 // A session history navigation should have been accompanied by state. |
| 966 CHECK_EQ(params.page_id, -1); | 1025 CHECK_EQ(params.page_id, -1); |
| 967 | 1026 |
| 968 if (!params.request_params.extra_headers.empty()) { | |
| 969 for (net::HttpUtil::HeadersIterator i( | |
| 970 params.request_params.extra_headers.begin(), | |
| 971 params.request_params.extra_headers.end(), | |
| 972 "\n"); | |
| 973 i.GetNext();) { | |
| 974 request.addHTTPHeaderField(WebString::fromUTF8(i.name()), | |
| 975 WebString::fromUTF8(i.values())); | |
| 976 } | |
| 977 } | |
| 978 | |
| 979 if (params.request_params.is_post) { | |
| 980 request.setHTTPMethod(WebString::fromUTF8("POST")); | |
| 981 | |
| 982 // Set post data. | |
| 983 WebHTTPBody http_body; | |
| 984 http_body.initialize(); | |
| 985 const char* data = NULL; | |
| 986 if (params.request_params.browser_initiated_post_data.size()) { | |
| 987 data = reinterpret_cast<const char*>( | |
| 988 ¶ms.request_params.browser_initiated_post_data.front()); | |
| 989 } | |
| 990 http_body.appendData(WebData( | |
| 991 data, params.request_params.browser_initiated_post_data.size())); | |
| 992 request.setHTTPBody(http_body); | |
| 993 } | |
| 994 | |
| 995 // Record this before starting the load, we need a lower bound of this time | 1027 // Record this before starting the load, we need a lower bound of this time |
| 996 // to sanitize the navigationStart override set below. | 1028 // to sanitize the navigationStart override set below. |
| 997 base::TimeTicks renderer_navigation_start = base::TimeTicks::Now(); | 1029 base::TimeTicks renderer_navigation_start = base::TimeTicks::Now(); |
| 998 frame->loadRequest(request); | 1030 frame->loadRequest(request); |
| 999 | 1031 |
| 1000 UpdateFrameNavigationTiming( | 1032 UpdateFrameNavigationTiming( |
| 1001 frame, params.commit_params.browser_navigation_start, | 1033 frame, params.commit_params.browser_navigation_start, |
| 1002 renderer_navigation_start); | 1034 renderer_navigation_start); |
| 1003 } | 1035 } |
| 1004 | 1036 |
| (...skipping 2448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3453 if (renderer_accessibility_) | 3485 if (renderer_accessibility_) |
| 3454 renderer_accessibility_->HandleWebAccessibilityEvent(obj, event); | 3486 renderer_accessibility_->HandleWebAccessibilityEvent(obj, event); |
| 3455 } | 3487 } |
| 3456 | 3488 |
| 3457 void RenderFrameImpl::FocusedNodeChanged(const WebNode& node) { | 3489 void RenderFrameImpl::FocusedNodeChanged(const WebNode& node) { |
| 3458 if (renderer_accessibility_) | 3490 if (renderer_accessibility_) |
| 3459 renderer_accessibility_->FocusedNodeChanged(node); | 3491 renderer_accessibility_->FocusedNodeChanged(node); |
| 3460 } | 3492 } |
| 3461 | 3493 |
| 3462 // PlzNavigate | 3494 // PlzNavigate |
| 3495 void RenderFrameImpl::OnRequestNavigation( | |
| 3496 const CommonNavigationParams& common_params, | |
| 3497 const RequestNavigationParams& request_params) { | |
| 3498 CHECK(CommandLine::ForCurrentProcess()->HasSwitch( | |
| 3499 switches::kEnableBrowserSideNavigation)); | |
| 3500 // TODO(clamy): Execute the beforeunload event. | |
| 3501 WebURLRequest request = | |
| 3502 CreateURLRequestForNavigation(common_params, | |
| 3503 request_params, | |
| 3504 scoped_ptr<StreamOverrideParameters>(), | |
| 3505 frame_->isViewSourceModeEnabled()); | |
| 3506 willSendRequest(frame_, 0, request, blink::WebURLResponse()); | |
|
nasko
2014/10/08 17:40:32
Shouldn't this go the same way as OnNaivate throug
clamy
2014/10/10 02:33:11
At this stage we are just trying to get whatever m
nasko
2014/10/13 17:04:24
Let's put some of the explanation above in a TODO
clamy
2014/10/13 19:13:10
Done.
| |
| 3507 // TODO(clamy): Apply devtools override. | |
| 3508 // TODO(clamy): Make sure that navigation request are not modified somewhere | |
|
carlosk
2014/10/08 14:28:55
nit: /are/is/
clamy
2014/10/10 02:33:11
Changed it to navigation requests are
| |
| 3509 // else in blink. | |
| 3510 // TODO(clamy): Same-document navigations should not be sent back to the | |
| 3511 // browser. | |
| 3512 Send(new FrameHostMsg_BeginNavigation(routing_id_, | |
| 3513 MakeBeginNavigationParams(request), | |
| 3514 MakeCommonNavigationParams(request))); | |
| 3515 } | |
| 3516 | |
| 3517 // PlzNavigate | |
| 3463 void RenderFrameImpl::OnCommitNavigation( | 3518 void RenderFrameImpl::OnCommitNavigation( |
| 3464 const ResourceResponseHead& response, | 3519 const ResourceResponseHead& response, |
| 3465 const GURL& stream_url, | 3520 const GURL& stream_url, |
| 3466 const CommonNavigationParams& common_params, | 3521 const CommonNavigationParams& common_params, |
| 3467 const CommitNavigationParams& commit_params) { | 3522 const CommitNavigationParams& commit_params) { |
| 3468 CHECK(CommandLine::ForCurrentProcess()->HasSwitch( | 3523 CHECK(CommandLine::ForCurrentProcess()->HasSwitch( |
| 3469 switches::kEnableBrowserSideNavigation)); | 3524 switches::kEnableBrowserSideNavigation)); |
| 3470 bool is_reload = false; | 3525 bool is_reload = false; |
| 3471 WebURLRequest::CachePolicy cache_policy = | 3526 WebURLRequest::CachePolicy cache_policy = |
| 3472 WebURLRequest::UseProtocolCachePolicy; | 3527 WebURLRequest::UseProtocolCachePolicy; |
| 3473 if (!RenderFrameImpl::PrepareRenderViewForNavigation( | 3528 if (!RenderFrameImpl::PrepareRenderViewForNavigation( |
| 3474 common_params.url, common_params.navigation_type, | 3529 common_params.url, common_params.navigation_type, |
| 3475 commit_params.page_state, false, -1, -1, &is_reload, &cache_policy)) { | 3530 commit_params.page_state, false, -1, -1, &is_reload, &cache_policy)) { |
| 3476 return; | 3531 return; |
| 3477 } | 3532 } |
| 3478 | 3533 |
| 3479 GetContentClient()->SetActiveURL(common_params.url); | 3534 GetContentClient()->SetActiveURL(common_params.url); |
| 3480 | 3535 |
| 3481 // Commit the url. | 3536 // Commit the url. |
| 3482 scoped_ptr<StreamOverrideParameters> stream_override( | 3537 scoped_ptr<StreamOverrideParameters> stream_override( |
| 3483 new StreamOverrideParameters()); | 3538 new StreamOverrideParameters()); |
| 3484 stream_override->stream_url = stream_url; | 3539 stream_override->stream_url = stream_url; |
| 3485 stream_override->response = response; | 3540 stream_override->response = response; |
| 3486 WebURLRequest request = CreateURLRequestForNavigation( | 3541 WebURLRequest request = |
| 3487 common_params, stream_override.Pass(), frame_->isViewSourceModeEnabled()); | 3542 CreateURLRequestForNavigation(common_params, |
| 3543 RequestNavigationParams(), | |
| 3544 stream_override.Pass(), | |
| 3545 frame_->isViewSourceModeEnabled()); | |
| 3488 | 3546 |
| 3489 // Record this before starting the load, we need a lower bound of this time | 3547 // Record this before starting the load, we need a lower bound of this time |
| 3490 // to sanitize the navigationStart override set below. | 3548 // to sanitize the navigationStart override set below. |
| 3491 base::TimeTicks renderer_navigation_start = base::TimeTicks::Now(); | 3549 base::TimeTicks renderer_navigation_start = base::TimeTicks::Now(); |
| 3492 frame_->loadRequest(request); | 3550 frame_->loadRequest(request); |
| 3493 UpdateFrameNavigationTiming( | 3551 UpdateFrameNavigationTiming( |
| 3494 frame_, commit_params.browser_navigation_start, | 3552 frame_, commit_params.browser_navigation_start, |
| 3495 renderer_navigation_start); | 3553 renderer_navigation_start); |
| 3496 } | 3554 } |
| 3497 | 3555 |
| (...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3982 | 4040 |
| 3983 #if defined(ENABLE_BROWSER_CDMS) | 4041 #if defined(ENABLE_BROWSER_CDMS) |
| 3984 RendererCdmManager* RenderFrameImpl::GetCdmManager() { | 4042 RendererCdmManager* RenderFrameImpl::GetCdmManager() { |
| 3985 if (!cdm_manager_) | 4043 if (!cdm_manager_) |
| 3986 cdm_manager_ = new RendererCdmManager(this); | 4044 cdm_manager_ = new RendererCdmManager(this); |
| 3987 return cdm_manager_; | 4045 return cdm_manager_; |
| 3988 } | 4046 } |
| 3989 #endif // defined(ENABLE_BROWSER_CDMS) | 4047 #endif // defined(ENABLE_BROWSER_CDMS) |
| 3990 | 4048 |
| 3991 } // namespace content | 4049 } // namespace content |
| OLD | NEW |