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

Side by Side Diff: third_party/WebKit/Source/core/loader/DocumentLoader.cpp

Issue 2905113002: Initialize a default feature policy for all documents (Closed)
Patch Set: Fix layout test Created 3 years, 6 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 /* 1 /*
2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
3 * Copyright (C) 2011 Google Inc. All rights reserved. 3 * Copyright (C) 2011 Google 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 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 8 *
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. 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 977 matching lines...) Expand 10 before | Expand all | Expand 10 after
988 // Links with media values need more information (like viewport information). 988 // Links with media values need more information (like viewport information).
989 // This happens after the first chunk is parsed in HTMLDocumentParser. 989 // This happens after the first chunk is parsed in HTMLDocumentParser.
990 DispatchLinkHeaderPreloads(nullptr, LinkLoader::kOnlyLoadNonMedia); 990 DispatchLinkHeaderPreloads(nullptr, LinkLoader::kOnlyLoadNonMedia);
991 991
992 TRACE_EVENT1("devtools.timeline", "CommitLoad", "data", 992 TRACE_EVENT1("devtools.timeline", "CommitLoad", "data",
993 InspectorCommitLoadEvent::Data(frame_)); 993 InspectorCommitLoadEvent::Data(frame_));
994 probe::didCommitLoad(frame_, this); 994 probe::didCommitLoad(frame_, this);
995 frame_->GetPage()->DidCommitLoad(frame_); 995 frame_->GetPage()->DidCommitLoad(frame_);
996 } 996 }
997 997
998 void SetFeaturePolicy(Document* document, const String& feature_policy_header) {
999 if (!RuntimeEnabledFeatures::featurePolicyEnabled())
1000 return;
1001 LocalFrame* frame = document->GetFrame();
1002 WebFeaturePolicy* parent_feature_policy =
1003 frame->IsMainFrame()
1004 ? nullptr
1005 : frame->Tree().Parent()->GetSecurityContext()->GetFeaturePolicy();
1006 Vector<String> messages;
1007 const WebParsedFeaturePolicy& parsed_header = ParseFeaturePolicy(
1008 feature_policy_header, frame->GetSecurityContext()->GetSecurityOrigin(),
1009 &messages);
1010 WebParsedFeaturePolicy container_policy;
1011 if (frame->Owner())
1012 container_policy = frame->Owner()->ContainerPolicy();
1013 // Check that if there is a parent frame, that its feature policy is
1014 // correctly initialized. Crash if that is not the case. (Temporary crash for
1015 // isolating the cause of https://crbug.com/722333)
1016 // Note that even with this check removed, the process will stil crash in
1017 // feature_policy.cc when it attempts to dereference parent_feature_policy.
1018 // This check is to distinguish between two possible causes.
1019 if (!container_policy.empty())
1020 CHECK(frame->IsMainFrame() || parent_feature_policy);
1021 frame->GetSecurityContext()->InitializeFeaturePolicy(
1022 parsed_header, container_policy, parent_feature_policy);
1023
1024 for (auto& message : messages) {
1025 document->AddConsoleMessage(
1026 ConsoleMessage::Create(kOtherMessageSource, kErrorMessageLevel,
1027 "Error with Feature-Policy header: " + message));
1028 }
1029 if (!parsed_header.empty())
1030 frame->Client()->DidSetFeaturePolicyHeader(parsed_header);
1031 }
1032
1033 // static 998 // static
1034 bool DocumentLoader::ShouldClearWindowName( 999 bool DocumentLoader::ShouldClearWindowName(
1035 const LocalFrame& frame, 1000 const LocalFrame& frame,
1036 SecurityOrigin* previous_security_origin, 1001 SecurityOrigin* previous_security_origin,
1037 const Document& new_document) { 1002 const Document& new_document) {
1038 if (!previous_security_origin) 1003 if (!previous_security_origin)
1039 return false; 1004 return false;
1040 if (!frame.IsMainFrame()) 1005 if (!frame.IsMainFrame())
1041 return false; 1006 return false;
1042 if (frame.Loader().Opener()) 1007 if (frame.Loader().Opener())
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1089 // will use stale values from HTMLParserOption. 1054 // will use stale values from HTMLParserOption.
1090 if (reason == InstallNewDocumentReason::kNavigation) 1055 if (reason == InstallNewDocumentReason::kNavigation)
1091 DidCommitNavigation(); 1056 DidCommitNavigation();
1092 1057
1093 writer_ = 1058 writer_ =
1094 DocumentWriter::Create(document, parsing_policy, mime_type, encoding); 1059 DocumentWriter::Create(document, parsing_policy, mime_type, encoding);
1095 1060
1096 // FeaturePolicy is reset in the browser process on commit, so this needs to 1061 // FeaturePolicy is reset in the browser process on commit, so this needs to
1097 // be initialized and replicated to the browser process after commit messages 1062 // be initialized and replicated to the browser process after commit messages
1098 // are sent in didCommitNavigation(). 1063 // are sent in didCommitNavigation().
1099 SetFeaturePolicy(document, 1064 document->SetFeaturePolicy(
1100 response_.HttpHeaderField(HTTPNames::Feature_Policy)); 1065 response_.HttpHeaderField(HTTPNames::Feature_Policy));
1101 1066
1102 GetFrameLoader().DispatchDidClearDocumentOfWindowObject(); 1067 GetFrameLoader().DispatchDidClearDocumentOfWindowObject();
1103 } 1068 }
1104 1069
1105 const AtomicString& DocumentLoader::MimeType() const { 1070 const AtomicString& DocumentLoader::MimeType() const {
1106 if (writer_) 1071 if (writer_)
1107 return writer_->MimeType(); 1072 return writer_->MimeType();
1108 return response_.MimeType(); 1073 return response_.MimeType();
1109 } 1074 }
1110 1075
1111 // This is only called by 1076 // This is only called by
1112 // FrameLoader::replaceDocumentWhileExecutingJavaScriptURL() 1077 // FrameLoader::replaceDocumentWhileExecutingJavaScriptURL()
1113 void DocumentLoader::ReplaceDocumentWhileExecutingJavaScriptURL( 1078 void DocumentLoader::ReplaceDocumentWhileExecutingJavaScriptURL(
1114 const DocumentInit& init, 1079 const DocumentInit& init,
1115 const String& source) { 1080 const String& source) {
1116 InstallNewDocument(init, MimeType(), 1081 InstallNewDocument(init, MimeType(),
1117 writer_ ? writer_->Encoding() : g_empty_atom, 1082 writer_ ? writer_->Encoding() : g_empty_atom,
1118 InstallNewDocumentReason::kJavascriptURL, 1083 InstallNewDocumentReason::kJavascriptURL,
1119 kForceSynchronousParsing, KURL()); 1084 kForceSynchronousParsing, KURL());
1120 if (!source.IsNull()) 1085 if (!source.IsNull())
1121 writer_->AppendReplacingData(source); 1086 writer_->AppendReplacingData(source);
1122 EndWriting(); 1087 EndWriting();
1123 } 1088 }
1124 1089
1125 DEFINE_WEAK_IDENTIFIER_MAP(DocumentLoader); 1090 DEFINE_WEAK_IDENTIFIER_MAP(DocumentLoader);
1126 1091
1127 } // namespace blink 1092 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698