package com.dbs.mplus.fatima.view.web;

import android.content.Context;
import android.os.Message;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.widget.ProgressBar;

/**
 * progressBar 처리 
 * @author hyeeun 
 *
 */
public class MPlusWebChromeClient extends WebChromeClient {
    private final Context context;
    private final ProgressBar pb;

    /**
     * 생성자
     * @param context
     * @param pb
     */
    public MPlusWebChromeClient(Context context, ProgressBar pb) {
        this.pb = pb;
        this.context = context;
    }

    @Override
    public void onProgressChanged(WebView view, int newPB) {
        this.pb.setProgress(newPB);
        super.onProgressChanged(view, newPB);
    }

    @Override
    public boolean onCreateWindow(WebView view, boolean isDialog, boolean isUserGesture, Message resultMsg) {
        // a tag의 target=_blank 처리하기 위함임
        // http://lsit81.tistory.com/entry/Android-WebView%EC%97%90%EC%84%9C-a-%ED%83%9C%EA%B7%B8%EC%9D%98-blank-target-%EC%B2%98%EB%A6%AC%ED%95%98%EA%B8%B0
        WebView newView = new WebView(this.context);

        WebView.WebViewTransport transport = (WebView.WebViewTransport)resultMsg.obj;
        transport.setWebView(newView);
        resultMsg.sendToTarget();

        return true;
    }
}
