Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / content / browser / media / capture / web_contents_capture_util.cc
blobe1c5d52351f83bfe592ab5accb10c6fd88dd65c6
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/media/capture/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"
12 namespace content {
14 bool WebContentsCaptureUtil::IsWebContentsDeviceId(
15 const std::string& device_id) {
16 int ignored;
17 return ExtractTabCaptureTarget(device_id, &ignored, &ignored);
20 bool WebContentsCaptureUtil::ExtractTabCaptureTarget(
21 const std::string& device_id_param,
22 int* render_process_id,
23 int* main_render_frame_id) {
24 static const char kDeviceScheme[] = "web-contents-media-stream://";
25 if (!StartsWithASCII(device_id_param, kDeviceScheme, true))
26 return false;
28 const std::string device_id = device_id_param.substr(
29 arraysize(kDeviceScheme) - 1);
31 const size_t sep_pos = device_id.find(':');
32 if (sep_pos == std::string::npos)
33 return false;
35 const base::StringPiece component1(device_id.data(), sep_pos);
36 const base::StringPiece component2(device_id.data() + sep_pos + 1,
37 device_id.length() - sep_pos - 1);
39 return (base::StringToInt(component1, render_process_id) &&
40 base::StringToInt(component2, main_render_frame_id));
43 } // namespace content