Fixing mojo dependencies for blink/modules/indexeddb

This splits the mojo code in two. Once small chunk of helper classes that
are mojo wrapped, and some high level code that is allowed to use mojo
itself.

This CL also makes it allowed and possible to use modules_export.h in
mojo types that map to code in blink/modules.

Without this patch gn check --check-generated reports errors like
the ones below:

ERROR at //out/Default/gen/third_party/blink/public/mojom/indexeddb/indexeddb.mojom-blink-forward.h:24:11: Include not allowed.
-#include "third_party/blink/renderer/modules/modules_export.h"
          ^--------------------------------------------------
It is not in any dependency of
  //third_party/blink/public/mojom:mojom_modules_blink
The include file is in the target(s):
  //third_party/blink/renderer/modules:modules
which should somehow be reachable.
------------------------------------------------
ERROR at //out/Default/gen/third_party/blink/public/mojom/indexeddb/indexeddb.mojom-blink.h:55:11: Include not allowed.
#include "third_party/blink/renderer/modules/indexeddb/idb_key_path.h"
          ^----------------------------------------------------------
It is not in any dependency of
  //third_party/blink/public/mojom:mojom_modules_blink
The include file is in the target(s):
  //third_party/blink/renderer/modules/indexeddb:indexeddb
which should somehow be reachable.

Bug: 938893
Change-Id: I0cd9bfb502fa4290a21e61f686b6095455eb4e86
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1547696
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Commit-Queue: Daniel Bratell <bratell@opera.com>
Cr-Commit-Position: refs/heads/master@{#647200}
diff --git a/third_party/blink/public/mojom/BUILD.gn b/third_party/blink/public/mojom/BUILD.gn
index 8aae434..96f7c52 100644
--- a/third_party/blink/public/mojom/BUILD.gn
+++ b/third_party/blink/public/mojom/BUILD.gn
@@ -319,7 +319,10 @@
     ":mojom_core",
     ":mojom_platform",
   ]
-  component_deps_blink = [ "//third_party/blink/renderer/core" ]
+  component_deps_blink = [
+    "//third_party/blink/renderer/core",
+    "//third_party/blink/renderer/modules:modules_export_header",
+  ]
 
   export_class_attribute = "BLINK_COMMON_EXPORT"
   export_define = "BLINK_COMMON_IMPLEMENTATION=1"
diff --git a/third_party/blink/renderer/modules/BUILD.gn b/third_party/blink/renderer/modules/BUILD.gn
index 24999f7..2a7f86f 100644
--- a/third_party/blink/renderer/modules/BUILD.gn
+++ b/third_party/blink/renderer/modules/BUILD.gn
@@ -55,7 +55,6 @@
     "event_modules.h",
     "event_modules_factory.h",
     "event_target_modules.h",
-    "modules_export.h",
     "modules_initializer.cc",
     "modules_initializer.h",
   ]
@@ -81,6 +80,10 @@
     "//tools/v8_context_snapshot:use_v8_context_snapshot",
   ]
 
+  public_deps = [
+    ":modules_export_header",
+  ]
+
   deps = [
     ":make_modules_generated",
     ":module_names",
@@ -191,6 +194,20 @@
   }
 }
 
+# modules_export.h is in its own build target to allow mojo types to use it
+# without depending on the whole of modules.
+source_set("modules_export_header") {
+  # Opening up for mojo types to use this header.
+  visibility = []
+  visibility = [
+    "//third_party/blink/public/mojom:mojom_modules_blink",
+    "//third_party/blink/renderer/*",
+  ]
+  sources = [
+    "modules_export.h",
+  ]
+}
+
 jumbo_source_set("modules_testing") {
   sources = [
     "$bindings_modules_v8_output_dir/v8_internals_partial.cc",
diff --git a/third_party/blink/renderer/modules/indexeddb/BUILD.gn b/third_party/blink/renderer/modules/indexeddb/BUILD.gn
index 48b1124..80c1435 100644
--- a/third_party/blink/renderer/modules/indexeddb/BUILD.gn
+++ b/third_party/blink/renderer/modules/indexeddb/BUILD.gn
@@ -25,15 +25,6 @@
     "idb_factory.h",
     "idb_index.cc",
     "idb_index.h",
-    "idb_key.cc",
-    "idb_key.h",
-    "idb_key_path.cc",
-    "idb_key_path.h",
-    "idb_key_range.cc",
-    "idb_key_range.h",
-    "idb_metadata.cc",
-    "idb_metadata.h",
-    "idb_name_and_version.h",
     "idb_object_store.cc",
     "idb_object_store.h",
     "idb_observation.cc",
@@ -53,15 +44,11 @@
     "idb_tracing.h",
     "idb_transaction.cc",
     "idb_transaction.h",
-    "idb_value.cc",
-    "idb_value.h",
     "idb_value_wrapping.cc",
     "idb_value_wrapping.h",
     "idb_version_change_event.cc",
     "idb_version_change_event.h",
     "indexed_db.h",
-    "indexed_db_blink_mojom_traits.cc",
-    "indexed_db_blink_mojom_traits.h",
     "indexed_db_client.cc",
     "indexed_db_client.h",
     "indexed_db_database_callbacks_impl.cc",
@@ -91,6 +78,34 @@
   ]
 
   public_deps = [
+    ":mojo_wrapped_idb_types",
     "//third_party/blink/public/mojom:mojom_modules_blink",
   ]
 }
+
+# Some of the code is in its own build target to that it can be used
+# from the mojo type IDBKeyRange without creating a dependency cycle
+# between indexeddb and the mojo bindings.
+blink_modules_sources("mojo_wrapped_idb_types") {
+  visibility = []
+  visibility = [
+    "//third_party/blink/public/mojom:mojom_modules_blink",
+    "//third_party/blink/renderer/modules/*",
+  ]
+
+  sources = [
+    "idb_key.cc",
+    "idb_key.h",
+    "idb_key_path.cc",
+    "idb_key_path.h",
+    "idb_key_range.cc",
+    "idb_key_range.h",
+    "idb_metadata.cc",
+    "idb_metadata.h",
+    "idb_name_and_version.h",
+    "idb_value.cc",
+    "idb_value.h",
+    "indexed_db_blink_mojom_traits.cc",
+    "indexed_db_blink_mojom_traits.h",
+  ]
+}
diff --git a/third_party/blink/renderer/modules/indexeddb/indexed_db_blink.typemap b/third_party/blink/renderer/modules/indexeddb/indexed_db_blink.typemap
index 536050e..7ad4e3a6 100644
--- a/third_party/blink/renderer/modules/indexeddb/indexed_db_blink.typemap
+++ b/third_party/blink/renderer/modules/indexeddb/indexed_db_blink.typemap
@@ -19,6 +19,7 @@
 ]
 deps = [
   "//mojo/public/cpp/bindings",
+  "//third_party/blink/renderer/modules/indexeddb:mojo_wrapped_idb_types",
   "//third_party/blink/renderer/platform/wtf",
 ]
 type_mappings = [