mobile/android/base/preferences/PrivateDataPreference.java

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/mobile/android/base/preferences/PrivateDataPreference.java	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,59 @@
     1.4 +/* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*-
     1.5 + * This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +package org.mozilla.gecko.preferences;
    1.10 +
    1.11 +import org.mozilla.gecko.GeckoAppShell;
    1.12 +import org.mozilla.gecko.GeckoEvent;
    1.13 +import org.mozilla.gecko.Telemetry;
    1.14 +import org.mozilla.gecko.TelemetryContract;
    1.15 +
    1.16 +import org.json.JSONException;
    1.17 +import org.json.JSONObject;
    1.18 +
    1.19 +import android.content.Context;
    1.20 +import android.util.AttributeSet;
    1.21 +import android.util.Log;
    1.22 +
    1.23 +class PrivateDataPreference extends MultiChoicePreference {
    1.24 +    private static final String LOGTAG = "GeckoPrivateDataPreference";
    1.25 +    private static final String PREF_KEY_PREFIX = "private.data.";
    1.26 +
    1.27 +    public PrivateDataPreference(Context context, AttributeSet attrs) {
    1.28 +        super(context, attrs);
    1.29 +    }
    1.30 +
    1.31 +    @Override
    1.32 +    protected void onDialogClosed(boolean positiveResult) {
    1.33 +        super.onDialogClosed(positiveResult);
    1.34 +
    1.35 +        if (!positiveResult)
    1.36 +            return;
    1.37 +
    1.38 +        Telemetry.sendUIEvent(TelemetryContract.Event.SANITIZE, TelemetryContract.Method.DIALOG);
    1.39 +
    1.40 +        CharSequence keys[] = getEntryKeys();
    1.41 +        boolean values[] = getValues();
    1.42 +        JSONObject json = new JSONObject();
    1.43 +
    1.44 +        for (int i = 0; i < keys.length; i++) {
    1.45 +            // Privacy pref checkbox values are stored in Android prefs to
    1.46 +            // remember their check states. The key names are private.data.X,
    1.47 +            // where X is a string from Gecko sanitization. This prefix is
    1.48 +            // removed here so we can send the values to Gecko, which then does
    1.49 +            // the sanitization for each key.
    1.50 +            String key = keys[i].toString().substring(PREF_KEY_PREFIX.length());
    1.51 +            boolean value = values[i];
    1.52 +            try {
    1.53 +                json.put(key, value);
    1.54 +            } catch (JSONException e) {
    1.55 +                Log.e(LOGTAG, "JSON error", e);
    1.56 +            }
    1.57 +        }
    1.58 +
    1.59 +        // clear private data in gecko
    1.60 +        GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("Sanitize:ClearData", json.toString()));
    1.61 +    }
    1.62 +}

mercurial