summaryrefslogtreecommitdiffstats
path: root/src/com/android
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android')
-rw-r--r--src/com/android/browser/BrowserActivity.java34
-rwxr-xr-xsrc/com/android/browser/GeolocationPermissionsPrompt.java116
-rw-r--r--src/com/android/browser/TabControl.java74
3 files changed, 210 insertions, 14 deletions
diff --git a/src/com/android/browser/BrowserActivity.java b/src/com/android/browser/BrowserActivity.java
index 8117961..3c46fc9 100644
--- a/src/com/android/browser/BrowserActivity.java
+++ b/src/com/android/browser/BrowserActivity.java
@@ -107,6 +107,7 @@ import android.view.animation.TranslateAnimation;
import android.webkit.CookieManager;
import android.webkit.CookieSyncManager;
import android.webkit.DownloadListener;
+import android.webkit.GeolocationPermissions;
import android.webkit.HttpAuthHandler;
import android.webkit.PluginManager;
import android.webkit.SslErrorHandler;
@@ -1988,9 +1989,9 @@ public class BrowserActivity extends Activity
// Attach the given tab to the content view.
private void attachTabToContentView(TabControl.Tab t) {
- final WebView main = t.getWebView();
- // Attach the main WebView.
- mContentView.addView(main, COVER_SCREEN_PARAMS);
+ // Attach the container that contains the main WebView and any other UI
+ // associated with the tab.
+ mContentView.addView(t.getContainer(), COVER_SCREEN_PARAMS);
if (mShouldShowErrorConsole) {
ErrorConsoleView errorConsole = mTabControl.getCurrentErrorConsole(true);
@@ -2024,8 +2025,8 @@ public class BrowserActivity extends Activity
// Remove the given tab from the content view.
private void removeTabFromContentView(TabControl.Tab t) {
- // Remove the main WebView.
- mContentView.removeView(t.getWebView());
+ // Remove the container that contains the main WebView.
+ mContentView.removeView(t.getContainer());
if (mTabControl.getCurrentErrorConsole(false) != null) {
mErrorConsoleContainer.removeView(mTabControl.getCurrentErrorConsole(false));
@@ -3873,6 +3874,29 @@ public class BrowserActivity extends Activity
spaceNeeded, totalUsedQuota, quotaUpdater);
}
+ /**
+ * Instructs the browser to show a prompt to ask the user to set the
+ * Geolocation permission state for the specified origin.
+ * @param origin The origin for which Geolocation permissions are
+ * requested.
+ * @param callback The callback to call once the user has set the
+ * Geolocation permission state.
+ */
+ @Override
+ public void onGeolocationPermissionsShowPrompt(String origin,
+ GeolocationPermissions.Callback callback) {
+ mTabControl.getCurrentTab().getGeolocationPermissionsPrompt().show(
+ origin, callback);
+ }
+
+ /**
+ * Instructs the browser to hide the Geolocation permissions prompt.
+ */
+ @Override
+ public void onGeolocationPermissionsHidePrompt() {
+ mTabControl.getCurrentTab().getGeolocationPermissionsPrompt().hide();
+ }
+
/* Adds a JavaScript error message to the system log.
* @param message The error message to report.
* @param lineNumber The line number of the error.
diff --git a/src/com/android/browser/GeolocationPermissionsPrompt.java b/src/com/android/browser/GeolocationPermissionsPrompt.java
new file mode 100755
index 0000000..16737fe
--- /dev/null
+++ b/src/com/android/browser/GeolocationPermissionsPrompt.java
@@ -0,0 +1,116 @@
+/*
+ * Copyright (C) 2009 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.browser;
+
+import android.content.Context;
+import android.graphics.drawable.Drawable;
+import android.util.AttributeSet;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.webkit.WebView;
+import android.webkit.GeolocationPermissions;
+import android.widget.Button;
+import android.widget.CheckBox;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+
+public class GeolocationPermissionsPrompt extends LinearLayout {
+ private LinearLayout mInner;
+ private TextView mMessage;
+ private Button mShareButton;
+ private Button mDontShareButton;
+ private CheckBox mRemember;
+ private GeolocationPermissions.Callback mCallback;
+ private String mOrigin;
+
+ public GeolocationPermissionsPrompt(Context context) {
+ this(context, null);
+ }
+
+ public GeolocationPermissionsPrompt(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ LayoutInflater factory = LayoutInflater.from(context);
+ factory.inflate(R.layout.geolocation_permissions_prompt, this);
+
+ mInner = (LinearLayout) findViewById(R.id.inner);
+ mMessage = (TextView) findViewById(R.id.message);
+ mShareButton = (Button) findViewById(R.id.share_button);
+ mDontShareButton = (Button) findViewById(R.id.dont_share_button);
+ mRemember = (CheckBox) findViewById(R.id.remember);
+ setButtonClickListeners();
+ }
+
+ /**
+ * Shows the prompt for the given origin. When the user clicks on one of
+ * the buttons, the supplied callback is be called.
+ */
+ public void show(String origin, GeolocationPermissions.Callback callback) {
+ mOrigin = origin;
+ mCallback = callback;
+ setMessage(mOrigin);
+ showDialog(true);
+ }
+
+ /**
+ * Hides the prompt.
+ */
+ public void hide() {
+ showDialog(false);
+ }
+
+ /**
+ * Sets the on click listeners for the buttons.
+ */
+ private void setButtonClickListeners() {
+ final GeolocationPermissionsPrompt me = this;
+ mShareButton.setOnClickListener(new View.OnClickListener() {
+ public void onClick(View v) {
+ me.handleButtonClick(true);
+ }
+ });
+ mDontShareButton.setOnClickListener(new View.OnClickListener() {
+ public void onClick(View v) {
+ me.handleButtonClick(false);
+ }
+ });
+ }
+
+ /**
+ * Handles a click on one the buttons by invoking the callback.
+ */
+ private void handleButtonClick(boolean allow) {
+ boolean remember = mRemember.isChecked();
+ showDialog(false);
+ mCallback.invoke(mOrigin, allow, remember);
+ }
+
+ /**
+ * Sets the prompt's message.
+ */
+ private void setMessage(CharSequence origin) {
+ mMessage.setText(String.format(
+ getResources().getString(R.string.geolocation_permissions_prompt_message),
+ origin));
+ }
+
+ /**
+ * Shows or hides the prompt.
+ */
+ private void showDialog(boolean shown) {
+ mInner.setVisibility(shown ? View.VISIBLE : View.GONE);
+ }
+}
diff --git a/src/com/android/browser/TabControl.java b/src/com/android/browser/TabControl.java
index c5085b3..e6cacb8 100644
--- a/src/com/android/browser/TabControl.java
+++ b/src/com/android/browser/TabControl.java
@@ -38,6 +38,7 @@ import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.FrameLayout;
import android.widget.ImageButton;
+import android.widget.LinearLayout;
import java.io.File;
import java.io.FileInputStream;
@@ -162,6 +163,9 @@ class TabControl {
* Private class for maintaining Tabs with a main WebView and a subwindow.
*/
public class Tab implements WebView.PictureListener {
+ // The Geolocation permissions prompt
+ private GeolocationPermissionsPrompt mGeolocationPermissionsPrompt;
+ private View mContainer;
// Main WebView
private WebView mMainView;
// Subwindow WebView
@@ -198,11 +202,47 @@ class TabControl {
private ErrorConsoleView mErrorConsole;
// Construct a new tab
- private Tab(WebView w, boolean closeOnExit, String appId, String url) {
- mMainView = w;
+ private Tab(WebView w, boolean closeOnExit, String appId, String url, Context context) {
mCloseOnExit = closeOnExit;
mAppId = appId;
mOriginalUrl = url;
+
+ // The tab consists of a container view, which contains the main
+ // WebView, as well as any other UI elements associated with the tab.
+ //
+ // FIXME: Fix the interaction between this layout and the animation
+ // used when switching to and from the tab picker. This may not be
+ // required if the tab selection UI is redesigned.
+ LayoutInflater factory = LayoutInflater.from(context);
+ mContainer = factory.inflate(R.layout.tab, null);
+
+ mGeolocationPermissionsPrompt =
+ (GeolocationPermissionsPrompt) mContainer.findViewById(
+ R.id.geolocation_permissions_prompt);
+
+ setWebView(w);
+ }
+
+ /**
+ * Sets the WebView for this tab, correctly removing the old WebView
+ * from, and inserting the new WebView into, the container view.
+ */
+ public void setWebView(WebView w) {
+ if (mMainView == w) {
+ return;
+ }
+ // If the WebView is changing, the page will be reloaded, so any ongoing Geolocation
+ // permission requests are void.
+ mGeolocationPermissionsPrompt.hide();
+
+ FrameLayout wrapper = (FrameLayout) mContainer.findViewById(R.id.webview_wrapper);
+ if (mMainView != null) {
+ wrapper.removeView(mMainView);
+ }
+ mMainView = w;
+ if (mMainView != null) {
+ wrapper.addView(mMainView);
+ }
}
/**
@@ -228,6 +268,20 @@ class TabControl {
}
/**
+ * @return The container for this tab.
+ */
+ public View getContainer() {
+ return mContainer;
+ }
+
+ /**
+ * @return The geolocation permissions prompt for this tab.
+ */
+ public GeolocationPermissionsPrompt getGeolocationPermissionsPrompt() {
+ return mGeolocationPermissionsPrompt;
+ }
+
+ /**
* Return the subwindow of this tab or null if there is no subwindow.
* @return The subwindow of this tab or null.
*/
@@ -488,8 +542,9 @@ class TabControl {
return null;
}
final WebView w = createNewWebView();
+
// Create a new tab and add it to the tab list
- Tab t = new Tab(w, closeOnExit, appId, url);
+ Tab t = new Tab(w, closeOnExit, appId, url, mActivity);
mTabs.add(t);
// Initially put the tab in the background.
putTabInBackground(t);
@@ -528,7 +583,7 @@ class TabControl {
t.mMainView.getSettings());
// Destroy the main view and subview
t.mMainView.destroy();
- t.mMainView = null;
+ t.setWebView(null);
}
// clear it's references to parent and children
t.removeFromTree();
@@ -589,7 +644,7 @@ class TabControl {
dismissSubWindow(t);
s.deleteObserver(t.mMainView.getSettings());
t.mMainView.destroy();
- t.mMainView = null;
+ t.setWebView(null);
}
}
mTabs.clear();
@@ -661,7 +716,7 @@ class TabControl {
} else {
// Create a new tab and don't restore the state yet, add it
// to the tab list
- Tab t = new Tab(null, false, null, null);
+ Tab t = new Tab(null, false, null, null, mActivity);
t.mSavedState = inState.getBundle(WEBVIEW + i);
if (t.mSavedState != null) {
populatePickerDataFromSavedState(t);
@@ -758,7 +813,7 @@ class TabControl {
// observers.
BrowserSettings.getInstance().deleteObserver(t.mMainView.getSettings());
t.mMainView.destroy();
- t.mMainView = null;
+ t.setWebView(null);
}
/**
@@ -896,7 +951,7 @@ class TabControl {
}
// Create a new WebView. If this tab is the current tab, we need to put
// back all the clients so force it to be the current tab.
- t.mMainView = createNewWebView();
+ t.setWebView(createNewWebView());
if (getCurrentTab() == t) {
setCurrentTab(t, true);
}
@@ -1008,7 +1063,8 @@ class TabControl {
boolean needRestore = (mainView == null);
if (needRestore) {
// Same work as in createNewTab() except don't do new Tab()
- newTab.mMainView = mainView = createNewWebView();
+ mainView = createNewWebView();
+ newTab.setWebView(mainView);
}
putViewInForeground(mainView, mActivity.getWebViewClient(),
mActivity.getWebChromeClient());