Add blink::Platform methods needed by PeerConnectionDependencyFactory (1/2)

... when peer_connection_dependency_factory.cc|h gets Onion soup'ed.

Namely, the methods are:

- GetWebRTCMediaPermission()
- GetWebRTCRendererPreferences()

In order to test the code being added right away, the CL also
routes the callsite through the newly added methods.

The CL eliminates the needs for
PeerConnectionDependencyFactory::CreatePortAllocator(), to reference
RenderFrameImpl and RenderViewImpl directly.

In a follow up CL, further methods will be added to replace the remaining
references to base::CommandLine & switches.

BUG=787452
R=guidou@chromium.org, haraken@chromium.org

Change-Id: Ia897d304a21395c89fb032a4bfc80ec1a82ff858
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1799102
Commit-Queue: Antonio Gomes <tonikitoo@igalia.com>
Reviewed-by: Guido Urdaneta <guidou@chromium.org>
Reviewed-by: Kentaro Hara <haraken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#696097}
diff --git a/content/renderer/media/webrtc/peer_connection_dependency_factory.cc b/content/renderer/media/webrtc/peer_connection_dependency_factory.cc
index 214e60f..a1cf14f 100644
--- a/content/renderer/media/webrtc/peer_connection_dependency_factory.cc
+++ b/content/renderer/media/webrtc/peer_connection_dependency_factory.cc
@@ -16,7 +16,6 @@
 #include "base/location.h"
 #include "base/logging.h"
 #include "base/macros.h"
-#include "base/metrics/field_trial.h"
 #include "base/strings/string_util.h"
 #include "base/strings/utf_string_conversions.h"
 #include "base/synchronization/waitable_event.h"
@@ -29,9 +28,7 @@
 #include "content/renderer/p2p/mdns_responder_adapter.h"
 #include "content/renderer/p2p/port_allocator.h"
 #include "content/renderer/p2p/socket_dispatcher.h"
-#include "content/renderer/render_frame_impl.h"
 #include "content/renderer/render_thread_impl.h"
-#include "content/renderer/render_view_impl.h"
 #include "crypto/openssl_util.h"
 #include "jingle/glue/thread_wrapper.h"
 #include "media/base/media_permission.h"
@@ -43,7 +40,6 @@
 #include "third_party/blink/public/platform/modules/p2p/filtering_network_manager.h"
 #include "third_party/blink/public/platform/modules/p2p/ipc_network_manager.h"
 #include "third_party/blink/public/platform/modules/peerconnection/audio_codec_factory.h"
-#include "third_party/blink/public/platform/modules/peerconnection/stun_field_trial.h"
 #include "third_party/blink/public/platform/modules/peerconnection/video_codec_factory.h"
 #include "third_party/blink/public/platform/modules/webrtc/webrtc_logging.h"
 #include "third_party/blink/public/platform/platform.h"
