]> khamidou — GitHub mirrors - electron.git/commitdiff
Add WebContents.setUserAgent
authorCheng Zhao <zcbenz@gmail.com>
Fri, 24 Oct 2014 12:57:44 +0000 (20:57 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Fri, 24 Oct 2014 12:57:44 +0000 (20:57 +0800)
atom/browser/api/atom_api_web_contents.cc
atom/browser/api/atom_api_web_contents.h
atom/renderer/lib/web-view.coffee
docs/api/browser-window.md

index 4ddf302467ba8478582bd5feb6b204253d66a5b4..7f8db5855bb0866fcbe0e88a6b4b739bf74843e8 100644 (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)
index 1dc37a62ebe2e0282a77e61c9047ddfdedf93878..6ee1184a53396109dcf0f9c671f729b91c9ebda5 100644 (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);
index 1a09aed3c084471fbfe335f42464fde10962488c..2a637fcf8460598e86a8b12ee5049ca3c0ec9671 100644 (file)
@@ -513,11 +513,10 @@ registerWebViewElement = ->
     "isCrashed"
     "executeJavaScript"
     "send"
-    # "getUserAgent"
+    "setUserAgent"
     # "getZoom"
     # "insertCSS"
     # "print"
-    # "setUserAgentOverride"
     # "setZoom"
     # "terminate"
   ]
index 1cead5071682c1e3711d216309c1cc60b8c67945..72280a88c6edff86d08403525241a3ff65bdb30d 100644 (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