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 render_view_id, the WebContentsTracker | 5 // Given a starting render_process_id and main_render_frame_id, the |
6 // tracks RenderViewHost instance swapping during the lifetime of a WebContents | 6 // WebContentsTracker tracks RenderViewHost instance swapping during the |
7 // instance. This is used when mirroring tab video and audio so that user | 7 // lifetime of a WebContents instance. This is used when mirroring tab video |
8 // navigations, crashes, etc., during a tab's lifetime allow the capturing code | 8 // and audio so that user navigations, crashes, etc., during a tab's lifetime |
9 // to remain active on the current/latest RenderView. | 9 // allow the capturing code to remain active on the current/latest RenderView. |
| 10 // |
| 11 // TODO(miu): In a soon upcoming change, the cross-site isolation migration of |
| 12 // this code will be completed such that the main RenderFrameHost is tracked |
| 13 // instead of the RenderViewHost. |
10 // | 14 // |
11 // Threading issues: Start(), Stop() and the ChangeCallback are invoked on the | 15 // Threading issues: Start(), Stop() and the ChangeCallback are invoked on the |
12 // same thread. This can be any thread, and the decision is locked-in by | 16 // same thread. This can be any thread, and the decision is locked-in by |
13 // WebContentsTracker when Start() is called. | 17 // WebContentsTracker when Start() is called. |
14 | 18 |
15 #ifndef CONTENT_BROWSER_MEDIA_CAPTURE_WEB_CONTENTS_TRACKER_H_ | 19 #ifndef CONTENT_BROWSER_MEDIA_CAPTURE_WEB_CONTENTS_TRACKER_H_ |
16 #define CONTENT_BROWSER_MEDIA_CAPTURE_WEB_CONTENTS_TRACKER_H_ | 20 #define CONTENT_BROWSER_MEDIA_CAPTURE_WEB_CONTENTS_TRACKER_H_ |
17 | 21 |
18 #include "base/callback.h" | 22 #include "base/callback.h" |
19 #include "base/memory/ref_counted.h" | 23 #include "base/memory/ref_counted.h" |
(...skipping 12 matching lines...) Expand all Loading... |
32 public: | 36 public: |
33 WebContentsTracker(); | 37 WebContentsTracker(); |
34 | 38 |
35 // Callback for whenever the target is swapped. The callback is also invoked | 39 // Callback for whenever the target is swapped. The callback is also invoked |
36 // with both arguments set to MSG_ROUTING_NONE to indicate tracking will not | 40 // with both arguments set to MSG_ROUTING_NONE to indicate tracking will not |
37 // continue (i.e., the WebContents instance was not found or has been | 41 // continue (i.e., the WebContents instance was not found or has been |
38 // destroyed). | 42 // destroyed). |
39 typedef base::Callback<void(int render_process_id, int render_view_id)> | 43 typedef base::Callback<void(int render_process_id, int render_view_id)> |
40 ChangeCallback; | 44 ChangeCallback; |
41 | 45 |
42 // Start tracking. The last-known |render_process_id| and |render_view_id| | 46 // Start tracking. The last-known |render_process_id| and |
43 // are provided, and the given callback is invoked asynchronously one or more | 47 // |main_render_frame_id| are provided, and the given callback is invoked |
44 // times. The callback will be invoked on the same thread calling Start(). | 48 // asynchronously one or more times. The callback will be invoked on the same |
45 virtual void Start(int render_process_id, int render_view_id, | 49 // thread calling Start(). |
| 50 virtual void Start(int render_process_id, int main_render_frame_id, |
46 const ChangeCallback& callback); | 51 const ChangeCallback& callback); |
47 | 52 |
48 // Stop tracking. Once this method returns, the callback is guaranteed not to | 53 // Stop tracking. Once this method returns, the callback is guaranteed not to |
49 // be invoked again. | 54 // be invoked again. |
50 virtual void Stop(); | 55 virtual void Stop(); |
51 | 56 |
52 protected: | 57 protected: |
53 friend class base::RefCountedThreadSafe<WebContentsTracker>; | 58 friend class base::RefCountedThreadSafe<WebContentsTracker>; |
54 virtual ~WebContentsTracker(); | 59 virtual ~WebContentsTracker(); |
55 | 60 |
56 private: | 61 private: |
57 // Reads the render_process_id/render_view_id from the current WebContents | 62 // Reads the render_process_id/render_view_id from the current WebContents |
58 // instance and then invokes the callback. | 63 // instance and then invokes the callback. |
59 void OnWebContentsChangeEvent(); | 64 void OnWebContentsChangeEvent(); |
60 | 65 |
61 // Called on the thread that Start()/Stop() are called on, check whether the | 66 // Called on the thread that Start()/Stop() are called on, check whether the |
62 // callback is still valid and, if so, invoke it. | 67 // callback is still valid and, if so, invoke it. |
63 void MaybeDoCallback(int render_process_id, int render_view_id); | 68 void MaybeDoCallback(int render_process_id, int render_view_id); |
64 | 69 |
65 // Look-up the current WebContents instance associated with the given | 70 // Look-up the current WebContents instance associated with the given |
66 // |render_process_id| and |render_view_id| and begin observing it. | 71 // |render_process_id| and |main_render_frame_id| and begin observing it. |
67 void LookUpAndObserveWebContents(int render_process_id, | 72 void LookUpAndObserveWebContents(int render_process_id, |
68 int render_view_id); | 73 int main_render_frame_id); |
69 | 74 |
70 // WebContentsObserver overrides to react to events of interest. | 75 // WebContentsObserver overrides to react to events of interest. |
71 virtual void RenderViewReady() OVERRIDE; | 76 virtual void RenderViewReady() OVERRIDE; |
72 virtual void AboutToNavigateRenderView(RenderViewHost* render_view_host) | 77 virtual void AboutToNavigateRenderView(RenderViewHost* render_view_host) |
73 OVERRIDE; | 78 OVERRIDE; |
74 virtual void DidNavigateMainFrame(const LoadCommittedDetails& details, | 79 virtual void DidNavigateMainFrame(const LoadCommittedDetails& details, |
75 const FrameNavigateParams& params) OVERRIDE; | 80 const FrameNavigateParams& params) OVERRIDE; |
76 virtual void WebContentsDestroyed() OVERRIDE; | 81 virtual void WebContentsDestroyed() OVERRIDE; |
77 | 82 |
78 scoped_refptr<base::MessageLoopProxy> message_loop_; | 83 scoped_refptr<base::MessageLoopProxy> message_loop_; |
79 ChangeCallback callback_; | 84 ChangeCallback callback_; |
80 | 85 |
81 DISALLOW_COPY_AND_ASSIGN(WebContentsTracker); | 86 DISALLOW_COPY_AND_ASSIGN(WebContentsTracker); |
82 }; | 87 }; |
83 | 88 |
84 } // namespace content | 89 } // namespace content |
85 | 90 |
86 #endif // CONTENT_BROWSER_MEDIA_CAPTURE_WEB_CONTENTS_TRACKER_H_ | 91 #endif // CONTENT_BROWSER_MEDIA_CAPTURE_WEB_CONTENTS_TRACKER_H_ |
OLD | NEW |