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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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, web_contents_id) < |
| 102 std::tie(other.type, other.id, other.aura_id, other.web_contents_id); |
| 103 #else |
| 104 return std::tie(type, id, web_contents_id) < |
| 105 std::tie(other.type, other.id, web_contents_id); |
| 106 #endif |
| 107 } |
| 108 |
| 109 bool DesktopMediaID::operator==(const DesktopMediaID& other) const { |
| 110 #if defined(USE_AURA) |
| 111 return type == other.type && id == other.id && aura_id == other.aura_id && |
| 112 web_contents_id == other.web_contents_id; |
| 113 #else |
| 114 return type == other.type && id == other.id && |
| 115 web_contents_id == other.web_contents_id; |
| 116 #endif |
| 117 } |
| 118 |
99 // static | 119 // static |
| 120 // Input string should in format: |
| 121 // for WebContents: |
| 122 // web-contents-media-stream://"render_process_id":"render_process_id" |
| 123 // for no aura screen and window: screen:"window_id" or window:"window_id" |
| 124 // for aura screen and window: screen:"window_id:aura_id" or |
| 125 // window:"window_id:aura_id". |
100 DesktopMediaID DesktopMediaID::Parse(const std::string& str) { | 126 DesktopMediaID DesktopMediaID::Parse(const std::string& str) { |
| 127 // For WebContents type. |
| 128 WebContentsMediaCaptureId web_id = WebContentsMediaCaptureId::Parse(str); |
| 129 if (!web_id.is_null()) |
| 130 return DesktopMediaID(TYPE_WEB_CONTENTS, 0, web_id); |
| 131 |
| 132 // For screen and window types. |
101 std::vector<std::string> parts = base::SplitString( | 133 std::vector<std::string> parts = base::SplitString( |
102 str, ":", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); | 134 str, ":", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
103 | 135 |
104 #if defined(USE_AURA) | 136 #if defined(USE_AURA) |
105 if (parts.size() != 3) | 137 if (parts.size() != 3) |
106 return DesktopMediaID(); | 138 return DesktopMediaID(); |
107 #else | 139 #else |
108 if (parts.size() != 2) | 140 if (parts.size() != 2) |
109 return DesktopMediaID(); | 141 return DesktopMediaID(); |
110 #endif | 142 #endif |
(...skipping 16 matching lines...) Expand all Loading... |
127 #if defined(USE_AURA) | 159 #if defined(USE_AURA) |
128 int64_t aura_id; | 160 int64_t aura_id; |
129 if (!base::StringToInt64(parts[2], &aura_id)) | 161 if (!base::StringToInt64(parts[2], &aura_id)) |
130 return DesktopMediaID(); | 162 return DesktopMediaID(); |
131 media_id.aura_id = aura_id; | 163 media_id.aura_id = aura_id; |
132 #endif // defined(USE_AURA) | 164 #endif // defined(USE_AURA) |
133 | 165 |
134 return media_id; | 166 return media_id; |
135 } | 167 } |
136 | 168 |
137 std::string DesktopMediaID::ToString() { | 169 std::string DesktopMediaID::ToString() const { |
138 std::string prefix; | 170 std::string prefix; |
139 switch (type) { | 171 switch (type) { |
140 case TYPE_NONE: | 172 case TYPE_NONE: |
141 NOTREACHED(); | 173 NOTREACHED(); |
142 return std::string(); | 174 return std::string(); |
143 case TYPE_SCREEN: | 175 case TYPE_SCREEN: |
144 prefix = kScreenPrefix; | 176 prefix = kScreenPrefix; |
145 break; | 177 break; |
146 case TYPE_WINDOW: | 178 case TYPE_WINDOW: |
147 prefix = kWindowPrefix; | 179 prefix = kWindowPrefix; |
148 break; | 180 break; |
| 181 case TYPE_WEB_CONTENTS: |
| 182 return web_contents_id.ToString(); |
| 183 break; |
149 } | 184 } |
150 DCHECK(!prefix.empty()); | 185 DCHECK(!prefix.empty()); |
151 | 186 |
| 187 // Screen and Window types. |
152 prefix.append(":"); | 188 prefix.append(":"); |
153 prefix.append(base::Int64ToString(id)); | 189 prefix.append(base::Int64ToString(id)); |
154 | 190 |
155 #if defined(USE_AURA) | 191 #if defined(USE_AURA) |
156 prefix.append(":"); | 192 prefix.append(":"); |
157 prefix.append(base::Int64ToString(aura_id)); | 193 prefix.append(base::Int64ToString(aura_id)); |
158 #endif // defined(USE_AURA) | 194 #endif // defined(USE_AURA) |
159 | 195 |
160 return prefix; | 196 return prefix; |
161 } | 197 } |
162 | 198 |
163 } // namespace content | 199 } // namespace content |
OLD | NEW |