diff options
Diffstat (limited to 'webkit/glue')
-rw-r--r-- | webkit/glue/webframe.h | 3 | ||||
-rw-r--r-- | webkit/glue/webframe_impl.cc | 20 | ||||
-rw-r--r-- | webkit/glue/webframe_impl.h | 1 |
3 files changed, 24 insertions, 0 deletions
diff --git a/webkit/glue/webframe.h b/webkit/glue/webframe.h index 90b1ec8..9be5100 100644 --- a/webkit/glue/webframe.h +++ b/webkit/glue/webframe.h @@ -99,6 +99,9 @@ class WebFrame { virtual void ExecuteScriptInNewContext( const webkit_glue::WebScriptSource* sources, int num_sources) = 0; + // Inserts the given CSS styles at the beginning of the document. + virtual bool InsertCSSStyles(const std::string& css) = 0; + // Returns a string representing the state of the previous page load for // later use when loading. The previous page is the page that was loaded // before DidCommitLoadForFrame was received. diff --git a/webkit/glue/webframe_impl.cc b/webkit/glue/webframe_impl.cc index 9f87b20..5ad4219 100644 --- a/webkit/glue/webframe_impl.cc +++ b/webkit/glue/webframe_impl.cc @@ -93,6 +93,7 @@ MSVC_PUSH_WARNING_LEVEL(0); #include "GraphicsContext.h" #include "HTMLHeadElement.h" #include "HTMLLinkElement.h" +#include "HTMLNames.h" #include "HistoryItem.h" #include "InspectorController.h" #include "markup.h" @@ -1656,6 +1657,25 @@ void WebFrameImpl::ExecuteScript(const webkit_glue::WebScriptSource& source) { source.start_line)); } +bool WebFrameImpl::InsertCSSStyles(const std::string& css) { + Document* document = frame()->document(); + if (!document) + return false; + WebCore::Element* document_element = document->documentElement(); + if (!document_element) + return false; + + RefPtr<WebCore::Element> stylesheet = document->createElement( + WebCore::HTMLNames::styleTag, false); + ExceptionCode err = 0; + stylesheet->setTextContent(webkit_glue::StdStringToString(css), err); + DCHECK(!err) << "Failed to set style element content"; + WebCore::Node* first = document_element->firstChild(); + bool success = document_element->insertBefore(stylesheet, first, err); + DCHECK(success) << "Failed to insert stylesheet"; + return success; +} + void WebFrameImpl::ExecuteScriptInNewContext( const webkit_glue::WebScriptSource* sources_in, int num_sources) { Vector<WebCore::ScriptSourceCode> sources; diff --git a/webkit/glue/webframe_impl.h b/webkit/glue/webframe_impl.h index c0b4616..96045e1 100644 --- a/webkit/glue/webframe_impl.h +++ b/webkit/glue/webframe_impl.h @@ -93,6 +93,7 @@ class WebFrameImpl : public WebFrame, public base::RefCounted<WebFrameImpl> { virtual void ExecuteScript(const webkit_glue::WebScriptSource& source); virtual void ExecuteScriptInNewContext( const webkit_glue::WebScriptSource* sources, int num_sources); + virtual bool InsertCSSStyles(const std::string& css); virtual bool GetPreviousHistoryState(std::string* history_state) const; virtual bool GetCurrentHistoryState(std::string* history_state) const; virtual bool HasCurrentHistoryState() const; |