A new nightly build of WebKit is available! Please take a moment to update to it before continuing your testing.という表記が出て、"update to it" のリンクをクリックするとアップデートするかどうかのダイアログが出る。これはどうやっているのだろうか?
答えは webkit 独自のプロトコルを使っている、が正解。ソースを見てみよう。
var script = document.createElement("script");最初の読み込みに "x-webkit-launcher:is-x-webkit-launcher-available.js" というファイルを読み込む。
script.src = "x-webkit-launcher:is-x-webkit-launcher-available.js";
document.documentElement.appendChild(script);
このファイルの中身はひとつの変数が定義されているだけである。
var isWebKitLauncherAvailable = true;先程のファイルは webkit.org ドメイン以外では読み込んでも中身は何も無い(/etc/hostsで偽装すれば実行可能)。"update to it" のリンクは JavaScript のイベントコールバックとして実行される。このコールバックの中身は以下の通りである。
if (!isWebKitLauncherAvailable)return;意外なことにアップデートダイアログは HTMLImageElement クラスを用いて呼ばれるのである。これも webkit.org 以外で実行しても何も起こらない。
var image = new Image();
image.src = "x-webkit-launcher:check-for-updates";
以上から、まとめると以下の通りである。
- x-webkit-launcher:is-x-webkit-launcher-available.js を読み込んでアップデートダイアログが利用可能かかを調べる
- HTMLImageElement オブジェクトを生成し、"x-webkit-launcher:check-for-updates" をソースにしてアップデートダイアログを生成する
- これらは webkit.org 以外では何も起きない
0 件のコメント:
コメントを投稿