summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteve Block <steveblock@google.com>2009-07-30 14:45:13 +0100
committerSteve Block <steveblock@google.com>2009-08-06 13:07:43 +0100
commit2bc69918d97a767a02132090e58718077381ba1a (patch)
treebf05f606399a558713c009e8e20abf7ad84d2b20
parent3918d4443ff38ef1870e02aa51a8b29f8352bb1a (diff)
downloadandroid_packages_apps_Gello-2bc69918d97a767a02132090e58718077381ba1a.tar.gz
android_packages_apps_Gello-2bc69918d97a767a02132090e58718077381ba1a.tar.bz2
android_packages_apps_Gello-2bc69918d97a767a02132090e58718077381ba1a.zip
Adds the browser Geolocation permissions prompt.
Note that the appearance of the prompt has not yet been finalized. Also the interaction of the prompt with the animation used to move to and from the tab picker is not fixed. This may become unecessary if the tab selection UI is redisgned.
-rwxr-xr-xres/layout/geolocation_permissions_prompt.xml63
-rwxr-xr-xres/layout/tab.xml38
-rw-r--r--res/values/colors.xml2
-rw-r--r--res/values/strings.xml5
-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
7 files changed, 318 insertions, 14 deletions
diff --git a/res/layout/geolocation_permissions_prompt.xml b/res/layout/geolocation_permissions_prompt.xml
new file mode 100755
index 00000000..404637ba
--- /dev/null
+++ b/res/layout/geolocation_permissions_prompt.xml
@@ -0,0 +1,63 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+
+ This is the layout for the Geolocation permissions prompt.
+ FIXME: Make this looks pretty.
+-->
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:fitsSystemWindows="true"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content">
+
+ <!-- Use an inner element as we can't show a hidden outermost element -->
+ <LinearLayout android:id="@+id/inner"
+ android:orientation="vertical"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:background="@color/geolocation_permissions_prompt_background"
+ android:visibility="gone">
+
+ <!-- 'google.com wants to know your location' -->
+ <TextView android:id="@+id/message"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:textSize="14dip"
+ android:textColor="@color/white" />
+
+ <!-- Buttons -->
+ <LinearLayout
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content">
+ <Button android:id="@+id/share_button"
+ android:text="@string/geolocation_permissions_prompt_share"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content" />
+ <Button android:id="@+id/dont_share_button"
+ android:text="@string/geolocation_permissions_prompt_dont_share"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content" />
+ </LinearLayout>
+
+ <CheckBox android:id="@+id/remember"
+ android:text="@string/geolocation_permissions_prompt_remember"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:drawablePadding="10dip"
+ android:textSize="16dip"
+ android:textColor="@color/white" />
+
+ </LinearLayout>
+</LinearLayout>
diff --git a/res/layout/tab.xml b/res/layout/tab.xml
new file mode 100755
index 00000000..ea9cd1a1
--- /dev/null
+++ b/res/layout/tab.xml
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+
+
+ This layout provides the structure for a browser tab. A tab contains the
+ WebView and any number of other UI elements specific to that tab.
+ Currently, the only such element is the Geolocation permissions prompt.
+-->
+
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:fitsSystemWindows="true"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent">
+
+ <!-- Wrapper layout for the WebView, which must be in a FrameLayout. -->
+ <FrameLayout android:id="@+id/webview_wrapper"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent" />
+
+ <!-- Geolocation permissions prompt -->
+ <com.android.browser.GeolocationPermissionsPrompt
+ android:id="@+id/geolocation_permissions_prompt"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content" />
+
+</FrameLayout>
diff --git a/res/values/colors.xml b/res/values/colors.xml
index f34b6404..def8ac8f 100644
--- a/res/values/colors.xml
+++ b/res/values/colors.xml
@@ -38,5 +38,7 @@
<color name="permission_border">#f1cc1d</color>
<color name="permission_background">#faefb8</color>
<color name="dialog_link">#ff0000ff</color>
+
+ <color name="geolocation_permissions_prompt_background">#CC888888</color>
</resources>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 47f1a60b..3f4c7861 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -785,6 +785,11 @@
<string name="webstorage_origin_summary_mb_stored">MB stored on your phone</string>
<!-- Geolocation -->
+ <!-- Permissions prompt -->
+ <string name="geolocation_permissions_prompt_message">%s wants to know your location</string>
+ <string name="geolocation_permissions_prompt_share">Share</string>
+ <string name="geolocation_permissions_prompt_dont_share">Don\'t share</string>
+ <string name="geolocation_permissions_prompt_remember">Remember</string>
<!-- Settings page, Advanced Settings -> Website settings -> <origin> -->
<string name="geolocation_settings_page_title">Clear location access</string>
<string name="geolocation_settings_page_summary_allowed">This site can currently access your location</string>
diff --git a/src/com/android/browser/BrowserActivity.java b/src/com/android/browser/BrowserActivity.java
index 8117961f..3c46fc9d 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 00000000..16737fe7
--- /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 c5085b3b..e6cacb88 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());