• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
18 import android.net.Uri;
19 import android.text.TextUtils;
20 import android.util.Log;
21 
22 import java.util.Map;
23 import java.util.regex.Pattern;
24 
25 /**
26  * Class to manage the controlling of preloaded tab.
27  */
28 public class PreloadedTabControl {
29     private static final boolean LOGD_ENABLED = com.android.browser.Browser.LOGD_ENABLED;
30     private static final String LOGTAG = "PreloadedTabControl";
31 
32     final Tab mTab;
33     private String mLastQuery;
34     private boolean mDestroyed;
35 
PreloadedTabControl(Tab t)36     public PreloadedTabControl(Tab t) {
37         if (LOGD_ENABLED) Log.d(LOGTAG, "PreloadedTabControl.<init>");
38         mTab = t;
39     }
40 
setQuery(String query)41     public void setQuery(String query) {
42         if (LOGD_ENABLED) Log.d(LOGTAG, "Cannot set query: no searchbox interface");
43     }
44 
searchBoxSubmit(final String query, final String fallbackUrl, final Map<String, String> fallbackHeaders)45     public boolean searchBoxSubmit(final String query,
46             final String fallbackUrl, final Map<String, String> fallbackHeaders) {
47         return false;
48     }
49 
searchBoxCancel()50     public void searchBoxCancel() {
51     }
52 
loadUrlIfChanged(String url, Map<String, String> headers)53     public void loadUrlIfChanged(String url, Map<String, String> headers) {
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)) {
65             loadUrl(url, headers);
66         }
67     }
68 
loadUrl(String url, Map<String, String> headers)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 
destroy()74     public void destroy() {
75         if (LOGD_ENABLED) Log.d(LOGTAG, "PreloadedTabControl.destroy");
76         mDestroyed = true;
77         mTab.destroy();
78     }
79 
getTab()80     public Tab getTab() {
81         return mTab;
82     }
83 
84 }
85