2017-03-24 22 views
1

我很困惑,關於Android系統的移動設備(phone),該用戶代理基於Chromium瀏覽器的(例如webview)有Mobile關鍵字,但在某些移動設備(例如tablets),它不存在,那麼在哪裏在chrmoium代碼中區分?useragent中的'mobile'關鍵字來自鉻?

其中有Mobile關鍵字的移動設備:

"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" 

回答

1

也許你可以檢查並引用DeviceUtils.java和鉻源aw_content_client.cc,它會通過在DeviceUtils.javaDeviceFormFactor.isTablet()檢查設備類型來決定是否需要添加Mobile關鍵字,並設置Mobile關鍵字aw_content_client.cc,希望這些信息可以幫助你:

//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()); 
} 
+0

完全按照您p rovided,非常感謝! – stacker

相關問題