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://"; | |
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 device_id.substr( | |
miu
2012/11/22 00:53:50
Don't need 2nd arg to substr(). Also, consider in
justinlin
2012/11/26 20:19:20
Done.
| |
28 arraysize(kVirtualDeviceScheme) - 1, device_id.length()); | |
29 } | |
30 | |
31 bool WebContentsCaptureUtil::IsWebContentsDeviceId( | |
32 const std::string& device_id) { | |
33 return StartsWithASCII(device_id, kVirtualDeviceScheme, true); | |
34 } | |
35 | |
12 bool WebContentsCaptureUtil::ExtractTabCaptureTarget( | 36 bool WebContentsCaptureUtil::ExtractTabCaptureTarget( |
13 const std::string& device_id, | 37 const std::string& device_id_param, |
14 int* render_process_id, | 38 int* render_process_id, |
15 int* render_view_id) { | 39 int* render_view_id) { |
40 DCHECK(IsWebContentsDeviceId(device_id_param)); | |
41 const std::string device_id = device_id_param.substr( | |
42 arraysize(kVirtualDeviceScheme) - 1, device_id_param.length()); | |
miu
2012/11/22 00:53:50
Don't need 2nd arg to substr().
justinlin
2012/11/26 20:19:20
Done.
| |
43 | |
16 const size_t sep_pos = device_id.find(':'); | 44 const size_t sep_pos = device_id.find(':'); |
17 if (sep_pos == std::string::npos) | 45 if (sep_pos == std::string::npos) |
18 return false; | 46 return false; |
19 | 47 |
20 const base::StringPiece component1(device_id.data(), sep_pos); | 48 const base::StringPiece component1(device_id.data(), sep_pos); |
21 const base::StringPiece component2(device_id.data() + sep_pos + 1, | 49 const base::StringPiece component2(device_id.data() + sep_pos + 1, |
22 device_id.length() - sep_pos - 1); | 50 device_id.length() - sep_pos - 1); |
23 | 51 |
24 return (base::StringToInt(component1, render_process_id) && | 52 return (base::StringToInt(component1, render_process_id) && |
25 base::StringToInt(component2, render_view_id)); | 53 base::StringToInt(component2, render_view_id)); |
26 } | 54 } |
27 | 55 |
28 } // namespace content | 56 } // namespace content |
OLD | NEW |