Commit 509c1c3d authored by aa@chromium.org's avatar aa@chromium.org

2010-07-08 Aaron Boodman <aa@chromium.org>

        Reviewed by Timothy Hatcher.

        Add the ability for user scripts and user styles to affect just the top frame.

        https://bugs.webkit.org/show_bug.cgi?id=41529

        * platform/win/Skipped: Skipped test because WebKit API needs updating.
        * userscripts/mixed-case-stylesheet.html: Added new allFrames param.
        * userscripts/resources/frame1.html: Added.
        * userscripts/resources/frame2.html: Added.
        * userscripts/script-not-run-for-fragments.html: Added new allFrames param.
        * userscripts/script-run-at-end.html: Ditto.
        * userscripts/script-run-at-start.html: Ditto.
        * userscripts/simple-stylesheet.html: Ditto.
        * userscripts/user-script-all-frames-expected.txt: Added.
        * userscripts/user-script-all-frames.html: Added.
        * userscripts/user-script-top-frame-only-expected.txt: Added.
        * userscripts/user-script-top-frame-only.html: Added.
        * userscripts/user-style-all-frames-expected.txt: Added.
        * userscripts/user-style-all-frames.html: Added.
        * userscripts/user-style-top-frame-only-expected.txt: Added.
        * userscripts/user-style-top-frame-only.html: Added.
2010-07-08  Aaron Boodman  <aa@chromium.org>

        Reviewed by Timothy Hatcher.

        Add the ability for user scripts and user styles to affect just the top frame.

        https://bugs.webkit.org/show_bug.cgi?id=41529

        Tests: userscripts/user-script-all-frames.html
               userscripts/user-script-top-frame-only.html
               userscripts/user-style-all-frames.html
               userscripts/user-style-top-frame-only.html

        * WebCore.base.exp: Update PageGroup method signatures.
        * dom/Document.cpp:
        (WebCore::Document::pageGroupUserSheets): Check allFrames before injecting.
        * page/Frame.cpp:
        (WebCore::Frame::injectUserScriptsForWorld): Ditto.
        * page/PageGroup.cpp:
        (WebCore::PageGroup::addUserScriptToWorld):
        (WebCore::PageGroup::addUserStyleSheetToWorld):
        * page/PageGroup.h:
        * page/UserScript.h:
        (WebCore::UserScript::UserScript):
        (WebCore::UserScript::injectedFrames):
        * page/UserScriptTypes.h:
        (WebCore::):
        * page/UserStyleSheet.h:
        (WebCore::UserStyleSheet::UserStyleSheet):
        (WebCore::UserStyleSheet::injectedFrames):
2010-07-08  Aaron Boodman  <aa@chromium.org>

        Reviewed by Timothy Hatcher.

        Add the ability for user scripts and user styles to affect just the top frame.

        https://bugs.webkit.org/show_bug.cgi?id=41529

        * public/WebView.h:
        (WebKit::WebView::):
        (WebKit::WebView::addUserScript):
        (WebKit::WebView::addUserStyleSheet):
        * src/AssertMatchingEnums.cpp:
        * src/WebViewImpl.cpp:
        (WebKit::WebView::addUserScript):
        (WebKit::WebView::addUserStyleSheet):
2010-07-08  Aaron Boodman  <aa@chromium.org>

        Reviewed by Timothy Hatcher.

        Add the ability for user scripts and user styles to affect just the top frame.

        https://bugs.webkit.org/show_bug.cgi?id=41529

        * WebView/WebView.mm:
        (+[WebView _addUserScriptToGroup:world:source:url:whitelist:blacklist:injectionTime:]):
        (+[WebView _addUserScriptToGroup:world:source:url:whitelist:blacklist:injectionTime:injectedFrames:]):
        (+[WebView _addUserStyleSheetToGroup:world:source:url:whitelist:blacklist:]):
        (+[WebView _addUserStyleSheetToGroup:world:source:url:whitelist:blacklist:injectedFrames:]):
        * WebView/WebViewPrivate.h:
