Index: chrome/android/java/src/org/chromium/chrome/browser/WebsiteSettingsPopup.java |
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/WebsiteSettingsPopup.java b/chrome/android/java/src/org/chromium/chrome/browser/WebsiteSettingsPopup.java |
new file mode 100644 |
index 0000000000000000000000000000000000000000..ec37166e7c7221e2009ba582a3545ee9aa0725fa |
--- /dev/null |
+++ b/chrome/android/java/src/org/chromium/chrome/browser/WebsiteSettingsPopup.java |
@@ -0,0 +1,154 @@ |
+// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+package org.chromium.chrome.browser; |
+ |
+import android.app.Dialog; |
+import android.content.Context; |
+import android.content.DialogInterface; |
+import android.content.Intent; |
+import android.graphics.Bitmap; |
+import android.graphics.Color; |
+import android.graphics.Typeface; |
+import android.provider.Browser; |
+import android.text.Html; |
+import android.view.LayoutInflater; |
+import android.view.View; |
+import android.view.View.OnClickListener; |
+import android.view.ViewGroup.LayoutParams; |
+import android.view.Window; |
+import android.widget.ImageView; |
+import android.widget.LinearLayout; |
+import android.widget.ScrollView; |
+import android.widget.TextView; |
+ |
+import org.chromium.base.CalledByNative; |
+import org.chromium.chrome.R; |
+import org.chromium.content.browser.ContentViewCore; |
+ |
+import java.net.URISyntaxException; |
+ |
+/** |
+ * Java side of Android implementation of the website settings UI. |
+ */ |
+public class WebsiteSettingsPopup implements OnClickListener { |
+ private static final String HELP_URL = |
+ "http://www.google.com/support/chrome/bin/answer.py?answer=95617"; |
+ private final Context mContext; |
+ private final Dialog mDialog; |
+ private final LinearLayout mContainer; |
+ private TextView mCertificateViewer, mMoreInfoLink; |
+ private String mLinkUrl; |
+ ContentViewCore mContentViewCore; |
Ted C
2013/01/25 02:04:05
private?
Yaron
2013/01/25 19:25:17
Done.
|
+ private final int mPadding; |
+ |
+ WebsiteSettingsPopup(Context context, ContentViewCore contentViewCore, |
+ final int nativeWebsiteSettingsPopup) { |
+ mContext = context; |
+ mDialog = new Dialog(mContext); |
+ mDialog.requestWindowFeature(Window.FEATURE_NO_TITLE); |
+ mDialog.setCanceledOnTouchOutside(true); |
+ mDialog.setOnCancelListener(new DialogInterface.OnCancelListener() { |
+ @Override |
+ public void onCancel(DialogInterface dialogInterface) { |
+ assert nativeWebsiteSettingsPopup != 0; |
+ nativeDestroy(nativeWebsiteSettingsPopup); |
+ } |
+ }); |
+ mContainer = new LinearLayout(mContext); |
+ mContainer.setOrientation(LinearLayout.VERTICAL); |
+ mContentViewCore = contentViewCore; |
+ mPadding = (int) context.getResources().getDimension(R.dimen.certificate_viewer_padding); |
+ mContainer.setPadding(mPadding, 0, mPadding, 0); |
+ } |
+ |
+ /** Adds a section, which contains an icon, a headline, and a description. */ |
+ @CalledByNative |
+ void addSection(Bitmap icon, String headline, String description) { |
+ View section = LayoutInflater.from(mContext).inflate(R.layout.website_settings, null); |
+ ImageView i = (ImageView) section.findViewById(R.id.website_settings_icon); |
+ i.setImageBitmap(icon); |
+ TextView h = (TextView) section.findViewById(R.id.website_settings_headline); |
+ h.setText(headline); |
+ h.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD)); |
Ted C
2013/01/25 02:04:05
any reason it's not configured to be bold in the x
Yaron
2013/01/25 19:25:17
Done.
|
+ if (headline == null || headline.length() == 0) h.setVisibility(View.GONE); |
Ted C
2013/01/25 02:04:05
TextUtils.isEmpty(headline)
Yaron
2013/01/25 19:25:17
Done.
|
+ |
+ TextView d = (TextView) section.findViewById(R.id.website_settings_description); |
+ d.setText(description); |
+ if (description == null || description.length() == 0) d.setVisibility(View.GONE); |
Ted C
2013/01/25 02:04:05
same thing here about TextUtils.
Yaron
2013/01/25 19:25:17
Done.
|
+ |
+ mContainer.addView(section); |
+ } |
+ |
+ /** Adds a horizontal dividing line to separate sections. */ |
+ @CalledByNative |
+ void addDivider() { |
Ted C
2013/01/25 02:04:05
private?
Yaron
2013/01/25 19:25:17
Done.
|
+ View divider = new View(mContext); |
+ divider.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, 2)); |
Ted C
2013/01/25 02:04:05
should the 2 be in DP or pixels?
Yaron
2013/01/25 19:25:17
I guess dp?
|
+ divider.setBackgroundColor(Color.GRAY); |
+ mContainer.addView(divider); |
+ } |
+ |
+ @CalledByNative |
+ private void setCertificateViewer(String label) { |
+ assert mCertificateViewer == null; |
+ mCertificateViewer = new TextView(mContext); |
+ mCertificateViewer.setText(Html.fromHtml("<a href='#'>" + label + "</a>")); |
+ mCertificateViewer.setOnClickListener(this); |
+ mCertificateViewer.setPadding(0, 0, 0, mPadding); |
+ mContainer.addView(mCertificateViewer); |
+ } |
+ |
+ @CalledByNative |
+ private void addMoreInfoLink() { |
+ addUrl(mContext.getResources().getString(R.string.website_settings_more_info), |
+ HELP_URL); |
Ted C
2013/01/25 02:04:05
I think this is only indented 7 instead of 8.
Yaron
2013/01/25 19:25:17
Done.
|
+ } |
+ |
+ /** Adds a section containing a description and a hyperlink. */ |
+ void addUrl(String label, String url) { |
Ted C
2013/01/25 02:04:05
private?
Yaron
2013/01/25 19:25:17
Done.
|
+ mMoreInfoLink = new TextView(mContext); |
+ mLinkUrl = url; |
+ mMoreInfoLink.setText(Html.fromHtml("<a href='#'>" + label + "</a>")); |
+ mMoreInfoLink.setPadding(0, mPadding, 0, mPadding); |
+ mMoreInfoLink.setOnClickListener(this); |
+ mContainer.addView(mMoreInfoLink); |
+ } |
+ |
+ /** Displays the WebsiteSettingsPopup. */ |
+ @CalledByNative |
+ void show() { |
Ted C
2013/01/25 02:04:05
private
Yaron
2013/01/25 19:25:17
Done.
|
+ ScrollView scrollView = new ScrollView(mContext); |
+ scrollView.addView(mContainer); |
+ mDialog.addContentView(scrollView, |
+ new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, |
+ LinearLayout.LayoutParams.MATCH_PARENT)); |
Ted C
2013/01/25 02:04:05
same thing here too..should be indented 8 from pre
Yaron
2013/01/25 19:25:17
Done.
|
+ mDialog.show(); |
+ } |
+ |
+ @Override |
+ public void onClick(View v) { |
+ mDialog.dismiss(); |
+ if (mCertificateViewer == v) { |
+ byte[][] certChain = nativeGetCertChain(mContentViewCore); |
+ CertificateViewer.showCertChain(mContext, certChain); |
+ } else if (mMoreInfoLink == v) { |
+ try { |
+ Intent i = Intent.parseUri(mLinkUrl, Intent.URI_INTENT_SCHEME); |
+ i.putExtra(Browser.EXTRA_CREATE_NEW_TAB, true); |
+ i.putExtra(Browser.EXTRA_APPLICATION_ID, mContext.getPackageName()); |
+ mContext.startActivity(i); |
+ } catch (URISyntaxException ex) {} |
+ } |
+ } |
+ |
+ @CalledByNative |
+ private static WebsiteSettingsPopup create(Context context, ContentViewCore contentViewCore, |
+ int nativeWebsiteSettingsPopup) { |
+ return new WebsiteSettingsPopup(context, contentViewCore, nativeWebsiteSettingsPopup); |
+ } |
+ |
+ private native void nativeDestroy(int nativeWebsiteSettingsPopupAndroid); |
+ private native byte[][] nativeGetCertChain(ContentViewCore contentViewCore); |
+} |