// Copyright 2017 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef CONTENT_PUBLIC_BROWSER_DOCUMENT_SERVICE_H_ #define CONTENT_PUBLIC_BROWSER_DOCUMENT_SERVICE_H_ #include #include #include "base/bind.h" #include "base/check.h" #include "base/strings/string_piece.h" #include "base/threading/thread_checker.h" #include "content/public/browser/document_service_internal.h" #include "content/public/browser/render_frame_host.h" #include "mojo/public/cpp/bindings/pending_receiver.h" #include "mojo/public/cpp/bindings/receiver.h" #include "url/origin.h" namespace content { enum class DocumentServiceDestructionReason : int { // The mojo connection terminated. kConnectionTerminated, // The document pointed to by `render_frame_host()` is being destroyed. kEndOfDocumentLifetime, }; // Provides a safe alternative to mojo::MakeSelfOwnedReceiver(...) for // document-scoped Mojo interface implementations. Use of this helper prevents // logic bugs when Mojo IPCs for `Interface` race against Mojo IPCs for // navigation. One example of a past bug caused by this IPC race is // https://crbug.com/769189, where an interface implementation performed a // permission check using the wrong origin. // // Like C++ implementations owned by mojo::MakeSelfOwnedReceiver(...), a // subclass of DocumentService will delete itself when the // corresponding message pipe is disconnected by setting a disconnect handler on // the mojo::Receiver. // // In addition, a subclass of DocumentService will also track // the lifetime of the current document of the supplied RenderFrameHost and // delete itself: // // - if the RenderFrameHost is deleted (for example, the