@@ -402,65 +398,46 @@
     VLOG(3) << "WebRTC routing preferences will not be enforced";
   } else {
     if (web_frame && web_frame->View()) {
-      RenderViewImpl* renderer_view_impl =
-          RenderViewImpl::FromWebView(web_frame->View());
-      if (renderer_view_impl) {
-        // TODO(guoweis): |enable_multiple_routes| should be renamed to
-        // |request_multiple_routes|. Whether local IP addresses could be
-        // collected depends on if mic/camera permission is granted for this
-        // origin.
-        WebRTCIPHandlingPolicy policy =
-            GetWebRTCIPHandlingPolicy(renderer_view_impl->renderer_preferences()
-                                          .webrtc_ip_handling_policy);
-        switch (policy) {
-          // TODO(guoweis): specify the flag of disabling local candidate
-          // collection when webrtc is updated.
-          case DEFAULT_PUBLIC_INTERFACE_ONLY:
-          case DEFAULT_PUBLIC_AND_PRIVATE_INTERFACES:
-            port_config.enable_multiple_routes = false;
-            port_config.enable_nonproxied_udp = true;
-            port_config.enable_default_local_candidate =
-                (policy == DEFAULT_PUBLIC_AND_PRIVATE_INTERFACES);
-            break;
-          case DISABLE_NON_PROXIED_UDP:
-            port_config.enable_multiple_routes = false;
-            port_config.enable_nonproxied_udp = false;
-            break;
-          case DEFAULT:
-            port_config.enable_multiple_routes = true;
-            port_config.enable_nonproxied_udp = true;
-            break;
-        }
+      blink::WebString webrtc_ip_handling_policy;
+      blink::Platform::Current()->GetWebRTCRendererPreferences(
+          web_frame, &webrtc_ip_handling_policy, &min_port, &max_port);
 
-        min_port =
-            renderer_view_impl->renderer_preferences().webrtc_udp_min_port;
-        max_port =
-            renderer_view_impl->renderer_preferences().webrtc_udp_max_port;
-
-        VLOG(3) << "WebRTC routing preferences: "
-                << "policy: " << policy
-                << ", multiple_routes: " << port_config.enable_multiple_routes
-                << ", nonproxied_udp: " << port_config.enable_nonproxied_udp
-                << ", min_udp_port: " << min_port
-                << ", max_udp_port: " << max_port;
+      // TODO(guoweis): |enable_multiple_routes| should be renamed to
+      // |request_multiple_routes|. Whether local IP addresses could be
+      // collected depends on if mic/camera permission is granted for this
+      // origin.
+      WebRTCIPHandlingPolicy policy =
+          GetWebRTCIPHandlingPolicy(webrtc_ip_handling_policy.Utf8());
+      switch (policy) {
+        // TODO(guoweis): specify the flag of disabling local candidate
+        // collection when webrtc is updated.
+        case DEFAULT_PUBLIC_INTERFACE_ONLY:
+        case DEFAULT_PUBLIC_AND_PRIVATE_INTERFACES:
+          port_config.enable_multiple_routes = false;
+          port_config.enable_nonproxied_udp = true;
+          port_config.enable_default_local_candidate =
+              (policy == DEFAULT_PUBLIC_AND_PRIVATE_INTERFACES);
+          break;
+        case DISABLE_NON_PROXIED_UDP:
+          port_config.enable_multiple_routes = false;
+          port_config.enable_nonproxied_udp = false;
+          break;
+        case DEFAULT:
+          port_config.enable_multiple_routes = true;
+          port_config.enable_nonproxied_udp = true;
+          break;
       }
+
+      VLOG(3) << "WebRTC routing preferences: "
+              << "policy: " << policy
+              << ", multiple_routes: " << port_config.enable_multiple_routes
+              << ", nonproxied_udp: " << port_config.enable_nonproxied_udp
+              << ", min_udp_port: " << min_port
+              << ", max_udp_port: " << max_port;
     }
     if (port_config.enable_multiple_routes) {
-      bool create_media_permission =
-          base::CommandLine::ForCurrentProcess()->HasSwitch(
-              switches::kEnforceWebRtcIPPermissionCheck);
-      create_media_permission =
-          create_media_permission ||
-          !StartsWith(base::FieldTrialList::FindFullName(
-                          "WebRTC-LocalIPPermissionCheck"),
-                      "Disabled", base::CompareCase::SENSITIVE);
-      if (create_media_permission) {
-        content::RenderFrameImpl* render_frame =
-            content::RenderFrameImpl::FromWebFrame(web_frame);
-        if (render_frame)
-          media_permission = render_frame->GetMediaPermission();
-        DCHECK(media_permission);
-      }
+      media_permission =
+          blink::Platform::Current()->GetWebRTCMediaPermission(web_frame);
     }
   }
 
diff --git a/content/renderer/renderer_blink_platform_impl.cc b/content/renderer/renderer_blink_platform_impl.cc
index 6f84ef0..341413b 100644
--- a/content/renderer/renderer_blink_platform_impl.cc
+++ b/content/renderer/renderer_blink_platform_impl.cc
@@ -51,6 +51,7 @@
 #include "content/renderer/media/webrtc/peer_connection_tracker.h"
 #include "content/renderer/media/webrtc/rtc_peer_connection_handler.h"
 #include "content/renderer/p2p/port_allocator.h"
+#include "content/renderer/render_frame_impl.h"
 #include "content/renderer/render_thread_impl.h"
 #include "content/renderer/storage_util.h"
 #include "content/renderer/webgraphicscontext3d_provider_impl.h"
@@ -61,6 +62,7 @@
 #include "gpu/config/gpu_info.h"
 #include "gpu/ipc/client/gpu_channel_host.h"
 #include "media/audio/audio_output_device.h"
+#include "media/base/media_permission.h"
 #include "media/base/media_switches.h"
 #include "media/blink/webcontentdecryptionmodule_impl.h"
 #include "media/filters/stream_parser_factory.h"
@@ -687,6 +689,46 @@
       ->WebRTCPlatformSpecificAudioProcessingConfiguration();
 }
 
