blob: 81779dd333ecad64fa37e80a48541dbd52426975 [file] [log] [blame]
Sander Alewijnse93476d62014-10-01 12:23:06 +01001/*
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
17package com.android.managedprovisioning;
18
19import android.app.Activity;
20import android.os.Bundle;
21import android.webkit.WebView;
22import 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 */
35public 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
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}