OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "config.h" | 5 #include "config.h" |
6 #include "core/css/FontLoader.h" | 6 #include "core/css/FontLoader.h" |
7 | 7 |
8 #include "core/css/CSSFontSelector.h" | 8 #include "core/css/CSSFontSelector.h" |
9 #include "core/dom/Document.h" | |
9 #include "core/fetch/FontResource.h" | 10 #include "core/fetch/FontResource.h" |
10 #include "core/fetch/ResourceFetcher.h" | 11 #include "core/fetch/ResourceFetcher.h" |
11 | 12 |
12 namespace blink { | 13 namespace blink { |
13 | 14 |
14 FontLoader::FontLoader(CSSFontSelector* fontSelector, ResourceFetcher* resourceF etcher) | 15 FontLoader::FontLoader(CSSFontSelector* fontSelector, ResourceFetcher* resourceF etcher) |
15 : m_beginLoadingTimer(this, &FontLoader::beginLoadTimerFired) | 16 : m_beginLoadingTimer(this, &FontLoader::beginLoadTimerFired) |
16 , m_fontSelector(fontSelector) | 17 , m_fontSelector(fontSelector) |
17 , m_resourceFetcher(resourceFetcher) | 18 , m_resourceFetcher(resourceFetcher) |
18 { | 19 { |
(...skipping 27 matching lines...) Expand all Loading... | |
46 | 47 |
47 void FontLoader::beginLoadTimerFired(Timer<blink::FontLoader>*) | 48 void FontLoader::beginLoadTimerFired(Timer<blink::FontLoader>*) |
48 { | 49 { |
49 loadPendingFonts(); | 50 loadPendingFonts(); |
50 } | 51 } |
51 | 52 |
52 void FontLoader::loadPendingFonts() | 53 void FontLoader::loadPendingFonts() |
53 { | 54 { |
54 ASSERT(m_resourceFetcher); | 55 ASSERT(m_resourceFetcher); |
55 | 56 |
57 if (m_fontsToBeginLoading.isEmpty()) | |
58 return; | |
59 | |
56 FontsToLoadVector fontsToBeginLoading; | 60 FontsToLoadVector fontsToBeginLoading; |
57 fontsToBeginLoading.swap(m_fontsToBeginLoading); | 61 fontsToBeginLoading.swap(m_fontsToBeginLoading); |
62 bool loaded = false; | |
58 for (FontsToLoadVector::iterator it = fontsToBeginLoading.begin(); it != fon tsToBeginLoading.end(); ++it) { | 63 for (FontsToLoadVector::iterator it = fontsToBeginLoading.begin(); it != fon tsToBeginLoading.end(); ++it) { |
59 FontResource* fontResource = it->first.get(); | 64 FontResource* fontResource = it->first.get(); |
60 fontResource->beginLoadIfNeeded(m_resourceFetcher); | 65 if (fontResource->stillNeedsLoad()) { |
66 fontResource->beginLoadIfNeeded(m_resourceFetcher); | |
67 loaded = true; | |
68 } | |
69 } | |
70 | |
71 if (!loaded) { | |
72 // Since we have prevented load event by RequestCountTracker but did not | |
73 // start any load, schedule a check for load event here. | |
74 Document* document = m_resourceFetcher->document(); | |
75 if (document && !document->loadEventFinished() && !document->isDelayingL oadEvent()) | |
76 document->checkLoadEventSoon(); | |
Nate Chapin
2014/08/11 22:06:15
Do we need to block the load event on webfonts in
Kunihiko Sakamoto
2014/08/12 03:12:09
It worked this way for years and I think many webs
| |
61 } | 77 } |
62 | 78 |
63 // When the local fontsToBeginLoading vector goes out of scope it will | 79 // When the local fontsToBeginLoading vector goes out of scope it will |
64 // decrement the request counts on the ResourceFetcher for all the fonts | 80 // decrement the request counts on the ResourceFetcher for all the fonts |
65 // that were just loaded. | 81 // that were just loaded. |
66 } | 82 } |
67 | 83 |
68 void FontLoader::fontFaceInvalidated() | 84 void FontLoader::fontFaceInvalidated() |
69 { | 85 { |
70 if (m_fontSelector) | 86 if (m_fontSelector) |
(...skipping 15 matching lines...) Expand all Loading... | |
86 } | 102 } |
87 #endif | 103 #endif |
88 | 104 |
89 void FontLoader::trace(Visitor* visitor) | 105 void FontLoader::trace(Visitor* visitor) |
90 { | 106 { |
91 visitor->trace(m_resourceFetcher); | 107 visitor->trace(m_resourceFetcher); |
92 visitor->trace(m_fontSelector); | 108 visitor->trace(m_fontSelector); |
93 } | 109 } |
94 | 110 |
95 } // namespace blink | 111 } // namespace blink |
OLD | NEW |