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

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

Issue 364123002: [Cross-Site Isolation] Migrate entire MediaStream verticals to be per-RenderFrame. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: It's random enough. + REBASE Created 6 years, 5 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 | Annotate | Revision Log
OLDNEW
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/browser/media/capture/web_contents_capture_util.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 {
13
14 const char kVirtualDeviceScheme[] = "virtual-media-stream://";
15
16 } // namespace
17
18 namespace content { 12 namespace content {
19 13
20 std::string WebContentsCaptureUtil::AppendWebContentsDeviceScheme(
21 const std::string& device_id) {
22 return kVirtualDeviceScheme + device_id;
23 }
24
25 std::string WebContentsCaptureUtil::StripWebContentsDeviceScheme(
26 const std::string& device_id) {
27 return (IsWebContentsDeviceId(device_id) ?
28 device_id.substr(arraysize(kVirtualDeviceScheme) - 1) :
29 device_id);
30 }
31
32 bool WebContentsCaptureUtil::IsWebContentsDeviceId( 14 bool WebContentsCaptureUtil::IsWebContentsDeviceId(
33 const std::string& device_id) { 15 const std::string& device_id) {
34 return StartsWithASCII(device_id, kVirtualDeviceScheme, true); 16 int ignored;
17 return ExtractTabCaptureTarget(device_id, &ignored, &ignored);
35 } 18 }
36 19
37 bool WebContentsCaptureUtil::ExtractTabCaptureTarget( 20 bool WebContentsCaptureUtil::ExtractTabCaptureTarget(
38 const std::string& device_id_param, 21 const std::string& device_id_param,
39 int* render_process_id, 22 int* render_process_id,
40 int* render_view_id) { 23 int* main_render_frame_id) {
41 if (!IsWebContentsDeviceId(device_id_param)) 24 static const char kDeviceScheme[] = "web-contents-media-stream://";
25 if (!StartsWithASCII(device_id_param, kDeviceScheme, true))
42 return false; 26 return false;
43 27
44 const std::string device_id = device_id_param.substr( 28 const std::string device_id = device_id_param.substr(
45 arraysize(kVirtualDeviceScheme) - 1); 29 arraysize(kDeviceScheme) - 1);
46 30
47 const size_t sep_pos = device_id.find(':'); 31 const size_t sep_pos = device_id.find(':');
48 if (sep_pos == std::string::npos) 32 if (sep_pos == std::string::npos)
49 return false; 33 return false;
50 34
51 const base::StringPiece component1(device_id.data(), sep_pos); 35 const base::StringPiece component1(device_id.data(), sep_pos);
52 const base::StringPiece component2(device_id.data() + sep_pos + 1, 36 const base::StringPiece component2(device_id.data() + sep_pos + 1,
53 device_id.length() - sep_pos - 1); 37 device_id.length() - sep_pos - 1);
54 38
55 return (base::StringToInt(component1, render_process_id) && 39 return (base::StringToInt(component1, render_process_id) &&
56 base::StringToInt(component2, render_view_id)); 40 base::StringToInt(component2, main_render_frame_id));
57 } 41 }
58 42
59 } // namespace content 43 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/media/capture/web_contents_capture_util.h ('k') | content/browser/media/capture/web_contents_tracker.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698