Changeset 218947 in webkit


Ignore:
Timestamp:
Jun 29, 2017 11:07:32 AM (7 years ago)
Author:
commit-queue@webkit.org
Message:

[Curl] Separate global curl settings from ResourceHandleManager as CurlContext class
https://bugs.webkit.org/show_bug.cgi?id=173629

Patch by Basuke Suzuki <Basuke Suzuki> on 2017-06-29
Reviewed by Alex Christensen.

  • PlatformWinCairo.cmake:
  • platform/network/curl/CookieJarCurl.cpp:

(WebCore::setCookiesFromDOM):
(WebCore::cookiesForSession):

  • platform/network/curl/CurlContext.cpp: Added.

(WebCore::certificatePath):
(WebCore::cookieJarPath):
(WebCore::CurlContext::CurlContext):
(WebCore::CurlContext::~CurlContext):
(WebCore::CurlContext::initCookieSession):
(WebCore::CurlContext::ProxyInfo::url):
(WebCore::CurlContext::setProxyInfo):
(WebCore::CurlContext::getEffectiveURL):
(WebCore::CurlContext::createMultiHandle):
(WebCore::CurlContext::mutexFor):
(WebCore::CurlContext::lock):
(WebCore::CurlContext::unlock):

  • platform/network/curl/CurlContext.h: Added.

(WebCore::CurlContext::singleton):
(WebCore::CurlContext::curlShareHandle):
(WebCore::CurlContext::getCookieJarFileName):
(WebCore::CurlContext::setCookieJarFileName):
(WebCore::CurlContext::getCertificatePath):
(WebCore::CurlContext::shouldIgnoreSSLErrors):
(WebCore::CurlContext::proxyInfo):
(WebCore::CurlContext::setProxyInfo):
(WebCore::CurlContext::getLogFile):
(WebCore::CurlContext::isVerbose):

  • platform/network/curl/CurlDownload.cpp:

(WebCore::CurlDownload::init):
(WebCore::CurlDownload::start):
(WebCore::CurlDownload::cancel):
(WebCore::CurlDownload::didReceiveHeader):

  • platform/network/curl/CurlDownload.h:
  • platform/network/curl/CurlJobManager.cpp: Renamed from Source/WebCore/platform/network/curl/CurlManager.cpp.

(WebCore::CurlJobManager::CurlJobManager):
(WebCore::CurlJobManager::~CurlJobManager):
(WebCore::CurlJobManager::add):
(WebCore::CurlJobManager::remove):
(WebCore::CurlJobManager::getActiveCount):
(WebCore::CurlJobManager::getPendingCount):
(WebCore::CurlJobManager::startThreadIfNeeded):
(WebCore::CurlJobManager::stopThread):
(WebCore::CurlJobManager::stopThreadIfIdle):
(WebCore::CurlJobManager::updateHandleList):
(WebCore::CurlJobManager::addToCurl):
(WebCore::CurlJobManager::removeFromCurl):
(WebCore::CurlJobManager::workerThread):

  • platform/network/curl/CurlJobManager.h: Renamed from Source/WebCore/platform/network/curl/CurlManager.h.

(WebCore::CurlJobManager::singleton):

  • platform/network/curl/ResourceHandleManager.cpp:

(WebCore::ResourceHandleManager::ResourceHandleManager):
(WebCore::ResourceHandleManager::~ResourceHandleManager):
(WebCore::handleLocalReceiveResponse):
(WebCore::getProtectionSpace):
(WebCore::headerCallback):
(WebCore::ResourceHandleManager::downloadTimerCallback):
(WebCore::ResourceHandleManager::initializeHandle):
(WebCore::certificatePath): Deleted.
(WebCore::cookieJarPath): Deleted.
(WebCore::ResourceHandleManager::setCookieJarFileName): Deleted.
(WebCore::ResourceHandleManager::getCookieJarFileName): Deleted.
(WebCore::ResourceHandleManager::setProxyInfo): Deleted.
(WebCore::ResourceHandleManager::initCookieSession): Deleted.

  • platform/network/curl/ResourceHandleManager.h:

(): Deleted.

