[Curl][WebKit] Implement Proxy configuration API.
authorbasuke.suzuki@sony.com <basuke.suzuki@sony.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 9 Nov 2018 20:43:23 +0000 (20:43 +0000)
committerbasuke.suzuki@sony.com <basuke.suzuki@sony.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 9 Nov 2018 20:43:23 +0000 (20:43 +0000)
https://bugs.webkit.org/show_bug.cgi?id=189053

Reviewed by Youenn Fablet.

Source/WebCore:

Added API to set proxy from the app.

No new tests because there's no behaviour change in WebCore.

* platform/network/NetworkStorageSession.h:
* platform/network/curl/CurlContext.h:
(WebCore::CurlContext::setProxySettings):
* platform/network/curl/CurlProxySettings.h:
* platform/network/curl/NetworkStorageSessionCurl.cpp:
(WebCore::NetworkStorageSession::setProxySettings const):

Source/WebKit:

Added proxy configuration API to WebsiteDataStore. Three API were added in WKWebsiteDataStoreRefCurl.h:
- WKWebsiteDataStoreEnableDefaultNetworkProxySettings(WKWebsiteDataStoreRef)
- WKWebsiteDataStoreEnableCustomNetworkProxySettings(WKWebsiteDataStoreRef, WKURLRef, WKStringRef ignoreHosts)
- WKWebsiteDataStoreDisableNetworkProxySettings(WKWebsiteDataStoreRef)

* NetworkProcess/NetworkProcess.h:
* NetworkProcess/NetworkProcess.messages.in:
* NetworkProcess/NetworkSessionCreationParameters.h:
(WebKit::NetworkSessionCreationParameters::encode const):
(WebKit::NetworkSessionCreationParameters::decode):
* NetworkProcess/curl/NetworkProcessCurl.cpp:
(WebKit::NetworkProcess::setNetworkProxySettings):
* NetworkProcess/curl/NetworkSessionCurl.cpp:
(WebKit::NetworkSessionCurl::NetworkSessionCurl):
* NetworkProcess/curl/RemoteNetworkingContextCurl.cpp:
(WebKit::RemoteNetworkingContext::ensureWebsiteDataStoreSession):
* PlatformWin.cmake:
* Shared/WebCoreArgumentCoders.h:
* Shared/curl/WebCoreArgumentCodersCurl.cpp:
(IPC::ArgumentCoder<CurlProxySettings>::encode):
(IPC::ArgumentCoder<CurlProxySettings>::decode):
* UIProcess/API/C/curl/WKWebsiteDataStoreRefCurl.cpp:
  Copied from Source/WebKit/NetworkProcess/curl/NetworkSessionCurl.cpp.
(WKWebsiteDataStoreEnableDefaultNetworkProxySettings):
(WKWebsiteDataStoreEnableCustomNetworkProxySettings):
(WKWebsiteDataStoreDisableNetworkProxySettings):
* UIProcess/API/C/curl/WKWebsiteDataStoreRefCurl.h:
  Copied from Source/WebKit/NetworkProcess/curl/NetworkSessionCurl.cpp.
* UIProcess/WebsiteData/WebsiteDataStore.cpp:
(WebKit::WebsiteDataStore::parameters):
* UIProcess/WebsiteData/WebsiteDataStore.h:
(WebKit::WebsiteDataStore::networkProxySettings const):
* UIProcess/WebsiteData/curl/WebsiteDataStoreCurl.cpp:
  Copied from Source/WebKit/NetworkProcess/curl/NetworkSessionCurl.cpp.
(WebKit::WebsiteDataStore::platformSetParameters):
(WebKit::WebsiteDataStore::setNetworkProxySettings):

Tools:

Added Proxy Settings dialog to call newly added API.

* MiniBrowser/win/BrowserWindow.h:
* MiniBrowser/win/Common.cpp:
(askProxySettings):
(askCredential):
(authDialogProc): Deleted.
* MiniBrowser/win/Common.h:
* MiniBrowser/win/DialogHelper.h: Added.
(Dialog::run):
(Dialog::doalogProc):
(Dialog::handle):
(Dialog::setup):
(Dialog::update):
(Dialog::validate):
(Dialog::updateOkButton):
(Dialog::command):
(Dialog::ok):
(Dialog::cancel):
(Dialog::close):
(Dialog::hDlg):
(Dialog::item):
(Dialog::setEnabled):
(Dialog::setText):
(Dialog::getText):
(Dialog::getTextLength):
(Dialog::RadioGroup::RadioGroup):
(Dialog::RadioGroup::set):
(Dialog::RadioGroup::get):
(Dialog::radioGroup):
* MiniBrowser/win/MainWindow.cpp:
(MainWindow::WndProc):
* MiniBrowser/win/MiniBrowserLib.rc:
* MiniBrowser/win/MiniBrowserLibResource.h:
* MiniBrowser/win/WebKitBrowserWindow.cpp:
(createWKURL):
(WebKitBrowserWindow::WebKitBrowserWindow):
(WebKitBrowserWindow::updateProxySettings):
(WebKitBrowserWindow::loadURL):
(WebKitBrowserWindow::loadHTMLString):
(WebKitBrowserWindow::openProxySettings):
* MiniBrowser/win/WebKitBrowserWindow.h:
* MiniBrowser/win/WebKitLegacyBrowserWindow.cpp:
(WebKitLegacyBrowserWindow::openProxySettings):
* MiniBrowser/win/WebKitLegacyBrowserWindow.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@238051 268f45cc-cd09-0410-ab3c-d52691b4dbfc

32 files changed:
Source/WebCore/ChangeLog
Source/WebCore/platform/network/NetworkStorageSession.h
Source/WebCore/platform/network/curl/CurlContext.h
Source/WebCore/platform/network/curl/CurlProxySettings.h
Source/WebCore/platform/network/curl/NetworkStorageSessionCurl.cpp
Source/WebKit/ChangeLog
Source/WebKit/NetworkProcess/NetworkProcess.h
Source/WebKit/NetworkProcess/NetworkProcess.messages.in
Source/WebKit/NetworkProcess/NetworkSessionCreationParameters.h
Source/WebKit/NetworkProcess/curl/NetworkProcessCurl.cpp
Source/WebKit/NetworkProcess/curl/NetworkSessionCurl.cpp
Source/WebKit/NetworkProcess/curl/RemoteNetworkingContextCurl.cpp
Source/WebKit/PlatformWin.cmake
Source/WebKit/Shared/WebCoreArgumentCoders.h
Source/WebKit/Shared/curl/WebCoreArgumentCodersCurl.cpp
Source/WebKit/UIProcess/API/C/curl/WKWebsiteDataStoreRefCurl.cpp [new file with mode: 0644]
Source/WebKit/UIProcess/API/C/curl/WKWebsiteDataStoreRefCurl.h [new file with mode: 0644]
Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.cpp
Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.h
Source/WebKit/UIProcess/WebsiteData/curl/WebsiteDataStoreCurl.cpp [new file with mode: 0644]
Tools/ChangeLog
Tools/MiniBrowser/win/BrowserWindow.h
Tools/MiniBrowser/win/Common.cpp
Tools/MiniBrowser/win/Common.h
Tools/MiniBrowser/win/DialogHelper.h [new file with mode: 0644]
Tools/MiniBrowser/win/MainWindow.cpp
Tools/MiniBrowser/win/MiniBrowserLib.rc
Tools/MiniBrowser/win/MiniBrowserLibResource.h
Tools/MiniBrowser/win/WebKitBrowserWindow.cpp
Tools/MiniBrowser/win/WebKitBrowserWindow.h
Tools/MiniBrowser/win/WebKitLegacyBrowserWindow.cpp
Tools/MiniBrowser/win/WebKitLegacyBrowserWindow.h

