Posted on Leave a comment

Chromium Android工程迁移编译过程

本文从Chromium编译的中间产物入手深入分析、学习Chromium Android版本的工程化定制流程。初始工作依赖于Chromium的ninja、GYP构建系统,在构建完成后基于编译中间产物,迁入Android Studio作为新的构建工程,测试编译发布的过程。

注:这种编译过程除了资源文件外其他编译中间产物,都不可修改,不具备大规模定制化的可能性,仅作为熟悉编译过程和代码结构的学习、测试使用。

前提

Chromium代码结构、Android开发、Android Studio使用

编译Chromium

编译步骤可以参考Chromium团队的文章,可以选择编译目标为chrome_public_apk、content_shell_apk,本文以chrome_public_apk为例。

编译结果APK

在以chrome_public_apk为编译目标后,在经历一段时间后编译完成,在out/***文件夹内就包含了所有的编译结果和编译中间产物,其中apk在apks文件夹内,可以拉取安装一下,除了包名外其他功能与Chrome基本一致,本文的迁移目标就是在Android Studio工程下同样可以编译出这个APK,再探讨后续的源码迁移和定制工作。

工作目录

在out/***文件夹下,我们主要涉及到的文件分为三类:so、jar、resource,各自又来自不同的Chromium模块。

apks—编译目标文件目录

gen—编译过程中间产物,基本不涉及

lib.java—jar文件的主要来源,将不同模块的java文件编译后汇集在这个目录

locale—国际化的资源文件

resource-zips—资源文件的主要来源,也是Android Studio module化的主要依据

lib.unstripped—so文件目录

建立Android Studio工程

由于Chromium原有模块是基于命名空间来管理的,而且Android的R资源文件定义方式与此关联,所以需要通过Android Application、Library module的方式进行区分,同时还需要将Android Support这一类第三方库通过Gradle依赖的方式进行关联,而不是JAR+资源文件的方式。

所以基于Chromium的模块划分方式分为如下几个子module:

app—org.chromium.chrome,主App Application

ui—org.chromium.ui,Android Library

base—org.chromium.base,Android Library

components—com.chromium.components,Android Library

content—org.chromium.content,Android Library

media—org.chromium.media,Android Library

autofill—org.chromium.components.autofill,Android Library

web_contents_delegate_android—org.chromium.components.web_contents_delegate_android,Android Library

third_party—com.chromium.third_party,Android Library

tools—org.chromium.tools,Android Library

url—org.chromium.url,Android Library

builder—org.chromium.build,Android Library

net—org.chromium.net,Android Library

mojo—org.chromium.mojo,Android Library

device—org.chromium.device,Android Library

gpu—org.chromium.gpu,Android Library

printing—org.chromium.printing,Android Library

services—org.chromium.services,Android Library

skia—org.chromium.skia,Android Library

迁移编译后so

lib.unstripped目录下的所有so文件,迁入主工程的jniLibs文件中,并在CMake文件中配置引入,切记。

add_library(xxx SHARED IMPORTED)
set_target_properties(xxx PROPERTIES IMPORTED_LOCATION src/main/jniLibs/${ANDROID_ABI}/libxxx.so)

迁移编译后Jar

lib.java目录下按照已经建立好的Android Library工程分别放入libs目录下,注意仅放入非interface.jar的文件,否则可能导致duplicate class问题,同时注意JAR文件重名问题,建议以多多级目录重命名的方式导入。

迁移编译后Resource

gen/chrome/android/chrome_public_apk目录下的AndroidManifest.xml 拷贝到主工程中

resource_zips目录下也同样按照Android Library工程分别解压放入res目录下,尤其注意覆盖问题,因为同一模块下可能有同名的资源文件。android_deps、gvr目录下的资源文件不引入,后续将通过Gradle依赖方式引入。

除此之外还需要将额外的资源文件引入主工程assets目录中,并且禁用压缩。文件如下:chrome_100_percent.pak

icudtl.dat

resources.pak

snapshot_blob.bin

locales目录(包含目录这一级)

修正工程参数+Gradle

上述步骤做完以后工程不能如期运行,还需要调整几个地方,因为有些java文件是在编译过程中生成的:

gen/chrome/android/chrome_public_apk__build_config_java下的buildConfig.java

此文件主要定义启动参数等信息,这个文件主要参考信息,由于Gradle编译的过程中最终会覆盖这个文件,所以里面的所有参数需要通过Gradle配置进行定义。

gen/chrome/android/chrome_public_apk__native_libraries_java下的NativeLibraries.java

此文件主要定义了需要引入哪些so文件、版本号等信息。

运行编译

这一系列的步骤,可以通过一步步的运行报错进行修正,最后得到正确运行的编译包。最后还是那句话,这只是探索定制化过程的一小小步,Chromium项目庞大,需要长久的深入。

如果只是想体验一下迁移后的结果工程,文末附Github工程

Posted on Leave a comment

浅析宽带运营商劫持

今天请求公司主站裸域会导致莫名奇妙的跳转到yiqifa.com然后再跳转回www域的诡异问题,清理Cookies、更换DNS均无效,郁闷!在公司群里讨论了一下大概可以锁定为宽带运营商劫持,由于之前安装了Wireshark也没怎么用,正好出现类似问题,使用HTTP抓包工具分析再好不过了。关闭大部分的可能产生网络连接的软件,Start&Action!

去掉正常的请求响应包,锁定到302请求,依次向下查看,果然发现了一些猫腻。截图如下:Screen Shot 2015-04-18 at 16.07.18

96号 百度HM请求包61.135.185.140

URL:http://hm.baidu.com/h.js?ca88bf7b092f300a228b2c153a0a9fc8

97号 百度HM响应包61.135.185.140

HTTP 302 Location=http://122.141.234.60:51234/bdpop.sl.php?http://hm.baidu.com/h.js?ca88bf7b092f300a228b2c153a0a9fc8

当浏览器302跳转上述地址时响应Cookie里面增加了一个DIANSHANG=54

 

100号 跳转URL请求包122.141.234.60

URL:http://122.141.234.60:51234/bdpop.sl.php?http://hm.baidu.com/h.js?ca88bf7b092f300a228b2c153a0a9fc8

 

103号TCP超时快速重传包61.135.185.140

HTTP 304

 

106号跳转URL响应包122.141.234.60

HTTP 200

window.location=’http://p.yiqifa.com/n?k=2mLErn2OWE3lrI6H2mLErI6H6ljqWmLm6lwLWN6HWl3FWNtsrI6HkQLErnWLWlDO39MErBXpgZUfgmL-&e=c&t=http://www.wangjiu.com’;

 

117号浏览器加载上述Location请求包

 

我们所看到的劫持发生在96号请求包和97号响应包之间,大致过程如下:

1)浏览器将/h.js的请求(96号)发送到百度;

2)宽带运营商嗅探到这个请求后,会将百度的302响应进行篡改,然后转发至用户浏览器(97号),与此同时对百度TCP连接的响应直接给予超时处理;

3)此时真正的响应(来自百度)可能还未到达用户。这就导致了百度服务器认为响应没有送达用户浏览器-发起TCP快速重传(103号),但是用户浏览器在这个过程已经确认收到响应(来自宽带运营商);

4)根据响应结果,浏览器触发302跳转,然后就是我们所看到的先跳转yiqifa.com(117号)然后yiqifa将它的CPSID带上再跳转回主站(后续包)。

Posted on Leave a comment

Google Chrome:如何变得更快,更强,更智能

如果你还没有用过Chrome这款浏览器,抓紧安装体验一下吧。在这个比拼浏览器速度的年代,Google完胜Mozilla、微软,特别是JavaScript的性能方面。即便如此,如果你对Chrome做一些额外的调整将会让它更快。

为了我们

To help with that effort, we’ve gathered for your consideration a few of our favorite free Google Chrome. Experience the power enhancements they provide, and in a few days you’ll wonder how you ever survived online with a bare-bones browser.

如果你是Geek,通过Chrome的实验特性发挥CPU、GPU的性能来优化你的网上冲浪。这些特性被隐藏在不起眼的Chrome菜单中,这样做是为了防止初级用户无意搞崩他们的浏览器,所以在这里我们会说明这些特性是如何工作的。速度来围观吧!

效率扩展程序
如果你还没安装最新版的Chrome,猛戳此处下载再说吧。下载完后打开Chrome web商店,你就会看到众多的适合你的扩展程序-游戏、音乐播放器、社交网络等等。
下面列出的这些扩展能够让我们的Chrome更加易用方便。

FastestChrome: 正如它的名字让你有所期待一样,安装上它可以为你节省大量的时间。它主要提供一些界面上的操作。比如你选中一个词想知道它的意思时,它会弹出一个浮动框,提供维基百科、Google、Surf Canyon、DuckDuckGo四个搜索引擎来查看这个词语的解释。

 

这个扩展程序还可以将你选中的URL文本转换为可以点击的链接(这使得阅读那些来自技术一般人写的Email变得非常容易)。除此之外,自动翻页会在你浏览到web网页(比如Google 搜索结果页、一个8页的文章)末尾时自动加载下一页内容而无需点击下一页链接。

Google Quick Scroll: 这个扩展可以让你直接看到目标网站上的搜索关键词。使用它,每次你点击一个搜索链接,一个包含搜索关键词的小组件会显示在目标网页的右下角,点击组件可以直达你要搜索的关键词位置。

Chrome Toolbox: 这个扩展可以让你一次点击打开多个书签;缓存未提交的表单数据从而避免下次再次输入;在浏览器内部放大图片、视频等等,总之,它让Chrome的用途翻倍了。

冒险体验实验特性

运行Chrome,在地址栏键入chrome://flags/ ,回车,打开Chrome实验特性列表,它们会直接影响到你的web浏览性能。如果你想查看其他隐藏的Chrome菜单,在地址栏键入chrome://chrome-urls/ ,回车。flags页面包含了所有的实验特性,所以我们先来说它。

At this is the point, we’d normally offer a disclaimer about messing around with experimental features in an application—but Google has handled that task quite well on its own. 当你进入Chrome flags页面首先会有如下的警告信息:

请小心,这些实验可能有风险 我们随时可能会更改、中止或取消这些实验性功能。因此,我们完全无法保证您启用某项实验性功能后会发生什么情况,您的浏览器甚至可能会自动崩溃。请注意,您的浏览器可能会删除所有的数据,您的安全性和隐私权也有可能遭到意外损害。您启用的所有实验性功能会面向此浏览器的所有用户。请谨慎操作。

Though the stuff we’ll discuss doing in this article is more likely to cause simple rendering errors or to adversely affect performance than to wreak any major havoc, caution is appropriate.

Flipping switches

Google Chrome’s flags menu presents a long list of experimental options, only a few of which focus on performance. They include the following seven options.

Override software rendering list Mac, Windows, Linux, Chrome OS: This option overrides Chrome’s built-in software rendering list and permits GPU acceleration on unsupported system configurations. If you’re running experimental GPU drivers, switching this flag on will probably shorten loading times for games and videos.

GPU compositing on all pages Mac, Windows, Linux: This option will force GPU-accelerated compositing on all webpages, not just those with GPU-accelerated layers. Enabling this option will probably give you a minor speed boost across the board.

Threaded compositing Mac, Windows, Linux, Chrome OS: Threaded compositing will launch a secondary thread on multicore systems dedicated to webpage compositing. Enabling this option may result in smoother scrolling, even if the main thread is busy with other processing duties.

Disable accelerated 2D canvas Mac, Windows, Linux, Chrome OS: Disabling this option prevents the GPU from performing 2D canvas rendering and causes it instead to use the hot CPU for software rendering.

Disable accelerated CSS animations Mac, Windows, Linux, Chrome OS: When threaded compositing is active, accelerated CSS animations run on the compositing thread. However, running accelerated CSS animations, even without the compositor thread, may yield performance gains.

GPU Accelerated SVG Filters Mac, Windows, Linux, Chrome OS: This option taps your GPU to accelerate the rendering of scalable vector graphics filters, which could speed up the loading process on websites that use a lot of heavy drop shadows or other visual filter effects.

Disable GPU VSync Mac, Windows, Linux, and Chrome OS: If you’re a gamer, you’ve probably heard of vertical sync, aka Vsync. Shutting off Vsync disables synchronization with your monitor’s vertical refresh rate. If your monitor has a refresh rate of 60Hz, for example, disabling Vsync allows the GPU to output at a rate faster than 60Hz—or 60 frames per second—when possible.

Depending on your system’s configuration and on your version of Chrome, some of these options may or may not be enabled by default. And depending on the graphics drivers and OS updates you’ve installed, some of them may not have any effect on performance at all. Nevertheless, it’s worth experimenting with them and visiting your favorite websites to see if they produce any benefits. In our experience, the Accelerated 2D canvas and GPU compositing options offer the most extensive advantages. On the other hand, disabling Vsync seemed to cause rendering issues on our Windows 8 Pro-based test systems on websites that use HTML5 animations.

Establishing the benefits (or drawbacks) of many of the experimental settings mentioned above proved to be rather difficult. We did, however, observe some performance differences when we ran quick tests using Rightware’s BrowserMark and some of the browser benchmarks available on the IE 10 Test Drive site.

With all of the hardware acceleration options disabled in Chrome, our Core i3-powered Acer TravelMate test system (with 8GB of RAM and Windows 8 Pro) using Chrome v22.0.1229.96 scored 314,359 in BrowserMark, and it managed a frame rate of 16 frames per second in the “Bubbles” benchmark on the IE 10 Testdrive site.

Enabling GPU and threaded compositing in Chrome resulted produced a BrowserMark score of 351,492, but had no impact on the Bubbles benchmark. Enabling the other features (and disabling Vsync) yielded a Browsermark score of 361,687; however, the Bubble benchmark wouldn’t render properly and wasn’t fully visible on-screen. Reenabling Vsync fixed the Bubble benchmark, and bumped the measured frame rate to 27 fps. Specifically, the Accelerated 2D canvas setting boosted the graphics performance in the Bubbles test.

If you already have a fast system and you keep your software, drivers, and browser version up-to-date, it probably already uses some form of hardware acceleration—and its performance should be quite good. Even so, experimenting with some of the hidden features in Chrome may net some additional performance for free, and that’s never a bad thing.

原文链接:http://www.pcworld.com/article/2027955/google-chrome-how-to-make-it-faster-smarter-and-better-than-before.html