OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_WEB_CONTENTS_CAPTURE_UTIL_H_ |
| 6 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_WEB_CONTENTS_CAPTURE_UTIL_H_ |
| 7 |
| 8 #include <string> |
| 9 |
| 10 #include "base/callback.h" |
| 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/synchronization/lock.h" |
| 13 #include "content/public/browser/web_contents_observer.h" |
| 14 |
| 15 namespace content { |
| 16 |
| 17 class WebContents; |
| 18 |
| 19 class WebContentsCaptureUtil { |
| 20 public: |
| 21 // Tracks RenderView changes during the lifetime of a WebContents. |
| 22 class RenderViewTracker |
| 23 : public base::RefCountedThreadSafe<RenderViewTracker>, |
| 24 public WebContentsObserver { |
| 25 public: |
| 26 RenderViewTracker(); |
| 27 |
| 28 // Callback for whenever a new RenderView is swapped in. The callback is |
| 29 // also invoked with both arguments set to MSG_ROUTING_NONE to indicate |
| 30 // tracking will not continue (i.e., the WebContents instance was not found |
| 31 // or has been destroyed). |
| 32 typedef base::Callback<void(int render_process_id, int render_view_id)> |
| 33 ChangeCallback; |
| 34 |
| 35 // Start tracking. The last-known |render_process_id| and |render_view_id| |
| 36 // are provided, and the given callback is invoked asynchronously one or |
| 37 // more times. |
| 38 void Start(int render_process_id, int render_view_id, |
| 39 const ChangeCallback& callback); |
| 40 |
| 41 // Stop tracking. Once this method returns, the callback is guaranteed not |
| 42 // to be invoked again. |
| 43 void Stop(); |
| 44 |
| 45 private: |
| 46 friend class base::RefCountedThreadSafe<RenderViewTracker>; |
| 47 |
| 48 virtual ~RenderViewTracker(); |
| 49 |
| 50 // Reads the render_process_id/render_view_id from the current WebContents |
| 51 // instance and then invokes the callback. |
| 52 void OnWebContentsChangeEvent(); |
| 53 |
| 54 // Look-up the current WebContents instance associated with the given |
| 55 // |render_process_id| and |render_view_id| and begin observing it. |
| 56 void LookUpAndObserveWebContents(int render_process_id, |
| 57 int render_view_id); |
| 58 |
| 59 // How WebContents notifies us of a new RenderView target. |
| 60 virtual void RenderViewReady() OVERRIDE; |
| 61 |
| 62 // Called when a WebContents has been destroyed. This invokes the callback |
| 63 // with MSG_ROUTING_NONE values to indicate tracking will not continue. |
| 64 virtual void WebContentsDestroyed(WebContents* web_contents) OVERRIDE; |
| 65 |
| 66 base::Lock lock_; // Guards changes to callback_. |
| 67 ChangeCallback callback_; |
| 68 }; |
| 69 |
| 70 // Function to extract the target renderer id's from a tab media stream |
| 71 // request's device id. |
| 72 static bool ExtractTabCaptureTarget(const std::string& device_id, |
| 73 int* render_process_id, |
| 74 int* render_view_id); |
| 75 }; |
| 76 |
| 77 } // namespace content |
| 78 |
| 79 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_WEB_CONTENTS_CAPTURE_UTIL_H_ |
OLD | NEW |