From e214ce6bc407086346c03bfd0f2da5c4c7625f97 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 24 Oct 2014 21:04:50 +0800 Subject: [PATCH] Add WebContents.insertCSS --- atom/browser/api/atom_api_web_contents.cc | 5 +++++ atom/browser/api/atom_api_web_contents.h | 1 + atom/renderer/lib/web-view.coffee | 6 +++--- docs/api/browser-window.md | 6 ++++++ 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index 7f8db5855bb0..5d732cc97f3c 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -293,6 +293,10 @@ void WebContents::SetUserAgent(const std::string& user_agent) { web_contents()->SetUserAgentOverride(user_agent); } +void WebContents::InsertCSS(const std::string& css) { + web_contents()->InsertCSS(css); +} + void WebContents::ExecuteJavaScript(const base::string16& code) { web_contents()->GetMainFrame()->ExecuteJavaScript(code); } @@ -365,6 +369,7 @@ mate::ObjectTemplateBuilder WebContents::GetObjectTemplateBuilder( .SetMethod("getProcessId", &WebContents::GetProcessID) .SetMethod("isCrashed", &WebContents::IsCrashed) .SetMethod("setUserAgent", &WebContents::SetUserAgent) + .SetMethod("insertCSS", &WebContents::InsertCSS) .SetMethod("_executeJavaScript", &WebContents::ExecuteJavaScript) .SetMethod("_send", &WebContents::SendIPCMessage) .SetMethod("setAutoSize", &WebContents::SetAutoSize) diff --git a/atom/browser/api/atom_api_web_contents.h b/atom/browser/api/atom_api_web_contents.h index 6ee1184a5339..393fd4969d16 100644 --- a/atom/browser/api/atom_api_web_contents.h +++ b/atom/browser/api/atom_api_web_contents.h @@ -55,6 +55,7 @@ class WebContents : public mate::EventEmitter, int GetProcessID() const; bool IsCrashed() const; void SetUserAgent(const std::string& user_agent); + void InsertCSS(const std::string& css); void ExecuteJavaScript(const base::string16& code); bool SendIPCMessage(const base::string16& channel, const base::ListValue& args); diff --git a/atom/renderer/lib/web-view.coffee b/atom/renderer/lib/web-view.coffee index 2a637fcf8460..0c16485d1d41 100644 --- a/atom/renderer/lib/web-view.coffee +++ b/atom/renderer/lib/web-view.coffee @@ -511,11 +511,11 @@ registerWebViewElement = -> "goToIndex" "goToOffset" "isCrashed" - "executeJavaScript" - "send" "setUserAgent" + "executeJavaScript" + "insertCSS" + "send" # "getZoom" - # "insertCSS" # "print" # "setZoom" # "terminate" diff --git a/docs/api/browser-window.md b/docs/api/browser-window.md index 72280a88c6ed..94c638a77902 100644 --- a/docs/api/browser-window.md +++ b/docs/api/browser-window.md @@ -612,6 +612,12 @@ Whether the renderer process has crashed. Overrides the user agent for this page. +### WebContents.insertCSS(css) + +* `css` String + +Injects CSS into this page. + ### WebContents.executeJavaScript(code) * `code` String