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 #include "content/public/browser/desktop_media_id.h" | 5 #include "content/public/browser/desktop_media_id.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
75 namespace content { | 75 namespace content { |
76 | 76 |
77 const char kScreenPrefix[] = "screen"; | 77 const char kScreenPrefix[] = "screen"; |
78 const char kWindowPrefix[] = "window"; | 78 const char kWindowPrefix[] = "window"; |
79 | 79 |
80 #if defined(USE_AURA) | 80 #if defined(USE_AURA) |
81 | 81 |
82 // static | 82 // static |
83 DesktopMediaID DesktopMediaID::RegisterAuraWindow(DesktopMediaID::Type type, | 83 DesktopMediaID DesktopMediaID::RegisterAuraWindow(DesktopMediaID::Type type, |
84 aura::Window* window) { | 84 aura::Window* window) { |
85 DCHECK(type == TYPE_SCREEN || type == TYPE_WINDOW); | 85 DCHECK(type == TYPE_SCREEN || type == TYPE_WINDOW || type == TYPE_TAB); |
86 DCHECK(window); | 86 DCHECK(window); |
87 DesktopMediaID media_id(type, kNullId); | 87 DesktopMediaID media_id(type, kNullId); |
88 media_id.aura_id = AuraWindowRegistry::GetInstance()->RegisterWindow(window); | 88 media_id.aura_id = AuraWindowRegistry::GetInstance()->RegisterWindow(window); |
89 return media_id; | 89 return media_id; |
90 } | 90 } |
91 | 91 |
92 // static | 92 // static |
93 aura::Window* DesktopMediaID::GetAuraWindowById(const DesktopMediaID& id) { | 93 aura::Window* DesktopMediaID::GetAuraWindowById(const DesktopMediaID& id) { |
94 return AuraWindowRegistry::GetInstance()->GetWindowById(id.aura_id); | 94 return AuraWindowRegistry::GetInstance()->GetWindowById(id.aura_id); |
95 } | 95 } |
96 | 96 |
97 #endif // defined(USE_AURA) | 97 #endif // defined(USE_AURA) |
98 | 98 |
99 bool DesktopMediaID::operator<(const DesktopMediaID& other) const { | |
100 #if defined(USE_AURA) | |
101 return std::tie(type, id, aura_id, tab_id) < | |
102 std::tie(other.type, other.id, other.aura_id, other.tab_id); | |
103 #else | |
104 return std::tie(type, id, tab_id) < std::tie(other.type, other.id, tab_id); | |
105 #endif | |
106 } | |
107 | |
108 bool DesktopMediaID::operator==(const DesktopMediaID& other) const { | |
109 #if defined(USE_AURA) | |
110 return type == other.type && id == other.id && aura_id == other.aura_id && | |
111 tab_id == other.tab_id; | |
112 #else | |
113 return type == other.type && id == other.id && tab_id == other.tab_id; | |
114 #endif | |
115 } | |
116 | |
99 // static | 117 // static |
118 // Input string should in format: | |
119 // for tab: web-contents-media-stream://"render_process_id":"render_process_id" | |
120 // for no tab and aura: screen:"window_id" or window:"window_id" | |
121 // for no tab and no aura: screen:"window_id:aura_id" or | |
122 // window:"window_id:aura_id". | |
100 DesktopMediaID DesktopMediaID::Parse(const std::string& str) { | 123 DesktopMediaID DesktopMediaID::Parse(const std::string& str) { |
101 std::vector<std::string> parts = base::SplitString( | 124 std::vector<std::string> parts = base::SplitString( |
102 str, ":", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); | 125 str, ":", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
103 | 126 |
127 if (parts.size() < 2) | |
128 return DesktopMediaID(); | |
129 | |
130 Type type = TYPE_NONE; | |
131 if (parts[0] == kScreenPrefix) { | |
132 type = TYPE_SCREEN; | |
133 } else if (parts[0] == kWindowPrefix) { | |
134 type = TYPE_WINDOW; | |
135 } else if (parts[0] == kWebContentsCaptureScheme) { | |
136 type = TYPE_TAB; | |
Avi (use Gerrit)
2016/01/11 16:27:57
Yeah, the TYPE_WEB_CONTENTS fits better here.
GeorgeZ
2016/01/11 19:16:19
Done.
| |
137 } else { | |
138 return DesktopMediaID(); | |
139 } | |
140 | |
141 // Tab type. | |
142 if (type == TYPE_TAB) { | |
143 WebContentsMediaCaptureId temp_id = WebContentsMediaCaptureId::Parse(str); | |
144 return DesktopMediaID(type, 0, temp_id); | |
145 } | |
146 | |
147 // Screen and window types. | |
104 #if defined(USE_AURA) | 148 #if defined(USE_AURA) |
105 if (parts.size() != 3) | 149 if (parts.size() != 3) |
106 return DesktopMediaID(); | 150 return DesktopMediaID(); |
107 #else | 151 #else |
108 if (parts.size() != 2) | 152 if (parts.size() != 2) |
109 return DesktopMediaID(); | 153 return DesktopMediaID(); |
110 #endif | 154 #endif // defined(USE_AURA) |
111 | 155 |
112 Type type = TYPE_NONE; | 156 int64_t tempid; |
113 if (parts[0] == kScreenPrefix) { | 157 if (!base::StringToInt64(parts[1], &tempid)) |
114 type = TYPE_SCREEN; | |
115 } else if (parts[0] == kWindowPrefix) { | |
116 type = TYPE_WINDOW; | |
117 } else { | |
118 return DesktopMediaID(); | |
119 } | |
120 | |
121 int64_t id; | |
122 if (!base::StringToInt64(parts[1], &id)) | |
123 return DesktopMediaID(); | 158 return DesktopMediaID(); |
124 | 159 |
125 DesktopMediaID media_id(type, id); | 160 DesktopMediaID media_id(type, tempid); |
126 | 161 |
127 #if defined(USE_AURA) | 162 #if defined(USE_AURA) |
128 int64_t aura_id; | 163 int64_t aura_id; |
129 if (!base::StringToInt64(parts[2], &aura_id)) | 164 if (!base::StringToInt64(parts[2], &aura_id)) |
130 return DesktopMediaID(); | 165 return DesktopMediaID(); |
166 | |
131 media_id.aura_id = aura_id; | 167 media_id.aura_id = aura_id; |
132 #endif // defined(USE_AURA) | 168 #endif // defined(USE_AURA) |
133 | 169 |
134 return media_id; | 170 return media_id; |
135 } | 171 } |
136 | 172 |
137 std::string DesktopMediaID::ToString() { | 173 std::string DesktopMediaID::ToString() const { |
138 std::string prefix; | 174 std::string prefix; |
139 switch (type) { | 175 switch (type) { |
140 case TYPE_NONE: | 176 case TYPE_NONE: |
141 NOTREACHED(); | 177 NOTREACHED(); |
142 return std::string(); | 178 return std::string(); |
143 case TYPE_SCREEN: | 179 case TYPE_SCREEN: |
144 prefix = kScreenPrefix; | 180 prefix = kScreenPrefix; |
145 break; | 181 break; |
146 case TYPE_WINDOW: | 182 case TYPE_WINDOW: |
147 prefix = kWindowPrefix; | 183 prefix = kWindowPrefix; |
148 break; | 184 break; |
185 case TYPE_TAB: | |
186 return tab_id.ToString(); | |
187 break; | |
149 } | 188 } |
150 DCHECK(!prefix.empty()); | 189 DCHECK(!prefix.empty()); |
151 | 190 |
191 // Screen and Window types. | |
152 prefix.append(":"); | 192 prefix.append(":"); |
153 prefix.append(base::Int64ToString(id)); | 193 prefix.append(base::Int64ToString(id)); |
154 | 194 |
155 #if defined(USE_AURA) | 195 #if defined(USE_AURA) |
156 prefix.append(":"); | 196 prefix.append(":"); |
157 prefix.append(base::Int64ToString(aura_id)); | 197 prefix.append(base::Int64ToString(aura_id)); |
158 #endif // defined(USE_AURA) | 198 #endif // defined(USE_AURA) |
159 | 199 |
160 return prefix; | 200 return prefix; |
161 } | 201 } |
162 | 202 |
163 } // namespace content | 203 } // namespace content |
OLD | NEW |