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

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
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..6cbea92374f7030d43439152158e8d2da0a9cd6e
--- /dev/null
+++ b/content/public/browser/web_contents_media_capture_id.cc
@@ -0,0 +1,110 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
Avi (use Gerrit) 2016/01/08 17:11:39 No (c), and it's 2016.
GeorgeZ 2016/01/08 19:39:03 Done.
+// 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 kEnableFlag[] = "?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("://");
+ s.append(base::Int64ToString(render_process_id));
+ s.append(":");
+ s.append(base::Int64ToString(main_render_frame_id));
+
+ if (enable_auto_throttling)
+ s.append(kEnableFlag);
+
+ return s;
+}
+
+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));
+}
+
+bool WebContentsMediaCaptureId::IsWebContentsDeviceId(
+ const std::string& device_id) {
+ int ignored;
+ return ExtractTabCaptureTarget(device_id, &ignored, &ignored);
+}
+
+bool WebContentsMediaCaptureId::ExtractTabCaptureTarget(
+ const std::string& device_id_param,
+ int* render_process_id,
+ int* main_render_frame_id) {
+ const std::string device_scheme =
+ std::string(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() - 1);
+
+ 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));
+}
+
+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(kEnableFlag) == 0;
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698