Location:
trunk/Source/WebCore
Files:
2 added
7 edited
2 moved

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r218944 r218947  
     12017-06-29  Basuke Suzuki  <Basuke.Suzuki@sony.com>
     2
     3        [Curl] Separate global curl settings from ResourceHandleManager as CurlContext class
     4        https://bugs.webkit.org/show_bug.cgi?id=173629
     5
     6        Reviewed by Alex Christensen.
     7
     8        * PlatformWinCairo.cmake:
     9        * platform/network/curl/CookieJarCurl.cpp:
     10        (WebCore::setCookiesFromDOM):
     11        (WebCore::cookiesForSession):
     12        * platform/network/curl/CurlContext.cpp: Added.
     13        (WebCore::certificatePath):
     14        (WebCore::cookieJarPath):
     15        (WebCore::CurlContext::CurlContext):
     16        (WebCore::CurlContext::~CurlContext):
     17        (WebCore::CurlContext::initCookieSession):
     18        (WebCore::CurlContext::ProxyInfo::url):
     19        (WebCore::CurlContext::setProxyInfo):
     20        (WebCore::CurlContext::getEffectiveURL):
     21        (WebCore::CurlContext::createMultiHandle):
     22        (WebCore::CurlContext::mutexFor):
     23        (WebCore::CurlContext::lock):
     24        (WebCore::CurlContext::unlock):
     25        * platform/network/curl/CurlContext.h: Added.
     26        (WebCore::CurlContext::singleton):
     27        (WebCore::CurlContext::curlShareHandle):
     28        (WebCore::CurlContext::getCookieJarFileName):
     29        (WebCore::CurlContext::setCookieJarFileName):
     30        (WebCore::CurlContext::getCertificatePath):
     31        (WebCore::CurlContext::shouldIgnoreSSLErrors):
     32        (WebCore::CurlContext::proxyInfo):
     33        (WebCore::CurlContext::setProxyInfo):
     34        (WebCore::CurlContext::getLogFile):
     35        (WebCore::CurlContext::isVerbose):
     36        * platform/network/curl/CurlDownload.cpp:
     37        (WebCore::CurlDownload::init):
     38        (WebCore::CurlDownload::start):
     39        (WebCore::CurlDownload::cancel):
     40        (WebCore::CurlDownload::didReceiveHeader):
     41        * platform/network/curl/CurlDownload.h:
     42        * platform/network/curl/CurlJobManager.cpp: Renamed from Source/WebCore/platform/network/curl/CurlManager.cpp.
     43        (WebCore::CurlJobManager::CurlJobManager):
     44        (WebCore::CurlJobManager::~CurlJobManager):
     45        (WebCore::CurlJobManager::add):
     46        (WebCore::CurlJobManager::remove):
     47        (WebCore::CurlJobManager::getActiveCount):
     48        (WebCore::CurlJobManager::getPendingCount):
     49        (WebCore::CurlJobManager::startThreadIfNeeded):
     50        (WebCore::CurlJobManager::stopThread):
     51        (WebCore::CurlJobManager::stopThreadIfIdle):
     52        (WebCore::CurlJobManager::updateHandleList):
     53        (WebCore::CurlJobManager::addToCurl):
     54        (WebCore::CurlJobManager::removeFromCurl):
     55        (WebCore::CurlJobManager::workerThread):
     56        * platform/network/curl/CurlJobManager.h: Renamed from Source/WebCore/platform/network/curl/CurlManager.h.
     57        (WebCore::CurlJobManager::singleton):
     58        * platform/network/curl/ResourceHandleManager.cpp:
     59        (WebCore::ResourceHandleManager::ResourceHandleManager):
     60        (WebCore::ResourceHandleManager::~ResourceHandleManager):
     61        (WebCore::handleLocalReceiveResponse):
     62        (WebCore::getProtectionSpace):
     63        (WebCore::headerCallback):
     64        (WebCore::ResourceHandleManager::downloadTimerCallback):
     65        (WebCore::ResourceHandleManager::initializeHandle):
     66        (WebCore::certificatePath): Deleted.
     67        (WebCore::cookieJarPath): Deleted.
     68        (WebCore::ResourceHandleManager::setCookieJarFileName): Deleted.
     69        (WebCore::ResourceHandleManager::getCookieJarFileName): Deleted.
     70        (WebCore::ResourceHandleManager::setProxyInfo): Deleted.
     71        (WebCore::ResourceHandleManager::initCookieSession): Deleted.
     72        * platform/network/curl/ResourceHandleManager.h:
     73        (): Deleted.
     74
    1752017-06-29  Chris Dumez  <cdumez@apple.com>
    276
  • trunk/Source/WebCore/PlatformWinCairo.cmake

    r218637 r218947  
    3434    platform/network/curl/CurlCacheEntry.cpp
    3535    platform/network/curl/CurlCacheManager.cpp
     36    platform/network/curl/CurlContext.cpp
    3637    platform/network/curl/CurlDownload.cpp
    37     platform/network/curl/CurlManager.cpp
     38    platform/network/curl/CurlJobManager.cpp
    3839    platform/network/curl/DNSCurl.cpp
    3940    platform/network/curl/FormDataStreamCurl.cpp
  • trunk/Source/WebCore/platform/network/curl/CookieJarCurl.cpp

    r218637 r218947  
    2323
    2424#include "Cookie.h"
    25 #include "CurlManager.h"
     25#include "CurlContext.h"
    2626#include "NotImplemented.h"
    27 #include "ResourceHandleManager.h"
    2827#include "URL.h"
    2928
     
    244243void setCookiesFromDOM(const NetworkStorageSession&, const URL&, const URL& url, const String& value)
    245244{
     245    const CurlContext& context = CurlContext::singleton();
     246
    246247    CURL* curl = curl_easy_init();
    247248
     
    249250        return;
    250251
    251     const char* cookieJarFileName = ResourceHandleManager::sharedInstance()->getCookieJarFileName();
    252     CURLSH* curlsh = CurlManager::singleton().getCurlShareHandle();
     252    const char* cookieJarFileName = context.getCookieJarFileName();
     253    CURLSH* curlsh = context.curlShareHandle();
    253254
    254255    curl_easy_setopt(curl, CURLOPT_COOKIEJAR, cookieJarFileName);
     
    279280        return cookies;
    280281
    281     CURLSH* curlsh = CurlManager::singleton().getCurlShareHandle();
     282    CURLSH* curlsh = CurlContext::singleton().curlShareHandle();
    282283
    283284    curl_easy_setopt(curl, CURLOPT_SHARE, curlsh);
  • trunk/Source/WebCore/platform/network/curl/CurlDownload.cpp

    r218637 r218947  
    3030#include "CurlDownload.h"
    3131
     32#include "CurlContext.h"
     33
    3234#include "HTTPHeaderNames.h"
    3335#include "HTTPParsers.h"
     
    8688        curl_easy_setopt(m_curlHandle, CURLOPT_CAINFO, certPath);
    8789
    88     CURLSH* curlsh = CurlManager::singleton().getCurlShareHandle();
     90    CURLSH* curlsh = CurlContext::singleton().curlShareHandle();
    8991    if (curlsh)
    9092        curl_easy_setopt(m_curlHandle, CURLOPT_SHARE, curlsh);
     
    107109bool CurlDownload::start()
    108110{
    109     ref(); // CurlDownloadManager::downloadThread will call deref when the download has finished.
    110     return CurlManager::singleton().add(m_curlHandle);
     111    ref(); // CurlJobManager will call deref when the download has finished.
     112    return CurlJobManager::singleton().add(m_curlHandle);
    111113}
    112114
    113115bool CurlDownload::cancel()
    114116{
    115     return CurlManager::singleton().remove(m_curlHandle);
     117    return CurlJobManager::singleton().remove(m_curlHandle);
    116118}
    117119
     
    204206
    205207        if (httpCode >= 200 && httpCode < 300) {
    206             URL url = CurlUtils::getEffectiveURL(m_curlHandle);
     208            URL url = CurlContext::singleton().getEffectiveURL(m_curlHandle);
    207209            callOnMainThread([this, url = url.isolatedCopy(), protectedThis = makeRef(*this)] {
    208210                m_response.setURL(url);
  • trunk/Source/WebCore/platform/network/curl/CurlDownload.h

    r218637 r218947  
    3737#endif
    3838
    39 #include "CurlManager.h"
     39#include "CurlJobManager.h"
    4040
    4141namespace WebCore {
  • trunk/Source/WebCore/platform/network/curl/CurlJobManager.cpp

    r218944 r218947  
    2828
    2929#if USE(CURL)
    30 #include "CurlManager.h"
     30#include "CurlJobManager.h"
     31
     32#include "CurlContext.h"
    3133
    3234#include <wtf/MainThread.h>
     
    3739namespace WebCore {
    3840
    39 class CurlSharedResources {
    40 public:
    41     static void lock(CURL*, curl_lock_data, curl_lock_access, void*);
    42     static void unlock(CURL*, curl_lock_data, void*);
    43 
    44 private:
    45     static Lock* mutexFor(curl_lock_data);
    46 };
    47 
    48 // CurlDownloadManager -------------------------------------------------------------------
    49 
    50 CurlManager::CurlManager()
    51 {
    52     curl_global_init(CURL_GLOBAL_ALL);
    53     m_curlMultiHandle = curl_multi_init();
    54     m_curlShareHandle = curl_share_init();
    55     curl_share_setopt(m_curlShareHandle, CURLSHOPT_SHARE, CURL_LOCK_DATA_COOKIE);
    56     curl_share_setopt(m_curlShareHandle, CURLSHOPT_SHARE, CURL_LOCK_DATA_DNS);
    57     curl_share_setopt(m_curlShareHandle, CURLSHOPT_LOCKFUNC, CurlSharedResources::lock);
    58     curl_share_setopt(m_curlShareHandle, CURLSHOPT_UNLOCKFUNC, CurlSharedResources::unlock);
    59 }
    60 
    61 CurlManager::~CurlManager()
     41CurlJobManager::CurlJobManager()
     42{
     43    m_curlMultiHandle = CurlContext::singleton().createMultiHandle();
     44}
     45
     46CurlJobManager::~CurlJobManager()
    6247{
    6348    stopThread();
    6449    curl_multi_cleanup(m_curlMultiHandle);
    65     curl_share_cleanup(m_curlShareHandle);
    66     curl_global_cleanup();
    67 }
    68 
    69 bool CurlManager::add(CURL* curlHandle)
     50}
     51
     52bool CurlJobManager::add(CURL* curlHandle)
    7053{
    7154    ASSERT(isMainThread());
     
    8164}
    8265
    83 bool CurlManager::remove(CURL* curlHandle)
     66bool CurlJobManager::remove(CURL* curlHandle)
    8467{
    8568    LockHolder locker(m_mutex);
     
    9073}
    9174
    92 int CurlManager::getActiveCount() const
     75int CurlJobManager::getActiveCount() const
    9376{
    9477    LockHolder locker(m_mutex);
     
    9679}
    9780
    98 int CurlManager::getPendingCount() const
     81int CurlJobManager::getPendingCount() const
    9982{
    10083    LockHolder locker(m_mutex);
     
    10285}
    10386
    104 void CurlManager::startThreadIfNeeded()
     87void CurlJobManager::startThreadIfNeeded()
    10588{
    10689    ASSERT(isMainThread());
     
    11699}
    117100
    118 void CurlManager::stopThread()
    119 {
    120     ASSERT(isMainThread());
    121 
     101void CurlJobManager::stopThread()
     102{
    122103    setRunThread(false);
    123104
     
    128109}
    129110
    130 void CurlManager::stopThreadIfIdle()
     111void CurlJobManager::stopThreadIfIdle()
    131112{
    132113    if (!getActiveCount() && !getPendingCount())
     
    134115}
    135116
    136 void CurlManager::updateHandleList()
     117void CurlJobManager::updateHandleList()
    137118{
    138119    LockHolder locker(m_mutex);
     
    153134}
    154135
    155 bool CurlManager::addToCurl(CURL* curlHandle)
     136bool CurlJobManager::addToCurl(CURL* curlHandle)
    156137{
    157138    CURLMcode retval = curl_multi_add_handle(m_curlMultiHandle, curlHandle);
     
    163144}
    164145
    165 bool CurlManager::removeFromCurl(CURL* curlHandle)
     146bool CurlJobManager::removeFromCurl(CURL* curlHandle)
    166147{
    167148    int handlePos = m_activeHandleList.find(curlHandle);
     
    179160}
    180161
    181 void CurlManager::workerThread()
     162void CurlJobManager::workerThread()
    182163{
    183164    ASSERT(!isMainThread());
     
    237218}
    238219
    239 // CURL Utilities
    240 
    241 URL CurlUtils::getEffectiveURL(CURL* handle)
    242 {
    243     const char* url;
    244     CURLcode err = curl_easy_getinfo(handle, CURLINFO_EFFECTIVE_URL, &url);
    245     if (CURLE_OK != err)
    246         return URL();
    247     return URL(URL(), url);
    248 }
    249 
    250 // Shared Resource management =======================
    251 
    252 Lock* CurlSharedResources::mutexFor(curl_lock_data data)
    253 {
    254     DEPRECATED_DEFINE_STATIC_LOCAL(Lock, cookieMutex, ());
    255     DEPRECATED_DEFINE_STATIC_LOCAL(Lock, dnsMutex, ());
    256     DEPRECATED_DEFINE_STATIC_LOCAL(Lock, shareMutex, ());
    257 
    258     switch (data) {
    259     case CURL_LOCK_DATA_COOKIE:
    260         return &cookieMutex;
    261     case CURL_LOCK_DATA_DNS:
    262         return &dnsMutex;
    263     case CURL_LOCK_DATA_SHARE:
    264         return &shareMutex;
    265     default:
    266         ASSERT_NOT_REACHED();
    267         return nullptr;
    268     }
    269 }
    270 
    271 // libcurl does not implement its own thread synchronization primitives.
    272 // these two functions provide mutexes for cookies, and for the global DNS
    273 // cache.
    274 void CurlSharedResources::lock(CURL* /* handle */, curl_lock_data data, curl_lock_access /* access */, void* /* userPtr */)
    275 {
    276     if (Lock* mutex = CurlSharedResources::mutexFor(data))
    277         mutex->lock();
    278 }
    279 
    280 void CurlSharedResources::unlock(CURL* /* handle */, curl_lock_data data, void* /* userPtr */)
    281 {
    282     if (Lock* mutex = CurlSharedResources::mutexFor(data))
    283         mutex->unlock();
    284 }
    285 
    286220}
    287221
  • trunk/Source/WebCore/platform/network/curl/CurlJobManager.h

    r218944 r218947  
    2929#include <wtf/Lock.h>
    3030#include <wtf/Threading.h>
     31#include <wtf/Vector.h>
    3132
    3233#if PLATFORM(WIN)
     
    3637
    3738#include <curl/curl.h>
    38 #include "URL.h"
    3939
    4040namespace WebCore {
     
    4747};
    4848
    49 class CurlManager {
     49class CurlJobManager {
    5050public:
    51     static CurlManager& singleton()
     51    static CurlJobManager& singleton()
    5252    {
    5353        // Since it's a static variable, if the class has already been created,
     
    5555        // And it **is** thread-safe in C++11.
    5656
    57         static CurlManager shared;
     57        static CurlJobManager shared;
    5858        return shared;
    5959    }
    6060
    61     CurlManager();
    62     virtual ~CurlManager();
     61    CurlJobManager();
     62    virtual ~CurlJobManager();
    6363
    6464    bool add(CURL* curlHandle);
     
    6767    int getActiveCount() const;
    6868    int getPendingCount() const;
    69 
    70     CURLSH* getCurlShareHandle() const { return m_curlShareHandle; }
    7169
    7270private:
     
    9593    bool m_runThread { false };
    9694
    97     CURLSH* m_curlShareHandle { nullptr };
    98 
    9995    friend class CurlJob;
    10096};
    10197
    102 class CurlUtils {
    103 public:
    104     static URL getEffectiveURL(CURL* handle);
    105 };
    106 
    10798}
  • trunk/Source/WebCore/platform/network/curl/ResourceHandleManager.cpp

    r218637 r218947  
    4343#include "CredentialStorage.h"
    4444#include "CurlCacheManager.h"
    45 #include "CurlManager.h"
     45#include "CurlContext.h"
    4646#include "HTTPHeaderNames.h"
    4747#include "HTTPParsers.h"
     
    6161
    6262#if OS(WINDOWS)
    63 #include "WebCoreBundleWin.h"
    64 #include <shlobj.h>
    65 #include <shlwapi.h>
    6663#else
    6764#include <sys/param.h>
     
    7471#include <wtf/CurrentTime.h>
    7572#endif
    76 #if USE(CF)
    77 #include <wtf/RetainPtr.h>
    78 #endif
    7973#include <wtf/Lock.h>
    8074#include <wtf/Threading.h>
    8175#include <wtf/Vector.h>
    82 #include <wtf/text/CString.h>
    8376
    8477namespace WebCore {
     
    8982const char* const errorDomainCurl = "CurlErrorDomain";
    9083
    91 static const bool ignoreSSLErrors = getenv("WEBKIT_IGNORE_SSL_ERRORS");
    92 
    93 static CString certificatePath()
    94 {
    95     char* envPath = getenv("CURL_CA_BUNDLE_PATH");
    96     if (envPath)
    97         return envPath;
    98 
    99 #if USE(CF)
    100     CFBundleRef webKitBundleRef = webKitBundle();
    101     if (webKitBundleRef) {
    102         RetainPtr<CFURLRef> certURLRef = adoptCF(CFBundleCopyResourceURL(webKitBundleRef, CFSTR("cacert"), CFSTR("pem"), CFSTR("certificates")));
    103         if (certURLRef) {
    104             char path[MAX_PATH];
    105             CFURLGetFileSystemRepresentation(certURLRef.get(), false, reinterpret_cast<UInt8*>(path), MAX_PATH);
    106             return path;
    107         }
    108     }
    109 #endif
    110 
    111     return CString();
    112 }
    113 
    114 static char* cookieJarPath()
    115 {
    116     char* cookieJarPath = getenv("CURL_COOKIE_JAR_PATH");
    117     if (cookieJarPath)
    118         return fastStrDup(cookieJarPath);
    119 
    120 #if OS(WINDOWS)
    121     char executablePath[MAX_PATH];
    122     char appDataDirectory[MAX_PATH];
    123     char cookieJarFullPath[MAX_PATH];
    124     char cookieJarDirectory[MAX_PATH];
    125 
    126     if (FAILED(::SHGetFolderPathA(0, CSIDL_LOCAL_APPDATA | CSIDL_FLAG_CREATE, 0, 0, appDataDirectory))
    127         || FAILED(::GetModuleFileNameA(0, executablePath, MAX_PATH)))
    128         return fastStrDup("cookies.dat");
    129 
    130     ::PathRemoveExtensionA(executablePath);
    131     LPSTR executableName = ::PathFindFileNameA(executablePath);
    132     sprintf_s(cookieJarDirectory, MAX_PATH, "%s/%s", appDataDirectory, executableName);
    133     sprintf_s(cookieJarFullPath, MAX_PATH, "%s/cookies.dat", cookieJarDirectory);
    134 
    135     if (::SHCreateDirectoryExA(0, cookieJarDirectory, 0) != ERROR_SUCCESS
    136         && ::GetLastError() != ERROR_FILE_EXISTS
    137         && ::GetLastError() != ERROR_ALREADY_EXISTS)
    138         return fastStrDup("cookies.dat");
    139 
    140     return fastStrDup(cookieJarFullPath);
    141 #else
    142     return fastStrDup("cookies.dat");
    143 #endif
    144 }
    145 
    14684#if ENABLE(WEB_TIMING)
    14785static void calculateWebTimingInformations(ResourceHandleInternal* d)
     
    193131ResourceHandleManager::ResourceHandleManager()
    194132    : m_downloadTimer(*this, &ResourceHandleManager::downloadTimerCallback)
    195     , m_cookieJarFileName(cookieJarPath())
    196     , m_certificatePath(certificatePath())
    197133    , m_runningJobs(0)
    198 #ifndef NDEBUG
    199     , m_logFile(nullptr)
    200 #endif
    201 {
    202     CURLSH* h = CurlManager::singleton().getCurlShareHandle();
    203     m_curlShareHandle = h;
    204     m_curlMultiHandle = curl_multi_init();
    205 
    206 
    207     initCookieSession();
    208 
    209 #ifndef NDEBUG
    210     char* logFile = getenv("CURL_LOG_FILE");
    211     if (logFile)
    212         m_logFile = fopen(logFile, "a");
    213 #endif
     134{
     135    m_curlMultiHandle = CurlContext::singleton().createMultiHandle();
    214136}
    215137
     
    217139{
    218140    curl_multi_cleanup(m_curlMultiHandle);
    219     if (m_cookieJarFileName)
    220         fastFree(m_cookieJarFileName);
    221 
    222 #ifndef NDEBUG
    223     if (m_logFile)
    224         fclose(m_logFile);
    225 #endif
    226 }
    227 
    228 void ResourceHandleManager::setCookieJarFileName(const char* cookieJarFileName)
    229 {
    230     m_cookieJarFileName = fastStrDup(cookieJarFileName);
    231 }
    232 
    233 const char* ResourceHandleManager::getCookieJarFileName() const
    234 {
    235     return m_cookieJarFileName;
    236141}
    237142
     
    251156    // Run the code here for local files to resolve the issue.
    252157    // TODO: See if there is a better approach for handling this.
    253     URL url = CurlUtils::getEffectiveURL(handle);
     158    URL url = CurlContext::singleton().getEffectiveURL(handle);
    254159    ASSERT(url.isValid());
    255160    d->m_response.setURL(url);
     
    362267        return false;
    363268
    364     URL url = CurlUtils::getEffectiveURL(h);
     269    URL url = CurlContext::singleton().getEffectiveURL(h);
    365270    if (!url.isValid())
    366271        return false;
     
    451356        d->m_response.setExpectedContentLength(static_cast<long long int>(contentLength));
    452357
    453         d->m_response.setURL(CurlUtils::getEffectiveURL(h));
     358        d->m_response.setURL(CurlContext::singleton().getEffectiveURL(h));
    454359
    455360        d->m_response.setHTTPStatusCode(httpCode);
     
    658563            }
    659564        } else {
    660             URL url = CurlUtils::getEffectiveURL(d->m_handle);
     565            URL url = CurlContext::singleton().getEffectiveURL(d->m_handle);
    661566#ifndef NDEBUG
    662567            fprintf(stderr, "Curl ERROR for url='%s', error: '%s'\n", url.string().utf8().data(), curl_easy_strerror(msg->data.result));
     
    677582    if (!m_downloadTimer.isActive() && (started || (runningHandles > 0)))
    678583        m_downloadTimer.startOneShot(pollTime);
    679 }
    680 
    681 void ResourceHandleManager::setProxyInfo(const String& host,
    682                                          unsigned long port,
    683                                          ProxyType type,
    684                                          const String& username,
    685                                          const String& password)
    686 {
    687     m_proxyType = type;
    688 
    689     if (!host.length()) {
    690         m_proxy = emptyString();
    691     } else {
    692         String userPass;
    693         if (username.length() || password.length())
    694             userPass = username + ":" + password + "@";
    695 
    696         m_proxy = String("http://") + userPass + host + ":" + String::number(port);
    697     }
    698584}
    699585
     
    1020906void ResourceHandleManager::initializeHandle(ResourceHandle* job)
    1021907{
     908    CurlContext& context = CurlContext::singleton();
     909
    1022910    static const int allowedProtocols = CURLPROTO_FILE | CURLPROTO_FTP | CURLPROTO_FTPS | CURLPROTO_HTTP | CURLPROTO_HTTPS;
    1023911    URL url = job->firstRequest().url();
     
    1049937    }
    1050938#ifndef NDEBUG
    1051     if (getenv("DEBUG_CURL"))
     939    if (context.isVerbose())
    1052940        curl_easy_setopt(d->m_handle, CURLOPT_VERBOSE, 1);
    1053     if (m_logFile)
    1054         curl_easy_setopt(d->m_handle, CURLOPT_STDERR, m_logFile);
     941    if (context.getLogFile())
     942        curl_easy_setopt(d->m_handle, CURLOPT_STDERR, context.getLogFile());
    1055943#endif
    1056944    curl_easy_setopt(d->m_handle, CURLOPT_SSL_VERIFYPEER, 1L);
     
    1066954    curl_easy_setopt(d->m_handle, CURLOPT_MAXREDIRS, 10);
    1067955    curl_easy_setopt(d->m_handle, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
    1068     curl_easy_setopt(d->m_handle, CURLOPT_SHARE, m_curlShareHandle);
     956    curl_easy_setopt(d->m_handle, CURLOPT_SHARE, CurlContext::singleton().curlShareHandle());
    1069957    curl_easy_setopt(d->m_handle, CURLOPT_DNS_CACHE_TIMEOUT, 60 * 5); // 5 minutes
    1070958    curl_easy_setopt(d->m_handle, CURLOPT_PROTOCOLS, allowedProtocols);
     
    1072960    setSSLClientCertificate(job);
    1073961
    1074     if (ignoreSSLErrors)
     962    if (context.shouldIgnoreSSLErrors())
    1075963        curl_easy_setopt(d->m_handle, CURLOPT_SSL_VERIFYPEER, false);
    1076964    else
    1077965        setSSLVerifyOptions(job);
    1078966
    1079     if (!m_certificatePath.isNull())
    1080        curl_easy_setopt(d->m_handle, CURLOPT_CAINFO, m_certificatePath.data());
     967    const char* certificate = context.getCertificatePath();
     968    if (certificate)
     969        curl_easy_setopt(d->m_handle, CURLOPT_CAINFO, certificate);
    1081970
    1082971    // enable gzip and deflate through Accept-Encoding:
     
    1090979    curl_easy_setopt(d->m_handle, CURLOPT_URL, d->m_url);
    1091980
    1092     if (m_cookieJarFileName)
    1093         curl_easy_setopt(d->m_handle, CURLOPT_COOKIEJAR, m_cookieJarFileName);
     981    const char* cookieJar = context.getCookieJarFileName();
     982    if (cookieJar)
     983        curl_easy_setopt(d->m_handle, CURLOPT_COOKIEJAR, cookieJar);
    1094984
    1095985    struct curl_slist* headers = 0;
     
    11511041
    11521042    // Set proxy options if we have them.
    1153     if (m_proxy.length()) {
    1154         curl_easy_setopt(d->m_handle, CURLOPT_PROXY, m_proxy.utf8().data());
    1155         curl_easy_setopt(d->m_handle, CURLOPT_PROXYTYPE, m_proxyType);
    1156     }
    1157 }
    1158 
    1159 void ResourceHandleManager::initCookieSession()
    1160 {
    1161     // Curl saves both persistent cookies, and session cookies to the cookie file.
    1162     // The session cookies should be deleted before starting a new session.
    1163 
    1164     CURL* curl = curl_easy_init();
    1165 
    1166     if (!curl)
    1167         return;
    1168 
    1169     curl_easy_setopt(curl, CURLOPT_SHARE, m_curlShareHandle);
    1170 
    1171     if (m_cookieJarFileName) {
    1172         curl_easy_setopt(curl, CURLOPT_COOKIEFILE, m_cookieJarFileName);
    1173         curl_easy_setopt(curl, CURLOPT_COOKIEJAR, m_cookieJarFileName);
    1174     }
    1175 
    1176     curl_easy_setopt(curl, CURLOPT_COOKIESESSION, 1);
    1177 
    1178     curl_easy_cleanup(curl);
     1043    auto& proxy = CurlContext::singleton().proxyInfo();
     1044    if (proxy.type != CurlProxyType::Invalid) {
     1045        curl_easy_setopt(d->m_handle, CURLOPT_PROXY, proxy.url().utf8().data());
     1046        curl_easy_setopt(d->m_handle, CURLOPT_PROXYTYPE, proxy.type);
     1047    }
    11791048}
    11801049
  • trunk/Source/WebCore/platform/network/curl/ResourceHandleManager.h

    r218637 r218947  
    4747class ResourceHandleManager {
    4848public:
    49     enum ProxyType {
    50         HTTP = CURLPROXY_HTTP,
    51         Socks4 = CURLPROXY_SOCKS4,
    52         Socks4A = CURLPROXY_SOCKS4A,
    53         Socks5 = CURLPROXY_SOCKS5,
    54         Socks5Hostname = CURLPROXY_SOCKS5_HOSTNAME
    55     };
    5649    static ResourceHandleManager* sharedInstance();
    5750    void add(ResourceHandle*);
    5851    void cancel(ResourceHandle*);
    59 
    60     void setCookieJarFileName(const char* cookieJarFileName);
    61     const char* getCookieJarFileName() const;
    6252
    6353    void dispatchSynchronousJob(ResourceHandle*);
     
    6555    void setupPOST(ResourceHandle*, struct curl_slist**);
    6656    void setupPUT(ResourceHandle*, struct curl_slist**);
    67 
    68     void setProxyInfo(const String& host = emptyString(), unsigned long port = 0, ProxyType = HTTP, const String& username = emptyString(), const String& password = emptyString());
    6957
    7058private:
     
    8068    void initializeHandle(ResourceHandle*);
    8169
    82     void initCookieSession();
    83 
    8470    Timer m_downloadTimer;
    8571    CURLM* m_curlMultiHandle;
    86     CURLSH* m_curlShareHandle;
    87     char* m_cookieJarFileName;
    8872    char m_curlErrorBuffer[CURL_ERROR_SIZE];
    8973    Vector<ResourceHandle*> m_resourceHandleList;
    90     const CString m_certificatePath;
    9174    int m_runningJobs;
    92    
    93     String m_proxy;
    94     ProxyType m_proxyType;
    95 
    96 #ifndef NDEBUG
    97     FILE* m_logFile;
    98 #endif
    9975};
    10076
Note: See TracChangeset for help on using the changeset viewer.