chromium/chrome/updater/app/server/win/BUILD.gn

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

import("//build/toolchain/win/midl.gni")
import("//chrome/updater/branding.gni")
import("//chrome/version.gni")

# Processes IDL template files into a new IDL template with distinct user and
# system identities for interfaces that are decorated with `BEGIN_INTERFACE` and
# `END_INTERFACE`.
template("generate_user_system_idl") {
  assert(defined(invoker.idl_template_filename),
         "Need `idl_template_filename` in $target_name.")

  action(target_name) {
    script = "generate_user_system_idl.py"
    inputs = [
      script,
      invoker.idl_template_filename,
    ]

    idl_filename = invoker.idl_template_filename
    if (invoker.generate_for != "") {
      idl_filename = get_path_info(invoker.idl_template_filename, "name") +
                     "_" + invoker.generate_for + "." +
                     get_path_info(invoker.idl_template_filename, "extension")
    }

    output_file = "${target_gen_dir}/${idl_filename}"
    args = [
      "--idl_template_file",
      rebase_path(invoker.idl_template_filename, root_build_dir),
      "--idl_output_file",
      rebase_path(output_file, root_build_dir),
    ]
    if (invoker.generate_for != "") {
      args += [
        "--generate_for",
        invoker.generate_for,
      ]
    }
    outputs = [ output_file ]
  }
}

template("midl_user_system_idl") {
  assert(defined(invoker.replacement_guids),
         "Need `replacement_guids` in $target_name for placeholder guids.")

  foreach(scope,
          [
            "",
            "user",
            "system",
          ]) {
    midl_target_name = target_name
    if (scope != "") {
      midl_target_name = target_name + "_" + scope
    }
    target_name_generate = midl_target_name + "_gen"
    target_name_template = target_name + ".template"

    generate_user_system_idl(target_name_generate) {
      idl_template_filename = target_name_template
      generate_for = scope
    }

    midl(midl_target_name) {
      dynamic_guids = "ignore_proxy_stub," + invoker.replacement_guids
      sources = get_target_outputs(":$target_name_generate")
      writes_tlb = true
      deps = [ ":$target_name_generate" ]
    }
  }
}

# These GUIDs must depend on branding only.
branding_only_placeholder_guids = [
  "PLACEHOLDER-GUID-69464FF0-D9EC-4037-A35F-8AE4358106CC",  # UpdaterLib

  "PLACEHOLDER-GUID-158428a4-6014-4978-83ba-9fad0dabe791",  # UpdaterUserClass
  "PLACEHOLDER-GUID-415FD747-D79E-42D7-93AC-1BA6E5FD4E93",  # UpdaterSystemClass

  "PLACEHOLDER-GUID-63B8FFB1-5314-48C9-9C57-93EC8BC6184B",  # IUpdater
  "PLACEHOLDER-GUID-02AFCB67-0899-4676-91A9-67D92B3B7918",  # IUpdaterUser
  "PLACEHOLDER-GUID-FCE335F3-A55C-496E-814F-85971C9FA6F1",  # IUpdaterSystem

  "PLACEHOLDER-GUID-46ACF70B-AC13-406D-B53B-B2C4BF091FF6",  # IUpdateState
  "PLACEHOLDER-GUID-C3485D9F-C684-4C43-B85B-E339EA395C29",  # IUpdateStateUser
  "PLACEHOLDER-GUID-EA6FDC05-CDC5-4EA4-AB41-CCBD1040A2B5",  # IUpdateStateSystem

  "PLACEHOLDER-GUID-2FCD14AF-B645-4351-8359-E80A0E202A0B",  # ICompleteStatus
  "PLACEHOLDER-GUID-9AD1A645-5A4B-4D36-BC21-F0059482E6EA",  # ICompleteStatusUser
  "PLACEHOLDER-GUID-E2BD9A6B-0A19-4C89-AE8B-B7E9E51D9A07",  # ICompleteStatusSystem

  "PLACEHOLDER-GUID-7B416CFD-4216-4FD6-BD83-7C586054676E",  # IUpdaterObserver
  "PLACEHOLDER-GUID-B54493A0-65B7-408C-B650-06265D2182AC",  # IUpdaterObserverUser
  "PLACEHOLDER-GUID-057B500A-4BA2-496A-B1CD-C5DED3CCC61B",  # IUpdaterObserverSystem

  "PLACEHOLDER-GUID-8BAB6F84-AD67-4819-B846-CC890880FD3B",  # IUpdaterCallback
  "PLACEHOLDER-GUID-34ADC89D-552B-4102-8AE5-D613A691335B",  # IUpdaterCallbackUser
  "PLACEHOLDER-GUID-F0D6763A-0182-4136-B1FA-508E334CFFC1",  # IUpdaterCallbackSystem

  "PLACEHOLDER-GUID-A22AFC54-2DEF-4578-9187-DB3B24381090",  # IUpdaterAppState
  "PLACEHOLDER-GUID-028FEB84-44BC-4A73-A0CD-603678155CC3",  # IUpdaterAppStateUser
  "PLACEHOLDER-GUID-92631531-8044-46F4-B645-CDFBCCC7FA3B",  # IUpdaterAppStateSystem

  "PLACEHOLDER-GUID-EFE903C0-E820-4136-9FAE-FDCD7F256302",  # IUpdaterAppStatesCallback
  "PLACEHOLDER-GUID-BCFCF95C-DE48-4F42-B0E9-D50DB407DB53",  # IUpdaterAppStatesCallbackUser
  "PLACEHOLDER-GUID-2CB8867E-495E-459F-B1B6-2DD7FFDBD462",  # IUpdaterAppStatesCallbackSystem
]

