Commit c150aba7 authored by aa@chromium.org's avatar aa@chromium.org

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

        Reviewed by David Hyatt.

        Make the cascade level of "user" styles configurable
        https://bugs.webkit.org/show_bug.cgi?id=43457

        * WebCore.exp.in:
        * css/CSSStyleSelector.cpp:
        (WebCore::CSSStyleSelector::CSSStyleSelector):
        * dom/Document.cpp:
        (WebCore::Document::pageGroupUserSheets):
        * page/PageGroup.cpp:
        (WebCore::PageGroup::addUserStyleSheetToWorld):
        * page/PageGroup.h:
        * page/UserStyleSheet.h:
        (WebCore::UserStyleSheet::):
        (WebCore::UserStyleSheet::UserStyleSheet):
        (WebCore::UserStyleSheet::level):
2010-08-12  Aaron Boodman  <aa@chromium.org>

        Reviewed by David Hyatt.

        Make the cascade level of "user" styles configurable
        https://bugs.webkit.org/show_bug.cgi?id=43457

        * src/WebViewImpl.cpp:
        (WebKit::WebView::addUserStyleSheet):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@65273 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent d2525bb7
2010-08-12 Aaron Boodman <aa@chromium.org>
Reviewed by David Hyatt.
Make the cascade level of "user" styles configurable
https://bugs.webkit.org/show_bug.cgi?id=43457
* WebCore.exp.in:
* css/CSSStyleSelector.cpp:
(WebCore::CSSStyleSelector::CSSStyleSelector):
* dom/Document.cpp:
(WebCore::Document::pageGroupUserSheets):
* page/PageGroup.cpp:
(WebCore::PageGroup::addUserStyleSheetToWorld):
* page/PageGroup.h:
* page/UserStyleSheet.h:
(WebCore::UserStyleSheet::):
(WebCore::UserStyleSheet::UserStyleSheet):
(WebCore::UserStyleSheet::level):
2010-08-12 Jian Li <jianli@chromium.org>
Fix qt build break.
......@@ -820,7 +820,7 @@ __ZN7WebCore9PageGroup18addVisitedLinkHashEy
__ZN7WebCore9PageGroup20addUserScriptToWorldEPNS_15DOMWrapperWorldERKN3WTF6StringERKNS_4KURLENS3_10PassOwnPtrINS3_6VectorIS4_Lm0EEEEESD_NS_23UserScriptInjectionTimeENS_25UserContentInjectedFramesE
__ZN7WebCore9PageGroup20removeAllUserContentEv
__ZN7WebCore9PageGroup21removeAllVisitedLinksEv
__ZN7WebCore9PageGroup24addUserStyleSheetToWorldEPNS_15DOMWrapperWorldERKN3WTF6StringERKNS_4KURLENS3_10PassOwnPtrINS3_6VectorIS4_Lm0EEEEESD_NS_25UserContentInjectedFramesE
__ZN7WebCore9PageGroup24addUserStyleSheetToWorldEPNS_15DOMWrapperWorldERKN3WTF6StringERKNS_4KURLENS3_10PassOwnPtrINS3_6VectorIS4_Lm0EEEEESD_NS_25UserContentInjectedFramesENS_14UserStyleSheet5LevelE
__ZN7WebCore9PageGroup25removeUserScriptFromWorldEPNS_15DOMWrapperWorldERKNS_4KURLE
__ZN7WebCore9PageGroup26removeUserScriptsFromWorldEPNS_15DOMWrapperWorldE
__ZN7WebCore9PageGroup26setShouldTrackVisitedLinksEb
......
......@@ -458,25 +458,30 @@ CSSStyleSelector::CSSStyleSelector(Document* doc, StyleSheetList* styleSheets, C
m_medium = new MediaQueryEvaluator(view->mediaType(), view->frame(), m_rootDefaultStyle.get());
}
m_authorStyle = new CSSRuleSet();
// FIXME: This sucks! The user sheet is reparsed every time!
if (pageUserSheet || pageGroupUserSheets) {
m_userStyle = new CSSRuleSet();
OwnPtr<CSSRuleSet> tempUserStyle(new CSSRuleSet);
if (pageUserSheet)
m_userStyle->addRulesFromSheet(pageUserSheet, *m_medium, this);
tempUserStyle->addRulesFromSheet(pageUserSheet, *m_medium, this);
if (pageGroupUserSheets) {
unsigned length = pageGroupUserSheets->size();
for (unsigned i = 0; i < length; i++)
m_userStyle->addRulesFromSheet(pageGroupUserSheets->at(i).get(), *m_medium, this);
for (unsigned i = 0; i < length; i++) {
if (pageGroupUserSheets->at(i)->isUserStyleSheet())
tempUserStyle->addRulesFromSheet(pageGroupUserSheets->at(i).get(), *m_medium, this);
else
m_authorStyle->addRulesFromSheet(pageGroupUserSheets->at(i).get(), *m_medium, this);
}
}
// add stylesheets from document
m_authorStyle = new CSSRuleSet();
if (tempUserStyle->m_ruleCount > 0 || tempUserStyle->m_pageRuleCount > 0)
m_userStyle = tempUserStyle.leakPtr();
// Add rules from elements like SVG's <font-face>
if (mappedElementSheet)
m_authorStyle->addRulesFromSheet(mappedElementSheet, *m_medium, this);
// add stylesheets from document
unsigned length = styleSheets->length();
for (unsigned i = 0; i < length; i++) {
StyleSheet* sheet = styleSheets->item(i);
......
......@@ -2225,7 +2225,7 @@ const Vector<RefPtr<CSSStyleSheet> >* Document::pageGroupUserSheets() const
if (!UserContentURLPattern::matchesPatterns(url(), sheet->whitelist(), sheet->blacklist()))
continue;
RefPtr<CSSStyleSheet> parsedSheet = CSSStyleSheet::createInline(const_cast<Document*>(this), sheet->url());
parsedSheet->setIsUserStyleSheet(true);
parsedSheet->setIsUserStyleSheet(sheet->level() == UserStyleSheet::UserLevel);
parsedSheet->parseString(sheet->source(), !inCompatMode());
if (!m_pageGroupUserSheets)
m_pageGroupUserSheets.set(new Vector<RefPtr<CSSStyleSheet> >);
......
......@@ -236,11 +236,12 @@ void PageGroup::addUserScriptToWorld(DOMWrapperWorld* world, const String& sourc
void PageGroup::addUserStyleSheetToWorld(DOMWrapperWorld* world, const String& source, const KURL& url,
PassOwnPtr<Vector<String> > whitelist, PassOwnPtr<Vector<String> > blacklist,
UserContentInjectedFrames injectedFrames)
UserContentInjectedFrames injectedFrames,
UserStyleSheet::Level level)
{
ASSERT_ARG(world, world);
OwnPtr<UserStyleSheet> userStyleSheet(new UserStyleSheet(source, url, whitelist, blacklist, injectedFrames));
OwnPtr<UserStyleSheet> userStyleSheet(new UserStyleSheet(source, url, whitelist, blacklist, injectedFrames, level));
if (!m_userStyleSheets)
m_userStyleSheets.set(new UserStyleSheetMap);
UserStyleSheetVector*& styleSheetsInWorld = m_userStyleSheets->add(world, 0).first->second;
......
......@@ -80,7 +80,8 @@ namespace WebCore {
UserScriptInjectionTime, UserContentInjectedFrames);
void addUserStyleSheetToWorld(DOMWrapperWorld*, const String& source, const KURL&,
PassOwnPtr<Vector<String> > whitelist, PassOwnPtr<Vector<String> > blacklist,
UserContentInjectedFrames);
UserContentInjectedFrames,
UserStyleSheet::Level level = UserStyleSheet::UserLevel);
void removeUserScriptFromWorld(DOMWrapperWorld*, const KURL&);
void removeUserStyleSheetFromWorld(DOMWrapperWorld*, const KURL&);
......
......@@ -37,14 +37,20 @@ namespace WebCore {
class UserStyleSheet : public Noncopyable {
public:
enum Level {
UserLevel,
AuthorLevel
};
UserStyleSheet(const String& source, const KURL& url,
PassOwnPtr<Vector<String> > whitelist, PassOwnPtr<Vector<String> > blacklist,
UserContentInjectedFrames injectedFrames)
UserContentInjectedFrames injectedFrames, Level level)
: m_source(source)
, m_url(url)
, m_whitelist(whitelist)
, m_blacklist(blacklist)
, m_injectedFrames(injectedFrames)
, m_level(level)
{
}
......@@ -53,6 +59,7 @@ public:
const Vector<String>* whitelist() const { return m_whitelist.get(); }
const Vector<String>* blacklist() const { return m_blacklist.get(); }
UserContentInjectedFrames injectedFrames() const { return m_injectedFrames; }
Level level() const { return m_level; }
private:
String m_source;
......@@ -60,6 +67,7 @@ private:
OwnPtr<Vector<String> > m_whitelist;
OwnPtr<Vector<String> > m_blacklist;
UserContentInjectedFrames m_injectedFrames;
Level m_level;
};
} // namespace WebCore
......
2010-08-12 Aaron Boodman <aa@chromium.org>
Reviewed by David Hyatt.
Make the cascade level of "user" styles configurable
https://bugs.webkit.org/show_bug.cgi?id=43457
* src/WebViewImpl.cpp:
(WebKit::WebView::addUserStyleSheet):
2010-08-12 John Gregg <johnnyg@google.com>
Reviewed by Kent Tamura.
......
......@@ -1949,8 +1949,14 @@ void WebView::addUserStyleSheet(const WebString& sourceCode,
PageGroup* pageGroup = PageGroup::pageGroup(pageGroupName);
RefPtr<DOMWrapperWorld> world(DOMWrapperWorld::create());
// FIXME: Current callers always want the level to be "author". It probably makes sense to let
// callers specify this though, since in other cases the caller will probably want "user" level.
//
// FIXME: It would be nice to populate the URL correctly, instead of passing an empty URL.
pageGroup->addUserStyleSheetToWorld(world.get(), sourceCode, WebURL(), patterns.release(), 0,
static_cast<UserContentInjectedFrames>(injectIn));
static_cast<UserContentInjectedFrames>(injectIn),
UserStyleSheet::AuthorLevel);
}
void WebView::removeAllUserContent()
......
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