Mathew Inwood | 29721c2 | 2011-06-29 17:55:24 +0100 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | package com.android.browser; |
| 17 | |
Mathew Inwood | e1dbb95 | 2011-07-08 17:27:38 +0100 | [diff] [blame] | 18 | import android.net.Uri; |
Mathew Inwood | 29721c2 | 2011-06-29 17:55:24 +0100 | [diff] [blame] | 19 | import android.text.TextUtils; |
| 20 | import android.util.Log; |
Mathew Inwood | 29721c2 | 2011-06-29 17:55:24 +0100 | [diff] [blame] | 21 | |
| 22 | import java.util.Map; |
Mathew Inwood | a829d55 | 2011-09-02 14:16:25 +0100 | [diff] [blame] | 23 | import java.util.regex.Pattern; |
Mathew Inwood | 29721c2 | 2011-06-29 17:55:24 +0100 | [diff] [blame] | 24 | |
| 25 | /** |
| 26 | * Class to manage the controlling of preloaded tab. |
| 27 | */ |
| 28 | public class PreloadedTabControl { |
Mathew Inwood | e1dbb95 | 2011-07-08 17:27:38 +0100 | [diff] [blame] | 29 | private static final boolean LOGD_ENABLED = com.android.browser.Browser.LOGD_ENABLED; |
Mathew Inwood | 29721c2 | 2011-06-29 17:55:24 +0100 | [diff] [blame] | 30 | 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 Inwood | e1dbb95 | 2011-07-08 17:27:38 +0100 | [diff] [blame] | 37 | if (LOGD_ENABLED) Log.d(LOGTAG, "PreloadedTabControl.<init>"); |
Mathew Inwood | 29721c2 | 2011-06-29 17:55:24 +0100 | [diff] [blame] | 38 | mTab = t; |
| 39 | } |
| 40 | |
Mathew Inwood | 29721c2 | 2011-06-29 17:55:24 +0100 | [diff] [blame] | 41 | public void setQuery(String query) { |
Selim Gurun | 70c7844 | 2012-09-11 12:01:50 -0700 | [diff] [blame^] | 42 | if (LOGD_ENABLED) Log.d(LOGTAG, "Cannot set query: no searchbox interface"); |
Mathew Inwood | 29721c2 | 2011-06-29 17:55:24 +0100 | [diff] [blame] | 43 | } |
| 44 | |
Mathew Inwood | 9ad1eac | 2011-09-15 11:29:50 +0100 | [diff] [blame] | 45 | public boolean searchBoxSubmit(final String query, |
| 46 | final String fallbackUrl, final Map<String, String> fallbackHeaders) { |
Selim Gurun | 70c7844 | 2012-09-11 12:01:50 -0700 | [diff] [blame^] | 47 | return false; |
Mathew Inwood | 29721c2 | 2011-06-29 17:55:24 +0100 | [diff] [blame] | 48 | } |
| 49 | |
Mathew Inwood | dffa72f | 2011-08-10 12:37:43 +0100 | [diff] [blame] | 50 | public void searchBoxCancel() { |
Mathew Inwood | dffa72f | 2011-08-10 12:37:43 +0100 | [diff] [blame] | 51 | } |
| 52 | |
Mathew Inwood | 29721c2 | 2011-06-29 17:55:24 +0100 | [diff] [blame] | 53 | public void loadUrlIfChanged(String url, Map<String, String> headers) { |
Mathew Inwood | e1dbb95 | 2011-07-08 17:27:38 +0100 | [diff] [blame] | 54 | 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 Inwood | 29721c2 | 2011-06-29 17:55:24 +0100 | [diff] [blame] | 65 | 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 Inwood | e1dbb95 | 2011-07-08 17:27:38 +0100 | [diff] [blame] | 75 | if (LOGD_ENABLED) Log.d(LOGTAG, "PreloadedTabControl.destroy"); |
Mathew Inwood | 29721c2 | 2011-06-29 17:55:24 +0100 | [diff] [blame] | 76 | mDestroyed = true; |
| 77 | mTab.destroy(); |
| 78 | } |
| 79 | |
| 80 | public Tab getTab() { |
| 81 | return mTab; |
| 82 | } |
| 83 | |
| 84 | } |