summaryrefslogtreecommitdiff
path: root/Source/WebKit/win/WebView.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Source/WebKit/win/WebView.cpp')
-rw-r--r--Source/WebKit/win/WebView.cpp176
1 files changed, 79 insertions, 97 deletions
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();