Exposed setOptions via RTCPeerConnectionFactory

Exposed setOptions API for iOS SDK via RTCPeerConnectionFactory method
to provide ability to disable encryption and control which network
adapters are ignored.
Only subset of webrtc::PeerConnectionFactoryInterface::Options options
are exposed via iOS SDK, additional options can be exposed as requested.
Android SDK has already exposed setOption API via Java's PeerConnection
constructor, there changes provide similar functionaly to iOS SDK.

Bug: webrtc:8712
Change-Id: Ia2de38cf382afc1bad9bbec6c6eac21ad29aee89
Reviewed-on: https://webrtc-review.googlesource.com/34900
Commit-Queue: Taylor Brandstetter <deadbeef@webrtc.org>
Reviewed-by: Taylor Brandstetter <deadbeef@webrtc.org>
Reviewed-by: Magnus Jedvert <magjed@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#21504}
diff --git a/sdk/BUILD.gn b/sdk/BUILD.gn
index 95ba756..60dbe05 100644
--- a/sdk/BUILD.gn
+++ b/sdk/BUILD.gn
@@ -431,6 +431,8 @@
         "objc/Framework/Classes/PeerConnection/RTCPeerConnection+Private.h",
         "objc/Framework/Classes/PeerConnection/RTCPeerConnection+Stats.mm",
         "objc/Framework/Classes/PeerConnection/RTCPeerConnection.mm",
+        "objc/Framework/Classes/PeerConnection/RTCPeerConnectionFactoryOptions+Private.h",
+        "objc/Framework/Classes/PeerConnection/RTCPeerConnectionFactoryOptions.mm",
         "objc/Framework/Classes/PeerConnection/RTCRtpCodecParameters+Private.h",
         "objc/Framework/Classes/PeerConnection/RTCRtpCodecParameters.mm",
         "objc/Framework/Classes/PeerConnection/RTCRtpEncodingParameters+Private.h",
@@ -481,6 +483,7 @@
         "objc/Framework/Headers/WebRTC/RTCMetricsSampleInfo.h",
         "objc/Framework/Headers/WebRTC/RTCPeerConnection.h",
         "objc/Framework/Headers/WebRTC/RTCPeerConnectionFactory.h",
+        "objc/Framework/Headers/WebRTC/RTCPeerConnectionFactoryOptions.h",
         "objc/Framework/Headers/WebRTC/RTCRtpCodecParameters.h",
         "objc/Framework/Headers/WebRTC/RTCRtpEncodingParameters.h",
         "objc/Framework/Headers/WebRTC/RTCRtpParameters.h",
@@ -687,6 +690,7 @@
           "objc/Framework/Headers/WebRTC/RTCMetricsSampleInfo.h",
           "objc/Framework/Headers/WebRTC/RTCPeerConnection.h",
           "objc/Framework/Headers/WebRTC/RTCPeerConnectionFactory.h",
+          "objc/Framework/Headers/WebRTC/RTCPeerConnectionFactoryOptions.h",
           "objc/Framework/Headers/WebRTC/RTCRtpCodecParameters.h",
           "objc/Framework/Headers/WebRTC/RTCRtpEncodingParameters.h",
           "objc/Framework/Headers/WebRTC/RTCRtpParameters.h",
diff --git a/sdk/objc/Framework/Classes/PeerConnection/RTCPeerConnectionFactory.mm b/sdk/objc/Framework/Classes/PeerConnection/RTCPeerConnectionFactory.mm
index 7a102c4..31d5695 100644
--- a/sdk/objc/Framework/Classes/PeerConnection/RTCPeerConnectionFactory.mm
+++ b/sdk/objc/Framework/Classes/PeerConnection/RTCPeerConnectionFactory.mm
@@ -10,6 +10,7 @@
 
 #import "RTCPeerConnectionFactory+Native.h"
 #import "RTCPeerConnectionFactory+Private.h"
+#import "RTCPeerConnectionFactoryOptions+Private.h"
 
 #import "NSString+StdString.h"
 #import "RTCAVFoundationVideoSource+Private.h"
@@ -242,6 +243,11 @@
                                            delegate:delegate];
 }
 
