Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2009, 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2009, 2012 Google Inc. All rights reserved. |
| 3 * Copyright (C) 2011 Apple Inc. All rights reserved. | 3 * Copyright (C) 2011 Apple Inc. All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
| 7 * met: | 7 * met: |
| 8 * | 8 * |
| 9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 117 // Convenience helper for frame tree helpers in FrameClient to reduce the amount | 117 // Convenience helper for frame tree helpers in FrameClient to reduce the amount |
| 118 // of null-checking boilerplate code. Since the frame tree is maintained in the | 118 // of null-checking boilerplate code. Since the frame tree is maintained in the |
| 119 // web/ layer, the frame tree helpers often have to deal with null WebFrames: | 119 // web/ layer, the frame tree helpers often have to deal with null WebFrames: |
| 120 // for example, a frame with no parent will return null for WebFrame::parent(). | 120 // for example, a frame with no parent will return null for WebFrame::parent(). |
| 121 // TODO(dcheng): Remove duplication between LocalFrameClientImpl and | 121 // TODO(dcheng): Remove duplication between LocalFrameClientImpl and |
| 122 // RemoteFrameClientImpl somehow... | 122 // RemoteFrameClientImpl somehow... |
| 123 Frame* ToCoreFrame(WebFrame* frame) { | 123 Frame* ToCoreFrame(WebFrame* frame) { |
| 124 return frame ? WebFrame::ToCoreFrame(*frame) : nullptr; | 124 return frame ? WebFrame::ToCoreFrame(*frame) : nullptr; |
| 125 } | 125 } |
| 126 | 126 |
| 127 // Return the parent of |frame| as a LocalFrame, nullptr when there is no | |
| 128 // parent or when the parent is a remote frame. | |
| 129 LocalFrame* GetLocalParentFrame(WebLocalFrameImpl* frame) { | |
| 130 WebFrame* parent = frame->Parent(); | |
| 131 if (!parent || !parent->IsWebLocalFrame()) | |
| 132 return nullptr; | |
| 133 | |
| 134 return ToWebLocalFrameImpl(parent)->GetFrame(); | |
| 135 } | |
| 136 | |
| 137 // Returns whether the |local_frame| has been loaded using an MHTMLArchive. When | |
| 138 // it is the case, each subframe must use it for loading. | |
| 139 bool IsLoadedAsMHTMLArchive(LocalFrame* local_frame) { | |
| 140 return local_frame && | |
| 141 local_frame->Loader().GetDocumentLoader()->Fetcher()->Archive(); | |
|
Nate Chapin
2017/05/12 19:30:08
Nit: you can get the fetcher a little more concise
arthursonzogni
2017/05/15 10:57:55
Done.
| |
| 142 } | |
| 143 | |
| 144 // Returns whether the |local_frame| is in a middle of a back/forward | |
| 145 // navigation. | |
| 146 bool IsBackForwardNavigationInProgress(LocalFrame* local_frame) { | |
| 147 return local_frame && | |
| 148 IsBackForwardLoadType( | |
| 149 local_frame->Loader().GetDocumentLoader()->LoadType()) && | |
| 150 !local_frame->GetDocument()->LoadEventFinished(); | |
| 151 } | |
| 152 | |
| 127 } // namespace | 153 } // namespace |
| 128 | 154 |
| 129 LocalFrameClientImpl::LocalFrameClientImpl(WebLocalFrameImpl* frame) | 155 LocalFrameClientImpl::LocalFrameClientImpl(WebLocalFrameImpl* frame) |
| 130 : web_frame_(frame) {} | 156 : web_frame_(frame) {} |
| 131 | 157 |
| 132 LocalFrameClientImpl* LocalFrameClientImpl::Create(WebLocalFrameImpl* frame) { | 158 LocalFrameClientImpl* LocalFrameClientImpl::Create(WebLocalFrameImpl* frame) { |
| 133 return new LocalFrameClientImpl(frame); | 159 return new LocalFrameClientImpl(frame); |
| 134 } | 160 } |
| 135 | 161 |
| 136 LocalFrameClientImpl::~LocalFrameClientImpl() {} | 162 LocalFrameClientImpl::~LocalFrameClientImpl() {} |
| (...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 476 if (!web_frame_->Client()) | 502 if (!web_frame_->Client()) |
| 477 return kNavigationPolicyIgnore; | 503 return kNavigationPolicyIgnore; |
| 478 | 504 |
| 479 if (policy == kNavigationPolicyNewBackgroundTab && | 505 if (policy == kNavigationPolicyNewBackgroundTab && |
| 480 !AllowCreatingBackgroundTabs() && | 506 !AllowCreatingBackgroundTabs() && |
| 481 !UIEventWithKeyState::NewTabModifierSetFromIsolatedWorld()) | 507 !UIEventWithKeyState::NewTabModifierSetFromIsolatedWorld()) |
| 482 policy = kNavigationPolicyNewForegroundTab; | 508 policy = kNavigationPolicyNewForegroundTab; |
| 483 | 509 |
| 484 WebDataSourceImpl* ds = WebDataSourceImpl::FromDocumentLoader(loader); | 510 WebDataSourceImpl* ds = WebDataSourceImpl::FromDocumentLoader(loader); |
| 485 | 511 |
| 486 // Newly created child frames may need to be navigated to a history item | |
| 487 // during a back/forward navigation. This will only happen when the parent | |
| 488 // is a LocalFrame doing a back/forward navigation that has not completed. | |
| 489 // (If the load has completed and the parent later adds a frame with script, | |
| 490 // we do not want to use a history item for it.) | |
| 491 bool is_history_navigation_in_new_child_frame = | |
| 492 web_frame_->Parent() && web_frame_->Parent()->IsWebLocalFrame() && | |
| 493 IsBackForwardLoadType(ToWebLocalFrameImpl(web_frame_->Parent()) | |
| 494 ->GetFrame() | |
| 495 ->Loader() | |
| 496 .GetDocumentLoader() | |
| 497 ->LoadType()) && | |
| 498 !ToWebLocalFrameImpl(web_frame_->Parent()) | |
| 499 ->GetFrame() | |
| 500 ->GetDocument() | |
| 501 ->LoadEventFinished(); | |
| 502 | |
| 503 WrappedResourceRequest wrapped_resource_request(request); | 512 WrappedResourceRequest wrapped_resource_request(request); |
| 504 WebFrameClient::NavigationPolicyInfo navigation_info( | 513 WebFrameClient::NavigationPolicyInfo navigation_info( |
| 505 wrapped_resource_request); | 514 wrapped_resource_request); |
| 506 navigation_info.navigation_type = static_cast<WebNavigationType>(type); | 515 navigation_info.navigation_type = static_cast<WebNavigationType>(type); |
| 507 navigation_info.default_policy = static_cast<WebNavigationPolicy>(policy); | 516 navigation_info.default_policy = static_cast<WebNavigationPolicy>(policy); |
| 508 navigation_info.extra_data = ds ? ds->GetExtraData() : nullptr; | 517 navigation_info.extra_data = ds ? ds->GetExtraData() : nullptr; |
| 509 navigation_info.replaces_current_history_item = replaces_current_history_item; | 518 navigation_info.replaces_current_history_item = replaces_current_history_item; |
| 510 navigation_info.is_history_navigation_in_new_child_frame = | |
| 511 is_history_navigation_in_new_child_frame; | |
| 512 navigation_info.is_client_redirect = is_client_redirect; | 519 navigation_info.is_client_redirect = is_client_redirect; |
| 513 navigation_info.should_check_main_world_content_security_policy = | 520 navigation_info.should_check_main_world_content_security_policy = |
| 514 should_check_main_world_content_security_policy == | 521 should_check_main_world_content_security_policy == |
| 515 kCheckContentSecurityPolicy | 522 kCheckContentSecurityPolicy |
| 516 ? kWebContentSecurityPolicyDispositionCheck | 523 ? kWebContentSecurityPolicyDispositionCheck |
| 517 : kWebContentSecurityPolicyDispositionDoNotCheck; | 524 : kWebContentSecurityPolicyDispositionDoNotCheck; |
| 518 | 525 |
| 519 if (IsLoadedAsMHTMLArchive()) { | 526 // Can be null. |
| 520 navigation_info.archive_status = | 527 LocalFrame* local_parent_frame = GetLocalParentFrame(web_frame_); |
| 521 WebFrameClient::NavigationPolicyInfo::ArchiveStatus::Present; | 528 |
| 522 } | 529 // Newly created child frames may need to be navigated to a history item |
| 530 // during a back/forward navigation. This will only happen when the parent | |
| 531 // is a LocalFrame doing a back/forward navigation that has not completed. | |
| 532 // (If the load has completed and the parent later adds a frame with script, | |
| 533 // we do not want to use a history item for it.) | |
| 534 navigation_info.is_history_navigation_in_new_child_frame = | |
| 535 IsBackForwardNavigationInProgress(local_parent_frame); | |
| 536 | |
| 537 // TODO(nasko): How should this work with OOPIF? | |
| 538 // The MHTMLArchive is parsed as a whole, but can be constructed from frames | |
| 539 // in multiple processes. In that case, which process should parse it and how | |
| 540 // should the output be spread back across multiple processes? | |
| 541 navigation_info.archive_status = | |
| 542 IsLoadedAsMHTMLArchive(local_parent_frame) | |
| 543 ? WebFrameClient::NavigationPolicyInfo::ArchiveStatus::Present | |
| 544 : WebFrameClient::NavigationPolicyInfo::ArchiveStatus::Absent; | |
| 523 | 545 |
| 524 // Caching could be disabled for requests initiated by DevTools. | 546 // Caching could be disabled for requests initiated by DevTools. |
| 525 // TODO(ananta) | 547 // TODO(ananta) |
| 526 // We should extract the network cache state into a global component which | 548 // We should extract the network cache state into a global component which |
| 527 // can be queried here and wherever necessary. | 549 // can be queried here and wherever necessary. |
| 528 navigation_info.is_cache_disabled = | 550 navigation_info.is_cache_disabled = |
| 529 DevToolsAgent() ? DevToolsAgent()->CacheDisabled() : false; | 551 DevToolsAgent() ? DevToolsAgent()->CacheDisabled() : false; |
| 530 if (form) | 552 if (form) |
| 531 navigation_info.form = WebFormElement(form); | 553 navigation_info.form = WebFormElement(form); |
| 532 | 554 |
| (...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 980 WrappedResourceRequest(request)); | 1002 WrappedResourceRequest(request)); |
| 981 } | 1003 } |
| 982 return false; | 1004 return false; |
| 983 } | 1005 } |
| 984 | 1006 |
| 985 WebDevToolsAgentImpl* LocalFrameClientImpl::DevToolsAgent() { | 1007 WebDevToolsAgentImpl* LocalFrameClientImpl::DevToolsAgent() { |
| 986 return WebLocalFrameImpl::FromFrame(web_frame_->GetFrame()->LocalFrameRoot()) | 1008 return WebLocalFrameImpl::FromFrame(web_frame_->GetFrame()->LocalFrameRoot()) |
| 987 ->DevToolsAgentImpl(); | 1009 ->DevToolsAgentImpl(); |
| 988 } | 1010 } |
| 989 | 1011 |
| 990 bool LocalFrameClientImpl::IsLoadedAsMHTMLArchive() const { | |
| 991 WebFrame* parent_frame = web_frame_->Parent(); | |
| 992 if (!parent_frame) | |
| 993 return false; | |
| 994 | |
| 995 // TODO(nasko): How should this work with OOPIF? | |
| 996 // The MHTMLArchive is parsed as a whole, but can be constructed from frames | |
| 997 // in multiple processes. In that case, which process should parse it and how | |
| 998 // should the output be spread back across multiple processes? | |
| 999 if (!parent_frame->IsWebLocalFrame()) | |
| 1000 return false; | |
| 1001 | |
| 1002 return ToWebLocalFrameImpl(parent_frame) | |
| 1003 ->GetFrame() | |
| 1004 ->Loader() | |
| 1005 .GetDocumentLoader() | |
| 1006 ->Fetcher() | |
| 1007 ->Archive(); | |
| 1008 } | |
| 1009 | |
| 1010 KURL LocalFrameClientImpl::OverrideFlashEmbedWithHTML(const KURL& url) { | 1012 KURL LocalFrameClientImpl::OverrideFlashEmbedWithHTML(const KURL& url) { |
| 1011 return web_frame_->Client()->OverrideFlashEmbedWithHTML(WebURL(url)); | 1013 return web_frame_->Client()->OverrideFlashEmbedWithHTML(WebURL(url)); |
| 1012 } | 1014 } |
| 1013 | 1015 |
| 1014 void LocalFrameClientImpl::SetHasReceivedUserGesture(bool received_previously) { | 1016 void LocalFrameClientImpl::SetHasReceivedUserGesture(bool received_previously) { |
| 1015 // The client potentially needs to dispatch the event to other processes only | 1017 // The client potentially needs to dispatch the event to other processes only |
| 1016 // for the first time. | 1018 // for the first time. |
| 1017 if (!received_previously && web_frame_->Client()) | 1019 if (!received_previously && web_frame_->Client()) |
| 1018 web_frame_->Client()->SetHasReceivedUserGesture(); | 1020 web_frame_->Client()->SetHasReceivedUserGesture(); |
| 1019 // WebAutofillClient reacts only to the user gestures for this particular | 1021 // WebAutofillClient reacts only to the user gestures for this particular |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 1031 void LocalFrameClientImpl::AbortClientNavigation() { | 1033 void LocalFrameClientImpl::AbortClientNavigation() { |
| 1032 if (web_frame_->Client()) | 1034 if (web_frame_->Client()) |
| 1033 web_frame_->Client()->AbortClientNavigation(); | 1035 web_frame_->Client()->AbortClientNavigation(); |
| 1034 } | 1036 } |
| 1035 | 1037 |
| 1036 TextCheckerClient& LocalFrameClientImpl::GetTextCheckerClient() const { | 1038 TextCheckerClient& LocalFrameClientImpl::GetTextCheckerClient() const { |
| 1037 return web_frame_->GetTextCheckerClient(); | 1039 return web_frame_->GetTextCheckerClient(); |
| 1038 } | 1040 } |
| 1039 | 1041 |
| 1040 } // namespace blink | 1042 } // namespace blink |
| OLD | NEW |