[haiku-webkit-commits] r468 - in webkit/trunk/WebKit/haiku: API WebPositive

  • From: webkit@xxxxxxxxxxxxxxx
  • To: haiku-webkit-commits@xxxxxxxxxxxxx
  • Date: Fri, 30 Apr 2010 17:49:22 +0000

Author: stippi
Date: Fri Apr 30 17:49:21 2010
New Revision: 468
URL: http://mmlr.dyndns.org/changeset/468

Log:
* Added page for proxy server configuration to the Settings window.
* Added necessary wiring in BWebSettings for proxy server configuration.

Actual proxy server usage untested, feedback welcome.

Modified:
   webkit/trunk/WebKit/haiku/API/WebSettings.cpp
   webkit/trunk/WebKit/haiku/API/WebSettings.h
   webkit/trunk/WebKit/haiku/WebPositive/SettingsKeys.cpp
   webkit/trunk/WebKit/haiku/WebPositive/SettingsKeys.h
   webkit/trunk/WebKit/haiku/WebPositive/SettingsWindow.cpp
   webkit/trunk/WebKit/haiku/WebPositive/SettingsWindow.h

Modified: webkit/trunk/WebKit/haiku/API/WebSettings.cpp
==============================================================================
--- webkit/trunk/WebKit/haiku/API/WebSettings.cpp       Fri Apr 30 16:33:17 
2010        (r467)
+++ webkit/trunk/WebKit/haiku/API/WebSettings.cpp       Fri Apr 30 17:49:21 
2010        (r468)
@@ -34,6 +34,7 @@
 #include "IconDatabase.h"
 #include "Image.h"
 #include "IntSize.h"
+#include "ResourceHandleManager.h"
 #include "Settings.h"
 #include "WebSettingsPrivate.h"
 #include <Application.h>
@@ -57,6 +58,7 @@
        HANDLE_SET_LOCAL_STORAGE_PATH = 'hslp',
        HANDLE_SET_FONT = 'hsfn',
        HANDLE_SET_FONT_SIZE = 'hsfs',
+       HANDLE_SET_PROXY_INFO = 'hspi',
        HANDLE_APPLY = 'hapl'
 };
 
@@ -186,6 +188,18 @@
     _PostFontSize(FIXED_FONT_SIZE, size);
 }
 
+void BWebSettings::SetProxyInfo(const BString& host, uint32 port,
+       BProxyType type, const BString& username, const BString& password)
+{
+       BMessage message(HANDLE_SET_PROXY_INFO);
+       message.AddString("host", host);
+       message.AddUInt32("port", port);
+       message.AddUInt32("type", type);
+       message.AddString("username", username);
+       message.AddString("password", password);
+       _PostMessage(Default(), &message);
+}
+
 void BWebSettings::Apply()
 {
     Looper()->PostMessage(HANDLE_APPLY, this);
@@ -300,6 +314,11 @@
        case HANDLE_SET_FONT_SIZE:
                _HandleSetFontSize(message);
                break;
+
+       case HANDLE_SET_PROXY_INFO:
+               _HandleSetProxyInfo(message);
+               break;
+
        case HANDLE_APPLY:
                _HandleApply();
                break;
@@ -476,6 +495,43 @@
        }
 }
 
+void BWebSettings::_HandleSetProxyInfo(BMessage* message)
+{
+       BString host;
+       uint32 port;
+       BProxyType type;
+       BString username;
+       BString password;
+       if (message->FindString("host", &host) != B_OK
+               || message->FindUInt32("port", &port) != B_OK
+               || message->FindUInt32("type", 
reinterpret_cast<uint32*>(&type)) != B_OK
+               || message->FindString("username", &username) != B_OK
+               || message->FindString("password", &password) != B_OK)
+               return;
+
+       WebCore::ResourceHandleManager::ProxyType curlProxyType;
+       switch (type) {
+       case B_PROXY_TYPE_HTTP:
+               curlProxyType = WebCore::ResourceHandleManager::HTTP;
+               break;
+       case B_PROXY_TYPE_SOCKS4:
+               curlProxyType = WebCore::ResourceHandleManager::Socks4;
+               break;
+       case B_PROXY_TYPE_SOCKS4A:
+               curlProxyType = WebCore::ResourceHandleManager::Socks4A;
+               break;
+       case B_PROXY_TYPE_SOCKS5:
+               curlProxyType = WebCore::ResourceHandleManager::Socks5;
+               break;
+       case B_PROXY_TYPE_SOCKS5_HOSTNAME:
+               curlProxyType = WebCore::ResourceHandleManager::Socks5Hostname;
+               break;
+       }
+
+       WebCore::ResourceHandleManager::sharedInstance()->setProxyInfo(host, 
port,
+               curlProxyType, username, password);
+}
+
 void BWebSettings::_HandleApply()
 {
        fData->apply();

Modified: webkit/trunk/WebKit/haiku/API/WebSettings.h
==============================================================================
--- webkit/trunk/WebKit/haiku/API/WebSettings.h Fri Apr 30 16:33:17 2010        
(r467)
+++ webkit/trunk/WebKit/haiku/API/WebSettings.h Fri Apr 30 17:49:21 2010        
(r468)
@@ -44,6 +44,16 @@
 class WebSettingsPrivate;
 }
 
