版权声明:转载请邮件联系我([email protected]),以取得授权,谢谢! https://blog.csdn.net/yeshennet/article/details/84717288
引文
通过前面几篇文章的介绍,现在来看ARChon的js代码就简单多了。基础代码是 ARC 的运行环境。然后ChromeApp启动,ChromeApp在配置项中配置了apk的路径。然后调用 ARChon的扩展程序。打开一个窗口。
那么 ARChon 从哪里看起呢?
main.js
chrome.app.runtime.onLaunched.addListener(onLaunch);
...
launchAppWindow();
...
function launchAppWindow(opt_userEmail) {
var time_0 = (new Date()).getTime();
var abs_index_html = 'runtime/gen_index.min.html';
var window_id = '';
var runtime_id = getRuntimeID();
// Workaround crbug.com/180039 by constructing the absolute path (within
// the App CRX root) to index.html
abs_index_html = '/_modules/' + runtime_id + '/gen_index.min.html';
window_id = runtime_id;
// Override the window ID so App windows from tests will be distinct.
if (args.hasOwnProperty('windowIdOverride')) {
window_id = args['windowIdOverride'];
}
appWindow = chrome.app.window.get(window_id);
if (appWindow != null && !args.forceWindowCreate) {
var onRelaunched = appWindow.contentWindow.arc.onRelaunched;
if (!onRelaunched) {
console.error('onLaunched is called during initialization.');
return;
}
onRelaunched(args);
return;
}
// Note: The code above this point runs every time the App Launcher
// icon is clicked, regardless of whether the App is currently launched.
// Do not put one-time init code above this point.
// TODO(crbug.com/417403): Refactor this whole function, there are clearly
// two paths here, one for when the app is already launched and needs to
// be relaunched, and when we need a new window to be created. There
// should not be the need for a comment like this about not putting one-time
// init code in "launchAppWindow".
console.time('ARC Window Popup');
maybeKillDexopt_();
crashReporter.init();
var appWidth = arcMetadata.getValue('width');
var appHeight = arcMetadata.getValue('height') + _TOPBAR_HEIGHT;
var options = {
// Specify an id for the window to make the window a singleton.
id: window_id,
// TODO(jhorwich) Switch to innerBounds when Chrome 36 is stable as this
// bounds is deprecated in favor of innerBounds.
width: appWidth,
height: appHeight,
resizable: arcMetadata.getValue('resize') != 'disabled',
// Showing the app window is not a cheap operation for the browser
// process. Not to slow down nexe loading, create the window with
// 'hidden: true', and show it later in plugin.js when the process
// is idle.
hidden: true,
frame: 'none'
};
if (!systemDirectoriesCreated) {
systemDirectoriesCreated = createSystemDirectories();
}
chrome.app.window.create(abs_index_html, options, function(w) {
console.timeEnd('ARC Window Popup');
console.time('ARC appWindow Init');
if (opt_appWindowCreationCallback)
opt_appWindowCreationCallback(w);
appWindow = w;
appWindow.contentWindow['arc'] = {
launchArgs: args,
appLaunchTime: time_0,
backgroundPage: window,
runtimeUpdatedWhileRunning: null,
userEmail: opt_userEmail,
systemDirectoriesReady: new PromiseBridge(systemDirectoriesCreated)
};
appWindow.setBounds({width: appWidth, height: appHeight});
appWindow.contentWindow.openParentWindow = function(url) {
return window.open(url);
};
appWindow.onClosed.addListener(function() {
appWindow = null;
// Reset |appLaunched| so that the onInstalled handler can dexopt
// an apk when the app is auto-updated.
appLaunched = false;
});
console.timeEnd('ARC appWindow Init');
});
}
可以看到,它是获取了ARC运行环境,然后把参数(arcMetadata)都填给ARC。dexopt等安装细节、窗口的显示与渲染、点击事件的输出都是ARC处理的。通过nmf的配置文件可知,chrome会先做连接,然后启动 arc_nacl_x86_64.nexe
。
那么什么是ARC?如何编译呢?参考这篇文章的背景介绍。
// TODO 未完待续