Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(367)

Side by Side Diff: content/renderer/render_frame_impl.cc

Issue 2445053002: Fix history nav to a script-injected about:blank frame. (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
(...skipping 5020 matching lines...) Expand 10 before | Expand all | Expand 10 after
5031 if (is_content_initiated && IsTopLevelNavigation(frame_) && 5031 if (is_content_initiated && IsTopLevelNavigation(frame_) &&
5032 render_view_->renderer_preferences_ 5032 render_view_->renderer_preferences_
5033 .browser_handles_all_top_level_requests) { 5033 .browser_handles_all_top_level_requests) {
5034 OpenURL(url, IsHttpPost(info.urlRequest), 5034 OpenURL(url, IsHttpPost(info.urlRequest),
5035 GetRequestBodyForWebURLRequest(info.urlRequest), referrer, 5035 GetRequestBodyForWebURLRequest(info.urlRequest), referrer,
5036 info.defaultPolicy, info.replacesCurrentHistoryItem, false); 5036 info.defaultPolicy, info.replacesCurrentHistoryItem, false);
5037 return blink::WebNavigationPolicyIgnore; // Suppress the load here. 5037 return blink::WebNavigationPolicyIgnore; // Suppress the load here.
5038 } 5038 }
5039 5039
5040 // In OOPIF-enabled modes, back/forward navigations in newly created subframes 5040 // In OOPIF-enabled modes, back/forward navigations in newly created subframes
5041 // should be sent to the browser if there is a matching FrameNavigationEntry. 5041 // should be sent to the browser if there is a matching FrameNavigationEntry,
5042 // If this frame isn't on the list of unique names that have history items, 5042 // and if it isn't just staying at about:blank. If this frame isn't in the
5043 // fall back to loading the default url. (We remove each name as we encounter 5043 // map of unique names that have history items, or if it's staying at the
5044 // it, because it will only be used once as the frame is created.) 5044 // initial about:blank URL, fall back to loading the default url. (We remove
5045 // each name as we encounter it, because it will only be used once as the
5046 // frame is created.)
5045 if (SiteIsolationPolicy::UseSubframeNavigationEntries() && 5047 if (SiteIsolationPolicy::UseSubframeNavigationEntries() &&
5046 info.isHistoryNavigationInNewChildFrame && is_content_initiated && 5048 info.isHistoryNavigationInNewChildFrame && is_content_initiated &&
5047 frame_->parent() && 5049 frame_->parent()) {
5048 RenderFrameImpl::FromWebFrame(frame_->parent()) 5050 // Check whether the browser has a history item for this frame that isn't
5049 ->history_subframe_unique_names_.erase( 5051 // just staying at the initial about:blank document.
5050 frame_->uniqueName().utf8()) > 0) { 5052 bool should_ask_browser = false;
5051 // Don't do this if |info| also says it is a client redirect, in which case 5053 RenderFrameImpl* parent = RenderFrameImpl::FromWebFrame(frame_->parent());
5052 // JavaScript on the page is trying to interrupt the history navigation. 5054 const auto& iter = parent->history_subframe_unique_names_.find(
5053 if (!info.isClientRedirect) { 5055 frame_->uniqueName().utf8());
5054 OpenURL(url, IsHttpPost(info.urlRequest), 5056 if (iter != parent->history_subframe_unique_names_.end()) {
5055 GetRequestBodyForWebURLRequest(info.urlRequest), referrer, 5057 bool history_item_is_about_blank = iter->second;
5056 info.defaultPolicy, info.replacesCurrentHistoryItem, true); 5058 should_ask_browser =
5057 // Suppress the load in Blink but mark the frame as loading. 5059 !history_item_is_about_blank || url != GURL(url::kAboutBlankURL);
5058 return blink::WebNavigationPolicyHandledByClient; 5060 parent->history_subframe_unique_names_.erase(frame_->uniqueName().utf8());
5059 } else { 5061 }
5060 // Client redirects during an initial history load should attempt to 5062
5061 // cancel the history navigation. They will create a provisional document 5063 if (should_ask_browser) {
5062 // loader, causing the history load to be ignored in NavigateInternal, and 5064 // Don't do this if |info| also says it is a client redirect, in which
5063 // this IPC will try to cancel any cross-process history load. 5065 // case JavaScript on the page is trying to interrupt the history
5064 Send(new FrameHostMsg_CancelInitialHistoryLoad(routing_id_)); 5066 // navigation.
5067 if (!info.isClientRedirect) {
5068 OpenURL(url, IsHttpPost(info.urlRequest),
5069 GetRequestBodyForWebURLRequest(info.urlRequest), referrer,
5070 info.defaultPolicy, info.replacesCurrentHistoryItem, true);
5071 // Suppress the load in Blink but mark the frame as loading.
5072 return blink::WebNavigationPolicyHandledByClient;
5073 } else {
5074 // Client redirects during an initial history load should attempt to
5075 // cancel the history navigation. They will create a provisional
5076 // document loader, causing the history load to be ignored in
5077 // NavigateInternal, and this IPC will try to cancel any cross-process
5078 // history load.
5079 Send(new FrameHostMsg_CancelInitialHistoryLoad(routing_id_));
5080 }
5065 } 5081 }
5066 } 5082 }
5067 5083
5068 // Use the frame's original request's URL rather than the document's URL for 5084 // Use the frame's original request's URL rather than the document's URL for
5069 // subsequent checks. For a popup, the document's URL may become the opener 5085 // subsequent checks. For a popup, the document's URL may become the opener
5070 // window's URL if the opener has called document.write(). 5086 // window's URL if the opener has called document.write().
5071 // See http://crbug.com/93517. 5087 // See http://crbug.com/93517.
5072 GURL old_url(frame_->dataSource()->request().url()); 5088 GURL old_url(frame_->dataSource()->request().url());
5073 5089
5074 // Detect when we're crossing a permission-based boundary (e.g. into or out of 5090 // Detect when we're crossing a permission-based boundary (e.g. into or out of
(...skipping 615 matching lines...) Expand 10 before | Expand all | Expand 10 after
5690 item_for_history_navigation.documentSequenceNumber()) { 5706 item_for_history_navigation.documentSequenceNumber()) {
5691 history_load_type = blink::WebHistoryDifferentDocumentLoad; 5707 history_load_type = blink::WebHistoryDifferentDocumentLoad;
5692 } 5708 }
5693 } 5709 }
5694 } 5710 }
5695 5711
5696 // If this navigation is to a history item for a new child frame, we may 5712 // If this navigation is to a history item for a new child frame, we may
5697 // want to ignore it in some cases. If a Javascript navigation (i.e., 5713 // want to ignore it in some cases. If a Javascript navigation (i.e.,
5698 // client redirect) interrupted it and has either been scheduled, 5714 // client redirect) interrupted it and has either been scheduled,
5699 // started loading, or has committed, we should ignore the history item. 5715 // started loading, or has committed, we should ignore the history item.
5700 // Similarly, if the history item just says to stay on about:blank,
5701 // don't load it again, which might clobber injected content.
5702 bool interrupted_by_client_redirect = 5716 bool interrupted_by_client_redirect =
5703 frame_->isNavigationScheduledWithin(0) || 5717 frame_->isNavigationScheduledWithin(0) ||
5704 frame_->provisionalDataSource() || 5718 frame_->provisionalDataSource() ||
5705 !current_history_item_.isNull(); 5719 !current_history_item_.isNull();
5706 bool staying_at_about_blank =
5707 current_history_item_.isNull() &&
5708 item_for_history_navigation.urlString() == url::kAboutBlankURL;
5709 if (staying_at_about_blank) {
5710 // TODO(creis): We should avoid the need to go to the browser and back
5711 // when loading about:blank as a history item, which we can do by
5712 // sending a subtree of same-process history items when navigating a
5713 // frame back/forward (see https://crbug.com/639842).
5714 //
5715 // Until then, we need to fake a DidStopLoading, since there's no easy
5716 // way to generate a commit for the initial empty document at this
5717 // point in time.
5718 //
5719 // Note that the stopLoading call may run script which might delete
5720 // this frame, so return immediately if this frame is no longer valid.
5721 base::WeakPtr<RenderFrameImpl> weak_this = weak_factory_.GetWeakPtr();
5722 frame_->stopLoading();
5723 if (!weak_this)
5724 return;
5725 }
5726 if (request_params.is_history_navigation_in_new_child && 5720 if (request_params.is_history_navigation_in_new_child &&
5727 (interrupted_by_client_redirect || staying_at_about_blank)) { 5721 interrupted_by_client_redirect) {
5728 should_load_request = false; 5722 should_load_request = false;
5729 has_history_navigation_in_frame = false; 5723 has_history_navigation_in_frame = false;
5730 } 5724 }
5731 5725
5732 // Generate the request for the load from the HistoryItem. 5726 // Generate the request for the load from the HistoryItem.
5733 // PlzNavigate: use the data sent by the browser for the url and the 5727 // PlzNavigate: use the data sent by the browser for the url and the
5734 // HTTP state. The restoration of user state such as scroll position 5728 // HTTP state. The restoration of user state such as scroll position
5735 // will be done based on the history item during the load. 5729 // will be done based on the history item during the load.
5736 if (!browser_side_navigation && should_load_request) { 5730 if (!browser_side_navigation && should_load_request) {
5737 request = frame_->requestFromHistoryItem(item_for_history_navigation, 5731 request = frame_->requestFromHistoryItem(item_for_history_navigation,
(...skipping 753 matching lines...) Expand 10 before | Expand all | Expand 10 after
6491 // event target. Potentially a Pepper plugin will receive the event. 6485 // event target. Potentially a Pepper plugin will receive the event.
6492 // In order to tell whether a plugin gets the last mouse event and which it 6486 // In order to tell whether a plugin gets the last mouse event and which it
6493 // is, we set |pepper_last_mouse_event_target_| to null here. If a plugin gets 6487 // is, we set |pepper_last_mouse_event_target_| to null here. If a plugin gets
6494 // the event, it will notify us via DidReceiveMouseEvent() and set itself as 6488 // the event, it will notify us via DidReceiveMouseEvent() and set itself as
6495 // |pepper_last_mouse_event_target_|. 6489 // |pepper_last_mouse_event_target_|.
6496 pepper_last_mouse_event_target_ = nullptr; 6490 pepper_last_mouse_event_target_ = nullptr;
6497 #endif 6491 #endif
6498 } 6492 }
6499 6493
6500 } // namespace content 6494 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698