// Copyright (c) 2018 GitHub, Inc.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.

#include <string>

#include "atom/app/command_line_args.h"

#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "content/public/common/content_switches.h"

namespace {

bool IsUrlArg(const base::CommandLine::CharType* arg) {
  // the first character must be a letter for this to be a URL
  auto c = *arg;
  if (('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z')) {
    for (auto p = arg + 1; *p; ++p) {
      c = *p;

      // colon indicates that the argument starts with a URI scheme
      if (c == ':') {
        // it could also be a Windows filesystem path
        if (p == arg + 1)
          break;

        return true;
      }

      // white-space before a colon means it's not a URL
      if (c == ' ' || (0x9 <= c && c <= 0xD))
        break;
    }
  }

  return false;
}

const char* blacklist[] = {
  // node
  "inspect",
  "inspect-brk",

  // chromium switches:
  // find ./ \( -name "*switches.cc" -o -name "*switch_list.h" \) \
  //  | xargs grep -P --no-filename '"\S+"[);]$' \
  //  | perl -pe 's|^.*?"(\S+)"[);]$|  "$1",|'; \
  //  | LANG="C" sort | uniq
  "/prefetch:1",
  "/prefetch:2",
  "/prefetch:3",
  "/prefetch:4",
  "/prefetch:5",
  "/prefetch:6",
  "/prefetch:8",
  "0",
  "?",
  "BlacklistOnly",
  "ChromeOSMemoryPressureHandling",
  "Disabled",
  "OnlineCheckOnly",
  "SafeSites",
  "accept-resource-provider",
  "adaboost",
  "aec-refined-adaptive-filter",
  "agc-startup-min-volume",
  "aggressive",
  "aggressive-cache-discard",
  "aggressive-tab-discard",
  "all-toolchains",
  "allow-cross-origin-auth-prompt",
  "allow-external-pages",
  "allow-failed-policy-fetch-for-test",
  "allow-file-access-from-files",
  "allow-hidden-media-playback",
  "allow-http-background-page",
  "allow-http-screen-capture",
  "allow-insecure-localhost",
  "allow-legacy-extension-manifests",
  "allow-loopback-in-peer-connection",
  "allow-nacl-crxfs-api",
  "allow-nacl-file-handle-api",
  "allow-nacl-socket-api",
  "allow-no-sandbox-job",
  "allow-outdated-plugins",
  "allow-ra-in-dev-mode",
  "allow-running-insecure-content",
  "allow-sandbox-debugging",
  "allow-silent-push",
  "alsa-check-close-timeout",
  "alsa-enable-upsampling",
  "alsa-fixed-output-sample-rate",
  "alsa-input-device",
  "alsa-mute-device-name",
  "alsa-mute-element-name",
  "alsa-output-avail-min",
  "alsa-output-buffer-size",
  "alsa-output-device",
  "alsa-output-period-size",
  "alsa-output-start-threshold",
  "alsa-volume-device-name",
  "alsa-volume-element-name",
  "also-emit-success-logs",
  "always-authorize-plugins",
  "always-on",
  "always-use-complex-text",
  "alwaystrue",
  "android-fonts-path",
  "android-stderr-port",
  "android-stdin-port",
  "android-stdout-port",
  "angle",
  "app",
  "app-auto-launched",
  "app-id",
  "app-mode-auth-code",
  "app-mode-oauth-token",
  "app-mode-oem-manifest",
  "app-shell-allow-roaming",
  "app-shell-host-window-size",
  "app-shell-preferred-network",
  "app-shell-refresh-token",
  "app-shell-user",
  "apple",
  "apps-gallery-download-url",
  "apps-gallery-update-url",
  "apps-gallery-url",
  "apps-keep-chrome-alive-in-tests",
  "arc-always-start",
  "arc-availability",
  "arc-available",
  "args",
  "artifacts-dir",
  "ash-adjustable-large-cursor",
  "ash-animate-from-boot-splash-screen",
  "ash-constrain-pointer-to-root",
  "ash-copy-host-background-at-boot",
  "ash-debug-shortcuts",
  "ash-dev-shortcuts",
  "ash-disable-maximize-mode-window-backdrop",
  "ash-disable-screen-orientation-lock",
  "ash-disable-touch-exploration-mode",
  "ash-enable-magnifier-key-scroller",
  "ash-enable-mirrored-screen",
  "ash-enable-palette-on-all-displays",
  "ash-enable-smooth-screen-rotation",
  "ash-enable-software-mirroring",
  "ash-enable-unified-desktop",
  "ash-estimated-presentation-delay",
  "ash-force-enable-palette",
  "ash-hide-notifications-for-factory",
  "ash-host-window-bounds",
  "ash-shelf-color",
  "ash-shelf-color-scheme",
  "ash-touch-hud",
  "ash-webui-init",
  "attestation-server",
  "audio-buffer-size",
  "aura-legacy-power-button",
  "auth-ext-path",
  "auth-server-whitelist",
  "auth-spnego-account-type",
  "auto",
  "auto-open-devtools-for-tabs",
  "auto-select-desktop-capture-source",
  "blink-settings",
  "bootstrap",
  "browser-subprocess-path",
  "browser-test",
  "bwsi",
  "bypass-app-banner-engagement-checks",
  "canvas-msaa-sample-count",
  "cast-initial-screen-height",
  "cast-initial-screen-width",
  "cc-layer-tree-test-long-timeout",
  "cc-layer-tree-test-no-timeout",
  "cc-rebaseline-pixeltests",
  "cellular-first",
  "cellular-only",
  "check-for-update-interval",
  "check-layout-test-sys-deps",
  "child-process",
  "child-wallpaper-large",
  "child-wallpaper-small",
  "cipher-suite-blacklist",
  "clamshell",
  "class",
  "clear-token-service",
  "cloud-print-file",
  "cloud-print-file-type",
  "cloud-print-job-title",
  "cloud-print-print-ticket",
  "cloud-print-setup-proxy",
  "cloud-print-url",
  "cloud-print-xmpp-endpoint",
  "color",
  "compensate-for-unstable-pinch-zoom",
  "compile-shader-always-succeeds",
  "component-updater",
  "connectivity-check-url",
  "conservative",
  "content-image-texture-target",
  "content-shell-host-window-size",
  "controller",
  "crash-dumps-dir",
  "crash-on-failure",
  "crash-on-hang-threads",
  "crash-server-url",
  "crash-test",
  "crashpad-handler",
  "create-browser-on-startup-for-tests",
  "create-default-gl-context",
  "cros-region",
  "cros-regions-mode",
  "crosh-command",
  "cryptauth-http-host",
  "custom-devtools-frontend",
  "custom-launcher-page",
  "custom_summary",
  "d3d11",
  "d3d9",
  "daemon",
  "dark_muted",
  "dark_vibrant",
  "data-path",
  "data-reduction-proxy-config-url",
  "data-reduction-proxy-experiment",
  "data-reduction-proxy-http-proxies",
  "data-reduction-proxy-lo-fi",
  "data-reduction-proxy-pingback-url",
  "data-reduction-proxy-secure-proxy-check-url",
  "data-reduction-proxy-server-experiments-disabled",
  "data-reduction-proxy-warmup-url",
  "dbus-stub",
  "debug-devtools",
  "debug-enable-frame-toggle",
  "debug-packed-apps",
  "debug-print",
  "default",
  "default-background-color",
  "default-tile-height",
  "default-tile-width",
  "default-wallpaper-is-oem",
  "default-wallpaper-large",
  "default-wallpaper-small",
  "demo",
  "derelict-detection-timeout",
  "derelict-idle-timeout",
  "desktop",
  "desktop-window-1080p",
  "deterministic-fetch",
  "device-management-url",
  "device-scale-factor",
  "devtools-flags",
  "diagnostics",
  "diagnostics-format",
  "diagnostics-recovery",
  "disable",
  "disable-2d-canvas-clip-aa",
  "disable-2d-canvas-image-chromium",
  "disable-3d-apis",
  "disable-accelerated-2d-canvas",
  "disable-accelerated-jpeg-decoding",
  "disable-accelerated-mjpeg-decode",
  "disable-accelerated-video-decode",
  "disable-add-to-shelf",
  "disable-app-info-dialog-mac",
  "disable-app-list-dismiss-on-blur",
  "disable-app-window-cycling",
  "disable-appcontainer",
  "disable-arc-data-wipe",
  "disable-arc-opt-in-verification",
  "disable-audio-support-for-desktop-share",
  "disable-autofill-keyboard-accessory-view",
  "disable-avfoundation-overlays",
  "disable-background-networking",
  "disable-background-timer-throttling",
  "disable-backgrounding-occluded-windows",
  "disable-backing-store-limit",
  "disable-blink-features",
  "disable-boot-animation",
  "disable-breakpad",
  "disable-browser-task-scheduler",
  "disable-bundled-ppapi-flash",
  "disable-canvas-aa",
  "disable-captive-portal-bypass-proxy",
  "disable-cast-streaming-hw-encoding",
  "disable-clear-browsing-data-counters",
  "disable-client-side-phishing-detection",
  "disable-cloud-import",
  "disable-component-cloud-policy",
  "disable-component-extensions-with-background-pages",
  "disable-component-update",
  "disable-composited-antialiasing",
  "disable-contextual-search",
  "disable-d3d11",
  "disable-databases",
  "disable-datasaver-prompt",
  "disable-default-apps",
  "disable-demo-mode",
  "disable-device-disabling",
  "disable-device-discovery-notifications",
  "disable-dinosaur-easter-egg",
  "disable-direct-composition",
  "disable-direct-composition-layers",
  "disable-directwrite-for-ui",
  "disable-display-color-calibration",
  "disable-display-list-2d-canvas",
  "disable-distance-field-text",
  "disable-domain-blocking-for-3d-apis",
  "disable-domain-reliability",
  "disable-download-image-renaming",
  "disable-drive-search-in-app-launcher",
  "disable-dwm-composition",
  "disable-encryption-migration",
  "disable-eol-notification",
  "disable-es3-apis",
  "disable-es3-gl-context",
  "disable-extensions",
  "disable-extensions-except",
  "disable-extensions-file-access-check",
  "disable-extensions-http-throttling",
  "disable-fast-web-scroll-view-insets",
  "disable-features",
  "disable-field-trial-config",
  "disable-file-system",
  "disable-flash-3d",
  "disable-flash-stage3d",
  "disable-fullscreen-low-power-mode",
  "disable-fullscreen-tab-detaching",
  "disable-gaia-services",
  "disable-gesture-editing",
  "disable-gesture-requirement-for-media-playback",
  "disable-gesture-requirement-for-presentation",
  "disable-gesture-typing",
  "disable-gl-drawing-for-tests",
  "disable-gl-error-limit",
  "disable-gl-extensions",
  "disable-glsl-translator",
  "disable-gpu",
  "disable-gpu-async-worker-context",
  "disable-gpu-compositing",
  "disable-gpu-driver-bug-workarounds",
  "disable-gpu-early-init",
  "disable-gpu-memory-buffer-compositor-resources",
  "disable-gpu-memory-buffer-video-frames",
  "disable-gpu-process-crash-limit",
  "disable-gpu-program-cache",
  "disable-gpu-rasterization",
  "disable-gpu-sandbox",
  "disable-gpu-shader-disk-cache",
  "disable-gpu-vsync",
  "disable-gpu-watchdog",
  "disable-hang-monitor",
  "disable-hid-detection-on-oobe",
  "disable-hide-inactive-stacked-tab-close-buttons",
  "disable-histogram-customizer",
  "disable-hosted-app-shim-creation",
  "disable-hosted-apps-in-windows",
  "disable-http2",
  "disable-in-process-stack-traces",
  "disable-infobars",
  "disable-input-ime-api",
  "disable-input-view",
  "disable-ios-password-generation",
  "disable-ios-password-suggestions",
  "disable-ios-physical-web",
  "disable-javascript-harmony-shipping",
  "disable-kill-after-bad-ipc",
  "disable-lcd-text",
  "disable-legacy-window",
  "disable-local-storage",
  "disable-logging",
  "disable-login-animations",
  "disable-low-end-device-mode",
  "disable-low-latency-dxva",
  "disable-low-res-tiling",
  "disable-lru-snapshot-cache",
  "disable-mac-overlays",
  "disable-mac-views-native-app-windows",
  "disable-main-frame-before-activation",
  "disable-md-oobe",
  "disable-media-session-api",
  "disable-media-suspend",
  "disable-merge-key-char-events",
  "disable-minimize-on-second-launcher-item-click",
  "disable-mojo-renderer",
  "disable-mtp-write-support",
  "disable-multi-display-layout",
  "disable-namespace-sandbox",
  "disable-native-cups",
  "disable-native-gpu-memory-buffers",
  "disable-network-portal-notification",
  "disable-new-channel-switcher-ui",
  "disable-new-kiosk-ui",
  "disable-new-korean-ime",
  "disable-new-zip-unpacker",
  "disable-notifications",
  "disable-ntp-popular-sites",
  "disable-nv12-dxgi-video",
  "disable-offer-store-unmasked-wallet-cards",
  "disable-offer-upload-credit-cards",
  "disable-office-editing-component-extension",
  "disable-offline-auto-reload",
  "disable-offline-auto-reload-visible-only",
  "disable-overscroll-edge-effect",
  "disable-panel-fitting",
  "disable-partial-raster",
  "disable-password-generation",
  "disable-payment-request",
  "disable-pepper-3d",
  "disable-pepper-3d-image-chromium",
  "disable-per-monitor-dpi",
  "disable-permission-action-reporting",
  "disable-permissions-api",
  "disable-physical-keyboard-autocorrect",
  "disable-pinch",
  "disable-pnacl-crash-throttling",
  "disable-popup-blocking",
  "disable-prefer-compositing-to-lcd-text",
  "disable-presentation-api",
  "disable-print-preview",
  "disable-prompt-on-repost",
  "disable-pull-to-refresh-effect",
  "disable-push-api-background-mode",
  "disable-quic",
  "disable-reading-from-canvas",
  "disable-remote-core-animation",
  "disable-remote-fonts",
  "disable-remote-playback-api",
  "disable-renderer-accessibility",
  "disable-renderer-backgrounding",
  "disable-renderer-priority-management",
  "disable-resize-lock",
  "disable-rgba-4444-textures",
  "disable-rollback-option",
  "disable-rtc-smoothness-algorithm",
  "disable-screen-orientation-lock",
  "disable-search-geolocation-disclosure",
  "disable-seccomp-filter-sandbox",
  "disable-settings-window",
  "disable-setuid-sandbox",
  "disable-shader-name-hashing",
  "disable-shared-workers",
  "disable-signin-promo",
  "disable-signin-scoped-device-id",
  "disable-single-click-autofill",
  "disable-slimming-paint-invalidation",
  "disable-smart-virtual-keyboard",
  "disable-smooth-scrolling",
  "disable-software-rasterizer",
  "disable-speech-api",
  "disable-suggestions-ui",
  "disable-sync",
  "disable-sync-app-list",
  "disable-sync-types",
  "disable-system-timezone-automatic-detection",
  "disable-tab-for-desktop-share",
  "disable-tab-strip-autoscroll-new-tabs",
  "disable-threaded-animation",
  "disable-threaded-compositing",
  "disable-threaded-scrolling",
  "disable-touch-adjustment",
  "disable-touch-drag-drop",
  "disable-translate",
  "disable-translate-new-ux",
  "disable-usb-keyboard-detect",
  "disable-v8-idle-tasks",
  "disable-vaapi-accelerated-video-encode",
  "disable-views-rect-based-targeting",
  "disable-virtual-keyboard-overscroll",
  "disable-voice-input",
  "disable-volume-adjust-sound",
  "disable-wake-on-wifi",
  "disable-web-notification-custom-layouts",
  "disable-web-security",
  "disable-webgl",
  "disable-webgl-image-chromium",
  "disable-webrtc-encryption",
  "disable-webrtc-hw-decoding",
  "disable-webrtc-hw-encoding",
  "disable-webrtc-hw-vp8-encoding",
  "disable-win32k-lockdown",
  "disable-xss-auditor",
  "disable-zero-browsers-open-for-tests",
  "disable-zero-copy",
  "disable-zero-copy-dxgi-video",
  "disabled",
  "disk-cache-dir",
  "disk-cache-size",
  "display",
  "dmg-device",
  "dns-log-details",
  "dom-automation",
  "dotfile",
  "draw-view-bounds-rects",
  "duck-flash",
  "dump-browser-histograms",
  "dump-dom",
  "eafe-path",
  "eafe-url",
  "early-tracing",
  "easy-unlock-app-path",
  "edge-touch-filtering",
  "egl",
  "elevate",
  "embedded-extension-options",
  "emphasize-titles-in-omnibox-dropdown",
  "emulate-shader-precision",
  "enable-accelerated-2d-canvas",
  "enable-accelerated-vpx-decode",
  "enable-accessibility-tab-switcher",
  "enable-account-consistency",
  "enable-adaptive-selection-handle-orientation",
  "enable-add-to-shelf",
  "enable-aggressive-domstorage-flushing",
  "enable-android-wallpapers-app",
  "enable-app-info-dialog-mac",
  "enable-app-list",
  "enable-app-window-cycling",
  "enable-appcontainer",
  "enable-arc",
  "enable-arc-oobe-optin",
  "enable-audio-debug-recordings-from-extension",
  "enable-autofill-keyboard-accessory-view",
  "enable-automation",
  "enable-benchmarking",
  "enable-ble-advertising-in-apps",
  "enable-blink-features",
  "enable-bookmark-undo",
  "enable-browser-side-navigation",
  "enable-browser-task-scheduler",
  "enable-canvas-2d-dynamic-rendering-mode-switching",
  "enable-checker-imaging",
  "enable-chromevox-arc-support",
  "enable-clear-browsing-data-counters",
  "enable-cloud-print-proxy",
  "enable-cloud-print-xps",
  "enable-color-correct-rendering",
  "enable-color-correct-rendering-default-mode",
  "enable-consumer-kiosk",
  "enable-contextual-search",
  "enable-crash-reporter",
  "enable-crash-reporter-for-testing",
  "enable-crx-hash-check",
  "enable-data-reduction-proxy-bypass-warning",
  "enable-data-reduction-proxy-carrier-test",
  "enable-data-reduction-proxy-force-pingback",
  "enable-data-reduction-proxy-lite-page",
  "enable-data-reduction-proxy-savings-promo",
  "enable-datasaver-prompt",
  "enable-default-media-session",
  "enable-device-discovery-notifications",
  "enable-devtools-experiments",
  "enable-direct-composition-layers",
  "enable-display-list-2d-canvas",
  "enable-distance-field-text",
  "enable-distillability-service",
  "enable-dom-distiller",
  "enable-domain-reliability",
  "enable-download-image-renaming",
  "enable-drive-search-in-app-launcher",
  "enable-drm-atomic",
  "enable-embedded-extension-options",
  "enable-encryption-migration",
  "enable-es3-apis",
  "enable-exclusive-audio",
  "enable-experimental-accessibility-features",
  "enable-experimental-canvas-features",
  "enable-experimental-extension-apis",
  "enable-experimental-input-view-features",
  "enable-experimental-web-platform-features",
  "enable-extension-activity-log-testing",
  "enable-extension-activity-logging",
  "enable-extension-assets-sharing",
  "enable-fast-unload",
  "enable-fast-web-scroll-view-insets",
  "enable-features",
  "enable-first-run-ui-transitions",
  "enable-floating-virtual-keyboard",
  "enable-font-antialiasing",
  "enable-fullscreen-tab-detaching",
  "enable-fullscreen-toolbar-reveal",
  "enable-google-branded-context-menu",
  "enable-gpu-async-worker-context",
  "enable-gpu-benchmarking",
  "enable-gpu-client-logging",
  "enable-gpu-client-tracing",
  "enable-gpu-command-logging",
  "enable-gpu-debugging",
  "enable-gpu-driver-debug-logging",
  "enable-gpu-memory-buffer-compositor-resources",
  "enable-gpu-memory-buffer-video-frames",
  "enable-gpu-rasterization",
  "enable-gpu-service-logging",
  "enable-gpu-service-tracing",
  "enable-grouped-history",
  "enable-hardware-overlays",
  "enable-harfbuzz-rendertext",
  "enable-hdr",
  "enable-heap-profiling",
  "enable-hosted-app-quit-notification",
  "enable-hosted-apps-in-windows",
  "enable-hosted-mode",
  "enable-hotword-hardware",
  "enable-hung-renderer-infobar",
  "enable-inband-text-tracks",
  "enable-input-ime-api",
  "enable-ios-handoff-to-other-devices",
  "enable-ios-password-generation",
  "enable-ios-physical-web",
  "enable-kiosk-mode",
  "enable-layer-lists",
  "enable-lcd-text",
  "enable-leak-detection",
  "enable-local-file-accesses",
  "enable-local-sync-backend",
  "enable-logging",
  "enable-login-screen-apps",
  "enable-longpress-drag-selection",
  "enable-low-end-device-mode",
  "enable-low-res-tiling",
  "enable-lru-snapshot-cache",
  "enable-mac-views-native-app-windows",
  "enable-main-frame-before-activation",
  "enable-md-feedback",
  "enable-md-policy-page",
  "enable-media-suspend",
  "enable-merge-key-char-events",
  "enable-message-center-always-scroll-up-upon-notification-removal",
  "enable-nacl",
  "enable-nacl-debug",
  "enable-nacl-nonsfi-mode",
  "enable-native-gpu-memory-buffers",
  "enable-natural-scroll-default",
  "enable-navigation-tracing",
  "enable-net-benchmarking",
  "enable-network-information",
  "enable-network-portal-notification",
  "enable-network-service",
  "enable-new-vp9-codec-string",
  "enable-ntp-popular-sites",
  "enable-ntp-search-engine-country-detection",
  "enable-offer-store-unmasked-wallet-cards",
  "enable-offer-upload-credit-cards",
  "enable-offline-auto-reload",
  "enable-offline-auto-reload-visible-only",
  "enable-osk-overscroll",
  "enable-override-bookmarks-ui",
  "enable-partial-raster",
  "enable-password-generation",
  "enable-payment-request",
  "enable-pepper-testing",
  "enable-per-monitor-dpi",
  "enable-permission-action-reporting",
  "enable-physical-keyboard-autocorrect",
  "enable-pinch",
  "enable-pixel-output-in-tests",
  "enable-plugin-placeholder-testing",
  "enable-potentially-annoying-security-features",
  "enable-power-overlay",
  "enable-precache",
  "enable-precise-memory-info",
  "enable-prefer-compositing-to-lcd-text",
  "enable-print-browser",
  "enable-print-preview-register-promos",
  "enable-profile-shortcut-manager",
  "enable-profiling",
  "enable-proximity-auth-bluetooth-low-energy-discovery",
  "enable-proximity-auth-proximity-detection",
  "enable-push-api-background-mode",
  "enable-quic",
  "enable-reader-mode-toolbar-icon",
  "enable-refresh-token-annotation-request",
  "enable-request-tablet-site",
  "enable-rgba-4444-textures",
  "enable-sandbox",
  "enable-sandbox-logging",
  "enable-screenshot-testing-with-mode",
  "enable-scripts-require-action",
  "enable-scroll-prediction",
  "enable-service-manager-tracing",
  "enable-settings-window",
  "enable-sgi-video-sync",
  "enable-signin-promo",
  "enable-single-click-autofill",
  "enable-site-engagement-eviction-policy",
  "enable-site-settings",
  "enable-skia-benchmarking",
  "enable-slimming-paint-invalidation",
  "enable-slimming-paint-v2",
  "enable-smooth-scrolling",
  "enable-spatial-navigation",
  "enable-spdy-proxy-auth",
  "enable-speech-dispatcher",
  "enable-spelling-feedback-field-trial",
  "enable-spotlight-actions",
  "enable-stats-collection-bindings",
  "enable-stats-table",
  "enable-strict-mixed-content-checking",
  "enable-strict-powerful-feature-restrictions",
  "enable-suggestions-ui",
  "enable-suggestions-with-substring-match",
  "enable-supervised-user-managed-bookmarks-folder",
  "enable-surface-synchronization",
  "enable-swap-buffers-with-bounds",
  "enable-sync-app-list",
  "enable-sync-articles",
  "enable-tab-audio-muting",
  "enable-tcp-fastopen",
  "enable-tether",
  "enable-threaded-compositing",
  "enable-threaded-texture-mailboxes",
  "enable-thumbnail-retargeting",
  "enable-tile-compression",
  "enable-touch-calibration-setting",
  "enable-touch-drag-drop",
  "enable-touch-support-for-screen-magnifier",
  "enable-touchpad-three-finger-click",
  "enable-touchview",
  "enable-trace-app-source",
  "enable-tracing",
  "enable-tracing-output",
  "enable-translate-new-ux",
  "enable-ui-devtools",
  "enable-use-zoom-for-dsf",
  "enable-user-controlled-alternate-protocol-ports",
  "enable-user-metrics",
  "enable-usermedia-screen-capturing",
  "enable-video-player-chromecast-support",
  "enable-viewport",
  "enable-virtual-keyboard",
  "enable-voice-interaction",
  "enable-vp9-in-mp4",
  "enable-vtune-support",
  "enable-vulkan",
  "enable-wayland-server",
  "enable-web-notification-custom-layouts",
  "enable-webfonts-intervention-trigger",
  "enable-webfonts-intervention-v2",
  "enable-webgl-draft-extensions",
  "enable-webgl-image-chromium",
  "enable-webrtc-event-logging-from-extension",
  "enable-webrtc-srtp-aes-gcm",
  "enable-webrtc-stun-origin",
  "enable-webvr",
  "enable-wifi-credential-sync",
  "enable-win7-webrtc-hw-h264-decoding",
  "enable-zero-copy",
  "enable-zip-archiver-on-file-manager",
  "enabled",
  "enabled-2g",
  "enabled-3g",
  "enabled-slow2g",
  "encode-binary",
  "enforce",
  "enforce-gl-minimums",
  "enforce-webrtc-ip-permission-check",
  "enforce_strict",
  "enterprise-disable-arc",
  "enterprise-enable-forced-re-enrollment",
  "enterprise-enable-zero-touch-enrollment",
  "enterprise-enrollment-initial-modulus",
  "enterprise-enrollment-modulus-limit",
  "error-console",
  "explicitly-allowed-ports",
  "expose-internals-for-testing",
  "extension-content-verification",
  "extension-process",
  "extensions-install-verification",
  "extensions-multi-account",
  "extensions-not-webstore",
  "extensions-on-chrome-urls",
  "extensions-update-frequency",
  "extra-search-query-params",
  "fail-on-unused-args",
  "fake-variations-channel",
  "false",
  "fast",
  "fast-start",
  "feedback-server",
  "field-trial-handle",
  "first-exec-after-boot",
  "flag-switches-begin",
  "flag-switches-end",
  "font-cache-shared-handle",
  "force-android-app-mode",
  "force-app-mode",
  "force-desktop-ios-promotion",
  "force-dev-mode-highlighting",
  "force-device-scale-factor",
  "force-display-list-2d-canvas",
  "force-fieldtrial-params",
  "force-fieldtrials",
  "force-first-run",
  "force-first-run-ui",
  "force-gpu-mem-available-mb",
  "force-gpu-rasterization",
  "force-happiness-tracking-system",
  "force-load-easy-unlock-app-in-tests",
  "force-local-ntp",
  "force-login-manager-in-tests",
  "force-mediafoundation",
  "force-overlay-fullscreen-video",
  "force-pnacl-subzero",
  "force-renderer-accessibility",
  "force-show-update-menu-badge",
  "force-show-update-menu-item",
  "force-system-compositor-mode",
  "force-tablet-mode",
  "force-ui-direction",
  "force-variation-ids",
  "force-video-overlays",
  "force-wave-audio",
  "force-webrtc-ip-handling-policy",
  "full-memory-crash-report",
  "gaia-url",
  "gcm-checkin-url",
  "gcm-mcs-endpoint",
  "gcm-registration-url",
  "generate-accessibility-test-expectations",
  "gl",
  "gl-composited-texture-quad-border",
  "gl-shader-interm-output",
  "gles",
  "golden-screenshots-dir",
  "google-apis-url",
  "google-base-url",
  "google-doodle-url",
  "google-url",
  "gpu-active-device-id",
  "gpu-active-vendor-id",
  "gpu-device-id",
  "gpu-driver-bug-workarounds",
  "gpu-driver-date",
  "gpu-driver-vendor",
  "gpu-driver-version",
  "gpu-launcher",
  "gpu-no-complete-info-collection",
  "gpu-no-context-lost",
  "gpu-process",
  "gpu-program-cache-size-kb",
  "gpu-rasterization-msaa-sample-count",
  "gpu-sandbox-allow-sysv-shm",
  "gpu-sandbox-failures-fatal",
  "gpu-sandbox-start-early",
  "gpu-secondary-device-ids",
  "gpu-secondary-vendor-ids",
  "gpu-startup-dialog",
  "gpu-testing-device-id",
  "gpu-testing-driver-date",
  "gpu-testing-gl-renderer",
  "gpu-testing-gl-vendor",
  "gpu-testing-gl-version",
  "gpu-testing-os-version",
  "gpu-testing-secondary-device-ids",
  "gpu-testing-secondary-vendor-ids",
  "gpu-testing-vendor-id",
  "gpu-vendor-id",
  "guest-wallpaper-large",
  "guest-wallpaper-small",
  "h",
  "has-chromeos-diamond-key",
  "headless",
  "help",
  "hide",
  "hide-icons",
  "hide-scrollbars",
  "history-entry-requires-user-gesture",
  "homedir",
  "homepage",
  "host",
  "host-pairing-oobe",
  "host-resolver-retry-attempts",
  "host-resolver-rules",
  "host-rules",
  "icu-data-dir",
  "ignore-autocomplete-off-autofill",
  "ignore-certificate-errors",
  "ignore-gpu-blacklist",
  "ignore-urlfetcher-cert-requests",
  "ignore-user-profile-mapping-for-tests",
  "in-process-gpu",
  "incognito",
  "inert-visual-viewport",
  "input",
  "inspect",
  "inspect-brk",
  "install-chrome-app",
  "install-supervised-user-whitelists",
  "instant-process",
  "interests-url",
  "invalidation-use-gcm-channel",
  "ipc-connection-timeout",
  "ipc-dump-directory",
  "ipc-fuzzer-testcase",
  "is-running-in-mash",
  "isolate-extensions",
  "isolate-sites-for-testing",
  "javascript-harmony",
  "js-flags",
  "keep-alive-for-test",
  "kiosk",
  "kiosk-printing",
  "lang",
  "last-launched-app",
  "layer",
  "light_muted",
  "light_vibrant",
  "load-and-launch-app",
  "load-apps",
  "load-extension",
  "load-media-router-component-extension",
  "local-heuristics-only-for-password-generation",
  "local-ntp-reload",
  "local-sync-backend-dir",
  "log-gpu-control-list-decisions",
  "log-level",
  "log-net-log",
  "login-manager",
  "login-profile",
  "login-user",
  "lso-url",
  "ltr",
  "main-frame-resizes-are-orientation-changes",
  "make-chrome-default",
  "make-default-browser",
  "managed-user-id",
  "managed-user-sync-token",
  "mark-non-secure-as",
  "markdown",
  "market-url-for-testing",
  "mash",
  "material",
  "material-design-ink-drop-animation-speed",
  "material-hybrid",
  "max-gum-fps",
  "max-output-volume-dba1m",
  "max-untiled-layer-height",
  "max-untiled-layer-width",
  "media-cache-size",
  "mem-pressure-system-reserved-kb",
  "memory-metrics",
  "memory-pressure-off",
  "memory-pressure-thresholds",
  "memory-pressure-thresholds-mb",
  "message-center-changes-while-open",
  "metrics-client-id",
  "metrics-recording-only",
  "mhtml-generator-option",
  "mock",
  "mojo-channel-token",
  "mojo-local-storage",
  "mojo-pipe-token",
  "monitoring-destination-id",
  "mse-audio-buffer-size-limit",
  "mse-video-buffer-size-limit",
  "mus",
  "mus-config",
  "mute-audio",
  "nacl-broker",
  "nacl-dangerous-no-sandbox-nonsfi",
  "nacl-debug-mask",
  "nacl-gdb",
  "nacl-gdb-script",
  "nacl-loader",
  "nacl-loader-nonsfi",
  "native",
  "native-crx-bindings",
  "net-log-capture-mode",
  "netifs-to-ignore",
  "network-country-iso",
  "new-window",
  "no-default-browser-check",
  "no-experiments",
  "no-first-run",
  "no-managed-user-acknowledgment-check",
  "no-network-profile-warning",
  "no-pings",
  "no-proxy-server",
  "no-referrers",
  "no-sandbox",
  "no-service-autorun",
  "no-startup-window",
  "no-wifi",
  "no-zygote",
  "nocolor",
  "noerrdialogs",
  "non-material",
  "non-secure",
  "none",
  "normal_muted",
  "normal_vibrant",
  "note-taking-app-ids",
  "ntp-snippets-add-incomplete",
  "ntp-switch-to-existing-tab",
  "null",
  "num-pac-threads",
  "num-raster-threads",
  "oauth2-client-id",
  "oauth2-client-secret",
  "off",
  "on",
  "oobe-bootstrapping-master",
  "oobe-guest-session",
  "oobe-skip-postlogin",
  "oobe-timer-interval",
  "open-ash",
  "opengraph",
  "origin-to-force-quic-on",
  "origin-trial-disabled-features",
  "origin-trial-disabled-tokens",
  "origin-trial-public-key",
  "original-process-start-time",
  "osmesa",
  "output",
  "override",
  "override-metrics-upload-url",
  "override-plugin-power-saver-for-testing",
  "override-use-software-gl-for-tests",
  "overscroll-history-navigation",
  "overscroll-start-threshold",
  "ozone-dump-file",
  "ozone-platform",
  "pack-extension",
  "pack-extension-key",
  "parent-profile",
  "parent-window",
  "passive-listeners-default",
  "password-store",
  "permission-request-api-scope",
  "permission-request-api-url",
  "power-stub",
  "ppapi",
  "ppapi-antialiased-text-enabled",
  "ppapi-broker",
  "ppapi-flash-args",
  "ppapi-flash-path",
  "ppapi-flash-version",
  "ppapi-in-process",
  "ppapi-plugin-launcher",
  "ppapi-startup-dialog",
  "ppapi-subpixel-rendering-setting",
  "precache-config-settings-url",
  "precache-manifest-url-prefix",
  "prerender-from-omnibox",
  "previous-app",
  "primary",
  "primordial-pipe-token",
  "print-to-pdf",
  "privet-ipv6-only",
  "process-per-site",
  "process-per-tab",
  "process-service-name",
  "product-version",
  "profile-directory",
  "profiler-timing",
  "profiling-at-start",
  "profiling-file",
  "profiling-flush",
  "progress-bar-animation",
  "progress-bar-completion",
  "prompt-for-external-extensions",
  "proxy-auto-detect",
  "proxy-bypass-list",
  "proxy-pac-url",
  "proxy-server",
  "q",
  "quic-connection-options",
  "quic-host-whitelist",
  "quic-max-packet-length",
  "quic-version",
  "rdp_desktop_session",
  "reader-mode-feedback",
  "reader-mode-heuristics",
  "rebaseline-pixel-tests",
  "reduce-security-for-testing",
  "reduced-referrer-granularity",
  "register-font-files",
  "register-pepper-plugins",
  "relauncher",
  "remote-debugging-address",
  "remote-debugging-port",
  "remote-debugging-socket-name",
  "remote-debugging-targets",
  "renderer",
  "renderer-client-id",
  "renderer-cmd-prefix",
  "renderer-process-limit",
  "renderer-startup-dialog",
  "renderer-wait-for-java-debugger",
  "renderpass",
  "repl",
  "report-vp9-as-an-unsupported-mime-type",
  "require-audio-hardware-for-testing",
  "reset-app-list-install-state",
  "reset-variation-state",
  "restore-last-session",
  "root",
  "root-layer-scrolls",
  "rtl",
  "run-layout-test",
  "runtime-deps-list-file",
  "safebrowsing-disable-auto-update",
  "safebrowsing-disable-download-protection",
  "safebrowsing-disable-extension-blacklist",
  "safebrowsing-manual-download-blacklist",
  "sandbox-ipc",
  "save-page-as-mhtml",
  "saveas-menu-label",
  "screen-config",
  "screenshot",
  "script-executable",
  "scripts-require-action",
  "scroll-end-effect",
  "secondary",
  "secondary-display-layout",
  "secondary-ui-md",
  "service",
  "service-overrides",
  "service-request-channel-token",
  "shared-files",
  "shill-stub",
  "show-app-list",
  "show-autofill-signatures",
  "show-autofill-type-predictions",
  "show-component-extension-options",
  "show-composited-layer-borders",
  "show-fps-counter",
  "show-icons",
  "show-layer-animation-bounds",
  "show-mac-overlay-borders",
  "show-overdraw-feedback",
  "show-paint-rects",
  "show-property-changed-rects",
  "show-saved-copy",
  "show-screenspace-rects",
  "show-surface-damage-rects",
  "show_summary",
  "silent-debugger-extension-api",
  "silent-launch",
  "simulate-critical-update",
  "simulate-elevated-recovery",
  "simulate-outdated",
  "simulate-outdated-no-au",
  "simulate-upgrade",
  "single-process",
  "site-per-process",
  "skip-gpu-data-loading",
  "skip-nostore-all",
  "skip-nostore-main",
  "skip-reencoding-on-skp-capture",
  "slow",
  "slow-connections-only",
  "slow-down-raster-scale-factor",
  "sms-test-messages",
  "spdy-proxy-auth-fallback",
  "spdy-proxy-auth-origin",
  "spdy-proxy-auth-value",
  "spelling-service-feedback-interval-seconds",
  "spelling-service-feedback-url",
  "ssl-key-log-file",
  "ssl-version-max",
  "ssl-version-min",
  "stable-release-mode",
  "start-fullscreen",
  "start-maximized",
  "start-stack-profiler",
  "started",
  "stub",
  "stub-cros-settings",
  "supports-dual-gpus",
  "surface",
  "swiftshader",
  "swiftshader-webgl",
  "sync-allow-insecure-xmpp-connection",
  "sync-deferred-startup-timeout-seconds",
  "sync-disable-deferred-startup",
  "sync-enable-get-update-avoidance",
  "sync-notification-host-port",
  "sync-on-draw-hardware",
  "sync-short-initial-retry-override",
  "sync-short-nudge-delay-for-test",
  "sync-url",
  "system-developer-mode",
  "system-log-upload-frequency",
  "tab-management-experiment-type-disabled",
  "tab-management-experiment-type-elderberry",
  "task-profiler",
  "team-drives",
  "test-auto-update-ui",
  "test-child-process",
  "test-cros-gaia-id-migration",
  "test-do-not-initialize-icu",
  "test-encryption-migration-ui",
  "test-gl-lib",
  "test-launcher-batch-limit",
  "test-launcher-bot-mode",
  "test-launcher-debug-launcher",
  "test-launcher-filter-file",
  "test-launcher-force-run-broken-tests",
  "test-launcher-jobs",
  "test-launcher-list-tests",
  "test-launcher-output",
  "test-launcher-print-test-stdio",
  "test-launcher-print-writable-path",
  "test-launcher-retry-limit",
  "test-launcher-shard-index",
  "test-launcher-summary-output",
  "test-launcher-timeout",
  "test-launcher-total-shards",
  "test-launcher-trace",
  "test-name",
  "test-tiny-timeout",
  "test-type",
  "testing-fixed-http-port",
  "testing-fixed-https-port",
  "threads",
  "time",
  "timeout",
  "tls1",
  "tls1.1",
  "tls1.2",
  "tls1.3",
  "top-chrome-md",
  "top-controls-hide-threshold",
  "top-controls-show-threshold",
  "top-document-isolation",
  "touch-calibration",
  "touch-devices",
  "touch-events",
  "touch-noise-filtering",
  "touch-selection-strategy",
  "touch_view",
  "trace-config-file",
  "trace-export-events-to-etw",
  "trace-shutdown",
  "trace-shutdown-file",
  "trace-startup",
  "trace-startup-duration",
  "trace-startup-file",
  "trace-to-console",
  "trace-to-file",
  "trace-to-file-name",
  "trace-upload-url",
  "tracelog",
  "translate-ranker-model-url",
  "translate-script-url",
  "translate-security-origin",
  "true",
  "try-chrome-again",
  "try-supported-channel-layouts",
  "type",
  "ui-disable-partial-swap",
  "ui-enable-layer-lists",
  "ui-enable-rgba-4444-textures",
  "ui-enable-zero-copy",
  "ui-prioritize-in-gpu-process",
  "ui-show-fps-counter",
  "ui-show-layer-animation-bounds",
  "ui-show-layer-borders",
  "ui-show-paint-rects",
  "ui-show-property-changed-rects",
  "ui-show-screenspace-rects",
  "ui-show-surface-damage-rects",
  "ui-slow-animations",
  "ui-test-action-max-timeout",
  "ui-test-action-timeout",
  "uninstall",
  "unlimited-storage",
  "unsafe-pac-url",
  "unsafely-allow-protected-media-identifier-for-domain",
  "unsafely-treat-insecure-origin-as-secure",
  "use-angle",
  "use-cras",
  "use-double-buffering",
  "use-fake-device-for-media-stream",
  "use-fake-jpeg-decode-accelerator",
  "use-fake-ui-for-media-stream",
  "use-file-for-fake-audio-capture",
  "use-file-for-fake-video-capture",
  "use-first-display-as-internal",
  "use-gl",
  "use-gpu-in-tests",
  "use-mobile-user-agent",
  "use-mock-keychain",
  "use-new-virtual-keyboard-behavior",
  "use-passthrough-cmd-decoder",
  "use-simple-cache-backend",
  "use-test-config",
  "use_new_features_summary",
  "user-agent",
  "user-always-affiliated",
  "user-data-dir",
  "utility",
  "utility-allowed-dir",
  "utility-cmd-prefix",
  "utility-run-elevated",
  "v",
  "v8-cache-options",
  "v8-cache-strategies-for-cache-storage",
  "validate-crx",
  "validate-input-event-stream",
  "variations-server-url",
  "version",
  "video-image-texture-target",
  "video-threads",
  "video-underflow-threshold-ms",
  "viewer-launch-via-appid",
  "virtual-time-budget",
  "vmodule",
  "wait-for-debugger",
  "wait-for-debugger-children",
  "wake-on-wifi-packet",
  "wallet-service-use-sandbox",
  "watcher",
  "waveout-buffers",
  "webapk-server-url",
  "webrtc-max-cpu-consumption-percentage",
  "webrtc-stun-probe-trial",
  "webview-enable-safebrowsing-support",
  "webview-sandboxed-renderer",
  "whitelisted-extension-id",
  "win-jumplist-action",
  "window-position",
  "window-size",
  "window-workspace",
  "windows10-custom-titlebar",
  "windows8-search",
  "winhttp-proxy-resolver",
  "wm-window-animations-disabled",
  "yield-between-content-script-runs",
  "zygote",
  "zygote-cmd-prefix"
};

bool IsBlacklistedArg(const base::CommandLine::CharType* arg) {
#if defined(OS_WIN)
  const auto converted = base::WideToUTF8(arg);
  const char* a = converted.c_str();
#else
  const char* a = arg;
#endif

  static const char* prefixes[] = {"--", "-", "/"};

  int prefix_length = 0;
  for (auto& prefix : prefixes) {
    if (base::StartsWith(a, prefix, base::CompareCase::SENSITIVE)) {
      prefix_length = strlen(prefix);
      break;
    }
  }

  if (prefix_length > 0) {
    a += prefix_length;
    std::string switch_name =
        base::ToLowerASCII(base::StringPiece(a, strcspn(a, "=")));
    for (auto& item : blacklist) {
      if (switch_name == item)
        return true;
    }
  }

  return false;
}

}  // namespace

namespace atom {

bool CheckCommandLineArguments(int argc, base::CommandLine::CharType** argv) {
  const base::CommandLine::StringType dashdash(2, '-');
  bool block_blacklisted_args = false;
  for (int i = 0; i < argc; ++i) {
    if (argv[i] == dashdash)
      break;
    if (block_blacklisted_args) {
      if (IsBlacklistedArg(argv[i]))
        return false;
    } else if (IsUrlArg(argv[i])) {
      block_blacklisted_args = true;
    }
  }
  return true;
}

}  // namespace atom
