Skip to content

Commit

Permalink
Move GrantLoadLocalResources to WebNavigationParams
Browse files Browse the repository at this point in the history
This is decided per navigation, no need to later change it
through WebDocument.

Bug: none
Change-Id: Ibae0f2ea53d56163f1dd59fa2f89ddd6993676f6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1844194
Reviewed-by: Bo <boliu@chromium.org>
Commit-Queue: Dmitry Gozman <dgozman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#703302}
  • Loading branch information
dgozman authored and Commit Bot committed Oct 7, 2019
1 parent 68ba239 commit c387337
Show file tree
Hide file tree
Showing 12 changed files with 29 additions and 26 deletions.
9 changes: 1 addition & 8 deletions android_webview/renderer/aw_render_frame_ext.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@
#include "components/autofill/content/renderer/password_autofill_agent.h"
#include "components/content_capture/common/content_capture_features.h"
#include "components/content_capture/renderer/content_capture_sender.h"
#include "content/public/renderer/document_state.h"
#include "content/public/renderer/render_frame.h"
#include "content/public/renderer/render_view.h"
#include "third_party/blink/public/platform/web_security_origin.h"
#include "third_party/blink/public/platform/web_size.h"
#include "third_party/blink/public/web/web_document.h"
#include "third_party/blink/public/web/web_element.h"
#include "third_party/blink/public/web/web_element_collection.h"
#include "third_party/blink/public/web/web_frame_widget.h"
Expand Down Expand Up @@ -202,19 +200,14 @@ bool AwRenderFrameExt::OnAssociatedInterfaceRequestForFrame(
void AwRenderFrameExt::DidCommitProvisionalLoad(
bool is_same_document_navigation,
ui::PageTransition transition) {
blink::WebLocalFrame* frame = render_frame()->GetWebFrame();
content::DocumentState* document_state =
content::DocumentState::FromDocumentLoader(frame->GetDocumentLoader());
if (document_state->can_load_local_resources())
frame->GetDocument().GrantLoadLocalResources();

// Clear the cache when we cross site boundaries in the main frame.
//
// We're trying to approximate what happens with a multi-process Chromium,
// where navigation across origins would cause a new render process to spin
// up, and thus start with a clear cache. Wiring up a signal from browser to
// renderer code to say "this navigation would have switched processes" would
// be disruptive, so this clearing of the cache is the compromise.
blink::WebLocalFrame* frame = render_frame()->GetWebFrame();
if (!frame->Parent()) {
url::Origin new_origin = url::Origin::Create(frame->GetDocument().Url());
if (!new_origin.IsSameOriginWith(last_origin_)) {
Expand Down
4 changes: 1 addition & 3 deletions content/public/renderer/document_state.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ DocumentState::DocumentState()
was_alpn_negotiated_(false),
was_alternate_protocol_available_(false),
connection_info_(net::HttpResponseInfo::CONNECTION_INFO_UNKNOWN),
was_load_data_with_base_url_request_(false),
can_load_local_resources_(false) {}
was_load_data_with_base_url_request_(false) {}

DocumentState::~DocumentState() {}

Expand All @@ -27,7 +26,6 @@ std::unique_ptr<DocumentState> DocumentState::Clone() {
new_document_state->set_was_load_data_with_base_url_request(
was_load_data_with_base_url_request_);
new_document_state->set_data_url(data_url_);
new_document_state->set_can_load_local_resources(can_load_local_resources_);
return new_document_state;
}

Expand Down
7 changes: 0 additions & 7 deletions content/public/renderer/document_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,6 @@ class CONTENT_EXPORT DocumentState : public blink::WebDocumentLoader::ExtraData,
data_url_ = data_url;
}

bool can_load_local_resources() const { return can_load_local_resources_; }
void set_can_load_local_resources(bool can_load) {
can_load_local_resources_ = can_load;
}

private:
bool was_fetched_via_spdy_;
bool was_alpn_negotiated_;
Expand All @@ -95,8 +90,6 @@ class CONTENT_EXPORT DocumentState : public blink::WebDocumentLoader::ExtraData,

bool was_load_data_with_base_url_request_;
GURL data_url_;

bool can_load_local_resources_;
};

} // namespace content
Expand Down
10 changes: 8 additions & 2 deletions content/renderer/render_frame_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -932,8 +932,6 @@ std::unique_ptr<DocumentState> BuildDocumentStateFromParams(
mojom::NavigationType::RELOAD_ORIGINAL_REQUEST_URL);
internal_data->set_previews_state(common_params.previews_state);
internal_data->set_request_id(request_id);
document_state->set_can_load_local_resources(
commit_params.can_load_local_resources);

if (head) {
if (head->headers)
Expand Down Expand Up @@ -1047,6 +1045,14 @@ void FillMiscNavigationParams(

navigation_params->is_browser_initiated = commit_params.is_browser_initiated;

#if defined(OS_ANDROID)
// Only android webview uses this.
navigation_params->grant_load_local_resources =
commit_params.can_load_local_resources;
#else
DCHECK(!commit_params.can_load_local_resources);
#endif

if (commit_params.origin_to_commit) {
navigation_params->origin_to_commit =
commit_params.origin_to_commit.value();
Expand Down
1 change: 0 additions & 1 deletion third_party/blink/public/web/web_document.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ class WebDocument : public WebNode {
// Note: Security checks should use the getSecurityOrigin(), not url().
BLINK_EXPORT WebSecurityOrigin GetSecurityOrigin() const;
BLINK_EXPORT bool IsSecureContext() const;
BLINK_EXPORT void GrantLoadLocalResources();

BLINK_EXPORT WebString Encoding() const;
BLINK_EXPORT WebString ContentLanguage() const;
Expand Down
2 changes: 2 additions & 0 deletions third_party/blink/public/web/web_navigation_params.h
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,8 @@ struct BLINK_EXPORT WebNavigationParams {
bool is_user_activated = false;
// Whether this navigation was browser initiated.
bool is_browser_initiated = false;
// Whether the document should be able to access local file:// resources.
bool grant_load_local_resources = false;
// The previews state which should be used for this navigation.
WebURLRequest::PreviewsState previews_state =
WebURLRequest::kPreviewsUnspecified;
Expand Down
3 changes: 3 additions & 0 deletions third_party/blink/renderer/core/dom/document.cc
Original file line number Diff line number Diff line change
Expand Up @@ -844,6 +844,9 @@ class Document::SecurityContextInit : public FeaturePolicyParserDelegate {
}
}
}

if (initializer.GrantLoadLocalResources())
security_origin_->GrantLoadLocalResources();
}

void InitializeFeaturePolicy(const DocumentInit& initializer,
Expand Down
6 changes: 6 additions & 0 deletions third_party/blink/renderer/core/dom/document_init.cc
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,12 @@ DocumentInit& DocumentInit::WithBlockedByCSP(bool blocked_by_csp) {
return *this;
}

DocumentInit& DocumentInit::WithGrantLoadLocalResources(
bool grant_load_local_resources) {
grant_load_local_resources_ = grant_load_local_resources;
return *this;
}

DocumentInit& DocumentInit::WithRegistrationContext(
V0CustomElementRegistrationContext* registration_context) {
DCHECK(!create_new_registration_context_);
Expand Down
5 changes: 5 additions & 0 deletions third_party/blink/renderer/core/dom/document_init.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class CORE_EXPORT DocumentInit final {
WebInsecureRequestPolicy GetInsecureRequestPolicy() const;
const SecurityContext::InsecureNavigationsSet* InsecureNavigationsToUpgrade()
const;
bool GrantLoadLocalResources() const { return grant_load_local_resources_; }

Settings* GetSettings() const;

Expand Down Expand Up @@ -119,6 +120,7 @@ class CORE_EXPORT DocumentInit final {

DocumentInit& WithSrcdocDocument(bool is_srcdoc_document);
DocumentInit& WithBlockedByCSP(bool blocked_by_csp);
DocumentInit& WithGrantLoadLocalResources(bool grant_load_local_resources);

DocumentInit& WithRegistrationContext(V0CustomElementRegistrationContext*);
V0CustomElementRegistrationContext* RegistrationContext(Document*) const;
Expand Down Expand Up @@ -183,6 +185,9 @@ class CORE_EXPORT DocumentInit final {
// empty document instead.
bool blocked_by_csp_ = false;

// Whether the document should be able to access local file:// resources.
bool grant_load_local_resources_ = false;

Member<V0CustomElementRegistrationContext> registration_context_;
bool create_new_registration_context_;

Expand Down
5 changes: 0 additions & 5 deletions third_party/blink/renderer/core/exported/web_document.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,6 @@ WebSecurityOrigin WebDocument::GetSecurityOrigin() const {
return WebSecurityOrigin(ConstUnwrap<Document>()->GetSecurityOrigin());
}

void WebDocument::GrantLoadLocalResources() {
if (Document* document = Unwrap<Document>())
document->GetMutableSecurityOrigin()->GrantLoadLocalResources();
}

bool WebDocument::IsSecureContext() const {
const Document* document = ConstUnwrap<Document>();
return document && document->IsSecureContext();
Expand Down
2 changes: 2 additions & 0 deletions third_party/blink/renderer/core/loader/document_loader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ DocumentLoader::DocumentLoader(
unreachable_url_ = params_->unreachable_url;
previews_state_ = params_->previews_state;
ip_address_space_ = params_->ip_address_space;
grant_load_local_resources_ = params_->grant_load_local_resources;

WebNavigationTimings& timings = params_->navigation_timings;
if (!timings.input_start.is_null())
Expand Down Expand Up @@ -1477,6 +1478,7 @@ void DocumentLoader::InstallNewDocument(
.WithIPAddressSpace(ip_address_space_)
.WithSrcdocDocument(loading_srcdoc_)
.WithBlockedByCSP(was_blocked_by_csp_)
.WithGrantLoadLocalResources(grant_load_local_resources_)
.WithNewRegistrationContext()
.WithFeaturePolicyHeader(feature_policy.ToString())
.WithOriginTrialsHeader(
Expand Down
1 change: 1 addition & 0 deletions third_party/blink/renderer/core/loader/document_loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@ class CORE_EXPORT DocumentLoader : public GarbageCollected<DocumentLoader>,
std::unique_ptr<WebNavigationBodyLoader> body_loader_;
network::mojom::IPAddressSpace ip_address_space_ =
network::mojom::IPAddressSpace::kUnknown;
bool grant_load_local_resources_ = false;

// Params are saved in constructor and are cleared after StartLoading().
// TODO(dgozman): remove once StartLoading is merged with constructor.
Expand Down

0 comments on commit c387337

Please sign in to comment.