Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / browser / extensions / api / tab_capture / tab_capture_registry.h
blob60d5f2b6b9f4ac72ca5ddfd22fb002405d92bc9d
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.
5 #ifndef CHROME_BROWSER_EXTENSIONS_API_TAB_CAPTURE_TAB_CAPTURE_REGISTRY_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_TAB_CAPTURE_TAB_CAPTURE_REGISTRY_H_
8 #include <string>
9 #include <utility>
10 #include <vector>
12 #include "base/memory/scoped_vector.h"
13 #include "base/scoped_observer.h"
14 #include "chrome/browser/media/media_capture_devices_dispatcher.h"
15 #include "chrome/common/extensions/api/tab_capture.h"
16 #include "content/public/browser/media_request_state.h"
17 #include "extensions/browser/browser_context_keyed_api_factory.h"
18 #include "extensions/browser/extension_registry_observer.h"
20 namespace base {
21 class ListValue;
24 namespace content {
25 class BrowserContext;
26 class WebContents;
29 namespace extensions {
31 class ExtensionRegistry;
33 namespace tab_capture = api::tab_capture;
35 class TabCaptureRegistry : public BrowserContextKeyedAPI,
36 public ExtensionRegistryObserver,
37 public MediaCaptureDevicesDispatcher::Observer {
38 public:
39 static TabCaptureRegistry* Get(content::BrowserContext* context);
41 // Used by BrowserContextKeyedAPI.
42 static BrowserContextKeyedAPIFactory<TabCaptureRegistry>*
43 GetFactoryInstance();
45 // List all pending, active and stopped capture requests.
46 void GetCapturedTabs(const std::string& extension_id,
47 base::ListValue* list_of_capture_info) const;
49 // Add a tab capture request to the registry when a stream is requested
50 // through the API. |target_contents| refers to the WebContents associated
51 // with the tab to be captured. |extension_id| refers to the Extension
52 // initiating the request.
53 bool AddRequest(content::WebContents* target_contents,
54 const std::string& extension_id);
56 // Called by MediaStreamDevicesController to verify the request before
57 // creating the stream. |render_process_id| and |render_frame_id| are used to
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);
66 private:
67 friend class BrowserContextKeyedAPIFactory<TabCaptureRegistry>;
68 class LiveRequest;
70 explicit TabCaptureRegistry(content::BrowserContext* context);
71 ~TabCaptureRegistry() override;
73 // Used by BrowserContextKeyedAPI.
74 static const char* service_name() {
75 return "TabCaptureRegistry";
78 static const bool kServiceIsCreatedWithBrowserContext = false;
79 static const bool kServiceRedirectedInIncognito = true;
81 // ExtensionRegistryObserver implementation.
82 void OnExtensionUnloaded(content::BrowserContext* browser_context,
83 const Extension* extension,
84 UnloadedExtensionInfo::Reason reason) override;
86 // MediaCaptureDevicesDispatcher::Observer implementation.
87 void OnRequestUpdate(int original_target_render_process_id,
88 int original_target_render_frame_id,
89 content::MediaStreamType stream_type,
90 const content::MediaRequestState state) override;
92 // Send a StatusChanged event containing the current state of |request|.
93 void DispatchStatusChangeEvent(const LiveRequest* request) const;
95 // Look-up a LiveRequest associated with the given |target_contents| (or
96 // the originally targetted RenderFrameHost), if any.
97 LiveRequest* FindRequest(const content::WebContents* target_contents) const;
98 LiveRequest* FindRequest(int original_target_render_process_id,
99 int original_target_render_frame_id) const;
101 // Removes the |request| from |requests_|, thus causing its destruction.
102 void KillRequest(LiveRequest* request);
104 content::BrowserContext* const browser_context_;
105 ScopedVector<LiveRequest> requests_;
107 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver>
108 extension_registry_observer_;
110 DISALLOW_COPY_AND_ASSIGN(TabCaptureRegistry);
113 } // namespace extensions
115 #endif // CHROME_BROWSER_EXTENSIONS_API_TAB_CAPTURE_TAB_CAPTURE_REGISTRY_H_