1 /*
   2  * Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
   3  */
   4 #include "config.h"
   5 #include "ResourceRequest.h"
   6 
   7 #include <wtf/java/JavaEnv.h>
   8 
   9 namespace ResourceRequestJavaInternal {
  10 
  11 static JGClass networkContextClass;
  12 static jmethodID getMaximumHTTPConnectionCountPerHostMethod;
  13 
  14 static void initRefs(JNIEnv* env)
  15 {
  16     if (!networkContextClass) {
  17         networkContextClass = JLClass(env->FindClass(
  18                 "com/sun/webkit/network/NetworkContext"));
  19         ASSERT(networkContextClass);
  20 
  21         getMaximumHTTPConnectionCountPerHostMethod = env->GetStaticMethodID(
  22                 networkContextClass,
  23                 "fwkGetMaximumHTTPConnectionCountPerHost",
  24                 "()I");
  25         ASSERT(getMaximumHTTPConnectionCountPerHostMethod);
  26     }
  27 }
  28 }
  29 
  30 namespace WebCore {
  31 
  32 unsigned initializeMaximumHTTPConnectionCountPerHost()
  33 {
  34     using namespace ResourceRequestJavaInternal;
  35     // This is used by the loader to control the number of parallel load
  36     // requests. Our java framework employs HttpURLConnection for all
  37     // HTTP exchanges, so we delegate this call to java to return
  38     // the value of the "http.maxConnections" system property.
  39     JNIEnv* env = WebCore_GetJavaEnv();
  40     initRefs(env);
  41 
  42     jint result = env->CallStaticIntMethod(
  43             networkContextClass,
  44             getMaximumHTTPConnectionCountPerHostMethod);
  45     CheckAndClearException(env);
  46 
  47     ASSERT(result >= 0);
  48     return result;
  49 }
  50 
  51 } // namespace WebCore