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

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

Issue 2438743005: Fix history nav to a script-injected about:blank frame. (Closed)
Patch Set: Fix nits. Created 4 years, 2 months 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 5034 matching lines...) Expand 10 before | Expand all | Expand 10 after
5045 render_view_->renderer_preferences_ 5045 render_view_->renderer_preferences_
5046 .browser_handles_all_top_level_requests) { 5046 .browser_handles_all_top_level_requests) {
5047 OpenURL(url, IsHttpPost(info.urlRequest), 5047 OpenURL(url, IsHttpPost(info.urlRequest),
5048 GetRequestBodyForWebURLRequest(info.urlRequest), 5048 GetRequestBodyForWebURLRequest(info.urlRequest),
5049 GetWebURLRequestHeaders(info.urlRequest), referrer, 5049 GetWebURLRequestHeaders(info.urlRequest), referrer,
5050 info.defaultPolicy, info.replacesCurrentHistoryItem, false); 5050 info.defaultPolicy, info.replacesCurrentHistoryItem, false);
5051 return blink::WebNavigationPolicyIgnore; // Suppress the load here. 5051 return blink::WebNavigationPolicyIgnore; // Suppress the load here.
5052 } 5052 }
5053 5053
5054 // In OOPIF-enabled modes, back/forward navigations in newly created subframes 5054 // In OOPIF-enabled modes, back/forward navigations in newly created subframes
5055 // should be sent to the browser if there is a matching FrameNavigationEntry. 5055 // should be sent to the browser if there is a matching FrameNavigationEntry,
5056 // If this frame isn't on the list of unique names that have history items, 5056 // and if it isn't just staying at about:blank. If this frame isn't in the
5057 // fall back to loading the default url. (We remove each name as we encounter 5057 // map of unique names that have history items, or if it's staying at the
5058 // it, because it will only be used once as the frame is created.) 5058 // initial about:blank URL, fall back to loading the default url. (We remove
5059 // each name as we encounter it, because it will only be used once as the
5060 // frame is created.)
5059 if (SiteIsolationPolicy::UseSubframeNavigationEntries() && 5061 if (SiteIsolationPolicy::UseSubframeNavigationEntries() &&
5060 info.isHistoryNavigationInNewChildFrame && is_content_initiated && 5062 info.isHistoryNavigationInNewChildFrame && is_content_initiated &&
5061 frame_->parent() && 5063 frame_->parent()) {
5062 RenderFrameImpl::FromWebFrame(frame_->parent()) 5064 // Check whether the browser has a history item for this frame that isn't
5063 ->history_subframe_unique_names_.erase( 5065 // just staying at the initial about:blank document.
5064 frame_->uniqueName().utf8()) > 0) { 5066 bool should_ask_browser = false;
5065 // Don't do this if |info| also says it is a client redirect, in which case 5067 RenderFrameImpl* parent = RenderFrameImpl::FromWebFrame(frame_->parent());
5066 // JavaScript on the page is trying to interrupt the history navigation. 5068 const auto& iter = parent->history_subframe_unique_names_.find(
5067 if (!info.isClientRedirect) { 5069 frame_->uniqueName().utf8());
5068 OpenURL(url, IsHttpPost(info.urlRequest), 5070 if (iter != parent->history_subframe_unique_names_.end()) {
5069 GetRequestBodyForWebURLRequest(info.urlRequest), 5071 bool history_item_is_about_blank = iter->second;
5070 GetWebURLRequestHeaders(info.urlRequest), referrer, 5072 should_ask_browser =
5071 info.defaultPolicy, info.replacesCurrentHistoryItem, true); 5073 !history_item_is_about_blank || url != GURL(url::kAboutBlankURL);
5072 // Suppress the load in Blink but mark the frame as loading. 5074 parent->history_subframe_unique_names_.erase(frame_->uniqueName().utf8());
5073 return blink::WebNavigationPolicyHandledByClient; 5075 }
5074 } else { 5076
5075 // Client redirects during an initial history load should attempt to 5077 if (should_ask_browser) {
5076 // cancel the history navigation. They will create a provisional document 5078 // Don't do this if |info| also says it is a client redirect, in which
5077 // loader, causing the history load to be ignored in NavigateInternal, and 5079 // case JavaScript on the page is trying to interrupt the history
5078 // this IPC will try to cancel any cross-process history load. 5080 // navigation.
5079 Send(new FrameHostMsg_CancelInitialHistoryLoad(routing_id_)); 5081 if (!info.isClientRedirect) {
5082 OpenURL(url, IsHttpPost(info.urlRequest),
5083 GetRequestBodyForWebURLRequest(info.urlRequest),
5084 GetWebURLRequestHeaders(info.urlRequest), referrer,
5085 info.defaultPolicy, info.replacesCurrentHistoryItem, true);
5086 // Suppress the load in Blink but mark the frame as loading.
5087 return blink::WebNavigationPolicyHandledByClient;
5088 } else {
5089 // Client redirects during an initial history load should attempt to
5090 // cancel the history navigation. They will create a provisional
5091 // document loader, causing the history load to be ignored in
5092 // NavigateInternal, and this IPC will try to cancel any cross-process
5093 // history load.
5094 Send(new FrameHostMsg_CancelInitialHistoryLoad(routing_id_));
5095 }
5080 } 5096 }
5081 } 5097 }
5082 5098
5083 // Use the frame's original request's URL rather than the document's URL for 5099 // Use the frame's original request's URL rather than the document's URL for
5084 // subsequent checks. For a popup, the document's URL may become the opener 5100 // subsequent checks. For a popup, the document's URL may become the opener
5085 // window's URL if the opener has called document.write(). 5101 // window's URL if the opener has called document.write().
5086 // See http://crbug.com/93517. 5102 // See http://crbug.com/93517.
5087 GURL old_url(frame_->dataSource()->request().url()); 5103 GURL old_url(frame_->dataSource()->request().url());
5088 5104
5089 // Detect when we're crossing a permission-based boundary (e.g. into or out of 5105 // Detect when we're crossing a permission-based boundary (e.g. into or out of
(...skipping 619 matching lines...) Expand 10 before | Expand all | Expand 10 after
5709 item_for_history_navigation.documentSequenceNumber()) { 5725 item_for_history_navigation.documentSequenceNumber()) {
5710 history_load_type = blink::WebHistoryDifferentDocumentLoad; 5726 history_load_type = blink::WebHistoryDifferentDocumentLoad;
5711 } 5727 }
5712 } 5728 }
5713 } 5729 }
5714 5730
5715 // If this navigation is to a history item for a new child frame, we may 5731 // If this navigation is to a history item for a new child frame, we may
5716 // want to ignore it in some cases. If a Javascript navigation (i.e., 5732 // want to ignore it in some cases. If a Javascript navigation (i.e.,
5717 // client redirect) interrupted it and has either been scheduled, 5733 // client redirect) interrupted it and has either been scheduled,
5718 // started loading, or has committed, we should ignore the history item. 5734 // started loading, or has committed, we should ignore the history item.
5719 // Similarly, if the history item just says to stay on about:blank,
5720 // don't load it again, which might clobber injected content.
5721 bool interrupted_by_client_redirect = 5735 bool interrupted_by_client_redirect =
5722 frame_->isNavigationScheduledWithin(0) || 5736 frame_->isNavigationScheduledWithin(0) ||
5723 frame_->provisionalDataSource() || 5737 frame_->provisionalDataSource() ||
5724 !current_history_item_.isNull(); 5738 !current_history_item_.isNull();
5725 bool staying_at_about_blank =
5726 current_history_item_.isNull() &&
5727 item_for_history_navigation.urlString() == url::kAboutBlankURL;
5728 if (staying_at_about_blank) {
5729 // TODO(creis): We should avoid the need to go to the browser and back
5730 // when loading about:blank as a history item, which we can do by
5731 // sending a subtree of same-process history items when navigating a
5732 // frame back/forward (see https://crbug.com/639842).
5733 //
5734 // Until then, we need to fake a DidStopLoading, since there's no easy
5735 // way to generate a commit for the initial empty document at this
5736 // point in time.
5737 //
5738 // Note that the stopLoading call may run script which might delete
5739 // this frame, so return immediately if this frame is no longer valid.
5740 base::WeakPtr<RenderFrameImpl> weak_this = weak_factory_.GetWeakPtr();
5741 frame_->stopLoading();
5742 if (!weak_this)
5743 return;
5744 }
5745 if (request_params.is_history_navigation_in_new_child && 5739 if (request_params.is_history_navigation_in_new_child &&
5746 (interrupted_by_client_redirect || staying_at_about_blank)) { 5740 interrupted_by_client_redirect) {
5747 should_load_request = false; 5741 should_load_request = false;
5748 has_history_navigation_in_frame = false; 5742 has_history_navigation_in_frame = false;
5749 } 5743 }
5750 5744
5751 // Generate the request for the load from the HistoryItem. 5745 // Generate the request for the load from the HistoryItem.
5752 // PlzNavigate: use the data sent by the browser for the url and the 5746 // PlzNavigate: use the data sent by the browser for the url and the
5753 // HTTP state. The restoration of user state such as scroll position 5747 // HTTP state. The restoration of user state such as scroll position
5754 // will be done based on the history item during the load. 5748 // will be done based on the history item during the load.
5755 if (!browser_side_navigation && should_load_request) { 5749 if (!browser_side_navigation && should_load_request) {
5756 request = frame_->requestFromHistoryItem(item_for_history_navigation, 5750 request = frame_->requestFromHistoryItem(item_for_history_navigation,
(...skipping 745 matching lines...) Expand 10 before | Expand all | Expand 10 after
6502 // event target. Potentially a Pepper plugin will receive the event. 6496 // event target. Potentially a Pepper plugin will receive the event.
6503 // In order to tell whether a plugin gets the last mouse event and which it 6497 // In order to tell whether a plugin gets the last mouse event and which it
6504 // is, we set |pepper_last_mouse_event_target_| to null here. If a plugin gets 6498 // is, we set |pepper_last_mouse_event_target_| to null here. If a plugin gets
6505 // the event, it will notify us via DidReceiveMouseEvent() and set itself as 6499 // the event, it will notify us via DidReceiveMouseEvent() and set itself as
6506 // |pepper_last_mouse_event_target_|. 6500 // |pepper_last_mouse_event_target_|.
6507 pepper_last_mouse_event_target_ = nullptr; 6501 pepper_last_mouse_event_target_ = nullptr;
6508 #endif 6502 #endif
6509 } 6503 }
6510 6504
6511 } // namespace content 6505 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698