Skip to content

Add WebRTCIPPolicy setting to webContents - #8866

Merged
kevinsawicki merged 5 commits into
electron:masterfrom
jkleinsc:master
Mar 9, 2017
Merged

kevinsawicki merged 5 commits into
electron:masterfrom
jkleinsc:master

Conversation

@jkleinsc

@jkleinsc jkleinsc commented Mar 8, 2017 •

Copy link
Copy Markdown
Member

Resolves #8777

The WebRTC IP Handling Policy can now be set on webContents via the setWebRTCIPHandlingPolicy method. The following values are supported:

  • default - Exposes user's public and local IPs. This is the default behavior if not specified.
  • default_public_interface_only - Exposes user's public IP, but does not expose user's local IP.
  • default_public_and_private_interfaces - Exposes user's public and local IPs.
  • disable_non_proxied_udp - Does not expose public or local IPs.

Code to set and get the policy on webContents come from the Muon framework code:
https://github.com/brave/muon/blob/master/atom/browser/api/atom_api_web_
contents.cc#L1324...L1343

Here is a screenshot of a sample Electron app setting the WebRTCIPPolicy to disable_non_proxied_udp

screen shot 2017-03-08 at 10 20 56 am

@kevinsawicki

Copy link
Copy Markdown
Contributor

@jkleinsc thanks for adding this.

I'm wondering though if we really need the new <webview> attribute or that could just be set directly on the webContents.

Adding <webview> attributes for each new webContents API is a lot to maintain and since it is available on the webContents it can be accessed in a dom-ready event on the webview or via the web-contents-created event on app.

Would you be okay just setting it via one of those methods instead?

@kevinsawicki kevinsawicki self-assigned this Mar 8, 2017
@jkleinsc

jkleinsc commented Mar 8, 2017

Copy link
Copy Markdown
Member Author

@kevinsawicki I'm fine with it just being set on webContents. Adding it to <webview> was kind of a freebie and a way of giving multiple ways to do the same thing, but I understand not wanting to pollute the <webview> attributes.

I can update the PR to not include the <webview> changes. It is always fun to delete code! 🔥

@jkleinsc jkleinsc changed the title Add WebRTCIPPolicy setting to webContents and webview Add WebRTCIPPolicy setting to webContents Mar 8, 2017
@jkleinsc

jkleinsc commented Mar 8, 2017

Copy link
Copy Markdown
Member Author

@kevinsawicki PR has been updated to not include the <webview> changes. Let me know if you need anything else.

@kevinsawicki

Copy link
Copy Markdown
Contributor

PR has been updated to not include the changes. Let me know if you need anything else.

Awesome, thanks, would you also mind adding a small spec to spec/api-web-contents-spec.js that verifies the getter and setter with a few different values?

void GoForward();
void GoToOffset(int offset);
const std::string& GetWebRTCIPHandlingPolicy() const;
void SetWebRTCIPHandlingPolicy(const std::string webrtc_ip_handling_policy);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should take a reference:

void SetWebRTCIPHandlingPolicy(const std::string& webrtc_ip_handling_policy);

void GoBack();
void GoForward();
void GoToOffset(int offset);
const std::string& GetWebRTCIPHandlingPolicy() const;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like our other getter APIs like GetUserAgent and GetTitle don't return references so I think it is fine to just return a std::string here for consistency.

@jkleinsc

jkleinsc commented Mar 9, 2017

Copy link
Copy Markdown
Member Author

@kevinsawicki thanks for the feedback. I updated the reference issues and added the spec. Let me know if you have any further feedback.

Comment thread docs/api/web-contents.md Outdated
* `default` - Exposes user's public and local IPs. This is the default behavior if not specified.
* `default_public_interface_only` - Exposes user's public IP, but does not expose user's local IP.
* `default_public_and_private_interfaces` - Exposes user's public and local IPs.
* `disable_non_proxied_udp` - Does not expose public or local IPs.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I'll update the PR.

@jkleinsc

jkleinsc commented Mar 9, 2017

Copy link
Copy Markdown
Member Author

Docs have been updated.

@kevinsawicki

Copy link
Copy Markdown
Contributor

Thanks for this @jkleinsc, great to support this in Electron 👍 🔒 📶

@kevinsawicki
kevinsawicki merged commit 783b5e8 into electron:master Mar 9, 2017
@Binom777

Binom777 commented May 6, 2017

Copy link
Copy Markdown

OS: Linux mint 18.1 KDE Edition (64)
Electron: v1.6.6

crash when you use the code

const electron = require('electron');
const app = electron.app;
const BrowserWindow = electron.BrowserWindow;
let mainWindow;

function createWindow (  ) {
    mainWindow = new BrowserWindow({ width: 1024,  height: 768, });
    mainWindow.webContents.setWebRTCIPHandlingPolicy('disable_non_proxied_udp')
    mainWindow.loadURL("https://whoer.net/")


    mainWindow.on('closed', function() {
        mainWindow = null;
    });
}

app.on('ready', createWindow);
app.on('window-all-closed', function () {
    if (process.platform !== 'darwin') {
        app.quit()
    }
});

bg3

@kevinsawicki

Copy link
Copy Markdown
Contributor

@Binom777 Having trouble reproducing with your app, it successfully loads for me, can you double check you are using Electron 1.6.4 or above?

@Binom777

Copy link
Copy Markdown

@kevinsawicki I apologize, this is my inattention.

buge163

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants