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

Side by Side Diff: Source/core/css/FontFaceSet.cpp

Issue 1233173002: Have ScriptPromiseResolver on the Oilpan heap always. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: fix webusb ScriptPromiseResolver usage Created 5 years, 4 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
« no previous file with comments | « Source/core/css/FontFaceSet.h ('k') | Source/core/imagebitmap/ImageBitmapFactories.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met: 5 * modification, are permitted provided that the following conditions are met:
6 * 6 *
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 : m_numLoading(faces.size()) 68 : m_numLoading(faces.size())
69 , m_errorOccured(false) 69 , m_errorOccured(false)
70 , m_resolver(ScriptPromiseResolver::create(scriptState)) 70 , m_resolver(ScriptPromiseResolver::create(scriptState))
71 { 71 {
72 m_fontFaces.swap(faces); 72 m_fontFaces.swap(faces);
73 } 73 }
74 74
75 WillBeHeapVector<RefPtrWillBeMember<FontFace>> m_fontFaces; 75 WillBeHeapVector<RefPtrWillBeMember<FontFace>> m_fontFaces;
76 int m_numLoading; 76 int m_numLoading;
77 bool m_errorOccured; 77 bool m_errorOccured;
78 RefPtrWillBeMember<ScriptPromiseResolver> m_resolver; 78 PersistentWillBeMember<ScriptPromiseResolver> m_resolver;
79 }; 79 };
80 80
81 void LoadFontPromiseResolver::loadFonts(ExecutionContext* context) 81 void LoadFontPromiseResolver::loadFonts(ExecutionContext* context)
82 { 82 {
83 if (!m_numLoading) { 83 if (!m_numLoading) {
84 m_resolver->resolve(m_fontFaces); 84 m_resolver->resolve(m_fontFaces);
85 return; 85 return;
86 } 86 }
87 87
88 for (size_t i = 0; i < m_fontFaces.size(); i++) 88 for (size_t i = 0; i < m_fontFaces.size(); i++)
(...skipping 18 matching lines...) Expand all
107 } 107 }
108 } 108 }
109 109
110 DEFINE_TRACE(LoadFontPromiseResolver) 110 DEFINE_TRACE(LoadFontPromiseResolver)
111 { 111 {
112 visitor->trace(m_fontFaces); 112 visitor->trace(m_fontFaces);
113 visitor->trace(m_resolver); 113 visitor->trace(m_resolver);
114 LoadFontCallback::trace(visitor); 114 LoadFontCallback::trace(visitor);
115 } 115 }
116 116
117 class FontsReadyPromiseResolver final : public NoBaseWillBeGarbageCollected<Font sReadyPromiseResolver> { 117 class FontsReadyPromiseResolver final : public GarbageCollected<FontsReadyPromis eResolver> {
118 public: 118 public:
119 static PassOwnPtrWillBeRawPtr<FontsReadyPromiseResolver> create(ScriptState* scriptState) 119 static FontsReadyPromiseResolver* create(ScriptState* scriptState)
120 { 120 {
121 return adoptPtrWillBeNoop(new FontsReadyPromiseResolver(scriptState)); 121 return new FontsReadyPromiseResolver(scriptState);
122 } 122 }
123 123
124 void resolve(PassRefPtrWillBeRawPtr<FontFaceSet> fontFaceSet) 124 void resolve(PassRefPtrWillBeRawPtr<FontFaceSet> fontFaceSet)
125 { 125 {
126 m_resolver->resolve(fontFaceSet); 126 m_resolver->resolve(fontFaceSet);
127 } 127 }
128 128
129 ScriptPromise promise() { return m_resolver->promise(); } 129 ScriptPromise promise() { return m_resolver->promise(); }
130 130
131 DEFINE_INLINE_TRACE() 131 DEFINE_INLINE_TRACE()
132 { 132 {
133 visitor->trace(m_resolver); 133 visitor->trace(m_resolver);
134 } 134 }
135 135
136 private: 136 private:
137 explicit FontsReadyPromiseResolver(ScriptState* scriptState) 137 explicit FontsReadyPromiseResolver(ScriptState* scriptState)
138 : m_resolver(ScriptPromiseResolver::create(scriptState)) 138 : m_resolver(ScriptPromiseResolver::create(scriptState))
139 { 139 {
140 } 140 }
141 141
142 RefPtrWillBeMember<ScriptPromiseResolver> m_resolver; 142 Member<ScriptPromiseResolver> m_resolver;
143 }; 143 };
144 144
145 FontFaceSet::FontFaceSet(Document& document) 145 FontFaceSet::FontFaceSet(Document& document)
146 : ActiveDOMObject(&document) 146 : ActiveDOMObject(&document)
147 , m_shouldFireLoadingEvent(false) 147 , m_shouldFireLoadingEvent(false)
148 , m_isLoading(false) 148 , m_isLoading(false)
149 , m_asyncRunner(this, &FontFaceSet::handlePendingEventsAndPromises) 149 , m_asyncRunner(this, &FontFaceSet::handlePendingEventsAndPromises)
150 { 150 {
151 suspendIfNeeded(); 151 suspendIfNeeded();
152 } 152 }
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 { 267 {
268 m_loadingFonts.remove(fontFace); 268 m_loadingFonts.remove(fontFace);
269 if (m_loadingFonts.isEmpty()) 269 if (m_loadingFonts.isEmpty())
270 handlePendingEventsAndPromisesSoon(); 270 handlePendingEventsAndPromisesSoon();
271 } 271 }
272 272
273 ScriptPromise FontFaceSet::ready(ScriptState* scriptState) 273 ScriptPromise FontFaceSet::ready(ScriptState* scriptState)
274 { 274 {
275 if (!inActiveDocumentContext()) 275 if (!inActiveDocumentContext())
276 return ScriptPromise(); 276 return ScriptPromise();
277 OwnPtrWillBeRawPtr<FontsReadyPromiseResolver> resolver = FontsReadyPromiseRe solver::create(scriptState); 277 FontsReadyPromiseResolver* resolver = FontsReadyPromiseResolver::create(scri ptState);
278 ScriptPromise promise = resolver->promise(); 278 ScriptPromise promise = resolver->promise();
279 m_readyResolvers.append(resolver.release()); 279 m_readyResolvers.append(resolver);
280 handlePendingEventsAndPromisesSoon(); 280 handlePendingEventsAndPromisesSoon();
281 return promise; 281 return promise;
282 } 282 }
283 283
284 void FontFaceSet::add(FontFace* fontFace, ExceptionState& exceptionState) 284 void FontFaceSet::add(FontFace* fontFace, ExceptionState& exceptionState)
285 { 285 {
286 if (!inActiveDocumentContext()) 286 if (!inActiveDocumentContext())
287 return; 287 return;
288 if (!fontFace) { 288 if (!fontFace) {
289 exceptionState.throwTypeError("The argument is not a FontFace."); 289 exceptionState.throwTypeError("The argument is not a FontFace.");
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 errorEvent = FontFaceSetLoadEvent::createForFontFaces(EventTypeNames ::loadingerror, m_failedFonts); 425 errorEvent = FontFaceSetLoadEvent::createForFontFaces(EventTypeNames ::loadingerror, m_failedFonts);
426 m_failedFonts.clear(); 426 m_failedFonts.clear();
427 } 427 }
428 m_isLoading = false; 428 m_isLoading = false;
429 dispatchEvent(doneEvent); 429 dispatchEvent(doneEvent);
430 if (errorEvent) 430 if (errorEvent)
431 dispatchEvent(errorEvent); 431 dispatchEvent(errorEvent);
432 } 432 }
433 433
434 if (!m_readyResolvers.isEmpty()) { 434 if (!m_readyResolvers.isEmpty()) {
435 WillBeHeapVector<OwnPtrWillBeMember<FontsReadyPromiseResolver>> resolver s; 435 HeapVector<Member<FontsReadyPromiseResolver>> resolvers;
436 m_readyResolvers.swap(resolvers); 436 m_readyResolvers.swap(resolvers);
437 for (size_t index = 0; index < resolvers.size(); ++index) 437 for (size_t index = 0; index < resolvers.size(); ++index)
438 resolvers[index]->resolve(this); 438 resolvers[index]->resolve(this);
439 } 439 }
440 } 440 }
441 441
442 ScriptPromise FontFaceSet::load(ScriptState* scriptState, const String& fontStri ng, const String& text) 442 ScriptPromise FontFaceSet::load(ScriptState* scriptState, const String& fontStri ng, const String& text)
443 { 443 {
444 if (!inActiveDocumentContext()) 444 if (!inActiveDocumentContext())
445 return ScriptPromise(); 445 return ScriptPromise();
446 446
447 Font font; 447 Font font;
448 if (!resolveFontStyle(fontString, font)) { 448 if (!resolveFontStyle(fontString, font)) {
449 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolv er::create(scriptState); 449 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptSt ate);
450 ScriptPromise promise = resolver->promise(); 450 ScriptPromise promise = resolver->promise();
451 resolver->reject(DOMException::create(SyntaxError, "Could not resolve '" + fontString + "' as a font.")); 451 resolver->reject(DOMException::create(SyntaxError, "Could not resolve '" + fontString + "' as a font."));
452 return promise; 452 return promise;
453 } 453 }
454 454
455 FontFaceCache* fontFaceCache = document()->styleEngine().fontSelector()->fon tFaceCache(); 455 FontFaceCache* fontFaceCache = document()->styleEngine().fontSelector()->fon tFaceCache();
456 FontFaceArray faces; 456 FontFaceArray faces;
457 for (const FontFamily* f = &font.fontDescription().family(); f; f = f->next( )) { 457 for (const FontFamily* f = &font.fontDescription().family(); f; f = f->next( )) {
458 CSSSegmentedFontFace* segmentedFontFace = fontFaceCache->get(font.fontDe scription(), f->family()); 458 CSSSegmentedFontFace* segmentedFontFace = fontFaceCache->get(font.fontDe scription(), f->family());
459 if (segmentedFontFace) 459 if (segmentedFontFace)
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
580 } 580 }
581 581
582 DEFINE_TRACE(FontFaceSet) 582 DEFINE_TRACE(FontFaceSet)
583 { 583 {
584 #if ENABLE(OILPAN) 584 #if ENABLE(OILPAN)
585 visitor->trace(m_loadingFonts); 585 visitor->trace(m_loadingFonts);
586 visitor->trace(m_readyResolvers); 586 visitor->trace(m_readyResolvers);
587 visitor->trace(m_loadedFonts); 587 visitor->trace(m_loadedFonts);
588 visitor->trace(m_failedFonts); 588 visitor->trace(m_failedFonts);
589 visitor->trace(m_nonCSSConnectedFaces); 589 visitor->trace(m_nonCSSConnectedFaces);
590 WillBeHeapSupplement<Document>::trace(visitor); 590 HeapSupplement<Document>::trace(visitor);
591 #endif 591 #endif
592 EventTargetWithInlineData::trace(visitor); 592 EventTargetWithInlineData::trace(visitor);
593 ActiveDOMObject::trace(visitor); 593 ActiveDOMObject::trace(visitor);
594 } 594 }
595 595
596 } // namespace blink 596 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/css/FontFaceSet.h ('k') | Source/core/imagebitmap/ImageBitmapFactories.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698