OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_WEB_CONTENTS_CAPTURE_UTIL_H_ | 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_WEB_CONTENTS_CAPTURE_UTIL_H_ |
6 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_WEB_CONTENTS_CAPTURE_UTIL_H_ | 6 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_WEB_CONTENTS_CAPTURE_UTIL_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/callback.h" | |
11 #include "base/memory/ref_counted.h" | |
12 #include "content/common/content_export.h" | |
13 #include "content/public/browser/web_contents_observer.h" | |
14 | |
15 namespace base { | |
16 class MessageLoopProxy; | |
17 } | |
18 | |
10 namespace content { | 19 namespace content { |
11 | 20 |
12 class WebContentsCaptureUtil { | 21 class WebContentsCaptureUtil { |
13 public: | 22 public: |
14 // Returns a new id after appending the device id scheme for virtual streams. | 23 // Returns a new id after appending the device id scheme for virtual streams. |
15 static std::string AppendWebContentsDeviceScheme( | 24 static std::string AppendWebContentsDeviceScheme( |
16 const std::string& device_id_param); | 25 const std::string& device_id_param); |
17 | 26 |
18 static std::string StripWebContentsDeviceScheme( | 27 static std::string StripWebContentsDeviceScheme( |
19 const std::string& device_id_param); | 28 const std::string& device_id_param); |
20 | 29 |
21 // Check whether the device id indicates that this is a web contents stream. | 30 // Check whether the device id indicates that this is a web contents stream. |
22 static bool IsWebContentsDeviceId(const std::string& device_id); | 31 static bool IsWebContentsDeviceId(const std::string& device_id); |
23 | 32 |
24 // Function to extract the target renderer id's from a tab media stream | 33 // Function to extract the target renderer id's from a tab media stream |
25 // request's device id. | 34 // request's device id. |
26 static bool ExtractTabCaptureTarget(const std::string& device_id, | 35 static bool ExtractTabCaptureTarget(const std::string& device_id, |
27 int* render_process_id, | 36 int* render_process_id, |
28 int* render_view_id); | 37 int* render_view_id); |
29 }; | 38 }; |
30 | 39 |
40 // Given a starting render_process_id and render_view_id, tracks RenderView | |
41 // instance swapping during the lifetime of a WebContents instance. | |
42 // | |
43 // Threading issues: Start(), Stop() and the ChangeCallback are invoked on the | |
44 // same thread. This can be any thread, and the decision is locked-in by | |
45 // WebContentsTracker when Start() is called. | |
46 class CONTENT_EXPORT WebContentsTracker | |
DaleCurtis
2013/01/15 22:02:18
Why put this here vs separate file vs private clas
miu
2013/01/16 03:22:18
This class is a utility meant to be used by only W
DaleCurtis
2013/01/17 01:15:52
Hmm, it depends on the usage pattern. In general,
miu
2013/01/17 05:33:55
Agreed. This stuff with the device_id parsing is
| |
47 : public base::RefCountedThreadSafe<WebContentsTracker>, | |
48 public WebContentsObserver { | |
49 public: | |
50 WebContentsTracker(); | |
51 | |
52 // Callback for whenever the target is swapped. The callback is also invoked | |
53 // with both arguments set to MSG_ROUTING_NONE to indicate tracking will not | |
54 // continue (i.e., the WebContents instance was not found or has been | |
55 // destroyed). | |
56 typedef base::Callback<void(int render_process_id, int render_view_id)> | |
57 ChangeCallback; | |
58 | |
59 // Start tracking. The last-known |render_process_id| and |render_view_id| | |
60 // are provided, and the given callback is invoked asynchronously one or more | |
61 // times. The callback will be invoked on the same thread calling Start(). | |
62 virtual void Start(int render_process_id, int render_view_id, | |
63 const ChangeCallback& callback); | |
64 | |
65 // Stop tracking. Once this method returns, the callback is guaranteed not to | |
66 // be invoked again. | |
67 virtual void Stop(); | |
68 | |
69 protected: | |
70 friend class base::RefCountedThreadSafe<WebContentsTracker>; | |
71 virtual ~WebContentsTracker(); | |
72 | |
73 private: | |
74 // Reads the render_process_id/render_view_id from the current WebContents | |
75 // instance and then invokes the callback. | |
76 void OnWebContentsChangeEvent(); | |
77 | |
78 // Called on the thread that Start()/Stop() are called on, check whether the | |
79 // callback is still valid and, if so, invoke it. | |
80 void MaybeDoCallback(int render_process_id, int render_view_id); | |
81 | |
82 // Look-up the current WebContents instance associated with the given | |
83 // |render_process_id| and |render_view_id| and begin observing it. | |
84 void LookUpAndObserveWebContents(int render_process_id, | |
85 int render_view_id); | |
86 | |
87 // WebContentsObserver overrides to react to events of interest. | |
88 virtual void RenderViewReady() OVERRIDE; | |
89 virtual void AboutToNavigateRenderView(RenderViewHost* render_view_host) | |
90 OVERRIDE; | |
91 virtual void DidNavigateMainFrame(const LoadCommittedDetails& details, | |
92 const FrameNavigateParams& params) OVERRIDE; | |
93 virtual void WebContentsDestroyed(WebContents* web_contents) OVERRIDE; | |
94 | |
95 scoped_refptr<base::MessageLoopProxy> message_loop_; | |
96 ChangeCallback callback_; | |
97 | |
98 DISALLOW_COPY_AND_ASSIGN(WebContentsTracker); | |
99 }; | |
100 | |
31 } // namespace content | 101 } // namespace content |
32 | 102 |
33 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_WEB_CONTENTS_CAPTURE_UTIL_H_ | 103 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_WEB_CONTENTS_CAPTURE_UTIL_H_ |
OLD | NEW |