2010-07-08  Aaron Boodman  <aa@chromium.org>

        Reviewed by Timothy Hatcher.

        Add the ability for user scripts and user styles to affect just the top frame.

        https://bugs.webkit.org/show_bug.cgi?id=41529

        * WebView.cpp:
        (WebView::addUserScriptToGroup):
        (WebView::addUserStyleSheetToGroup):
2010-07-08  Aaron Boodman  <aa@chromium.org>

        Reviewed by Timothy Hatcher.

        Add the ability for user scripts and user styles to affect just the top frame.

        https://bugs.webkit.org/show_bug.cgi?id=41529

        * DumpRenderTree/LayoutTestController.h: Added new allFrames param.
        * DumpRenderTree/LayoutTestController.cpp: Ditto.
        (addUserScriptCallback):
        (addUserStyleSheetCallback):
        * DumpRenderTree/chromium/LayoutTestController.cpp: Ditto.
        (LayoutTestController::addUserScript):
        (LayoutTestController::addUserStyleSheet):
        * DumpRenderTree/gtk/LayoutTestControllerGtk.cpp: Ditto.
        (LayoutTestController::addUserScript):
        (LayoutTestController::addUserStyleSheet):
        * DumpRenderTree/mac/LayoutTestControllerMac.mm: Ditto.
        (LayoutTestController::addUserScript):
        (LayoutTestController::addUserStyleSheet):
        * DumpRenderTree/win/LayoutTestControllerWin.cpp: Ditto.
        (LayoutTestController::addUserScript):
        (LayoutTestController::addUserStyleSheet):
        * DumpRenderTree/wx/LayoutTestControllerWx.cpp: Ditto.
        (LayoutTestController::addUserScript):
        (LayoutTestController::addUserStyleSheet):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@62876 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent b9d22b1b
