Merge pull request #2297 from atom/get-user-agent

Implement getUserAgent API.
This commit is contained in:
Cheng Zhao 2015-07-22 15:38:35 +08:00
commit 3250764e72
5 changed files with 15 additions and 0 deletions

View file

@ -563,6 +563,10 @@ void WebContents::SetUserAgent(const std::string& user_agent) {
base::Bind(&SetUserAgentInIO, getter, user_agent)); base::Bind(&SetUserAgentInIO, getter, user_agent));
} }
std::string WebContents::GetUserAgent() {
return web_contents()->GetUserAgentOverride();
}
void WebContents::InsertCSS(const std::string& css) { void WebContents::InsertCSS(const std::string& css) {
web_contents()->InsertCSS(css); web_contents()->InsertCSS(css);
} }
@ -767,6 +771,7 @@ mate::ObjectTemplateBuilder WebContents::GetObjectTemplateBuilder(
.SetMethod("_goToOffset", &WebContents::GoToOffset) .SetMethod("_goToOffset", &WebContents::GoToOffset)
.SetMethod("isCrashed", &WebContents::IsCrashed) .SetMethod("isCrashed", &WebContents::IsCrashed)
.SetMethod("setUserAgent", &WebContents::SetUserAgent) .SetMethod("setUserAgent", &WebContents::SetUserAgent)
.SetMethod("getUserAgent", &WebContents::GetUserAgent)
.SetMethod("insertCSS", &WebContents::InsertCSS) .SetMethod("insertCSS", &WebContents::InsertCSS)
.SetMethod("_executeJavaScript", &WebContents::ExecuteJavaScript) .SetMethod("_executeJavaScript", &WebContents::ExecuteJavaScript)
.SetMethod("openDevTools", &WebContents::OpenDevTools) .SetMethod("openDevTools", &WebContents::OpenDevTools)

View file

@ -63,6 +63,7 @@ class WebContents : public mate::TrackableObject<WebContents>,
void GoToOffset(int offset); void GoToOffset(int offset);
bool IsCrashed() const; bool IsCrashed() const;
void SetUserAgent(const std::string& user_agent); void SetUserAgent(const std::string& user_agent);
std::string GetUserAgent();
void InsertCSS(const std::string& css); void InsertCSS(const std::string& css);
void ExecuteJavaScript(const base::string16& code); void ExecuteJavaScript(const base::string16& code);
void OpenDevTools(mate::Arguments* args); void OpenDevTools(mate::Arguments* args);

View file

@ -269,6 +269,7 @@ registerWebViewElement = ->
"goToOffset" "goToOffset"
"isCrashed" "isCrashed"
"setUserAgent" "setUserAgent"
"getUserAgent"
"executeJavaScript" "executeJavaScript"
"insertCSS" "insertCSS"
"openDevTools" "openDevTools"

View file

@ -875,6 +875,10 @@ Whether the renderer process has crashed.
Overrides the user agent for this page. Overrides the user agent for this page.
### WebContents.getUserAgent()
Returns a `String` represents the user agent for this page.
### WebContents.insertCSS(css) ### WebContents.insertCSS(css)
* `css` String * `css` String

View file

@ -215,6 +215,10 @@ Whether the renderer process has crashed.
Overrides the user agent for guest page. Overrides the user agent for guest page.
### `<webview>`.getUserAgent()
Returns a `String` represents the user agent for guest page.
### `<webview>`.insertCSS(css) ### `<webview>`.insertCSS(css)
* `css` String * `css` String