• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2015 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.
4 package org.chromium.webview_shell;
5 
6 import android.app.Activity;
7 import android.content.Intent;
8 import android.os.Bundle;
9 import android.os.Trace;
10 import android.webkit.CookieManager;
11 import android.webkit.WebSettings;
12 import android.webkit.WebView;
13 import android.webkit.WebViewClient;
14 
15 /**
16  * This activity is designed for Telemetry testing of WebView.
17  */
18 public class TelemetryActivity extends Activity {
19     static final String DEFAULT_START_UP_TRACE_TAG = "WebViewStartupInterval";
20     static final String DEFAULT_LOAD_URL_TRACE_TAG = "WebViewBlankUrlLoadInterval";
21     static final String DEFAULT_START_UP_AND_LOAD_URL_TRACE_TAG =
22             "WebViewStartupAndLoadBlankUrlInterval";
23 
24     @Override
onCreate(Bundle savedInstanceState)25     public void onCreate(Bundle savedInstanceState) {
26         super.onCreate(savedInstanceState);
27         getWindow().setTitle(
28                 getResources().getString(R.string.title_activity_telemetry));
29 
30         Intent intent = getIntent();
31         final String startUpTraceTag = intent.getStringExtra("WebViewStartUpTraceTag");
32         final String loadUrlTraceTag = intent.getStringExtra("WebViewLoadUrlTraceTag");
33         final String startUpAndLoadUrlTraceTag =
34                 intent.getStringExtra("WebViewStartUpAndLoadUrlTraceTag");
35 
36         Trace.beginSection(startUpTraceTag == null ? DEFAULT_START_UP_AND_LOAD_URL_TRACE_TAG
37                                                    : startUpAndLoadUrlTraceTag);
38         Trace.beginSection(startUpTraceTag == null ? DEFAULT_START_UP_TRACE_TAG : startUpTraceTag);
39         WebView webView = new WebView(this);
40         setContentView(webView);
41         Trace.endSection();
42 
43         CookieManager.setAcceptFileSchemeCookies(true);
44         WebSettings settings = webView.getSettings();
45         settings.setJavaScriptEnabled(true);
46         settings.setUseWideViewPort(true);
47         settings.setLoadWithOverviewMode(true);
48         settings.setDomStorageEnabled(true);
49         settings.setMediaPlaybackRequiresUserGesture(false);
50         String userAgentString = intent.getStringExtra("userAgent");
51         if (userAgentString != null) {
52             settings.setUserAgentString(userAgentString);
53         }
54 
55         webView.setWebViewClient(new WebViewClient() {
56             @SuppressWarnings("deprecation") // because we support api level 19 and up.
57             @Override
58             public boolean shouldOverrideUrlLoading(WebView view, String url) {
59                 return false;
60             }
61 
62             @Override
63             public void onPageFinished(WebView view, String url) {
64                 super.onPageFinished(view, url);
65                 Trace.endSection();
66                 Trace.endSection();
67             }
68         });
69 
70         Trace.beginSection(loadUrlTraceTag == null ? DEFAULT_LOAD_URL_TRACE_TAG : loadUrlTraceTag);
71         webView.loadUrl("about:blank");
72     }
73 }
74