Commit b3145606 authored by aroben@apple.com's avatar aroben@apple.com

Small clean-up in WebView's user content functions

Preparation for <http://webkit.org/b/31414> Implement new SPI for
dealing with user scripts/stylesheets and isolated worlds

Reviewed by Dave Hyatt.

* WebView.cpp:
(toString):
(toKURL):
Added these helper functions to convert BSTRs to WebCore types.

(toStringVector):
(WebView::addUserScriptToGroup):
(WebView::addUserStyleSheetToGroup):
(WebView::removeUserScriptFromGroup):
(WebView::removeUserStyleSheetFromGroup):
(WebView::removeUserScriptsFromGroup):
(WebView::removeUserStyleSheetsFromGroup):
(WebView::removeAllUserContentFromGroup):
Use the new helper functions.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@50906 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 1abf02c8
2009-11-12 Adam Roben <aroben@apple.com>
Small clean-up in WebView's user content functions
Preparation for <http://webkit.org/b/31414> Implement new SPI for
dealing with user scripts/stylesheets and isolated worlds
Reviewed by Dave Hyatt.
* WebView.cpp:
(toString):
(toKURL):
Added these helper functions to convert BSTRs to WebCore types.
(toStringVector):
(WebView::addUserScriptToGroup):
(WebView::addUserStyleSheetToGroup):
(WebView::removeUserScriptFromGroup):
(WebView::removeUserStyleSheetFromGroup):
(WebView::removeUserScriptsFromGroup):
(WebView::removeUserStyleSheetsFromGroup):
(WebView::removeAllUserContentFromGroup):
Use the new helper functions.
2009-11-11 Beth Dakin <bdakin@apple.com>
Build fix. No review needed.
......
......@@ -5469,6 +5469,16 @@ 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));
}
static PassOwnPtr<Vector<String> > toStringVector(unsigned patternsCount, BSTR* patterns)
{
// Convert the patterns into a Vector.
......@@ -5476,7 +5486,7 @@ static PassOwnPtr<Vector<String> > toStringVector(unsigned patternsCount, BSTR*
return 0;
Vector<String>* patternsVector = new Vector<String>;
for (unsigned i = 0; i < patternsCount; ++i)
patternsVector->append(String(patterns[i], SysStringLen(patterns[i])));
patternsVector->append(toString(patterns[i]));
return patternsVector;
}
......@@ -5485,7 +5495,7 @@ HRESULT WebView::addUserScriptToGroup(BSTR groupName, unsigned worldID, BSTR sou
unsigned blacklistCount, BSTR* blacklist,
WebUserScriptInjectionTime injectionTime)
{
String group(groupName, SysStringLen(groupName));
String group = toString(groupName);
if (group.isEmpty() || !worldID || worldID == numeric_limits<unsigned>::max())
return E_INVALIDARG;
......@@ -5494,7 +5504,7 @@ HRESULT WebView::addUserScriptToGroup(BSTR groupName, unsigned worldID, BSTR sou
if (!pageGroup)
return E_FAIL;
pageGroup->addUserScriptToWorld(worldID, String(source, SysStringLen(source)), KURL(KURL(), String(url, SysStringLen(url))),
pageGroup->addUserScriptToWorld(worldID, toString(source), toKURL(url),
toStringVector(whitelistCount, whitelist), toStringVector(blacklistCount, blacklist),
injectionTime == WebInjectAtDocumentStart ? InjectAtDocumentStart : InjectAtDocumentEnd);
......@@ -5505,7 +5515,7 @@ HRESULT WebView::addUserStyleSheetToGroup(BSTR groupName, unsigned worldID, BSTR
unsigned whitelistCount, BSTR* whitelist,
unsigned blacklistCount, BSTR* blacklist)
{
String group(groupName, SysStringLen(groupName));
String group = toString(groupName);
if (group.isEmpty() || !worldID || worldID == numeric_limits<unsigned>::max())
return E_INVALIDARG;
......@@ -5514,7 +5524,7 @@ HRESULT WebView::addUserStyleSheetToGroup(BSTR groupName, unsigned worldID, BSTR
if (!pageGroup)
return E_FAIL;
pageGroup->addUserStyleSheetToWorld(worldID, String(source, SysStringLen(source)), KURL(KURL(), String(url, SysStringLen(url))),
pageGroup->addUserStyleSheetToWorld(worldID, toString(source), toKURL(url),
toStringVector(whitelistCount, whitelist), toStringVector(blacklistCount, blacklist));
return S_OK;
......@@ -5522,7 +5532,7 @@ HRESULT WebView::addUserStyleSheetToGroup(BSTR groupName, unsigned worldID, BSTR
HRESULT WebView::removeUserScriptFromGroup(BSTR groupName, unsigned worldID, BSTR url)
{
String group(groupName, SysStringLen(groupName));
String group = toString(groupName);
if (group.isEmpty() || !worldID || worldID == numeric_limits<unsigned>::max())
return E_INVALIDARG;
......@@ -5531,14 +5541,14 @@ HRESULT WebView::removeUserScriptFromGroup(BSTR groupName, unsigned worldID, BST
if (!pageGroup)
return E_FAIL;
pageGroup->removeUserScriptFromWorld(worldID, KURL(KURL(), String(url, SysStringLen(url))));
pageGroup->removeUserScriptFromWorld(worldID, toKURL(url));
return S_OK;
}
HRESULT WebView::removeUserStyleSheetFromGroup(BSTR groupName, unsigned worldID, BSTR url)
{
String group(groupName, SysStringLen(groupName));
String group = toString(groupName);
if (group.isEmpty() || !worldID || worldID == numeric_limits<unsigned>::max())
return E_INVALIDARG;
......@@ -5547,14 +5557,14 @@ HRESULT WebView::removeUserStyleSheetFromGroup(BSTR groupName, unsigned worldID,
if (!pageGroup)
return E_FAIL;
pageGroup->removeUserStyleSheetFromWorld(worldID, KURL(KURL(), String(url, SysStringLen(url))));
pageGroup->removeUserStyleSheetFromWorld(worldID, toKURL(url));
return S_OK;
}
HRESULT WebView::removeUserScriptsFromGroup(BSTR groupName, unsigned worldID)
{
String group(groupName, SysStringLen(groupName));
String group = toString(groupName);
if (group.isEmpty() || !worldID || worldID == numeric_limits<unsigned>::max())
return E_INVALIDARG;
......@@ -5569,7 +5579,7 @@ HRESULT WebView::removeUserScriptsFromGroup(BSTR groupName, unsigned worldID)
HRESULT WebView::removeUserStyleSheetsFromGroup(BSTR groupName, unsigned worldID)
{
String group(groupName, SysStringLen(groupName));
String group = toString(groupName);
if (group.isEmpty() || !worldID || worldID == numeric_limits<unsigned>::max())
return E_INVALIDARG;
......@@ -5584,7 +5594,7 @@ HRESULT WebView::removeUserStyleSheetsFromGroup(BSTR groupName, unsigned worldID
HRESULT WebView::removeAllUserContentFromGroup(BSTR groupName)
{
String group(groupName, SysStringLen(groupName));
String group = toString(groupName);
if (group.isEmpty())
return E_INVALIDARG;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment