Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(604)

Side by Side Diff: content/browser/media/capture/web_contents_capture_util.cc

Issue 1503563004: Desktop chrome tab capture-chooseDesktopMedia() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 <stddef.h>
8
9 #include "base/macros.h"
10 #include "base/strings/string_number_conversions.h"
11 #include "base/strings/string_piece.h"
12 #include "base/strings/string_util.h"
13
14 namespace content {
15
16 bool WebContentsCaptureUtil::IsWebContentsDeviceId(
17 const std::string& device_id) {
18 int ignored;
19 return ExtractTabCaptureTarget(device_id, &ignored, &ignored);
20 }
21
22 bool WebContentsCaptureUtil::ExtractTabCaptureTarget(
23 const std::string& device_id_param,
24 int* render_process_id,
25 int* main_render_frame_id) {
26 static const char kDeviceScheme[] = "web-contents-media-stream://";
27 if (!base::StartsWith(device_id_param, kDeviceScheme,
28 base::CompareCase::SENSITIVE))
29 return false;
30
31 const std::string device_id = device_id_param.substr(
32 arraysize(kDeviceScheme) - 1);
33
34 const size_t sep_pos = device_id.find(':');
35 if (sep_pos == std::string::npos)
36 return false;
37
38 const base::StringPiece component1(device_id.data(), sep_pos);
39 size_t end_pos = device_id.find('?');
40 if (end_pos == std::string::npos)
41 end_pos = device_id.length();
42 const base::StringPiece component2(device_id.data() + sep_pos + 1,
43 end_pos - sep_pos - 1);
44
45 return (base::StringToInt(component1, render_process_id) &&
46 base::StringToInt(component2, main_render_frame_id));
47 }
48
49 bool WebContentsCaptureUtil::IsAutoThrottlingOptionSet(
50 const std::string& device_id) {
51 if (!IsWebContentsDeviceId(device_id))
52 return false;
53
54 // Find the option part of the string and just do a naive string compare since
55 // there are no other options in the |device_id| to account for (at the time
56 // of this writing).
57 const size_t option_pos = device_id.find('?');
58 if (option_pos == std::string::npos)
59 return false;
60 const base::StringPiece component(device_id.data() + option_pos,
61 device_id.length() - option_pos);
62 static const char kEnableFlag[] = "?throttling=auto";
63 return component.compare(kEnableFlag) == 0;
64 }
65
66 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698