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