Title: [128809] trunk/Source
Revision
128809
Author
[email protected]
Date
2012-09-17 14:43:53 -0700 (Mon, 17 Sep 2012)

Log Message

[WIN] Use BString in favour of BSTR to improve memory management
https://bugs.webkit.org/show_bug.cgi?id=93128

Reviewed by Anders Carlsson.

BString automatically calls SysFreeString() in its destructor which helps
avoiding memory leaks. So it should be used instead of BSTR directly.
Add operator& to BString to allow its usage for out parameters too (like COMPtr).
This fixes already a few memory leaks in the existing code.

* platform/win/BString.cpp:
(WebCore::BString::~BString):
(WebCore::BString::adoptBSTR):
(WebCore::BString::clear):
(WebCore):
* platform/win/BString.h:
(BString):
(WebCore::BString::operator&):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (128808 => 128809)


--- trunk/Source/WebCore/ChangeLog	2012-09-17 21:41:04 UTC (rev 128808)
+++ trunk/Source/WebCore/ChangeLog	2012-09-17 21:43:53 UTC (rev 128809)
@@ -1,3 +1,24 @@
+2012-09-17  Patrick Gansterer  <[email protected]>
+
+        [WIN] Use BString in favour of BSTR to improve memory management
+        https://bugs.webkit.org/show_bug.cgi?id=93128
+
+        Reviewed by Anders Carlsson.
+
+        BString automatically calls SysFreeString() in its destructor which helps
+        avoiding memory leaks. So it should be used instead of BSTR directly.
+        Add operator& to BString to allow its usage for out parameters too (like COMPtr).
+        This fixes already a few memory leaks in the existing code.
+
+        * platform/win/BString.cpp:
+        (WebCore::BString::~BString):
+        (WebCore::BString::adoptBSTR):
+        (WebCore::BString::clear):
+        (WebCore):
+        * platform/win/BString.h:
+        (BString):
+        (WebCore::BString::operator&):
+
 2012-09-17  Tony Chang  <[email protected]>
 
         Make CSS.PrefixUsage histogram smaller to save memory

Modified: trunk/Source/WebCore/platform/win/BString.cpp (128808 => 128809)


--- trunk/Source/WebCore/platform/win/BString.cpp	2012-09-17 21:41:04 UTC (rev 128808)
+++ trunk/Source/WebCore/platform/win/BString.cpp	2012-09-17 21:43:53 UTC (rev 128809)
@@ -106,7 +106,7 @@
 
 BString::~BString()
 {
-    SysFreeString(m_bstr);
+    clear();
 }
 
 BString::BString(const BString& other)
@@ -119,11 +119,15 @@
 
 void BString::adoptBSTR(BSTR bstr)
 {
-    if (m_bstr)
-        SysFreeString(m_bstr);
+    clear();
     m_bstr = bstr;
 }
 
+void BString::clear()
+{
+    SysFreeString(m_bstr);
+}
+
 BString& BString::operator=(const BString& other)
 {
     if (this != &other)

Modified: trunk/Source/WebCore/platform/win/BString.h (128808 => 128809)


--- trunk/Source/WebCore/platform/win/BString.h	2012-09-17 21:41:04 UTC (rev 128808)
+++ trunk/Source/WebCore/platform/win/BString.h	2012-09-17 21:43:53 UTC (rev 128809)
@@ -52,11 +52,13 @@
         ~BString();
 
         void adoptBSTR(BSTR);
+        void clear();
 
         BString(const BString&);
         BString& operator=(const BString&);
         BString& operator=(const BSTR&);
 
+        BSTR* operator&() { ASSERT(!m_bstr); return &m_bstr; }
         operator BSTR() const { return m_bstr; }
 
         BSTR release() { BSTR result = m_bstr; m_bstr = 0; return result; }

Modified: trunk/Source/WebKit/win/DefaultPolicyDelegate.cpp (128808 => 128809)


--- trunk/Source/WebKit/win/DefaultPolicyDelegate.cpp	2012-09-17 21:41:04 UTC (rev 128808)
+++ trunk/Source/WebKit/win/DefaultPolicyDelegate.cpp	2012-09-17 21:43:53 UTC (rev 128809)
@@ -27,6 +27,7 @@
 #include "WebKitDLL.h"
 #include "DefaultPolicyDelegate.h"
 
+#include <WebCore/BString.h>
 #include <WebCore/COMPtr.h>
 #include <wtf/text/WTFString.h>
 
@@ -116,7 +117,7 @@
         else if (navType == WebNavigationTypePlugInRequest)
             listener->use();
         else {
-            BSTR url;
+            BString url;
             // A file URL shouldn't fall through to here, but if it did,
             // it would be a security risk to open it.
             if (SUCCEEDED(request->URL(&url)) && !String(url, SysStringLen(url)).startsWith("file:")) {
@@ -124,7 +125,6 @@
                 ;
             }
             listener->ignore();
-            SysFreeString(url);
         }
     }
     return S_OK;