+media::MediaPermission* RendererBlinkPlatformImpl::GetWebRTCMediaPermission(
+    blink::WebLocalFrame* web_frame) {
+  media::MediaPermission* media_permission = nullptr;
+  bool create_media_permission =
+      base::CommandLine::ForCurrentProcess()->HasSwitch(
+          switches::kEnforceWebRtcIPPermissionCheck);
+  create_media_permission =
+      create_media_permission ||
+      !StartsWith(
+          base::FieldTrialList::FindFullName("WebRTC-LocalIPPermissionCheck"),
+          "Disabled", base::CompareCase::SENSITIVE);
+  if (create_media_permission) {
+    RenderFrameImpl* render_frame = RenderFrameImpl::FromWebFrame(web_frame);
+    if (render_frame)
+      media_permission = render_frame->GetMediaPermission();
+    DCHECK(media_permission);
+  }
+
+  return media_permission;
+}
+
+void RendererBlinkPlatformImpl::GetWebRTCRendererPreferences(
+    blink::WebLocalFrame* web_frame,
+    blink::WebString* ip_handling_policy,
+    uint16_t* udp_min_port,
+    uint16_t* udp_max_port) {
+  DCHECK(ip_handling_policy);
+  DCHECK(udp_min_port);
+  DCHECK(udp_max_port);
+
+  auto* render_frame = RenderFrameImpl::FromWebFrame(web_frame);
+  if (!render_frame)
+    return;
+
+  *ip_handling_policy = blink::WebString::FromUTF8(
+      render_frame->GetRendererPreferences().webrtc_ip_handling_policy);
+  *udp_min_port = render_frame->GetRendererPreferences().webrtc_udp_min_port;
+  *udp_max_port = render_frame->GetRendererPreferences().webrtc_udp_max_port;
+}
+
 base::Optional<int> RendererBlinkPlatformImpl::GetAgcStartupMinimumVolume() {
   std::string min_volume_str =
       base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
diff --git a/content/renderer/renderer_blink_platform_impl.h b/content/renderer/renderer_blink_platform_impl.h
index 130d123..9f133b7 100644
--- a/content/renderer/renderer_blink_platform_impl.h
+++ b/content/renderer/renderer_blink_platform_impl.h
@@ -154,6 +154,12 @@
       blink::WebAudioDeviceSourceType source_type) override;
   blink::WebRtcAudioDeviceImpl* GetWebRtcAudioDevice() override;
   base::Optional<std::string> GetWebRTCAudioProcessingConfiguration() override;
+  media::MediaPermission* GetWebRTCMediaPermission(
+      blink::WebLocalFrame* web_frame) override;
+  void GetWebRTCRendererPreferences(blink::WebLocalFrame* web_frame,
+                                    blink::WebString* ip_handling_policy,
+                                    uint16_t* udp_min_port,
+                                    uint16_t* udp_max_port) override;
   base::Optional<int> GetAgcStartupMinimumVolume() override;
   void TrackGetUserMedia(
       const blink::WebUserMediaRequest& web_request) override;
diff --git a/third_party/blink/public/platform/platform.h b/third_party/blink/public/platform/platform.h
index 1a08bba..d93c5114 100644
--- a/third_party/blink/public/platform/platform.h
+++ b/third_party/blink/public/platform/platform.h
@@ -84,6 +84,7 @@
 namespace media {
 struct AudioSinkParameters;
 struct AudioSourceParameters;
+class MediaPermission;
 class GpuVideoAcceleratorFactories;
 }
 
@@ -640,6 +641,16 @@
     return base::nullopt;
   }
 
+  virtual media::MediaPermission* GetWebRTCMediaPermission(
+      WebLocalFrame* web_frame) {
+    return nullptr;
+  }
+
+  virtual void GetWebRTCRendererPreferences(WebLocalFrame* web_frame,
+                                            WebString* ip_handling_policy,
+                                            uint16_t* udp_min_port,
+                                            uint16_t* udp_max_port) {}
+
   virtual base::Optional<int> GetAgcStartupMinimumVolume() {
     return base::nullopt;
   }