michael@0: /* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*- michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: package org.mozilla.gecko.preferences; michael@0: michael@0: import org.mozilla.gecko.GeckoAppShell; michael@0: import org.mozilla.gecko.GeckoEvent; michael@0: import org.mozilla.gecko.Telemetry; michael@0: import org.mozilla.gecko.TelemetryContract; michael@0: michael@0: import org.json.JSONException; michael@0: import org.json.JSONObject; michael@0: michael@0: import android.content.Context; michael@0: import android.util.AttributeSet; michael@0: import android.util.Log; michael@0: michael@0: class PrivateDataPreference extends MultiChoicePreference { michael@0: private static final String LOGTAG = "GeckoPrivateDataPreference"; michael@0: private static final String PREF_KEY_PREFIX = "private.data."; michael@0: michael@0: public PrivateDataPreference(Context context, AttributeSet attrs) { michael@0: super(context, attrs); michael@0: } michael@0: michael@0: @Override michael@0: protected void onDialogClosed(boolean positiveResult) { michael@0: super.onDialogClosed(positiveResult); michael@0: michael@0: if (!positiveResult) michael@0: return; michael@0: michael@0: Telemetry.sendUIEvent(TelemetryContract.Event.SANITIZE, TelemetryContract.Method.DIALOG); michael@0: michael@0: CharSequence keys[] = getEntryKeys(); michael@0: boolean values[] = getValues(); michael@0: JSONObject json = new JSONObject(); michael@0: michael@0: for (int i = 0; i < keys.length; i++) { michael@0: // Privacy pref checkbox values are stored in Android prefs to michael@0: // remember their check states. The key names are private.data.X, michael@0: // where X is a string from Gecko sanitization. This prefix is michael@0: // removed here so we can send the values to Gecko, which then does michael@0: // the sanitization for each key. michael@0: String key = keys[i].toString().substring(PREF_KEY_PREFIX.length()); michael@0: boolean value = values[i]; michael@0: try { michael@0: json.put(key, value); michael@0: } catch (JSONException e) { michael@0: Log.e(LOGTAG, "JSON error", e); michael@0: } michael@0: } michael@0: michael@0: // clear private data in gecko michael@0: GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("Sanitize:ClearData", json.toString())); michael@0: } michael@0: }