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 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 |
22 namespace content { | 20 namespace content { |
23 class BrowserContext; | 21 class BrowserContext; |
22 class WebContents; | |
24 } | 23 } |
25 | 24 |
26 namespace extensions { | 25 namespace extensions { |
27 | 26 |
28 struct TabCaptureRequest; | 27 struct TabCaptureRequest; |
29 class ExtensionRegistry; | 28 class ExtensionRegistry; |
30 class FullscreenObserver; | 29 class FullscreenObserver; |
31 | 30 |
32 namespace tab_capture = api::tab_capture; | 31 namespace tab_capture = api::tab_capture; |
33 | 32 |
34 class TabCaptureRegistry : public BrowserContextKeyedAPI, | 33 class TabCaptureRegistry : public BrowserContextKeyedAPI, |
35 public content::NotificationObserver, | |
ncarter (slow)
2014/07/10 01:17:51
You are a saint.
miu
2014/07/10 22:16:11
:)
| |
36 public ExtensionRegistryObserver, | 34 public ExtensionRegistryObserver, |
37 public MediaCaptureDevicesDispatcher::Observer { | 35 public MediaCaptureDevicesDispatcher::Observer { |
38 public: | 36 public: |
39 typedef std::vector<std::pair<int, tab_capture::TabCaptureState> > | 37 typedef std::vector<std::pair<int, tab_capture::TabCaptureState> > |
40 RegistryCaptureInfo; | 38 RegistryCaptureInfo; |
41 | 39 |
42 static TabCaptureRegistry* Get(content::BrowserContext* context); | 40 static TabCaptureRegistry* Get(content::BrowserContext* context); |
43 | 41 |
44 // Used by BrowserContextKeyedAPI. | 42 // Used by BrowserContextKeyedAPI. |
45 static BrowserContextKeyedAPIFactory<TabCaptureRegistry>* | 43 static BrowserContextKeyedAPIFactory<TabCaptureRegistry>* |
46 GetFactoryInstance(); | 44 GetFactoryInstance(); |
47 | 45 |
48 // List all pending, active and stopped capture requests. | 46 // List all pending, active and stopped capture requests. |
49 const RegistryCaptureInfo GetCapturedTabs( | 47 const RegistryCaptureInfo GetCapturedTabs( |
50 const std::string& extension_id) const; | 48 const std::string& extension_id) const; |
51 | 49 |
52 // Add a tab capture request to the registry when a stream is requested | 50 // Add a tab capture request to the registry when a stream is requested |
53 // through the API. | 51 // through the API. |
54 bool AddRequest(int render_process_id, | 52 bool AddRequest(content::WebContents* target_contents, |
ncarter (slow)
2014/07/10 01:17:51
Could you document the parameters here? In particu
miu
2014/07/10 22:16:11
Done.
| |
55 int render_view_id, | |
56 const std::string& extension_id, | 53 const std::string& extension_id, |
57 int tab_id, | 54 int tab_id, |
ncarter (slow)
2014/07/10 01:17:51
If we have the |target_contents|, do we need the t
miu
2014/07/10 22:16:11
Excellent point. In fact, I was able to remove bo
| |
58 tab_capture::TabCaptureState status); | 55 tab_capture::TabCaptureState status); |
59 | 56 |
60 // The MediaStreamDevicesController will verify the request before creating | 57 // The MediaStreamDevicesController will verify the request before creating |
61 // the stream by checking the registry here. | 58 // the stream by checking the registry here. |
ncarter (slow)
2014/07/10 01:17:51
What about the request, exactly, is verified? It m
miu
2014/07/10 22:16:11
Done.
| |
62 bool VerifyRequest(int render_process_id, int render_view_id); | 59 bool VerifyRequest(const content::WebContents* target_contents, |
60 const std::string& extension_id); | |
63 | 61 |
64 private: | 62 private: |
65 friend class BrowserContextKeyedAPIFactory<TabCaptureRegistry>; | 63 friend class BrowserContextKeyedAPIFactory<TabCaptureRegistry>; |
66 friend class FullscreenObserver; | 64 friend class FullscreenObserver; |
67 | 65 |
68 explicit TabCaptureRegistry(content::BrowserContext* context); | 66 explicit TabCaptureRegistry(content::BrowserContext* context); |
69 virtual ~TabCaptureRegistry(); | 67 virtual ~TabCaptureRegistry(); |
70 | 68 |
71 // Used by BrowserContextKeyedAPI. | 69 // Used by BrowserContextKeyedAPI. |
72 static const char* service_name() { | 70 static const char* service_name() { |
73 return "TabCaptureRegistry"; | 71 return "TabCaptureRegistry"; |
74 } | 72 } |
75 | 73 |
76 static const bool kServiceIsCreatedWithBrowserContext = false; | 74 static const bool kServiceIsCreatedWithBrowserContext = false; |
77 static const bool kServiceRedirectedInIncognito = true; | 75 static const bool kServiceRedirectedInIncognito = true; |
78 | 76 |
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. | 77 // ExtensionRegistryObserver implementation. |
85 virtual void OnExtensionUnloaded( | 78 virtual void OnExtensionUnloaded( |
86 content::BrowserContext* browser_context, | 79 content::BrowserContext* browser_context, |
87 const Extension* extension, | 80 const Extension* extension, |
88 UnloadedExtensionInfo::Reason reason) OVERRIDE; | 81 UnloadedExtensionInfo::Reason reason) OVERRIDE; |
89 | 82 |
90 // MediaCaptureDevicesDispatcher::Observer implementation. | 83 // MediaCaptureDevicesDispatcher::Observer implementation. |
91 virtual void OnRequestUpdate( | 84 virtual void OnRequestUpdate( |
92 int render_process_id, | 85 int render_process_id, |
93 int render_view_id, | 86 int render_frame_id, |
94 const content::MediaStreamDevice& device, | 87 content::MediaStreamType stream_type, |
95 const content::MediaRequestState state) OVERRIDE; | 88 const content::MediaRequestState state) OVERRIDE; |
96 | 89 |
97 void DispatchStatusChangeEvent(const TabCaptureRequest* request) const; | 90 void DispatchStatusChangeEvent(const TabCaptureRequest* request) const; |
98 | 91 |
99 TabCaptureRequest* FindCaptureRequest(int render_process_id, | 92 TabCaptureRequest* FindCaptureRequest( |
100 int render_view_id) const; | 93 const content::WebContents* target_contents) const; |
101 | 94 |
102 void DeleteCaptureRequest(int render_process_id, int render_view_id); | |
103 | |
104 content::NotificationRegistrar registrar_; | |
105 content::BrowserContext* const browser_context_; | 95 content::BrowserContext* const browser_context_; |
106 ScopedVector<TabCaptureRequest> requests_; | 96 ScopedVector<TabCaptureRequest> requests_; |
107 | 97 |
108 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> | 98 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> |
109 extension_registry_observer_; | 99 extension_registry_observer_; |
110 | 100 |
111 DISALLOW_COPY_AND_ASSIGN(TabCaptureRegistry); | 101 DISALLOW_COPY_AND_ASSIGN(TabCaptureRegistry); |
112 }; | 102 }; |
113 | 103 |
114 } // namespace extensions | 104 } // namespace extensions |
115 | 105 |
116 #endif // CHROME_BROWSER_EXTENSIONS_API_TAB_CAPTURE_TAB_CAPTURE_REGISTRY_H_ | 106 #endif // CHROME_BROWSER_EXTENSIONS_API_TAB_CAPTURE_TAB_CAPTURE_REGISTRY_H_ |
OLD | NEW |