Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*- |
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 | package org.mozilla.gecko; |
michael@0 | 7 | |
michael@0 | 8 | import org.json.JSONObject; |
michael@0 | 9 | |
michael@0 | 10 | import android.text.TextUtils; |
michael@0 | 11 | |
michael@0 | 12 | public class SiteIdentity { |
michael@0 | 13 | private SecurityMode mSecurityMode; |
michael@0 | 14 | private String mHost; |
michael@0 | 15 | private String mOwner; |
michael@0 | 16 | private String mSupplemental; |
michael@0 | 17 | private String mVerifier; |
michael@0 | 18 | private String mEncrypted; |
michael@0 | 19 | |
michael@0 | 20 | // The order of the items here correspond to image |
michael@0 | 21 | // levels in site_security_level.xml |
michael@0 | 22 | public enum SecurityMode { |
michael@0 | 23 | UNKNOWN("unknown"), |
michael@0 | 24 | IDENTIFIED("identified"), |
michael@0 | 25 | VERIFIED("verified"), |
michael@0 | 26 | MIXED_CONTENT_BLOCKED("mixed_content_blocked"), |
michael@0 | 27 | MIXED_CONTENT_LOADED("mixed_content_loaded"); |
michael@0 | 28 | |
michael@0 | 29 | private final String mId; |
michael@0 | 30 | |
michael@0 | 31 | private SecurityMode(String id) { |
michael@0 | 32 | mId = id; |
michael@0 | 33 | } |
michael@0 | 34 | |
michael@0 | 35 | public static SecurityMode fromString(String id) { |
michael@0 | 36 | if (id == null) { |
michael@0 | 37 | throw new IllegalArgumentException("Can't convert null String to SiteIdentity"); |
michael@0 | 38 | } |
michael@0 | 39 | |
michael@0 | 40 | for (SecurityMode mode : SecurityMode.values()) { |
michael@0 | 41 | if (TextUtils.equals(mode.mId, id.toLowerCase())) { |
michael@0 | 42 | return mode; |
michael@0 | 43 | } |
michael@0 | 44 | } |
michael@0 | 45 | |
michael@0 | 46 | throw new IllegalArgumentException("Could not convert String id to SiteIdentity"); |
michael@0 | 47 | } |
michael@0 | 48 | |
michael@0 | 49 | @Override |
michael@0 | 50 | public String toString() { |
michael@0 | 51 | return mId; |
michael@0 | 52 | } |
michael@0 | 53 | } |
michael@0 | 54 | |
michael@0 | 55 | public SiteIdentity() { |
michael@0 | 56 | reset(SecurityMode.UNKNOWN); |
michael@0 | 57 | } |
michael@0 | 58 | |
michael@0 | 59 | private void reset(SecurityMode securityMode) { |
michael@0 | 60 | mSecurityMode = securityMode; |
michael@0 | 61 | mHost = null; |
michael@0 | 62 | mOwner = null; |
michael@0 | 63 | mSupplemental = null; |
michael@0 | 64 | mVerifier = null; |
michael@0 | 65 | mEncrypted = null; |
michael@0 | 66 | } |
michael@0 | 67 | |
michael@0 | 68 | void update(JSONObject identityData) { |
michael@0 | 69 | try { |
michael@0 | 70 | mSecurityMode = SecurityMode.fromString(identityData.getString("mode")); |
michael@0 | 71 | } catch (Exception e) { |
michael@0 | 72 | reset(SecurityMode.UNKNOWN); |
michael@0 | 73 | return; |
michael@0 | 74 | } |
michael@0 | 75 | |
michael@0 | 76 | try { |
michael@0 | 77 | mHost = identityData.getString("host"); |
michael@0 | 78 | mOwner = identityData.getString("owner"); |
michael@0 | 79 | mSupplemental = identityData.optString("supplemental", null); |
michael@0 | 80 | mVerifier = identityData.getString("verifier"); |
michael@0 | 81 | mEncrypted = identityData.getString("encrypted"); |
michael@0 | 82 | } catch (Exception e) { |
michael@0 | 83 | reset(mSecurityMode); |
michael@0 | 84 | } |
michael@0 | 85 | } |
michael@0 | 86 | |
michael@0 | 87 | public SecurityMode getSecurityMode() { |
michael@0 | 88 | return mSecurityMode; |
michael@0 | 89 | } |
michael@0 | 90 | |
michael@0 | 91 | public String getHost() { |
michael@0 | 92 | return mHost; |
michael@0 | 93 | } |
michael@0 | 94 | |
michael@0 | 95 | public String getOwner() { |
michael@0 | 96 | return mOwner; |
michael@0 | 97 | } |
michael@0 | 98 | |
michael@0 | 99 | public String getSupplemental() { |
michael@0 | 100 | return mSupplemental; |
michael@0 | 101 | } |
michael@0 | 102 | |
michael@0 | 103 | public String getVerifier() { |
michael@0 | 104 | return mVerifier; |
michael@0 | 105 | } |
michael@0 | 106 | |
michael@0 | 107 | public String getEncrypted() { |
michael@0 | 108 | return mEncrypted; |
michael@0 | 109 | } |
michael@0 | 110 | } |