[M108 Migration] Add implementation of SetUserAgentOverride
[platform/framework/web/chromium-efl.git] / tizen_src / chromium_impl / content / browser / web_contents / web_contents_impl_efl.cc
index 60e7f33..95c65e5 100644 (file)
@@ -23,6 +23,7 @@
 #include "content/public/browser/web_contents_efl_delegate.h"
 #include "content/public/common/content_client.h"
 #include "content/public/common/result_codes.h"
+#include "net/http/http_util.h"
 
 // Majority of the code in this file was taken directly from
 // WebContentsImpl::CreateNewWindow. Compared to the original, the function
@@ -81,7 +82,28 @@ std::unique_ptr<WebContents> WebContentsImplEfl::Clone() {
 
 void WebContentsImplEfl::SetUserAgentOverride(
     const blink::UserAgentOverride& ua_override,
-    bool override_in_new_tabs) {}
+    bool override_in_new_tabs) {
+  if (GetUserAgentOverride() == ua_override)
+    return;
+
+  if (!ua_override.ua_string_override.empty() &&
+      !net::HttpUtil::IsValidHeaderValue(ua_override.ua_string_override)) {
+    return;
+  }
+
+  should_override_user_agent_in_new_tabs_ = override_in_new_tabs;
+
+  renderer_preferences_.user_agent_override = ua_override;
+
+  // Send the new override string to all renderers in the current page.
+  SyncRendererPrefs();
+
+  // In chromium upstream, the page is reloaded if a load is currently in
+  // progress. However, the behaviour is different for chromium efl port.
+
+  observers_.NotifyObservers(&WebContentsObserver::UserAgentOverrideSet,
+                             ua_override);
+}
 
 WebContentsImpl* WebContentsImplEfl::CreateWebContentsForNewWindow(
     BrowserContext* browser_context,