diff options
Diffstat (limited to 'Source/WebKit/win')
| -rw-r--r-- | Source/WebKit/win/ChangeLog | 70 | ||||
| -rw-r--r-- | Source/WebKit/win/DefaultPolicyDelegate.cpp | 15 | ||||
| -rw-r--r-- | Source/WebKit/win/MarshallingHelpers.cpp | 26 | ||||
| -rw-r--r-- | Source/WebKit/win/WebCoreSupport/WebChromeClient.cpp | 12 | ||||
| -rw-r--r-- | Source/WebKit/win/WebCoreSupport/WebEditorClient.cpp | 9 | ||||
| -rw-r--r-- | Source/WebKit/win/WebFrame.cpp | 3 | ||||
| -rw-r--r-- | Source/WebKit/win/WebHistory.cpp | 7 | ||||
| -rw-r--r-- | Source/WebKit/win/WebIconDatabase.cpp | 3 | ||||
| -rw-r--r-- | Source/WebKit/win/WebNotificationCenter.cpp | 6 | ||||
| -rw-r--r-- | Source/WebKit/win/WebPreferences.cpp | 4 | ||||
| -rw-r--r-- | Source/WebKit/win/WebView.cpp | 176 |
11 files changed, 181 insertions, 150 deletions
diff --git a/Source/WebKit/win/ChangeLog b/Source/WebKit/win/ChangeLog index 73b494a9f..5e7a2d4e2 100644 --- a/Source/WebKit/win/ChangeLog +++ b/Source/WebKit/win/ChangeLog @@ -1,3 +1,73 @@ +2012-09-19 Patrick Gansterer <paroga@webkit.org> + + [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. + + * DefaultPolicyDelegate.cpp: + (DefaultPolicyDelegate::decidePolicyForNavigationAction): + (DefaultPolicyDelegate::decidePolicyForMIMEType): + (DefaultPolicyDelegate::unableToImplementPolicyWithError): + * MarshallingHelpers.cpp: + (MarshallingHelpers::KURLToBSTR): + (MarshallingHelpers::CFStringRefToBSTR): + (MarshallingHelpers::stringArrayToSafeArray): + (MarshallingHelpers::safeArrayToStringArray): + * WebCoreSupport/WebChromeClient.cpp: + (WebChromeClient::runJavaScriptPrompt): + * WebCoreSupport/WebEditorClient.cpp: + (WebEditorClient::checkGrammarOfString): + (WebEditorClient::getGuessesForWord): + * WebFrame.cpp: + (WebFrame::canProvideDocumentSource): + * WebHistory.cpp: + (WebHistory::removeItem): + (WebHistory::addItem): + * WebIconDatabase.cpp: + (WebIconDatabase::startUpIconDatabase): + * WebNotificationCenter.cpp: + (WebNotificationCenter::postNotification): + * WebPreferences.cpp: + (WebPreferences::setStringValue): + * WebView.cpp: + (toAtomicString): + (toString): + (toKURL): + (PreferencesChangedOrRemovedObserver::onNotify): + (WebView::close): + (WebView::canShowMIMEType): + (WebView::initWithFrame): + (WebView::setApplicationNameForUserAgent): + (WebView::setCustomUserAgent): + (WebView::userAgentForURL): + (WebView::setCustomTextEncodingName): + (WebView::customTextEncodingName): + (WebView::setPreferences): + (WebView::searchFor): + (WebView::executeCoreCommandByName): + (WebView::markAllMatchesForText): + (WebView::setGroupName): + (WebView::registerURLSchemeAsLocal): + (WebView::replaceSelectionWithText): + (WebView::onNotify): + (WebView::notifyPreferencesChanged): + (WebView::MIMETypeForExtension): + (WebView::standardUserAgentWithApplicationName): + (WebView::addAdditionalPluginDirectory): + (WebView::registerEmbeddedViewMIMEType): + (WebView::addOriginAccessWhitelistEntry): + (WebView::removeOriginAccessWhitelistEntry): + (WebView::geolocationDidFailWithError): + (WebView::setDomainRelaxationForbiddenForURLScheme): + (WebView::setCompositionForTesting): + (WebView::confirmCompositionForTesting): + 2012-09-17 Sheriff Bot <webkit.review.bot@gmail.com> Unreviewed, rolling out r128809. diff --git a/Source/WebKit/win/DefaultPolicyDelegate.cpp b/Source/WebKit/win/DefaultPolicyDelegate.cpp index e83a8e977..f37969794 100644 --- a/Source/WebKit/win/DefaultPolicyDelegate.cpp +++ b/Source/WebKit/win/DefaultPolicyDelegate.cpp @@ -27,9 +27,12 @@ #include "WebKitDLL.h" #include "DefaultPolicyDelegate.h" +#include <WebCore/BString.h> #include <WebCore/COMPtr.h> #include <wtf/text/WTFString.h> +using namespace WebCore; + // FIXME: move this enum to a separate header file when other code begins to use it. typedef enum WebExtraNavigationType { WebNavigationTypePlugInRequest = WebNavigationTypeOther + 1 @@ -116,7 +119,7 @@ HRESULT STDMETHODCALLTYPE DefaultPolicyDelegate::decidePolicyForNavigationAction 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 +127,6 @@ HRESULT STDMETHODCALLTYPE DefaultPolicyDelegate::decidePolicyForNavigationAction ; } listener->ignore(); - SysFreeString(url); } } return S_OK; @@ -152,7 +154,7 @@ HRESULT STDMETHODCALLTYPE DefaultPolicyDelegate::decidePolicyForMIMEType( if (FAILED(webView->canShowMIMEType(type, &canShowMIMEType))) canShowMIMEType = FALSE; - BSTR url; + BString url; request->URL(&url); if (String(url, SysStringLen(url)).startsWith("file:")) { @@ -171,7 +173,6 @@ HRESULT STDMETHODCALLTYPE DefaultPolicyDelegate::decidePolicyForMIMEType( listener->use(); else listener->ignore(); - SysFreeString(url); return S_OK; } @@ -180,15 +181,13 @@ HRESULT STDMETHODCALLTYPE DefaultPolicyDelegate::unableToImplementPolicyWithErro /*[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; } diff --git a/Source/WebKit/win/MarshallingHelpers.cpp b/Source/WebKit/win/MarshallingHelpers.cpp index 138e4b425..6a037061f 100644 --- a/Source/WebKit/win/MarshallingHelpers.cpp +++ b/Source/WebKit/win/MarshallingHelpers.cpp @@ -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 @@ KURL MarshallingHelpers::BSTRToKURL(BSTR urlStr) 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 @@ CFStringRef MarshallingHelpers::LPCOLESTRToCFStringRef(LPCOLESTR str) 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 @@ SAFEARRAY* MarshallingHelpers::stringArrayToSafeArray(CFArrayRef inArray) 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 @@ CFArrayRef MarshallingHelpers::safeArrayToStringArray(SAFEARRAY* inArray) 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); diff --git a/Source/WebKit/win/WebCoreSupport/WebChromeClient.cpp b/Source/WebKit/win/WebCoreSupport/WebChromeClient.cpp index 3f7a418e6..c75bbe5df 100644 --- a/Source/WebKit/win/WebCoreSupport/WebChromeClient.cpp +++ b/Source/WebKit/win/WebCoreSupport/WebChromeClient.cpp @@ -410,17 +410,15 @@ bool WebChromeClient::runJavaScriptPrompt(Frame*, const String& message, const S 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) diff --git a/Source/WebKit/win/WebCoreSupport/WebEditorClient.cpp b/Source/WebKit/win/WebCoreSupport/WebEditorClient.cpp index 7767fff12..a189f70f1 100644 --- a/Source/WebKit/win/WebCoreSupport/WebEditorClient.cpp +++ b/Source/WebKit/win/WebCoreSupport/WebEditorClient.cpp @@ -695,21 +695,19 @@ void WebEditorClient::checkGrammarOfString(const UChar* text, int length, Vector 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 @@ void WebEditorClient::getGuessesForWord(const String& word, const String& contex 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); } } diff --git a/Source/WebKit/win/WebFrame.cpp b/Source/WebKit/win/WebFrame.cpp index 8a0a82cc5..ee9cdd8c4 100644 --- a/Source/WebKit/win/WebFrame.cpp +++ b/Source/WebKit/win/WebFrame.cpp @@ -1442,11 +1442,10 @@ HRESULT WebFrame::canProvideDocumentSource(bool* result) 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; diff --git a/Source/WebKit/win/WebHistory.cpp b/Source/WebKit/win/WebHistory.cpp index e842c1407..91f882fb8 100644 --- a/Source/WebKit/win/WebHistory.cpp +++ b/Source/WebKit/win/WebHistory.cpp @@ -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 STDMETHODCALLTYPE WebHistory::historyAgeInDaysLimit( 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 @@ HRESULT WebHistory::addItem(IWebHistoryItem* entry, bool discardDuplicate, bool* 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())); diff --git a/Source/WebKit/win/WebIconDatabase.cpp b/Source/WebKit/win/WebIconDatabase.cpp index 329817aa2..cddc40d81 100644 --- a/Source/WebKit/win/WebIconDatabase.cpp +++ b/Source/WebKit/win/WebIconDatabase.cpp @@ -84,12 +84,11 @@ void WebIconDatabase::startUpIconDatabase() 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(); diff --git a/Source/WebKit/win/WebNotificationCenter.cpp b/Source/WebKit/win/WebNotificationCenter.cpp index 23de1c1c9..e02abd593 100644 --- a/Source/WebKit/win/WebNotificationCenter.cpp +++ b/Source/WebKit/win/WebNotificationCenter.cpp @@ -28,6 +28,7 @@ #include "WebNotificationCenter.h" #include "WebNotification.h" +#include <WebCore/BString.h> #include <WebCore/COMPtr.h> #include <utility> #include <wchar.h> @@ -38,6 +39,8 @@ #include <wtf/text/StringHash.h> #include <wtf/text/WTFString.h> +using namespace WebCore; + typedef std::pair<COMPtr<IUnknown>, COMPtr<IWebNotificationObserver> > ObjectObserverPair; typedef Vector<ObjectObserverPair> ObjectObserverList; typedef ObjectObserverList::iterator ObserverListIterator; @@ -160,7 +163,7 @@ HRESULT STDMETHODCALLTYPE WebNotificationCenter::addObserver( HRESULT STDMETHODCALLTYPE WebNotificationCenter::postNotification( /* [in] */ IWebNotification* notification) { - BSTR name; + BString name; HRESULT hr = notification->name(&name); if (FAILED(hr)) return hr; @@ -171,7 +174,6 @@ HRESULT STDMETHODCALLTYPE WebNotificationCenter::postNotification( return hr; postNotificationInternal(notification, name, obj.get()); - SysFreeString(name); return hr; } diff --git a/Source/WebKit/win/WebPreferences.cpp b/Source/WebKit/win/WebPreferences.cpp index e1784a761..5634a15b3 100644 --- a/Source/WebKit/win/WebPreferences.cpp +++ b/Source/WebKit/win/WebPreferences.cpp @@ -349,10 +349,10 @@ LONGLONG WebPreferences::longlongValueForKey(CFStringRef key) 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)); diff --git a/Source/WebKit/win/WebView.cpp b/Source/WebKit/win/WebView.cpp index 3f38060cc..6f1069302 100644 --- a/Source/WebKit/win/WebView.cpp +++ b/Source/WebKit/win/WebView.cpp @@ -199,6 +199,21 @@ WebView* kit(Page* page) 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 @@ HRESULT PreferencesChangedOrRemovedObserver::onNotify(IWebNotification* notifica 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 @@ HRESULT STDMETHODCALLTYPE WebView::close() 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 @@ HRESULT STDMETHODCALLTYPE WebView::canShowMIMEType( /* [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 @@ HRESULT STDMETHODCALLTYPE WebView::initWithFrame( 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 @@ HRESULT STDMETHODCALLTYPE WebView::initWithFrame( 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 @@ float WebView::zoomMultiplier(bool isTextOnly) 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 @@ HRESULT STDMETHODCALLTYPE WebView::setCustomUserAgent( /* [in] */ BSTR userAgentString) { m_userAgentOverridden = userAgentString; - m_userAgentCustom = String(userAgentString, SysStringLen(userAgentString)); + m_userAgentCustom = toString(userAgentString); return S_OK; } @@ -3096,7 +3103,7 @@ HRESULT STDMETHODCALLTYPE WebView::userAgentForURL( /* [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 @@ HRESULT STDMETHODCALLTYPE WebView::setCustomTextEncodingName( 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 @@ HRESULT STDMETHODCALLTYPE WebView::customTextEncodingName( 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 @@ HRESULT STDMETHODCALLTYPE WebView::setPreferences( 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 @@ HRESULT STDMETHODCALLTYPE WebView::searchFor( 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,12 +3423,9 @@ HRESULT STDMETHODCALLTYPE WebView::updateFocusedAndActiveState() 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(name).execute(value); + m_page->focusController()->focusedOrMainFrame()->editor()->command(toString(name)).execute(toString(value)); return S_OK; } @@ -3447,7 +3449,7 @@ HRESULT STDMETHODCALLTYPE WebView::markAllMatchesForText( 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 @@ HRESULT STDMETHODCALLTYPE WebView::setGroupName( { 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 @@ HRESULT STDMETHODCALLTYPE WebView::registerURLSchemeAsLocal( 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::replaceSelectionWithNode( 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::stopSpeaking( 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 @@ HRESULT WebView::notifyPreferencesChanged(IWebNotification* notification) ASSERT(preferences == m_preferences); - BSTR str; + BString str; int size; BOOL enabled; @@ -4577,8 +4575,8 @@ HRESULT WebView::notifyPreferencesChanged(IWebNotification* notification) 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 @@ HRESULT WebView::notifyPreferencesChanged(IWebNotification* notification) 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 @@ HRESULT WebView::notifyPreferencesChanged(IWebNotification* notification) 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 @@ HRESULT WebView::notifyPreferencesChanged(IWebNotification* notification) 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 @@ HRESULT WebView::notifyPreferencesChanged(IWebNotification* notification) 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 @@ HRESULT WebView::notifyPreferencesChanged(IWebNotification* notification) } settings->setUserStyleSheetLocation(url.get()); - SysFreeString(str); - } else { + str.clear(); + } else settings->setUserStyleSheetLocation(KURL()); - } hr = preferences->shouldPrintBackgrounds(&enabled); if (FAILED(hr)) @@ -4978,9 +4975,7 @@ HRESULT STDMETHODCALLTYPE WebView::MIMETypeForExtension( if (!mimeType) return E_POINTER; - String extensionStr(extension, SysStringLen(extension)); - - *mimeType = BString(MIMETypeRegistry::getMIMETypeForExtension(extensionStr)).release(); + *mimeType = BString(MIMETypeRegistry::getMIMETypeForExtension(toString(extension))).release(); return S_OK; } @@ -5228,8 +5223,7 @@ HRESULT STDMETHODCALLTYPE WebView::standardUserAgentWithApplicationName( 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::setAllowSiteSpecificHacks( 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 @@ HRESULT STDMETHODCALLTYPE WebView::registerEmbeddedViewMIMEType(BSTR mimeType) 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 @@ HRESULT WebView::setCanStartPlugins(BOOL canStartPlugins) 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::invalidateBackingStore(const RECT* rect) 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 @@ HRESULT WebView::geolocationDidFailWithError(IWebError* error) 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 @@ HRESULT STDMETHODCALLTYPE WebView::setCompositionForTesting( 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 @@ HRESULT STDMETHODCALLTYPE WebView::confirmCompositionForTesting(/* [in] */ BSTR if (!frame || !frame->editor()->canEdit()) return E_FAIL; - String compositionStr(composition, SysStringLen(composition)); + String compositionStr = toString(composition); if (compositionStr.isNull()) frame->editor()->confirmComposition(); |
