blob: 21dafa9d45dfcc1a52b92146e6c2d3980ebc110e [file] [log] [blame]
Mathew Inwood29721c22011-06-29 17:55:24 +01001/*
2 * Copyright (C) 2011 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 */
Bijan Amirzada41242f22014-03-21 12:12:18 -070016package com.android.browser;
Mathew Inwood29721c22011-06-29 17:55:24 +010017
Mathew Inwoode1dbb952011-07-08 17:27:38 +010018import android.net.Uri;
Mathew Inwood29721c22011-06-29 17:55:24 +010019import android.text.TextUtils;
20import android.util.Log;
Mathew Inwood29721c22011-06-29 17:55:24 +010021
22import java.util.Map;
Mathew Inwooda829d552011-09-02 14:16:25 +010023import java.util.regex.Pattern;
Mathew Inwood29721c22011-06-29 17:55:24 +010024
25/**
26 * Class to manage the controlling of preloaded tab.
27 */
28public class PreloadedTabControl {
Bijan Amirzada41242f22014-03-21 12:12:18 -070029 private static final boolean LOGD_ENABLED = com.android.browser.Browser.LOGD_ENABLED;
Mathew Inwood29721c22011-06-29 17:55:24 +010030 private static final String LOGTAG = "PreloadedTabControl";
31
32 final Tab mTab;
33 private String mLastQuery;
34 private boolean mDestroyed;
35
36 public PreloadedTabControl(Tab t) {
Mathew Inwoode1dbb952011-07-08 17:27:38 +010037 if (LOGD_ENABLED) Log.d(LOGTAG, "PreloadedTabControl.<init>");
Mathew Inwood29721c22011-06-29 17:55:24 +010038 mTab = t;
39 }
40
Mathew Inwood29721c22011-06-29 17:55:24 +010041 public void setQuery(String query) {
Selim Gurun70c78442012-09-11 12:01:50 -070042 if (LOGD_ENABLED) Log.d(LOGTAG, "Cannot set query: no searchbox interface");
Mathew Inwood29721c22011-06-29 17:55:24 +010043 }
44
Mathew Inwood9ad1eac2011-09-15 11:29:50 +010045 public boolean searchBoxSubmit(final String query,
46 final String fallbackUrl, final Map<String, String> fallbackHeaders) {
Selim Gurun70c78442012-09-11 12:01:50 -070047 return false;
Mathew Inwood29721c22011-06-29 17:55:24 +010048 }
49
Mathew Inwooddffa72f2011-08-10 12:37:43 +010050 public void searchBoxCancel() {
Mathew Inwooddffa72f2011-08-10 12:37:43 +010051 }
52
Mathew Inwood29721c22011-06-29 17:55:24 +010053 public void loadUrlIfChanged(String url, Map<String, String> headers) {
Mathew Inwoode1dbb952011-07-08 17:27:38 +010054 String currentUrl = mTab.getUrl();
55 if (!TextUtils.isEmpty(currentUrl)) {
56 try {
57 // remove fragment:
58 currentUrl = Uri.parse(currentUrl).buildUpon().fragment(null).build().toString();
59 } catch (UnsupportedOperationException e) {
60 // carry on
61 }
62 }
63 if (LOGD_ENABLED) Log.d(LOGTAG, "loadUrlIfChanged\nnew: " + url + "\nold: " +currentUrl);
64 if (!TextUtils.equals(url, currentUrl)) {
Mathew Inwood29721c22011-06-29 17:55:24 +010065 loadUrl(url, headers);
66 }
67 }
68
69 public void loadUrl(String url, Map<String, String> headers) {
70 if (LOGD_ENABLED) Log.d(LOGTAG, "Preloading " + url);
71 mTab.loadUrl(url, headers);
72 }
73
74 public void destroy() {
Mathew Inwoode1dbb952011-07-08 17:27:38 +010075 if (LOGD_ENABLED) Log.d(LOGTAG, "PreloadedTabControl.destroy");
Mathew Inwood29721c22011-06-29 17:55:24 +010076 mDestroyed = true;
77 mTab.destroy();
78 }
79
80 public Tab getTab() {
81 return mTab;
82 }
83
84}