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 || |
86 type == TYPE_WEB_CONTENTS); | |
86 DCHECK(window); | 87 DCHECK(window); |
87 DesktopMediaID media_id(type, kNullId); | 88 DesktopMediaID media_id(type, kNullId); |
88 media_id.aura_id = AuraWindowRegistry::GetInstance()->RegisterWindow(window); | 89 media_id.aura_id = AuraWindowRegistry::GetInstance()->RegisterWindow(window); |
89 return media_id; | 90 return media_id; |
90 } | 91 } |
91 | 92 |
92 // static | 93 // static |
93 aura::Window* DesktopMediaID::GetAuraWindowById(const DesktopMediaID& id) { | 94 aura::Window* DesktopMediaID::GetAuraWindowById(const DesktopMediaID& id) { |
94 return AuraWindowRegistry::GetInstance()->GetWindowById(id.aura_id); | 95 return AuraWindowRegistry::GetInstance()->GetWindowById(id.aura_id); |
95 } | 96 } |
96 | 97 |
97 #endif // defined(USE_AURA) | 98 #endif // defined(USE_AURA) |
98 | 99 |
100 bool DesktopMediaID::operator<(const DesktopMediaID& other) const { | |
101 #if defined(USE_AURA) | |
102 return std::tie(type, id, aura_id, web_contents_id) < | |
103 std::tie(other.type, other.id, other.aura_id, other.web_contents_id); | |
104 #else | |
105 return std::tie(type, id, web_contens_id) < | |
106 std::tie(other.type, other.id, web_contents_id); | |
107 #endif | |
108 } | |
109 | |
110 bool DesktopMediaID::operator==(const DesktopMediaID& other) const { | |
111 #if defined(USE_AURA) | |
112 return type == other.type && id == other.id && aura_id == other.aura_id && | |
113 web_contents_id == other.web_contents_id; | |
114 #else | |
115 return type == other.type && id == other.id && | |
116 web_contents_id == other.web_contents_id; | |
117 #endif | |
118 } | |
119 | |
99 // static | 120 // static |
121 // Input string should in format: | |
122 // for WebContents: | |
123 // web-contents-media-stream://"render_process_id":"render_process_id" | |
124 // for no WebContentsand aura: screen:"window_id" or window:"window_id" | |
miu
2016/01/12 22:05:03
s/WebContentsand/WebContents and/
GeorgeZ
2016/01/13 17:51:07
Done.
| |
125 // for no web_contents and no aura: screen:"window_id:aura_id" or | |
126 // window:"window_id:aura_id". | |
100 DesktopMediaID DesktopMediaID::Parse(const std::string& str) { | 127 DesktopMediaID DesktopMediaID::Parse(const std::string& str) { |
101 std::vector<std::string> parts = base::SplitString( | 128 std::vector<std::string> parts = base::SplitString( |
102 str, ":", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); | 129 str, ":", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
103 | 130 |
131 if (parts.size() < 2) | |
132 return DesktopMediaID(); | |
133 | |
134 Type type = TYPE_NONE; | |
135 if (parts[0] == kScreenPrefix) { | |
136 type = TYPE_SCREEN; | |
137 } else if (parts[0] == kWindowPrefix) { | |
138 type = TYPE_WINDOW; | |
139 } else if (parts[0] == kWebContentsCaptureScheme) { | |
140 type = TYPE_WEB_CONTENTS; | |
141 } else { | |
142 return DesktopMediaID(); | |
143 } | |
144 | |
145 // WebContents type. | |
146 if (type == TYPE_WEB_CONTENTS) { | |
147 WebContentsMediaCaptureId temp_id = WebContentsMediaCaptureId::Parse(str); | |
148 return DesktopMediaID(type, 0, temp_id); | |
149 } | |
150 | |
151 // Screen and window types. | |
104 #if defined(USE_AURA) | 152 #if defined(USE_AURA) |
105 if (parts.size() != 3) | 153 if (parts.size() != 3) |
106 return DesktopMediaID(); | 154 return DesktopMediaID(); |
107 #else | 155 #else |
108 if (parts.size() != 2) | 156 if (parts.size() != 2) |
109 return DesktopMediaID(); | 157 return DesktopMediaID(); |
110 #endif | 158 #endif // defined(USE_AURA) |
111 | 159 |
112 Type type = TYPE_NONE; | 160 int64_t tempid; |
113 if (parts[0] == kScreenPrefix) { | 161 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(); | 162 return DesktopMediaID(); |
124 | 163 |
125 DesktopMediaID media_id(type, id); | 164 DesktopMediaID media_id(type, tempid); |
126 | 165 |
127 #if defined(USE_AURA) | 166 #if defined(USE_AURA) |
128 int64_t aura_id; | 167 int64_t aura_id; |
129 if (!base::StringToInt64(parts[2], &aura_id)) | 168 if (!base::StringToInt64(parts[2], &aura_id)) |
130 return DesktopMediaID(); | 169 return DesktopMediaID(); |
170 | |
131 media_id.aura_id = aura_id; | 171 media_id.aura_id = aura_id; |
132 #endif // defined(USE_AURA) | 172 #endif // defined(USE_AURA) |
133 | 173 |
134 return media_id; | 174 return media_id; |
135 } | 175 } |
136 | 176 |
137 std::string DesktopMediaID::ToString() { | 177 std::string DesktopMediaID::ToString() const { |
138 std::string prefix; | 178 std::string prefix; |
139 switch (type) { | 179 switch (type) { |
140 case TYPE_NONE: | 180 case TYPE_NONE: |
141 NOTREACHED(); | 181 NOTREACHED(); |
142 return std::string(); | 182 return std::string(); |
143 case TYPE_SCREEN: | 183 case TYPE_SCREEN: |
144 prefix = kScreenPrefix; | 184 prefix = kScreenPrefix; |
145 break; | 185 break; |
146 case TYPE_WINDOW: | 186 case TYPE_WINDOW: |
147 prefix = kWindowPrefix; | 187 prefix = kWindowPrefix; |
148 break; | 188 break; |
189 case TYPE_WEB_CONTENTS: | |
190 return web_contents_id.ToString(); | |
191 break; | |
149 } | 192 } |
150 DCHECK(!prefix.empty()); | 193 DCHECK(!prefix.empty()); |
151 | 194 |
195 // Screen and Window types. | |
152 prefix.append(":"); | 196 prefix.append(":"); |
153 prefix.append(base::Int64ToString(id)); | 197 prefix.append(base::Int64ToString(id)); |
154 | 198 |
155 #if defined(USE_AURA) | 199 #if defined(USE_AURA) |
156 prefix.append(":"); | 200 prefix.append(":"); |
157 prefix.append(base::Int64ToString(aura_id)); | 201 prefix.append(base::Int64ToString(aura_id)); |
158 #endif // defined(USE_AURA) | 202 #endif // defined(USE_AURA) |
159 | 203 |
160 return prefix; | 204 return prefix; |
161 } | 205 } |
162 | 206 |
163 } // namespace content | 207 } // namespace content |
OLD | NEW |