Chromium Code Reviews| 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 <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/id_map.h" | 9 #include "base/id_map.h" |
| 10 #include "base/memory/singleton.h" | 10 #include "base/memory/singleton.h" |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 66 }; | 66 }; |
| 67 | 67 |
| 68 #endif // defined(USE_AURA) | 68 #endif // defined(USE_AURA) |
| 69 | 69 |
| 70 } // namespace | 70 } // namespace |
| 71 | 71 |
| 72 namespace content { | 72 namespace content { |
| 73 | 73 |
| 74 const char kScreenPrefix[] = "screen"; | 74 const char kScreenPrefix[] = "screen"; |
| 75 const char kWindowPrefix[] = "window"; | 75 const char kWindowPrefix[] = "window"; |
| 76 // Prefix for tab and consist with existing code for tab capture. | |
| 77 const char kTabPrefix[] = "web-contents-media-stream"; | |
|
miu
2015/12/08 01:54:38
This and a lot of the other changes in this file d
GeorgeZ
2015/12/09 19:36:38
After modification, DesktopMediaID has an instance
| |
| 76 | 78 |
| 77 #if defined(USE_AURA) | 79 #if defined(USE_AURA) |
| 78 | 80 |
| 79 // static | 81 // static |
| 80 DesktopMediaID DesktopMediaID::RegisterAuraWindow(DesktopMediaID::Type type, | 82 DesktopMediaID DesktopMediaID::RegisterAuraWindow(DesktopMediaID::Type type, |
| 81 aura::Window* window) { | 83 aura::Window* window) { |
| 82 DCHECK(type == TYPE_SCREEN || type == TYPE_WINDOW); | 84 DCHECK(type == TYPE_SCREEN || type == TYPE_WINDOW || type == TYPE_TAB); |
| 83 DCHECK(window); | 85 DCHECK(window); |
| 84 DesktopMediaID media_id(type, kNullId); | 86 DesktopMediaID media_id(type, kNullId); |
| 85 media_id.aura_id = AuraWindowRegistry::GetInstance()->RegisterWindow(window); | 87 media_id.aura_id = AuraWindowRegistry::GetInstance()->RegisterWindow(window); |
| 86 return media_id; | 88 return media_id; |
| 87 } | 89 } |
| 88 | 90 |
| 89 // static | 91 // static |
| 90 aura::Window* DesktopMediaID::GetAuraWindowById(const DesktopMediaID& id) { | 92 aura::Window* DesktopMediaID::GetAuraWindowById(const DesktopMediaID& id) { |
| 91 return AuraWindowRegistry::GetInstance()->GetWindowById(id.aura_id); | 93 return AuraWindowRegistry::GetInstance()->GetWindowById(id.aura_id); |
| 92 } | 94 } |
| 93 | 95 |
| 94 #endif // defined(USE_AURA) | 96 #endif // defined(USE_AURA) |
| 95 | 97 |
| 96 // static | 98 // static |
| 99 // Input string should in format: | |
| 100 // for tab: web-contents-media-stream://"render_process_id":"render_process_id" | |
| 101 // for no tab and aura: screen:"window_id" or window:"window_id" | |
| 102 // for no tab and no aura: screen:"window_id:aura_id" or | |
| 103 // window:"window_id:aura_id". | |
| 97 DesktopMediaID DesktopMediaID::Parse(const std::string& str) { | 104 DesktopMediaID DesktopMediaID::Parse(const std::string& str) { |
| 98 std::vector<std::string> parts = base::SplitString( | 105 std::vector<std::string> parts = base::SplitString( |
| 99 str, ":", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); | 106 str, ":", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
| 100 | 107 |
| 101 #if defined(USE_AURA) | 108 if (parts.size() < 2) |
| 102 if (parts.size() != 3) | |
| 103 return DesktopMediaID(); | 109 return DesktopMediaID(); |
| 104 #else | |
| 105 if (parts.size() != 2) | |
| 106 return DesktopMediaID(); | |
| 107 #endif | |
| 108 | 110 |
| 109 Type type = TYPE_NONE; | 111 Type type = TYPE_NONE; |
| 110 if (parts[0] == kScreenPrefix) { | 112 if (parts[0] == kScreenPrefix) { |
| 111 type = TYPE_SCREEN; | 113 type = TYPE_SCREEN; |
| 112 } else if (parts[0] == kWindowPrefix) { | 114 } else if (parts[0] == kWindowPrefix) { |
| 113 type = TYPE_WINDOW; | 115 type = TYPE_WINDOW; |
| 116 } else if (parts[0] == kTabPrefix) { | |
| 117 type = TYPE_TAB; | |
| 114 } else { | 118 } else { |
| 115 return DesktopMediaID(); | 119 return DesktopMediaID(); |
| 116 } | 120 } |
| 117 | 121 |
| 122 if (type == TYPE_TAB) { | |
| 123 if (parts.size() != 3) | |
| 124 return DesktopMediaID(); | |
| 125 } else { | |
| 126 #if defined(USE_AURA) | |
| 127 if (parts.size() != 3) | |
| 128 return DesktopMediaID(); | |
| 129 #else | |
| 130 if (parts.size() != 2) | |
| 131 return DesktopMediaID(); | |
| 132 #endif // defined(USE_AURA) | |
| 133 } | |
| 134 | |
| 118 int64 id; | 135 int64 id; |
| 119 if (!base::StringToInt64(parts[1], &id)) | 136 if (type != TYPE_TAB) { |
| 120 return DesktopMediaID(); | 137 if (!base::StringToInt64(parts[1], &id)) |
| 138 return DesktopMediaID(); | |
| 121 | 139 |
| 122 DesktopMediaID media_id(type, id); | 140 DesktopMediaID media_id(type, id); |
| 123 | 141 |
| 124 #if defined(USE_AURA) | 142 #if defined(USE_AURA) |
| 125 int64 aura_id; | 143 int64 aura_id; |
| 126 if (!base::StringToInt64(parts[2], &aura_id)) | 144 if (!base::StringToInt64(parts[2], &aura_id)) |
| 127 return DesktopMediaID(); | 145 return DesktopMediaID(); |
| 128 media_id.aura_id = aura_id; | 146 media_id.aura_id = aura_id; |
| 129 #endif // defined(USE_AURA) | 147 #endif // defined(USE_AURA) |
| 130 | 148 |
| 131 return media_id; | 149 return media_id; |
| 150 } else { | |
| 151 int64 rend_process_id, main_render_frame_id; | |
| 152 if (!base::StringToInt64(parts[1].substr(2, parts[1].size() - 2), | |
| 153 &rend_process_id)) | |
| 154 return DesktopMediaID(); | |
| 155 | |
| 156 if (!base::StringToInt64(parts[2], &main_render_frame_id)) | |
| 157 return DesktopMediaID(); | |
| 158 | |
| 159 DesktopMediaID media_id(type, 0); | |
| 160 media_id.render_process_id = rend_process_id; | |
|
qiangchen
2015/12/07 22:45:56
Consider adding a constructor for DesktopMediaID.
GeorgeZ
2015/12/09 19:36:38
Done.
| |
| 161 media_id.main_render_frame_id = main_render_frame_id; | |
| 162 return media_id; | |
| 163 } | |
| 132 } | 164 } |
| 133 | 165 |
| 134 std::string DesktopMediaID::ToString() { | 166 std::string DesktopMediaID::ToString() const { |
| 135 std::string prefix; | 167 std::string prefix; |
| 136 switch (type) { | 168 switch (type) { |
| 137 case TYPE_NONE: | 169 case TYPE_NONE: |
| 138 NOTREACHED(); | 170 NOTREACHED(); |
| 139 return std::string(); | 171 return std::string(); |
| 140 case TYPE_SCREEN: | 172 case TYPE_SCREEN: |
| 141 prefix = kScreenPrefix; | 173 prefix = kScreenPrefix; |
| 142 break; | 174 break; |
| 143 case TYPE_WINDOW: | 175 case TYPE_WINDOW: |
| 144 prefix = kWindowPrefix; | 176 prefix = kWindowPrefix; |
| 145 break; | 177 break; |
| 178 case TYPE_TAB: | |
| 179 prefix = kTabPrefix; | |
| 180 break; | |
| 146 } | 181 } |
| 147 DCHECK(!prefix.empty()); | 182 DCHECK(!prefix.empty()); |
| 148 | 183 |
| 149 prefix.append(":"); | 184 if (type != TYPE_TAB) { |
| 150 prefix.append(base::Int64ToString(id)); | 185 prefix.append(":"); |
| 186 prefix.append(base::Int64ToString(id)); | |
| 151 | 187 |
| 152 #if defined(USE_AURA) | 188 #if defined(USE_AURA) |
| 153 prefix.append(":"); | 189 prefix.append(":"); |
| 154 prefix.append(base::Int64ToString(aura_id)); | 190 prefix.append(base::Int64ToString(aura_id)); |
| 155 #endif // defined(USE_AURA) | 191 #endif // defined(USE_AURA) |
| 192 } else { | |
| 193 prefix.append("://"); | |
| 194 prefix.append(base::Int64ToString(render_process_id)); | |
| 195 prefix.append(":"); | |
| 196 prefix.append(base::Int64ToString(main_render_frame_id)); | |
| 197 } | |
| 156 | 198 |
| 157 return prefix; | 199 return prefix; |
| 158 } | 200 } |
| 159 | 201 |
| 160 } // namespace content | 202 } // namespace content |
| OLD | NEW |