+
+enum BProxyType {
+       B_PROXY_TYPE_HTTP = 0,
+       B_PROXY_TYPE_SOCKS4 = 1,
+       B_PROXY_TYPE_SOCKS4A = 2,
+       B_PROXY_TYPE_SOCKS5 = 3,
+       B_PROXY_TYPE_SOCKS5_HOSTNAME = 4
+};
+
+
 class BWebSettings : public BHandler {
 // TODO: Inherit from BReferenceable.
 public:
@@ -81,6 +91,12 @@
                        void                            
SetDefaultStandardFontSize(float size);
                        void                            
SetDefaultFixedFontSize(float size);
 
+       static  void                            SetProxyInfo(const BString& 
host = "",
+                                                                       uint32 
port = 0,
+                                                                       
BProxyType type = B_PROXY_TYPE_HTTP,
+                                                                       const 
BString& username = "",
+                                                                       const 
BString& password = "");
+
                        void                            Apply();
 
 private:
@@ -111,6 +127,7 @@
                        void                            
_HandleSetLocalStoragePath(const BString& path);
                        void                            
_HandleSetFont(BMessage* message);
                        void                            
_HandleSetFontSize(BMessage* message);
+                       void                            
_HandleSetProxyInfo(BMessage* message);
                        void                            _HandleApply();
 private:
                        BPrivate::WebSettingsPrivate* fData;

Modified: webkit/trunk/WebKit/haiku/WebPositive/SettingsKeys.cpp
==============================================================================
--- webkit/trunk/WebKit/haiku/WebPositive/SettingsKeys.cpp      Fri Apr 30 
16:33:17 2010        (r467)
+++ webkit/trunk/WebKit/haiku/WebPositive/SettingsKeys.cpp      Fri Apr 30 
17:49:21 2010        (r468)
@@ -42,3 +42,6 @@
        = "file:///boot/system/documentation/welcome/welcome_en.html";
 const char* kDefaultSearchPageURL = "http://www.google.com";;
 
+const char* kSettingsKeyUseProxy = "use http proxy";
+const char* kSettingsKeyProxyAddress = "http proxy address";
+const char* kSettingsKeyProxyPort = "http proxy port";

Modified: webkit/trunk/WebKit/haiku/WebPositive/SettingsKeys.h
==============================================================================
--- webkit/trunk/WebKit/haiku/WebPositive/SettingsKeys.h        Fri Apr 30 
16:33:17 2010        (r467)
+++ webkit/trunk/WebKit/haiku/WebPositive/SettingsKeys.h        Fri Apr 30 
17:49:21 2010        (r468)
@@ -42,4 +42,8 @@
 extern const char* kDefaultStartPageURL;
 extern const char* kDefaultSearchPageURL;
 
+extern const char* kSettingsKeyUseProxy;
+extern const char* kSettingsKeyProxyAddress;
+extern const char* kSettingsKeyProxyPort;
+
 #endif // SETTINGS_KEYS_H

Modified: webkit/trunk/WebKit/haiku/WebPositive/SettingsWindow.cpp
==============================================================================
--- webkit/trunk/WebKit/haiku/WebPositive/SettingsWindow.cpp    Fri Apr 30 
16:33:17 2010        (r467)
+++ webkit/trunk/WebKit/haiku/WebPositive/SettingsWindow.cpp    Fri Apr 30 
17:49:21 2010        (r468)
@@ -78,6 +78,10 @@
 
        MSG_STANDARD_FONT_SIZE_SELECTED         = 'sfss',
        MSG_FIXED_FONT_SIZE_SELECTED            = 'ffss',
+
+       MSG_USE_PROXY_CHANGED                           = 'upsc',
+       MSG_PROXY_ADDRESS_CHANGED                       = 'psac',
+       MSG_PROXY_PORT_CHANGED                          = 'pspc',
 };
 
 static const int32 kDefaultFontSize = 14;
@@ -112,6 +116,7 @@
 
        tabView->AddTab(_CreateGeneralPage(spacing));
        tabView->AddTab(_CreateFontsPage(spacing));
+       tabView->AddTab(_CreateProxyPage(spacing));
 
        _SetupFontSelectionView(fStandardFontView,
                new BMessage(MSG_STANDARD_FONT_CHANGED));
