zoukankan      html  css  js  c++  java
  • Browser设置UA值

    SWE Browser中的OptionMenu是Controller通过onKeyDown监听KEYCODE_MENU来显示的

        public boolean onKeyDown(int keyCode, KeyEvent event) {
              if (keyCode == KeyEvent.KEYCODE_MENU && event.getRepeatCount() == 0) {
                  // Hardware menu key
                  mAppMenuHandler.showAppMenu(mActivity.findViewById(R.id.taburlbar),
                        true, false);
                  return true;
              }
    mAppMenuHandler = new AppMenuHandler(browser, this, R.menu.browser);

    查看“关于”菜单处理,Engine.getDefaultUserAgent()来获取UA值。 看上去没法直接修改UA值了。(直接用string重新赋值无法通过A-ku test,因为UA没写到系统里)

    case R.id.about_menu_id:
                    Bundle bundle = new Bundle();
                    Log.i("antoon", "Engine.getDefaultUserAgent = "+Engine.getDefaultUserAgent());
                    bundle.putCharSequence("UA", Engine.getDefaultUserAgent());//org.codeaurora.swe.Engine看上去遥不可及
                    bundle.putCharSequence("TabTitle", mTabControl.getCurrentTab().getTitle());
                    bundle.putCharSequence("TabURL", mTabControl.getCurrentTab().getUrl());
                    BrowserPreferencesPage.startPreferenceFragmentExtraForResult(mActivity,
                            AboutPreferencesFragment.class.getName(), bundle, 0);
                    break;
    ------------------------------------------
    org.codeaurora.swe.Engine中
    public static String getDefaultUserAgent() {
            return AwSettings.getDefaultUserAgent();//org.chromium.android_webview.AwSettings看上去更加遥不可及
    }
    然后搜索到这个 http://blog.csdn.net/chaoy1116/article/details/19083081?utm_source=tuicool  都要改动 C/C++ 了,对于不懂C的似乎没法改了。

    然后发现com.android.browser.BrowserConfigBase中可以对UA进行自定义,Browser中已经提供了完整的设置方法,不用担心UA写到底层的处理。

      public void overrideUserAgent() {
     
            // Check if the UA is already present using command line file
            if (BrowserCommandLine.hasSwitch(OVERRIDE_USER_AGENT)) {
                return;
            }        
           
            //String ua = mContext.getResources().getString(R.string.def_useragent);//源码默认用R.string.def_useragent配置
            String ua = Settings.System.getString(mContext.getContentResolver(), UA);//我改成读取Settings.system数据库配置
            
            if (TextUtils.isEmpty(ua))
                return;
    
            ua = constructUserAgent(ua);
    
            if (!TextUtils.isEmpty(ua)){
                BrowserCommandLine.appendSwitchWithValue(OVERRIDE_USER_AGENT, ua);//这里将UA写到系统中
            }
        }
    --------------------------------------------
    org.codeaurora.swe.BrowserCommandLine
      public static void appendSwitchWithValue(String switchString, String value) {
            CommandLine.getInstance().appendSwitchWithValue(switchString, value);//org.chromium.base.CommandLine
        }
    和上面org.chromium.android_webview.AwSettings获取UA同理,org.chromium.base.CommandLine设置UA值也写到了C/C++层了。
    由于 BrowserConfigBase设置UA 在Browser启动初始化时调用,所以Engine.getDefaultUserAgent()获取的就是自定义的UA了
  • 相关阅读:
    zpf 视图
    html5本地存储
    sqlite 使用记录
    百度开放平台
    PHP exit() 输出
    yum笔记
    手动编译安装软件
    while循环
    linux下面测试网络带宽 (转载)
    软件包管理器的核心功能(笔记)
  • 原文地址:https://www.cnblogs.com/antoon/p/4466140.html
Copyright © 2011-2022 走看看