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

Side by Side Diff: third_party/WebKit/Source/core/timing/Performance.cpp

Issue 2515993002: Replace DOMWindow with iframe attrs: src, id, name (Closed)
Patch Set: move getattribute to helper method 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 /* 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 16 matching lines...) Expand all
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32 #include "core/timing/Performance.h" 32 #include "core/timing/Performance.h"
33 33
34 #include "bindings/core/v8/ScriptValue.h" 34 #include "bindings/core/v8/ScriptValue.h"
35 #include "bindings/core/v8/V8ObjectBuilder.h" 35 #include "bindings/core/v8/V8ObjectBuilder.h"
36 #include "core/dom/Document.h" 36 #include "core/dom/Document.h"
37 #include "core/dom/QualifiedName.h"
38 #include "core/frame/DOMWindow.h"
37 #include "core/frame/LocalFrame.h" 39 #include "core/frame/LocalFrame.h"
38 #include "core/frame/UseCounter.h" 40 #include "core/frame/UseCounter.h"
41 #include "core/html/HTMLFrameOwnerElement.h"
39 #include "core/loader/DocumentLoader.h" 42 #include "core/loader/DocumentLoader.h"
40 #include "core/origin_trials/OriginTrials.h" 43 #include "core/origin_trials/OriginTrials.h"
41 #include "core/timing/PerformanceTiming.h" 44 #include "core/timing/PerformanceTiming.h"
42 45
46 #include <tuple>
47
43 static const double kLongTaskThreshold = 0.05; 48 static const double kLongTaskThreshold = 0.05;
44 49
45 static const char kUnknownAttribution[] = "unknown"; 50 static const char kUnknownAttribution[] = "unknown";
46 static const char kAmbugiousAttribution[] = "multiple-contexts"; 51 static const char kAmbugiousAttribution[] = "multiple-contexts";
47 static const char kSameOriginAttribution[] = "same-origin"; 52 static const char kSameOriginAttribution[] = "same-origin";
48 static const char kAncestorAttribution[] = "cross-origin-ancestor"; 53 static const char kAncestorAttribution[] = "cross-origin-ancestor";
49 static const char kDescendantAttribution[] = "cross-origin-descendant"; 54 static const char kDescendantAttribution[] = "cross-origin-descendant";
50 static const char kCrossOriginAttribution[] = "cross-origin-unreachable"; 55 static const char kCrossOriginAttribution[] = "cross-origin-unreachable";
51 56
52 namespace blink { 57 namespace blink {
53 58
59 namespace {
60
61 String getFrameAttribute(HTMLFrameOwnerElement* frameOwner,
62 const QualifiedName& attrName,
63 bool truncate) {
64 String attrValue;
65 if (frameOwner->hasAttribute(attrName)) {
66 attrValue = frameOwner->getAttribute(attrName);
67 if (truncate && attrValue.length() > 100)
68 attrValue = attrValue.substring(0, 100); // Truncate to 100 chars
69 }
70 return attrValue;
71 }
72
73 } // namespace
74
54 static double toTimeOrigin(LocalFrame* frame) { 75 static double toTimeOrigin(LocalFrame* frame) {
55 if (!frame) 76 if (!frame)
56 return 0.0; 77 return 0.0;
57 78
58 Document* document = frame->document(); 79 Document* document = frame->document();
59 if (!document) 80 if (!document)
60 return 0.0; 81 return 0.0;
61 82
62 DocumentLoader* loader = document->loader(); 83 DocumentLoader* loader = document->loader();
63 if (!loader) 84 if (!loader)
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 } 203 }
183 return std::make_pair(kDescendantAttribution, 204 return std::make_pair(kDescendantAttribution,
184 lastCrossOriginFrame->domWindow()); 205 lastCrossOriginFrame->domWindow());
185 } 206 }
186 if (observerFrame->tree().isDescendantOf(culpritFrame)) { 207 if (observerFrame->tree().isDescendantOf(culpritFrame)) {
187 return std::make_pair(kAncestorAttribution, nullptr); 208 return std::make_pair(kAncestorAttribution, nullptr);
188 } 209 }
189 return std::make_pair(kCrossOriginAttribution, nullptr); 210 return std::make_pair(kCrossOriginAttribution, nullptr);
190 } 211 }
191 212
213 std::tuple<String, String, String> Performance::culpritFrameAttributes(
skobes 2016/11/22 00:21:25 It seems unnecessary to wrap these in a std::tuple
panicker 2016/11/22 00:39:47 Agreed. Done.
214 HTMLFrameOwnerElement* frameOwner) {
215 return std::make_tuple(
216 getFrameAttribute(frameOwner, HTMLNames::srcAttr, false),
217 getFrameAttribute(frameOwner, HTMLNames::idAttr, true),
218 getFrameAttribute(frameOwner, HTMLNames::nameAttr, true));
219 }
220
192 void Performance::reportLongTask( 221 void Performance::reportLongTask(
193 double startTime, 222 double startTime,
194 double endTime, 223 double endTime,
195 const HeapHashSet<Member<Frame>>& contextFrames) { 224 const HeapHashSet<Member<Frame>>& contextFrames) {
196 std::pair<String, DOMWindow*> attribution = 225 std::pair<String, DOMWindow*> attribution =
197 Performance::sanitizedAttribution(contextFrames, frame()); 226 Performance::sanitizedAttribution(contextFrames, frame());
198 addLongTaskTiming(startTime, endTime, attribution.first, attribution.second); 227 DOMWindow* culpritDomWindow = attribution.second;
228 if (!culpritDomWindow || !culpritDomWindow->document() ||
229 !culpritDomWindow->document()->localOwner()) {
230 addLongTaskTiming(startTime, endTime, attribution.first, "", "", "");
231 } else {
232 std::tuple<String, String, String> frameAttribution =
233 culpritFrameAttributes(culpritDomWindow->document()->localOwner());
234 addLongTaskTiming(
235 startTime, endTime, attribution.first, std::get<0>(frameAttribution),
236 std::get<1>(frameAttribution), std::get<2>(frameAttribution));
237 }
199 } 238 }
200 239
201 } // namespace blink 240 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/timing/Performance.h ('k') | third_party/WebKit/Source/core/timing/PerformanceBase.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698