@@ -152,7 +152,7 @@
     if (FAILED(webView->canShowMIMEType(type, &canShowMIMEType)))
         canShowMIMEType = FALSE;
 
-    BSTR url;
+    BString url;
     request->URL(&url);
 
     if (String(url, SysStringLen(url)).startsWith("file:")) {
@@ -171,7 +171,6 @@
         listener->use();
     else
         listener->ignore();
-    SysFreeString(url);
     return S_OK;
 }
 
@@ -180,15 +179,13 @@
     /*[in]*/ IWebError* error, 
     /*[in]*/ IWebFrame* frame)
 {
-    BSTR errorStr;
+    BString errorStr;
     error->localizedDescription(&errorStr);
 
-    BSTR frameName;
+    BString frameName;
     frame->name(&frameName);
 
     LOG_ERROR("called unableToImplementPolicyWithError:%S inFrame:%S", errorStr ? errorStr : TEXT(""), frameName ? frameName : TEXT(""));
-    SysFreeString(errorStr);
-    SysFreeString(frameName);
 
     return S_OK;
 }

Modified: trunk/Source/WebKit/win/MarshallingHelpers.cpp (128808 => 128809)


--- trunk/Source/WebKit/win/MarshallingHelpers.cpp	2012-09-17 21:41:04 UTC (rev 128808)
+++ trunk/Source/WebKit/win/MarshallingHelpers.cpp	2012-09-17 21:43:53 UTC (rev 128809)
@@ -27,6 +27,7 @@
 #include "WebKitDLL.h"
 #include "MarshallingHelpers.h"
 
+#include <WebCore/BString.h>
 #include <WebCore/IntRect.h>
 #include <WebCore/KURL.h>
 #include <wtf/MathExtras.h>
@@ -46,7 +47,7 @@
 
 BSTR MarshallingHelpers::KURLToBSTR(const KURL& url)
 {
-    return SysAllocStringLen(url.string().characters(), url.string().length());
+    return BString(url.string()).release();
 }
 
 CFURLRef MarshallingHelpers::PathStringToFileCFURLRef(const String& string)
@@ -89,20 +90,7 @@
 
 BSTR MarshallingHelpers::CFStringRefToBSTR(CFStringRef str)
 {
-    if (!str)
-        return 0;
-
-    const UniChar* uniChars = CFStringGetCharactersPtr(str);
-    if (uniChars)
-        return SysAllocStringLen((LPCTSTR)uniChars, CFStringGetLength(str));
-
-    CFIndex length = CFStringGetLength(str);
-    BSTR bstr = SysAllocStringLen(0, length);
-    if (bstr) {
-        CFStringGetCharacters(str, CFRangeMake(0, length), (UniChar*)bstr);
-        bstr[length] = 0;
-    }
-    return bstr;
+    return BString(str).release();
 }
 
 int MarshallingHelpers::CFNumberRefToInt(CFNumberRef num)
@@ -159,9 +147,8 @@
     long count = 0;
     for (CFIndex i=0; i<size; i++) {
         CFStringRef item = (CFStringRef) CFArrayGetValueAtIndex(inArray, i);
-        BSTR bstr = CFStringRefToBSTR(item);
-        ::SafeArrayPutElement(sa, &count, bstr);
-        SysFreeString(bstr);    // SafeArrayPutElement() should make a copy of the string
+        BString bstr(item);
+        ::SafeArrayPutElement(sa, &count, bstr); // SafeArrayPutElement() copies the string correctly.
         count++;
     }
     return sa;
@@ -232,10 +219,9 @@
     if (len > 0) {
         items = new CFStringRef[len];
         for (; lBound <= uBound; lBound++) {
-            BSTR str;
+            BString str;
             hr = ::SafeArrayGetElement(inArray, &lBound, &str);
             items[lBound] = BSTRToCFStringRef(str);
-            SysFreeString(str);
         }
     }
     CFArrayRef result = CFArrayCreate(0, (const void**)items, len, &kCFTypeArrayCallBacks);

Modified: trunk/Source/WebKit/win/WebCoreSupport/WebChromeClient.cpp (128808 => 128809)


--- trunk/Source/WebKit/win/WebCoreSupport/WebChromeClient.cpp	2012-09-17 21:41:04 UTC (rev 128808)
+++ trunk/Source/WebKit/win/WebCoreSupport/WebChromeClient.cpp	2012-09-17 21:43:53 UTC (rev 128809)
@@ -410,17 +410,15 @@
 
     TimerBase::fireTimersInNestedEventLoop();
 
-    BSTR resultBSTR = 0;
+    BString resultBSTR;
     if (FAILED(ui->runJavaScriptTextInputPanelWithPrompt(m_webView, BString(message), BString(defaultValue), &resultBSTR)))
         return false;
 