uuid5_guids = []
foreach(guid, branding_only_placeholder_guids) {
  uuid5_guids += [ guid + "=uuid5:$updater_product_full_name" ]
}
uuid5_guids = string_join(",", uuid5_guids)

midl_user_system_idl("updater_idl") {
  replacement_guids = uuid5_guids
}

# These GUIDs must depend on branding and version.
branding_version_placeholder_guids = [
  "PLACEHOLDER-GUID-C6CE92DB-72CA-42EF-8C98-6EE92481B3C9",  # UpdaterInternalLib
  "PLACEHOLDER-GUID-1F87FE2F-D6A9-4711-9D11-8187705F8457",  # UpdaterInternalUserClass
  "PLACEHOLDER-GUID-4556BA55-517E-4F03-8016-331A43C269C9",  # UpdaterInternalSystemClass
  "PLACEHOLDER-GUID-526DA036-9BD3-4697-865A-DA12D37DFFCA",  # IUpdaterInternal
  "PLACEHOLDER-GUID-C82AFDA3-CA76-46EE-96E9-474717BFA7BA",  # IUpdaterInternalUser
  "PLACEHOLDER-GUID-E690EB97-6E46-4361-AF8F-90A4F5496475",  # IUpdaterInternalSystem
  "PLACEHOLDER-GUID-D272C794-2ACE-4584-B993-3B90C622BE65",  # IUpdaterInternalCallback
  "PLACEHOLDER-GUID-618D9B82-9F51-4490-AF24-BB80489E1537",  # IUpdaterInternalCallbackUser
  "PLACEHOLDER-GUID-7E806C73-B2A4-4BC5-BDAD-2249D87F67FC",  # IUpdaterInternalCallbackSystem
]

uuid5_guids = []
foreach(guid, branding_version_placeholder_guids) {
  uuid5_guids +=
      [ guid + "=uuid5:$updater_product_full_name$chrome_version_full" ]
}
uuid5_guids = string_join(",", uuid5_guids)

midl_user_system_idl("updater_internal_idl") {
  replacement_guids = uuid5_guids
}

