541cf9ef8793ce422332f1b4378331c875509de8
[platform/framework/web/chromium-efl.git] / headless / BUILD.gn
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 import("//build/config/c++/c++.gni")
6 import("//build/config/chrome_build.gni")
7 import("//build/config/python.gni")
8 import("//build/util/lastchange.gni")
9 import("//build/util/process_version.gni")
10 import("//headless/headless.gni")
11 import("//mojo/public/tools/bindings/mojom.gni")
12 import("//printing/buildflags/buildflags.gni")
13 import("//testing/test.gni")
14 import("//third_party/closure_compiler/compile_js.gni")
15 import("//third_party/inspector_protocol/inspector_protocol.gni")
16 import("//tools/grit/grit_rule.gni")
17 import("//tools/grit/repack.gni")
18 import("//tools/v8_context_snapshot/v8_context_snapshot.gni")
19
20 if (headless_use_policy) {
21   assert(headless_use_prefs,
22          "'headless_use_policy' requires 'headless_use_prefs'.")
23 }
24
25 # Headless defines config applied to every target below.
26 config("headless_defines_config") {
27   defines = []
28
29   if (headless_use_prefs) {
30     defines += [ "HEADLESS_USE_PREFS" ]
31   }
32
33   if (headless_use_policy) {
34     defines += [ "HEADLESS_USE_POLICY" ]
35   }
36 }
37
38 # For code inside the build component "headless".
39 config("inside_headless_component") {
40   defines = [ "HEADLESS_IMPLEMENTATION" ]
41 }
42
43 group("headless_lib") {
44   deps = [ ":headless_non_renderer" ]
45 }
46
47 repack("pak") {
48   sources = [
49     "$root_gen_dir/components/components_resources.pak",
50     "$root_gen_dir/components/strings/components_strings_en-US.pak",
51     "$root_gen_dir/content/app/resources/content_resources_100_percent.pak",
52     "$root_gen_dir/content/browser/tracing/tracing_resources.pak",
53     "$root_gen_dir/content/content_resources.pak",
54     "$root_gen_dir/content/dev_ui_content_resources.pak",
55     "$root_gen_dir/headless/headless_lib_resources.pak",
56     "$root_gen_dir/mojo/public/js/mojo_bindings_resources.pak",
57     "$root_gen_dir/net/net_resources.pak",
58     "$root_gen_dir/third_party/blink/public/resources/blink_resources.pak",
59     "$root_gen_dir/third_party/blink/public/resources/blink_scaled_resources_100_percent.pak",
60     "$root_gen_dir/third_party/blink/public/strings/blink_strings_en-US.pak",
61     "$root_gen_dir/ui/resources/ui_resources_100_percent.pak",
62     "$root_gen_dir/ui/resources/webui_generated_resources.pak",
63     "$root_gen_dir/ui/resources/webui_resources.pak",
64     "$root_gen_dir/ui/strings/app_locale_settings_en-US.pak",
65     "$root_gen_dir/ui/strings/ui_strings_en-US.pak",
66   ]
67
68   if (is_chrome_branded) {
69     sources += [ "${root_gen_dir}/components/strings/components_google_chrome_strings_en-US.pak" ]
70   } else {
71     sources += [ "${root_gen_dir}/components/strings/components_chromium_strings_en-US.pak" ]
72   }
73
74   deps = [
75     ":resources",
76     "//components/resources:components_resources",
77     "//components/strings",
78     "//content:content_resources",
79     "//content:dev_ui_content_resources",
80     "//content/app/resources",
81     "//content/browser/tracing:resources",
82     "//mojo/public/js:resources",
83     "//net:net_resources",
84     "//third_party/blink/public:resources",
85     "//third_party/blink/public:scaled_resources_100_percent",
86     "//third_party/blink/public/strings",
87     "//ui/resources",
88     "//ui/strings",
89   ]
90
91   if (!is_fuchsia) {
92     sources +=
93         [ "$root_gen_dir/content/browser/devtools/devtools_resources.pak" ]
94     deps += [ "//content/browser/devtools:devtools_resources" ]
95   }
96
97   output = "$root_out_dir/headless_lib.pak"
98 }
99
100 action("embed_resources") {
101   # TODO(altimin): Consider zipping file here, it can reduce size up to 80%.
102   script = "lib/embed_data.py"
103
104   inputs = [ "$root_out_dir/headless_lib.pak" ]
105
106   outputs = [
107     "$root_gen_dir/headless/embedded_resource_pak.cc",
108     "$root_gen_dir/headless/embedded_resource_pak.h",
109   ]
110
111   args = [
112     "--data_file",
113     rebase_path("$root_out_dir/headless_lib.pak", root_build_dir),
114     "--gendir",
115     rebase_path("$root_gen_dir", root_build_dir),
116     "--header_file",
117     "headless/embedded_resource_pak.h",
118     "--source_file",
119     "headless/embedded_resource_pak.cc",
120     "--namespace",
121     "headless",
122     "--variable_name",
123     "kHeadlessResourcePak",
124   ]
125
126   deps = [ ":pak" ]
127 }
128
129 grit("resources") {
130   source = "lib/resources/headless_lib_resources.grd"
131   outputs = [
132     "grit/headless_lib_resources.h",
133     "$root_gen_dir/headless/headless_lib_resources.pak",
134   ]
135 }
136
137 devtools_domains = [
138   "accessibility",
139   "animation",
140   "application_cache",
141   "browser",
142   "cache_storage",
143   "console",
144   "css",
145   "database",
146   "debugger",
147   "device_orientation",
148   "dom",
149   "dom_debugger",
150   "dom_snapshot",
151   "dom_storage",
152   "emulation",
153   "fetch",
154   "headless_experimental",
155   "heap_profiler",
156   "indexeddb",
157   "input",
158   "inspector",
159   "io",
160   "layer_tree",
161   "log",
162   "memory",
163   "network",
164   "page",
165   "performance",
166   "profiler",
167   "runtime",
168   "security",
169   "service_worker",
170   "target",
171   "tracing",
172 ]
173
174 generated_devtools_api = []
175 foreach(domain, devtools_domains) {
176   generated_devtools_api += [
177     "$target_gen_dir/public/devtools/domains/" + domain + ".cc",
178     "$target_gen_dir/public/devtools/domains/" + domain + ".h",
179     "$target_gen_dir/public/devtools/domains/types_" + domain + ".h",
180     "$target_gen_dir/public/devtools/domains/types_" + domain + ".cc",
181     "$target_gen_dir/public/devtools/internal/type_conversions_" + domain +
182         ".h",
183     "$target_gen_dir/public/devtools/internal/" +
184         "types_forward_declarations_" + domain + ".h",
185   ]
186 }
187
188 action("gen_devtools_client_api") {
189   script = "lib/browser/devtools_api/client_api_generator.py"
190   deps = [ "//third_party/blink/public/devtools_protocol:protocol_version" ]
191   inputs = [
192     "$root_gen_dir/third_party/blink/public/devtools_protocol/protocol.json",
193   ]
194
195   outputs = generated_devtools_api
196   sources = [
197     "lib/browser/devtools_api/domain_cc.template",
198     "lib/browser/devtools_api/domain_h.template",
199     "lib/browser/devtools_api/domain_type_conversions_h.template",
200     "lib/browser/devtools_api/domain_types_cc.template",
201     "lib/browser/devtools_api/domain_types_forward_declarations_h.template",
202     "lib/browser/devtools_api/domain_types_h.template",
203   ]
204
205   args = [
206     "--protocol",
207     rebase_path(inputs[0], root_build_dir),
208     "--output_dir",
209     rebase_path(target_gen_dir, root_build_dir) + "/public",
210   ]
211 }
212
213 if (headless_fontconfig_utils && !is_fuchsia) {
214   static_library("headless_fontconfig_utils") {
215     sources = [
216       "public/util/fontconfig.cc",
217       "public/util/fontconfig.h",
218     ]
219
220     deps = [
221       "//build/config/freetype",
222       "//third_party/fontconfig",
223     ]
224
225     configs += [ ":inside_headless_component" ]
226   }
227 }
228
229 inspector_protocol_generate("protocol_sources") {
230   visibility = [ "//headless:headless_shared_sources" ]
231   deps = [ "//third_party/blink/public/devtools_protocol:protocol_version" ]
232   _blink_protocol_path = rebase_path(
233           "$root_gen_dir/third_party/blink/public/devtools_protocol/protocol.json",
234           root_build_dir)
235
236   inspector_protocol_dir = "//third_party/inspector_protocol"
237   out_dir = target_gen_dir
238   config_file = "protocol_config.json"
239   config_values = [ "protocol.path=$_blink_protocol_path" ]
240
241   inputs = [
242     "$root_gen_dir/third_party/blink/public/devtools_protocol/protocol.json",
243     config_file,
244   ]
245
246   # These are relative to $target_gen_dir.
247   outputs = [
248     "lib/browser/protocol/base_string_adapter.cc",
249     "lib/browser/protocol/base_string_adapter.h",
250     "lib/browser/protocol/dp_browser.cc",
251     "lib/browser/protocol/dp_browser.h",
252     "lib/browser/protocol/dp_headless_experimental.cc",
253     "lib/browser/protocol/dp_headless_experimental.h",
254     "lib/browser/protocol/dp_page.cc",
255     "lib/browser/protocol/dp_page.h",
256     "lib/browser/protocol/dp_target.cc",
257     "lib/browser/protocol/dp_target.h",
258     "lib/browser/protocol/protocol.cc",
259     "lib/browser/protocol/protocol.h",
260   ]
261 }
262
263 # Code needed in both processes. Only exposed through the |headless_renderer|
264 # target and the |headless_non_renderer| component.
265 source_set("headless_shared_sources") {
266   visibility = [
267     ":headless_non_renderer",
268     ":headless_renderer",
269   ]
270   defines = []
271
272   sources = [
273     "app/headless_shell_switches.cc",
274     "app/headless_shell_switches.h",
275     "lib/headless_content_client.cc",
276     "lib/headless_content_client.h",
277     "public/headless_browser.cc",
278     "public/headless_browser.h",
279     "public/headless_export.h",
280     "public/internal/headless_devtools_client_impl.h",
281     "public/internal/message_dispatcher.h",
282     "public/internal/value_conversions.h",
283     "public/util/error_reporter.cc",
284     "public/util/error_reporter.h",
285     "public/util/user_agent.cc",
286     "public/util/user_agent.h",
287   ]
288
289   sources += generated_devtools_api
290   sources += get_target_outputs(":protocol_sources")
291
292   if (!is_fuchsia) {
293     sources += [
294       "lib/headless_crash_reporter_client.cc",
295       "lib/headless_crash_reporter_client.h",
296     ]
297   }
298
299   deps = [
300     ":gen_devtools_client_api",
301     ":protocol_sources",
302     ":version_header",
303     "//base:base_static",
304     "//components/embedder_support/origin_trials",
305     "//content/public/common",
306     "//third_party/inspector_protocol:crdtp",
307     "//ui/base",
308     "//url",
309   ]
310
311   if (!is_fuchsia) {
312     deps += [
313       "//components/crash/content/browser",
314       "//components/crash/core/app",
315     ]
316   }
317   if (is_win) {
318     deps += [ "//sandbox" ]
319   }
320
321   configs += [ ":inside_headless_component" ]
322   configs += [ ":headless_defines_config" ]
323 }
324
325 # Code that is not needed in a renderer process.
326 component("headless_non_renderer") {
327   sources = [
328     "lib/browser/headless_browser_context_impl.cc",
329     "lib/browser/headless_browser_context_impl.h",
330     "lib/browser/headless_browser_context_options.cc",
331     "lib/browser/headless_browser_context_options.h",
332     "lib/browser/headless_browser_impl.cc",
333     "lib/browser/headless_browser_impl.h",
334     "lib/browser/headless_browser_main_parts.cc",
335     "lib/browser/headless_browser_main_parts.h",
336     "lib/browser/headless_devtools.cc",
337     "lib/browser/headless_devtools.h",
338     "lib/browser/headless_devtools_agent_host_client.cc",
339     "lib/browser/headless_devtools_agent_host_client.h",
340     "lib/browser/headless_devtools_client_impl.cc",
341     "lib/browser/headless_devtools_manager_delegate.cc",
342     "lib/browser/headless_devtools_manager_delegate.h",
343     "lib/browser/headless_permission_manager.cc",
344     "lib/browser/headless_permission_manager.h",
345     "lib/browser/headless_platform_event_source.cc",
346     "lib/browser/headless_platform_event_source.h",
347     "lib/browser/headless_quota_permission_context.cc",
348     "lib/browser/headless_quota_permission_context.h",
349     "lib/browser/headless_request_context_manager.cc",
350     "lib/browser/headless_request_context_manager.h",
351     "lib/browser/headless_window_tree_host.h",
352     "lib/browser/protocol/browser_handler.cc",
353     "lib/browser/protocol/browser_handler.h",
354     "lib/browser/protocol/domain_handler.h",
355     "lib/browser/protocol/headless_devtools_session.cc",
356     "lib/browser/protocol/headless_devtools_session.h",
357     "lib/browser/protocol/headless_handler.cc",
358     "lib/browser/protocol/headless_handler.h",
359     "lib/browser/protocol/page_handler.cc",
360     "lib/browser/protocol/page_handler.h",
361     "lib/browser/protocol/target_handler.cc",
362     "lib/browser/protocol/target_handler.h",
363     "public/headless_browser_context.h",
364     "public/headless_devtools_channel.h",
365     "public/headless_devtools_client.h",
366     "public/headless_devtools_target.h",
367     "public/headless_web_contents.h",
368   ]
369
370   if (is_mac) {
371     sources += [
372       "lib/browser/headless_browser_impl_mac.mm",
373       "lib/browser/headless_browser_main_parts_mac.mm",
374       "lib/browser/headless_shell_application_mac.h",
375       "lib/browser/headless_shell_application_mac.mm",
376     ]
377   }
378
379   if (is_linux || is_chromeos) {
380     sources += [ "lib/browser/headless_browser_main_parts_linux.cc" ]
381   }
382
383   if (headless_use_policy) {
384     sources += [
385       "lib/browser/headless_pref_names.cc",
386       "lib/browser/headless_pref_names.h",
387       "lib/browser/policy/headless_browser_policy_connector.cc",
388       "lib/browser/policy/headless_browser_policy_connector.h",
389       "lib/browser/policy/headless_mode_policy.cc",
390       "lib/browser/policy/headless_mode_policy.h",
391       "lib/browser/policy/headless_policies.cc",
392       "lib/browser/policy/headless_policies.h",
393     ]
394   }
395
396   if (use_aura) {
397     sources += [
398       "lib/browser/headless_browser_impl_aura.cc",
399       "lib/browser/headless_clipboard.cc",
400       "lib/browser/headless_clipboard.h",
401       "lib/browser/headless_focus_client.cc",
402       "lib/browser/headless_focus_client.h",
403       "lib/browser/headless_screen.cc",
404       "lib/browser/headless_screen.h",
405       "lib/browser/headless_window_parenting_client.cc",
406       "lib/browser/headless_window_parenting_client.h",
407       "lib/browser/headless_window_tree_host.cc",
408     ]
409   }
410
411   if (enable_basic_printing) {
412     sources += [
413       "lib/browser/headless_print_manager.cc",
414       "lib/browser/headless_print_manager.h",
415     ]
416   }
417
418   public_deps = [
419     "//base",
420     "//net",
421   ]
422
423   data_deps = []
424   data = []
425   defines = []
426
427   if (enable_basic_printing) {
428     public_deps += [ "//skia" ]
429   }
430
431   deps = [
432     ":headless_shared_sources",
433     ":version_header",
434     "//base:base_static",
435     "//build:branding_buildflags",
436     "//build:chromeos_buildflags",
437     "//components/cookie_config",
438     "//components/embedder_support",
439     "//components/keyed_service/content",
440     "//components/policy:policy_code_generate",
441     "//components/policy/core/browser",
442     "//components/policy/core/common:common_constants",
443     "//components/pref_registry",
444     "//components/prefs",
445     "//components/profile_metrics",
446     "//components/security_state/core",
447     "//content/public/app",
448     "//content/public/browser",
449     "//content/public/common",
450     "//printing/buildflags",
451     "//services/cert_verifier/public/mojom",
452     "//services/device/public/cpp/geolocation",
453     "//services/service_manager/public/cpp",
454     "//third_party/inspector_protocol:crdtp",
455     "//ui/base",
456     "//ui/base/clipboard",
457     "//ui/compositor",
458     "//ui/display",
459     "//ui/events/devices",
460     "//ui/gfx",
461     "//url",
462   ]
463
464   if (enable_basic_printing) {
465     deps += [
466       "//components/printing/browser",
467       "//components/printing/common:mojo_interfaces",
468       "//printing",
469       "//printing/mojom",
470     ]
471   }
472
473   if (is_component_build) {
474     sources += [
475       "lib/browser/headless_content_browser_client.cc",
476       "lib/browser/headless_content_browser_client.h",
477       "lib/browser/headless_web_contents_impl.cc",
478       "lib/browser/headless_web_contents_impl.h",
479       "lib/headless_content_main_delegate.cc",
480       "lib/headless_content_main_delegate.h",
481       "lib/renderer/headless_content_renderer_client.cc",
482       "lib/renderer/headless_content_renderer_client.h",
483       "lib/utility/headless_content_utility_client.cc",
484       "lib/utility/headless_content_utility_client.h",
485     ]
486
487     if (is_mac) {
488       sources += [ "lib/headless_content_main_delegate_mac.mm" ]
489     }
490
491     if (enable_basic_printing) {
492       sources += [
493         "lib/renderer/headless_print_render_frame_helper_delegate.cc",
494         "lib/renderer/headless_print_render_frame_helper_delegate.h",
495       ]
496     }
497
498     deps += [
499       "//components/crash/core/common",
500       "//components/security_state/content",
501       "//gin",
502       "//third_party/blink/public:blink",
503       "//ui/gl",
504       "//v8",
505     ]
506
507     if (!is_fuchsia) {
508       deps += [
509         "//components/crash/content/browser",
510         "//components/crash/core/app",
511       ]
512     }
513
514     if (enable_basic_printing) {
515       deps += [
516         "//components/printing/browser",
517         "//components/printing/renderer",
518         "//components/services/print_compositor",
519         "//components/services/print_compositor/public/mojom",
520       ]
521     }
522
523     if (headless_use_prefs) {
524       deps += [ "//components/os_crypt" ]
525     }
526
527     if (headless_use_policy) {
528       deps += [
529         "//components/policy/content",
530         "//components/user_prefs",
531       ]
532     }
533   }
534
535   # Normally set to false (see build/args/headless.gn), but we can optionally
536   # use external v8 startup data too.
537   if ((is_win && is_component_build) || !is_win) {
538     if (v8_use_external_startup_data) {
539       public_deps += [ "//v8" ]
540       if (use_v8_context_snapshot) {
541         data += [ "$root_out_dir/$v8_context_snapshot_filename" ]
542         data_deps += [ "//tools/v8_context_snapshot" ]
543       } else {
544         data += [ "$root_out_dir/snapshot_blob.bin" ]
545       }
546     }
547   }
548
549   if (is_mac) {
550     deps += [ ":mac_helpers" ]
551     frameworks = [
552       "AppKit.framework",
553       "CoreFoundation.framework",
554     ]
555   } else {
556     deps += [ "//ui/aura" ]
557   }
558
559   if (headless_use_embedded_resources) {
560     defines += [ "HEADLESS_USE_EMBEDDED_RESOURCES" ]
561     deps += [ ":embed_resources" ]
562     sources += [
563       "$root_gen_dir/headless/embedded_resource_pak.cc",
564       "$root_gen_dir/headless/embedded_resource_pak.h",
565     ]
566   } else {
567     deps += [ ":pak" ]
568   }
569
570   if (use_ozone) {
571     deps += [ "//ui/ozone" ]
572   }
573
574   if (use_dbus) {
575     defines += [ "USE_DBUS" ]
576     deps += [ "//device/bluetooth" ]
577   }
578
579   if (headless_fontconfig_utils && !is_fuchsia) {
580     deps += [ ":headless_fontconfig_utils" ]
581   }
582
583   configs += [ ":inside_headless_component" ]
584   configs += [ ":headless_defines_config" ]
585 }
586
587 # Headless renderer is a convenience library for non component builds that
588 # includes headless classes that depend on the renderer.
589 if (!is_component_build) {
590   static_library("headless_renderer") {
591     defines = []
592     sources = [
593       "lib/browser/headless_web_contents_impl.cc",
594       "lib/browser/headless_web_contents_impl.h",
595       "lib/headless_content_main_delegate.cc",
596       "lib/headless_content_main_delegate.h",
597       "lib/renderer/headless_content_renderer_client.cc",
598       "lib/renderer/headless_content_renderer_client.h",
599       "lib/utility/headless_content_utility_client.cc",
600       "lib/utility/headless_content_utility_client.h",
601     ]
602
603     if (is_mac) {
604       sources += [ "lib/headless_content_main_delegate_mac.mm" ]
605     }
606
607     if (enable_basic_printing) {
608       sources += [
609         "lib/renderer/headless_print_render_frame_helper_delegate.cc",
610         "lib/renderer/headless_print_render_frame_helper_delegate.h",
611       ]
612     }
613
614     deps = [
615       ":headless_shared_sources",
616       "//build:chromeos_buildflags",
617       "//components/crash/core/common",
618       "//components/security_state/content",
619       "//components/security_state/core",
620       "//content/public/app",
621       "//content/public/browser",
622       "//content/public/common",
623       "//content/public/renderer",
624       "//content/public/utility",
625       "//printing/buildflags",
626       "//third_party/blink/public:blink_headers",
627       "//ui/base",
628       "//ui/compositor",
629       "//v8",
630     ]
631     if (use_ozone) {
632       deps += [ "//ui/ozone" ]
633     }
634     if (enable_basic_printing) {
635       deps += [
636         "//components/printing/renderer",
637         "//components/services/print_compositor",
638         "//components/services/print_compositor/public/mojom",
639       ]
640     }
641     configs += [ ":headless_defines_config" ]
642     if (headless_use_embedded_resources) {
643       defines += [ "HEADLESS_USE_EMBEDDED_RESOURCES" ]
644       deps += [ ":embed_resources" ]
645       sources += [
646         "$root_gen_dir/headless/embedded_resource_pak.cc",
647         "$root_gen_dir/headless/embedded_resource_pak.h",
648       ]
649     }
650
651     if (is_mac || is_win || is_linux || is_chromeos) {
652       deps += [ "//components/crash/core/app" ]
653     }
654   }
655 } else {
656   # For component builds all dependencies are already included in the headless
657   # component.
658   group("headless_renderer") {
659     deps = [ ":headless_non_renderer" ]
660   }
661 }
662
663 group("headless_tests") {
664   testonly = true
665
666   deps = [
667     ":headless_browsertests",
668     ":headless_example",
669     ":headless_unittests",
670   ]
671 }
672
673 test("headless_unittests") {
674   sources = [
675     "public/domains/types_unittest.cc",
676     "public/util/error_reporter_unittest.cc",
677   ]
678   defines = []
679
680   deps = [
681     ":headless_shell_lib",
682     "//base/test:run_all_unittests",
683     "//base/test:test_support",
684     "//components/security_state/content",
685     "//content/public/app",
686     "//content/public/child:child",
687     "//content/public/common",
688     "//testing/gmock",
689     "//testing/gtest",
690   ]
691
692   if (is_win) {
693     deps += [ "//components/crash/core/app:crash_export_thunks" ]
694   }
695
696   if (enable_basic_printing) {
697     sources += [ "lib/browser/headless_printing_unittest.cc" ]
698     deps += [
699       "//components/printing/browser",
700       "//printing",
701       "//printing/buildflags",
702       "//third_party/blink/public:blink",
703     ]
704   }
705
706   configs += [ ":headless_defines_config" ]
707 }
708
709 if (is_mac) {
710   copy("mac_helpers") {
711     sources = [ "$root_out_dir/chrome_crashpad_handler" ]
712
713     deps = [ "//components/crash/core/app:chrome_crashpad_handler" ]
714
715     outputs = [ "$root_out_dir/Helpers/{{source_file_part}}" ]
716   }
717 }
718
719 test("headless_browsertests") {
720   configs += [ "//net:net_test_config" ]
721   sources = [
722     "test/headless_browser_browsertest.cc",
723     "test/headless_browser_context_browsertest.cc",
724     "test/headless_browser_test.cc",
725     "test/headless_browser_test.h",
726     "test/headless_client_browsertest.cc",
727     "test/headless_devtools_client_browsertest.cc",
728     "test/headless_origin_trials_browsertest.cc",
729     "test/headless_policy_browsertest.cc",
730     "test/headless_policy_browsertest.h",
731     "test/headless_test_launcher.cc",
732     "test/headless_web_contents_browsertest.cc",
733     "test/test_network_interceptor.cc",
734     "test/test_network_interceptor.h",
735   ]
736
737   # TODO(https://crbug.com/1107396): These tests flakily timeout on fuchsia.
738   if (!is_fuchsia) {
739     sources += [
740       "test/headless_compositor_browsertest.cc",
741       "test/headless_protocol_browsertest.cc",
742       "test/headless_protocol_browsertest.h",
743     ]
744   }
745
746   data = [
747     "test/data/",
748     "test/dom_tree_extraction_expected_nodes.txt",
749     "test/dom_tree_extraction_expected_styles.txt",
750     "$root_out_dir/headless_lib.pak",
751     "//net/tools/testserver/",
752     "//third_party/blink/web_tests/http/tests/inspector-protocol/",
753     "//third_party/pywebsocket3/",
754     "//third_party/tlslite/",
755   ]
756
757   if (is_fuchsia) {
758     additional_manifest_fragments = [
759       "//build/config/fuchsia/test/font_capabilities.test-cmx",
760
761       # TODO(crbug.com/1185811): Figure out why jit_capabilities is needed.
762       "//build/config/fuchsia/test/jit_capabilities.test-cmx",
763
764       "//build/config/fuchsia/test/network_capabilities.test-cmx",
765       "//build/config/fuchsia/test/vulkan_capabilities.test-cmx",
766     ]
767   }
768
769   if (is_mac) {
770     data_deps = [ ":mac_helpers" ]
771   }
772
773   defines = [ "HAS_OUT_OF_PROC_TEST_RUNNER" ]
774
775   deps = [
776     ":headless_shell_lib",
777     "//base",
778     "//cc:test_support",
779     "//components/policy/core/browser",
780     "//components/security_state/content",
781     "//content/test:browsertest_support",
782     "//content/test:test_support",
783     "//net:test_support",
784     "//printing/buildflags",
785     "//services/network/public/mojom",
786     "//testing/gmock",
787     "//testing/gtest",
788     "//ui/base/clipboard",
789   ]
790
791   if (is_mac) {
792     deps += [ "//third_party/crashpad/crashpad/client" ]
793   }
794
795   if (enable_basic_printing) {
796     deps += [
797       "//components/printing/browser",
798       "//pdf",
799       "//printing",
800     ]
801   }
802
803   if (headless_use_policy) {
804     deps += [ "//components/policy/core/common:test_support" ]
805   }
806
807   configs += [ ":headless_defines_config" ]
808 }
809
810 if (is_win) {
811   # Headless library with only browser dependencies. This is used when no child
812   # dependencies are needed in the target (e.g. chrome:main_dll).
813   static_library("headless_shell_browser_lib") {
814     sources = [
815       "app/headless_shell.cc",
816       "app/headless_shell.h",
817       "lib/browser/headless_content_browser_client.cc",
818       "lib/browser/headless_content_browser_client.h",
819       "public/headless_shell.h",
820     ]
821     deps = [
822       ":headless_non_renderer",
823       "//build:branding_buildflags",
824       "//components/crash/core/app:run_as_crashpad_handler",
825       "//components/embedder_support",
826       "//content:sandbox_helper_win",
827       "//content/public/app",
828       "//content/public/browser",
829       "//content/public/common",
830       "//net",
831       "//printing/buildflags",
832       "//sandbox",
833     ]
834     if (headless_use_policy) {
835       deps += [ "//components/policy/content" ]
836     }
837     configs += [ ":headless_defines_config" ]
838   }
839 }
840
841 # Headless library with all included dependencies. Use this library unless you
842 # have browser/child dependencies restrictions.
843 static_library("headless_shell_lib") {
844   sources = [
845     "app/headless_shell.cc",
846     "app/headless_shell.h",
847     "public/headless_shell.h",
848   ]
849   defines = []
850
851   if (!is_component_build) {
852     sources += [
853       "lib/browser/headless_content_browser_client.cc",
854       "lib/browser/headless_content_browser_client.h",
855       "lib/utility/headless_content_utility_client.cc",
856       "lib/utility/headless_content_utility_client.h",
857     ]
858   }
859
860   deps = [
861     ":headless_renderer",
862     "//build:branding_buildflags",
863     "//components/embedder_support",
864     "//components/security_state/content",
865     "//content",
866     "//content/public/app",
867     "//content/public/browser",
868     "//content/public/child:child",
869     "//content/public/common",
870     "//content/public/utility",
871     "//printing/buildflags",
872   ]
873
874   public_deps = [ "//base" ]
875
876   if (!is_component_build) {
877     public_deps += [ ":headless_non_renderer" ]
878   }
879
880   if (!is_fuchsia) {
881     deps += [ "//components/crash/content/browser" ]
882   }
883
884   if (enable_basic_printing) {
885     deps += [
886       "//components/printing/browser",
887       "//components/printing/renderer",
888       "//components/services/print_compositor",
889       "//components/services/print_compositor/public/mojom",
890     ]
891   }
892
893   if (headless_use_policy && !is_component_build) {
894     deps += [ "//components/policy/content" ]
895   }
896
897   if (is_win) {
898     defines = [ "HEADLESS_USE_CRASHPAD" ]
899
900     deps += [
901       "//components/crash/core/app:run_as_crashpad_handler",
902       "//content:sandbox_helper_win",
903       "//sandbox",
904     ]
905   }
906
907   if (is_mac) {
908     deps += [ "//components/os_crypt" ]
909   }
910
911   if (is_win || (is_posix && !is_mac)) {
912     deps += [ "//components/crash/core/app" ]
913   }
914
915   configs += [ ":headless_defines_config" ]
916 }
917
918 if (is_fuchsia) {
919   cr_fuchsia_package("headless_shell_pkg") {
920     binary = ":headless_shell"
921     package_name_override = "headless_shell"
922     manifest = "//build/config/fuchsia/test/minimum_capabilities.test-cmx"
923   }
924
925   fuchsia_package_runner("headless_shell_fuchsia") {
926     package = ":headless_shell_pkg"
927     package_name_override = "headless_shell"
928   }
929 }
930
931 executable("headless_shell") {
932   sources = [ "app/headless_shell_main.cc" ]
933   defines = []
934
935   deps = [ ":headless_shell_lib" ]
936
937   if (!headless_use_embedded_resources) {
938     data = [ "$root_out_dir/headless_lib.pak" ]
939   }
940
941   if (is_win) {
942     deps += [
943       "//build/win:default_exe_manifest",
944       "//content/public/app",
945     ]
946   }
947
948   if (is_mac) {
949     deps += [ "//sandbox/mac:seatbelt" ]
950   }
951
952   configs += [ ":headless_defines_config" ]
953 }
954
955 process_version("version_header") {
956   template_file = "public/version.h.in"
957   sources = [
958     "//chrome/VERSION",
959     lastchange_file,
960   ]
961   output = "$target_gen_dir/public/version.h"
962 }
963
964 executable("headless_example") {
965   sources = [ "app/headless_example.cc" ]
966   defines = []
967
968   deps = [
969     ":headless_shell_lib",
970     "//content",
971     "//sandbox",
972     "//skia",  # we need this to override font render hinting in headless build
973     "//ui/gfx/geometry",
974   ]
975
976   if (is_win) {
977     deps += [ "//content/public/app" ]
978   }
979
980   configs += [ ":headless_defines_config" ]
981 }