OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.chrome.browser; | 5 package org.chromium.chrome.browser; |
6 | 6 |
7 import android.app.Dialog; | 7 import android.app.Dialog; |
8 import android.content.Context; | 8 import android.content.Context; |
9 import android.content.DialogInterface; | 9 import android.content.DialogInterface; |
10 import android.content.Intent; | 10 import android.content.Intent; |
11 import android.graphics.Color; | 11 import android.graphics.Color; |
12 import android.provider.Browser; | 12 import android.provider.Browser; |
13 import android.text.Html; | 13 import android.text.Html; |
14 import android.text.TextUtils; | 14 import android.text.TextUtils; |
15 import android.view.LayoutInflater; | 15 import android.view.LayoutInflater; |
16 import android.view.View; | 16 import android.view.View; |
17 import android.view.View.OnClickListener; | 17 import android.view.View.OnClickListener; |
18 import android.view.ViewGroup.LayoutParams; | 18 import android.view.ViewGroup.LayoutParams; |
19 import android.view.Window; | 19 import android.view.Window; |
20 import android.widget.ImageView; | 20 import android.widget.ImageView; |
21 import android.widget.LinearLayout; | 21 import android.widget.LinearLayout; |
22 import android.widget.ScrollView; | 22 import android.widget.ScrollView; |
23 import android.widget.TextView; | 23 import android.widget.TextView; |
24 | 24 |
25 import org.chromium.base.CalledByNative; | 25 import org.chromium.base.CalledByNative; |
26 import org.chromium.chrome.R; | 26 import org.chromium.chrome.R; |
27 import org.chromium.content.browser.ContentViewCore; | 27 import org.chromium.content_public.browser.WebContents; |
28 | 28 |
29 import java.net.URISyntaxException; | 29 import java.net.URISyntaxException; |
30 | 30 |
31 /** | 31 /** |
32 * Java side of Android implementation of the website settings UI. | 32 * Java side of Android implementation of the website settings UI. |
33 */ | 33 */ |
34 class WebsiteSettingsPopup implements OnClickListener { | 34 public class WebsiteSettingsPopup implements OnClickListener { |
35 private static final String HELP_URL = | 35 private static final String HELP_URL = |
36 "http://www.google.com/support/chrome/bin/answer.py?answer=95617"; | 36 "http://www.google.com/support/chrome/bin/answer.py?answer=95617"; |
37 private final Context mContext; | 37 private final Context mContext; |
38 private final Dialog mDialog; | 38 private final Dialog mDialog; |
39 private final LinearLayout mContainer; | 39 private final LinearLayout mContainer; |
40 private final ContentViewCore mContentViewCore; | 40 private final WebContents mWebContents; |
41 private final int mPadding; | 41 private final int mPadding; |
42 private TextView mCertificateViewer, mMoreInfoLink; | 42 private TextView mCertificateViewer, mMoreInfoLink; |
43 private String mLinkUrl; | 43 private String mLinkUrl; |
44 | 44 |
45 private WebsiteSettingsPopup(Context context, ContentViewCore contentViewCor
e, | 45 private WebsiteSettingsPopup(Context context, WebContents webContents) { |
46 final long nativeWebsiteSettingsPopup) { | |
47 mContext = context; | 46 mContext = context; |
| 47 mWebContents = webContents; |
| 48 |
| 49 mContainer = new LinearLayout(mContext); |
| 50 mContainer.setOrientation(LinearLayout.VERTICAL); |
| 51 mPadding = (int) context.getResources().getDimension(R.dimen.certificate
_viewer_padding); |
| 52 mContainer.setPadding(mPadding, 0, mPadding, 0); |
| 53 |
48 mDialog = new Dialog(mContext); | 54 mDialog = new Dialog(mContext); |
49 mDialog.requestWindowFeature(Window.FEATURE_NO_TITLE); | 55 mDialog.requestWindowFeature(Window.FEATURE_NO_TITLE); |
50 mDialog.setCanceledOnTouchOutside(true); | 56 mDialog.setCanceledOnTouchOutside(true); |
51 mDialog.setOnCancelListener(new DialogInterface.OnCancelListener() { | 57 // This needs to come after other member initialization. |
| 58 final long nativeWebsiteSettingsPopup = nativeInit(this, webContents); |
| 59 mDialog.setOnDismissListener(new DialogInterface.OnDismissListener() { |
52 @Override | 60 @Override |
53 public void onCancel(DialogInterface dialogInterface) { | 61 public void onDismiss(DialogInterface dialog) { |
54 assert nativeWebsiteSettingsPopup != 0; | 62 assert nativeWebsiteSettingsPopup != 0; |
55 nativeDestroy(nativeWebsiteSettingsPopup); | 63 nativeDestroy(nativeWebsiteSettingsPopup); |
56 } | 64 } |
57 }); | 65 }); |
58 mContainer = new LinearLayout(mContext); | |
59 mContainer.setOrientation(LinearLayout.VERTICAL); | |
60 mContentViewCore = contentViewCore; | |
61 mPadding = (int) context.getResources().getDimension(R.dimen.certificate
_viewer_padding); | |
62 mContainer.setPadding(mPadding, 0, mPadding, 0); | |
63 } | 66 } |
64 | 67 |
65 /** Adds a section, which contains an icon, a headline, and a description. *
/ | 68 /** Adds a section, which contains an icon, a headline, and a description. *
/ |
66 @CalledByNative | 69 @CalledByNative |
67 private void addSection(int enumeratedIconId, String headline, String descri
ption) { | 70 private void addSection(int enumeratedIconId, String headline, String descri
ption) { |
68 View section = LayoutInflater.from(mContext).inflate(R.layout.website_se
ttings, null); | 71 View section = LayoutInflater.from(mContext).inflate(R.layout.website_se
ttings, null); |
69 ImageView i = (ImageView) section.findViewById(R.id.website_settings_ico
n); | 72 ImageView i = (ImageView) section.findViewById(R.id.website_settings_ico
n); |
70 int drawableId = ResourceId.mapToDrawableId(enumeratedIconId); | 73 int drawableId = ResourceId.mapToDrawableId(enumeratedIconId); |
71 i.setImageResource(drawableId); | 74 i.setImageResource(drawableId); |
72 | 75 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 mMoreInfoLink = new TextView(mContext); | 114 mMoreInfoLink = new TextView(mContext); |
112 mLinkUrl = url; | 115 mLinkUrl = url; |
113 mMoreInfoLink.setText(Html.fromHtml("<a href='#'>" + label + "</a>")); | 116 mMoreInfoLink.setText(Html.fromHtml("<a href='#'>" + label + "</a>")); |
114 mMoreInfoLink.setPadding(0, mPadding, 0, mPadding); | 117 mMoreInfoLink.setPadding(0, mPadding, 0, mPadding); |
115 mMoreInfoLink.setOnClickListener(this); | 118 mMoreInfoLink.setOnClickListener(this); |
116 mContainer.addView(mMoreInfoLink); | 119 mContainer.addView(mMoreInfoLink); |
117 } | 120 } |
118 | 121 |
119 /** Displays the WebsiteSettingsPopup. */ | 122 /** Displays the WebsiteSettingsPopup. */ |
120 @CalledByNative | 123 @CalledByNative |
121 private void show() { | 124 private void showDialog() { |
122 ScrollView scrollView = new ScrollView(mContext); | 125 ScrollView scrollView = new ScrollView(mContext); |
123 scrollView.addView(mContainer); | 126 scrollView.addView(mContainer); |
124 mDialog.addContentView(scrollView, | 127 mDialog.addContentView(scrollView, |
125 new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PA
RENT, | 128 new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PA
RENT, |
126 LinearLayout.LayoutParams.MATCH_PARENT)); | 129 LinearLayout.LayoutParams.MATCH_PARENT)); |
127 mDialog.show(); | 130 mDialog.show(); |
128 } | 131 } |
129 | 132 |
130 @Override | 133 @Override |
131 public void onClick(View v) { | 134 public void onClick(View v) { |
132 mDialog.dismiss(); | 135 mDialog.dismiss(); |
133 if (mCertificateViewer == v) { | 136 if (mCertificateViewer == v) { |
134 byte[][] certChain = nativeGetCertificateChain(mContentViewCore); | 137 byte[][] certChain = nativeGetCertificateChain(mWebContents); |
| 138 if (certChain == null) { |
| 139 // The WebContents may have been destroyed/invalidated. If so, |
| 140 // ignore this request. |
| 141 return; |
| 142 } |
135 CertificateViewer.showCertificateChain(mContext, certChain); | 143 CertificateViewer.showCertificateChain(mContext, certChain); |
136 } else if (mMoreInfoLink == v) { | 144 } else if (mMoreInfoLink == v) { |
137 try { | 145 try { |
138 Intent i = Intent.parseUri(mLinkUrl, Intent.URI_INTENT_SCHEME); | 146 Intent i = Intent.parseUri(mLinkUrl, Intent.URI_INTENT_SCHEME); |
139 i.putExtra(Browser.EXTRA_CREATE_NEW_TAB, true); | 147 i.putExtra(Browser.EXTRA_CREATE_NEW_TAB, true); |
140 i.putExtra(Browser.EXTRA_APPLICATION_ID, mContext.getPackageName
()); | 148 i.putExtra(Browser.EXTRA_APPLICATION_ID, mContext.getPackageName
()); |
141 mContext.startActivity(i); | 149 mContext.startActivity(i); |
142 } catch (URISyntaxException ex) {} | 150 } catch (URISyntaxException ex) {} |
143 } | 151 } |
144 } | 152 } |
145 | 153 |
146 @CalledByNative | 154 /** |
147 private static WebsiteSettingsPopup create(Context context, ContentViewCore
contentViewCore, | 155 * Shows a WebsiteSettings dialog for the provided WebContents. |
148 long nativeWebsiteSettingsPopup) { | 156 * |
149 return new WebsiteSettingsPopup(context, contentViewCore, nativeWebsiteS
ettingsPopup); | 157 * The popup adds itself to the view hierarchy which owns the reference whil
e it's |
| 158 * visible. |
| 159 * |
| 160 * @param context Context which is used for launching a dialog. |
| 161 * @param webContents The WebContents for which to show Website information.
This |
| 162 * information is retrieved for the visible entry. |
| 163 */ |
| 164 @SuppressWarnings("unused") |
| 165 public static void show(Context context, WebContents webContents) { |
| 166 new WebsiteSettingsPopup(context, webContents); |
150 } | 167 } |
151 | 168 |
| 169 private static native long nativeInit(WebsiteSettingsPopup popup, WebContent
s webContents); |
152 private native void nativeDestroy(long nativeWebsiteSettingsPopupAndroid); | 170 private native void nativeDestroy(long nativeWebsiteSettingsPopupAndroid); |
153 private native byte[][] nativeGetCertificateChain(ContentViewCore contentVie
wCore); | 171 private native byte[][] nativeGetCertificateChain(WebContents webContents); |
154 } | 172 } |
OLD | NEW |