Implement insertCSS on webFrame

This commit is contained in:
Kevin Sawicki 2016-12-19 15:50:47 -08:00 committed by Birunthan Mohanathas
parent 017df93ffa
commit d6eb0d6629
4 changed files with 8 additions and 5 deletions

View file

@ -977,10 +977,6 @@ std::string WebContents::GetUserAgent() {
return web_contents()->GetUserAgentOverride(); return web_contents()->GetUserAgentOverride();
} }
void WebContents::InsertCSS(const std::string& css) {
// FIXME(zcbenz): Redirect this method to webFrame.
}
bool WebContents::SavePage(const base::FilePath& full_file_path, bool WebContents::SavePage(const base::FilePath& full_file_path,
const content::SavePageType& save_type, const content::SavePageType& save_type,
const SavePageHandler::SavePageCallback& callback) { const SavePageHandler::SavePageCallback& callback) {
@ -1561,7 +1557,6 @@ void WebContents::BuildPrototype(v8::Isolate* isolate,
.SetMethod("isCrashed", &WebContents::IsCrashed) .SetMethod("isCrashed", &WebContents::IsCrashed)
.SetMethod("setUserAgent", &WebContents::SetUserAgent) .SetMethod("setUserAgent", &WebContents::SetUserAgent)
.SetMethod("getUserAgent", &WebContents::GetUserAgent) .SetMethod("getUserAgent", &WebContents::GetUserAgent)
.SetMethod("insertCSS", &WebContents::InsertCSS)
.SetMethod("savePage", &WebContents::SavePage) .SetMethod("savePage", &WebContents::SavePage)
.SetMethod("openDevTools", &WebContents::OpenDevTools) .SetMethod("openDevTools", &WebContents::OpenDevTools)
.SetMethod("closeDevTools", &WebContents::CloseDevTools) .SetMethod("closeDevTools", &WebContents::CloseDevTools)

View file

@ -190,6 +190,11 @@ void WebFrame::InsertText(const std::string& text) {
web_frame_->insertText(blink::WebString::fromUTF8(text)); web_frame_->insertText(blink::WebString::fromUTF8(text));
} }
void WebFrame::InsertCSS(const std::string& css) {
web_frame_->document().insertStyleSheet(blink::WebString::fromUTF8(css));
}
void WebFrame::ExecuteJavaScript(const base::string16& code, void WebFrame::ExecuteJavaScript(const base::string16& code,
mate::Arguments* args) { mate::Arguments* args) {
bool has_user_gesture = false; bool has_user_gesture = false;
@ -251,6 +256,7 @@ void WebFrame::BuildPrototype(
.SetMethod("registerURLSchemeAsPrivileged", .SetMethod("registerURLSchemeAsPrivileged",
&WebFrame::RegisterURLSchemeAsPrivileged) &WebFrame::RegisterURLSchemeAsPrivileged)
.SetMethod("insertText", &WebFrame::InsertText) .SetMethod("insertText", &WebFrame::InsertText)
.SetMethod("insertCSS", &WebFrame::InsertCSS)
.SetMethod("executeJavaScript", &WebFrame::ExecuteJavaScript) .SetMethod("executeJavaScript", &WebFrame::ExecuteJavaScript)
.SetMethod("getResourceUsage", &WebFrame::GetResourceUsage) .SetMethod("getResourceUsage", &WebFrame::GetResourceUsage)
.SetMethod("clearCache", &WebFrame::ClearCache) .SetMethod("clearCache", &WebFrame::ClearCache)

View file

@ -69,6 +69,7 @@ class WebFrame : public mate::Wrappable<WebFrame> {
// Editing. // Editing.
void InsertText(const std::string& text); void InsertText(const std::string& text);
void InsertCSS(const std::string& css);
// Excecuting scripts. // Excecuting scripts.
void ExecuteJavaScript(const base::string16& code, mate::Arguments* args); void ExecuteJavaScript(const base::string16& code, mate::Arguments* args);

View file

@ -99,6 +99,7 @@ WebContents.prototype.sendToAll = function (channel, ...args) {
// Following methods are mapped to webFrame. // Following methods are mapped to webFrame.
const webFrameMethods = [ const webFrameMethods = [
'insertCSS',
'insertText', 'insertText',
'setLayoutZoomLevelLimits', 'setLayoutZoomLevelLimits',
'setVisualZoomLevelLimits', 'setVisualZoomLevelLimits',