From 462e6e0a826950535a14e6854901797f648e9bcc Mon Sep 17 00:00:00 2001 From: Haojian Wu Date: Wed, 22 Jul 2015 12:25:10 +0800 Subject: [PATCH] Implement getUserAgent API. --- atom/browser/api/atom_api_web_contents.cc | 5 +++++ atom/browser/api/atom_api_web_contents.h | 1 + atom/renderer/lib/web-view/web-view.coffee | 1 + docs/api/browser-window.md | 4 ++++ docs/api/web-view-tag.md | 4 ++++ 5 files changed, 15 insertions(+) diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index 6311e1eaf9a4..4bd1e9b6d6e8 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -563,6 +563,10 @@ void WebContents::SetUserAgent(const std::string& user_agent) { base::Bind(&SetUserAgentInIO, getter, user_agent)); } +std::string WebContents::GetUserAgent() { + return web_contents()->GetUserAgentOverride(); +} + void WebContents::InsertCSS(const std::string& css) { web_contents()->InsertCSS(css); } @@ -767,6 +771,7 @@ mate::ObjectTemplateBuilder WebContents::GetObjectTemplateBuilder( .SetMethod("_goToOffset", &WebContents::GoToOffset) .SetMethod("isCrashed", &WebContents::IsCrashed) .SetMethod("setUserAgent", &WebContents::SetUserAgent) + .SetMethod("getUserAgent", &WebContents::GetUserAgent) .SetMethod("insertCSS", &WebContents::InsertCSS) .SetMethod("_executeJavaScript", &WebContents::ExecuteJavaScript) .SetMethod("openDevTools", &WebContents::OpenDevTools) diff --git a/atom/browser/api/atom_api_web_contents.h b/atom/browser/api/atom_api_web_contents.h index bb6b22ac84e2..e3dc363972d4 100644 --- a/atom/browser/api/atom_api_web_contents.h +++ b/atom/browser/api/atom_api_web_contents.h @@ -63,6 +63,7 @@ class WebContents : public mate::TrackableObject, void GoToOffset(int offset); bool IsCrashed() const; void SetUserAgent(const std::string& user_agent); + std::string GetUserAgent(); void InsertCSS(const std::string& css); void ExecuteJavaScript(const base::string16& code); void OpenDevTools(mate::Arguments* args); diff --git a/atom/renderer/lib/web-view/web-view.coffee b/atom/renderer/lib/web-view/web-view.coffee index 72fee948d137..eedee732938f 100644 --- a/atom/renderer/lib/web-view/web-view.coffee +++ b/atom/renderer/lib/web-view/web-view.coffee @@ -269,6 +269,7 @@ registerWebViewElement = -> "goToOffset" "isCrashed" "setUserAgent" + "getUserAgent" "executeJavaScript" "insertCSS" "openDevTools" diff --git a/docs/api/browser-window.md b/docs/api/browser-window.md index ebd511fff0db..f202884f51c6 100644 --- a/docs/api/browser-window.md +++ b/docs/api/browser-window.md @@ -875,6 +875,10 @@ Whether the renderer process has crashed. Overrides the user agent for this page. +### WebContents.getUserAgent() + +Returns a `String` represents the user agent for this page. + ### WebContents.insertCSS(css) * `css` String diff --git a/docs/api/web-view-tag.md b/docs/api/web-view-tag.md index 54e82ef3a7bc..973b62f5b767 100644 --- a/docs/api/web-view-tag.md +++ b/docs/api/web-view-tag.md @@ -215,6 +215,10 @@ Whether the renderer process has crashed. Overrides the user agent for guest page. +### ``.getUserAgent() + +Returns a `String` represents the user agent for guest page. + ### ``.insertCSS(css) * `css` String