OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 CONTENT_PUBLIC_BROWSER_DESKTOP_MEDIA_ID_H_ | 5 #ifndef CONTENT_PUBLIC_BROWSER_DESKTOP_MEDIA_ID_H_ |
6 #define CONTENT_PUBLIC_BROWSER_DESKTOP_MEDIA_ID_H_ | 6 #define CONTENT_PUBLIC_BROWSER_DESKTOP_MEDIA_ID_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <tuple> | 9 #include <tuple> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "content/common/content_export.h" | 12 #include "content/common/content_export.h" |
13 #include "content/public/browser/web_contents_media_capture_id.h" | |
13 | 14 |
14 #if defined(USE_AURA) | 15 #if defined(USE_AURA) |
15 namespace aura { | 16 namespace aura { |
16 class Window; | 17 class Window; |
17 } // namespace aura | 18 } // namespace aura |
18 #endif // defined(USE_AURA) | 19 #endif // defined(USE_AURA) |
19 | 20 |
20 namespace content { | 21 namespace content { |
21 | 22 |
22 // Type used to identify desktop media sources. It's converted to string and | 23 // Type used to identify desktop media sources. It's converted to string and |
23 // stored in MediaStreamRequest::requested_video_device_id. | 24 // stored in MediaStreamRequest::requested_video_device_id. |
24 struct CONTENT_EXPORT DesktopMediaID { | 25 struct CONTENT_EXPORT DesktopMediaID { |
25 public: | 26 public: |
26 enum Type { | 27 enum Type { TYPE_NONE, TYPE_SCREEN, TYPE_WINDOW, TYPE_TAB }; |
27 TYPE_NONE, | |
28 TYPE_SCREEN, | |
29 TYPE_WINDOW, | |
30 }; | |
31 | 28 |
32 typedef intptr_t Id; | 29 typedef intptr_t Id; |
33 | 30 |
34 // Represents an "unset" value for either |id| or |aura_id|. | 31 // Represents an "unset" value for either |id| or |aura_id|. |
35 static const Id kNullId = 0; | 32 static const Id kNullId = 0; |
36 | 33 |
37 #if defined(USE_AURA) | 34 #if defined(USE_AURA) |
38 // Assigns integer identifier to the |window| and returns its DesktopMediaID. | 35 // Assigns integer identifier to the |window| and returns its DesktopMediaID. |
39 static DesktopMediaID RegisterAuraWindow(Type type, aura::Window* window); | 36 static DesktopMediaID RegisterAuraWindow(Type type, aura::Window* window); |
40 | 37 |
41 // Returns the Window that was previously registered using | 38 // Returns the Window that was previously registered using |
42 // RegisterAuraWindow(), else nullptr. | 39 // RegisterAuraWindow(), else nullptr. |
43 static aura::Window* GetAuraWindowById(const DesktopMediaID& id); | 40 static aura::Window* GetAuraWindowById(const DesktopMediaID& id); |
44 #endif // defined(USE_AURA) | 41 #endif // defined(USE_AURA) |
45 | 42 |
46 static DesktopMediaID Parse(const std::string& str); | |
47 | |
48 DesktopMediaID() = default; | 43 DesktopMediaID() = default; |
49 | 44 |
50 DesktopMediaID(Type type, Id id) | 45 DesktopMediaID(Type type, Id id) : type(type), id(id) {} |
51 : type(type), | 46 |
52 id(id) { | 47 DesktopMediaID(Type type, Id id, WebContentsMediaCaptureId tab_id) |
53 } | 48 : type(type), id(id), tab_id(tab_id) {} |
49 | |
50 DesktopMediaID(Type type, | |
Sergey Ulanov
2016/01/04 18:59:29
I don't think this constructor is necessary given
GeorgeZ
2016/01/06 22:41:39
Done.
| |
51 Id id, | |
52 int render_process_id, | |
53 int main_render_frame_id) | |
54 : type(type), id(id), tab_id(render_process_id, main_render_frame_id) {} | |
54 | 55 |
55 // Operators so that DesktopMediaID can be used with STL containers. | 56 // Operators so that DesktopMediaID can be used with STL containers. |
56 bool operator<(const DesktopMediaID& other) const { | 57 bool operator<(const DesktopMediaID& other) const; |
57 #if defined(USE_AURA) | 58 bool operator==(const DesktopMediaID& other) const; |
58 return std::tie(type, id, aura_id) < | |
59 std::tie(other.type, other.id, other.aura_id); | |
60 #else | |
61 return std::tie(type, id) < std::tie(other.type, other.id); | |
62 #endif | |
63 } | |
64 bool operator==(const DesktopMediaID& other) const { | |
65 #if defined(USE_AURA) | |
66 return type == other.type && id == other.id && aura_id == other.aura_id; | |
67 #else | |
68 return type == other.type && id == other.id; | |
69 #endif | |
70 } | |
71 | 59 |
72 bool is_null() { return type == TYPE_NONE; } | 60 bool is_null() const { return type == TYPE_NONE; } |
73 | 61 std::string ToString() const; |
74 std::string ToString(); | 62 static DesktopMediaID Parse(const std::string& str); |
75 | 63 |
76 Type type = TYPE_NONE; | 64 Type type = TYPE_NONE; |
77 | 65 |
78 // The IDs referring to the target native screen or window. |id| will be | 66 // The IDs referring to the target native screen or window. |id| will be |
79 // non-null if and only if it refers to a native screen/window. |aura_id| | 67 // non-null if and only if it refers to a native screen/window. |aura_id| |
80 // will be non-null if and only if it refers to an Aura window. Note that is | 68 // will be non-null if and only if it refers to an Aura window. Note that is |
81 // it possible for both of these to be non-null, which means both IDs are | 69 // it possible for both of these to be non-null, which means both IDs are |
82 // referring to the same logical window. | 70 // referring to the same logical window. |
83 Id id = kNullId; | 71 Id id = kNullId; |
84 #if defined(USE_AURA) | 72 #if defined(USE_AURA) |
85 // TODO(miu): Make this an int, after clean-up for http://crbug.com/513490. | 73 // TODO(miu): Make this an int, after clean-up for http://crbug.com/513490. |
86 Id aura_id = kNullId; | 74 Id aura_id = kNullId; |
87 #endif | 75 #endif |
76 | |
77 // This id contains information for tab capture. | |
78 WebContentsMediaCaptureId tab_id; | |
88 }; | 79 }; |
89 | 80 |
90 } // namespace content | 81 } // namespace content |
91 | 82 |
92 #endif // CONTENT_PUBLIC_BROWSER_DESKTOP_MEDIA_ID_H_ | 83 #endif // CONTENT_PUBLIC_BROWSER_DESKTOP_MEDIA_ID_H_ |
OLD | NEW |