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/string_number_conversions.h" | 7 #include "base/string_number_conversions.h" |
8 #include "base/string_piece.h" | 8 #include "base/string_piece.h" |
9 #include "base/string_util.h" | |
10 | |
11 namespace { | |
12 | |
13 const char kVirtualDeviceScheme[] = "virtual://"; | |
14 | |
15 } // namespace | |
9 | 16 |
10 namespace content { | 17 namespace content { |
11 | 18 |
19 std::string WebContentsCaptureUtil::AppendWebContentsDeviceScheme( | |
20 const std::string& device_id) { | |
21 return kVirtualDeviceScheme + device_id; | |
22 } | |
23 | |
24 bool WebContentsCaptureUtil::IsWebContentsDeviceId( | |
25 const std::string& device_id) { | |
26 return StartsWithASCII(device_id, kVirtualDeviceScheme, true); | |
27 } | |
28 | |
12 bool WebContentsCaptureUtil::ExtractTabCaptureTarget( | 29 bool WebContentsCaptureUtil::ExtractTabCaptureTarget( |
13 const std::string& device_id, | 30 const std::string& device_id_param, |
14 int& render_process_id, | 31 int& render_process_id, |
15 int& render_view_id) { | 32 int& render_view_id) { |
33 DCHECK(IsWebContentsDeviceId(device_id_param)); | |
34 const std::string device_id = device_id_param.substr( | |
35 strlen(kVirtualDeviceScheme), device_id_param.length()); | |
miu
2012/11/21 07:29:49
nit: strlen() must compute the length every time.
justinlin
2012/11/21 08:09:54
Done. Nice catch.
| |
36 | |
16 const size_t sep_pos = device_id.find(':'); | 37 const size_t sep_pos = device_id.find(':'); |
17 if (sep_pos == std::string::npos) | 38 if (sep_pos == std::string::npos) |
18 return false; | 39 return false; |
19 | 40 |
20 const base::StringPiece component1(device_id.data(), sep_pos); | 41 const base::StringPiece component1(device_id.data(), sep_pos); |
21 const base::StringPiece component2(device_id.data() + sep_pos + 1, | 42 const base::StringPiece component2(device_id.data() + sep_pos + 1, |
22 device_id.length() - sep_pos - 1); | 43 device_id.length() - sep_pos - 1); |
23 | 44 |
24 return (base::StringToInt(component1, &render_process_id) && | 45 return (base::StringToInt(component1, &render_process_id) && |
25 base::StringToInt(component2, &render_view_id)); | 46 base::StringToInt(component2, &render_view_id)); |
26 } | 47 } |
27 | 48 |
28 } // namespace content | 49 } // namespace content |
OLD | NEW |