blob: 9fdfff1607d272b33fd41f088850adbbeb0d8d34 [file] [log] [blame]
Avi Drissman4e1b7bc32022-09-15 14:03:501// Copyright 2012 The Chromium Authors
[email protected]1d8a3d1f2011-02-19 07:11:522// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HELPER_H_
6#define CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HELPER_H_
[email protected]1d8a3d1f2011-02-19 07:11:527
avib533f5d2015-12-25 03:11:158#include <stdint.h>
9
[email protected]1d8a3d1f2011-02-19 07:11:5210#include <map>
11
lfg052af412015-03-19 16:49:5312#include "base/atomic_sequence_num.h"
[email protected]3b63f8f42011-03-28 01:54:1513#include "base/memory/ref_counted.h"
[email protected]fa20e002013-07-23 21:20:5414#include "base/process/process.h"
Dave Tapuska4e60c232020-11-05 15:49:3215#include "base/synchronization/lock.h"
16#include "base/thread_annotations.h"
[email protected]c63b4d42012-04-26 01:01:0717#include "content/public/browser/browser_thread.h"
[email protected]e1986832013-06-14 07:27:2818#include "content/public/browser/global_request_id.h"
danakj829cdd142018-09-14 21:13:2719#include "content/public/common/widget_type.h"
Julie Jeongeun Kimcaacf9102019-09-12 02:13:0520#include "mojo/public/cpp/bindings/pending_remote.h"
Chris Hamilton6c60a832021-02-19 20:35:4621#include "third_party/blink/public/common/tokens/tokens.h"
[email protected]1d8a3d1f2011-02-19 07:11:5222
[email protected]fc4616f2012-07-21 01:29:5823namespace content {
csharrison95f01e922017-04-24 18:52:3524
[email protected]1d8a3d1f2011-02-19 07:11:5225// Instantiated per RenderProcessHost to provide various optimizations on
26// behalf of a RenderWidgetHost. This class bridges between the IO thread
27// where the RenderProcessHost's MessageFilter lives and the UI thread where
28// the RenderWidgetHost lives.
[email protected]1d8a3d1f2011-02-19 07:11:5229class RenderWidgetHelper
[email protected]fc4616f2012-07-21 01:29:5830 : public base::RefCountedThreadSafe<RenderWidgetHelper,
31 BrowserThread::DeleteOnIOThread> {
[email protected]1d8a3d1f2011-02-19 07:11:5232 public:
33 RenderWidgetHelper();
34
Peter Boström9b036532021-10-28 23:37:2835 RenderWidgetHelper(const RenderWidgetHelper&) = delete;
36 RenderWidgetHelper& operator=(const RenderWidgetHelper&) = delete;
37
John Abd-El-Malek0e82fe7f2019-07-27 00:06:2938 void Init(int render_process_id);
[email protected]1d8a3d1f2011-02-19 07:11:5239
40 // Gets the next available routing id. This is thread safe.
41 int GetNextRoutingID();
42
Dave Tapuska9291eff2023-12-08 17:06:3743 // Retrieve a previously stored data. Returns true if the tokens
Dave Tapuska4e60c232020-11-05 15:49:3244 // were found.
Dave Tapuska9291eff2023-12-08 17:06:3745 bool TakeStoredDataForFrameToken(const blink::LocalFrameToken& frame_token,
46 int32_t& routing_id,
47 base::UnguessableToken& devtools_frame_token,
48 blink::DocumentToken& document_token);
Dave Tapuska4e60c232020-11-05 15:49:3249
50 // Store a set of frame tokens given a routing id. This is usually called on
51 // the IO thread, and |GetFrameTokensForFrameRoutingID| will be called on the
52 // UI thread at a later point.
53 void StoreNextFrameRoutingID(
54 int32_t routing_id,
Chris Hamilton6c60a832021-02-19 20:35:4655 const blink::LocalFrameToken& frame_token,
Daniel Cheng284c38942022-09-22 23:30:3456 const base::UnguessableToken& devtools_frame_token,
57 const blink::DocumentToken& document_token);
Dave Tapuska4e60c232020-11-05 15:49:3258
[email protected]c63b4d42012-04-26 01:01:0759 // IO THREAD ONLY -----------------------------------------------------------
60
[email protected]1d8a3d1f2011-02-19 07:11:5261 private:
[email protected]1d8a3d1f2011-02-19 07:11:5262 friend class base::RefCountedThreadSafe<RenderWidgetHelper>;
[email protected]fc4616f2012-07-21 01:29:5863 friend struct BrowserThread::DeleteOnThread<BrowserThread::IO>;
[email protected]c63b4d42012-04-26 01:01:0764 friend class base::DeleteHelper<RenderWidgetHelper>;
[email protected]1d8a3d1f2011-02-19 07:11:5265
[email protected]1d8a3d1f2011-02-19 07:11:5266 ~RenderWidgetHelper();
67
[email protected]1d8a3d1f2011-02-19 07:11:5268 int render_process_id_;
69
Dave Tapuska4e60c232020-11-05 15:49:3270 struct FrameTokens {
Dave Tapuska9291eff2023-12-08 17:06:3771 FrameTokens(int32_t routing_id,
Daniel Cheng284c38942022-09-22 23:30:3472 const base::UnguessableToken& devtools_frame_token,
73 const blink::DocumentToken& document_token);
Chris Hamilton6c60a832021-02-19 20:35:4674 FrameTokens(const FrameTokens& other);
75 FrameTokens& operator=(const FrameTokens& other);
76 ~FrameTokens();
77
Dave Tapuska9291eff2023-12-08 17:06:3778 int32_t routing_id;
Dave Tapuska4e60c232020-11-05 15:49:3279 base::UnguessableToken devtools_frame_token;
Daniel Cheng284c38942022-09-22 23:30:3480 blink::DocumentToken document_token;
Dave Tapuska4e60c232020-11-05 15:49:3281 };
82
Dave Tapuska9291eff2023-12-08 17:06:3783 // Lock that is used to provide access to `frame_storage_map_`
Dave Tapuska4e60c232020-11-05 15:49:3284 // from the IO and UI threads.
85 base::Lock frame_token_map_lock_;
86
87 // Map that stores handed out routing IDs and frame tokens. Items
Dave Tapuska9291eff2023-12-08 17:06:3788 // will be removed from this table in TakeStoredDataForFrameToken.
Dave Tapuska4e60c232020-11-05 15:49:3289 // Locked by |lock_|
Dave Tapuska9291eff2023-12-08 17:06:3790 std::map<blink::LocalFrameToken, FrameTokens> frame_storage_map_
Dave Tapuska4e60c232020-11-05 15:49:3291 GUARDED_BY(frame_token_map_lock_);
92
lfg052af412015-03-19 16:49:5393 // The next routing id to use.
94 base::AtomicSequenceNumber next_routing_id_;
[email protected]1d8a3d1f2011-02-19 07:11:5295};
96
[email protected]fc4616f2012-07-21 01:29:5897} // namespace content
98
[email protected]1d8a3d1f2011-02-19 07:11:5299#endif // CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HELPER_H_