-    if (resultBSTR) {
-        result = String(resultBSTR, SysStringLen(resultBSTR));
-        SysFreeString(resultBSTR);
-        return true;
-    }
+    if (!resultBSTR)
+        return false;
 
-    return false;
+    result = String(resultBSTR, SysStringLen(resultBSTR));
+    return true;
 }
 
 void WebChromeClient::setStatusbarText(const String& statusText)

Modified: trunk/Source/WebKit/win/WebCoreSupport/WebEditorClient.cpp (128808 => 128809)


--- trunk/Source/WebKit/win/WebCoreSupport/WebEditorClient.cpp	2012-09-17 21:41:04 UTC (rev 128808)
+++ trunk/Source/WebKit/win/WebCoreSupport/WebEditorClient.cpp	2012-09-17 21:43:53 UTC (rev 128809)
@@ -695,21 +695,19 @@
             continue;
         if (FAILED(detailObj->location(&detail.location)))
             continue;
-        BSTR userDesc;
+        BString userDesc;
         if (FAILED(detailObj->userDescription(&userDesc)))
             continue;
         detail.userDescription = String(userDesc, SysStringLen(userDesc));
-        SysFreeString(userDesc);
 
         COMPtr<IEnumSpellingGuesses> enumGuessesObj;
         if (FAILED(detailObj->guesses(&enumGuessesObj)))
             continue;
         while (true) {
-            BSTR guess;
+            BString guess;
             if (enumGuessesObj->Next(1, &guess, &fetched) != S_OK)
                 break;
             detail.guesses.append(String(guess, SysStringLen(guess)));
-            SysFreeString(guess);
         }
 
         details.append(detail);
@@ -778,11 +776,10 @@
 
     while (true) {
         ULONG fetched;
-        BSTR guess;
+        BString guess;
         if (enumGuessesObj->Next(1, &guess, &fetched) != S_OK)
             break;
         guesses.append(String(guess, SysStringLen(guess)));
-        SysFreeString(guess);
     }
 }
 

Modified: trunk/Source/WebKit/win/WebFrame.cpp (128808 => 128809)


--- trunk/Source/WebKit/win/WebFrame.cpp	2012-09-17 21:41:04 UTC (rev 128808)
+++ trunk/Source/WebKit/win/WebFrame.cpp	2012-09-17 21:43:53 UTC (rev 128809)
@@ -1442,11 +1442,10 @@
     COMPtr<IWebURLResponse> urlResponse;
     hr = dataSource->response(&urlResponse);
     if (SUCCEEDED(hr) && urlResponse) {
-        BSTR mimeTypeBStr;
+        BString mimeTypeBStr;
         if (SUCCEEDED(urlResponse->MIMEType(&mimeTypeBStr))) {
             String mimeType(mimeTypeBStr, SysStringLen(mimeTypeBStr));
             *result = mimeType == "text/html" || WebCore::DOMImplementation::isXMLMIMEType(mimeType);
-            SysFreeString(mimeTypeBStr);
         }
     }
     return hr;

Modified: trunk/Source/WebKit/win/WebHistory.cpp (128808 => 128809)


--- trunk/Source/WebKit/win/WebHistory.cpp	2012-09-17 21:41:04 UTC (rev 128808)
+++ trunk/Source/WebKit/win/WebHistory.cpp	2012-09-17 21:43:53 UTC (rev 128809)
@@ -36,6 +36,7 @@
 #include "WebNotificationCenter.h"
 #include "WebPreferences.h"
 #include <CoreFoundation/CoreFoundation.h>
+#include <WebCore/BString.h>
 #include <WebCore/HistoryItem.h>
 #include <WebCore/HistoryPropertyList.h>
 #include <WebCore/KURL.h>
