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
3 // found in the LICENSE file.
5 #include "content/browser/renderer_host/media/web_contents_capture_util.h"
7 #include "base/basictypes.h"
8 #include "base/strings/string_number_conversions.h"
9 #include "base/strings/string_piece.h"
10 #include "base/strings/string_util.h"
14 const char kVirtualDeviceScheme
[] = "virtual-media-stream://";
20 std::string
WebContentsCaptureUtil::AppendWebContentsDeviceScheme(
21 const std::string
& device_id
) {
22 return kVirtualDeviceScheme
+ device_id
;
25 std::string
WebContentsCaptureUtil::StripWebContentsDeviceScheme(
26 const std::string
& device_id
) {
27 return (IsWebContentsDeviceId(device_id
) ?
28 device_id
.substr(arraysize(kVirtualDeviceScheme
) - 1) :
32 bool WebContentsCaptureUtil::IsWebContentsDeviceId(
33 const std::string
& device_id
) {
34 return StartsWithASCII(device_id
, kVirtualDeviceScheme
, true);
37 bool WebContentsCaptureUtil::ExtractTabCaptureTarget(
38 const std::string
& device_id_param
,
39 int* render_process_id
,
40 int* render_view_id
) {
41 if (!IsWebContentsDeviceId(device_id_param
))
44 const std::string device_id
= device_id_param
.substr(
45 arraysize(kVirtualDeviceScheme
) - 1);
47 const size_t sep_pos
= device_id
.find(':');
48 if (sep_pos
== std::string::npos
)
51 const base::StringPiece
component1(device_id
.data(), sep_pos
);
52 const base::StringPiece
component2(device_id
.data() + sep_pos
+ 1,
53 device_id
.length() - sep_pos
- 1);
55 return (base::StringToInt(component1
, render_process_id
) &&
56 base::StringToInt(component2
, render_view_id
));
59 } // namespace content