index 954032b..d0f64f0 100644 (file)
@@ -1,3 +1,21 @@
+2018-11-09  Basuke Suzuki  <basuke.suzuki@sony.com>
+
+        [Curl][WebKit] Implement Proxy configuration API.
+        https://bugs.webkit.org/show_bug.cgi?id=189053
+
+        Reviewed by Youenn Fablet.
+
+        Added API to set proxy from the app.
+
+        No new tests because there's no behaviour change in WebCore.
+
+        * platform/network/NetworkStorageSession.h:
+        * platform/network/curl/CurlContext.h:
+        (WebCore::CurlContext::setProxySettings):
+        * platform/network/curl/CurlProxySettings.h:
+        * platform/network/curl/NetworkStorageSessionCurl.cpp:
+        (WebCore::NetworkStorageSession::setProxySettings const):
+
 2018-11-09  Antti Koivisto  <antti@apple.com>
 
         Use OptionSet for layout milestones
index aa9e428..e24f3a5 100644 (file)
@@ -60,6 +60,7 @@ typedef struct _SoupCookieJar SoupCookieJar;
 
 namespace WebCore {
 
+class CurlProxySettings;
 class NetworkingContext;
 class ResourceRequest;
 class SoupNetworkSession;
@@ -133,7 +134,9 @@ public:
 
     const CookieJarCurl& cookieStorage() const { return m_cookieStorage; };
     CookieJarDB& cookieDatabase() const;
-    WEBCORE_EXPORT void setCookieDatabase(UniqueRef<CookieJarDB>&&) const;
+    WEBCORE_EXPORT void setCookieDatabase(UniqueRef<CookieJarDB>&&);
+
+    WEBCORE_EXPORT void setProxySettings(CurlProxySettings&&);
 
     NetworkingContext* context() const;
 #else
index 3732601..8052b82 100644 (file)
@@ -104,7 +104,7 @@ public:
 
     // Proxy
     const CurlProxySettings& proxySettings() const { return m_proxySettings; }
-    void setProxySettings(const CurlProxySettings& settings) { m_proxySettings = settings; }
+    void setProxySettings(CurlProxySettings&& settings) { m_proxySettings = WTFMove(settings); }
     void setProxyUserPass(const String& user, const String& password) { m_proxySettings.setUserPass(user, password); }
     void setDefaultProxyAuthMethod() { m_proxySettings.setDefaultAuthMethod(); }
     void setProxyAuthMethod(long authMethod) { m_proxySettings.setAuthMethod(authMethod); }
index a61c6ec..27a7021 100644 (file)
@@ -35,7 +35,7 @@ namespace WebCore {
 
 class CurlProxySettings {
 public:
-    enum class Mode {
+    enum class Mode : uint8_t {
         Default,
         NoProxy,
         Custom
index e110ad1..b07083b 100644 (file)
@@ -71,7 +71,7 @@ NetworkingContext* NetworkStorageSession::context() const
     return m_context.get();
 }
 
-void NetworkStorageSession::setCookieDatabase(UniqueRef<CookieJarDB>&& cookieDatabase) const
+void NetworkStorageSession::setCookieDatabase(UniqueRef<CookieJarDB>&& cookieDatabase)
 {
     m_cookieDatabase = WTFMove(cookieDatabase);
 }
@@ -193,6 +193,11 @@ std::pair<String, bool> NetworkStorageSession::cookieRequestHeaderFieldValue(con
     return cookieStorage().cookieRequestHeaderFieldValue(*this, headerFieldProxy.firstParty, headerFieldProxy.sameSiteInfo, headerFieldProxy.url, headerFieldProxy.frameID, headerFieldProxy.pageID, headerFieldProxy.includeSecureCookies);
 }
 
+void NetworkStorageSession::setProxySettings(CurlProxySettings&& proxySettings)
+{
+    CurlContext::singleton().setProxySettings(WTFMove(proxySettings));
+}
+
 } // namespace WebCore
 
 #endif // USE(CURL)
index da023d2..85db751 100644 (file)
@@ -1,3 +1,47 @@
+2018-11-09  Basuke Suzuki  <basuke.suzuki@sony.com>
+
+        [Curl][WebKit] Implement Proxy configuration API.
+        https://bugs.webkit.org/show_bug.cgi?id=189053
+
+        Reviewed by Youenn Fablet.
+
+        Added proxy configuration API to WebsiteDataStore. Three API were added in WKWebsiteDataStoreRefCurl.h:
+        - WKWebsiteDataStoreEnableDefaultNetworkProxySettings(WKWebsiteDataStoreRef)
+        - WKWebsiteDataStoreEnableCustomNetworkProxySettings(WKWebsiteDataStoreRef, WKURLRef, WKStringRef ignoreHosts)
+        - WKWebsiteDataStoreDisableNetworkProxySettings(WKWebsiteDataStoreRef)
+
+        * NetworkProcess/NetworkProcess.h:
+        * NetworkProcess/NetworkProcess.messages.in:
+        * NetworkProcess/NetworkSessionCreationParameters.h:
+        (WebKit::NetworkSessionCreationParameters::encode const):
+        (WebKit::NetworkSessionCreationParameters::decode):
+        * NetworkProcess/curl/NetworkProcessCurl.cpp:
+        (WebKit::NetworkProcess::setNetworkProxySettings):
+        * NetworkProcess/curl/NetworkSessionCurl.cpp:
+        (WebKit::NetworkSessionCurl::NetworkSessionCurl):
+        * NetworkProcess/curl/RemoteNetworkingContextCurl.cpp:
+        (WebKit::RemoteNetworkingContext::ensureWebsiteDataStoreSession):
+        * PlatformWin.cmake:
+        * Shared/WebCoreArgumentCoders.h:
+        * Shared/curl/WebCoreArgumentCodersCurl.cpp:
+        (IPC::ArgumentCoder<CurlProxySettings>::encode):
+        (IPC::ArgumentCoder<CurlProxySettings>::decode):
+        * UIProcess/API/C/curl/WKWebsiteDataStoreRefCurl.cpp:
+          Copied from Source/WebKit/NetworkProcess/curl/NetworkSessionCurl.cpp.
+        (WKWebsiteDataStoreEnableDefaultNetworkProxySettings):
+        (WKWebsiteDataStoreEnableCustomNetworkProxySettings):
+        (WKWebsiteDataStoreDisableNetworkProxySettings):
+        * UIProcess/API/C/curl/WKWebsiteDataStoreRefCurl.h:
+          Copied from Source/WebKit/NetworkProcess/curl/NetworkSessionCurl.cpp.
+        * UIProcess/WebsiteData/WebsiteDataStore.cpp:
+        (WebKit::WebsiteDataStore::parameters):
+        * UIProcess/WebsiteData/WebsiteDataStore.h:
+        (WebKit::WebsiteDataStore::networkProxySettings const):
+        * UIProcess/WebsiteData/curl/WebsiteDataStoreCurl.cpp:
+          Copied from Source/WebKit/NetworkProcess/curl/NetworkSessionCurl.cpp.
+        (WebKit::WebsiteDataStore::platformSetParameters):
+        (WebKit::WebsiteDataStore::setNetworkProxySettings):
+
 2018-11-09  Wenson Hsieh  <wenson_hsieh@apple.com>
 
         [Cocoa] Introduce WKWebView SPI to insert nested ordered and unordered lists
index bb0ce83..b2a23fe 100644 (file)
@@ -59,6 +59,7 @@ class SessionID;
 
 namespace WebCore {
 class CertificateInfo;
+class CurlProxySettings;
 class DownloadID;
 class NetworkStorageSession;
 class ProtectionSpace;
@@ -302,6 +303,10 @@ private:
     void setNetworkProxySettings(const WebCore::SoupNetworkProxySettings&);
 #endif
 
+#if USE(CURL)
+    void setNetworkProxySettings(PAL::SessionID, WebCore::CurlProxySettings&&);
+#endif
+
 #if PLATFORM(MAC)
     static void setSharedHTTPCookieStorage(const Vector<uint8_t>& identifier);
 #endif
index 7fbb074..c42f5a1 100644 (file)
@@ -33,6 +33,10 @@ messages -> NetworkProcess LegacyReceiver {
     SetNetworkProxySettings(struct WebCore::SoupNetworkProxySettings settings)
 #endif
 
+#if USE(CURL)
+    SetNetworkProxySettings(PAL::SessionID sessionID, WebCore::CurlProxySettings settings)
+#endif
+
     ClearCachedCredentials()
 
     AddWebsiteDataStore(struct WebKit::WebsiteDataStoreParameters websiteDataStoreParameters);
index ece5517..a2dfbb8 100644 (file)
 #include "ArgumentCodersCF.h"
 #endif
 
+#if USE(CURL)
+#include "WebCoreArgumentCoders.h"
+#include <WebCore/CurlProxySettings.h>
+#endif
+
 namespace WebKit {
 
 class LegacyCustomProtocolManager;
@@ -51,6 +56,9 @@ struct NetworkSessionCreationParameters {
     String sourceApplicationBundleIdentifier;
     String sourceApplicationSecondaryIdentifier;
 #endif
+#if USE(CURL)
+    WebCore::CurlProxySettings proxySettings;
+#endif
 };
 
 inline void NetworkSessionCreationParameters::encode(IPC::Encoder& encoder) const
@@ -63,6 +71,9 @@ inline void NetworkSessionCreationParameters::encode(IPC::Encoder& encoder) cons
     encoder << sourceApplicationBundleIdentifier;
     encoder << sourceApplicationSecondaryIdentifier;
 #endif
+#if USE(CURL)
+    encoder << proxySettings;
+#endif
 }
 
 inline std::optional<NetworkSessionCreationParameters> NetworkSessionCreationParameters::decode(IPC::Decoder& decoder)
@@ -96,7 +107,14 @@ inline std::optional<NetworkSessionCreationParameters> NetworkSessionCreationPar
     if (!sourceApplicationSecondaryIdentifier)
         return std::nullopt;
 #endif
-    
+
+#if USE(CURL)
+    std::optional<WebCore::CurlProxySettings> proxySettings;
+    decoder >> proxySettings;
+    if (!proxySettings)
+        return std::nullopt;
+#endif
+
     return {{
         sessionID
         , WTFMove(*boundInterfaceIdentifier)
@@ -106,6 +124,9 @@ inline std::optional<NetworkSessionCreationParameters> NetworkSessionCreationPar
         , WTFMove(*sourceApplicationBundleIdentifier)
         , WTFMove(*sourceApplicationSecondaryIdentifier)
 #endif
+#if USE(CURL)
+        , WTFMove(*proxySettings)
+#endif
     }};
 }
 
index 19131c6..e7a3b47 100644 (file)
 #include "config.h"
 #include "NetworkProcess.h"
 
-#include "NetworkCache.h"
 #include "NetworkProcessCreationParameters.h"
-#include "ResourceCachesToClear.h"
-#include "WebCookieManager.h"
-#include <WebCore/CertificateInfo.h>
-#include <WebCore/FileSystem.h>
-#include <WebCore/NetworkStorageSession.h>
 #include "WebCookieManager.h"
 #include <WebCore/CurlContext.h>
+#include <WebCore/NetworkStorageSession.h>
 #include <WebCore/NotImplemented.h>
-#include <WebCore/ResourceHandle.h>
-#include <wtf/RAMSize.h>
-#include <wtf/text/CString.h>
-#include <wtf/text/StringBuilder.h>
 
 using namespace WebCore;
 
@@ -92,4 +83,12 @@ void NetworkProcess::platformProcessDidTransitionToBackground()
     notImplemented();
 }
 
+void NetworkProcess::setNetworkProxySettings(PAL::SessionID sessionID, WebCore::CurlProxySettings&& settings)
+{
+    if (auto* networkStorageSession = NetworkStorageSession::storageSession(sessionID))
+        networkStorageSession->setProxySettings(WTFMove(settings));
+    else
+        ASSERT_NOT_REACHED();
+}
+
 } // namespace WebKit
index 5d3a66d..fa68b6e 100644 (file)
@@ -27,6 +27,8 @@
 #include "NetworkSessionCurl.h"
 
 #include "NetworkSessionCreationParameters.h"
+#include <WebCore/CurlContext.h>
+#include <WebCore/NetworkStorageSession.h>
 
 using namespace WebCore;
 
@@ -35,7 +37,7 @@ namespace WebKit {
 NetworkSessionCurl::NetworkSessionCurl(NetworkSessionCreationParameters&& parameters)
     : NetworkSession(parameters.sessionID)
 {
-
+    networkStorageSession().setProxySettings(WTFMove(parameters.proxySettings));
 }
 
 NetworkSessionCurl::~NetworkSessionCurl()
index 736ee98..75939b2 100644 (file)
 #include "config.h"
 #include "RemoteNetworkingContext.h"
 
+#include "NetworkSession.h"
+#include "SessionTracker.h"
 #include "WebsiteDataStoreParameters.h"
-#include <WebCore/NotImplemented.h>
+#include <WebCore/NetworkStorageSession.h>
 
 using namespace WebCore;
 
 namespace WebKit {
 
-void RemoteNetworkingContext::ensureWebsiteDataStoreSession(WebsiteDataStoreParameters&&)
+void RemoteNetworkingContext::ensureWebsiteDataStoreSession(WebsiteDataStoreParameters&& parameters)
 {
-    notImplemented();
+    auto sessionID = parameters.networkSessionParameters.sessionID;
+    if (NetworkStorageSession::storageSession(sessionID))
+        return;
+
+    NetworkStorageSession::ensureSession(sessionID, String::number(sessionID.sessionID()));
+    SessionTracker::setSession(sessionID, NetworkSession::create(WTFMove(parameters.networkSessionParameters)));
 }
 
 }
index 3aeb6a4..3dd5643 100644 (file)
@@ -40,6 +40,8 @@ list(APPEND WebKit_SOURCES
 
     UIProcess/API/C/WKViewportAttributes.cpp
 
+    UIProcess/API/C/curl/WKWebsiteDataStoreRefCurl.cpp
+
     UIProcess/API/C/win/WKView.cpp
 
     UIProcess/API/win/APIWebsiteDataStoreWin.cpp
@@ -48,6 +50,8 @@ list(APPEND WebKit_SOURCES
 
     UIProcess/WebStorage/StorageManager.cpp
 
+    UIProcess/WebsiteData/curl/WebsiteDataStoreCurl.cpp
+
     UIProcess/WebsiteData/win/WebsiteDataStoreWin.cpp
 
     UIProcess/win/PageClientImpl.cpp
@@ -105,6 +109,7 @@ list(APPEND WebKit_INCLUDE_DIRECTORIES
     "${WEBKIT_DIR}/Shared/unix"
     "${WEBKIT_DIR}/Shared/win"
     "${WEBKIT_DIR}/UIProcess/API/C/cairo"
+    "${WEBKIT_DIR}/UIProcess/API/C/curl"
     "${WEBKIT_DIR}/UIProcess/API/C/win"
     "${WEBKIT_DIR}/UIProcess/API/cpp/win"
     "${WEBKIT_DIR}/UIProcess/API/win"
@@ -196,6 +201,7 @@ set(WebKit_FORWARDING_HEADERS_DIRECTORIES
     UIProcess/API/C
     UIProcess/API/cpp
 
+    UIProcess/API/C/curl
     UIProcess/API/C/win
 
     WebProcess/InjectedBundle/API/c
index f509216..5958db1 100644 (file)
 #include <WebCore/PaymentHeaders.h>
 #endif
 
+#if USE(CURL)
+#include <WebCore/CurlProxySettings.h>
+#endif
+
 #if PLATFORM(COCOA)
 namespace WTF {
 class MachSendRight;
@@ -449,6 +453,13 @@ template<> struct ArgumentCoder<WebCore::PasteboardWebContent> {
 };
 #endif
 
+#if USE(CURL)
+template<> struct ArgumentCoder<WebCore::CurlProxySettings> {
+    static void encode(Encoder&, const WebCore::CurlProxySettings&);
+    static std::optional<WebCore::CurlProxySettings> decode(Decoder&);
+};
+#endif
+
 template<> struct ArgumentCoder<WebCore::CompositionUnderline> {
     static void encode(Encoder&, const WebCore::CompositionUnderline&);
     static std::optional<WebCore::CompositionUnderline> decode(Decoder&);
@@ -813,4 +824,15 @@ template <> struct EnumTraits<WebCore::WorkerType> {
     >;
 };
 
+#if USE(CURL)
+template <> struct EnumTraits<WebCore::CurlProxySettings::Mode> {
+    using values = EnumValues<
+        WebCore::CurlProxySettings::Mode,
+        WebCore::CurlProxySettings::Mode::Default,
+        WebCore::CurlProxySettings::Mode::NoProxy,
+        WebCore::CurlProxySettings::Mode::Custom
+    >;
+};
+#endif
+
 } // namespace WTF
index 36676d0..984aaf3 100644 (file)
@@ -28,6 +28,7 @@
 
 #include "DataReference.h"
 #include <WebCore/CertificateInfo.h>
+#include <WebCore/CurlProxySettings.h>
 #include <WebCore/ResourceError.h>
 #include <WebCore/ResourceRequest.h>
 #include <WebCore/ResourceResponse.h>
@@ -127,4 +128,34 @@ bool ArgumentCoder<Credential>::decodePlatformData(Decoder&, Credential&)
     return false;
 }
 
+void ArgumentCoder<CurlProxySettings>::encode(Encoder& encoder, const CurlProxySettings& settings)
+{
+    encoder << settings.mode();
+    if (settings.mode() != CurlProxySettings::Mode::Custom)
+        return;
+
+    encoder << settings.url();
+    encoder << settings.ignoreHosts();
+}
+
+std::optional<CurlProxySettings> ArgumentCoder<CurlProxySettings>::decode(Decoder& decoder)
+{
+    CurlProxySettings::Mode mode;
+    if (!decoder.decode(mode))
+        return std::nullopt;
+
+    if (mode != CurlProxySettings::Mode::Custom)
+        return CurlProxySettings { mode };
+
+    URL url;
+    if (!decoder.decode(url))
+        return std::nullopt;
+
+    String ignoreHosts;
+    if (!decoder.decode(ignoreHosts))
+        return std::nullopt;
+
+    return CurlProxySettings { WTFMove(url), WTFMove(ignoreHosts) };
+}
+
 }
diff --git a/Source/WebKit/UIProcess/API/C/curl/WKWebsiteDataStoreRefCurl.cpp b/Source/WebKit/UIProcess/API/C/curl/WKWebsiteDataStoreRefCurl.cpp
new file mode 100644 (file)
index 0000000..a3da059
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2018 Sony Interactive Entertainment Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "WKWebsiteDataStoreRefCurl.h"
+
+#include "APIWebsiteDataStore.h"
+#include "WKAPICast.h"
+#include <WebCore/CurlProxySettings.h>
+#include <WebCore/URL.h>
+#include <WebKit/WKWebsiteDataStoreRef.h>
+
+using namespace WebKit;
+
+void WKWebsiteDataStoreEnableDefaultNetworkProxySettings(WKWebsiteDataStoreRef dataStoreRef)
+{
+    toImpl(dataStoreRef)->websiteDataStore().setNetworkProxySettings(WebCore::CurlProxySettings(WebCore::CurlProxySettings::Mode::Default));
+}
+
+void WKWebsiteDataStoreEnableCustomNetworkProxySettings(WKWebsiteDataStoreRef dataStoreRef, WKURLRef proxyUrl, WKStringRef ignoreHosts)
+{
+    toImpl(dataStoreRef)->websiteDataStore().setNetworkProxySettings(WebCore::CurlProxySettings(WebCore::URL(WebCore::URL(), toWTFString(proxyUrl)), toWTFString(ignoreHosts)));
+}
+
+void WKWebsiteDataStoreDisableNetworkProxySettings(WKWebsiteDataStoreRef dataStoreRef)
+{
+    toImpl(dataStoreRef)->websiteDataStore().setNetworkProxySettings(WebCore::CurlProxySettings(WebCore::CurlProxySettings::Mode::NoProxy));
+}
diff --git a/Source/WebKit/UIProcess/API/C/curl/WKWebsiteDataStoreRefCurl.h b/Source/WebKit/UIProcess/API/C/curl/WKWebsiteDataStoreRefCurl.h
new file mode 100644 (file)
index 0000000..7bb27aa
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2018 Sony Interactive Entertainment Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include <WebKit/WKBase.h>
+#include <WebKit/WKWebsiteDataStoreRef.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+WK_EXPORT void WKWebsiteDataStoreEnableDefaultNetworkProxySettings(WKWebsiteDataStoreRef);
+WK_EXPORT void WKWebsiteDataStoreEnableCustomNetworkProxySettings(WKWebsiteDataStoreRef, WKURLRef proxyUrl, WKStringRef ignoreHosts);
+WK_EXPORT void WKWebsiteDataStoreDisableNetworkProxySettings(WKWebsiteDataStoreRef);
+
+#ifdef __cplusplus
+}
+#endif
index 1a255b8..0ebe0bb 100644 (file)
@@ -1667,6 +1667,10 @@ WebsiteDataStoreParameters WebsiteDataStore::parameters()
         SandboxExtension::createHandleForReadWriteDirectory(parameters.serviceWorkerRegistrationDirectory, parameters.serviceWorkerRegistrationDirectoryExtensionHandle);
 #endif
 
+#if USE(CURL)
+    platformSetParameters(parameters);
+#endif
+
     return parameters;
 }
 #endif
index bd57913..99ea686 100644 (file)
 #include <pal/spi/cf/CFNetworkSPI.h>
 #endif
 
+#if USE(CURL)
+#include <WebCore/CurlProxySettings.h>
+#endif
+
 namespace WebCore {
 class SecurityOrigin;
 }
@@ -187,7 +191,13 @@ public:
     void setProxyConfiguration(CFDictionaryRef configuration) { m_proxyConfiguration = configuration; }
     CFDictionaryRef proxyConfiguration() { return m_proxyConfiguration.get(); }
 #endif
-    
+
+#if USE(CURL)
+    void platformSetParameters(WebsiteDataStoreParameters&);
+    void setNetworkProxySettings(WebCore::CurlProxySettings&&);
+    const WebCore::CurlProxySettings& networkProxySettings() const { return m_proxySettings; }
+#endif
+
     static void allowWebsiteDataRecordsForAllOrigins();
 
 #if HAVE(SEC_KEY_PROXY)
@@ -252,8 +262,13 @@ private:
     RetainPtr<CFHTTPCookieStorageRef> m_cfCookieStorage;
     RetainPtr<CFDictionaryRef> m_proxyConfiguration;
 #endif
+
+#if USE(CURL)
+    WebCore::CurlProxySettings m_proxySettings;
+#endif
+
     HashSet<WebCore::Cookie> m_pendingCookies;
-    
+
     String m_boundInterfaceIdentifier;
     AllowsCellularAccess m_allowsCellularAccess { AllowsCellularAccess::Yes };
 
diff --git a/Source/WebKit/UIProcess/WebsiteData/curl/WebsiteDataStoreCurl.cpp b/Source/WebKit/UIProcess/WebsiteData/curl/WebsiteDataStoreCurl.cpp
new file mode 100644 (file)
index 0000000..38b6a0d
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2018 Sony Interactive Entertainment Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "WebsiteDataStore.h"
+
+#include "NetworkProcessMessages.h"
+#include "WebProcessPool.h"
+#include "WebsiteDataStoreParameters.h"
+
+namespace WebKit {
+
+void WebsiteDataStore::platformSetParameters(WebsiteDataStoreParameters& parameters)
+{
+    parameters.networkSessionParameters.proxySettings = m_proxySettings;
+}
+
+void WebsiteDataStore::setNetworkProxySettings(WebCore::CurlProxySettings&& proxySettings)
+{
+    m_proxySettings = WTFMove(proxySettings);
+
+    for (auto& processPool : processPools())
+        processPool->sendToNetworkingProcess(Messages::NetworkProcess::SetNetworkProxySettings(m_sessionID, m_proxySettings));
+}
+
+}
index f220818..9fec9d8 100644 (file)
@@ -1,3 +1,56 @@
+2018-11-09  Basuke Suzuki  <basuke.suzuki@sony.com>
+
+        [Curl][WebKit] Implement Proxy configuration API.
+        https://bugs.webkit.org/show_bug.cgi?id=189053
+
+        Reviewed by Youenn Fablet.
+
+        Added Proxy Settings dialog to call newly added API.
+
+        * MiniBrowser/win/BrowserWindow.h:
+        * MiniBrowser/win/Common.cpp:
+        (askProxySettings):
+        (askCredential):
+        (authDialogProc): Deleted.
+        * MiniBrowser/win/Common.h:
+        * MiniBrowser/win/DialogHelper.h: Added.
+        (Dialog::run):
+        (Dialog::doalogProc):
+        (Dialog::handle):
+        (Dialog::setup):
+        (Dialog::update):
+        (Dialog::validate):
+        (Dialog::updateOkButton):
+        (Dialog::command):
+        (Dialog::ok):
+        (Dialog::cancel):
+        (Dialog::close):
+        (Dialog::hDlg):
+        (Dialog::item):
+        (Dialog::setEnabled):
+        (Dialog::setText):
+        (Dialog::getText):
+        (Dialog::getTextLength):
+        (Dialog::RadioGroup::RadioGroup):
+        (Dialog::RadioGroup::set):
+        (Dialog::RadioGroup::get):
+        (Dialog::radioGroup):
+        * MiniBrowser/win/MainWindow.cpp:
+        (MainWindow::WndProc):
+        * MiniBrowser/win/MiniBrowserLib.rc:
+        * MiniBrowser/win/MiniBrowserLibResource.h:
+        * MiniBrowser/win/WebKitBrowserWindow.cpp:
+        (createWKURL):
+        (WebKitBrowserWindow::WebKitBrowserWindow):
+        (WebKitBrowserWindow::updateProxySettings):
+        (WebKitBrowserWindow::loadURL):
+        (WebKitBrowserWindow::loadHTMLString):
+        (WebKitBrowserWindow::openProxySettings):
+        * MiniBrowser/win/WebKitBrowserWindow.h:
+        * MiniBrowser/win/WebKitLegacyBrowserWindow.cpp:
+        (WebKitLegacyBrowserWindow::openProxySettings):
+        * MiniBrowser/win/WebKitLegacyBrowserWindow.h:
+
 2018-11-09  Wenson Hsieh  <wenson_hsieh@apple.com>
 
         [Cocoa] Introduce WKWebView SPI to insert nested ordered and unordered lists
index 91d7b39..a52237f 100644 (file)
@@ -44,6 +44,7 @@ public:
 
     virtual void print() = 0;
     virtual void launchInspector() = 0;
+    virtual void openProxySettings() = 0;
 
     virtual _bstr_t userAgent() = 0;
     void setUserAgent(UINT menuID);
index 956f115..4d16173 100644 (file)
@@ -29,6 +29,7 @@
 #include "stdafx.h"
 #include "Common.h"
 
+#include "DialogHelper.h"
 #include "MiniBrowserLibResource.h"
 #include "MiniBrowserReplace.h"
 #include <dbghelp.h>
@@ -119,54 +120,115 @@ void createCrashReport(EXCEPTION_POINTERS* exceptionPointers)
     }
 }
 
-struct AuthDialogData {
-    const std::wstring& realm;
-    Credential credential;
-};
-
-static INT_PTR CALLBACK authDialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
+bool askProxySettings(HWND hwnd, ProxySettings& settings)
 {
-    switch (message) {
-    case WM_INITDIALOG: {
-        SetWindowLongPtr(hDlg, DWLP_USER, lParam);
-        AuthDialogData& data = *reinterpret_cast<AuthDialogData*>(lParam);
-        SetDlgItemText(hDlg, IDC_REALM_TEXT, _bstr_t(data.realm.c_str()));
-        return TRUE;
-    }
-    case WM_COMMAND: {
-        AuthDialogData& data = *reinterpret_cast<AuthDialogData*>(GetWindowLongPtr(hDlg, DWLP_USER));
-        int wmId = LOWORD(wParam);
-        switch (wmId) {
-        case IDOK: {
-            TCHAR str[256];
-            int strLen = GetWindowText(GetDlgItem(hDlg, IDC_AUTH_USER), str, WTF_ARRAY_LENGTH(str)-1);
-            str[strLen] = 0;
-            data.credential.username = str;
-
-            strLen = GetWindowText(GetDlgItem(hDlg, IDC_AUTH_PASSWORD), str, WTF_ARRAY_LENGTH(str)-1);
-            str[strLen] = 0;
-            data.credential.password = str;
-
-            EndDialog(hDlg, true);
-            return TRUE;
+    class ProxyDialog : public Dialog {
+    public:
+        ProxyDialog(ProxySettings& settings)
+            : settings { settings }
+        {
         }
-        case IDCANCEL:
-            EndDialog(hDlg, false);
-            return TRUE;
+
+    protected:
+        ProxySettings& settings;
+
+        void setup() final
+        {
+            auto command = commandForProxyChoice();
+            proxyChoice().set(command);
+            setText(IDC_PROXY_URL, settings.url);
+            setText(IDC_PROXY_EXCLUDE, settings.excludeHosts);
         }
-        break;
-    }
-    }
-    return FALSE;
+
+        void ok() final
+        {
+            settings.url = getText(IDC_PROXY_URL);
+            settings.excludeHosts = getText(IDC_PROXY_EXCLUDE);
+            updateProxyChoice(proxyChoice().get());
+        }
+
+        bool validate() final
+        {
+            bool valid = true;
+
+            if (proxyChoice().get() == IDC_PROXY_CUSTOM) {
+                setEnabled(IDC_PROXY_URL, true);
+                setEnabled(IDC_PROXY_EXCLUDE, true);
+
+                if (!getTextLength(IDC_PROXY_URL))
+                    valid = false;
+            } else {
+                setEnabled(IDC_PROXY_URL, false);
+                setEnabled(IDC_PROXY_EXCLUDE, false);
+            }
+
+            return valid;
+        }
+
+        RadioGroup proxyChoice()
+        {
+            return radioGroup(IDC_PROXY_DEFAULT, IDC_PROXY_DISABLE);
+        }
+
+        int commandForProxyChoice()
+        {
+            if (!settings.enable)
+                return IDC_PROXY_DISABLE;
+            if (settings.custom)
+                return IDC_PROXY_CUSTOM;
+            return IDC_PROXY_DEFAULT;
+        }
+
+        void updateProxyChoice(int command)
+        {
+            switch (command) {
+            case IDC_PROXY_DEFAULT:
+                settings.enable = true;
+                settings.custom = false;
+                break;
+            case IDC_PROXY_CUSTOM:
+                settings.enable = true;
+                settings.custom = true;
+                break;
+            case IDC_PROXY_DISABLE:
+                settings.enable = false;
+                settings.custom = false;
+                break;
+            default:
+                break;
+            }
+        }
+    };
+
+    ProxyDialog dialog { settings };
+    return dialog.run(hInst, hwnd, IDD_PROXY);
 }
 
 std::optional<Credential> askCredential(HWND hwnd, const std::wstring& realm)
 {
-    AuthDialogData data { realm };
-    auto result = DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_AUTH), hwnd, authDialogProc, reinterpret_cast<LPARAM>(&data));
-    if (result <= 0)
-        return std::nullopt;
-    return data.credential;
+    struct AuthDialog : public Dialog {
+        std::wstring realm;
+        Credential credential;
+
+    protected:
+        void setup()
+        {
+            setText(IDC_REALM_TEXT, realm);
+        }
+
+        void ok() final
+        {
+            credential.username = getText(IDC_AUTH_USER);
+            credential.password = getText(IDC_AUTH_PASSWORD);
+        }
+    };
+
+    AuthDialog dialog;
+    dialog.realm = realm;
+
+    if (dialog.run(hInst, hwnd, IDD_AUTH))
+        return dialog.credential;
+    return std::nullopt;
 }
 
 CommandLineOptions parseCommandLine()
index 70a84c4..15bc4dd 100644 (file)
@@ -51,11 +51,19 @@ struct Credential {
     std::wstring password;
 };
 
+struct ProxySettings {
+    bool enable { true };
+    bool custom { false };
+    std::wstring url;
+    std::wstring excludeHosts;
+};
+
 void computeFullDesktopFrame();
 bool getAppDataFolder(_bstr_t& directory);
 CommandLineOptions parseCommandLine();
 void createCrashReport(EXCEPTION_POINTERS*);
 std::optional<Credential> askCredential(HWND, const std::wstring& realm);
+bool askProxySettings(HWND, ProxySettings&);
 
 extern HINSTANCE hInst;
 extern POINT s_windowPosition;
diff --git a/Tools/MiniBrowser/win/DialogHelper.h b/Tools/MiniBrowser/win/DialogHelper.h
new file mode 100644 (file)
index 0000000..093df47
--- /dev/null
@@ -0,0 +1,153 @@
+/*
+ * Copyright (C) 2018 Sony Interactive Entertainment Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include "stdafx.h"
+#include <string>
+#include <vector>
+
+class Dialog {
+public:
+    bool run(HINSTANCE hInst, HWND hwnd, int dialogId)
+    {
+        auto result = DialogBoxParam(hInst, MAKEINTRESOURCE(dialogId), hwnd, doalogProc, reinterpret_cast<LPARAM>(this));
+        return (result > 0);
+    }
+
+    static INT_PTR CALLBACK doalogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
+    {
+        if (message == WM_INITDIALOG)
+            SetWindowLongPtr(hDlg, DWLP_USER, lParam);
+        else
+            lParam = GetWindowLongPtr(hDlg, DWLP_USER);
+
+        auto* dialog = reinterpret_cast<Dialog*>(lParam);
+        return dialog->handle(hDlg, message, wParam);
+    }
+
+protected:
+    INT_PTR handle(HWND hDlg, UINT message, WPARAM wParam)
+    {
+        switch (message) {
+        case WM_INITDIALOG: {
+            m_hDlg = hDlg;
+            setup();
+            update();
+            return TRUE;
+        }
+        case WM_COMMAND:
+            int wmId = LOWORD(wParam);
+            switch (wmId) {
+            case IDOK:
+                ok();
+                close(true);
+                return TRUE;
+            case IDCANCEL:
+                cancel();
+                close(false);
+                return TRUE;
+            default:
+                auto handled = command(wmId);
+                update();
+                return handled;
+            }
+        }
+        return FALSE;
+    }
+
+    virtual void setup() { }
+    virtual void update() { updateOkButton(validate()); }
+    virtual bool validate() { return true; }
+    virtual void updateOkButton(bool isValid) { setEnabled(IDOK, isValid); }
+    virtual bool command(int wmId) { return false; }
+    virtual void ok() { }
+    virtual void cancel() { }
+
+    void close(bool success) { EndDialog(m_hDlg, success); }
+
+    HWND hDlg() { return m_hDlg; }
+
+    HWND item(int itemId) { return GetDlgItem(m_hDlg, itemId); }
+
+    void setEnabled(int itemId, bool enabled)
+    {
+        EnableWindow(item(itemId), enabled);
+    }
+
+    void setText(int itemId, const std::wstring& str)
+    {
+        SetDlgItemText(m_hDlg, itemId, _bstr_t(str.c_str()));
+    }
+
+    std::wstring getText(int itemId)
+    {
+        auto length = getTextLength(itemId);
+        std::vector<TCHAR> buffer(length + 1, 0);
+        GetWindowText(item(itemId), buffer.data(), length);
+        return std::wstring { buffer.data() };
+    }
+
+    int getTextLength(int itemId)
+    {
+        return GetWindowTextLength(item(itemId));
+    }
+
+    class RadioGroup {
+    public:
+        RadioGroup(Dialog& dialog, int first, int last)
+            : m_dialog(dialog)
+            , m_first(first)
+            , m_last(last)
+        {
+        }
+
+        void set(int item)
+        {
+            CheckRadioButton(m_dialog.hDlg(), m_first, m_last, item);
+        }
+
+        int get()
+        {
+            for (int id = m_first; id <= m_last; id++) {
+                if (IsDlgButtonChecked(m_dialog.hDlg(), id) == BST_CHECKED)
+                    return id;
+            }
+            return 0;
+        }
+
+    private:
+        Dialog& m_dialog;
+        int m_first;
+        int m_last;
+    };
+
+    RadioGroup radioGroup(int first, int last)
+    {
+        return RadioGroup(*this, first, last);
+    }
+
+    HWND m_hDlg { };
+};
index f90528c..7f4bdb4 100644 (file)
@@ -210,6 +210,9 @@ LRESULT CALLBACK MainWindow::WndProc(HWND hWnd, UINT message, WPARAM wParam, LPA
         case IDM_WEB_INSPECTOR:
             thisWindow->browserWindow()->launchInspector();
             break;
+        case IDM_PROXY_SETTINGS:
+            thisWindow->browserWindow()->openProxySettings();
+            break;
         case IDM_CACHES:
             if (!::IsWindow(thisWindow->m_hCacheWnd)) {
                 thisWindow->m_hCacheWnd = CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_CACHES), hWnd, cachesDialogProc, reinterpret_cast<LPARAM>(thisWindow.get()));
index 0a7a7f5..fd037ce 100755 (executable)
@@ -93,6 +93,7 @@ BEGIN
             MENUITEM SEPARATOR\r
             MENUITEM "Other",                       IDM_UA_OTHER\r
         END\r
+        MENUITEM "Proxy Settings...",           IDM_PROXY_SETTINGS\r
         MENUITEM SEPARATOR\r
         MENUITEM "Disable Images",              IDM_DISABLE_IMAGES\r
         MENUITEM "Disable Styles",              IDM_DISABLE_STYLES\r
@@ -259,6 +260,26 @@ BEGIN
     EDITTEXT        IDC_AUTH_PASSWORD,67,64,157,14,ES_PASSWORD | ES_AUTOHSCROLL\r
 END\r
 \r
+IDD_PROXY DIALOGEX 0, 0, 310, 176\r
+STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU\r
+CAPTION "Proxy Configuration"\r
+FONT 8, "MS Shell Dlg", 400, 0, 0x1\r
+BEGIN\r
+    DEFPUSHBUTTON   "OK",IDOK,199,155,50,14\r
+    PUSHBUTTON      "Cancel",IDCANCEL,253,155,50,14\r
+    CONTROL         "Use system default proxy configuration.",IDC_PROXY_DEFAULT,\r
+                    "Button",BS_AUTORADIOBUTTON | WS_GROUP,22,15,226,10\r
+    CONTROL         "Use custom proxy configuration:",IDC_PROXY_CUSTOM,\r
+                    "Button",BS_AUTORADIOBUTTON,22,33,226,10\r
+    CONTROL         "Don't use proxy.",IDC_PROXY_DISABLE,"Button",BS_AUTORADIOBUTTON,22,117,226,10\r
+    EDITTEXT        IDC_PROXY_URL,76,52,193,14,ES_AUTOHSCROLL\r
+    EDITTEXT        IDC_PROXY_EXCLUDE,76,85,193,14,ES_AUTOHSCROLL\r
+    LTEXT           "URL:",IDC_STATIC,30,55,43,8,0,WS_EX_RIGHT\r
+    LTEXT           "Excude list:",IDC_STATIC,30,88,43,8,0,WS_EX_RIGHT\r
+    LTEXT           "Example: http://192.168.0.2:8000",IDC_STATIC,80,68,194,8\r
+    LTEXT           "Comma separated hostnames.",IDC_STATIC,80,101,194,8\r
+END\r
+\r
 \r
 #ifdef APSTUDIO_INVOKED\r
 /////////////////////////////////////////////////////////////////////////////\r
@@ -327,6 +348,15 @@ BEGIN
         HORZGUIDE, 25\r
         HORZGUIDE, 50\r
     END\r
+\r
+    IDD_PROXY, DIALOG\r
+    BEGIN\r
+        LEFTMARGIN, 7\r
+        RIGHTMARGIN, 303\r
+        VERTGUIDE, 22\r
+        TOPMARGIN, 7\r
+        BOTTOMMARGIN, 169\r
+    END\r
 END\r
 #endif    // APSTUDIO_INVOKED\r
 \r
index e6c9b00..588e822 100755 (executable)
@@ -56,6 +56,7 @@
 #define IDM_SHOW_LAYER_TREE             175
 #define IDD_AUTH                        176
 #define IDM_DEBUG_INFO_LAYER            177
+#define IDD_PROXY                       178
 #define IDC_EMPTY_URL_CACHE             1000
 #define IDC_RETURN_FREE_MEMORY          1001
 #define IDC_EMPTY_WEBCORE_CACHE         1002
 #define IDC_AUTH_PASSWORD               1054
 #define IDC_URL_BAR                     1055
 #define IDC_REALM_TEXT                  1056
+#define IDC_PROXY_URL                   1057
+#define IDC_PROXY_DEFAULT               1058
+#define IDC_PROXY_CUSTOM                1059
+#define IDC_PROXY_EXCLUDE               1060
+#define IDC_PROXY_DISABLE               1061
 #define IDM_NEW_WEBKIT_WINDOW           32776
 #define IDM_NEW_WEBKITLEGACY_WINDOW     32777
+#define IDM_PROXY_SETTINGS              32778
 #define IDC_STATIC                      -1
 
 // Next default values for new objects
-// 
+//
 #ifdef APSTUDIO_INVOKED
 #ifndef APSTUDIO_READONLY_SYMBOLS
 #define _APS_NO_MFC                     1
-#define _APS_NEXT_RESOURCE_VALUE        175
-#define _APS_NEXT_COMMAND_VALUE         32778
-#define _APS_NEXT_CONTROL_VALUE         1055
+#define _APS_NEXT_RESOURCE_VALUE        179
+#define _APS_NEXT_COMMAND_VALUE         32779
+#define _APS_NEXT_CONTROL_VALUE         1062
 #define _APS_NEXT_SYMED_VALUE           110
 #endif
 #endif
index bf93cb6..a838606 100644 (file)
@@ -32,6 +32,7 @@
 #include <WebKit/WKCredential.h>
 #include <WebKit/WKInspector.h>
 #include <WebKit/WKProtectionSpace.h>
+#include <WebKit/WKWebsiteDataStoreRefCurl.h>
 #include <vector>
 
 std::wstring createString(WKStringRef wkString)
@@ -75,6 +76,12 @@ WKRetainPtr<WKURLRef> createWKURL(_bstr_t str)
     return adoptWK(WKURLCreateWithUTF8CString(utf8.data()));
 }
 
+WKRetainPtr<WKURLRef> createWKURL(const std::wstring& str)
+{
+    auto utf8 = createUTF8String(str.c_str(), str.length());
+    return adoptWK(WKURLCreateWithUTF8CString(utf8.data()));
+}
+
 Ref<BrowserWindow> WebKitBrowserWindow::create(HWND mainWnd, HWND urlBarWnd, bool, bool)
 {
     return adoptRef(*new WebKitBrowserWindow(mainWnd, urlBarWnd));
@@ -91,8 +98,8 @@ WebKitBrowserWindow::WebKitBrowserWindow(HWND mainWnd, HWND urlBarWnd)
     WKPreferencesSetDeveloperExtrasEnabled(prefs, true);
     WKPageConfigurationSetPreferences(conf.get(), prefs);
 
-    auto context = adoptWK(WKContextCreate());
-    WKPageConfigurationSetContext(conf.get(), context.get());
+    m_context = adoptWK(WKContextCreate());
+    WKPageConfigurationSetContext(conf.get(), m_context.get());
 
     m_view = adoptWK(WKViewCreate(rect, conf.get(), mainWnd));
     auto page = WKViewGetPage(m_view.get());
@@ -102,6 +109,27 @@ WebKitBrowserWindow::WebKitBrowserWindow(HWND mainWnd, HWND urlBarWnd)
     navigationClient.didCommitNavigation = didCommitNavigation;
     navigationClient.didReceiveAuthenticationChallenge = didReceiveAuthenticationChallenge;
     WKPageSetPageNavigationClient(page, &navigationClient.base);
+
+    updateProxySettings();
+}
+
+void WebKitBrowserWindow::updateProxySettings()
+{
+    auto store = WKContextGetWebsiteDataStore(m_context.get());
+
+    if (!m_proxy.enable) {
+        WKWebsiteDataStoreDisableNetworkProxySettings(store);
+        return;
+    }
+
+    if (!m_proxy.custom) {
+        WKWebsiteDataStoreEnableDefaultNetworkProxySettings(store);
+        return;
+    }
+
+    auto url = createWKURL(m_proxy.url);
+    auto excludeHosts = createWKString(m_proxy.excludeHosts);
+    WKWebsiteDataStoreEnableCustomNetworkProxySettings(store, url.get(), excludeHosts.get());
 }
 
 HRESULT WebKitBrowserWindow::init()
@@ -117,14 +145,14 @@ HWND WebKitBrowserWindow::hwnd()
 HRESULT WebKitBrowserWindow::loadURL(const BSTR& url)
 {
     auto page = WKViewGetPage(m_view.get());
-    WKPageLoadURL(page, createWKURL(url).get());
+    WKPageLoadURL(page, createWKURL(_bstr_t(url)).get());
     return true;
 }
 
 HRESULT WebKitBrowserWindow::loadHTMLString(const BSTR& str)
 {
     auto page = WKViewGetPage(m_view.get());
-    auto url = createWKURL(L"about:");
+    auto url = createWKURL(_bstr_t(L"about:"));
     WKPageLoadHTMLString(page, createWKString(_bstr_t(str)).get(), url.get());
     return true;
 }
@@ -170,6 +198,13 @@ void WebKitBrowserWindow::launchInspector()
     WKInspectorShow(inspector);
 }
 
+void WebKitBrowserWindow::openProxySettings()
+{
+    if (askProxySettings(m_hMainWnd, m_proxy))
+        updateProxySettings();
+
+}
+
 void WebKitBrowserWindow::setUserAgent(_bstr_t& customUAString)
 {
     auto page = WKViewGetPage(m_view.get());
index 4266e7c..003b35c 100644 (file)
@@ -25,6 +25,7 @@
 #pragma once
 
 #include "BrowserWindow.h"
+#include "Common.h"
 #include <WebKit/WKRetainPtr.h>
 #include <WebKit/WebKit2_C.h>
 
@@ -46,6 +47,7 @@ private:
 
     void print() override;
     void launchInspector() override;
+    void openProxySettings() override;
 
     _bstr_t userAgent() override;
     void setUserAgent(_bstr_t&) override;
@@ -57,11 +59,15 @@ private:
     void zoomIn() override;
     void zoomOut() override;
 
+    void updateProxySettings();
+
     static void didFinishNavigation(WKPageRef, WKNavigationRef, WKTypeRef, const void*);
     static void didCommitNavigation(WKPageRef, WKNavigationRef, WKTypeRef, const void*);
     static void didReceiveAuthenticationChallenge(WKPageRef, WKAuthenticationChallengeRef, const void*);
 
+    WKRetainPtr<WKContextRef> m_context;
     WKRetainPtr<WKViewRef> m_view;
     HWND m_hMainWnd { nullptr };
     HWND m_urlBarWnd { nullptr };
+    ProxySettings m_proxy { };
 };
index d3f88ba..f6fcd57 100644 (file)
@@ -430,6 +430,10 @@ void WebKitLegacyBrowserWindow::launchInspector()
     m_inspector->show();
 }
 
+void WebKitLegacyBrowserWindow::openProxySettings()
+{
+}
+
 void WebKitLegacyBrowserWindow::navigateForwardOrBackward(UINT menuID)
 {
     if (!m_webView)
index 711e745..ece4eaf 100644 (file)
@@ -71,6 +71,7 @@ private:
 
     void showLastVisitedSites(IWebView&);
     void launchInspector();
+    void openProxySettings();
     void navigateForwardOrBackward(UINT menuID);
     void navigateToHistory(UINT menuID);
     void exitProgram();