@@ -612,14 +613,13 @@
 HRESULT WebHistory::removeItem(IWebHistoryItem* entry)
 {
     HRESULT hr = S_OK;
-    BSTR urlBStr = 0;
+    BString urlBStr;
 
     hr = entry->URLString(&urlBStr);
     if (FAILED(hr))
         return hr;
 
     RetainPtr<CFStringRef> urlString(AdoptCF, MarshallingHelpers::BSTRToCFStringRef(urlBStr));
-    SysFreeString(urlBStr);
 
     // If this exact object isn't stored, then make no change.
     // FIXME: Is this the right behavior if this entry isn't present, but another entry for the same URL is?
@@ -646,13 +646,12 @@
     if (!entry)
         return E_FAIL;
 
-    BSTR urlBStr = 0;
+    BString urlBStr;
     hr = entry->URLString(&urlBStr);
     if (FAILED(hr))
         return hr;
 
     RetainPtr<CFStringRef> urlString(AdoptCF, MarshallingHelpers::BSTRToCFStringRef(urlBStr));
-    SysFreeString(urlBStr);
 
     COMPtr<IWebHistoryItem> oldEntry((IWebHistoryItem*) CFDictionaryGetValue(
         m_entriesByURL.get(), urlString.get()));

Modified: trunk/Source/WebKit/win/WebIconDatabase.cpp (128808 => 128809)


--- trunk/Source/WebKit/win/WebIconDatabase.cpp	2012-09-17 21:41:04 UTC (rev 128808)
+++ trunk/Source/WebKit/win/WebIconDatabase.cpp	2012-09-17 21:43:53 UTC (rev 128809)
@@ -84,12 +84,11 @@
 
     iconDatabase().setClient(this);
 
-    BSTR prefDatabasePath = 0;
+    BString prefDatabasePath;
     if (FAILED(standardPrefs->iconDatabaseLocation(&prefDatabasePath)))
         LOG_ERROR("Unable to get icon database location preference");
 
     String databasePath(prefDatabasePath, SysStringLen(prefDatabasePath));
-    SysFreeString(prefDatabasePath);
 
     if (databasePath.isEmpty()) {
         databasePath = localUserSpecificStorageDirectory();

Modified: trunk/Source/WebKit/win/WebNotificationCenter.cpp (128808 => 128809)


--- trunk/Source/WebKit/win/WebNotificationCenter.cpp	2012-09-17 21:41:04 UTC (rev 128808)
+++ trunk/Source/WebKit/win/WebNotificationCenter.cpp	2012-09-17 21:43:53 UTC (rev 128809)
@@ -28,6 +28,7 @@
 #include "WebNotificationCenter.h"
 
 #include "WebNotification.h"
+#include <WebCore/BString.h>
 #include <WebCore/COMPtr.h>
 #include <utility>
 #include <wchar.h>
@@ -160,7 +161,7 @@
 HRESULT STDMETHODCALLTYPE WebNotificationCenter::postNotification( 
     /* [in] */ IWebNotification* notification)
 {
-    BSTR name;
+    BString name;
     HRESULT hr = notification->name(&name);
     if (FAILED(hr))
         return hr;
@@ -171,7 +172,6 @@
         return hr;
 
     postNotificationInternal(notification, name, obj.get());
-    SysFreeString(name);
 
     return hr;
 }

Modified: trunk/Source/WebKit/win/WebPreferences.cpp (128808 => 128809)


--- trunk/Source/WebKit/win/WebPreferences.cpp	2012-09-17 21:41:04 UTC (rev 128808)
+++ trunk/Source/WebKit/win/WebPreferences.cpp	2012-09-17 21:43:53 UTC (rev 128809)
@@ -349,10 +349,10 @@
 
 void WebPreferences::setStringValue(CFStringRef key, LPCTSTR value)
 {
-    BSTR val = stringValueForKey(key);
+    BString val;
+    val.adoptBSTR(stringValueForKey(key));
     if (val && !wcscmp(val, value))
         return;
-    SysFreeString(val);
     
     RetainPtr<CFStringRef> valueRef(AdoptCF,
         CFStringCreateWithCharactersNoCopy(0, (UniChar*)_wcsdup(value), (CFIndex)wcslen(value), kCFAllocatorMalloc));

Modified: trunk/Source/WebKit/win/WebView.cpp (128808 => 128809)


--- trunk/Source/WebKit/win/WebView.cpp	2012-09-17 21:41:04 UTC (rev 128808)
+++ trunk/Source/WebKit/win/WebView.cpp	2012-09-17 21:43:53 UTC (rev 128809)
@@ -199,6 +199,21 @@
     return page ? static_cast<WebView*>(static_cast<WebChromeClient*>(page->chrome()->client())->webView()) : 0;
 }
 
+static inline AtomicString toAtomicString(BSTR bstr)
+{
+    return AtomicString(bstr, SysStringLen(bstr));
+}
+
+static inline String toString(BSTR bstr)
+{
+    return String(bstr, SysStringLen(bstr));
+}
+
+static inline KURL toKURL(BSTR bstr)
+{
+    return KURL(KURL(), toString(bstr));
+}
+
 class PreferencesChangedOrRemovedObserver : public IWebNotificationObserver {
 public:
     static PreferencesChangedOrRemovedObserver* sharedInstance();
@@ -245,12 +260,10 @@
     if (FAILED(hr))
         return hr;
 
-    BSTR nameBSTR;
-    hr = notification->name(&nameBSTR);
+    BString name;
+    hr = notification->name(&name);
     if (FAILED(hr))
         return hr;
-    BString name;
-    name.adoptBSTR(nameBSTR);
 
     if (wcscmp(name, WebPreferences::webPreferencesChangedNotification()) == 0)
         return notifyPreferencesChanged(cacheModel);
@@ -726,17 +739,15 @@
     notifyCenter->removeObserver(this, WebPreferences::webPreferencesChangedNotification(), static_cast<IWebPreferences*>(m_preferences.get()));
 
     if (COMPtr<WebPreferences> preferences = m_preferences) {
-        BSTR identifier = 0;
+        BString identifier;
         preferences->identifier(&identifier);
 
         m_preferences = 0;
         preferences->didRemoveFromWebView();
         // Make sure we release the reference, since WebPreferences::removeReferenceForIdentifier will check for last reference to WebPreferences
         preferences = 0;
-        if (identifier) {
+        if (identifier)
             WebPreferences::removeReferenceForIdentifier(identifier);
-            SysFreeString(identifier);
-        }
     }
 
     deleteBackingStore();
@@ -2513,7 +2524,7 @@
     /* [in] */ BSTR mimeType,
     /* [retval][out] */ BOOL* canShow)
 {
-    String mimeTypeStr(mimeType, SysStringLen(mimeType));
+    String mimeTypeStr = toString(mimeType);
 
     if (!canShow)
         return E_POINTER;
@@ -2680,18 +2691,14 @@
     m_page = new Page(pageClients);
     provideGeolocationTo(m_page, new WebGeolocationClient(this));
 
-    BSTR localStoragePath;
-    if (SUCCEEDED(m_preferences->localStorageDatabasePath(&localStoragePath))) {
-        m_page->settings()->setLocalStorageDatabasePath(String(localStoragePath, SysStringLen(localStoragePath)));
-        SysFreeString(localStoragePath);
-    }
+    BString localStoragePath;
+    if (SUCCEEDED(m_preferences->localStorageDatabasePath(&localStoragePath)))
+        m_page->settings()->setLocalStorageDatabasePath(toString(localStoragePath));
 
     if (m_uiDelegate) {
-        BSTR path;
-        if (SUCCEEDED(m_uiDelegate->ftpDirectoryTemplatePath(this, &path))) {
-            m_page->settings()->setFTPDirectoryTemplatePath(String(path, SysStringLen(path)));
-            SysFreeString(path);
-        }
+        BString path;
+        if (SUCCEEDED(m_uiDelegate->ftpDirectoryTemplatePath(this, &path)))
+            m_page->settings()->setFTPDirectoryTemplatePath(toString(path));
     }
 
     WebFrame* webFrame = WebFrame::createInstance();
@@ -2699,7 +2706,7 @@
     m_mainFrame = webFrame;
     webFrame->Release(); // The WebFrame is owned by the Frame, so release our reference to it.
 
-    coreFrame->tree()->setName(String(frameName, SysStringLen(frameName)));
+    coreFrame->tree()->setName(toString(frameName));
     coreFrame->init();
     setGroupName(groupName);
 
@@ -3057,7 +3064,7 @@
 HRESULT STDMETHODCALLTYPE WebView::setApplicationNameForUserAgent( 
     /* [in] */ BSTR applicationName)
 {
-    m_applicationName = String(applicationName, SysStringLen(applicationName));
+    m_applicationName = toString(applicationName);
     m_userAgentStandard = String();
     return S_OK;
 }
@@ -3075,7 +3082,7 @@
     /* [in] */ BSTR userAgentString)
 {
     m_userAgentOverridden = userAgentString;
-    m_userAgentCustom = String(userAgentString, SysStringLen(userAgentString));
+    m_userAgentCustom = toString(userAgentString);
     return S_OK;
 }
 
@@ -3096,7 +3103,7 @@
     /* [retval][out] */ BSTR* userAgent)
 {
     String userAgentString = userAgentForKURL(MarshallingHelpers::BSTRToKURL(url));
-    *userAgent = SysAllocStringLen(userAgentString.characters(), userAgentString.length());
+    *userAgent = BString(userAgentString).release();
     if (!*userAgent && userAgentString.length())
         return E_OUTOFMEMORY;
     return S_OK;
@@ -3116,14 +3123,14 @@
         return E_FAIL;
 
     HRESULT hr;
-    BSTR oldEncoding;
+    BString oldEncoding;
     hr = customTextEncodingName(&oldEncoding);
     if (FAILED(hr))
         return hr;
 
     if (oldEncoding != encodingName && (!oldEncoding || !encodingName || wcscmp(oldEncoding, encodingName))) {
         if (Frame* coreFrame = core(m_mainFrame))
-            coreFrame->loader()->reloadWithOverrideEncoding(String(encodingName, SysStringLen(encodingName)));
+            coreFrame->loader()->reloadWithOverrideEncoding(toString(encodingName));
     }
 
     return S_OK;
@@ -3155,7 +3162,7 @@
         return hr;
 
     if (!*encodingName)
-        *encodingName = SysAllocStringLen(m_overrideEncoding.characters(), m_overrideEncoding.length());
+        *encodingName = BString(m_overrideEncoding).release();
 
     if (!*encodingName && m_overrideEncoding.length())
         return E_OUTOFMEMORY;
@@ -3230,17 +3237,15 @@
     IWebNotificationCenter* nc = WebNotificationCenter::defaultCenterInternal();
     nc->removeObserver(this, WebPreferences::webPreferencesChangedNotification(), static_cast<IWebPreferences*>(m_preferences.get()));
 
-    BSTR identifier = 0;
+    BString identifier;
     oldPrefs->identifier(&identifier);
     oldPrefs->didRemoveFromWebView();
     oldPrefs = 0; // Make sure we release the reference, since WebPreferences::removeReferenceForIdentifier will check for last reference to WebPreferences
 
     m_preferences = webPrefs;
 
-    if (identifier) {
+    if (identifier)
         WebPreferences::removeReferenceForIdentifier(identifier);
-        SysFreeString(identifier);
-    }
 
     nc->addObserver(this, WebPreferences::webPreferencesChangedNotification(), static_cast<IWebPreferences*>(m_preferences.get()));
 
@@ -3388,7 +3393,7 @@
     if (!str || !SysStringLen(str))
         return E_INVALIDARG;
 
-    *found = m_page->findString(String(str, SysStringLen(str)), caseFlag ? TextCaseSensitive : TextCaseInsensitive, forward ? FindDirectionForward : FindDirectionBackward, wrapFlag);
+    *found = m_page->findString(toString(str), caseFlag ? TextCaseSensitive : TextCaseInsensitive, forward ? FindDirectionForward : FindDirectionBackward, wrapFlag);
     return S_OK;
 }
 
@@ -3418,13 +3423,10 @@
     return S_OK;
 }
 