2010-07-08 Aaron Boodman <aa@chromium.org>
Reviewed by Timothy Hatcher.
Add the ability for user scripts and user styles to affect just the top frame.
https://bugs.webkit.org/show_bug.cgi?id=41529
* platform/win/Skipped: Skipped test because WebKit API needs updating.
* userscripts/mixed-case-stylesheet.html: Added new allFrames param.
* userscripts/resources/frame1.html: Added.
* userscripts/resources/frame2.html: Added.
* userscripts/script-not-run-for-fragments.html: Added new allFrames param.
* userscripts/script-run-at-end.html: Ditto.
* userscripts/script-run-at-start.html: Ditto.
* userscripts/simple-stylesheet.html: Ditto.
* userscripts/user-script-all-frames-expected.txt: Added.
* userscripts/user-script-all-frames.html: Added.
* userscripts/user-script-top-frame-only-expected.txt: Added.
* userscripts/user-script-top-frame-only.html: Added.
* userscripts/user-style-all-frames-expected.txt: Added.
* userscripts/user-style-all-frames.html: Added.
* userscripts/user-style-top-frame-only-expected.txt: Added.
* userscripts/user-style-top-frame-only.html: Added.
2010-07-08 Adele Peterson <adele@apple.com>
Reviewed by Jon Honeycutt, Adam Roben, and Darin Adler.
......@@ -944,3 +944,11 @@ fast/forms/input-appearance-speechbutton.html
# Needs to be fixed at image decoder layer for Safari.
fast/images/large-size-image-crash.html
# Disable until the windows WebKit API supports injecting in the top frame only.
# https://bugs.webkit.org/show_bug.cgi?id=41800
userscripts/user-script-all-frames.html
userscripts/user-script-top-frame-only.html
userscripts/user-style-all-frames.html
userscripts/user-style-top-frame-only.html
userscripts/frameset-all-frames.html
userscripts/frameset-top-frame-only.html
......@@ -3,7 +3,7 @@
<script>
if (window.layoutTestController) {
window.layoutTestController.dumpAsText();
window.layoutTestController.addUserStyleSheet("#mixedCase { display: none }");
window.layoutTestController.addUserStyleSheet("#mixedCase { display: none }", true);
}
</script>
</head>
......
<html>
<body>
<div id="thinger">thinger</div>
<iframe src="frame2.html"></iframe>
</body>
</html>
<html>
<body>
<script>
window.onload = function() {
if (window.layoutTestController)
layoutTestController.notifyDone();
}
</script>
<div id="thinger">thinger</div>
</body>
</html>
......@@ -5,7 +5,7 @@
if (window.layoutTestController) {
layoutTestController.dumpAsText();
layoutTestController.waitUntilDone();
layoutTestController.addUserScript("console.log('injected'); var div = document.createElement('div'); div.innerHTML = '<p>hi</p>';", true);
layoutTestController.addUserScript("console.log('injected'); var div = document.createElement('div'); div.innerHTML = '<p>hi</p>';", true, true);
}
</script>
</head>
......
......@@ -4,7 +4,7 @@
<script>
if (window.layoutTestController) {
layoutTestController.dumpAsText();
layoutTestController.addUserScript("document.getElementById('target').innerHTML = 'PASS'", false);
layoutTestController.addUserScript("document.getElementById('target').innerHTML = 'PASS'", false, true);
}
</script>
</head>
......
......@@ -4,7 +4,7 @@
<script>
if (window.layoutTestController) {
layoutTestController.dumpAsText();
layoutTestController.addUserScript("if (window.location == 'about:blank') console.log('SUCCESS');", true);
layoutTestController.addUserScript("if (window.location == 'about:blank') console.log('SUCCESS');", true, true);
}
</script>
</head>
......
......@@ -4,7 +4,7 @@
<script>
if (window.layoutTestController) {
layoutTestController.dumpAsText();
layoutTestController.addUserStyleSheet("div { width:0; }");
layoutTestController.addUserStyleSheet("div { width:0; }", true);
}
</script>
</head>
......
If any thingers appear on this page, the test has failed.
--------
Frame: '<!--framePath //<!--frame0-->-->'
--------
--------
Frame: '<!--framePath //<!--frame0-->/<!--frame0-->-->'
--------
<html>
<head>
<script>
if (window.layoutTestController) {
window.layoutTestController.dumpAsText();
window.layoutTestController.dumpChildFramesAsText();
layoutTestController.waitUntilDone();
window.layoutTestController.addUserScript("document.getElementById('thinger').style.display = 'none';",
false, true);
}
</script>
</head>
<body>
If any thingers appear on this page, the test has failed.
<Div id="thinger">thinger</div>
<iframe src="resources/frame1.html"></iframe>
</body>
</html>
Two thingers should appear on this page. Otherwise the test has failed.
--------
Frame: '<!--framePath //<!--frame0-->-->'
--------
thinger
--------
Frame: '<!--framePath //<!--frame0-->/<!--frame0-->-->'
--------
thinger
<html>
<head>
<script>
if (window.layoutTestController) {
window.layoutTestController.dumpAsText();
window.layoutTestController.dumpChildFramesAsText();
layoutTestController.waitUntilDone();
window.layoutTestController.addUserScript("document.getElementById('thinger').style.display = 'none';",
false, false);
}
</script>
</head>
<body>
Two thingers should appear on this page. Otherwise the test has failed.
<Div id="thinger">thinger</div>
<iframe src="resources/frame1.html"></iframe>
</body>
</html>
If any thingers appear on this page, the test has failed.
--------
Frame: '<!--framePath //<!--frame0-->-->'
--------
--------
Frame: '<!--framePath //<!--frame0-->/<!--frame0-->-->'
--------
<html>
<head>
<script>
if (window.layoutTestController) {
window.layoutTestController.dumpAsText();
window.layoutTestController.dumpChildFramesAsText();
layoutTestController.waitUntilDone();
window.layoutTestController.addUserStyleSheet("#thinger { display:none; }", true);
}
</script>
</head>
<body>
If any thingers appear on this page, the test has failed.
<Div id="thinger">thinger</div>
<iframe src="resources/frame1.html"></iframe>
</body>
</html>
2 thingers should appear on this page. Otherwise the test has failed.
--------
Frame: '<!--framePath //<!--frame0-->-->'
--------
thinger
--------
Frame: '<!--framePath //<!--frame0-->/<!--frame0-->-->'
--------
thinger
<html>
<head>
<script>
if (window.layoutTestController) {
window.layoutTestController.dumpAsText();
window.layoutTestController.dumpChildFramesAsText();
layoutTestController.waitUntilDone();
window.layoutTestController.addUserStyleSheet("#thinger { display:none; }", false);
}
</script>
</head>
<body>
2 thingers should appear on this page. Otherwise the test has failed.
<Div id="thinger">thinger</div>
<iframe src="resources/frame1.html"></iframe>
</body>
</html>
2010-07-08 Aaron Boodman <aa@chromium.org>
Reviewed by Timothy Hatcher.
Add the ability for user scripts and user styles to affect just the top frame.
https://bugs.webkit.org/show_bug.cgi?id=41529
Tests: userscripts/user-script-all-frames.html
userscripts/user-script-top-frame-only.html
userscripts/user-style-all-frames.html
userscripts/user-style-top-frame-only.html
* WebCore.base.exp: Update PageGroup method signatures.
* dom/Document.cpp:
(WebCore::Document::pageGroupUserSheets): Check allFrames before injecting.
* page/Frame.cpp:
(WebCore::Frame::injectUserScriptsForWorld): Ditto.
* page/PageGroup.cpp:
(WebCore::PageGroup::addUserScriptToWorld):
(WebCore::PageGroup::addUserStyleSheetToWorld):
* page/PageGroup.h:
* page/UserScript.h:
(WebCore::UserScript::UserScript):
(WebCore::UserScript::injectedFrames):
* page/UserScriptTypes.h:
(WebCore::):
* page/UserStyleSheet.h:
(WebCore::UserStyleSheet::UserStyleSheet):
(WebCore::UserStyleSheet::injectedFrames):
2010-07-08 Adele Peterson <adele@apple.com>
Reviewed by Jon Honeycutt, Adam Roben, and Darin Adler.
......@@ -1600,6 +1600,7 @@ webcore_sources += \
WebCore/page/Timing.h \
WebCore/page/UserContentURLPattern.cpp \
WebCore/page/UserContentURLPattern.h \
WebCore/page/UserContentTypes.h \
WebCore/page/UserScript.h \
WebCore/page/UserScriptTypes.h \
WebCore/page/UserStyleSheet.h \
......
......@@ -750,10 +750,10 @@ __ZN7WebCore9PageCache11setCapacityEi
__ZN7WebCore9PageCache27releaseAutoreleasedPagesNowEv
__ZN7WebCore9PageGroup14addVisitedLinkEPKtm
__ZN7WebCore9PageGroup17closeLocalStorageEv
__ZN7WebCore9PageGroup20addUserScriptToWorldEPNS_15DOMWrapperWorldERKNS_6StringERKNS_4KURLEN3WTF10PassOwnPtrINS9_6VectorIS3_Lm0EEEEESD_NS_23UserScriptInjectionTimeE
__ZN7WebCore9PageGroup20addUserScriptToWorldEPNS_15DOMWrapperWorldERKNS_6StringERKNS_4KURLEN3WTF10PassOwnPtrINS9_6VectorIS3_Lm0EEEEESD_NS_23UserScriptInjectionTimeENS_25UserContentInjectedFramesE
__ZN7WebCore9PageGroup20removeAllUserContentEv
__ZN7WebCore9PageGroup21removeAllVisitedLinksEv
__ZN7WebCore9PageGroup24addUserStyleSheetToWorldEPNS_15DOMWrapperWorldERKNS_6StringERKNS_4KURLEN3WTF10PassOwnPtrINS9_6VectorIS3_Lm0EEEEESD_
__ZN7WebCore9PageGroup24addUserStyleSheetToWorldEPNS_15DOMWrapperWorldERKNS_6StringERKNS_4KURLEN3WTF10PassOwnPtrINS9_6VectorIS3_Lm0EEEEESD_NS_25UserContentInjectedFramesE
__ZN7WebCore9PageGroup25removeUserScriptFromWorldEPNS_15DOMWrapperWorldERKNS_4KURLE
__ZN7WebCore9PageGroup26removeUserScriptsFromWorldEPNS_15DOMWrapperWorldE
__ZN7WebCore9PageGroup26setShouldTrackVisitedLinksEb
......
......@@ -2036,6 +2036,7 @@
'page/Timing.h',
'page/UserContentURLPattern.cpp',
'page/UserContentURLPattern.h',
'page/UserContentTypes.h',
'page/UserScript.h',
'page/UserScriptTypes.h',
'page/UserStyleSheet.h',
......
......@@ -35,6 +35,7 @@
/* Begin PBXBuildFile section */
0014628A103CD1DE000B20DB /* OriginAccessEntry.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 00146288103CD1DE000B20DB /* OriginAccessEntry.cpp */; };
0014628B103CD1DE000B20DB /* OriginAccessEntry.h in Headers */ = {isa = PBXBuildFile; fileRef = 00146289103CD1DE000B20DB /* OriginAccessEntry.h */; };
003F1FEA11E6AB43008258D9 /* UserContentTypes.h in Headers */ = {isa = PBXBuildFile; fileRef = 003F1FE911E6AB43008258D9 /* UserContentTypes.h */; settings = {ATTRIBUTES = (Private, ); }; };
06027CAD0B1CBFC000884B2D /* ContextMenuItem.h in Headers */ = {isa = PBXBuildFile; fileRef = 06027CAC0B1CBFC000884B2D /* ContextMenuItem.h */; settings = {ATTRIBUTES = (Private, ); }; };
06027CB30B1CC03D00884B2D /* ContextMenuItemMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 06027CB20B1CC03D00884B2D /* ContextMenuItemMac.mm */; };
062287840B4DB322000C34DF /* FocusDirection.h in Headers */ = {isa = PBXBuildFile; fileRef = 062287830B4DB322000C34DF /* FocusDirection.h */; settings = {ATTRIBUTES = (Private, ); }; };
......@@ -5649,6 +5650,7 @@
/* Begin PBXFileReference section */
00146288103CD1DE000B20DB /* OriginAccessEntry.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = OriginAccessEntry.cpp; sourceTree = "<group>"; };
00146289103CD1DE000B20DB /* OriginAccessEntry.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OriginAccessEntry.h; sourceTree = "<group>"; };
003F1FE911E6AB43008258D9 /* UserContentTypes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UserContentTypes.h; sourceTree = "<group>"; };
06027CAC0B1CBFC000884B2D /* ContextMenuItem.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = ContextMenuItem.h; sourceTree = "<group>"; };
06027CB20B1CC03D00884B2D /* ContextMenuItemMac.mm */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.objcpp; path = ContextMenuItemMac.mm; sourceTree = "<group>"; };
062287830B4DB322000C34DF /* FocusDirection.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = FocusDirection.h; sourceTree = "<group>"; };
......@@ -12308,6 +12310,7 @@
8AF4E55811DC5A63000ED3DE /* Timing.cpp */,
8AF4E55911DC5A63000ED3DE /* Timing.h */,
8AF4E55A11DC5A63000ED3DE /* Timing.idl */,
003F1FE911E6AB43008258D9 /* UserContentTypes.h */,
BCACF3BA1072921A00C0C8A3 /* UserContentURLPattern.cpp */,
BCACF3BB1072921A00C0C8A3 /* UserContentURLPattern.h */,
BCA2B0601050475F0043BD1C /* UserScript.h */,
......@@ -19728,6 +19731,7 @@
BCA8C81E11E3D36900812FB7 /* BackForwardController.h in Headers */,
BCA8C83111E3D53200812FB7 /* BackForwardControllerClient.h in Headers */,
BCA8CA6011E4E6D100812FB7 /* BackForwardListImpl.h in Headers */,
003F1FEA11E6AB43008258D9 /* UserContentTypes.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......@@ -2154,6 +2154,8 @@ const Vector<RefPtr<CSSStyleSheet> >* Document::pageGroupUserSheets() const
const UserStyleSheetVector* sheets = it->second;
for (unsigned i = 0; i < sheets->size(); ++i) {
const UserStyleSheet* sheet = sheets->at(i).get();
if (sheet->injectedFrames() == InjectInTopFrameOnly && ownerElement())
continue;
if (!UserContentURLPattern::matchesPatterns(url(), sheet->whitelist(), sheet->blacklist()))
continue;
RefPtr<CSSStyleSheet> parsedSheet = CSSStyleSheet::createInline(const_cast<Document*>(this), sheet->url());
......
......@@ -691,6 +691,9 @@ void Frame::injectUserScriptsForWorld(DOMWrapperWorld* world, const UserScriptVe
unsigned count = userScripts.size();
for (unsigned i = 0; i < count; ++i) {
UserScript* script = userScripts[i].get();
if (script->injectedFrames() == InjectInTopFrameOnly && ownerElement())
continue;
if (script->injectionTime() == injectionTime && UserContentURLPattern::matchesPatterns(doc->url(), script->whitelist(), script->blacklist()))
m_script.evaluateInWorld(ScriptSourceCode(script->source(), script->url()), world);
}
......
......@@ -213,12 +213,13 @@ IndexedDatabase* PageGroup::indexedDatabase()
}
#endif
void PageGroup::addUserScriptToWorld(DOMWrapperWorld* world, const String& source, const KURL& url, PassOwnPtr<Vector<String> > whitelist,
PassOwnPtr<Vector<String> > blacklist, UserScriptInjectionTime injectionTime)
void PageGroup::addUserScriptToWorld(DOMWrapperWorld* world, const String& source, const KURL& url,
PassOwnPtr<Vector<String> > whitelist, PassOwnPtr<Vector<String> > blacklist,
UserScriptInjectionTime injectionTime, UserContentInjectedFrames injectedFrames)
{
ASSERT_ARG(world, world);
OwnPtr<UserScript> userScript(new UserScript(source, url, whitelist, blacklist, injectionTime));
OwnPtr<UserScript> userScript(new UserScript(source, url, whitelist, blacklist, injectionTime, injectedFrames));
if (!m_userScripts)
m_userScripts.set(new UserScriptMap);
UserScriptVector*& scriptsInWorld = m_userScripts->add(world, 0).first->second;
......@@ -227,19 +228,20 @@ void PageGroup::addUserScriptToWorld(DOMWrapperWorld* world, const String& sourc
scriptsInWorld->append(userScript.release());
}
void PageGroup::addUserStyleSheetToWorld(DOMWrapperWorld* world, const String& source, const KURL& url, PassOwnPtr<Vector<String> > whitelist,
PassOwnPtr<Vector<String> > blacklist)
void PageGroup::addUserStyleSheetToWorld(DOMWrapperWorld* world, const String& source, const KURL& url,
PassOwnPtr<Vector<String> > whitelist, PassOwnPtr<Vector<String> > blacklist,
UserContentInjectedFrames injectedFrames)
{
ASSERT_ARG(world, world);
OwnPtr<UserStyleSheet> userStyleSheet(new UserStyleSheet(source, url, whitelist, blacklist));
OwnPtr<UserStyleSheet> userStyleSheet(new UserStyleSheet(source, url, whitelist, blacklist, injectedFrames));
if (!m_userStyleSheets)
m_userStyleSheets.set(new UserStyleSheetMap);
UserStyleSheetVector*& styleSheetsInWorld = m_userStyleSheets->add(world, 0).first->second;
if (!styleSheetsInWorld)
styleSheetsInWorld = new UserStyleSheetVector;
styleSheetsInWorld->append(userStyleSheet.release());
// Clear our cached sheets and have them just reparse.
HashSet<Page*>::const_iterator end = m_pages.end();
for (HashSet<Page*>::const_iterator it = m_pages.begin(); it != end; ++it) {
......
......@@ -74,20 +74,21 @@ namespace WebCore {
IndexedDatabase* indexedDatabase();
#endif
void addUserScriptToWorld(DOMWrapperWorld*, const String& source, const KURL&,
void addUserScriptToWorld(DOMWrapperWorld*, const String& source, const KURL&,
PassOwnPtr<Vector<String> > whitelist, PassOwnPtr<Vector<String> > blacklist,
UserScriptInjectionTime);
UserScriptInjectionTime, UserContentInjectedFrames);
void addUserStyleSheetToWorld(DOMWrapperWorld*, const String& source, const KURL&,
PassOwnPtr<Vector<String> > whitelist, PassOwnPtr<Vector<String> > blacklist);
PassOwnPtr<Vector<String> > whitelist, PassOwnPtr<Vector<String> > blacklist,
UserContentInjectedFrames);
void removeUserScriptFromWorld(DOMWrapperWorld*, const KURL&);
void removeUserStyleSheetFromWorld(DOMWrapperWorld*, const KURL&);
void removeUserScriptsFromWorld(DOMWrapperWorld*);
void removeUserStyleSheetsFromWorld(DOMWrapperWorld*);
void removeAllUserContent();
const UserScriptMap* userScripts() const { return m_userScripts.get(); }
const UserStyleSheetMap* userStyleSheets() const { return m_userStyleSheets.get(); }
......
/*
* Copyright (C) 2009 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef UserContentTypes_h
#define UserContentTypes_h
#include <wtf/HashMap.h>
#include <wtf/Vector.h>
namespace WebCore {
enum UserContentInjectedFrames { InjectInAllFrames, InjectInTopFrameOnly };
} // namespace WebCore
#endif // UserContentTypes_h
......@@ -27,6 +27,7 @@
#define UserScript_h
#include "KURL.h"
#include "UserContentTypes.h"
#include "UserScriptTypes.h"
#include <wtf/OwnPtr.h>
#include <wtf/PassOwnPtr.h>
......@@ -38,12 +39,13 @@ class UserScript : public Noncopyable {
public:
UserScript(const String& source, const KURL& url,
PassOwnPtr<Vector<String> > whitelist, PassOwnPtr<Vector<String> > blacklist,
UserScriptInjectionTime injectionTime)
UserScriptInjectionTime injectionTime, UserContentInjectedFrames injectedFrames)
: m_source(source)
, m_url(url)
, m_whitelist(whitelist)
, m_blacklist(blacklist)
, m_injectionTime(injectionTime)
, m_injectedFrames(injectedFrames)
{
}
......@@ -52,15 +54,17 @@ public:
const Vector<String>* whitelist() const { return m_whitelist.get(); }
const Vector<String>* blacklist() const { return m_blacklist.get(); }
UserScriptInjectionTime injectionTime() const { return m_injectionTime; }
UserContentInjectedFrames injectedFrames() const { return m_injectedFrames; }
private:
String m_source;
KURL m_url;
OwnPtr<Vector<String> > m_whitelist;
OwnPtr<Vector<String> > m_blacklist;
UserScriptInjectionTime m_injectionTime;
UserContentInjectedFrames m_injectedFrames;
};
} // namespace WebCore
#endif // UserScript_h
......@@ -27,6 +27,7 @@
#define UserStyleSheet_h
#include "KURL.h"
#include "UserContentTypes.h"
#include "UserStyleSheetTypes.h"
#include <wtf/OwnPtr.h>
#include <wtf/PassOwnPtr.h>
......@@ -37,11 +38,13 @@ namespace WebCore {
class UserStyleSheet : public Noncopyable {
public:
UserStyleSheet(const String& source, const KURL& url,
PassOwnPtr<Vector<String> > whitelist, PassOwnPtr<Vector<String> > blacklist)
PassOwnPtr<Vector<String> > whitelist, PassOwnPtr<Vector<String> > blacklist,
UserContentInjectedFrames injectedFrames)
: m_source(source)
, m_url(url)
, m_whitelist(whitelist)
, m_blacklist(blacklist)
, m_injectedFrames(injectedFrames)
{
}
......@@ -49,12 +52,14 @@ public:
const KURL& url() const { return m_url; }
const Vector<String>* whitelist() const { return m_whitelist.get(); }
const Vector<String>* blacklist() const { return m_blacklist.get(); }
UserContentInjectedFrames injectedFrames() const { return m_injectedFrames; }
private:
String m_source;
KURL m_url;
OwnPtr<Vector<String> > m_whitelist;
OwnPtr<Vector<String> > m_blacklist;
UserContentInjectedFrames m_injectedFrames;
};
} // namespace WebCore
......
2010-07-08 Aaron Boodman <aa@chromium.org>
Reviewed by Timothy Hatcher.
Add the ability for user scripts and user styles to affect just the top frame.
https://bugs.webkit.org/show_bug.cgi?id=41529
* public/WebView.h:
(WebKit::WebView::):
(WebKit::WebView::addUserScript):
(WebKit::WebView::addUserStyleSheet):
* src/AssertMatchingEnums.cpp:
* src/WebViewImpl.cpp:
(WebKit::WebView::addUserScript):
(WebKit::WebView::addUserStyleSheet):
2010-07-08 James Robinson <jamesr@google.com>
Reviewed by Darin Fisher.
......
......@@ -54,6 +54,18 @@ struct WebPoint;
class WebView : public WebWidget {
public:
// Controls the time that user scripts injected into the document run.
enum UserScriptInjectAt {
UserScriptInjectAtDocumentStart,
UserScriptInjectAtDocumentEnd
};
// Controls which frames user content is injected into.
enum UserContentInjectIn {
UserContentInjectInAllFrames,
UserContentInjectInTopFrameOnly
};
// Initialization ------------------------------------------------------
// Creates a WebView that is NOT yet initialized. You will need to
......@@ -286,18 +298,22 @@ public:
// FIXME: These two methods are DEPRECATED. Remove once Chromium has been rolled.
virtual void addUserScript(const WebString& sourceCode, bool runAtStart)
{
addUserScript(sourceCode, WebVector<WebString>(), runAtStart);
addUserScript(sourceCode, WebVector<WebString>(),
runAtStart ? UserScriptInjectAtDocumentStart : UserScriptInjectAtDocumentEnd,
UserContentInjectInAllFrames);
}
virtual void addUserStyleSheet(const WebString& sourceCode)
{
addUserStyleSheet(sourceCode, WebVector<WebString>());
addUserStyleSheet(sourceCode, WebVector<WebString>(), UserContentInjectInAllFrames);
}
WEBKIT_API static void addUserScript(const WebString& sourceCode,
const WebVector<WebString>& patterns,
bool runAtStart);
UserScriptInjectAt injectAt,
UserContentInjectIn injectIn);
WEBKIT_API static void addUserStyleSheet(const WebString& sourceCode,
const WebVector<WebString>& patterns);
const WebVector<WebString>& patterns,
UserContentInjectIn injectIn);
WEBKIT_API static void removeAllUserContent();
// Modal dialog support ------------------------------------------------
......
......@@ -44,6 +44,8 @@
#include "Settings.h"
#include "StringImpl.h"
#include "TextAffinity.h"
#include "UserContentTypes.h"
#include "UserScriptTypes.h"
#include "WebAccessibilityObject.h"
#include "WebApplicationCacheHost.h"
#include "WebClipboard.h"
......@@ -56,6 +58,7 @@
#include "WebSettings.h"