1 // Copyright 2015 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 package org.chromium.components.security_state; 6 7 import androidx.annotation.VisibleForTesting; 8 9 import org.chromium.base.annotations.NativeMethods; 10 import org.chromium.content_public.browser.WebContents; 11 12 /** 13 * Provides a way of accessing helpers for page security state. 14 */ 15 public class SecurityStateModel { 16 /** 17 * Fetch the security level for a given web contents. 18 * 19 * @param webContents The web contents to get the security level for. 20 * @return The ConnectionSecurityLevel for the specified web contents. 21 * 22 * @see ConnectionSecurityLevel 23 */ getSecurityLevelForWebContents(WebContents webContents)24 public static int getSecurityLevelForWebContents(WebContents webContents) { 25 if (webContents == null) return ConnectionSecurityLevel.NONE; 26 return SecurityStateModelJni.get().getSecurityLevelForWebContents(webContents); 27 } 28 isContentDangerous(WebContents webContents)29 public static boolean isContentDangerous(WebContents webContents) { 30 return getSecurityLevelForWebContents(webContents) == ConnectionSecurityLevel.DANGEROUS; 31 } 32 33 /** 34 * Returns whether to use a danger icon instead of an info icon in the URL bar for the WARNING 35 * security level. 36 * 37 * @return Whether to downgrade the info icon to a danger triangle for the WARNING security 38 * level. 39 */ shouldShowDangerTriangleForWarningLevel()40 public static boolean shouldShowDangerTriangleForWarningLevel() { 41 return SecurityStateModelJni.get().shouldShowDangerTriangleForWarningLevel(); 42 } 43 SecurityStateModel()44 private SecurityStateModel() {} 45 46 @NativeMethods 47 @VisibleForTesting 48 public interface Natives { getSecurityLevelForWebContents(WebContents webContents)49 int getSecurityLevelForWebContents(WebContents webContents); shouldShowDangerTriangleForWarningLevel()50 boolean shouldShowDangerTriangleForWarningLevel(); 51 } 52 } 53