@@ -172,14 +177,14 @@
                        fStandardFontView->SetSize(size);
                        fSerifFontView->SetSize(size);
                        fSansSerifFontView->SetSize(size);
-                       _ValidateButtonsEnabled();
+                       _ValidateControlsEnabledStatus();
                        break;
                }
                case MSG_FIXED_FONT_SIZE_SELECTED:
                {
                        int32 size = _SizesMenuValue(fFixedSizesMenu->Menu());
                        fFixedFontView->SetSize(size);
-                       _ValidateButtonsEnabled();
+                       _ValidateControlsEnabledStatus();
                        break;
                }
 
@@ -194,8 +199,11 @@
                case MSG_SERIF_FONT_CHANGED:
                case MSG_SANS_SERIF_FONT_CHANGED:
                case MSG_FIXED_FONT_CHANGED:
+               case MSG_USE_PROXY_CHANGED:
+               case MSG_PROXY_ADDRESS_CHANGED:
+               case MSG_PROXY_PORT_CHANGED:
                        // TODO: Some settings could change live, some others 
not?
-                       _ValidateButtonsEnabled();
+                       _ValidateControlsEnabledStatus();
                        break;
 
                default:
@@ -329,7 +337,7 @@
 
                .SetInsets(spacing, spacing, spacing, spacing)
        ;
-       view->SetName("General");
+       view->SetName(TR("General"));
        return view;
 }
 
@@ -383,7 +391,48 @@
 
                .SetInsets(spacing, spacing, spacing, spacing)
        ;
-       view->SetName("Fonts");
+       view->SetName(TR("Fonts"));
+       return view;
+}
+
+
+BView*
+SettingsWindow::_CreateProxyPage(float spacing)
+{
+       fUseProxyCheckBox = new BCheckBox("use proxy",
+               TR("Use proxy server to connect to the internet."),
+               new BMessage(MSG_USE_PROXY_CHANGED));
+       fUseProxyCheckBox->SetValue(B_CONTROL_ON);
+
+       fProxyAddressControl = new BTextControl("proxy address",
+               TR("Proxy server address:"), "",
+               new BMessage(MSG_PROXY_ADDRESS_CHANGED));
+       fProxyAddressControl->SetModificationMessage(
+               new BMessage(MSG_PROXY_ADDRESS_CHANGED));
+       fProxyAddressControl->SetText(
+               fSettings->GetValue(kSettingsKeyProxyAddress, ""));
+
+       fProxyPortControl = new BTextControl("proxy port",
+               TR("Proxy server port:"), "", new 
BMessage(MSG_PROXY_PORT_CHANGED));
+       fProxyPortControl->SetModificationMessage(
+               new BMessage(MSG_PROXY_PORT_CHANGED));
+       fProxyPortControl->SetText(
+               fSettings->GetValue(kSettingsKeyProxyAddress, ""));
+
+       BView* view = BGroupLayoutBuilder(B_VERTICAL, spacing / 2)
+               .Add(fUseProxyCheckBox)
+               .Add(BGridLayoutBuilder(spacing / 2, spacing / 2)
+                       .Add(fProxyAddressControl->CreateLabelLayoutItem(), 0, 
0)
+                       .Add(fProxyAddressControl->CreateTextViewLayoutItem(), 
1, 0)
+               
+                       .Add(fProxyPortControl->CreateLabelLayoutItem(), 0, 1)
+                       .Add(fProxyPortControl->CreateTextViewLayoutItem(), 1, 
1)
+               )
+               .Add(BSpaceLayoutItem::CreateGlue())
+
+               .SetInsets(spacing, spacing, spacing, spacing)
+       ;
+       view->SetName(TR("Proxy server"));
        return view;
 }
 
@@ -482,6 +531,16 @@
        canApply = canApply || (_SizesMenuValue(fFixedSizesMenu->Menu())
                != fSettings->GetValue("fixed font size", kDefaultFontSize));
 
+       // Proxy settings
+       canApply = canApply || ((fUseProxyCheckBox->Value() == B_CONTROL_ON)
+               != fSettings->GetValue(kSettingsKeyUseProxy, false));
+
+       canApply = canApply || (strcmp(fProxyAddressControl->Text(),
+               fSettings->GetValue(kSettingsKeyProxyAddress, "")) != 0);
+
+       canApply = canApply || (_ProxyPort()
+               != fSettings->GetValue(kSettingsKeyProxyPort, (uint32)0));
+
        return canApply;
 }
 
@@ -516,6 +575,15 @@
        fSettings->SetValue("standard font size", standardFontSize);
        fSettings->SetValue("fixed font size", fixedFontSize);
 
