OLD | NEW |
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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 protected: | 62 protected: |
63 friend class base::RefCountedThreadSafe<WebContentsTracker>; | 63 friend class base::RefCountedThreadSafe<WebContentsTracker>; |
64 virtual ~WebContentsTracker(); | 64 ~WebContentsTracker() override; |
65 | 65 |
66 private: | 66 private: |
67 // Determine the target RenderWidgetHost and, if different from that last | 67 // Determine the target RenderWidgetHost and, if different from that last |
68 // reported, runs the ChangeCallback on the appropriate thread. If | 68 // reported, runs the ChangeCallback on the appropriate thread. If |
69 // |force_callback_run| is true, the ChangeCallback is run even if the | 69 // |force_callback_run| is true, the ChangeCallback is run even if the |
70 // RenderWidgetHost has not changed. | 70 // RenderWidgetHost has not changed. |
71 void OnPossibleTargetChange(bool force_callback_run); | 71 void OnPossibleTargetChange(bool force_callback_run); |
72 | 72 |
73 // Called on the thread that Start()/Stop() are called on. Checks whether the | 73 // Called on the thread that Start()/Stop() are called on. Checks whether the |
74 // callback is still valid and, if so, runs it. | 74 // callback is still valid and, if so, runs it. |
75 void MaybeDoCallback(RenderWidgetHost* rwh); | 75 void MaybeDoCallback(RenderWidgetHost* rwh); |
76 | 76 |
77 // Look-up the current WebContents instance associated with the given | 77 // Look-up the current WebContents instance associated with the given |
78 // |render_process_id| and |main_render_frame_id| and begin observing it. | 78 // |render_process_id| and |main_render_frame_id| and begin observing it. |
79 void StartObservingWebContents(int render_process_id, | 79 void StartObservingWebContents(int render_process_id, |
80 int main_render_frame_id); | 80 int main_render_frame_id); |
81 | 81 |
82 // WebContentsObserver overrides: According to web_contents_observer.h, these | 82 // WebContentsObserver overrides: According to web_contents_observer.h, these |
83 // two method overrides are all that is necessary to track the set of active | 83 // two method overrides are all that is necessary to track the set of active |
84 // RenderFrameHosts. | 84 // RenderFrameHosts. |
85 virtual void RenderFrameDeleted(RenderFrameHost* render_frame_host) override; | 85 void RenderFrameDeleted(RenderFrameHost* render_frame_host) override; |
86 virtual void RenderFrameHostChanged(RenderFrameHost* old_host, | 86 void RenderFrameHostChanged(RenderFrameHost* old_host, |
87 RenderFrameHost* new_host) override; | 87 RenderFrameHost* new_host) override; |
88 | 88 |
89 // WebContentsObserver override to notify the client that the capture target | 89 // WebContentsObserver override to notify the client that the capture target |
90 // has been permanently lost. | 90 // has been permanently lost. |
91 virtual void WebContentsDestroyed() override; | 91 void WebContentsDestroyed() override; |
92 | 92 |
93 // WebContentsObserver overrides to notify the client that the capture target | 93 // WebContentsObserver overrides to notify the client that the capture target |
94 // may have changed due to a separate fullscreen widget shown/destroyed. | 94 // may have changed due to a separate fullscreen widget shown/destroyed. |
95 virtual void DidShowFullscreenWidget(int routing_id) override; | 95 void DidShowFullscreenWidget(int routing_id) override; |
96 virtual void DidDestroyFullscreenWidget(int routing_id) override; | 96 void DidDestroyFullscreenWidget(int routing_id) override; |
97 | 97 |
98 // If true, the client is interested in the showing/destruction of fullscreen | 98 // If true, the client is interested in the showing/destruction of fullscreen |
99 // RenderWidgetHosts. | 99 // RenderWidgetHosts. |
100 const bool track_fullscreen_rwh_; | 100 const bool track_fullscreen_rwh_; |
101 | 101 |
102 // MessageLoop corresponding to the thread that called Start(). | 102 // MessageLoop corresponding to the thread that called Start(). |
103 scoped_refptr<base::MessageLoopProxy> message_loop_; | 103 scoped_refptr<base::MessageLoopProxy> message_loop_; |
104 | 104 |
105 // Callback to run when the target RenderWidgetHost has changed. | 105 // Callback to run when the target RenderWidgetHost has changed. |
106 ChangeCallback callback_; | 106 ChangeCallback callback_; |
107 | 107 |
108 // Pointer to the RenderWidgetHost provided in the last run of |callback_|. | 108 // Pointer to the RenderWidgetHost provided in the last run of |callback_|. |
109 // This is used to eliminate duplicate callback runs. | 109 // This is used to eliminate duplicate callback runs. |
110 RenderWidgetHost* last_target_; | 110 RenderWidgetHost* last_target_; |
111 | 111 |
112 DISALLOW_COPY_AND_ASSIGN(WebContentsTracker); | 112 DISALLOW_COPY_AND_ASSIGN(WebContentsTracker); |
113 }; | 113 }; |
114 | 114 |
115 } // namespace content | 115 } // namespace content |
116 | 116 |
117 #endif // CONTENT_BROWSER_MEDIA_CAPTURE_WEB_CONTENTS_TRACKER_H_ | 117 #endif // CONTENT_BROWSER_MEDIA_CAPTURE_WEB_CONTENTS_TRACKER_H_ |
OLD | NEW |