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

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

Issue 1857713004: DevTools: simplify the async instrumentation harness. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * Copyright (C) 2004, 2005, 2006, 2007, 2009, 2010 Apple Inc. All rights reserv ed. 4 * Copyright (C) 2004, 2005, 2006, 2007, 2009, 2010 Apple Inc. All rights reserv ed.
5 * 5 *
6 * This library is free software; you can redistribute it and/or 6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public 7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either 8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version. 9 * version 2 of the License, or (at your option) any later version.
10 * 10 *
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 } 86 }
87 87
88 Task(ImageLoader* loader, UpdateFromElementBehavior updateBehavior, Referrer Policy referrerPolicy) 88 Task(ImageLoader* loader, UpdateFromElementBehavior updateBehavior, Referrer Policy referrerPolicy)
89 : m_loader(loader) 89 : m_loader(loader)
90 , m_shouldBypassMainWorldCSP(shouldBypassMainWorldCSP(loader)) 90 , m_shouldBypassMainWorldCSP(shouldBypassMainWorldCSP(loader))
91 , m_updateBehavior(updateBehavior) 91 , m_updateBehavior(updateBehavior)
92 , m_weakFactory(this) 92 , m_weakFactory(this)
93 , m_referrerPolicy(referrerPolicy) 93 , m_referrerPolicy(referrerPolicy)
94 { 94 {
95 ExecutionContext& context = m_loader->element()->document(); 95 ExecutionContext& context = m_loader->element()->document();
96 m_operationId = InspectorInstrumentation::traceAsyncOperationStarting(&c ontext, "Load image"); 96 InspectorInstrumentation::asyncTaskScheduled(&context, "Image", this);
97 v8::Isolate* isolate = V8PerIsolateData::mainThreadIsolate(); 97 v8::Isolate* isolate = V8PerIsolateData::mainThreadIsolate();
98 v8::HandleScope scope(isolate); 98 v8::HandleScope scope(isolate);
99 // If we're invoked from C++ without a V8 context on the stack, we shoul d 99 // If we're invoked from C++ without a V8 context on the stack, we shoul d
100 // run the microtask in the context of the element's document's main wor ld. 100 // run the microtask in the context of the element's document's main wor ld.
101 if (ScriptState::hasCurrentScriptState(isolate)) { 101 if (ScriptState::hasCurrentScriptState(isolate)) {
102 m_scriptState = ScriptState::current(isolate); 102 m_scriptState = ScriptState::current(isolate);
103 } else { 103 } else {
104 m_scriptState = ScriptState::forMainWorld(loader->element()->documen t().frame()); 104 m_scriptState = ScriptState::forMainWorld(loader->element()->documen t().frame());
105 ASSERT(m_scriptState); 105 ASSERT(m_scriptState);
106 } 106 }
107 } 107 }
108 108
109 ~Task() override 109 ~Task() override
110 { 110 {
111 } 111 }
112 112
113 void run() override 113 void run() override
114 { 114 {
115 if (!m_loader) 115 if (!m_loader)
116 return; 116 return;
117 ExecutionContext& context = m_loader->element()->document(); 117 ExecutionContext& context = m_loader->element()->document();
118 InspectorInstrumentationCookie cookie = InspectorInstrumentation::traceA syncOperationCompletedCallbackStarting(&context, m_operationId); 118 InspectorInstrumentation::AsyncTask asyncTask(&context, this);
119 if (m_scriptState->contextIsValid()) { 119 if (m_scriptState->contextIsValid()) {
120 ScriptState::Scope scope(m_scriptState.get()); 120 ScriptState::Scope scope(m_scriptState.get());
121 m_loader->doUpdateFromElement(m_shouldBypassMainWorldCSP, m_updateBe havior, m_referrerPolicy); 121 m_loader->doUpdateFromElement(m_shouldBypassMainWorldCSP, m_updateBe havior, m_referrerPolicy);
122 } else { 122 } else {
123 m_loader->doUpdateFromElement(m_shouldBypassMainWorldCSP, m_updateBe havior, m_referrerPolicy); 123 m_loader->doUpdateFromElement(m_shouldBypassMainWorldCSP, m_updateBe havior, m_referrerPolicy);
124 } 124 }
125 InspectorInstrumentation::traceAsyncCallbackCompleted(cookie);
126 } 125 }
127 126
128 void clearLoader() 127 void clearLoader()
129 { 128 {
130 m_loader = nullptr; 129 m_loader = nullptr;
131 m_scriptState.clear(); 130 m_scriptState.clear();
132 } 131 }
133 132
134 WeakPtr<Task> createWeakPtr() 133 WeakPtr<Task> createWeakPtr()
135 { 134 {
136 return m_weakFactory.createWeakPtr(); 135 return m_weakFactory.createWeakPtr();
137 } 136 }
138 137
139 private: 138 private:
140 WeakPersistent<ImageLoader> m_loader; 139 WeakPersistent<ImageLoader> m_loader;
141 BypassMainWorldBehavior m_shouldBypassMainWorldCSP; 140 BypassMainWorldBehavior m_shouldBypassMainWorldCSP;
142 UpdateFromElementBehavior m_updateBehavior; 141 UpdateFromElementBehavior m_updateBehavior;
143 RefPtr<ScriptState> m_scriptState; 142 RefPtr<ScriptState> m_scriptState;
144 WeakPtrFactory<Task> m_weakFactory; 143 WeakPtrFactory<Task> m_weakFactory;
145 ReferrerPolicy m_referrerPolicy; 144 ReferrerPolicy m_referrerPolicy;
146 int m_operationId;
147 }; 145 };
148 146
149 ImageLoader::ImageLoader(Element* element) 147 ImageLoader::ImageLoader(Element* element)
150 : m_element(element) 148 : m_element(element)
151 , m_derefElementTimer(this, &ImageLoader::timerFired) 149 , m_derefElementTimer(this, &ImageLoader::timerFired)
152 , m_hasPendingLoadEvent(false) 150 , m_hasPendingLoadEvent(false)
153 , m_hasPendingErrorEvent(false) 151 , m_hasPendingErrorEvent(false)
154 , m_imageComplete(true) 152 , m_imageComplete(true)
155 , m_loadingImageDocument(false) 153 , m_loadingImageDocument(false)
156 , m_elementIsProtected(false) 154 , m_elementIsProtected(false)
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after
615 613
616 void ImageLoader::elementDidMoveToNewDocument() 614 void ImageLoader::elementDidMoveToNewDocument()
617 { 615 {
618 if (m_loadDelayCounter) 616 if (m_loadDelayCounter)
619 m_loadDelayCounter->documentChanged(m_element->document()); 617 m_loadDelayCounter->documentChanged(m_element->document());
620 clearFailedLoadURL(); 618 clearFailedLoadURL();
621 setImage(0); 619 setImage(0);
622 } 620 }
623 621
624 } // namespace blink 622 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698