Add WebContents.setUserAgent

This commit is contained in:
Cheng Zhao 2014-10-24 20:57:44 +08:00
parent 07a8a50861
commit 1f08d50e98
4 changed files with 15 additions and 2 deletions

View file

@ -289,6 +289,10 @@ bool WebContents::IsCrashed() const {
return web_contents()->IsCrashed();
}
void WebContents::SetUserAgent(const std::string& user_agent) {
web_contents()->SetUserAgentOverride(user_agent);
}
void WebContents::ExecuteJavaScript(const base::string16& code) {
web_contents()->GetMainFrame()->ExecuteJavaScript(code);
}
@ -360,6 +364,7 @@ mate::ObjectTemplateBuilder WebContents::GetObjectTemplateBuilder(
.SetMethod("getRoutingId", &WebContents::GetRoutingID)
.SetMethod("getProcessId", &WebContents::GetProcessID)
.SetMethod("isCrashed", &WebContents::IsCrashed)
.SetMethod("setUserAgent", &WebContents::SetUserAgent)
.SetMethod("_executeJavaScript", &WebContents::ExecuteJavaScript)
.SetMethod("_send", &WebContents::SendIPCMessage)
.SetMethod("setAutoSize", &WebContents::SetAutoSize)

View file

@ -5,6 +5,8 @@
#ifndef ATOM_BROWSER_API_ATOM_API_WEB_CONTENTS_H_
#define ATOM_BROWSER_API_ATOM_API_WEB_CONTENTS_H_
#include <string>
#include "atom/browser/api/event_emitter.h"
#include "content/public/browser/browser_plugin_guest_delegate.h"
#include "content/public/browser/web_contents_delegate.h"
@ -52,6 +54,7 @@ class WebContents : public mate::EventEmitter,
int GetRoutingID() const;
int GetProcessID() const;
bool IsCrashed() const;
void SetUserAgent(const std::string& user_agent);
void ExecuteJavaScript(const base::string16& code);
bool SendIPCMessage(const base::string16& channel,
const base::ListValue& args);

View file

@ -513,11 +513,10 @@ registerWebViewElement = ->
"isCrashed"
"executeJavaScript"
"send"
# "getUserAgent"
"setUserAgent"
# "getZoom"
# "insertCSS"
# "print"
# "setUserAgentOverride"
# "setZoom"
# "terminate"
]

View file

@ -606,6 +606,12 @@ Navigates to the specified offset from the "current entry".
Whether the renderer process has crashed.
### WebContents.setUserAgent(userAgent)
* `userAgent` String
Overrides the user agent for this page.
### WebContents.executeJavaScript(code)
* `code` String