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())); |
| 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(); |
| 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; |
| 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 2436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3441 if (renderer_accessibility_) | 3473 if (renderer_accessibility_) |
3442 renderer_accessibility_->HandleWebAccessibilityEvent(obj, event); | 3474 renderer_accessibility_->HandleWebAccessibilityEvent(obj, event); |
3443 } | 3475 } |
3444 | 3476 |
3445 void RenderFrameImpl::FocusedNodeChanged(const WebNode& node) { | 3477 void RenderFrameImpl::FocusedNodeChanged(const WebNode& node) { |
3446 if (renderer_accessibility_) | 3478 if (renderer_accessibility_) |
3447 renderer_accessibility_->FocusedNodeChanged(node); | 3479 renderer_accessibility_->FocusedNodeChanged(node); |
3448 } | 3480 } |
3449 | 3481 |
3450 // PlzNavigate | 3482 // PlzNavigate |
| 3483 void RenderFrameImpl::OnRequestNavigation( |
| 3484 const CommonNavigationParams& common_params, |
| 3485 const RequestNavigationParams& request_params) { |
| 3486 CHECK(CommandLine::ForCurrentProcess()->HasSwitch( |
| 3487 switches::kEnableBrowserSideNavigation)); |
| 3488 |
| 3489 // TODO(clamy): Execute the beforeunload event. |
| 3490 |
| 3491 WebURLRequest request = |
| 3492 CreateURLRequestForNavigation(common_params, |
| 3493 request_params, |
| 3494 scoped_ptr<StreamOverrideParameters>(), |
| 3495 frame_->isViewSourceModeEnabled()); |
| 3496 |
| 3497 // Note: At this stage, the goal is to apply all the modifications the |
| 3498 // renderer wants to make to the request, and then send it to the browser, so |
| 3499 // that the actual network request can be started. Ideally, all such |
| 3500 // modifications should take place in willSendRequest, and in the |
| 3501 // implementation of willSendRequest for the various InspectorAgents |
| 3502 // (devtools). |
| 3503 // |
| 3504 // TODO(clamy): Apply devtools override. |
| 3505 // TODO(clamy): Make sure that navigation requests are not modified somewhere |
| 3506 // else in blink. |
| 3507 willSendRequest(frame_, 0, request, blink::WebURLResponse()); |
| 3508 |
| 3509 // TODO(clamy): Same-document navigations should not be sent back to the |
| 3510 // browser. |
| 3511 Send(new FrameHostMsg_BeginNavigation(routing_id_, |
| 3512 MakeBeginNavigationParams(request), |
| 3513 MakeCommonNavigationParams(request))); |
| 3514 } |
| 3515 |
| 3516 // PlzNavigate |
3451 void RenderFrameImpl::OnCommitNavigation( | 3517 void RenderFrameImpl::OnCommitNavigation( |
3452 const ResourceResponseHead& response, | 3518 const ResourceResponseHead& response, |
3453 const GURL& stream_url, | 3519 const GURL& stream_url, |
3454 const CommonNavigationParams& common_params, | 3520 const CommonNavigationParams& common_params, |
3455 const CommitNavigationParams& commit_params) { | 3521 const CommitNavigationParams& commit_params) { |
3456 CHECK(CommandLine::ForCurrentProcess()->HasSwitch( | 3522 CHECK(CommandLine::ForCurrentProcess()->HasSwitch( |
3457 switches::kEnableBrowserSideNavigation)); | 3523 switches::kEnableBrowserSideNavigation)); |
3458 bool is_reload = false; | 3524 bool is_reload = false; |
3459 WebURLRequest::CachePolicy cache_policy = | 3525 WebURLRequest::CachePolicy cache_policy = |
3460 WebURLRequest::UseProtocolCachePolicy; | 3526 WebURLRequest::UseProtocolCachePolicy; |
3461 if (!RenderFrameImpl::PrepareRenderViewForNavigation( | 3527 if (!RenderFrameImpl::PrepareRenderViewForNavigation( |
3462 common_params.url, common_params.navigation_type, | 3528 common_params.url, common_params.navigation_type, |
3463 commit_params.page_state, false, -1, -1, &is_reload, &cache_policy)) { | 3529 commit_params.page_state, false, -1, -1, &is_reload, &cache_policy)) { |
3464 return; | 3530 return; |
3465 } | 3531 } |
3466 | 3532 |
3467 GetContentClient()->SetActiveURL(common_params.url); | 3533 GetContentClient()->SetActiveURL(common_params.url); |
3468 | 3534 |
3469 // Create a WebURLRequest that blink can use to get access to the body of the | 3535 // Create a WebURLRequest that blink can use to get access to the body of the |
3470 // response through a stream in the browser. Blink will then commit the | 3536 // response through a stream in the browser. Blink will then commit the |
3471 // navigation. | 3537 // navigation. |
3472 // TODO(clamy): Have the navigation commit directly, without going through | 3538 // TODO(clamy): Have the navigation commit directly, without going through |
3473 // loading a WebURLRequest. | 3539 // loading a WebURLRequest. |
3474 scoped_ptr<StreamOverrideParameters> stream_override( | 3540 scoped_ptr<StreamOverrideParameters> stream_override( |
3475 new StreamOverrideParameters()); | 3541 new StreamOverrideParameters()); |
3476 stream_override->stream_url = stream_url; | 3542 stream_override->stream_url = stream_url; |
3477 stream_override->response = response; | 3543 stream_override->response = response; |
3478 WebURLRequest request = CreateURLRequestForNavigation( | 3544 WebURLRequest request = |
3479 common_params, stream_override.Pass(), frame_->isViewSourceModeEnabled()); | 3545 CreateURLRequestForNavigation(common_params, |
| 3546 RequestNavigationParams(), |
| 3547 stream_override.Pass(), |
| 3548 frame_->isViewSourceModeEnabled()); |
3480 | 3549 |
3481 // Record this before starting the load. A lower bound of this time is needed | 3550 // Record this before starting the load. A lower bound of this time is needed |
3482 // to sanitize the navigationStart override set below. | 3551 // to sanitize the navigationStart override set below. |
3483 base::TimeTicks renderer_navigation_start = base::TimeTicks::Now(); | 3552 base::TimeTicks renderer_navigation_start = base::TimeTicks::Now(); |
3484 frame_->loadRequest(request); | 3553 frame_->loadRequest(request); |
3485 UpdateFrameNavigationTiming( | 3554 UpdateFrameNavigationTiming( |
3486 frame_, commit_params.browser_navigation_start, | 3555 frame_, commit_params.browser_navigation_start, |
3487 renderer_navigation_start); | 3556 renderer_navigation_start); |
3488 } | 3557 } |
3489 | 3558 |
(...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3974 | 4043 |
3975 #if defined(ENABLE_BROWSER_CDMS) | 4044 #if defined(ENABLE_BROWSER_CDMS) |
3976 RendererCdmManager* RenderFrameImpl::GetCdmManager() { | 4045 RendererCdmManager* RenderFrameImpl::GetCdmManager() { |
3977 if (!cdm_manager_) | 4046 if (!cdm_manager_) |
3978 cdm_manager_ = new RendererCdmManager(this); | 4047 cdm_manager_ = new RendererCdmManager(this); |
3979 return cdm_manager_; | 4048 return cdm_manager_; |
3980 } | 4049 } |
3981 #endif // defined(ENABLE_BROWSER_CDMS) | 4050 #endif // defined(ENABLE_BROWSER_CDMS) |
3982 | 4051 |
3983 } // namespace content | 4052 } // namespace content |
OLD | NEW |