Get value from command line switches

164 views
Skip to first unread message

R R

unread,
Apr 1, 2021, 3:45:09 PM4/1/21
to Chromium-dev
Hello everyone,
continuing to study the chromium code, I became interested in the ability to pass arguments from the command line to the browser
In my example, I would like to replace the address value in WebRTС candidate

in file
third_party > blink > renderer > modules > peerconnection > rtc_ice_candidate.cc
i found the function
String RTCIceCandidate::candidate() const { platform_candidate_->Candidate(); }

and tried to replace it with the value I needed
String RTCIceCandidate::candidate() const {
  String _rqs = platform_candidate_->Address();
  String _FakeAddress = "0.0.0.0";
  if(base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kFakeWebRTC)){
    _FakeAddress = base::CommandLine::GetSwitchValueASCII('fake-webrtc')
  }
  String copyq = platform_candidate_->Candidate();
  return copyq.Replace(_rqs,_FakeAddress);
}

I am also correct to create a new switch. Because in other files, the key is defined correctly.
But as a result I get my ip as 0.0.0.0
I think I am making a mistake when dealing with the base::CommandLine.

I did not find the information I needed, thanks.

Lei Zhang

unread,
Apr 1, 2021, 6:06:44 PM4/1/21
to saints...@gmail.com, Chromium-dev
The code in third_party/blink is most likely running in a renderer
process. The command line switches you passed in when you start the
browser goes to the browser process. The browser process has to make
sure your switch gets passed to the renderer. Try adding your switch
to the list in RenderProcessHostImpl::PropagateBrowserCommandLineToRenderer()
in content/browser/renderer_host/render_process_host_impl.cc.
> --
> --
> Chromium Developers mailing list: chromi...@chromium.org
> View archives, change email options, or unsubscribe:
> http://groups.google.com/a/chromium.org/group/chromium-dev
> ---
> You received this message because you are subscribed to the Google Groups "Chromium-dev" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to chromium-dev...@chromium.org.
> To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-dev/7b94c57f-6b56-46b2-ae08-787d786cdd4dn%40chromium.org.

R R

unread,
Apr 1, 2021, 8:16:25 PM4/1/21
to Chromium-dev, Lei Zhang, Chromium-dev, R R
Thank you so much!

пятница, 2 апреля 2021 г. в 03:06:44 UTC+5, Lei Zhang:
Reply all
Reply to author
Forward
0 new messages