| 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 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 #include "core/page/FrameView.h" | 43 #include "core/page/FrameView.h" |
| 44 #include "core/platform/HistogramSupport.h" | 44 #include "core/platform/HistogramSupport.h" |
| 45 | 45 |
| 46 namespace WebCore { | 46 namespace WebCore { |
| 47 | 47 |
| 48 static const int defaultFontSize = 10; | 48 static const int defaultFontSize = 10; |
| 49 static const char* const defaultFontFamily = "sans-serif"; | 49 static const char* const defaultFontFamily = "sans-serif"; |
| 50 | 50 |
| 51 class LoadFontPromiseResolver : public CSSSegmentedFontFace::LoadFontCallback { | 51 class LoadFontPromiseResolver : public CSSSegmentedFontFace::LoadFontCallback { |
| 52 public: | 52 public: |
| 53 static PassRefPtr<LoadFontPromiseResolver> create(const FontFamily& family,
ScriptExecutionContext* context) | 53 static PassRefPtr<LoadFontPromiseResolver> create(const FontFamily& family,
ScriptPromise promise, ScriptExecutionContext* context) |
| 54 { | 54 { |
| 55 int numFamilies = 0; | 55 int numFamilies = 0; |
| 56 for (const FontFamily* f = &family; f; f = f->next()) | 56 for (const FontFamily* f = &family; f; f = f->next()) |
| 57 numFamilies++; | 57 numFamilies++; |
| 58 return adoptRef<LoadFontPromiseResolver>(new LoadFontPromiseResolver(num
Families, context)); | 58 return adoptRef<LoadFontPromiseResolver>(new LoadFontPromiseResolver(num
Families, promise, context)); |
| 59 } | 59 } |
| 60 | 60 |
| 61 virtual void notifyLoaded(CSSSegmentedFontFace*) OVERRIDE; | 61 virtual void notifyLoaded(CSSSegmentedFontFace*) OVERRIDE; |
| 62 virtual void notifyError(CSSSegmentedFontFace*) OVERRIDE; | 62 virtual void notifyError(CSSSegmentedFontFace*) OVERRIDE; |
| 63 void loaded(Document*); | 63 void loaded(Document*); |
| 64 void error(Document*); | 64 void error(Document*); |
| 65 void resolve(); | 65 void resolve(); |
| 66 | 66 |
| 67 ScriptPromise promise() | |
| 68 { | |
| 69 ScriptPromise promise = m_resolver->promise(); | |
| 70 m_resolver->detachPromise(); | |
| 71 return promise; | |
| 72 } | |
| 73 | |
| 74 private: | 67 private: |
| 75 LoadFontPromiseResolver(int numLoading, ScriptExecutionContext* context) | 68 LoadFontPromiseResolver(int numLoading, ScriptPromise promise, ScriptExecuti
onContext* context) |
| 76 : m_numLoading(numLoading) | 69 : m_numLoading(numLoading) |
| 77 , m_errorOccured(false) | 70 , m_errorOccured(false) |
| 78 , m_scriptState(ScriptState::current()) | 71 , m_scriptState(ScriptState::current()) |
| 79 , m_resolver(ScriptPromiseResolver::create(context)) | 72 , m_resolver(ScriptPromiseResolver::create(promise, context)) |
| 80 { } | 73 { } |
| 81 | 74 |
| 82 int m_numLoading; | 75 int m_numLoading; |
| 83 bool m_errorOccured; | 76 bool m_errorOccured; |
| 84 ScriptState* m_scriptState; | 77 ScriptState* m_scriptState; |
| 85 RefPtr<ScriptPromiseResolver> m_resolver; | 78 RefPtr<ScriptPromiseResolver> m_resolver; |
| 86 }; | 79 }; |
| 87 | 80 |
| 88 void LoadFontPromiseResolver::loaded(Document* document) | 81 void LoadFontPromiseResolver::loaded(Document* document) |
| 89 { | 82 { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 109 { | 102 { |
| 110 error(face->fontSelector()->document()); | 103 error(face->fontSelector()->document()); |
| 111 } | 104 } |
| 112 | 105 |
| 113 void LoadFontPromiseResolver::resolve() | 106 void LoadFontPromiseResolver::resolve() |
| 114 { | 107 { |
| 115 ScriptScope scope(m_scriptState); | 108 ScriptScope scope(m_scriptState); |
| 116 if (m_errorOccured) | 109 if (m_errorOccured) |
| 117 m_resolver->reject(ScriptValue::createNull()); | 110 m_resolver->reject(ScriptValue::createNull()); |
| 118 else | 111 else |
| 119 m_resolver->fulfill(ScriptValue::createNull()); | 112 m_resolver->resolve(ScriptValue::createNull()); |
| 120 } | 113 } |
| 121 | 114 |
| 122 class FontsReadyPromiseResolver { | 115 class FontsReadyPromiseResolver { |
| 123 public: | 116 public: |
| 124 static PassOwnPtr<FontsReadyPromiseResolver> create(ScriptExecutionContext*
context) | 117 static PassOwnPtr<FontsReadyPromiseResolver> create(ScriptPromise promise, S
criptExecutionContext* context) |
| 125 { | 118 { |
| 126 return adoptPtr(new FontsReadyPromiseResolver(context)); | 119 return adoptPtr(new FontsReadyPromiseResolver(promise, context)); |
| 127 } | 120 } |
| 128 | 121 |
| 129 void call(PassRefPtr<FontFaceSet> fontFaceSet) | 122 void call(PassRefPtr<FontFaceSet> fontFaceSet) |
| 130 { | 123 { |
| 131 ScriptScope scope(m_scriptState); | 124 ScriptScope scope(m_scriptState); |
| 132 m_resolver->fulfill(fontFaceSet); | 125 m_resolver->resolve(fontFaceSet); |
| 133 } | |
| 134 | |
| 135 ScriptPromise promise() | |
| 136 { | |
| 137 ScriptPromise promise = m_resolver->promise(); | |
| 138 m_resolver->detachPromise(); | |
| 139 return promise; | |
| 140 } | 126 } |
| 141 | 127 |
| 142 private: | 128 private: |
| 143 FontsReadyPromiseResolver(ScriptExecutionContext* context) | 129 FontsReadyPromiseResolver(ScriptPromise promise, ScriptExecutionContext* con
text) |
| 144 : m_scriptState(ScriptState::current()) | 130 : m_scriptState(ScriptState::current()) |
| 145 , m_resolver(ScriptPromiseResolver::create(context)) | 131 , m_resolver(ScriptPromiseResolver::create(promise, context)) |
| 146 { } | 132 { } |
| 147 ScriptState* m_scriptState; | 133 ScriptState* m_scriptState; |
| 148 RefPtr<ScriptPromiseResolver> m_resolver; | 134 RefPtr<ScriptPromiseResolver> m_resolver; |
| 149 }; | 135 }; |
| 150 | 136 |
| 151 FontFaceSet::FontFaceSet(Document* document) | 137 FontFaceSet::FontFaceSet(Document* document) |
| 152 : ActiveDOMObject(document) | 138 : ActiveDOMObject(document) |
| 153 , m_loadingCount(0) | 139 , m_loadingCount(0) |
| 154 , m_shouldFireDoneEvent(false) | 140 , m_shouldFireDoneEvent(false) |
| 155 , m_timer(this, &FontFaceSet::timerFired) | 141 , m_timer(this, &FontFaceSet::timerFired) |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 if (!m_loadingCount) { | 270 if (!m_loadingCount) { |
| 285 ASSERT(!m_shouldFireDoneEvent); | 271 ASSERT(!m_shouldFireDoneEvent); |
| 286 m_shouldFireDoneEvent = true; | 272 m_shouldFireDoneEvent = true; |
| 287 if (!m_timer.isActive()) | 273 if (!m_timer.isActive()) |
| 288 m_timer.startOneShot(0); | 274 m_timer.startOneShot(0); |
| 289 } | 275 } |
| 290 } | 276 } |
| 291 | 277 |
| 292 ScriptPromise FontFaceSet::ready() | 278 ScriptPromise FontFaceSet::ready() |
| 293 { | 279 { |
| 294 OwnPtr<FontsReadyPromiseResolver> resolver = FontsReadyPromiseResolver::crea
te(scriptExecutionContext()); | 280 ScriptPromise promise = ScriptPromise::create(scriptExecutionContext()); |
| 295 ScriptPromise promise = resolver->promise(); | 281 OwnPtr<FontsReadyPromiseResolver> resolver = FontsReadyPromiseResolver::crea
te(promise, scriptExecutionContext()); |
| 296 m_readyResolvers.append(resolver.release()); | 282 m_readyResolvers.append(resolver.release()); |
| 297 if (!m_timer.isActive()) | 283 if (!m_timer.isActive()) |
| 298 m_timer.startOneShot(0); | 284 m_timer.startOneShot(0); |
| 299 return promise; | 285 return promise; |
| 300 } | 286 } |
| 301 | 287 |
| 302 void FontFaceSet::fireDoneEventIfPossible() | 288 void FontFaceSet::fireDoneEventIfPossible() |
| 303 { | 289 { |
| 304 if (!m_pendingEvents.isEmpty() || !m_pendingLoadResolvers.isEmpty()) | 290 if (!m_pendingEvents.isEmpty() || !m_pendingLoadResolvers.isEmpty()) |
| 305 return; | 291 return; |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 ScriptPromise FontFaceSet::load(const String& fontString, const String&, Excepti
onState& es) | 344 ScriptPromise FontFaceSet::load(const String& fontString, const String&, Excepti
onState& es) |
| 359 { | 345 { |
| 360 // FIXME: The second parameter (text) is ignored. | 346 // FIXME: The second parameter (text) is ignored. |
| 361 Font font; | 347 Font font; |
| 362 if (!resolveFontStyle(fontString, font)) { | 348 if (!resolveFontStyle(fontString, font)) { |
| 363 es.throwUninformativeAndGenericDOMException(SyntaxError); | 349 es.throwUninformativeAndGenericDOMException(SyntaxError); |
| 364 return ScriptPromise(); | 350 return ScriptPromise(); |
| 365 } | 351 } |
| 366 | 352 |
| 367 Document* d = document(); | 353 Document* d = document(); |
| 368 RefPtr<LoadFontPromiseResolver> resolver = LoadFontPromiseResolver::create(f
ont.family(), scriptExecutionContext()); | 354 ScriptPromise promise = ScriptPromise::create(scriptExecutionContext()); |
| 355 RefPtr<LoadFontPromiseResolver> resolver = LoadFontPromiseResolver::create(f
ont.family(), promise, scriptExecutionContext()); |
| 369 for (const FontFamily* f = &font.family(); f; f = f->next()) { | 356 for (const FontFamily* f = &font.family(); f; f = f->next()) { |
| 370 CSSSegmentedFontFace* face = d->styleResolver()->fontSelector()->getFont
Face(font.fontDescription(), f->family()); | 357 CSSSegmentedFontFace* face = d->styleResolver()->fontSelector()->getFont
Face(font.fontDescription(), f->family()); |
| 371 if (!face) { | 358 if (!face) { |
| 372 resolver->error(d); | 359 resolver->error(d); |
| 373 continue; | 360 continue; |
| 374 } | 361 } |
| 375 face->loadFont(font.fontDescription(), resolver); | 362 face->loadFont(font.fontDescription(), resolver); |
| 376 } | 363 } |
| 377 return resolver->promise(); | 364 return promise; |
| 378 } | 365 } |
| 379 | 366 |
| 380 bool FontFaceSet::check(const String& fontString, const String&, ExceptionState&
es) | 367 bool FontFaceSet::check(const String& fontString, const String&, ExceptionState&
es) |
| 381 { | 368 { |
| 382 // FIXME: The second parameter (text) is ignored. | 369 // FIXME: The second parameter (text) is ignored. |
| 383 Font font; | 370 Font font; |
| 384 if (!resolveFontStyle(fontString, font)) { | 371 if (!resolveFontStyle(fontString, font)) { |
| 385 es.throwUninformativeAndGenericDOMException(SyntaxError); | 372 es.throwUninformativeAndGenericDOMException(SyntaxError); |
| 386 return false; | 373 return false; |
| 387 } | 374 } |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 442 | 429 |
| 443 void FontFaceSet::FontLoadHistogram::record() | 430 void FontFaceSet::FontLoadHistogram::record() |
| 444 { | 431 { |
| 445 if (m_recorded) | 432 if (m_recorded) |
| 446 return; | 433 return; |
| 447 m_recorded = true; | 434 m_recorded = true; |
| 448 HistogramSupport::histogramCustomCounts("WebFont.WebFontsInPage", m_count, 1
, 100, 50); | 435 HistogramSupport::histogramCustomCounts("WebFont.WebFontsInPage", m_count, 1
, 100, 50); |
| 449 } | 436 } |
| 450 | 437 |
| 451 } // namespace WebCore | 438 } // namespace WebCore |
| OLD | NEW |