1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 package org.chromium.chromedriver_webview_shell;
7 import android.app.Activity;
8 import android.content.Intent;
9 import android.os.Bundle;
10 import android.view.Window;
11 import android.webkit.WebChromeClient;
12 import android.webkit.WebSettings;
13 import android.webkit.WebView;
14 import android.webkit.WebViewClient;
15 import android.widget.Toast;
17 public class Main extends Activity {
18 private WebView mWebView;
21 protected void onCreate(Bundle savedInstanceState) {
22 super.onCreate(savedInstanceState);
24 getWindow().requestFeature(Window.FEATURE_PROGRESS);
25 setContentView(R.layout.main_layout);
27 WebView.setWebContentsDebuggingEnabled(true);
28 mWebView = (WebView) findViewById(R.id.webview);
29 WebSettings webSettings = mWebView.getSettings();
30 webSettings.setJavaScriptEnabled(true);
32 final Activity activity = this;
33 mWebView.setWebChromeClient(new WebChromeClient() {
35 public void onProgressChanged(WebView view, int progress) {
36 activity.setProgress(progress * 100);
39 mWebView.setWebViewClient(new WebViewClient() {
41 public void onReceivedError(WebView view, int errorCode, String description,
43 Toast.makeText(activity, "Error: " + description, Toast.LENGTH_SHORT).show();
51 protected void onNewIntent(Intent intent) {
52 super.onNewIntent(intent);
56 private void loadUrl(Intent intent) {
57 if (intent != null && intent.getDataString() != null) {
58 mWebView.loadUrl(intent.getDataString());