#include "content/browser/service_worker/service_worker_client_utils.h"
#include <algorithm>
#include <memory>
#include <optional>
#include <tuple>
#include <utility>
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/location.h"
#include "base/task/sequenced_task_runner.h"
#include "base/task/single_thread_task_runner.h"
#include "base/time/time.h"
#include "content/browser/renderer_host/frame_tree_node.h"
#include "content/browser/renderer_host/navigation_request.h"
#include "content/browser/renderer_host/navigator.h"
#include "content/browser/renderer_host/render_frame_host_impl.h"
#include "content/browser/service_worker/service_worker_client.h"
#include "content/browser/service_worker/service_worker_context_core.h"
#include "content/browser/service_worker/service_worker_context_wrapper.h"
#include "content/browser/service_worker/service_worker_security_utils.h"
#include "content/browser/service_worker/service_worker_version.h"
#include "content/browser/web_contents/web_contents_impl.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/child_process_host.h"
#include "content/public/browser/content_browser_client.h"
#include "content/public/browser/global_routing_id.h"
#include "content/public/browser/navigation_handle.h"
#include "content/public/browser/page_navigator.h"
#include "content/public/browser/payment_app_provider.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_widget_host_view.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_observer.h"
#include "content/public/common/content_client.h"
#include "content/public/common/page_visibility_state.h"
#include "third_party/blink/public/common/storage_key/storage_key.h"
#include "third_party/blink/public/mojom/loader/request_context_frame_type.mojom.h"
#include "ui/base/window_open_disposition.h"
#include "url/gurl.h"
#include "url/origin.h"
namespace content {
namespace service_worker_client_utils {
namespace {
OpenURLCallback;
class OpenURLObserver : public WebContentsObserver { … };
blink::mojom::ServiceWorkerClientInfoPtr GetWindowClientInfo(
const GlobalRenderFrameHostId& rfh_id,
base::TimeTicks create_time,
const std::string& client_uuid) { … }
void DidOpenURL(OpenURLCallback callback, WebContents* web_contents) { … }
void AddWindowClient(
const ServiceWorkerClient& service_worker_client,
std::vector<
std::tuple<GlobalRenderFrameHostId, base::TimeTicks, std::string>>*
client_info) { … }
void AddNonWindowClient(
const ServiceWorkerClient& service_worker_client,
blink::mojom::ServiceWorkerClientType client_type,
std::vector<blink::mojom::ServiceWorkerClientInfoPtr>* out_clients) { … }
struct ServiceWorkerClientInfoSort { … };
void DidGetClients(
blink::mojom::ServiceWorkerHost::GetClientsCallback callback,
std::vector<blink::mojom::ServiceWorkerClientInfoPtr> clients) { … }
void GetNonWindowClients(
const base::WeakPtr<ServiceWorkerVersion>& controller,
blink::mojom::ServiceWorkerClientQueryOptionsPtr options,
blink::mojom::ServiceWorkerHost::GetClientsCallback callback,
std::vector<blink::mojom::ServiceWorkerClientInfoPtr> clients) { … }
void DidGetWindowClients(
const base::WeakPtr<ServiceWorkerVersion>& controller,
blink::mojom::ServiceWorkerClientQueryOptionsPtr options,
blink::mojom::ServiceWorkerHost::GetClientsCallback callback,
std::vector<blink::mojom::ServiceWorkerClientInfoPtr> clients) { … }
void GetWindowClients(
const base::WeakPtr<ServiceWorkerVersion>& controller,
blink::mojom::ServiceWorkerClientQueryOptionsPtr options,
blink::mojom::ServiceWorkerHost::GetClientsCallback callback,
std::vector<blink::mojom::ServiceWorkerClientInfoPtr> clients) { … }
void DidGetExecutionReadyClient(
const base::WeakPtr<ServiceWorkerContextCore>& context,
const std::string& client_uuid,
const GURL& script_url,
const blink::StorageKey& key,
NavigationCallback callback) { … }
}
void FocusWindowClient(ServiceWorkerClient* service_worker_client,
ClientCallback callback) { … }
void OpenWindow(const GURL& url,
const GURL& script_url,
const blink::StorageKey& key,
int worker_id,
int worker_process_id,
const base::WeakPtr<ServiceWorkerContextCore>& context,
WindowType type,
NavigationCallback callback) { … }
void NavigateClient(const GURL& url,
const GURL& script_url,
const blink::StorageKey& key,
const GlobalRenderFrameHostId& rfh_id,
const base::WeakPtr<ServiceWorkerContextCore>& context,
NavigationCallback callback) { … }
void GetClient(ServiceWorkerClient* service_worker_client,
ClientCallback callback) { … }
void GetClients(const base::WeakPtr<ServiceWorkerVersion>& controller,
blink::mojom::ServiceWorkerClientQueryOptionsPtr options,
blink::mojom::ServiceWorkerHost::GetClientsCallback callback) { … }
void DidNavigate(const base::WeakPtr<ServiceWorkerContextCore>& context,
const GURL& script_url,
const blink::StorageKey& key,
NavigationCallback callback,
GlobalRenderFrameHostId rfh_id) { … }
}
}