WebApps: Enables/disables file handling depending on trial validity.

File handling is a slightly different to other features which go into
origin trial: The underlying OS holds state to let it identify handlers
for different file types.

This CL cleans up that state when an origin trial expires, so that apps
which don't have a valid trial, don't show up as file handlers in the
operating system.

On navigation to a page inside an installed app with file handlers,
we store the time that the trial expires. If the trial has
already expired, we unregister the file handlers. If the trial is valid,
but the app's file handlers are not registered, we register them.

On Chrome start up, we unregister file handlers for all apps for
which the origin trial has past it's expiry date.

This ensures that apps without a valid origin trial token will show up
in the open with menu at most one Chrome restart, or until the user
visits the site again, whichever happens first.

Bug: 1028448
Change-Id: I6e2d19d7462d1f94955f1ca51abffd2a4c53096d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1940001
Reviewed-by: Kinuko Yasuda <[email protected]>
Reviewed-by: Giovanni Ortuño Urquidi <[email protected]>
Commit-Queue: Jay Harris <[email protected]>
Cr-Commit-Position: refs/heads/master@{#739137}
diff --git a/third_party/blink/public/mojom/BUILD.gn b/third_party/blink/public/mojom/BUILD.gn
index 30301a0..e480591 100644
--- a/third_party/blink/public/mojom/BUILD.gn
+++ b/third_party/blink/public/mojom/BUILD.gn
@@ -145,6 +145,7 @@
     "user_agent/user_agent_metadata.mojom",
     "v8_cache_options.mojom",
     "wake_lock/wake_lock.mojom",
+    "web_launch/file_handling_expiry.mojom",
     "web_launch/web_launch.mojom",
     "webaudio/audio_context_manager.mojom",
     "webdatabase/web_database.mojom",
diff --git a/third_party/blink/public/mojom/web_launch/file_handling_expiry.mojom b/third_party/blink/public/mojom/web_launch/file_handling_expiry.mojom
new file mode 100644
index 0000000..d77af7b7
--- /dev/null
+++ b/third_party/blink/public/mojom/web_launch/file_handling_expiry.mojom
@@ -0,0 +1,21 @@
+// Copyright 2020 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+module blink.mojom;
+
+import "mojo/public/mojom/base/time.mojom";
+
+// Interface for finding when the file handling origin trial for a WebApp will
+// expire. This information is needed because file handlers are registered
+// outside Chromium, in the underlying operating system, so we need to know
+// when the trial expires so that they can be cleaned up.
+//
+// This service is hosted in the renderer. The browser process is responsible
+// for acquiring this interface and calling it.
+interface FileHandlingExpiry {
+  // Gets the time that the FileHandlingAPI origin trial will expire. If there
+  // is a valid token, this will return the time the token expires. Otherwise
+  // it will return base::Time().
+  RequestOriginTrialExpiryTime() => (mojo_base.mojom.Time expiry_time);
+};
\ No newline at end of file