| OLD | NEW |
| 1 /* | 1 /* |
| 2 * This file is part of the internal font implementation. | 2 * This file is part of the internal font implementation. |
| 3 * | 3 * |
| 4 * Copyright (c) 2010 Google Inc. All rights reserved. | 4 * Copyright (c) 2010 Google Inc. All rights reserved. |
| 5 * | 5 * |
| 6 * This library is free software; you can redistribute it and/or | 6 * This library is free software; you can redistribute it and/or |
| 7 * modify it under the terms of the GNU Library General Public | 7 * modify it under the terms of the GNU Library General Public |
| 8 * License as published by the Free Software Foundation; either | 8 * License as published by the Free Software Foundation; either |
| 9 * version 2 of the License, or (at your option) any later version. | 9 * version 2 of the License, or (at your option) any later version. |
| 10 * | 10 * |
| 11 * This library is distributed in the hope that it will be useful, | 11 * This library is distributed in the hope that it will be useful, |
| 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 * Library General Public License for more details. | 14 * Library General Public License for more details. |
| 15 * | 15 * |
| 16 * You should have received a copy of the GNU Library General Public License | 16 * You should have received a copy of the GNU Library General Public License |
| 17 * along with this library; see the file COPYING.LIB. If not, write to | 17 * along with this library; see the file COPYING.LIB. If not, write to |
| 18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 19 * Boston, MA 02110-1301, USA. | 19 * Boston, MA 02110-1301, USA. |
| 20 * | 20 * |
| 21 */ | 21 */ |
| 22 | 22 |
| 23 // This file provides additional functionality to the Mac FontPlatformData class | 23 // This file provides additional functionality to the Mac FontPlatformData class |
| 24 // defined in WebCore/platform/cocoa/FontPlatformDataCocoa.mm . | 24 // defined in WebCore/platform/cocoa/FontPlatformDataCocoa.mm . |
| 25 // Because we want to support loading fonts between processes in the face of | 25 // Because we want to support loading fonts between processes in the face of |
| 26 // font loading being blocked by the sandbox, we need a mechnasim to both | 26 // font loading being blocked by the sandbox, we need a mechnasim to both |
| 27 // do the loading of in-memory fonts and keep track of them. | 27 // do the loading of in-memory fonts and keep track of them. |
| 28 | 28 |
| 29 #import "config.h" | 29 #import "config.h" |
| 30 #import "core/platform/graphics/chromium/CrossProcessFontLoading.h" | 30 #import "core/platform/graphics/mac/MemoryActivatedFont.h" |
| 31 | 31 |
| 32 #import <AppKit/NSFont.h> | 32 #import <AppKit/NSFont.h> |
| 33 #import "core/platform/graphics/FontPlatformData.h" | 33 #import "core/platform/graphics/FontPlatformData.h" |
| 34 #include "platform/LinkHash.h" | 34 #include "platform/LinkHash.h" |
| 35 #import "public/platform/mac/WebSandboxSupport.h" | 35 #import "public/platform/mac/WebSandboxSupport.h" |
| 36 #import "public/platform/Platform.h" | 36 #import "public/platform/Platform.h" |
| 37 #import "wtf/HashMap.h" | 37 #import "wtf/HashMap.h" |
| 38 | 38 |
| 39 namespace WebCore { | 39 namespace WebCore { |
| 40 | 40 |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 fontCacheByFontName().remove(m_inSandboxHashKey); | 164 fontCacheByFontName().remove(m_inSandboxHashKey); |
| 165 } | 165 } |
| 166 | 166 |
| 167 // Given an NSFont, try to load a representation of that font into the cgFont | 167 // Given an NSFont, try to load a representation of that font into the cgFont |
| 168 // parameter. If loading is blocked by the sandbox, the font may be loaded | 168 // parameter. If loading is blocked by the sandbox, the font may be loaded |
| 169 // cross-process. | 169 // cross-process. |
| 170 // If sandbox loading also fails, a fallback font is loaded. | 170 // If sandbox loading also fails, a fallback font is loaded. |
| 171 // | 171 // |
| 172 // Considerations: | 172 // Considerations: |
| 173 // * cgFont must be CFRelease()ed by the caller when done. | 173 // * cgFont must be CFRelease()ed by the caller when done. |
| 174 // | 174 // |
| 175 // Parameters: | 175 // Parameters: |
| 176 // * nsFont - The font we wish to load. | 176 // * nsFont - The font we wish to load. |
| 177 // * fontSize - point size of the font we wish to load. | 177 // * fontSize - point size of the font we wish to load. |
| 178 // * outNSFont - The font that was actually loaded or null if loading failed. | 178 // * outNSFont - The font that was actually loaded or null if loading failed. |
| 179 // * cgFont - on output this contains the CGFontRef corresponding to the NSFont | 179 // * cgFont - on output this contains the CGFontRef corresponding to the NSFont |
| 180 // that was picked in the end. The caller is responsible for calling | 180 // that was picked in the end. The caller is responsible for calling |
| 181 // CFRelease() on this parameter when done with it. | 181 // CFRelease() on this parameter when done with it. |
| 182 // * fontID - on output, the ID corresponding to nsFont. | 182 // * fontID - on output, the ID corresponding to nsFont. |
| 183 void FontPlatformData::loadFont(NSFont* nsFont, float fontSize, NSFont*& outNSFo
nt, CGFontRef& cgFont) | 183 void FontPlatformData::loadFont(NSFont* nsFont, float fontSize, NSFont*& outNSFo
nt, CGFontRef& cgFont) |
| 184 { | 184 { |
| 185 outNSFont = nsFont; | 185 outNSFont = nsFont; |
| 186 cgFont = CTFontCopyGraphicsFont(toCTFontRef(outNSFont), 0); | 186 cgFont = CTFontCopyGraphicsFont(toCTFontRef(outNSFont), 0); |
| 187 if (outNSFont && cgFont && isLastResortFont(cgFont)) { | 187 if (outNSFont && cgFont && isLastResortFont(cgFont)) { |
| 188 // Release old CGFontRef since it points at the LastResort font which we
don't want. | 188 // Release old CGFontRef since it points at the LastResort font which we
don't want. |
| 189 CFRelease(cgFont); | 189 CFRelease(cgFont); |
| 190 cgFont = 0; | 190 cgFont = 0; |
| 191 | 191 |
| 192 // Font loading was blocked by the Sandbox. | 192 // Font loading was blocked by the Sandbox. |
| 193 m_inMemoryFont = loadFontFromBrowserProcess(outNSFont); | 193 m_inMemoryFont = loadFontFromBrowserProcess(outNSFont); |
| 194 if (m_inMemoryFont) { | 194 if (m_inMemoryFont) { |
| 195 cgFont = m_inMemoryFont->cgFont(); | 195 cgFont = m_inMemoryFont->cgFont(); |
| 196 | 196 |
| 197 // Need to add an extra retain so output semantics of this function | 197 // Need to add an extra retain so output semantics of this function |
| 198 // are consistent. | 198 // are consistent. |
| 199 CFRetain(cgFont); | 199 CFRetain(cgFont); |
| 200 } else { | 200 } else { |
| 201 // If we still can't load the font, set |outNSFont| to null so that
FontPlatformData won't be used. | 201 // If we still can't load the font, set |outNSFont| to null so that
FontPlatformData won't be used. |
| 202 outNSFont = 0; | 202 outNSFont = 0; |
| 203 } | 203 } |
| 204 } | 204 } |
| 205 } | 205 } |
| 206 | 206 |
| 207 } // namespace WebCore | 207 } // namespace WebCore |
| OLD | NEW |