1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45

android_webview / browser / aw_enterprise_authentication_app_link_manager.cc [blame]

// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "android_webview/browser/aw_enterprise_authentication_app_link_manager.h"

#include "components/url_matcher/url_util.h"

namespace android_webview {

namespace prefs {
extern const char kEnterpriseAuthAppLinkPolicy[];
}

EnterpriseAuthenticationAppLinkManager::EnterpriseAuthenticationAppLinkManager(
    PrefService* pref_service) {
  pref_service_ = pref_service;
  pref_observer_.Init(pref_service);
  pref_observer_.Add(
      prefs::kEnterpriseAuthAppLinkPolicy,
      base::BindRepeating(
          &EnterpriseAuthenticationAppLinkManager::OnPolicyUpdated,
          base::Unretained(this)));

  // Call once to initialize the watcher with the current pref's values.
  OnPolicyUpdated();
}

EnterpriseAuthenticationAppLinkManager::
    ~EnterpriseAuthenticationAppLinkManager() = default;

void EnterpriseAuthenticationAppLinkManager::OnPolicyUpdated() {
  const base::Value::List& authentication_urls_policy =
      pref_service_->GetList(prefs::kEnterpriseAuthAppLinkPolicy);

  url_matcher_ = std::make_unique<url_matcher::URLMatcher>();
  url_matcher::util::AddAllowFiltersWithLimit(url_matcher_.get(),
                                              authentication_urls_policy);
}

bool EnterpriseAuthenticationAppLinkManager::IsEnterpriseAuthenticationUrl(
    const GURL& url) {
  return url_matcher_ && !(url_matcher_->MatchURL(url).empty());
}
}  // namespace android_webview