From d6eb0d6629360c42d17bad5498711a06aca65cd8 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Mon, 19 Dec 2016 15:50:47 -0800 Subject: [PATCH] Implement insertCSS on webFrame --- atom/browser/api/atom_api_web_contents.cc | 5 ----- atom/renderer/api/atom_api_web_frame.cc | 6 ++++++ atom/renderer/api/atom_api_web_frame.h | 1 + lib/browser/api/web-contents.js | 1 + 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index 17fe83a..3d1c247 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -977,10 +977,6 @@ std::string WebContents::GetUserAgent() { 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, const content::SavePageType& save_type, const SavePageHandler::SavePageCallback& callback) { @@ -1561,7 +1557,6 @@ void WebContents::BuildPrototype(v8::Isolate* isolate, .SetMethod("isCrashed", &WebContents::IsCrashed) .SetMethod("setUserAgent", &WebContents::SetUserAgent) .SetMethod("getUserAgent", &WebContents::GetUserAgent) - .SetMethod("insertCSS", &WebContents::InsertCSS) .SetMethod("savePage", &WebContents::SavePage) .SetMethod("openDevTools", &WebContents::OpenDevTools) .SetMethod("closeDevTools", &WebContents::CloseDevTools) diff --git a/atom/renderer/api/atom_api_web_frame.cc b/atom/renderer/api/atom_api_web_frame.cc index a7b71c3..7fa1968 100644 --- a/atom/renderer/api/atom_api_web_frame.cc +++ b/atom/renderer/api/atom_api_web_frame.cc @@ -190,6 +190,11 @@ void WebFrame::InsertText(const std::string& 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, mate::Arguments* args) { bool has_user_gesture = false; @@ -251,6 +256,7 @@ void WebFrame::BuildPrototype( .SetMethod("registerURLSchemeAsPrivileged", &WebFrame::RegisterURLSchemeAsPrivileged) .SetMethod("insertText", &WebFrame::InsertText) + .SetMethod("insertCSS", &WebFrame::InsertCSS) .SetMethod("executeJavaScript", &WebFrame::ExecuteJavaScript) .SetMethod("getResourceUsage", &WebFrame::GetResourceUsage) .SetMethod("clearCache", &WebFrame::ClearCache) diff --git a/atom/renderer/api/atom_api_web_frame.h b/atom/renderer/api/atom_api_web_frame.h index 4b5610c..a35b86c 100644 --- a/atom/renderer/api/atom_api_web_frame.h +++ b/atom/renderer/api/atom_api_web_frame.h @@ -69,6 +69,7 @@ class WebFrame : public mate::Wrappable { // Editing. void InsertText(const std::string& text); + void InsertCSS(const std::string& css); // Excecuting scripts. void ExecuteJavaScript(const base::string16& code, mate::Arguments* args); diff --git a/lib/browser/api/web-contents.js b/lib/browser/api/web-contents.js index ca702b1..de31eeb 100644 --- a/lib/browser/api/web-contents.js +++ b/lib/browser/api/web-contents.js @@ -99,6 +99,7 @@ WebContents.prototype.sendToAll = function (channel, ...args) { // Following methods are mapped to webFrame. const webFrameMethods = [ + 'insertCSS', 'insertText', 'setLayoutZoomLevelLimits', 'setVisualZoomLevelLimits', -- 2.7.4