updater_legacy_idl_guids = [
  "PLACEHOLDER-GUID-7A1FDE1F-AAA9-441B-B9AA-95B31D78592B=$UpdaterLegacyLibGUID",
  "PLACEHOLDER-GUID-A0FEB7CB-E0D8-4035-A4C9-5620A8C725AD=$GoogleUpdate3WebUserClassGUID",
  "PLACEHOLDER-GUID-FAC5C548-84EC-474C-A4B3-CD414E09B14C=$GoogleUpdate3WebSystemClassGUID",
  "PLACEHOLDER-GUID-687DCE9A-57BE-4026-BEC4-C0A9ACBBCAF2=$GoogleUpdate3WebServiceClassGUID",
  "PLACEHOLDER-GUID-E432DCFE-6A32-4C07-B038-9D74AC80D6AB=$PolicyStatusUserClassGUID",
  "PLACEHOLDER-GUID-F675D224-BD54-40E9-AECB-AA3B64EB9863=$PolicyStatusSystemClassGUID",
  "PLACEHOLDER-GUID-CEC2877D-4856-460E-BE73-11DD7CC7C821=$ProcessLauncherClassGUID",

  "PLACEHOLDER-GUID-AA10D17D-7A09-48AC-B1E4-F124937E3D26=$IAppVersionWebGUID",
  "PLACEHOLDER-GUID-AC817E10-993C-470F-8DCA-25F53D70EA8D=$IAppVersionWebUserGUID",
  "PLACEHOLDER-GUID-9367601E-C100-4702-8755-808D6BB385D8=$IAppVersionWebSystemGUID",

  "PLACEHOLDER-GUID-A643508B-B1E3-4457-9769-32C953BD1D57=$ICurrentStateGUID",
  "PLACEHOLDER-GUID-31479718-D170-467B-9274-27FC3E88CB76=$ICurrentStateUserGUID",
  "PLACEHOLDER-GUID-71CBC6BB-CA4B-4B5A-83C0-FC95F9CA6A30=$ICurrentStateSystemGUID",

  "PLACEHOLDER-GUID-A35E1C5E-0A18-4FF1-8C4D-DD8ED07B0BD0=$IGoogleUpdate3WebGUID",
  "PLACEHOLDER-GUID-EE8EE731-C592-4A4F-9774-BB04337B8F46=$IGoogleUpdate3WebUserGUID",
  "PLACEHOLDER-GUID-AE5F8C9D-B94D-4367-A422-D1DC4E913A52=$IGoogleUpdate3WebSystemGUID",

  "PLACEHOLDER-GUID-0569DBB9-BAA0-48D5-8543-0F3BE30A1648=$IAppBundleWebGUID",
  "PLACEHOLDER-GUID-CE7A37FD-A255-460C-BAF1-708765EB76EC=$IAppBundleWebUserGUID",
  "PLACEHOLDER-GUID-BFFD766D-A2DD-436E-89FA-BF05BC5B5958=$IAppBundleWebSystemGUID",

  "PLACEHOLDER-GUID-63D941DE-F67B-4E15-8A90-27881DA9EF4A=$IAppWebGUID",
  "PLACEHOLDER-GUID-47B9D508-CB72-4F8B-AF00-7D0143603B25=$IAppWebUserGUID",
  "PLACEHOLDER-GUID-540B227A-F442-45D5-BA52-298A05BAF1A8=$IAppWebSystemGUID",

  "PLACEHOLDER-GUID-10A2D03F-8BC7-49DB-A21E-A7D4429D2759=$IAppCommandWebGUID",
  "PLACEHOLDER-GUID-5515E66F-FA6F-4D74-B5EA-4FCFDA16FE12=$IAppCommandWebUserGUID",
  "PLACEHOLDER-GUID-C6E2C5D5-86FA-4A64-9D08-8C9B644F0E49=$IAppCommandWebSystemGUID",

  "PLACEHOLDER-GUID-6A54FE75-EDC8-404E-A41B-4278C0557151=$IPolicyStatusGUID",
  "PLACEHOLDER-GUID-EF739C0C-40B0-478D-B76B-3659B8F2B0EB=$IPolicyStatusUserGUID",
  "PLACEHOLDER-GUID-F3964464-A939-44D3-9244-36BD2E3630B8=$IPolicyStatusSystemGUID",

  "PLACEHOLDER-GUID-06A6AA1E-2680-4076-A7CD-6053722CF454=$IPolicyStatus2GUID",
  "PLACEHOLDER-GUID-AD91C851-86AC-499F-9BA9-9A561744AA4D=$IPolicyStatus2UserGUID",
  "PLACEHOLDER-GUID-F4A0362A-3702-48B8-9896-7D8013D03AB2=$IPolicyStatus2SystemGUID",

  "PLACEHOLDER-GUID-029BD175-5035-4E2A-8724-C9D47F4FAEA3=$IPolicyStatus3GUID",
  "PLACEHOLDER-GUID-BC39E1E1-E8FA-4E72-903F-3BF346E7E165=$IPolicyStatus3UserGUID",
  "PLACEHOLDER-GUID-7B26CC23-B2B8-441B-AA9C-8B551ABB611B=$IPolicyStatus3SystemGUID",

  "PLACEHOLDER-GUID-C07BC046-32E0-4184-BC9F-13C4533C24AC=$IPolicyStatus4GUID",
  "PLACEHOLDER-GUID-0F6696F3-7F48-446B-97FA-6B34EC2ADB32=$IPolicyStatus4UserGUID",
  "PLACEHOLDER-GUID-423FDEC3-0DBC-441E-B51D-FD8B82B9DCF2=$IPolicyStatus4SystemGUID",

  "PLACEHOLDER-GUID-2A7D2AE7-8EEE-45B4-B17F-31DAAC82CCBB=$IPolicyStatusValueGUID",
  "PLACEHOLDER-GUID-7E0A6B39-7CEB-4944-ABFA-F419D201D6A0=$IPolicyStatusValueUserGUID",
  "PLACEHOLDER-GUID-CC2CCD05-119C-44E1-852D-6DCC2DFB72EC=$IPolicyStatusValueSystemGUID",

  "PLACEHOLDER-GUID-4779D540-F6A3-455F-A929-7ADFE85B6F09=$IProcessLauncherGUID",
  "PLACEHOLDER-GUID-FFBAEC45-C5EC-4287-85CD-A831796BE952=$IProcessLauncherSystemGUID",

  "PLACEHOLDER-GUID-74F243B8-75D1-4E2D-BC89-5689798EEF3E=$IProcessLauncher2GUID",
  "PLACEHOLDER-GUID-5F41DC50-029C-4F5A-9860-EF352A0B66D2=$IProcessLauncher2SystemGUID",
]
updater_legacy_idl_guids = string_join(",", updater_legacy_idl_guids)

midl_user_system_idl("updater_legacy_idl") {
  replacement_guids = updater_legacy_idl_guids
}

# The COM server needs to work with Windows 7, so explicitly setting the defines
# to reflect this. Otherwise, WRL uses APIs that are only available in later
# Windows versions.
config("winver") {
  defines = [
    "NTDDI_VERSION=NTDDI_WIN7",

    # Hardcoding version 0x0601, since _WIN32_WINNT_WIN7 may not be defined.
    "_WIN32_WINNT=0x0601",
    "WINVER=0x0601",
  ]
}