-HRESULT STDMETHODCALLTYPE WebView::executeCoreCommandByName(BSTR bName, BSTR bValue)
+HRESULT STDMETHODCALLTYPE WebView::executeCoreCommandByName(BSTR name, BSTR value)
 {
-    String name(bName, SysStringLen(bName));
-    String value(bValue, SysStringLen(bValue));
+    m_page->focusController()->focusedOrMainFrame()->editor()->command(toString(name)).execute(toString(value));
 
-    m_page->focusController()->focusedOrMainFrame()->editor()->command(name).execute(value);
-
     return S_OK;
 }
 
@@ -3447,7 +3449,7 @@
     if (!str || !SysStringLen(str))
         return E_INVALIDARG;
 
-    *matches = m_page->markAllMatchesForText(String(str, SysStringLen(str)), caseSensitive ? TextCaseSensitive : TextCaseInsensitive, highlight, limit);
+    *matches = m_page->markAllMatchesForText(toString(str), caseSensitive ? TextCaseSensitive : TextCaseInsensitive, highlight, limit);
     return S_OK;
 }
 
@@ -3530,7 +3532,7 @@
 {
     if (!m_page)
         return S_OK;
-    m_page->setGroupName(String(groupName, SysStringLen(groupName)));
+    m_page->setGroupName(toString(groupName));
     return S_OK;
 }
     
