OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/browser/renderer_host/media/web_contents_capture_util.h" | 5 #include "content/browser/renderer_host/media/web_contents_capture_util.h" |
6 | 6 |
7 #include "base/basictypes.h" | |
7 #include "base/string_number_conversions.h" | 8 #include "base/string_number_conversions.h" |
8 #include "base/string_piece.h" | 9 #include "base/string_piece.h" |
10 #include "base/string_util.h" | |
11 | |
12 namespace { | |
13 | |
14 const char kVirtualDeviceScheme[] = "virtual://"; | |
Alpha Left Google
2012/11/28 01:04:47
maybe virtual-media-stream?
justinlin
2012/11/28 14:30:31
Done.
| |
15 | |
16 } // namespace | |
9 | 17 |
10 namespace content { | 18 namespace content { |
11 | 19 |
20 std::string WebContentsCaptureUtil::AppendWebContentsDeviceScheme( | |
21 const std::string& device_id) { | |
22 return kVirtualDeviceScheme + device_id; | |
23 } | |
24 | |
25 std::string WebContentsCaptureUtil::StripWebContentsDeviceScheme( | |
26 const std::string& device_id) { | |
27 return (IsWebContentsDeviceId(device_id) ? | |
Alpha Left Google
2012/11/28 01:04:47
indentation
justinlin
2012/11/28 14:30:31
Done.
| |
28 device_id.substr(arraysize(kVirtualDeviceScheme) - 1) : | |
Alpha Left Google
2012/11/28 01:04:47
Use url_parse? See: http://code.google.com/p/chrom
justinlin
2012/11/28 14:30:31
That seems a bit overkill? All we want is just to
| |
29 device_id); | |
30 } | |
31 | |
32 bool WebContentsCaptureUtil::IsWebContentsDeviceId( | |
33 const std::string& device_id) { | |
34 return StartsWithASCII(device_id, kVirtualDeviceScheme, true); | |
35 } | |
36 | |
12 bool WebContentsCaptureUtil::ExtractTabCaptureTarget( | 37 bool WebContentsCaptureUtil::ExtractTabCaptureTarget( |
13 const std::string& device_id, | 38 const std::string& device_id_param, |
14 int* render_process_id, | 39 int* render_process_id, |
15 int* render_view_id) { | 40 int* render_view_id) { |
41 DCHECK(IsWebContentsDeviceId(device_id_param)); | |
42 const std::string device_id = device_id_param.substr( | |
Alpha Left Google
2012/11/28 01:04:47
Use url_parse?
| |
43 arraysize(kVirtualDeviceScheme) - 1); | |
44 | |
16 const size_t sep_pos = device_id.find(':'); | 45 const size_t sep_pos = device_id.find(':'); |
17 if (sep_pos == std::string::npos) | 46 if (sep_pos == std::string::npos) |
18 return false; | 47 return false; |
19 | 48 |
20 const base::StringPiece component1(device_id.data(), sep_pos); | 49 const base::StringPiece component1(device_id.data(), sep_pos); |
21 const base::StringPiece component2(device_id.data() + sep_pos + 1, | 50 const base::StringPiece component2(device_id.data() + sep_pos + 1, |
22 device_id.length() - sep_pos - 1); | 51 device_id.length() - sep_pos - 1); |
23 | 52 |
24 return (base::StringToInt(component1, render_process_id) && | 53 return (base::StringToInt(component1, render_process_id) && |
25 base::StringToInt(component2, render_view_id)); | 54 base::StringToInt(component2, render_view_id)); |
26 } | 55 } |
27 | 56 |
28 } // namespace content | 57 } // namespace content |
OLD | NEW |