OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/common/font_cache_dispatcher_win.h" | 5 #include "content/common/font_cache_dispatcher_win.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 | 136 |
137 DISALLOW_COPY_AND_ASSIGN(FontCache); | 137 DISALLOW_COPY_AND_ASSIGN(FontCache); |
138 }; | 138 }; |
139 | 139 |
140 } | 140 } |
141 | 141 |
142 FontCacheDispatcher::FontCacheDispatcher() | 142 FontCacheDispatcher::FontCacheDispatcher() |
143 : sender_(NULL) { | 143 : sender_(NULL) { |
144 } | 144 } |
145 | 145 |
| 146 bool FontCacheDispatcher::Send(IPC::Message* message) { |
| 147 if (sender_) |
| 148 return sender_->Send(message); |
| 149 |
| 150 delete message; |
| 151 return false; |
| 152 } |
| 153 |
146 FontCacheDispatcher::~FontCacheDispatcher() { | 154 FontCacheDispatcher::~FontCacheDispatcher() { |
147 } | 155 } |
148 | 156 |
149 void FontCacheDispatcher::OnFilterAdded(IPC::Sender* sender) { | 157 void FontCacheDispatcher::OnFilterAdded(IPC::Sender* sender) { |
150 sender_ = sender; | 158 sender_ = sender; |
151 } | 159 } |
152 | 160 |
153 bool FontCacheDispatcher::OnMessageReceived(const IPC::Message& message) { | 161 bool FontCacheDispatcher::OnMessageReceived(const IPC::Message& message) { |
154 bool handled = true; | 162 bool handled = true; |
155 IPC_BEGIN_MESSAGE_MAP(FontCacheDispatcher, message) | 163 IPC_BEGIN_MESSAGE_MAP(FontCacheDispatcher, message) |
156 IPC_MESSAGE_HANDLER(ChildProcessHostMsg_PreCacheFont, OnPreCacheFont) | 164 IPC_MESSAGE_HANDLER(ChildProcessHostMsg_PreCacheFont, OnPreCacheFont) |
157 IPC_MESSAGE_HANDLER(ChildProcessHostMsg_ReleaseCachedFonts, | 165 IPC_MESSAGE_HANDLER(ChildProcessHostMsg_ReleaseCachedFonts, |
158 OnReleaseCachedFonts) | 166 OnReleaseCachedFonts) |
159 IPC_MESSAGE_UNHANDLED(handled = false) | 167 IPC_MESSAGE_UNHANDLED(handled = false) |
160 IPC_END_MESSAGE_MAP() | 168 IPC_END_MESSAGE_MAP() |
161 return handled; | 169 return handled; |
162 } | 170 } |
163 | 171 |
164 void FontCacheDispatcher::OnChannelClosing() { | 172 void FontCacheDispatcher::OnChannelClosing() { |
165 sender_ = NULL; | 173 sender_ = NULL; |
166 } | 174 } |
167 | 175 |
168 bool FontCacheDispatcher::Send(IPC::Message* message) { | |
169 if (sender_) | |
170 return sender_->Send(message); | |
171 | |
172 delete message; | |
173 return false; | |
174 } | |
175 | |
176 void FontCacheDispatcher::OnPreCacheFont(const LOGFONT& font) { | 176 void FontCacheDispatcher::OnPreCacheFont(const LOGFONT& font) { |
177 // If a child process is running in a sandbox, GetTextMetrics() | 177 // If a child process is running in a sandbox, GetTextMetrics() |
178 // can sometimes fail. If a font has not been loaded | 178 // can sometimes fail. If a font has not been loaded |
179 // previously, GetTextMetrics() will try to load the font | 179 // previously, GetTextMetrics() will try to load the font |
180 // from the font file. However, the sandboxed process does | 180 // from the font file. However, the sandboxed process does |
181 // not have permissions to access any font files and | 181 // not have permissions to access any font files and |
182 // the call fails. So we make the browser pre-load the | 182 // the call fails. So we make the browser pre-load the |
183 // font for us by using a dummy call to GetTextMetrics of | 183 // font for us by using a dummy call to GetTextMetrics of |
184 // the same font. | 184 // the same font. |
185 // This means the browser process just loads the font into memory so that | 185 // This means the browser process just loads the font into memory so that |
186 // when GDI attempt to query that font info in child process, it does not | 186 // when GDI attempt to query that font info in child process, it does not |
187 // need to load that file, hence no permission issues there. Therefore, | 187 // need to load that file, hence no permission issues there. Therefore, |
188 // when a font is asked to be cached, we always recreates the font object | 188 // when a font is asked to be cached, we always recreates the font object |
189 // to avoid the case that an in-cache font is swapped out by GDI. | 189 // to avoid the case that an in-cache font is swapped out by GDI. |
190 FontCache::GetInstance()->PreCacheFont(font, this); | 190 FontCache::GetInstance()->PreCacheFont(font, this); |
191 } | 191 } |
192 | 192 |
193 void FontCacheDispatcher::OnReleaseCachedFonts() { | 193 void FontCacheDispatcher::OnReleaseCachedFonts() { |
194 // Release cached fonts that requested from a pid by decrementing the ref | 194 // Release cached fonts that requested from a pid by decrementing the ref |
195 // count. When ref count is zero, the handles are released. | 195 // count. When ref count is zero, the handles are released. |
196 FontCache::GetInstance()->ReleaseCachedFonts(this); | 196 FontCache::GetInstance()->ReleaseCachedFonts(this); |
197 } | 197 } |
198 | 198 |
199 } // namespace content | 199 } // namespace content |
OLD | NEW |