hal/android/AndroidHal.cpp

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

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 "Hal.h"
michael@0 7 #include "HalImpl.h"
michael@0 8 #include "WindowIdentifier.h"
michael@0 9 #include "AndroidBridge.h"
michael@0 10 #include "mozilla/dom/network/Constants.h"
michael@0 11 #include "mozilla/dom/ScreenOrientation.h"
michael@0 12 #include "nsIScreenManager.h"
michael@0 13 #include "nsServiceManagerUtils.h"
michael@0 14
michael@0 15 using namespace mozilla::dom;
michael@0 16 using namespace mozilla::hal;
michael@0 17 using namespace mozilla::widget::android;
michael@0 18
michael@0 19 namespace mozilla {
michael@0 20 namespace hal_impl {
michael@0 21
michael@0 22 void
michael@0 23 Vibrate(const nsTArray<uint32_t> &pattern, const WindowIdentifier &)
michael@0 24 {
michael@0 25 // Ignore the WindowIdentifier parameter; it's here only because hal::Vibrate,
michael@0 26 // hal_sandbox::Vibrate, and hal_impl::Vibrate all must have the same
michael@0 27 // signature.
michael@0 28
michael@0 29 // Strangely enough, the Android Java API seems to treat vibrate([0]) as a
michael@0 30 // nop. But we want to treat vibrate([0]) like CancelVibrate! (Note that we
michael@0 31 // also need to treat vibrate([]) as a call to CancelVibrate.)
michael@0 32 bool allZero = true;
michael@0 33 for (uint32_t i = 0; i < pattern.Length(); i++) {
michael@0 34 if (pattern[i] != 0) {
michael@0 35 allZero = false;
michael@0 36 break;
michael@0 37 }
michael@0 38 }
michael@0 39
michael@0 40 if (allZero) {
michael@0 41 hal_impl::CancelVibrate(WindowIdentifier());
michael@0 42 return;
michael@0 43 }
michael@0 44
michael@0 45 AndroidBridge* b = AndroidBridge::Bridge();
michael@0 46 if (!b) {
michael@0 47 return;
michael@0 48 }
michael@0 49
michael@0 50 b->Vibrate(pattern);
michael@0 51 }
michael@0 52
michael@0 53 void
michael@0 54 CancelVibrate(const WindowIdentifier &)
michael@0 55 {
michael@0 56 // Ignore WindowIdentifier parameter.
michael@0 57
michael@0 58 mozilla::widget::android::GeckoAppShell::CancelVibrate();
michael@0 59 }
michael@0 60
michael@0 61 void
michael@0 62 EnableBatteryNotifications()
michael@0 63 {
michael@0 64 mozilla::widget::android::GeckoAppShell::EnableBatteryNotifications();
michael@0 65 }
michael@0 66
michael@0 67 void
michael@0 68 DisableBatteryNotifications()
michael@0 69 {
michael@0 70 mozilla::widget::android::GeckoAppShell::DisableBatteryNotifications();
michael@0 71 }
michael@0 72
michael@0 73 void
michael@0 74 GetCurrentBatteryInformation(hal::BatteryInformation* aBatteryInfo)
michael@0 75 {
michael@0 76 AndroidBridge::Bridge()->GetCurrentBatteryInformation(aBatteryInfo);
michael@0 77 }
michael@0 78
michael@0 79 void
michael@0 80 EnableNetworkNotifications()
michael@0 81 {
michael@0 82 mozilla::widget::android::GeckoAppShell::EnableNetworkNotifications();
michael@0 83 }
michael@0 84
michael@0 85 void
michael@0 86 DisableNetworkNotifications()
michael@0 87 {
michael@0 88 mozilla::widget::android::GeckoAppShell::DisableNetworkNotifications();
michael@0 89 }
michael@0 90
michael@0 91 void
michael@0 92 GetCurrentNetworkInformation(hal::NetworkInformation* aNetworkInfo)
michael@0 93 {
michael@0 94 AndroidBridge::Bridge()->GetCurrentNetworkInformation(aNetworkInfo);
michael@0 95 }
michael@0 96
michael@0 97 void
michael@0 98 EnableScreenConfigurationNotifications()
michael@0 99 {
michael@0 100 mozilla::widget::android::GeckoAppShell::EnableScreenOrientationNotifications();
michael@0 101 }
michael@0 102
michael@0 103 void
michael@0 104 DisableScreenConfigurationNotifications()
michael@0 105 {
michael@0 106 mozilla::widget::android::GeckoAppShell::DisableScreenOrientationNotifications();
michael@0 107 }
michael@0 108
michael@0 109 void
michael@0 110 GetCurrentScreenConfiguration(ScreenConfiguration* aScreenConfiguration)
michael@0 111 {
michael@0 112 AndroidBridge* bridge = AndroidBridge::Bridge();
michael@0 113 if (!bridge) {
michael@0 114 return;
michael@0 115 }
michael@0 116
michael@0 117 nsresult rv;
michael@0 118 nsCOMPtr<nsIScreenManager> screenMgr =
michael@0 119 do_GetService("@mozilla.org/gfx/screenmanager;1", &rv);
michael@0 120 if (NS_FAILED(rv)) {
michael@0 121 NS_ERROR("Can't find nsIScreenManager!");
michael@0 122 return;
michael@0 123 }
michael@0 124
michael@0 125 nsIntRect rect;
michael@0 126 int32_t colorDepth, pixelDepth;
michael@0 127 ScreenOrientation orientation;
michael@0 128 nsCOMPtr<nsIScreen> screen;
michael@0 129
michael@0 130 screenMgr->GetPrimaryScreen(getter_AddRefs(screen));
michael@0 131 screen->GetRect(&rect.x, &rect.y, &rect.width, &rect.height);
michael@0 132 screen->GetColorDepth(&colorDepth);
michael@0 133 screen->GetPixelDepth(&pixelDepth);
michael@0 134 orientation = static_cast<ScreenOrientation>(bridge->GetScreenOrientation());
michael@0 135
michael@0 136 *aScreenConfiguration =
michael@0 137 hal::ScreenConfiguration(rect, orientation, colorDepth, pixelDepth);
michael@0 138 }
michael@0 139
michael@0 140 bool
michael@0 141 LockScreenOrientation(const ScreenOrientation& aOrientation)
michael@0 142 {
michael@0 143 switch (aOrientation) {
michael@0 144 // The Android backend only supports these orientations.
michael@0 145 case eScreenOrientation_PortraitPrimary:
michael@0 146 case eScreenOrientation_PortraitSecondary:
michael@0 147 case eScreenOrientation_PortraitPrimary | eScreenOrientation_PortraitSecondary:
michael@0 148 case eScreenOrientation_LandscapePrimary:
michael@0 149 case eScreenOrientation_LandscapeSecondary:
michael@0 150 case eScreenOrientation_LandscapePrimary | eScreenOrientation_LandscapeSecondary:
michael@0 151 case eScreenOrientation_Default:
michael@0 152 mozilla::widget::android::GeckoAppShell::LockScreenOrientation(aOrientation);
michael@0 153 return true;
michael@0 154 default:
michael@0 155 return false;
michael@0 156 }
michael@0 157 }
michael@0 158
michael@0 159 void
michael@0 160 UnlockScreenOrientation()
michael@0 161 {
michael@0 162 mozilla::widget::android::GeckoAppShell::UnlockScreenOrientation();
michael@0 163 }
michael@0 164
michael@0 165 } // hal_impl
michael@0 166 } // mozilla
michael@0 167

mercurial