OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #include "content/browser/media/capture/web_contents_capture_util.h" | |
6 | |
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" | |
11 | |
12 namespace content { | |
13 | |
14 bool WebContentsCaptureUtil::IsWebContentsDeviceId( | |
15 const std::string& device_id) { | |
16 int ignored; | |
17 return ExtractTabCaptureTarget(device_id, &ignored, &ignored); | |
18 } | |
19 | |
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 (!base::StartsWith(device_id_param, kDeviceScheme, | |
26 base::CompareCase::SENSITIVE)) | |
27 return false; | |
28 | |
29 const std::string device_id = device_id_param.substr( | |
30 arraysize(kDeviceScheme) - 1); | |
31 | |
32 const size_t sep_pos = device_id.find(':'); | |
33 if (sep_pos == std::string::npos) | |
34 return false; | |
35 | |
36 const base::StringPiece component1(device_id.data(), sep_pos); | |
37 size_t end_pos = device_id.find('?'); | |
38 if (end_pos == std::string::npos) | |
39 end_pos = device_id.length(); | |
40 const base::StringPiece component2(device_id.data() + sep_pos + 1, | |
41 end_pos - sep_pos - 1); | |
42 | |
43 return (base::StringToInt(component1, render_process_id) && | |
44 base::StringToInt(component2, main_render_frame_id)); | |
45 } | |
46 | |
47 bool WebContentsCaptureUtil::IsAutoThrottlingOptionSet( | |
48 const std::string& device_id) { | |
49 if (!IsWebContentsDeviceId(device_id)) | |
50 return false; | |
51 | |
52 // Find the option part of the string and just do a naive string compare since | |
53 // there are no other options in the |device_id| to account for (at the time | |
54 // of this writing). | |
55 const size_t option_pos = device_id.find('?'); | |
56 if (option_pos == std::string::npos) | |
57 return false; | |
58 const base::StringPiece component(device_id.data() + option_pos, | |
59 device_id.length() - option_pos); | |
60 static const char kEnableFlag[] = "?throttling=auto"; | |
61 return component.compare(kEnableFlag) == 0; | |
62 } | |
63 | |
64 } // namespace content | |
OLD | NEW |