Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(291)

Side by Side Diff: content/common/font_loader_mac.mm

Issue 7655040: Work around a ridiculous bug in ATS, a deprecated system framework (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« chrome/app/framework.order ('K') | « chrome/app/framework.order ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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_loader_mac.h" 5 #include "content/common/font_loader_mac.h"
6 6
7 #import <Cocoa/Cocoa.h> 7 #import <Cocoa/Cocoa.h>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/file_path.h" 10 #include "base/file_path.h"
11 #include "base/file_util.h" 11 #include "base/file_util.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/mac/mac_util.h" 13 #include "base/mac/mac_util.h"
14 #include "base/sys_string_conversions.h" 14 #include "base/sys_string_conversions.h"
15 15
16 extern "C" {
17
18 // Work around http://crbug.com/93191, a really nasty memory smasher bug.
19 // On Mac OS X 10.7 ("Lion"), ATS writes to memory it doesn't own.
20 // SendDeactivateFontsInContainerMessage, called by ATSFontDeactivate,
21 // trashes memory whenever dlsym(RTLD_DEFAULT,
22 // "_CTFontManagerUnregisterFontForData") returns NULL. In that case, it tries
23 // to locate that symbol in the CoreText framework, doing some extremely
24 // sloppy string handling resulting in a likelihood that the string
25 // "Text.framework/Versions/A/CoreText" will be written over memory that it
26 // doesn't own. The kicker here is that Apple dlsym always inserts its own
27 // leading underscore, so ATS actually winds up looking up a
28 // __CTFontManagerUnregisterFontForData symbol, which doesn't even exist in
29 // CoreText. It's only got the single-underscore variant corresponding to an
30 // extern "C" name that has zero underscores.
31 //
32 // Providing a single-underscored extern "C" function by this name results in
33 // a __CTFontManagerUnregisterFontForData symbol that, as long as it's public
34 // (not private extern) and unstripped, ATS will find, and avoid making the
35 // amateur string mistakes that ruin everyone else's good time.
36 //
37 // Since ATS wouldn't normally be able to call this function anyway, it's just
38 // left as a no-op here.
39 //
40 // This file seems like as good as any other to place this function since it
41 // already interfaces with ATS for other reasons.
42 __attribute__((visibility("default")))
43 void _CTFontManagerUnregisterFontForData(NSUInteger, int) {
44 }
45
46 } // extern "C"
47
16 // static 48 // static
17 bool FontLoader::LoadFontIntoBuffer(NSFont* font_to_encode, 49 bool FontLoader::LoadFontIntoBuffer(NSFont* font_to_encode,
18 base::SharedMemory* font_data, 50 base::SharedMemory* font_data,
19 uint32* font_data_size, 51 uint32* font_data_size,
20 uint32* font_id) { 52 uint32* font_id) {
21 CHECK(font_data); 53 CHECK(font_data);
22 CHECK(font_data_size); 54 CHECK(font_data_size);
23 CHECK(font_id); 55 CHECK(font_id);
24 *font_data_size = 0; 56 *font_data_size = 0;
25 *font_id = 0; 57 *font_id = 0;
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 // This is the value used by WebKit when activating remote fonts. 149 // This is the value used by WebKit when activating remote fonts.
118 const ATSFontContext kFontContextPrivate = 3; 150 const ATSFontContext kFontContextPrivate = 3;
119 OSStatus err = ATSFontActivateFromMemory(shm.memory(), font_data_size, 151 OSStatus err = ATSFontActivateFromMemory(shm.memory(), font_data_size,
120 kFontContextPrivate, kATSFontFormatUnspecified, NULL, 152 kFontContextPrivate, kATSFontFormatUnspecified, NULL,
121 kATSOptionFlagsDefault, font_container); 153 kATSOptionFlagsDefault, font_container);
122 if (err != noErr || !font_container) 154 if (err != noErr || !font_container)
123 return false; 155 return false;
124 156
125 return true; 157 return true;
126 } 158 }
OLDNEW
« chrome/app/framework.order ('K') | « chrome/app/framework.order ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698