@@ -3764,7 +3766,7 @@
     if (!scheme)
         return E_POINTER;
 
-    SchemeRegistry::registerURLSchemeAsLocal(String(scheme, ::SysStringLen(scheme)));
+    SchemeRegistry::registerURLSchemeAsLocal(toString(scheme));
 
     return S_OK;
 }
@@ -4315,9 +4317,8 @@
 HRESULT STDMETHODCALLTYPE WebView::replaceSelectionWithText( 
         /* [in] */ BSTR text)
 {
-    String textString(text, ::SysStringLen(text));
     Position start = m_page->mainFrame()->selection()->selection().start();
-    m_page->focusController()->focusedOrMainFrame()->editor()->insertText(textString, 0);
+    m_page->focusController()->focusedOrMainFrame()->editor()->insertText(toString(text), 0);
     m_page->mainFrame()->selection()->setBase(start);
     return S_OK;
 }
@@ -4536,14 +4537,11 @@
 HRESULT STDMETHODCALLTYPE WebView::onNotify( 
     /* [in] */ IWebNotification* notification)
 {
-    BSTR nameBSTR;
-    HRESULT hr = notification->name(&nameBSTR);
+    BString name;
+    HRESULT hr = notification->name(&name);
     if (FAILED(hr))
         return hr;
 
-    BString name;
-    name.adoptBSTR(nameBSTR);
-
     if (!wcscmp(name, WebIconDatabase::iconDatabaseDidAddIconNotification()))
         return notifyDidAddIcon(notification);
 
@@ -4568,7 +4566,7 @@
 
     ASSERT(preferences == m_preferences);
 
-    BSTR str;
+    BString str;
     int size;
     BOOL enabled;
 
@@ -4577,8 +4575,8 @@
     hr = preferences->cursiveFontFamily(&str);
     if (FAILED(hr))
         return hr;
-    settings->setCursiveFontFamily(AtomicString(str, SysStringLen(str)));
-    SysFreeString(str);
+    settings->setCursiveFontFamily(toAtomicString(str));
+    str.clear();
 
     hr = preferences->defaultFixedFontSize(&size);
     if (FAILED(hr))
@@ -4589,24 +4587,24 @@
     if (FAILED(hr))
         return hr;
     settings->setDefaultFontSize(size);
-    
+
     hr = preferences->defaultTextEncodingName(&str);
     if (FAILED(hr))
         return hr;
-    settings->setDefaultTextEncodingName(String(str, SysStringLen(str)));
-    SysFreeString(str);
+    settings->setDefaultTextEncodingName(toString(str));
+    str.clear();
 
     hr = preferences->fantasyFontFamily(&str);
     if (FAILED(hr))
         return hr;
-    settings->setFantasyFontFamily(AtomicString(str, SysStringLen(str)));
-    SysFreeString(str);
+    settings->setFantasyFontFamily(toAtomicString(str));
+    str.clear();
 
     hr = preferences->fixedFontFamily(&str);
     if (FAILED(hr))
         return hr;
-    settings->setFixedFontFamily(AtomicString(str, SysStringLen(str)));
-    SysFreeString(str);
+    settings->setFixedFontFamily(toAtomicString(str));
+    str.clear();
 
 #if ENABLE(VIDEO_TRACK)
     hr = preferences->shouldDisplaySubtitles(&enabled);
@@ -4630,15 +4628,15 @@
         hr = prefsPrivate->localStorageDatabasePath(&str);
         if (FAILED(hr))
             return hr;
-        settings->setLocalStorageDatabasePath(String(str, SysStringLen(str)));
-        SysFreeString(str);
+        settings->setLocalStorageDatabasePath(toString(str));
+        str.clear();
     }
 
     hr = preferences->pictographFontFamily(&str);
     if (FAILED(hr))
         return hr;
