1 /* 2 * Copyright 2014, The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.managedprovisioning; 18 19 import android.app.Activity; 20 import android.os.Bundle; 21 import android.webkit.WebView; 22 import android.webkit.WebViewClient; 23 24 /** 25 * This activity shows a web view, which loads the {@link #EXTRA_URL} indicated in the starting 26 * intent. By default the user can click on links and load other urls. However, if the 27 * {@link EXTRA_ALLOWED_URL_BASE} is set in the starting intent, then only url starting with the 28 * allowed url base will be loaded. 29 * 30 * <p> 31 * This activity is currently used by the {@link UserConsentDialog} to display the google support 32 * web page about the Device Owner concept. 33 * </p> 34 */ 35 public class WebActivity extends Activity { 36 public static final String EXTRA_URL = "extra_url"; 37 38 // Users can only browse urls starting with the base specified by the following extra. 39 // If this extra is not used, there are no restrictions on browsable urls. 40 public static final String EXTRA_ALLOWED_URL_BASE = "extra_allowed_url_base"; 41 42 private WebView mWebView; 43 44 @Override onCreate(Bundle savedInstanceState)45 public void onCreate(Bundle savedInstanceState) { 46 super.onCreate(savedInstanceState); 47 48 mWebView = new WebView(this); 49 final String extraUrl = getIntent().getStringExtra(EXTRA_URL); 50 final String extraAllowedUrlBase = getIntent().getStringExtra(EXTRA_ALLOWED_URL_BASE); 51 if (extraUrl == null) { 52 ProvisionLogger.loge("No url provided to WebActivity."); 53 finish(); 54 return; 55 } 56 mWebView.loadUrl(extraUrl); 57 mWebView.setWebViewClient(new WebViewClient() { 58 @Override 59 public boolean shouldOverrideUrlLoading(WebView view, String url) { 60 if (extraAllowedUrlBase != null && url.startsWith(extraAllowedUrlBase)) { 61 view.loadUrl(url); 62 } 63 return true; 64 } 65 }); 66 67 this.setContentView(mWebView); 68 } 69 }