stacker stacker -4 years ago 97
Android Question

Where does 'mobile' keyword in the useragent come from in chromium?

I'm confused that on mobile devices(

phone
) on Android system, the useragent of chromium based browser(eg
webview
) have
Mobile
keyword, but on some mobile devices(eg
tablets
) it does not exist, so where is distinguished in the
chrmoium
code?

The mobile devices which have the
Mobile
keyword:

"Mozilla/5.0 (Linux; Android 5.1.1; Nexus 6 Build/LYZ28E) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.23 Mobile Safari/537.36"

Answer Source

Maybe you can check and reference the DeviceUtils.java and aw_content_client.cc in chromium source, it will check the device type by DeviceFormFactor.isTablet() in DeviceUtils.java to decide whether it need to add the Mobile keyword, and set the Mobile keyword in aw_content_client.cc, hopes this information can help you:

//DeviceUtils.java
package org.chromium.content.browser;

import android.content.Context;

import org.chromium.base.CommandLine;
import org.chromium.content.common.ContentSwitches;
import org.chromium.ui.base.DeviceFormFactor;

/**
 * A utility class that has helper methods for device configuration.
 */
public class DeviceUtils {

    /**
     * Appends the switch specifying which user agent should be used for this device.
     * @param context The context for the caller activity.
     */
    public static void addDeviceSpecificUserAgentSwitch(Context context) {
        if (DeviceFormFactor.isTablet(context)) {
            CommandLine.getInstance().appendSwitch(ContentSwitches.USE_MOBILE_UA);
        }
    }
}



   //aw_content_client.cc
   std::string GetUserAgent() {
  // "Version/4.0" had been hardcoded in the legacy WebView.
  std::string product = "Version/4.0 " + GetProduct();
  if (base::CommandLine::ForCurrentProcess()->HasSwitch(
        switches::kUseMobileUserAgent)) {
    product += " Mobile";
  }
  return content::BuildUserAgentFromProductAndExtraOSInfo(
          product,
          GetExtraOSUserAgentInfo());
}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download