[ContentIndex] Check if the SW is active.

As per 5.3.1.2 in the spec:
https://rayankans.github.io/content-index/spec/#content-index-add

Bug: 973844
Change-Id: Ib69b56b2f1def930ac62d40b4175a8bd65f964bb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1781679
Reviewed-by: Richard Knoll <[email protected]>
Reviewed-by: Mike West <[email protected]>
Commit-Queue: Rayan Kanso <[email protected]>
Cr-Commit-Position: refs/heads/master@{#693115}
diff --git a/content/browser/content_index/content_index_database.cc b/content/browser/content_index/content_index_database.cc
index 188ba82f..f3aaaa4 100644
--- a/content/browser/content_index/content_index_database.cc
+++ b/content/browser/content_index/content_index_database.cc
@@ -174,6 +174,15 @@
     return;
   }
 
+  auto* service_worker_registration =
+      service_worker_context_->GetLiveRegistration(
+          service_worker_registration_id);
+  if (!service_worker_registration ||
+      !service_worker_registration->active_version()) {
+    std::move(callback).Run(blink::mojom::ContentIndexError::NO_SERVICE_WORKER);
+    return;
+  }
+
   auto serialized_icons = std::make_unique<proto::SerializedIcons>();
   proto::SerializedIcons* serialized_icons_ptr = serialized_icons.get();