-    settings->setPictographFontFamily(AtomicString(str, SysStringLen(str)));
-    SysFreeString(str);
+    settings->setPictographFontFamily(toAtomicString(str));
+    str.clear();
 
     hr = preferences->isJavaEnabled(&enabled);
     if (FAILED(hr))
@@ -4683,20 +4681,20 @@
     hr = preferences->sansSerifFontFamily(&str);
     if (FAILED(hr))
         return hr;
-    settings->setSansSerifFontFamily(AtomicString(str, SysStringLen(str)));
-    SysFreeString(str);
+    settings->setSansSerifFontFamily(toAtomicString(str));
+    str.clear();
 
     hr = preferences->serifFontFamily(&str);
     if (FAILED(hr))
         return hr;
-    settings->setSerifFontFamily(AtomicString(str, SysStringLen(str)));
-    SysFreeString(str);
+    settings->setSerifFontFamily(toAtomicString(str));
+    str.clear();
 
     hr = preferences->standardFontFamily(&str);
     if (FAILED(hr))
         return hr;
-    settings->setStandardFontFamily(AtomicString(str, SysStringLen(str)));
-    SysFreeString(str);
+    settings->setStandardFontFamily(toAtomicString(str));
+    str.clear();
 
     hr = preferences->loadsImagesAutomatically(&enabled);
     if (FAILED(hr))
@@ -4711,7 +4709,7 @@
         if (FAILED(hr))
             return hr;
 
-        RetainPtr<CFStringRef> urlString(AdoptCF, String(str, SysStringLen(str)).createCFString());
+        RetainPtr<CFStringRef> urlString(AdoptCF, toString(str).createCFString());
         RetainPtr<CFURLRef> url(AdoptCF, CFURLCreateWithString(kCFAllocatorDefault, urlString.get(), 0));
 
         // Check if the passed in string is a path and convert it to a URL.
@@ -4729,10 +4727,9 @@
         }
 
         settings->setUserStyleSheetLocation(url.get());
-        SysFreeString(str);
-    } else {
+        str.clear();
+    } else
         settings->setUserStyleSheetLocation(KURL());
-    }
 
     hr = preferences->shouldPrintBackgrounds(&enabled);
     if (FAILED(hr))
@@ -4978,10 +4975,8 @@
     if (!mimeType)
         return E_POINTER;
 
-    String extensionStr(extension, SysStringLen(extension));
+    *mimeType = BString(MIMETypeRegistry::getMIMETypeForExtension(toString(extension))).release();
 
-    *mimeType = BString(MIMETypeRegistry::getMIMETypeForExtension(extensionStr)).release();
-
     return S_OK;
 }
 
@@ -5228,8 +5223,7 @@
         return E_POINTER;
     }
 
-    BString applicationNameBString(applicationName);
-    *groupName = BString(standardUserAgentWithApplicationName(String(applicationNameBString, SysStringLen(applicationNameBString)))).release();
+    *groupName = BString(standardUserAgentWithApplicationName(toString(applicationName))).release();
     return S_OK;
 }
 
