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

Side by Side Diff: chrome/browser/extensions/api/tab_capture/tab_capture_registry.h

Issue 364123002: [Cross-Site Isolation] Migrate entire MediaStream verticals to be per-RenderFrame. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: It's random enough. + REBASE Created 6 years, 5 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 | Annotate | Revision Log
OLDNEW
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 CHROME_BROWSER_EXTENSIONS_API_TAB_CAPTURE_TAB_CAPTURE_REGISTRY_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_TAB_CAPTURE_TAB_CAPTURE_REGISTRY_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_TAB_CAPTURE_TAB_CAPTURE_REGISTRY_H_ 6 #define CHROME_BROWSER_EXTENSIONS_API_TAB_CAPTURE_TAB_CAPTURE_REGISTRY_H_
7 7
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/memory/scoped_vector.h" 12 #include "base/memory/scoped_vector.h"
13 #include "base/scoped_observer.h" 13 #include "base/scoped_observer.h"
14 #include "chrome/browser/media/media_capture_devices_dispatcher.h" 14 #include "chrome/browser/media/media_capture_devices_dispatcher.h"
15 #include "chrome/common/extensions/api/tab_capture.h" 15 #include "chrome/common/extensions/api/tab_capture.h"
16 #include "content/public/browser/media_request_state.h" 16 #include "content/public/browser/media_request_state.h"
17 #include "content/public/browser/notification_observer.h"
18 #include "content/public/browser/notification_registrar.h"
19 #include "extensions/browser/browser_context_keyed_api_factory.h" 17 #include "extensions/browser/browser_context_keyed_api_factory.h"
20 #include "extensions/browser/extension_registry_observer.h" 18 #include "extensions/browser/extension_registry_observer.h"
21 19
20 namespace base {
21 class ListValue;
22 }
23
22 namespace content { 24 namespace content {
23 class BrowserContext; 25 class BrowserContext;
26 class WebContents;
24 } 27 }
25 28
26 namespace extensions { 29 namespace extensions {
27 30
28 struct TabCaptureRequest;
29 class ExtensionRegistry; 31 class ExtensionRegistry;
30 class FullscreenObserver;
31 32
32 namespace tab_capture = api::tab_capture; 33 namespace tab_capture = api::tab_capture;
33 34
34 class TabCaptureRegistry : public BrowserContextKeyedAPI, 35 class TabCaptureRegistry : public BrowserContextKeyedAPI,
35 public content::NotificationObserver,
36 public ExtensionRegistryObserver, 36 public ExtensionRegistryObserver,
37 public MediaCaptureDevicesDispatcher::Observer { 37 public MediaCaptureDevicesDispatcher::Observer {
38 public: 38 public:
39 typedef std::vector<std::pair<int, tab_capture::TabCaptureState> >
40 RegistryCaptureInfo;
41
42 static TabCaptureRegistry* Get(content::BrowserContext* context); 39 static TabCaptureRegistry* Get(content::BrowserContext* context);
43 40
44 // Used by BrowserContextKeyedAPI. 41 // Used by BrowserContextKeyedAPI.
45 static BrowserContextKeyedAPIFactory<TabCaptureRegistry>* 42 static BrowserContextKeyedAPIFactory<TabCaptureRegistry>*
46 GetFactoryInstance(); 43 GetFactoryInstance();
47 44
48 // List all pending, active and stopped capture requests. 45 // List all pending, active and stopped capture requests.
49 const RegistryCaptureInfo GetCapturedTabs( 46 void GetCapturedTabs(const std::string& extension_id,
50 const std::string& extension_id) const; 47 base::ListValue* list_of_capture_info) const;
51 48
52 // Add a tab capture request to the registry when a stream is requested 49 // Add a tab capture request to the registry when a stream is requested
53 // through the API. 50 // through the API. |target_contents| refers to the WebContents associated
54 bool AddRequest(int render_process_id, 51 // with the tab to be captured. |extension_id| refers to the Extension
55 int render_view_id, 52 // initiating the request.
56 const std::string& extension_id, 53 bool AddRequest(content::WebContents* target_contents,
57 int tab_id, 54 const std::string& extension_id);
58 tab_capture::TabCaptureState status);
59 55
60 // The MediaStreamDevicesController will verify the request before creating 56 // Called by MediaStreamDevicesController to verify the request before
61 // the stream by checking the registry here. 57 // creating the stream. |render_process_id| and |render_frame_id| are used to
62 bool VerifyRequest(int render_process_id, int render_view_id); 58 // look-up a WebContents instance, which should match the |target_contents|
59 // from the prior call to AddRequest(). In addition, a request is not
60 // verified unless the |extension_id| also matches AND the request itself is
61 // in the PENDING state.
62 bool VerifyRequest(int render_process_id,
63 int render_frame_id,
64 const std::string& extension_id);
63 65
64 private: 66 private:
65 friend class BrowserContextKeyedAPIFactory<TabCaptureRegistry>; 67 friend class BrowserContextKeyedAPIFactory<TabCaptureRegistry>;
66 friend class FullscreenObserver; 68 class LiveRequest;
67 69
68 explicit TabCaptureRegistry(content::BrowserContext* context); 70 explicit TabCaptureRegistry(content::BrowserContext* context);
69 virtual ~TabCaptureRegistry(); 71 virtual ~TabCaptureRegistry();
70 72
71 // Used by BrowserContextKeyedAPI. 73 // Used by BrowserContextKeyedAPI.
72 static const char* service_name() { 74 static const char* service_name() {
73 return "TabCaptureRegistry"; 75 return "TabCaptureRegistry";
74 } 76 }
75 77
76 static const bool kServiceIsCreatedWithBrowserContext = false; 78 static const bool kServiceIsCreatedWithBrowserContext = false;
77 static const bool kServiceRedirectedInIncognito = true; 79 static const bool kServiceRedirectedInIncognito = true;
78 80
79 // content::NotificationObserver implementation.
80 virtual void Observe(int type,
81 const content::NotificationSource& source,
82 const content::NotificationDetails& details) OVERRIDE;
83
84 // ExtensionRegistryObserver implementation. 81 // ExtensionRegistryObserver implementation.
85 virtual void OnExtensionUnloaded( 82 virtual void OnExtensionUnloaded(
86 content::BrowserContext* browser_context, 83 content::BrowserContext* browser_context,
87 const Extension* extension, 84 const Extension* extension,
88 UnloadedExtensionInfo::Reason reason) OVERRIDE; 85 UnloadedExtensionInfo::Reason reason) OVERRIDE;
89 86
90 // MediaCaptureDevicesDispatcher::Observer implementation. 87 // MediaCaptureDevicesDispatcher::Observer implementation.
91 virtual void OnRequestUpdate( 88 virtual void OnRequestUpdate(
92 int render_process_id, 89 int original_target_render_process_id,
93 int render_view_id, 90 int original_target_render_frame_id,
94 const content::MediaStreamDevice& device, 91 content::MediaStreamType stream_type,
95 const content::MediaRequestState state) OVERRIDE; 92 const content::MediaRequestState state) OVERRIDE;
96 93
97 void DispatchStatusChangeEvent(const TabCaptureRequest* request) const; 94 // Send a StatusChanged event containing the current state of |request|.
95 void DispatchStatusChangeEvent(const LiveRequest* request) const;
98 96
99 TabCaptureRequest* FindCaptureRequest(int render_process_id, 97 // Look-up a LiveRequest associated with the given |target_contents| (or
100 int render_view_id) const; 98 // the originally targetted RenderFrameHost), if any.
99 LiveRequest* FindRequest(const content::WebContents* target_contents) const;
100 LiveRequest* FindRequest(int original_target_render_process_id,
101 int original_target_render_frame_id) const;
101 102
102 void DeleteCaptureRequest(int render_process_id, int render_view_id); 103 // Removes the |request| from |requests_|, thus causing its destruction.
104 void KillRequest(LiveRequest* request);
103 105
104 content::NotificationRegistrar registrar_;
105 content::BrowserContext* const browser_context_; 106 content::BrowserContext* const browser_context_;
106 ScopedVector<TabCaptureRequest> requests_; 107 ScopedVector<LiveRequest> requests_;
107 108
108 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> 109 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver>
109 extension_registry_observer_; 110 extension_registry_observer_;
110 111
111 DISALLOW_COPY_AND_ASSIGN(TabCaptureRegistry); 112 DISALLOW_COPY_AND_ASSIGN(TabCaptureRegistry);
112 }; 113 };
113 114
114 } // namespace extensions 115 } // namespace extensions
115 116
116 #endif // CHROME_BROWSER_EXTENSIONS_API_TAB_CAPTURE_TAB_CAPTURE_REGISTRY_H_ 117 #endif // CHROME_BROWSER_EXTENSIONS_API_TAB_CAPTURE_TAB_CAPTURE_REGISTRY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698