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

Unified Diff: content/public/browser/web_contents_media_capture_id.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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/public/browser/web_contents_media_capture_id.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/public/browser/web_contents_media_capture_id.cc
diff --git a/content/public/browser/web_contents_media_capture_id.cc b/content/public/browser/web_contents_media_capture_id.cc
new file mode 100644
index 0000000000000000000000000000000000000000..d9b107b922241e12f4ba636042e62134c20a04d1
--- /dev/null
+++ b/content/public/browser/web_contents_media_capture_id.cc
@@ -0,0 +1,112 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/public/browser/web_contents_media_capture_id.h"
+
+#include <tuple>
+
+#include "base/strings/string_number_conversions.h"
+#include "base/strings/string_piece.h"
+#include "base/strings/string_util.h"
+
+namespace content {
+const char kWebContentsCaptureScheme[] = "web-contents-media-stream://";
+static char kEnableThrottlingFlag[] = "?throttling=auto";
+
+bool WebContentsMediaCaptureId::operator<(
+ const WebContentsMediaCaptureId& other) const {
+ return std::tie(render_process_id, main_render_frame_id,
+ enable_auto_throttling) <
+ std::tie(other.render_process_id, other.main_render_frame_id,
+ other.enable_auto_throttling);
+}
+
+bool WebContentsMediaCaptureId::operator==(
+ const WebContentsMediaCaptureId& other) const {
+ return std::tie(render_process_id, main_render_frame_id,
+ enable_auto_throttling) ==
+ std::tie(other.render_process_id, other.main_render_frame_id,
+ other.enable_auto_throttling);
+}
+
+bool WebContentsMediaCaptureId::is_null() const {
+ return (render_process_id < 0) || (main_render_frame_id < 0);
+}
+
+std::string WebContentsMediaCaptureId::ToString() const {
+ std::string s = kWebContentsCaptureScheme;
+ s.append(base::Int64ToString(render_process_id));
+ s.append(":");
+ s.append(base::Int64ToString(main_render_frame_id));
+
+ if (enable_auto_throttling)
+ s.append(kEnableThrottlingFlag);
+
+ return s;
+}
+
+// static
+WebContentsMediaCaptureId WebContentsMediaCaptureId::Parse(
+ const std::string& str) {
+ int render_process_id;
+ int main_render_frame_id;
+ if (!ExtractTabCaptureTarget(str, &render_process_id, &main_render_frame_id))
+ return WebContentsMediaCaptureId();
+
+ return WebContentsMediaCaptureId(render_process_id, main_render_frame_id,
+ IsAutoThrottlingOptionSet(str));
+}
+
+// static
+bool WebContentsMediaCaptureId::IsWebContentsDeviceId(
+ const std::string& device_id) {
+ int ignored;
+ return ExtractTabCaptureTarget(device_id, &ignored, &ignored);
+}
+
+// static
+bool WebContentsMediaCaptureId::ExtractTabCaptureTarget(
+ const std::string& device_id_param,
+ int* render_process_id,
+ int* main_render_frame_id) {
+ const std::string device_scheme = kWebContentsCaptureScheme;
+ if (!base::StartsWith(device_id_param, device_scheme,
+ base::CompareCase::SENSITIVE))
+ return false;
+
+ const std::string device_id = device_id_param.substr(device_scheme.size());
+
+ const size_t sep_pos = device_id.find(':');
+ if (sep_pos == std::string::npos)
+ return false;
+
+ const base::StringPiece component1(device_id.data(), sep_pos);
+ size_t end_pos = device_id.find('?');
+ if (end_pos == std::string::npos)
+ end_pos = device_id.length();
+ const base::StringPiece component2(device_id.data() + sep_pos + 1,
+ end_pos - sep_pos - 1);
+
+ return (base::StringToInt(component1, render_process_id) &&
+ base::StringToInt(component2, main_render_frame_id));
+}
+
+// static
+bool WebContentsMediaCaptureId::IsAutoThrottlingOptionSet(
+ const std::string& device_id) {
+ if (!IsWebContentsDeviceId(device_id))
+ return false;
+
+ // Find the option part of the string and just do a naive string compare since
+ // there are no other options in the |device_id| to account for (at the time
+ // of this writing).
+ const size_t option_pos = device_id.find('?');
+ if (option_pos == std::string::npos)
+ return false;
+ const base::StringPiece component(device_id.data() + option_pos,
+ device_id.length() - option_pos);
+ return component.compare(kEnableThrottlingFlag) == 0;
+}
+
+} // namespace content
« no previous file with comments | « content/public/browser/web_contents_media_capture_id.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698