@@ -5284,7 +5278,7 @@
 HRESULT STDMETHODCALLTYPE WebView::addAdditionalPluginDirectory( 
         /* [in] */ BSTR directory)
 {
-    PluginDatabase::installedPlugins()->addExtraPluginDirectory(String(directory, SysStringLen(directory)));
+    PluginDatabase::installedPlugins()->addExtraPluginDirectory(toString(directory));
     return S_OK;
 }
 
@@ -6118,7 +6112,7 @@
     if (!m_embeddedViewMIMETypes)
         m_embeddedViewMIMETypes = adoptPtr(new HashSet<String>);
 
-    m_embeddedViewMIMETypes->add(String(mimeType, ::SysStringLen(mimeType)));
+    m_embeddedViewMIMETypes->add(toString(mimeType));
     return S_OK;
 }
 
@@ -6190,16 +6184,6 @@
     return S_OK;
 }
 
-static String toString(BSTR bstr)
-{
-    return String(bstr, SysStringLen(bstr));
-}
-
-static KURL toKURL(BSTR bstr)
-{
-    return KURL(KURL(), toString(bstr));
-}
-
 void WebView::enterFullscreenForNode(Node* node)
 {
     if (!node->hasTagName(HTMLNames::videoTag) || !node->isElementNode())
@@ -6415,13 +6399,13 @@
 
 HRESULT WebView::addOriginAccessWhitelistEntry(BSTR sourceOrigin, BSTR destinationProtocol, BSTR destinationHost, BOOL allowDestinationSubdomains)
 {
-    SecurityPolicy::addOriginAccessWhitelistEntry(*SecurityOrigin::createFromString(String(sourceOrigin, SysStringLen(sourceOrigin))), String(destinationProtocol, SysStringLen(destinationProtocol)), String(destinationHost, SysStringLen(destinationHost)), allowDestinationSubdomains);
+    SecurityPolicy::addOriginAccessWhitelistEntry(*SecurityOrigin::createFromString(toString(sourceOrigin)), toString(destinationProtocol), toString(destinationHost), allowDestinationSubdomains);
     return S_OK;
 }
 
 HRESULT WebView::removeOriginAccessWhitelistEntry(BSTR sourceOrigin, BSTR destinationProtocol, BSTR destinationHost, BOOL allowDestinationSubdomains)
 {
-    SecurityPolicy::removeOriginAccessWhitelistEntry(*SecurityOrigin::createFromString(String(sourceOrigin, SysStringLen(sourceOrigin))), String(destinationProtocol, SysStringLen(destinationProtocol)), String(destinationHost, SysStringLen(destinationHost)), allowDestinationSubdomains);
+    SecurityPolicy::removeOriginAccessWhitelistEntry(*SecurityOrigin::createFromString(toString(sourceOrigin)), toString(destinationProtocol), toString(destinationHost), allowDestinationSubdomains);
     return S_OK;
 }
 
@@ -6598,20 +6582,18 @@
     if (!error)
         return E_POINTER;
 
-    BSTR descriptionBSTR;
-    if (FAILED(error->localizedDescription(&descriptionBSTR)))
+    BString description;
+    if (FAILED(error->localizedDescription(&description)))
         return E_FAIL;
-    String descriptionString(descriptionBSTR, SysStringLen(descriptionBSTR));
-    SysFreeString(descriptionBSTR);
 
-    RefPtr<GeolocationError> geolocationError = GeolocationError::create(GeolocationError::PositionUnavailable, descriptionString);
+    RefPtr<GeolocationError> geolocationError = GeolocationError::create(GeolocationError::PositionUnavailable, toString(description));
     GeolocationController::from(m_page)->errorOccurred(geolocationError.get());
     return S_OK;
 }
 
 HRESULT WebView::setDomainRelaxationForbiddenForURLScheme(BOOL forbidden, BSTR scheme)
 {
-    SchemeRegistry::setDomainRelaxationForbiddenForURLScheme(forbidden, String(scheme, SysStringLen(scheme)));
+    SchemeRegistry::setDomainRelaxationForbiddenForURLScheme(forbidden, toString(scheme));
     return S_OK;
 }
 
@@ -6906,7 +6888,7 @@
     if (!frame || !frame->editor()->canEdit())
         return E_FAIL;
 
-    String compositionStr(composition, SysStringLen(composition));
+    String compositionStr = toString(composition);
 
     Vector<CompositionUnderline> underlines;
     underlines.append(CompositionUnderline(0, compositionStr.length(), Color(Color::black), false));
@@ -6938,7 +6920,7 @@
     if (!frame || !frame->editor()->canEdit())
         return E_FAIL;
 
-    String compositionStr(composition, SysStringLen(composition));
+    String compositionStr = toString(composition);
 
     if (compositionStr.isNull())
         frame->editor()->confirmComposition();
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to