Chromium Code Reviews| 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 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 |
| 353 if (m_status == Loaded || m_status == Error) { | 355 if (m_status == Loaded || m_status == Error) { |
| 354 if (m_loadedProperty) { | 356 if (m_loadedProperty) { |
| 355 if (m_status == Loaded) | 357 if (m_status == Loaded) { |
|
jbroman
2017/01/12 18:40:46
Would you mind adding a comment explaining why thi
adithyas
2017/01/13 16:08:39
Added a comment.
| |
| 356 m_loadedProperty->resolve(this); | 358 getTaskRunner()->postTask( |
| 357 else | 359 BLINK_FROM_HERE, WTF::bind(&LoadedProperty::resolve<FontFace*>, |
| 360 wrapPersistent(m_loadedProperty.get()), | |
| 361 wrapPersistent(this))); | |
| 362 } else | |
| 358 m_loadedProperty->reject(m_error.get()); | 363 m_loadedProperty->reject(m_error.get()); |
| 359 } | 364 } |
| 360 | 365 |
| 361 HeapVector<Member<LoadFontCallback>> callbacks; | 366 getTaskRunner()->postTask( |
| 362 m_callbacks.swap(callbacks); | 367 BLINK_FROM_HERE, |
| 363 for (size_t i = 0; i < callbacks.size(); ++i) { | 368 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 } | 369 } |
| 370 } | 370 } |
| 371 | 371 |
| 372 WebTaskRunner* FontFace::getTaskRunner() { | |
| 373 return TaskRunnerHelper::get(TaskType::DOMManipulation, getExecutionContext()) | |
| 374 .get(); | |
| 375 } | |
| 376 | |
| 377 void FontFace::runCallbacks() { | |
| 378 HeapVector<Member<LoadFontCallback>> callbacks; | |
| 379 m_callbacks.swap(callbacks); | |
| 380 for (size_t i = 0; i < callbacks.size(); ++i) { | |
| 381 if (m_status == Loaded) | |
| 382 callbacks[i]->notifyLoaded(this); | |
| 383 else | |
| 384 callbacks[i]->notifyError(this); | |
| 385 } | |
| 386 } | |
| 387 | |
| 372 void FontFace::setError(DOMException* error) { | 388 void FontFace::setError(DOMException* error) { |
| 373 if (!m_error) | 389 if (!m_error) |
| 374 m_error = error ? error : DOMException::create(NetworkError); | 390 m_error = error ? error : DOMException::create(NetworkError); |
| 375 setLoadStatus(Error); | 391 setLoadStatus(Error); |
| 376 } | 392 } |
| 377 | 393 |
| 378 ScriptPromise FontFace::fontStatusPromise(ScriptState* scriptState) { | 394 ScriptPromise FontFace::fontStatusPromise(ScriptState* scriptState) { |
| 379 if (!m_loadedProperty) { | 395 if (!m_loadedProperty) { |
| 380 m_loadedProperty = new LoadedProperty(scriptState->getExecutionContext(), | 396 m_loadedProperty = new LoadedProperty(scriptState->getExecutionContext(), |
| 381 this, LoadedProperty::Loaded); | 397 this, LoadedProperty::Loaded); |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 640 | 656 |
| 641 bool FontFace::hadBlankText() const { | 657 bool FontFace::hadBlankText() const { |
| 642 return m_cssFontFace->hadBlankText(); | 658 return m_cssFontFace->hadBlankText(); |
| 643 } | 659 } |
| 644 | 660 |
| 645 bool FontFace::hasPendingActivity() const { | 661 bool FontFace::hasPendingActivity() const { |
| 646 return m_status == Loading && getExecutionContext(); | 662 return m_status == Loading && getExecutionContext(); |
| 647 } | 663 } |
| 648 | 664 |
| 649 } // namespace blink | 665 } // namespace blink |
| OLD | NEW |