Thu, 15 Jan 2015 15:59:08 +0100
Implement a real Private Browsing Mode condition by changing the API/ABI;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #include "nsScreenGtk.h" |
michael@0 | 7 | |
michael@0 | 8 | #include <gdk/gdk.h> |
michael@0 | 9 | #ifdef MOZ_X11 |
michael@0 | 10 | #include <gdk/gdkx.h> |
michael@0 | 11 | #include <X11/Xatom.h> |
michael@0 | 12 | #endif |
michael@0 | 13 | #include <gtk/gtk.h> |
michael@0 | 14 | |
michael@0 | 15 | nsScreenGtk :: nsScreenGtk ( ) |
michael@0 | 16 | : mScreenNum(0), |
michael@0 | 17 | mRect(0, 0, 0, 0), |
michael@0 | 18 | mAvailRect(0, 0, 0, 0) |
michael@0 | 19 | { |
michael@0 | 20 | } |
michael@0 | 21 | |
michael@0 | 22 | |
michael@0 | 23 | nsScreenGtk :: ~nsScreenGtk() |
michael@0 | 24 | { |
michael@0 | 25 | } |
michael@0 | 26 | |
michael@0 | 27 | |
michael@0 | 28 | NS_IMETHODIMP |
michael@0 | 29 | nsScreenGtk :: GetRect(int32_t *outLeft, int32_t *outTop, int32_t *outWidth, int32_t *outHeight) |
michael@0 | 30 | { |
michael@0 | 31 | *outLeft = mRect.x; |
michael@0 | 32 | *outTop = mRect.y; |
michael@0 | 33 | *outWidth = mRect.width; |
michael@0 | 34 | *outHeight = mRect.height; |
michael@0 | 35 | |
michael@0 | 36 | return NS_OK; |
michael@0 | 37 | |
michael@0 | 38 | } // GetRect |
michael@0 | 39 | |
michael@0 | 40 | |
michael@0 | 41 | NS_IMETHODIMP |
michael@0 | 42 | nsScreenGtk :: GetAvailRect(int32_t *outLeft, int32_t *outTop, int32_t *outWidth, int32_t *outHeight) |
michael@0 | 43 | { |
michael@0 | 44 | *outLeft = mAvailRect.x; |
michael@0 | 45 | *outTop = mAvailRect.y; |
michael@0 | 46 | *outWidth = mAvailRect.width; |
michael@0 | 47 | *outHeight = mAvailRect.height; |
michael@0 | 48 | |
michael@0 | 49 | return NS_OK; |
michael@0 | 50 | |
michael@0 | 51 | } // GetAvailRect |
michael@0 | 52 | |
michael@0 | 53 | |
michael@0 | 54 | NS_IMETHODIMP |
michael@0 | 55 | nsScreenGtk :: GetPixelDepth(int32_t *aPixelDepth) |
michael@0 | 56 | { |
michael@0 | 57 | GdkVisual * visual = gdk_screen_get_system_visual(gdk_screen_get_default()); |
michael@0 | 58 | *aPixelDepth = gdk_visual_get_depth(visual); |
michael@0 | 59 | |
michael@0 | 60 | return NS_OK; |
michael@0 | 61 | |
michael@0 | 62 | } // GetPixelDepth |
michael@0 | 63 | |
michael@0 | 64 | |
michael@0 | 65 | NS_IMETHODIMP |
michael@0 | 66 | nsScreenGtk :: GetColorDepth(int32_t *aColorDepth) |
michael@0 | 67 | { |
michael@0 | 68 | return GetPixelDepth ( aColorDepth ); |
michael@0 | 69 | |
michael@0 | 70 | } // GetColorDepth |
michael@0 | 71 | |
michael@0 | 72 | |
michael@0 | 73 | void |
michael@0 | 74 | nsScreenGtk :: Init (GdkWindow *aRootWindow) |
michael@0 | 75 | { |
michael@0 | 76 | // We listen for configure events on the root window to pick up |
michael@0 | 77 | // changes to this rect. We could listen for "size_changed" signals |
michael@0 | 78 | // on the default screen to do this, except that doesn't work with |
michael@0 | 79 | // versions of GDK predating the GdkScreen object. See bug 256646. |
michael@0 | 80 | mAvailRect = mRect = nsIntRect(0, 0, gdk_screen_width(), gdk_screen_height()); |
michael@0 | 81 | |
michael@0 | 82 | #ifdef MOZ_X11 |
michael@0 | 83 | // We need to account for the taskbar, etc in the available rect. |
michael@0 | 84 | // See http://freedesktop.org/Standards/wm-spec/index.html#id2767771 |
michael@0 | 85 | |
michael@0 | 86 | // XXX do we care about _NET_WM_STRUT_PARTIAL? That will |
michael@0 | 87 | // add much more complexity to the code here (our screen |
michael@0 | 88 | // could have a non-rectangular shape), but should |
michael@0 | 89 | // lead to greater accuracy. |
michael@0 | 90 | |
michael@0 | 91 | long *workareas; |
michael@0 | 92 | GdkAtom type_returned; |
michael@0 | 93 | int format_returned; |
michael@0 | 94 | int length_returned; |
michael@0 | 95 | |
michael@0 | 96 | GdkAtom cardinal_atom = gdk_x11_xatom_to_atom(XA_CARDINAL); |
michael@0 | 97 | |
michael@0 | 98 | gdk_error_trap_push(); |
michael@0 | 99 | |
michael@0 | 100 | // gdk_property_get uses (length + 3) / 4, hence G_MAXLONG - 3 here. |
michael@0 | 101 | if (!gdk_property_get(aRootWindow, |
michael@0 | 102 | gdk_atom_intern ("_NET_WORKAREA", FALSE), |
michael@0 | 103 | cardinal_atom, |
michael@0 | 104 | 0, G_MAXLONG - 3, FALSE, |
michael@0 | 105 | &type_returned, |
michael@0 | 106 | &format_returned, |
michael@0 | 107 | &length_returned, |
michael@0 | 108 | (guchar **) &workareas)) { |
michael@0 | 109 | // This window manager doesn't support the freedesktop standard. |
michael@0 | 110 | // Nothing we can do about it, so assume full screen size. |
michael@0 | 111 | return; |
michael@0 | 112 | } |
michael@0 | 113 | |
michael@0 | 114 | // Flush the X queue to catch errors now. |
michael@0 | 115 | gdk_flush(); |
michael@0 | 116 | |
michael@0 | 117 | if (!gdk_error_trap_pop() && |
michael@0 | 118 | type_returned == cardinal_atom && |
michael@0 | 119 | length_returned && (length_returned % 4) == 0 && |
michael@0 | 120 | format_returned == 32) { |
michael@0 | 121 | int num_items = length_returned / sizeof(long); |
michael@0 | 122 | |
michael@0 | 123 | for (int i = 0; i < num_items; i += 4) { |
michael@0 | 124 | nsIntRect workarea(workareas[i], workareas[i + 1], |
michael@0 | 125 | workareas[i + 2], workareas[i + 3]); |
michael@0 | 126 | if (!mRect.Contains(workarea)) { |
michael@0 | 127 | // Note that we hit this when processing screen size changes, |
michael@0 | 128 | // since we'll get the configure event before the toolbars have |
michael@0 | 129 | // been moved. We'll end up cleaning this up when we get the |
michael@0 | 130 | // change notification to the _NET_WORKAREA property. However, |
michael@0 | 131 | // we still want to listen to both, so we'll handle changes |
michael@0 | 132 | // properly for desktop environments that don't set the |
michael@0 | 133 | // _NET_WORKAREA property. |
michael@0 | 134 | NS_WARNING("Invalid bounds"); |
michael@0 | 135 | continue; |
michael@0 | 136 | } |
michael@0 | 137 | |
michael@0 | 138 | mAvailRect.IntersectRect(mAvailRect, workarea); |
michael@0 | 139 | } |
michael@0 | 140 | } |
michael@0 | 141 | g_free (workareas); |
michael@0 | 142 | #endif |
michael@0 | 143 | } |
michael@0 | 144 | |
michael@0 | 145 | #ifdef MOZ_X11 |
michael@0 | 146 | void |
michael@0 | 147 | nsScreenGtk :: Init (XineramaScreenInfo *aScreenInfo) |
michael@0 | 148 | { |
michael@0 | 149 | nsIntRect xineRect(aScreenInfo->x_org, aScreenInfo->y_org, |
michael@0 | 150 | aScreenInfo->width, aScreenInfo->height); |
michael@0 | 151 | |
michael@0 | 152 | mScreenNum = aScreenInfo->screen_number; |
michael@0 | 153 | |
michael@0 | 154 | mAvailRect = mRect = xineRect; |
michael@0 | 155 | } |
michael@0 | 156 | #endif |