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

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

Issue 273683006: ScriptPromise should understand the ScriptState from which the ScriptPromise is generated (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 7 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 | Annotate | Revision Log
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 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 } 108 }
109 109
110 void LoadFontPromiseResolver::trace(Visitor* visitor) 110 void LoadFontPromiseResolver::trace(Visitor* visitor)
111 { 111 {
112 visitor->trace(m_fontFaces); 112 visitor->trace(m_fontFaces);
113 LoadFontCallback::trace(visitor); 113 LoadFontCallback::trace(visitor);
114 } 114 }
115 115
116 class FontsReadyPromiseResolver { 116 class FontsReadyPromiseResolver {
117 public: 117 public:
118 static PassOwnPtr<FontsReadyPromiseResolver> create(ExecutionContext* contex t) 118 static PassOwnPtr<FontsReadyPromiseResolver> create(ScriptState* scriptState )
119 { 119 {
120 return adoptPtr(new FontsReadyPromiseResolver(context)); 120 return adoptPtr(new FontsReadyPromiseResolver(scriptState));
121 } 121 }
122 122
123 void resolve(PassRefPtrWillBeRawPtr<FontFaceSet> fontFaceSet) 123 void resolve(PassRefPtrWillBeRawPtr<FontFaceSet> fontFaceSet)
124 { 124 {
125 m_resolver->resolve(fontFaceSet); 125 m_resolver->resolve(fontFaceSet);
126 } 126 }
127 127
128 ScriptPromise promise() { return m_resolver->promise(); } 128 ScriptPromise promise() { return m_resolver->promise(); }
129 129
130 private: 130 private:
131 FontsReadyPromiseResolver(ExecutionContext* context) 131 explicit FontsReadyPromiseResolver(ScriptState* scriptState)
132 : m_resolver(ScriptPromiseResolverWithContext::create(ScriptState::curre nt(toIsolate(context)))) 132 : m_resolver(ScriptPromiseResolverWithContext::create(scriptState))
133 { 133 {
134 } 134 }
135 135
136 RefPtr<ScriptPromiseResolverWithContext> m_resolver; 136 RefPtr<ScriptPromiseResolverWithContext> m_resolver;
137 }; 137 };
138 138
139 FontFaceSet::FontFaceSet(Document& document) 139 FontFaceSet::FontFaceSet(Document& document)
140 : ActiveDOMObject(&document) 140 : ActiveDOMObject(&document)
141 , m_shouldFireLoadingEvent(false) 141 , m_shouldFireLoadingEvent(false)
142 , m_asyncRunner(this, &FontFaceSet::handlePendingEventsAndPromises) 142 , m_asyncRunner(this, &FontFaceSet::handlePendingEventsAndPromises)
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 m_loadingFonts.add(fontFace); 260 m_loadingFonts.add(fontFace);
261 } 261 }
262 262
263 void FontFaceSet::removeFromLoadingFonts(PassRefPtrWillBeRawPtr<FontFace> fontFa ce) 263 void FontFaceSet::removeFromLoadingFonts(PassRefPtrWillBeRawPtr<FontFace> fontFa ce)
264 { 264 {
265 m_loadingFonts.remove(fontFace); 265 m_loadingFonts.remove(fontFace);
266 if (RuntimeEnabledFeatures::fontLoadEventsEnabled() && m_loadingFonts.isEmpt y()) 266 if (RuntimeEnabledFeatures::fontLoadEventsEnabled() && m_loadingFonts.isEmpt y())
267 handlePendingEventsAndPromisesSoon(); 267 handlePendingEventsAndPromisesSoon();
268 } 268 }
269 269
270 ScriptPromise FontFaceSet::ready() 270 ScriptPromise FontFaceSet::ready(ScriptState* scriptState)
271 { 271 {
272 if (!inActiveDocumentContext()) 272 if (!inActiveDocumentContext())
273 return ScriptPromise(); 273 return ScriptPromise();
274 OwnPtr<FontsReadyPromiseResolver> resolver = FontsReadyPromiseResolver::crea te(executionContext()); 274 OwnPtr<FontsReadyPromiseResolver> resolver = FontsReadyPromiseResolver::crea te(scriptState);
275 ScriptPromise promise = resolver->promise(); 275 ScriptPromise promise = resolver->promise();
276 m_readyResolvers.append(resolver.release()); 276 m_readyResolvers.append(resolver.release());
277 handlePendingEventsAndPromisesSoon(); 277 handlePendingEventsAndPromisesSoon();
278 return promise; 278 return promise;
279 } 279 }
280 280
281 void FontFaceSet::add(FontFace* fontFace, ExceptionState& exceptionState) 281 void FontFaceSet::add(FontFace* fontFace, ExceptionState& exceptionState)
282 { 282 {
283 if (!inActiveDocumentContext()) 283 if (!inActiveDocumentContext())
284 return; 284 return;
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 resolvers[index]->resolve(this); 429 resolvers[index]->resolve(this);
430 } 430 }
431 } 431 }
432 432
433 static const String& nullToSpace(const String& s) 433 static const String& nullToSpace(const String& s)
434 { 434 {
435 DEFINE_STATIC_LOCAL(String, space, (" ")); 435 DEFINE_STATIC_LOCAL(String, space, (" "));
436 return s.isNull() ? space : s; 436 return s.isNull() ? space : s;
437 } 437 }
438 438
439 ScriptPromise FontFaceSet::load(const String& fontString, const String& text) 439 ScriptPromise FontFaceSet::load(ScriptState* scriptState, const String& fontStri ng, const String& text)
440 { 440 {
441 if (!inActiveDocumentContext()) 441 if (!inActiveDocumentContext())
442 return ScriptPromise(); 442 return ScriptPromise();
443 443
444 Font font; 444 Font font;
445 if (!resolveFontStyle(fontString, font)) { 445 if (!resolveFontStyle(fontString, font)) {
446 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(e xecutionContext()); 446 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(s criptState);
447 ScriptPromise promise = resolver->promise(); 447 ScriptPromise promise = resolver->promise();
448 resolver->reject(DOMError::create(SyntaxError, "Could not resolve '" + f ontString + "' as a font.")); 448 resolver->reject(DOMError::create(SyntaxError, "Could not resolve '" + f ontString + "' as a font."));
449 return promise; 449 return promise;
450 } 450 }
451 451
452 FontFaceCache* fontFaceCache = document()->styleEngine()->fontSelector()->fo ntFaceCache(); 452 FontFaceCache* fontFaceCache = document()->styleEngine()->fontSelector()->fo ntFaceCache();
453 FontFaceArray faces; 453 FontFaceArray faces;
454 for (const FontFamily* f = &font.fontDescription().family(); f; f = f->next( )) { 454 for (const FontFamily* f = &font.fontDescription().family(); f; f = f->next( )) {
455 CSSSegmentedFontFace* segmentedFontFace = fontFaceCache->get(font.fontDe scription(), f->family()); 455 CSSSegmentedFontFace* segmentedFontFace = fontFaceCache->get(font.fontDe scription(), f->family());
456 if (segmentedFontFace) 456 if (segmentedFontFace)
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
578 { 578 {
579 visitor->trace(m_loadingFonts); 579 visitor->trace(m_loadingFonts);
580 visitor->trace(m_loadedFonts); 580 visitor->trace(m_loadedFonts);
581 visitor->trace(m_failedFonts); 581 visitor->trace(m_failedFonts);
582 visitor->trace(m_nonCSSConnectedFaces); 582 visitor->trace(m_nonCSSConnectedFaces);
583 DocumentSupplement::trace(visitor); 583 DocumentSupplement::trace(visitor);
584 } 584 }
585 #endif 585 #endif
586 586
587 } // namespace WebCore 587 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698