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

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

Issue 11451006: Make TabCapture requests use the target render process and render view id's for UI permissions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review comments Created 8 years 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 <map> 8 #include <map>
9 #include <string>
10 #include <utility>
11 #include <vector>
9 12
10 #include "chrome/browser/media/media_internals.h" 13 #include "chrome/browser/media/media_internals.h"
11 #include "chrome/browser/media/media_internals_observer.h" 14 #include "chrome/browser/media/media_internals_observer.h"
12 #include "chrome/browser/profiles/profile_keyed_service.h" 15 #include "chrome/browser/profiles/profile_keyed_service.h"
13 #include "chrome/common/extensions/api/tab_capture.h" 16 #include "chrome/common/extensions/api/tab_capture.h"
14 #include "content/public/browser/browser_thread.h" 17 #include "content/public/browser/browser_thread.h"
15 #include "content/public/browser/media_request_state.h" 18 #include "content/public/browser/media_request_state.h"
16 #include "content/public/browser/notification_observer.h" 19 #include "content/public/browser/notification_observer.h"
17 #include "content/public/browser/notification_registrar.h" 20 #include "content/public/browser/notification_registrar.h"
18 #include "content/public/common/media_stream_request.h" 21 #include "content/public/common/media_stream_request.h"
19 22
20 class Profile; 23 class Profile;
21 24
22 namespace extensions { 25 namespace extensions {
23 26
24 namespace tab_capture = extensions::api::tab_capture; 27 namespace tab_capture = extensions::api::tab_capture;
25 28
26 class TabCaptureRegistry : public ProfileKeyedService, 29 class TabCaptureRegistry : public ProfileKeyedService,
27 public content::NotificationObserver { 30 public content::NotificationObserver {
28 public: 31 public:
29 struct TabCaptureRequest { 32 struct TabCaptureRequest {
30 std::string extension_id; 33 std::string extension_id;
31 int tab_id; 34 int tab_id;
32 tab_capture::TabCaptureState status; 35 tab_capture::TabCaptureState status;
33 36
34 TabCaptureRequest() {} 37 TabCaptureRequest() : tab_id(-1) {}
35 TabCaptureRequest(std::string extension_id, int tab_id, 38 TabCaptureRequest(std::string extension_id, int tab_id,
36 tab_capture::TabCaptureState status) 39 tab_capture::TabCaptureState status)
37 : extension_id(extension_id), tab_id(tab_id), status(status) {} 40 : extension_id(extension_id), tab_id(tab_id), status(status) {}
38 }; 41 };
39 typedef std::vector<TabCaptureRequest> CaptureRequestList; 42 typedef std::vector<TabCaptureRequest> CaptureRequestList;
40 43
41 explicit TabCaptureRegistry(Profile* profile); 44 explicit TabCaptureRegistry(Profile* profile);
42 45
43 const CaptureRequestList GetCapturedTabs(const std::string& extension_id); 46 const CaptureRequestList GetCapturedTabs(const std::string& extension_id);
44 bool AddRequest(const std::string& key, const TabCaptureRequest& request); 47 bool AddRequest(const std::pair<int, int>, const TabCaptureRequest& request);
45 bool VerifyRequest(const std::string& key); 48 bool VerifyRequest(int render_process_id, int render_view_id);
46 49
47 private: 50 private:
48 // Maps device_id to information about the media stream request. This is 51 // Maps device_id to information about the media stream request. This is
49 // expected to be small since maintaining a media stream is expensive. 52 // expected to be small since maintaining a media stream is expensive.
50 typedef std::map<std::string, TabCaptureRequest> DeviceCaptureRequestMap; 53 typedef std::map<const std::pair<int, int>, TabCaptureRequest>
54 DeviceCaptureRequestMap;
51 55
52 class MediaObserverProxy : public MediaInternalsObserver, 56 class MediaObserverProxy : public MediaInternalsObserver,
53 public base::RefCountedThreadSafe< 57 public base::RefCountedThreadSafe<
54 MediaObserverProxy> { 58 MediaObserverProxy> {
55 public: 59 public:
56 MediaObserverProxy() : handler_(NULL) {} 60 MediaObserverProxy() : handler_(NULL) {}
57 void Attach(TabCaptureRegistry* handler); 61 void Attach(TabCaptureRegistry* handler);
58 void Detach(); 62 void Detach();
59 63
60 private: 64 private:
61 friend class base::RefCountedThreadSafe<MediaObserverProxy>; 65 friend class base::RefCountedThreadSafe<MediaObserverProxy>;
62 virtual ~MediaObserverProxy() {} 66 virtual ~MediaObserverProxy() {}
63 67
64 // MediaInternalsObserver. 68 // MediaInternalsObserver.
65 virtual void OnRequestUpdate( 69 virtual void OnRequestUpdate(
70 int render_process_id,
71 int render_view_id,
66 const content::MediaStreamDevice& device, 72 const content::MediaStreamDevice& device,
67 const content::MediaRequestState state) OVERRIDE; 73 const content::MediaRequestState state) OVERRIDE;
68 74
69 void RegisterAsMediaObserverOnIOThread(bool unregister); 75 void RegisterAsMediaObserverOnIOThread(bool unregister);
70 void UpdateOnUIThread( 76 void UpdateOnUIThread(
77 int render_process_id,
78 int render_view_id,
71 const content::MediaStreamDevice& device, 79 const content::MediaStreamDevice& device,
72 const content::MediaRequestState new_state); 80 const content::MediaRequestState new_state);
73 81
74 TabCaptureRegistry* handler_; 82 TabCaptureRegistry* handler_;
75 }; 83 };
76 84
77 virtual ~TabCaptureRegistry(); 85 virtual ~TabCaptureRegistry();
78 86
79 void HandleRequestUpdateOnUIThread( 87 void HandleRequestUpdateOnUIThread(
88 int render_process_id,
89 int render_view_id,
80 const content::MediaStreamDevice& device, 90 const content::MediaStreamDevice& device,
81 const content::MediaRequestState state); 91 const content::MediaRequestState state);
82 92
83 // content::NotificationObserver implementation. 93 // content::NotificationObserver implementation.
84 virtual void Observe(int type, 94 virtual void Observe(int type,
85 const content::NotificationSource& source, 95 const content::NotificationSource& source,
86 const content::NotificationDetails& details) OVERRIDE; 96 const content::NotificationDetails& details) OVERRIDE;
87 97
88 scoped_refptr<MediaObserverProxy> proxy_; 98 scoped_refptr<MediaObserverProxy> proxy_;
89 content::NotificationRegistrar registrar_; 99 content::NotificationRegistrar registrar_;
90 Profile* const profile_; 100 Profile* const profile_;
91 DeviceCaptureRequestMap requests_; 101 DeviceCaptureRequestMap requests_;
92 102
93 DISALLOW_COPY_AND_ASSIGN(TabCaptureRegistry); 103 DISALLOW_COPY_AND_ASSIGN(TabCaptureRegistry);
94 }; 104 };
95 105
96 } // namespace extension 106 } // namespace extension
97 107
98 #endif // CHROME_BROWSER_EXTENSIONS_API_TAB_CAPTURE_TAB_CAPTURE_REGISTRY_H_ 108 #endif // CHROME_BROWSER_EXTENSIONS_API_TAB_CAPTURE_TAB_CAPTURE_REGISTRY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698