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

Unified Diff: content/public/browser/web_contents_media_capture_id.cc

Issue 2291893002: Let Contraints Controll Mute/Unmute Audio Local Playback For Desktop Sharing (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 4 years, 2 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
index d9b107b922241e12f4ba636042e62134c20a04d1..2835818bc44e0c884fbc9186e61e287cc2f4ff38 100644
--- a/content/public/browser/web_contents_media_capture_id.cc
+++ b/content/public/browser/web_contents_media_capture_id.cc
@@ -10,24 +10,92 @@
#include "base/strings/string_piece.h"
#include "base/strings/string_util.h"
+namespace {
+constexpr char kWebContentsCaptureScheme[] = "web-contents-media-stream://";
+constexpr char kEnableThrottlingFlag[] = "throttling=auto";
+constexpr char kDisableLocalEchoFlag[] = "local_echo=false";
+constexpr char kOptionStart = '?';
+constexpr char kOptionSeparator = '&';
+
+bool 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));
+}
+
+bool ExtractOptions(const std::string& device_id,
+ bool* auto_throttling,
+ bool* disable_local_echo) {
+ DCHECK(auto_throttling);
+ DCHECK(disable_local_echo);
+
+ *auto_throttling = false;
+ *disable_local_echo = 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).
+ size_t option_pos = device_id.find(kOptionStart);
+ if (option_pos == std::string::npos)
+ return true;
+
+ size_t option_pos_end;
+ while (option_pos < device_id.length()) {
+ option_pos_end = device_id.find(kOptionSeparator, option_pos + 1);
+ if (option_pos_end == std::string::npos)
+ option_pos_end = device_id.length();
+ const base::StringPiece component(device_id.data() + option_pos + 1,
+ option_pos_end - option_pos - 1);
+
+ if (component.compare(kEnableThrottlingFlag) == 0)
+ *auto_throttling = true;
+ else if (component.compare(kDisableLocalEchoFlag) == 0)
+ *disable_local_echo = true;
+ else // Some unknown parameter is specified, and thus this ID is invalid.
+ return false;
+
+ option_pos = option_pos_end;
+ }
+ return true;
+}
+
+} // namespace
+
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) <
+ enable_auto_throttling, disable_local_echo) <
std::tie(other.render_process_id, other.main_render_frame_id,
- other.enable_auto_throttling);
+ other.enable_auto_throttling, other.disable_local_echo);
}
bool WebContentsMediaCaptureId::operator==(
const WebContentsMediaCaptureId& other) const {
return std::tie(render_process_id, main_render_frame_id,
- enable_auto_throttling) ==
+ enable_auto_throttling, disable_local_echo) ==
std::tie(other.render_process_id, other.main_render_frame_id,
- other.enable_auto_throttling);
+ other.enable_auto_throttling, other.disable_local_echo);
}
bool WebContentsMediaCaptureId::is_null() const {
@@ -40,73 +108,43 @@ std::string WebContentsMediaCaptureId::ToString() const {
s.append(":");
s.append(base::Int64ToString(main_render_frame_id));
- if (enable_auto_throttling)
+ char connector = kOptionStart;
+ if (enable_auto_throttling) {
+ s += connector;
s.append(kEnableThrottlingFlag);
+ connector = kOptionSeparator;
+ }
+
+ if (disable_local_echo) {
+ s += connector;
+ s.append(kDisableLocalEchoFlag);
+ connector = kOptionSeparator;
+ }
return s;
}
// static
-WebContentsMediaCaptureId WebContentsMediaCaptureId::Parse(
- const std::string& str) {
+bool WebContentsMediaCaptureId::Parse(const std::string& str,
+ WebContentsMediaCaptureId* output_id) {
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)
+ bool auto_throttling, disable_local_echo;
+ if (!ExtractOptions(str, &auto_throttling, &disable_local_echo))
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);
+ if (output_id) {
+ output_id->render_process_id = render_process_id;
+ output_id->main_render_frame_id = main_render_frame_id;
+ output_id->enable_auto_throttling = auto_throttling;
+ output_id->disable_local_echo = disable_local_echo;
+ }
- return (base::StringToInt(component1, render_process_id) &&
- base::StringToInt(component2, main_render_frame_id));
+ return true;
}
-// 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') | content/public/common/media_stream_request.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698