+       // Store proxy settings
+
+       fSettings->SetValue(kSettingsKeyUseProxy,
+               fUseProxyCheckBox->Value() == B_CONTROL_ON);
+       fSettings->SetValue(kSettingsKeyProxyAddress,
+               fProxyAddressControl->Text());
+       uint32 proxyPort = _ProxyPort();
+       fSettings->SetValue(kSettingsKeyProxyPort, proxyPort);
+
        fSettings->Save();
 
        // Apply settings to default web page settings.
@@ -526,12 +594,18 @@
        BWebSettings::Default()->SetDefaultStandardFontSize(standardFontSize);
        BWebSettings::Default()->SetDefaultFixedFontSize(fixedFontSize);
 
+       if (fUseProxyCheckBox->Value() == B_CONTROL_ON) {
+               
BWebSettings::Default()->SetProxyInfo(fProxyAddressControl->Text(),
+                       proxyPort, B_PROXY_TYPE_HTTP, "", "");
+       } else
+               BWebSettings::Default()->SetProxyInfo();
+
        // This will find all currently instantiated page settings and apply
        // the default values, unless the page settings have local overrides.
        BWebSettings::Default()->Apply();
 
 
-       _ValidateButtonsEnabled();
+       _ValidateControlsEnabledStatus();
 }
 
 
@@ -606,12 +680,21 @@
        fFixedFontView->SetFont(fSettings->GetValue("fixed font",
                *be_fixed_font), defaultFixedFontSize);
 
-       _ValidateButtonsEnabled();
+       // Proxy settings
+       fUseProxyCheckBox->SetValue(fSettings->GetValue(kSettingsKeyUseProxy,
+               false));
+       
fProxyAddressControl->SetText(fSettings->GetValue(kSettingsKeyProxyAddress,
+               ""));
+       text = "";
+       text << fSettings->GetValue(kSettingsKeyProxyPort, (uint32)0);
+       fProxyPortControl->SetText(text.String());
+
+       _ValidateControlsEnabledStatus();
 }
 
 
 void
-SettingsWindow::_ValidateButtonsEnabled()
+SettingsWindow::_ValidateControlsEnabledStatus()
 {
        bool canApply = _CanApplySettings();
        fApplyButton->SetEnabled(canApply);
@@ -619,6 +702,10 @@
        // Let the Cancel button be enabled always, as another way to close the
        // window...
        fCancelButton->SetEnabled(true);
+
+       bool useProxy = fUseProxyCheckBox->Value() == B_CONTROL_ON;
+       fProxyAddressControl->SetEnabled(useProxy);
+       fProxyPortControl->SetEnabled(useProxy);
 }
 
 
@@ -714,3 +801,12 @@
        }
        return serifFont;
 }
+
+
+uint32
+SettingsWindow::_ProxyPort() const
+{
+       return atoul(fProxyPortControl->Text());
+}
+
+

Modified: webkit/trunk/WebKit/haiku/WebPositive/SettingsWindow.h
==============================================================================
--- webkit/trunk/WebKit/haiku/WebPositive/SettingsWindow.h      Fri Apr 30 
16:33:17 2010        (r467)
+++ webkit/trunk/WebKit/haiku/WebPositive/SettingsWindow.h      Fri Apr 30 
17:49:21 2010        (r468)
@@ -53,6 +53,7 @@
 private:
                        BView*                          
_CreateGeneralPage(float spacing);
                        BView*                          _CreateFontsPage(float 
spacing);
+                       BView*                          _CreateProxyPage(float 
spacing);
                        void                            _BuildSizesMenu(BMenu* 
menu,
                                                                        uint32 
messageWhat);
                        void                            _SetupFontSelectionView(
@@ -62,7 +63,7 @@
                        bool                            _CanApplySettings() 
const;
                        void                            _ApplySettings();
                        void                            _RevertSettings();
-                       void                            
_ValidateButtonsEnabled();
+                       void                            
_ValidateControlsEnabledStatus();
 
                        uint32                          _NewWindowPolicy() 
const;
                        uint32                          _NewTabPolicy() const;
@@ -73,6 +74,8 @@
 
                        BFont                           _FindDefaultSerifFont() 
const;
 
+                       uint32                          _ProxyPort() const;
+
 private:
                        SettingsMessage*        fSettings;
 
@@ -99,6 +102,10 @@
                        FontSelectionView*      fSansSerifFontView;
                        FontSelectionView*      fFixedFontView;
 
+                       BCheckBox*                      fUseProxyCheckBox;
+                       BTextControl*           fProxyAddressControl;
+                       BTextControl*           fProxyPortControl;
+
                        BButton*                        fApplyButton;
                        BButton*                        fCancelButton;
                        BButton*                        fRevertButton;

Other related posts:

  • » [haiku-webkit-commits] r468 - in webkit/trunk/WebKit/haiku: API WebPositive - webkit