Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(460)

Side by Side Diff: content/browser/media/capture/web_contents_tracker.h

Issue 1135823004: Implement all resolution change policies for desktop and tab capture. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@resolution_change_policy_constraints_ITEM1_CR1
Patch Set: Addressed Dale's comments. Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 // 4 //
5 // Given a starting render_process_id and main_render_frame_id, the 5 // Given a starting render_process_id and main_render_frame_id, the
6 // WebContentsTracker tracks changes to the active RenderFrameHost tree during 6 // WebContentsTracker tracks changes to the active RenderFrameHost tree during
7 // the lifetime of a WebContents instance. This is used when mirroring tab 7 // the lifetime of a WebContents instance. This is used when mirroring tab
8 // video and audio so that user navigations, crashes, iframes, etc., during a 8 // video and audio so that user navigations, crashes, iframes, etc., during a
9 // tab's lifetime allow the capturing code to remain active on the 9 // tab's lifetime allow the capturing code to remain active on the
10 // current/latest render frame tree. 10 // current/latest render frame tree.
(...skipping 24 matching lines...) Expand all
35 public: 35 public:
36 // If |track_fullscreen_rwh| is true, the ChangeCallback will be run when a 36 // If |track_fullscreen_rwh| is true, the ChangeCallback will be run when a
37 // WebContents shows/destroys a fullscreen RenderWidgetHost view. If false, 37 // WebContents shows/destroys a fullscreen RenderWidgetHost view. If false,
38 // fullscreen events are ignored. Specify true for video tab capture and 38 // fullscreen events are ignored. Specify true for video tab capture and
39 // false for audio tab capture. 39 // false for audio tab capture.
40 explicit WebContentsTracker(bool track_fullscreen_rwh); 40 explicit WebContentsTracker(bool track_fullscreen_rwh);
41 41
42 // Callback to indicate a new RenderWidgetHost should be targeted for capture. 42 // Callback to indicate a new RenderWidgetHost should be targeted for capture.
43 // This is also invoked with NULL to indicate tracking will not continue 43 // This is also invoked with NULL to indicate tracking will not continue
44 // (i.e., the WebContents instance was not found or has been destroyed). 44 // (i.e., the WebContents instance was not found or has been destroyed).
45 typedef base::Callback<void(RenderWidgetHost* rwh)> ChangeCallback; 45 typedef base::Callback<void(RenderWidgetHost* rwh)> ChangeCallback;
Wez 2015/05/14 01:44:55 As noted in the MaybeDoResizeCallback() impl, this
miu 2015/05/14 21:12:27 Agreed about the safety concern. See my response
46 46
47 // Start tracking. The last-known |render_process_id| and 47 // Start tracking. The last-known |render_process_id| and
48 // |main_render_frame_id| are provided, and |callback| will be run once to 48 // |main_render_frame_id| are provided, and |callback| will be run once to
49 // indicate the current capture target (this may occur during the invocation 49 // indicate the current capture target (this may occur during the invocation
50 // of Start(), or in the future). The callback will be invoked on the same 50 // of Start(), or in the future). The callback will be invoked on the same
51 // thread calling Start(). 51 // thread calling Start().
52 virtual void Start(int render_process_id, int main_render_frame_id, 52 virtual void Start(int render_process_id, int main_render_frame_id,
53 const ChangeCallback& callback); 53 const ChangeCallback& callback);
54 54
55 // Stop tracking. Once this method returns, the callback is guaranteed not to 55 // Stop tracking. Once this method returns, the callback is guaranteed not to
56 // be invoked again. 56 // be invoked again.
57 virtual void Stop(); 57 virtual void Stop();
58 58
59 // Current target. This must only be called on the UI BrowserThread. 59 // Current target. This must only be called on the UI BrowserThread.
60 RenderWidgetHost* GetTargetRenderWidgetHost() const; 60 RenderWidgetHost* GetTargetRenderWidgetHost() const;
61 61
62 // Set a callback that is run whenever the main frame of the WebContents is
63 // resized. The callback will be invoked on the same thread that called this
64 // method, which should be the same thread that calls Start()/Stop(). Calling
Wez 2015/05/14 01:44:55 nit: Suggest clarifying that this must be called f
miu 2015/05/14 21:12:27 Done.
65 // the Stop() method guarantees the callback will never be invoked again.
66 void SetResizeChangeCallback(const ChangeCallback& callback);
67
62 protected: 68 protected:
63 friend class base::RefCountedThreadSafe<WebContentsTracker>; 69 friend class base::RefCountedThreadSafe<WebContentsTracker>;
64 ~WebContentsTracker() override; 70 ~WebContentsTracker() override;
65 71
66 private: 72 private:
67 // Determine the target RenderWidgetHost and, if different from that last 73 // Determine the target RenderWidgetHost and, if different from that last
68 // reported, runs the ChangeCallback on the appropriate thread. If 74 // reported, runs the ChangeCallback on the appropriate thread. If
69 // |force_callback_run| is true, the ChangeCallback is run even if the 75 // |force_callback_run| is true, the ChangeCallback is run even if the
70 // RenderWidgetHost has not changed. 76 // RenderWidgetHost has not changed.
71 void OnPossibleTargetChange(bool force_callback_run); 77 void OnPossibleTargetChange(bool force_callback_run);
72 78
73 // Called on the thread that Start()/Stop() are called on. Checks whether the 79 // Called on the thread that Start()/Stop() are called on. Checks whether the
74 // callback is still valid and, if so, runs it. 80 // callback is still valid and, if so, runs it.
75 void MaybeDoCallback(RenderWidgetHost* rwh); 81 void MaybeDoCallback(RenderWidgetHost* rwh);
76 82
83 // Called on the thread that Start()/Stop() are called on. Checks whether the
84 // callback is still valid and, if so, runs it to indicate the main frame has
85 // changed in size.
86 void MaybeDoResizeCallback(RenderWidgetHost* rwh);
87
77 // Look-up the current WebContents instance associated with the given 88 // Look-up the current WebContents instance associated with the given
78 // |render_process_id| and |main_render_frame_id| and begin observing it. 89 // |render_process_id| and |main_render_frame_id| and begin observing it.
79 void StartObservingWebContents(int render_process_id, 90 void StartObservingWebContents(int render_process_id,
80 int main_render_frame_id); 91 int main_render_frame_id);
81 92
82 // WebContentsObserver overrides: According to web_contents_observer.h, these 93 // WebContentsObserver overrides: According to web_contents_observer.h, these
83 // two method overrides are all that is necessary to track the set of active 94 // two method overrides are all that is necessary to track the set of active
84 // RenderFrameHosts. 95 // RenderFrameHosts.
85 void RenderFrameDeleted(RenderFrameHost* render_frame_host) override; 96 void RenderFrameDeleted(RenderFrameHost* render_frame_host) override;
86 void RenderFrameHostChanged(RenderFrameHost* old_host, 97 void RenderFrameHostChanged(RenderFrameHost* old_host,
87 RenderFrameHost* new_host) override; 98 RenderFrameHost* new_host) override;
88 99
100 // WebContentsObserver override to notify the client that the source size has
101 // changed.
102 void MainFrameWasResized(bool width_changed) override;
103
89 // WebContentsObserver override to notify the client that the capture target 104 // WebContentsObserver override to notify the client that the capture target
90 // has been permanently lost. 105 // has been permanently lost.
91 void WebContentsDestroyed() override; 106 void WebContentsDestroyed() override;
92 107
93 // WebContentsObserver overrides to notify the client that the capture target 108 // WebContentsObserver overrides to notify the client that the capture target
94 // may have changed due to a separate fullscreen widget shown/destroyed. 109 // may have changed due to a separate fullscreen widget shown/destroyed.
95 void DidShowFullscreenWidget(int routing_id) override; 110 void DidShowFullscreenWidget(int routing_id) override;
96 void DidDestroyFullscreenWidget(int routing_id) override; 111 void DidDestroyFullscreenWidget(int routing_id) override;
97 112
98 // If true, the client is interested in the showing/destruction of fullscreen 113 // If true, the client is interested in the showing/destruction of fullscreen
99 // RenderWidgetHosts. 114 // RenderWidgetHosts.
100 const bool track_fullscreen_rwh_; 115 const bool track_fullscreen_rwh_;
101 116
102 // TaskRunner corresponding to the thread that called Start(). 117 // TaskRunner corresponding to the thread that called Start().
103 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; 118 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
104 119
105 // Callback to run when the target RenderWidgetHost has changed. 120 // Callback to run when the target RenderWidgetHost has changed.
106 ChangeCallback callback_; 121 ChangeCallback callback_;
107 122
108 // Pointer to the RenderWidgetHost provided in the last run of |callback_|. 123 // Pointer to the RenderWidgetHost provided in the last run of |callback_|.
109 // This is used to eliminate duplicate callback runs. 124 // This is used to eliminate duplicate callback runs.
110 RenderWidgetHost* last_target_; 125 RenderWidgetHost* last_target_;
111 126
127 // Callback to run when the target RenderWidgetHost has resized.
128 ChangeCallback resize_callback_;
129
112 DISALLOW_COPY_AND_ASSIGN(WebContentsTracker); 130 DISALLOW_COPY_AND_ASSIGN(WebContentsTracker);
113 }; 131 };
114 132
115 } // namespace content 133 } // namespace content
116 134
117 #endif // CONTENT_BROWSER_MEDIA_CAPTURE_WEB_CONTENTS_TRACKER_H_ 135 #endif // CONTENT_BROWSER_MEDIA_CAPTURE_WEB_CONTENTS_TRACKER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698