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/media/capture/web_contents_capture_util.h" | 5 #include "content/public/browser/web_contents_media_capture_id.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
9 #include "base/strings/string_piece.h" | 9 #include "base/strings/string_piece.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
11 | 11 |
12 namespace content { | 12 namespace content { |
13 bool WebContentsMediaCaptureId::operator<( | |
14 const WebContentsMediaCaptureId& other) const { | |
15 return std::tie(render_process_id, main_render_frame_id) < | |
16 std::tie(other.render_process_id, other.main_render_frame_id); | |
17 } | |
13 | 18 |
14 bool WebContentsCaptureUtil::IsWebContentsDeviceId( | 19 bool WebContentsMediaCaptureId::operator==( |
20 const WebContentsMediaCaptureId& other) const { | |
21 return std::tie(render_process_id, main_render_frame_id) == | |
22 std::tie(other.render_process_id, other.main_render_frame_id); | |
23 } | |
24 | |
25 bool WebContentsMediaCaptureId::is_null() const { | |
26 return (render_process_id < 0) || (main_render_frame_id < 0); | |
27 } | |
28 | |
29 std::string WebContentsMediaCaptureId::ToString() const { | |
30 std::string s = kTabPrefix; | |
31 s.append("://"); | |
32 s.append(base::Int64ToString(render_process_id)); | |
33 s.append(":"); | |
34 s.append(base::Int64ToString(main_render_frame_id)); | |
35 | |
36 return s; | |
37 } | |
38 | |
39 WebContentsMediaCaptureId WebContentsMediaCaptureId::Parse( | |
40 const std::string& str){ | |
41 int render_process_id; | |
42 int main_render_frame_id; | |
43 if(ExtractTabCaptureTarget(str, &render_process_id, &main_render_frame_id)) | |
miu
2015/12/12 00:00:33
style: Space after "if" and before open parenthesi
GeorgeZ
2015/12/14 18:33:07
Done.
| |
44 return WebContentsMediaCaptureId(render_process_id, main_render_frame_id); | |
45 else | |
46 return WebContentsMediaCaptureId(); | |
47 } | |
48 | |
49 bool WebContentsMediaCaptureId::IsWebContentsDeviceId( | |
15 const std::string& device_id) { | 50 const std::string& device_id) { |
16 int ignored; | 51 int ignored; |
17 return ExtractTabCaptureTarget(device_id, &ignored, &ignored); | 52 return ExtractTabCaptureTarget(device_id, &ignored, &ignored); |
18 } | 53 } |
19 | 54 |
20 bool WebContentsCaptureUtil::ExtractTabCaptureTarget( | 55 bool WebContentsMediaCaptureId::ExtractTabCaptureTarget( |
21 const std::string& device_id_param, | 56 const std::string& device_id_param, |
22 int* render_process_id, | 57 int* render_process_id, |
23 int* main_render_frame_id) { | 58 int* main_render_frame_id) { |
24 static const char kDeviceScheme[] = "web-contents-media-stream://"; | 59 static const char kDeviceScheme[] = "web-contents-media-stream://"; |
25 if (!base::StartsWith(device_id_param, kDeviceScheme, | 60 if (!base::StartsWith(device_id_param, kDeviceScheme, |
26 base::CompareCase::SENSITIVE)) | 61 base::CompareCase::SENSITIVE)) |
27 return false; | 62 return false; |
28 | 63 |
29 const std::string device_id = device_id_param.substr( | 64 const std::string device_id = device_id_param.substr( |
30 arraysize(kDeviceScheme) - 1); | 65 arraysize(kDeviceScheme) - 1); |
31 | 66 |
32 const size_t sep_pos = device_id.find(':'); | 67 const size_t sep_pos = device_id.find(':'); |
33 if (sep_pos == std::string::npos) | 68 if (sep_pos == std::string::npos) |
34 return false; | 69 return false; |
35 | 70 |
36 const base::StringPiece component1(device_id.data(), sep_pos); | 71 const base::StringPiece component1(device_id.data(), sep_pos); |
37 size_t end_pos = device_id.find('?'); | 72 size_t end_pos = device_id.find('?'); |
38 if (end_pos == std::string::npos) | 73 if (end_pos == std::string::npos) |
39 end_pos = device_id.length(); | 74 end_pos = device_id.length(); |
40 const base::StringPiece component2(device_id.data() + sep_pos + 1, | 75 const base::StringPiece component2(device_id.data() + sep_pos + 1, |
41 end_pos - sep_pos - 1); | 76 end_pos - sep_pos - 1); |
42 | 77 |
43 return (base::StringToInt(component1, render_process_id) && | 78 return (base::StringToInt(component1, render_process_id) && |
44 base::StringToInt(component2, main_render_frame_id)); | 79 base::StringToInt(component2, main_render_frame_id)); |
45 } | 80 } |
46 | 81 |
47 bool WebContentsCaptureUtil::IsAutoThrottlingOptionSet( | 82 bool WebContentsMediaCaptureId::IsAutoThrottlingOptionSet( |
48 const std::string& device_id) { | 83 const std::string& device_id) { |
49 if (!IsWebContentsDeviceId(device_id)) | 84 if (!IsWebContentsDeviceId(device_id)) |
50 return false; | 85 return false; |
51 | 86 |
52 // Find the option part of the string and just do a naive string compare since | 87 // 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 | 88 // there are no other options in the |device_id| to account for (at the time |
54 // of this writing). | 89 // of this writing). |
55 const size_t option_pos = device_id.find('?'); | 90 const size_t option_pos = device_id.find('?'); |
56 if (option_pos == std::string::npos) | 91 if (option_pos == std::string::npos) |
57 return false; | 92 return false; |
58 const base::StringPiece component(device_id.data() + option_pos, | 93 const base::StringPiece component(device_id.data() + option_pos, |
59 device_id.length() - option_pos); | 94 device_id.length() - option_pos); |
60 static const char kEnableFlag[] = "?throttling=auto"; | 95 static const char kEnableFlag[] = "?throttling=auto"; |
61 return component.compare(kEnableFlag) == 0; | 96 return component.compare(kEnableFlag) == 0; |
62 } | 97 } |
63 | 98 |
64 } // namespace content | 99 } // namespace content |
OLD | NEW |