+- (void)setOptions:(nonnull RTCPeerConnectionFactoryOptions *)options {
+  RTC_DCHECK(options != nil);
+  _nativeFactory->SetOptions(options.nativeOptions);
+}
+
 - (BOOL)startAecDumpWithFilePath:(NSString *)filePath
                   maxSizeInBytes:(int64_t)maxSizeInBytes {
   RTC_DCHECK(filePath.length);
diff --git a/sdk/objc/Framework/Classes/PeerConnection/RTCPeerConnectionFactoryOptions+Private.h b/sdk/objc/Framework/Classes/PeerConnection/RTCPeerConnectionFactoryOptions+Private.h
new file mode 100644
index 0000000..131e8ff
--- /dev/null
+++ b/sdk/objc/Framework/Classes/PeerConnection/RTCPeerConnectionFactoryOptions+Private.h
@@ -0,0 +1,26 @@
+/*
+ *  Copyright 2017 The WebRTC project authors. All Rights Reserved.
+ *
+ *  Use of this source code is governed by a BSD-style license
+ *  that can be found in the LICENSE file in the root of the source
+ *  tree. An additional intellectual property rights grant can be found
+ *  in the file PATENTS.  All contributing project authors may
+ *  be found in the AUTHORS file in the root of the source tree.
+ */
+
+#import "WebRTC/RTCPeerConnectionFactoryOptions.h"
+
+#include "api/peerconnectioninterface.h"
+
+NS_ASSUME_NONNULL_BEGIN
+
+@interface RTCPeerConnectionFactoryOptions ()
+
+/** Returns the equivalent native PeerConnectionFactoryInterface::Options
+ * structure. */
+@property(nonatomic, readonly)
+    webrtc::PeerConnectionFactoryInterface::Options nativeOptions;
+
+@end
+
+NS_ASSUME_NONNULL_END
diff --git a/sdk/objc/Framework/Classes/PeerConnection/RTCPeerConnectionFactoryOptions.mm b/sdk/objc/Framework/Classes/PeerConnection/RTCPeerConnectionFactoryOptions.mm
new file mode 100644
index 0000000..f0cc6a6
--- /dev/null
+++ b/sdk/objc/Framework/Classes/PeerConnection/RTCPeerConnectionFactoryOptions.mm
@@ -0,0 +1,56 @@
+/*
+ *  Copyright 2017 The WebRTC project authors. All Rights Reserved.
+ *
+ *  Use of this source code is governed by a BSD-style license
+ *  that can be found in the LICENSE file in the root of the source
+ *  tree. An additional intellectual property rights grant can be found
+ *  in the file PATENTS.  All contributing project authors may
+ *  be found in the AUTHORS file in the root of the source tree.
+ */
+
+#import "RTCPeerConnectionFactoryOptions+Private.h"
+
+#include "rtc_base/network_constants.h"
+
+namespace {
+
+void setNetworkBit(webrtc::PeerConnectionFactoryInterface::Options* options,
+                   rtc::AdapterType type,
+                   bool ignore) {
+  if (ignore) {
+    options->network_ignore_mask |= type;
+  } else {
+    options->network_ignore_mask &= ~type;
+  }
+}
+}  // namespace
+
+@implementation RTCPeerConnectionFactoryOptions
+
+@synthesize disableEncryption = _disableEncryption;
+@synthesize disableNetworkMonitor = _disableNetworkMonitor;
+@synthesize ignoreLoopbackNetworkAdapter = _ignoreLoopbackNetworkAdapter;
+@synthesize ignoreVPNNetworkAdapter = _ignoreVPNNetworkAdapter;
+@synthesize ignoreCellularNetworkAdapter = _ignoreCellularNetworkAdapter;
+@synthesize ignoreWiFiNetworkAdapter = _ignoreWiFiNetworkAdapter;
+@synthesize ignoreEthernetNetworkAdapter = _ignoreEthernetNetworkAdapter;
+
+- (instancetype)init {
+  return [super init];
+}
+
+- (webrtc::PeerConnectionFactoryInterface::Options)nativeOptions {
+  webrtc::PeerConnectionFactoryInterface::Options options;
+  options.disable_encryption = self.disableEncryption;
+  options.disable_network_monitor = self.disableNetworkMonitor;
+
+  setNetworkBit(&options, rtc::ADAPTER_TYPE_LOOPBACK, self.ignoreLoopbackNetworkAdapter);
+  setNetworkBit(&options, rtc::ADAPTER_TYPE_VPN, self.ignoreVPNNetworkAdapter);
+  setNetworkBit(&options, rtc::ADAPTER_TYPE_CELLULAR, self.ignoreCellularNetworkAdapter);
+  setNetworkBit(&options, rtc::ADAPTER_TYPE_WIFI, self.ignoreWiFiNetworkAdapter);
+  setNetworkBit(&options, rtc::ADAPTER_TYPE_ETHERNET, self.ignoreEthernetNetworkAdapter);
+
+  return options;
+}
+
+@end
diff --git a/sdk/objc/Framework/Headers/WebRTC/RTCPeerConnectionFactory.h b/sdk/objc/Framework/Headers/WebRTC/RTCPeerConnectionFactory.h
index 42acbfc..56c399e 100644
--- a/sdk/objc/Framework/Headers/WebRTC/RTCPeerConnectionFactory.h
+++ b/sdk/objc/Framework/Headers/WebRTC/RTCPeerConnectionFactory.h
@@ -23,6 +23,7 @@
 @class RTCPeerConnection;
 @class RTCVideoSource;
 @class RTCVideoTrack;
+@class RTCPeerConnectionFactoryOptions;
 @protocol RTCPeerConnectionDelegate;
 @protocol RTCVideoDecoderFactory;
 @protocol RTCVideoEncoderFactory;
@@ -75,6 +76,9 @@
                                               delegate:
     (nullable id<RTCPeerConnectionDelegate>)delegate;
 
+/** Set the options to be used for subsequently created RTCPeerConnections */
+- (void)setOptions:(nonnull RTCPeerConnectionFactoryOptions *)options;
+
 /** Start an AecDump recording. This API call will likely change in the future. */
 - (BOOL)startAecDumpWithFilePath:(NSString *)filePath
                   maxSizeInBytes:(int64_t)maxSizeInBytes;
diff --git a/sdk/objc/Framework/Headers/WebRTC/RTCPeerConnectionFactoryOptions.h b/sdk/objc/Framework/Headers/WebRTC/RTCPeerConnectionFactoryOptions.h
new file mode 100644
index 0000000..a65abc6
--- /dev/null
+++ b/sdk/objc/Framework/Headers/WebRTC/RTCPeerConnectionFactoryOptions.h
@@ -0,0 +1,38 @@
+/*
+ *  Copyright 2017 The WebRTC project authors. All Rights Reserved.
+ *
+ *  Use of this source code is governed by a BSD-style license
+ *  that can be found in the LICENSE file in the root of the source
+ *  tree. An additional intellectual property rights grant can be found
+ *  in the file PATENTS.  All contributing project authors may
+ *  be found in the AUTHORS file in the root of the source tree.
+ */
+
+#import <Foundation/Foundation.h>
+
+#import <WebRTC/RTCMacros.h>
+
+NS_ASSUME_NONNULL_BEGIN
+
+RTC_EXPORT
+@interface RTCPeerConnectionFactoryOptions : NSObject
+
+@property(nonatomic, assign) BOOL disableEncryption;
+
+@property(nonatomic, assign) BOOL disableNetworkMonitor;
+
+@property(nonatomic, assign) BOOL ignoreLoopbackNetworkAdapter;
+
+@property(nonatomic, assign) BOOL ignoreVPNNetworkAdapter;
+
+@property(nonatomic, assign) BOOL ignoreCellularNetworkAdapter;
+
+@property(nonatomic, assign) BOOL ignoreWiFiNetworkAdapter;
+
+@property(nonatomic, assign) BOOL ignoreEthernetNetworkAdapter;
+
+- (instancetype)init NS_DESIGNATED_INITIALIZER;
+
+@end
+
+NS_ASSUME_NONNULL_END
diff --git a/sdk/objc/Framework/Headers/WebRTC/WebRTC.h b/sdk/objc/Framework/Headers/WebRTC/WebRTC.h
index 64ca544..b9e0149 100644
--- a/sdk/objc/Framework/Headers/WebRTC/WebRTC.h
+++ b/sdk/objc/Framework/Headers/WebRTC/WebRTC.h
@@ -45,6 +45,7 @@
 #import <WebRTC/RTCMetricsSampleInfo.h>
 #import <WebRTC/RTCPeerConnection.h>
 #import <WebRTC/RTCPeerConnectionFactory.h>
+#import <WebRTC/RTCPeerConnectionFactoryOptions.h>
 #import <WebRTC/RTCRtpCodecParameters.h>
 #import <WebRTC/RTCRtpEncodingParameters.h>
 #import <WebRTC/RTCRtpParameters.h>