Tue, 06 Jan 2015 21:39:09 +0100
Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
michael@0 | 1 | # HG changeset patch |
michael@0 | 2 | # User Robert O'Callahan <robert@ocallahan.org> |
michael@0 | 3 | # Date 1357107533 -46800 |
michael@0 | 4 | # Node ID ed54dfdd2facb11a4d4158138b460a31de45e9f7 |
michael@0 | 5 | # Parent ab6457cc16ec14ea07386dcfc57cad6b8a9ac55d |
michael@0 | 6 | Bug 717178. Part 3 alternative: don't put Win32 cairo_font_face_ts into the font-face cache if they were created with an explicit HFONT. r=jrmuizel |
michael@0 | 7 | |
michael@0 | 8 | diff --git a/gfx/cairo/cairo/src/cairo-win32-font.c b/gfx/cairo/cairo/src/cairo-win32-font.c |
michael@0 | 9 | --- a/gfx/cairo/cairo/src/cairo-win32-font.c |
michael@0 | 10 | +++ b/gfx/cairo/cairo/src/cairo-win32-font.c |
michael@0 | 11 | @@ -1941,16 +1942,21 @@ const cairo_font_face_backend_t _cairo_w |
michael@0 | 12 | * The primary purpose of this mapping is to provide unique |
michael@0 | 13 | * #cairo_font_face_t values so that our cache and mapping from |
michael@0 | 14 | * #cairo_font_face_t => #cairo_scaled_font_t works. Once the |
michael@0 | 15 | * corresponding #cairo_font_face_t objects fall out of downstream |
michael@0 | 16 | * caches, we don't need them in this hash table anymore. |
michael@0 | 17 | * |
michael@0 | 18 | * Modifications to this hash table are protected by |
michael@0 | 19 | * _cairo_win32_font_face_mutex. |
michael@0 | 20 | + * |
michael@0 | 21 | + * Only #cairo_font_face_t values with null 'hfont' (no |
michael@0 | 22 | + * HFONT preallocated by caller) are stored in this table. We rely |
michael@0 | 23 | + * on callers to manage the lifetime of the HFONT, and they can't |
michael@0 | 24 | + * do that if we share #cairo_font_face_t values with other callers. |
michael@0 | 25 | */ |
michael@0 | 26 | |
michael@0 | 27 | static cairo_hash_table_t *cairo_win32_font_face_hash_table = NULL; |
michael@0 | 28 | |
michael@0 | 29 | static int |
michael@0 | 30 | _cairo_win32_font_face_keys_equal (const void *key_a, |
michael@0 | 31 | const void *key_b); |
michael@0 | 32 | |
michael@0 | 33 | @@ -2036,22 +2042,24 @@ static int |
michael@0 | 34 | } |
michael@0 | 35 | |
michael@0 | 36 | static void |
michael@0 | 37 | _cairo_win32_font_face_destroy (void *abstract_face) |
michael@0 | 38 | { |
michael@0 | 39 | cairo_hash_table_t *hash_table; |
michael@0 | 40 | cairo_win32_font_face_t *font_face = abstract_face; |
michael@0 | 41 | |
michael@0 | 42 | - hash_table = _cairo_win32_font_face_hash_table_lock (); |
michael@0 | 43 | - if (unlikely (hash_table == NULL)) { |
michael@0 | 44 | - return; |
michael@0 | 45 | + if (!font_face->hfont) { |
michael@0 | 46 | + hash_table = _cairo_win32_font_face_hash_table_lock (); |
michael@0 | 47 | + if (unlikely (hash_table == NULL)) { |
michael@0 | 48 | + return; |
michael@0 | 49 | + } |
michael@0 | 50 | + _cairo_hash_table_remove (hash_table, &font_face->base.hash_entry); |
michael@0 | 51 | + _cairo_win32_font_face_hash_table_unlock (); |
michael@0 | 52 | } |
michael@0 | 53 | - _cairo_hash_table_remove (hash_table, &font_face->base.hash_entry); |
michael@0 | 54 | - _cairo_win32_font_face_hash_table_unlock (); |
michael@0 | 55 | } |
michael@0 | 56 | |
michael@0 | 57 | /** |
michael@0 | 58 | * cairo_win32_font_face_create_for_logfontw_hfont: |
michael@0 | 59 | * @logfont: A #LOGFONTW structure specifying the font to use. |
michael@0 | 60 | * If @font is %NULL then the lfHeight, lfWidth, lfOrientation and lfEscapement |
michael@0 | 61 | * fields of this structure are ignored. Otherwise lfWidth, lfOrientation and |
michael@0 | 62 | * lfEscapement must be zero. |
michael@0 | 63 | @@ -2070,55 +2078,63 @@ static void |
michael@0 | 64 | **/ |
michael@0 | 65 | cairo_font_face_t * |
michael@0 | 66 | cairo_win32_font_face_create_for_logfontw_hfont (LOGFONTW *logfont, HFONT font) |
michael@0 | 67 | { |
michael@0 | 68 | cairo_win32_font_face_t *font_face, key; |
michael@0 | 69 | cairo_hash_table_t *hash_table; |
michael@0 | 70 | cairo_status_t status; |
michael@0 | 71 | |
michael@0 | 72 | - hash_table = _cairo_win32_font_face_hash_table_lock (); |
michael@0 | 73 | - if (unlikely (hash_table == NULL)) { |
michael@0 | 74 | - _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); |
michael@0 | 75 | - return (cairo_font_face_t *)&_cairo_font_face_nil; |
michael@0 | 76 | - } |
michael@0 | 77 | + if (!font) { |
michael@0 | 78 | + hash_table = _cairo_win32_font_face_hash_table_lock (); |
michael@0 | 79 | + if (unlikely (hash_table == NULL)) { |
michael@0 | 80 | + _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); |
michael@0 | 81 | + return (cairo_font_face_t *)&_cairo_font_face_nil; |
michael@0 | 82 | + } |
michael@0 | 83 | |
michael@0 | 84 | - _cairo_win32_font_face_init_key (&key, logfont, font); |
michael@0 | 85 | + _cairo_win32_font_face_init_key (&key, logfont, font); |
michael@0 | 86 | |
michael@0 | 87 | - /* Return existing unscaled font if it exists in the hash table. */ |
michael@0 | 88 | - font_face = _cairo_hash_table_lookup (hash_table, |
michael@0 | 89 | - &key.base.hash_entry); |
michael@0 | 90 | - if (font_face != NULL) { |
michael@0 | 91 | - cairo_font_face_reference (&font_face->base); |
michael@0 | 92 | - goto DONE; |
michael@0 | 93 | + /* Return existing unscaled font if it exists in the hash table. */ |
michael@0 | 94 | + font_face = _cairo_hash_table_lookup (hash_table, |
michael@0 | 95 | + &key.base.hash_entry); |
michael@0 | 96 | + if (font_face != NULL) { |
michael@0 | 97 | + cairo_font_face_reference (&font_face->base); |
michael@0 | 98 | + goto DONE; |
michael@0 | 99 | + } |
michael@0 | 100 | } |
michael@0 | 101 | |
michael@0 | 102 | /* Otherwise create it and insert into hash table. */ |
michael@0 | 103 | font_face = malloc (sizeof (cairo_win32_font_face_t)); |
michael@0 | 104 | if (!font_face) { |
michael@0 | 105 | _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); |
michael@0 | 106 | goto FAIL; |
michael@0 | 107 | } |
michael@0 | 108 | |
michael@0 | 109 | _cairo_win32_font_face_init_key (font_face, logfont, font); |
michael@0 | 110 | _cairo_font_face_init (&font_face->base, &_cairo_win32_font_face_backend); |
michael@0 | 111 | + assert (font_face->base.hash_entry.hash == key.base.hash_entry.hash); |
michael@0 | 112 | |
michael@0 | 113 | - assert (font_face->base.hash_entry.hash == key.base.hash_entry.hash); |
michael@0 | 114 | - status = _cairo_hash_table_insert (hash_table, |
michael@0 | 115 | - &font_face->base.hash_entry); |
michael@0 | 116 | - if (unlikely (status)) |
michael@0 | 117 | - goto FAIL; |
michael@0 | 118 | + if (!font) { |
michael@0 | 119 | + status = _cairo_hash_table_insert (hash_table, |
michael@0 | 120 | + &font_face->base.hash_entry); |
michael@0 | 121 | + if (unlikely (status)) |
michael@0 | 122 | + goto FAIL; |
michael@0 | 123 | + } |
michael@0 | 124 | |
michael@0 | 125 | DONE: |
michael@0 | 126 | - _cairo_win32_font_face_hash_table_unlock (); |
michael@0 | 127 | + if (!font) { |
michael@0 | 128 | + _cairo_win32_font_face_hash_table_unlock (); |
michael@0 | 129 | + } |
michael@0 | 130 | |
michael@0 | 131 | return &font_face->base; |
michael@0 | 132 | |
michael@0 | 133 | FAIL: |
michael@0 | 134 | - _cairo_win32_font_face_hash_table_unlock (); |
michael@0 | 135 | + if (!font) { |
michael@0 | 136 | + _cairo_win32_font_face_hash_table_unlock (); |
michael@0 | 137 | + } |
michael@0 | 138 | |
michael@0 | 139 | return (cairo_font_face_t *)&_cairo_font_face_nil; |
michael@0 | 140 | } |
michael@0 | 141 | |
michael@0 | 142 | /** |
michael@0 | 143 | * cairo_win32_font_face_create_for_logfontw: |
michael@0 | 144 | * @logfont: A #LOGFONTW structure specifying the font to use. |
michael@0 | 145 | * The lfHeight, lfWidth, lfOrientation and lfEscapement |