OLD | NEW |
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 | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 #include "core/css/RemoteFontFaceSource.h" | 47 #include "core/css/RemoteFontFaceSource.h" |
48 #include "core/css/StylePropertySet.h" | 48 #include "core/css/StylePropertySet.h" |
49 #include "core/css/StyleRule.h" | 49 #include "core/css/StyleRule.h" |
50 #include "core/css/parser/CSSParser.h" | 50 #include "core/css/parser/CSSParser.h" |
51 #include "core/dom/DOMArrayBuffer.h" | 51 #include "core/dom/DOMArrayBuffer.h" |
52 #include "core/dom/DOMArrayBufferView.h" | 52 #include "core/dom/DOMArrayBufferView.h" |
53 #include "core/dom/DOMException.h" | 53 #include "core/dom/DOMException.h" |
54 #include "core/dom/Document.h" | 54 #include "core/dom/Document.h" |
55 #include "core/dom/ExceptionCode.h" | 55 #include "core/dom/ExceptionCode.h" |
56 #include "core/dom/StyleEngine.h" | 56 #include "core/dom/StyleEngine.h" |
| 57 #include "core/dom/TaskRunnerHelper.h" |
57 #include "core/frame/LocalFrame.h" | 58 #include "core/frame/LocalFrame.h" |
58 #include "core/frame/Settings.h" | 59 #include "core/frame/Settings.h" |
59 #include "core/frame/UseCounter.h" | 60 #include "core/frame/UseCounter.h" |
60 #include "platform/FontFamilyNames.h" | 61 #include "platform/FontFamilyNames.h" |
61 #include "platform/Histogram.h" | 62 #include "platform/Histogram.h" |
62 #include "platform/SharedBuffer.h" | 63 #include "platform/SharedBuffer.h" |
| 64 #include "platform/WebTaskRunner.h" |
63 | 65 |
64 namespace blink { | 66 namespace blink { |
65 | 67 |
66 static const CSSValue* parseCSSValue(const Document* document, | 68 static const CSSValue* parseCSSValue(const Document* document, |
67 const String& value, | 69 const String& value, |
68 CSSPropertyID propertyID) { | 70 CSSPropertyID propertyID) { |
69 CSSParserContext context(*document, UseCounter::getFrom(document)); | 71 CSSParserContext context(*document, UseCounter::getFrom(document)); |
70 return CSSParser::parseFontFaceDescriptor(propertyID, value, context); | 72 return CSSParser::parseFontFaceDescriptor(propertyID, value, context); |
71 } | 73 } |
72 | 74 |
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 default: | 345 default: |
344 NOTREACHED(); | 346 NOTREACHED(); |
345 } | 347 } |
346 return emptyString(); | 348 return emptyString(); |
347 } | 349 } |
348 | 350 |
349 void FontFace::setLoadStatus(LoadStatusType status) { | 351 void FontFace::setLoadStatus(LoadStatusType status) { |
350 m_status = status; | 352 m_status = status; |
351 ASSERT(m_status != Error || m_error); | 353 ASSERT(m_status != Error || m_error); |
352 | 354 |
| 355 // When promises are resolved with 'thenables', instead of the object being |
| 356 // returned directly, the 'then' method is executed (the resolver tries to |
| 357 // resolve the thenable). This can lead to synchronous script execution, so we |
| 358 // post a task. This does not apply to promise rejection (i.e. a thenable |
| 359 // would be returned as is). |
353 if (m_status == Loaded || m_status == Error) { | 360 if (m_status == Loaded || m_status == Error) { |
354 if (m_loadedProperty) { | 361 if (m_loadedProperty) { |
355 if (m_status == Loaded) | 362 if (m_status == Loaded) { |
356 m_loadedProperty->resolve(this); | 363 getTaskRunner()->postTask( |
357 else | 364 BLINK_FROM_HERE, WTF::bind(&LoadedProperty::resolve<FontFace*>, |
| 365 wrapPersistent(m_loadedProperty.get()), |
| 366 wrapPersistent(this))); |
| 367 } else |
358 m_loadedProperty->reject(m_error.get()); | 368 m_loadedProperty->reject(m_error.get()); |
359 } | 369 } |
360 | 370 |
361 HeapVector<Member<LoadFontCallback>> callbacks; | 371 getTaskRunner()->postTask( |
362 m_callbacks.swap(callbacks); | 372 BLINK_FROM_HERE, |
363 for (size_t i = 0; i < callbacks.size(); ++i) { | 373 WTF::bind(&FontFace::runCallbacks, wrapPersistent(this))); |
364 if (m_status == Loaded) | |
365 callbacks[i]->notifyLoaded(this); | |
366 else | |
367 callbacks[i]->notifyError(this); | |
368 } | |
369 } | 374 } |
370 } | 375 } |
371 | 376 |
| 377 WebTaskRunner* FontFace::getTaskRunner() { |
| 378 return TaskRunnerHelper::get(TaskType::DOMManipulation, getExecutionContext()) |
| 379 .get(); |
| 380 } |
| 381 |
| 382 void FontFace::runCallbacks() { |
| 383 HeapVector<Member<LoadFontCallback>> callbacks; |
| 384 m_callbacks.swap(callbacks); |
| 385 for (size_t i = 0; i < callbacks.size(); ++i) { |
| 386 if (m_status == Loaded) |
| 387 callbacks[i]->notifyLoaded(this); |
| 388 else |
| 389 callbacks[i]->notifyError(this); |
| 390 } |
| 391 } |
| 392 |
372 void FontFace::setError(DOMException* error) { | 393 void FontFace::setError(DOMException* error) { |
373 if (!m_error) | 394 if (!m_error) |
374 m_error = error ? error : DOMException::create(NetworkError); | 395 m_error = error ? error : DOMException::create(NetworkError); |
375 setLoadStatus(Error); | 396 setLoadStatus(Error); |
376 } | 397 } |
377 | 398 |
378 ScriptPromise FontFace::fontStatusPromise(ScriptState* scriptState) { | 399 ScriptPromise FontFace::fontStatusPromise(ScriptState* scriptState) { |
379 if (!m_loadedProperty) { | 400 if (!m_loadedProperty) { |
380 m_loadedProperty = new LoadedProperty(scriptState->getExecutionContext(), | 401 m_loadedProperty = new LoadedProperty(scriptState->getExecutionContext(), |
381 this, LoadedProperty::Loaded); | 402 this, LoadedProperty::Loaded); |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
634 | 655 |
635 bool FontFace::hadBlankText() const { | 656 bool FontFace::hadBlankText() const { |
636 return m_cssFontFace->hadBlankText(); | 657 return m_cssFontFace->hadBlankText(); |
637 } | 658 } |
638 | 659 |
639 bool FontFace::hasPendingActivity() const { | 660 bool FontFace::hasPendingActivity() const { |
640 return m_status == Loading && getExecutionContext(); | 661 return m_status == Loading && getExecutionContext(); |
641 } | 662 } |
642 | 663 |
643 } // namespace blink | 664 } // namespace blink |
OLD | NEW |