Render lost WebGL contexts as a "sad canvas".

Remove the "Rats!" WebGL infobar and associated content/public API.
Blocking of WebGL is now handled entirely within content/.

Allow a particular domain to use WebGL again after a lost context via
any user-initiated or browser-initiated navigation (reload, explicit
navigation via the Omnibox, DevTools / Telemetry), but not reloads
initiated from JavaScript.

Bug: 575305

Cq-Include-Trybots: luci.chromium.try:android_optional_gpu_tests_rel;luci.chromium.try:linux_optional_gpu_tests_rel;luci.chromium.try:mac_optional_gpu_tests_rel;luci.chromium.try:win_optional_gpu_tests_rel
Change-Id: I9d9f65ba5f8ff6afe3da58d358ad88fb85c999c8
Reviewed-on: https://chromium-review.googlesource.com/522938
Reviewed-by: Kai Ninomiya <[email protected]>
Reviewed-by: Jochen Eisinger <[email protected]>
Reviewed-by: Ilya Sherman <[email protected]>
Reviewed-by: Antoine Labour <[email protected]>
Reviewed-by: Zhenyao Mo <[email protected]>
Reviewed-by: John Abd-El-Malek <[email protected]>
Commit-Queue: Kenneth Russell <[email protected]>
Cr-Commit-Position: refs/heads/master@{#550403}
diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc
index 6c71fa2..a45b0e7 100644
--- a/content/browser/web_contents/web_contents_impl.cc
+++ b/content/browser/web_contents/web_contents_impl.cc
@@ -56,6 +56,7 @@
 #include "content/browser/frame_host/navigator_impl.h"
 #include "content/browser/frame_host/render_frame_host_impl.h"
 #include "content/browser/frame_host/render_frame_proxy_host.h"
+#include "content/browser/gpu/gpu_data_manager_impl.h"
 #include "content/browser/loader/loader_io_thread_notifier.h"
 #include "content/browser/loader/resource_dispatcher_host_impl.h"
 #include "content/browser/manifest/manifest_manager_host.h"
@@ -3805,6 +3806,26 @@
   for (auto& observer : observers_)
     observer.ReadyToCommitNavigation(navigation_handle);
 
+  // If any domains are blocked from accessing 3D APIs because they may
+  // have caused the GPU to reset recently, unblock them here if the user
+  // initiated this navigation. This implies that the user was involved in
+  // the decision to navigate, so there's no concern about
+  // denial-of-service issues. Want to do this as early as
+  // possible to avoid race conditions with pages attempting to access
+  // WebGL early on.
+  //
+  // TODO(crbug.com/617904): currently navigations initiated by the browser
+  // (reload button, reload menu option, pressing return in the Omnibox)
+  // return false from HasUserGesture(). If or when that is addressed,
+  // remove the check for IsRendererInitiated() below.
+  //
+  // TODO(crbug.com/832180): HasUserGesture comes from the renderer
+  // process and isn't validated. Until it is, don't trust it.
+  if (!navigation_handle->IsRendererInitiated()) {
+    GpuDataManagerImpl::GetInstance()->UnblockDomainFrom3DAPIs(
+        navigation_handle->GetURL());
+  }
+
   if (navigation_handle->IsSameDocument())
     return;