您的位置:首页 > 移动开发

Chromium APP&Extension 下载安装流程

2016-10-18 13:39 225 查看
打开chromium浏览器的应用商店,点击想安装的应用图标后的页面如下图



1.BeginInstall
点击“添加至chrome”按钮触发事件BeginInstall,开始从webstore获取id,icon_url,manifest等data。这一步应该是在对应的js脚本中完成,然后借助V8引擎的js与C++交互,发送name为webstorePrivate.beginInstallWithManifest3的请求。

2.WebstorePrivateBeginInstallWithManifest3Function::Run
完成WebstorePrivateBeginInstallWithManifest3Function类的初始化后,运行WebstorePrivateBeginInstallWithManifest3Function::Run(),检查id的合法性、icon_url的合法性、是否已经安装过之后,调用WebstoreInstallHelper::Start()

3.WebstoreInstallHelper::Start
这一步的工作是解析manifest.json,成功后调用WebstoreInstallHelper::OnJSONParseSucceeded();获取icon,成功后调用WebstoreInstallHelper::OnFetchComplete()

4.WebstorePrivateBeginInstallWithManifest3Function::OnWebstoreParseSuccess
以上步骤均成功无报错后运行至WebstoreInstallHelper::ReportResultsIfComplete,调用WebstorePrivateBeginInstallWithManifest3Function::OnWebstoreParseSuccess通知data处理完成,在OnWebstoreParseSuccess中检验该应用是否符合管理政策(比如没有被用户加入黑名单之类),浏览器窗口是否被关闭,然后显示是否确定安装的弹框UI,如下图:



5.WebstorePrivateCompleteInstallFunction::Run
点击”添加应用“,触发事件,发送name为webstorePrivate.completeInstall的request,接到请求后完成WebstorePrivateCompleteInstallFunction的初始化,运行至WebstorePrivateCompleteInstallFunction::Run()函数,检查登陆合法性,检查id合法性,检查安装前置步骤解析manifest的完整性,调用WebstoreInstaller::Start()

6.WebstoreInstaller::Start
在这一步,首先检查id的合法性,检验需安装的应用的imports,加上应用的主模块一起加入pending_modules_中,通过V8完成c++与js的交互,改变页面上原来”添加至chrome“图标的显示,调用DownloadNextPendingModule(),判断pending_modules_的个数传不同参数给DownloadCrx()

7.WebstoreInstaller::DownloadCrx
首先根据传入的extension_id调用GetWebstoreInstallURL获取下载链接,创建下载目录后,调用StartDownload()开始下载,经过OnDownloadStarted->OnExtensionDownloadStarted->OnDownloadUpdated->OnExtensionDownloadProgress->UpdateDownloadProgress->OnDownloadUpdated->OnExtensionDownloadProgress->UpdateDownloadProgress->......->OnDownloadUpdated直至状态变为COMPLETE,调用StartCrxInstaller()

8.WebstoreInstaller::StartCrxInstaller
得到上一步的下载文件后,获取安装配置,调用CreateCrxInstaller()新建crx_installer,运行至InstallCrx函数

9.CrxInstaller::InstallCrx
通过NotifyCrxInstallBegin()告知js完成页面交互,借助SandboxedUnpacker类完成解压缩,运行至
OnUnpackSuccess()函数,在该函数中调用AllowInstall()进行许可性检查,之后运行至CheckInstall(),检查完成后调用OnInstallChecksComplete()校验检查结果,确认无误后调用ConfirmInstall()函数->调用UpdateCreationFlagsAndCompleteInstall()函数->调用CompleteInstall()函数,借助ExtensionAssetsManager类完成安装过程

10.CrxInstaller::ReloadExtensionAfterInstall
安装完成后执行回调:CrxInstaller::ReloadExtensionAfterInstall,加载刚刚安装的应用,执行ReportSuccessFromFileThread(),调用CleanupTempFiles(),执行OnExtensionInstalled()、NotifyCrxInstallComplete()进行收尾工作
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  chromium