Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
| 3 * Copyright (C) 2012 Intel Inc. All rights reserved. | 3 * Copyright (C) 2012 Intel 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 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 159 frame2->securityContext()->getSecurityOrigin(); | 159 frame2->securityContext()->getSecurityOrigin(); |
| 160 return securityOrigin1->canAccess(securityOrigin2); | 160 return securityOrigin1->canAccess(securityOrigin2); |
| 161 } | 161 } |
| 162 | 162 |
| 163 /** | 163 /** |
| 164 * Report sanitized name based on cross-origin policy. | 164 * Report sanitized name based on cross-origin policy. |
| 165 * See detailed Security doc here: http://bit.ly/2duD3F7 | 165 * See detailed Security doc here: http://bit.ly/2duD3F7 |
| 166 */ | 166 */ |
| 167 // static | 167 // static |
| 168 std::pair<String, DOMWindow*> Performance::sanitizedAttribution( | 168 std::pair<String, DOMWindow*> Performance::sanitizedAttribution( |
| 169 const HeapHashSet<Member<Frame>>& frames, | 169 ExecutionContext* taskContext, |
| 170 bool hasMultipleContexts, | |
| 170 Frame* observerFrame) { | 171 Frame* observerFrame) { |
| 171 if (frames.size() == 0) { | 172 if (!taskContext || !taskContext->isDocument() || |
|
caseq
2016/12/01 02:32:46
This will result in always returning kUnknownAttri
| |
| 173 !toDocument(taskContext)->frame()) { | |
| 172 // Unable to attribute as no script was involved. | 174 // Unable to attribute as no script was involved. |
| 173 return std::make_pair(kUnknownAttribution, nullptr); | 175 return std::make_pair(kUnknownAttribution, nullptr); |
| 174 } | 176 } |
| 175 if (frames.size() > 1) { | 177 if (hasMultipleContexts) { |
| 176 // Unable to attribute, multiple script execution contents were involved. | 178 // Unable to attribute, multiple script execution contents were involved. |
| 177 return std::make_pair(kAmbugiousAttribution, nullptr); | 179 return std::make_pair(kAmbugiousAttribution, nullptr); |
| 178 } | 180 } |
| 181 | |
| 179 // Exactly one culprit location, attribute based on origin boundary. | 182 // Exactly one culprit location, attribute based on origin boundary. |
| 180 DCHECK_EQ(1u, frames.size()); | 183 Frame* culpritFrame = toDocument(taskContext)->frame(); |
| 181 Frame* culpritFrame = *frames.begin(); | |
| 182 DCHECK(culpritFrame); | 184 DCHECK(culpritFrame); |
| 183 if (canAccessOrigin(observerFrame, culpritFrame)) { | 185 if (canAccessOrigin(observerFrame, culpritFrame)) { |
| 184 // From accessible frames or same origin, return culprit location URL. | 186 // From accessible frames or same origin, return culprit location URL. |
| 185 return std::make_pair(kSameOriginAttribution, culpritFrame->domWindow()); | 187 return std::make_pair(kSameOriginAttribution, culpritFrame->domWindow()); |
| 186 } | 188 } |
| 187 // For cross-origin, if the culprit is the descendant or ancestor of | 189 // For cross-origin, if the culprit is the descendant or ancestor of |
| 188 // observer then indicate the *closest* cross-origin frame between | 190 // observer then indicate the *closest* cross-origin frame between |
| 189 // the observer and the culprit, in the corresponding direction. | 191 // the observer and the culprit, in the corresponding direction. |
| 190 if (culpritFrame->tree().isDescendantOf(observerFrame)) { | 192 if (culpritFrame->tree().isDescendantOf(observerFrame)) { |
| 191 // If the culprit is a descendant of the observer, then walk up the tree | 193 // If the culprit is a descendant of the observer, then walk up the tree |
| 192 // from culprit to observer, and report the *last* cross-origin (from | 194 // from culprit to observer, and report the *last* cross-origin (from |
| 193 // observer) frame. If no intermediate cross-origin frame is found, then | 195 // observer) frame. If no intermediate cross-origin frame is found, then |
| 194 // report the culprit directly. | 196 // report the culprit directly. |
| 195 Frame* lastCrossOriginFrame = culpritFrame; | 197 Frame* lastCrossOriginFrame = culpritFrame; |
| 196 for (Frame* frame = culpritFrame; frame != observerFrame; | 198 for (Frame* frame = culpritFrame; frame != observerFrame; |
| 197 frame = frame->tree().parent()) { | 199 frame = frame->tree().parent()) { |
| 198 if (!canAccessOrigin(observerFrame, frame)) { | 200 if (!canAccessOrigin(observerFrame, frame)) { |
| 199 lastCrossOriginFrame = frame; | 201 lastCrossOriginFrame = frame; |
| 200 } | 202 } |
| 201 } | 203 } |
| 202 return std::make_pair(kDescendantAttribution, | 204 return std::make_pair(kDescendantAttribution, |
| 203 lastCrossOriginFrame->domWindow()); | 205 lastCrossOriginFrame->domWindow()); |
| 204 } | 206 } |
| 205 if (observerFrame->tree().isDescendantOf(culpritFrame)) { | 207 if (observerFrame->tree().isDescendantOf(culpritFrame)) { |
| 206 return std::make_pair(kAncestorAttribution, nullptr); | 208 return std::make_pair(kAncestorAttribution, nullptr); |
| 207 } | 209 } |
| 208 return std::make_pair(kCrossOriginAttribution, nullptr); | 210 return std::make_pair(kCrossOriginAttribution, nullptr); |
| 209 } | 211 } |
| 210 | 212 |
| 211 void Performance::reportLongTask( | 213 void Performance::reportLongTask(double startTime, |
| 212 double startTime, | 214 double endTime, |
| 213 double endTime, | 215 ExecutionContext* taskContext, |
| 214 const HeapHashSet<Member<Frame>>& contextFrames) { | 216 bool hasMultipleContexts) { |
| 215 std::pair<String, DOMWindow*> attribution = | 217 std::pair<String, DOMWindow*> attribution = Performance::sanitizedAttribution( |
| 216 Performance::sanitizedAttribution(contextFrames, frame()); | 218 taskContext, hasMultipleContexts, frame()); |
| 217 DOMWindow* culpritDomWindow = attribution.second; | 219 DOMWindow* culpritDomWindow = attribution.second; |
| 218 if (!culpritDomWindow || !culpritDomWindow->document() || | 220 if (!culpritDomWindow || !culpritDomWindow->document() || |
| 219 !culpritDomWindow->document()->localOwner()) { | 221 !culpritDomWindow->document()->localOwner()) { |
| 220 addLongTaskTiming(startTime, endTime, attribution.first, "", "", ""); | 222 addLongTaskTiming(startTime, endTime, attribution.first, "", "", ""); |
| 221 } else { | 223 } else { |
| 222 HTMLFrameOwnerElement* frameOwner = | 224 HTMLFrameOwnerElement* frameOwner = |
| 223 culpritDomWindow->document()->localOwner(); | 225 culpritDomWindow->document()->localOwner(); |
| 224 addLongTaskTiming(startTime, endTime, attribution.first, | 226 addLongTaskTiming(startTime, endTime, attribution.first, |
| 225 getFrameAttribute(frameOwner, HTMLNames::srcAttr, false), | 227 getFrameAttribute(frameOwner, HTMLNames::srcAttr, false), |
| 226 getFrameAttribute(frameOwner, HTMLNames::idAttr, false), | 228 getFrameAttribute(frameOwner, HTMLNames::idAttr, false), |
| 227 getFrameAttribute(frameOwner, HTMLNames::nameAttr, true)); | 229 getFrameAttribute(frameOwner, HTMLNames::nameAttr, true)); |
| 228 } | 230 } |
| 229 } | 231 } |
| 230 | 232 |
| 231 } // namespace blink | 233 } // namespace blink |
| OLD | NEW |