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; | |
14 import android.text.TextUtils; | 13 import android.text.TextUtils; |
15 import android.view.LayoutInflater; | 14 import android.view.LayoutInflater; |
16 import android.view.View; | 15 import android.view.View; |
17 import android.view.View.OnClickListener; | 16 import android.view.View.OnClickListener; |
18 import android.view.ViewGroup.LayoutParams; | 17 import android.view.ViewGroup; |
19 import android.view.Window; | 18 import android.view.Window; |
20 import android.widget.ImageView; | 19 import android.widget.ImageView; |
21 import android.widget.LinearLayout; | 20 import android.widget.LinearLayout; |
22 import android.widget.ScrollView; | 21 import android.widget.ScrollView; |
23 import android.widget.TextView; | 22 import android.widget.TextView; |
24 | 23 |
25 import org.chromium.base.CalledByNative; | 24 import org.chromium.base.CalledByNative; |
26 import org.chromium.chrome.R; | 25 import org.chromium.chrome.R; |
27 import org.chromium.content.browser.WebContentsObserverAndroid; | 26 import org.chromium.content.browser.WebContentsObserverAndroid; |
28 import org.chromium.content_public.browser.WebContents; | 27 import org.chromium.content_public.browser.WebContents; |
29 | 28 |
30 import java.net.URISyntaxException; | 29 import java.net.URISyntaxException; |
31 | 30 |
32 /** | 31 /** |
33 * Java side of Android implementation of the website settings UI. | 32 * Java side of Android implementation of the website settings UI. |
34 */ | 33 */ |
35 public class WebsiteSettingsPopup implements OnClickListener { | 34 public class WebsiteSettingsPopup implements OnClickListener { |
36 private static final String HELP_URL = | 35 private static final String HELP_URL = |
37 "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 static final int DESCRIPTION_TEXT_SIZE = 12; | |
David Trainor- moved to gerrit
2014/07/23 17:23:54
can you add a unit? DESCRIPTION_TEXT_SIZE_SP?
Ian Wen
2014/07/23 18:28:25
Done.
| |
38 private final Context mContext; | 38 private final Context mContext; |
39 private final Dialog mDialog; | 39 private final Dialog mDialog; |
40 private final LinearLayout mContainer; | 40 private final LinearLayout mContainer; |
41 private final WebContents mWebContents; | 41 private final WebContents mWebContents; |
42 private final int mPadding; | 42 private final int mPaddingWide, mPaddingThin; |
43 private TextView mCertificateViewer, mMoreInfoLink; | 43 private TextView mCertificateViewer, mMoreInfoLink; |
44 private ViewGroup mCertificateLayout, mDescriptionLayout; | |
44 private String mLinkUrl; | 45 private String mLinkUrl; |
45 | 46 |
46 private WebsiteSettingsPopup(Context context, WebContents webContents) { | 47 private WebsiteSettingsPopup(Context context, WebContents webContents) { |
47 mContext = context; | 48 mContext = context; |
48 mWebContents = webContents; | 49 mWebContents = webContents; |
49 | 50 |
50 mContainer = new LinearLayout(mContext); | 51 mContainer = new LinearLayout(mContext); |
51 mContainer.setOrientation(LinearLayout.VERTICAL); | 52 mContainer.setOrientation(LinearLayout.VERTICAL); |
52 mPadding = (int) context.getResources().getDimension(R.dimen.certificate _viewer_padding); | 53 mContainer.setBackgroundColor(Color.WHITE); |
53 mContainer.setPadding(mPadding, 0, mPadding, 0); | 54 mPaddingWide = (int) context.getResources().getDimension( |
55 R.dimen.certificate_viewer_padding_wide); | |
56 mPaddingThin = (int) context.getResources().getDimension( | |
57 R.dimen.certificate_viewer_padding_thin); | |
58 mContainer.setPadding(mPaddingWide, mPaddingWide + mPaddingThin, mPaddin gWide, | |
59 mPaddingWide); | |
54 | 60 |
55 mDialog = new Dialog(mContext); | 61 mDialog = new Dialog(mContext); |
56 mDialog.requestWindowFeature(Window.FEATURE_NO_TITLE); | 62 mDialog.requestWindowFeature(Window.FEATURE_NO_TITLE); |
57 mDialog.setCanceledOnTouchOutside(true); | 63 mDialog.setCanceledOnTouchOutside(true); |
58 // This needs to come after other member initialization. | 64 // This needs to come after other member initialization. |
59 final long nativeWebsiteSettingsPopup = nativeInit(this, webContents); | 65 final long nativeWebsiteSettingsPopup = nativeInit(this, webContents); |
60 final WebContentsObserverAndroid webContentsObserver = | 66 final WebContentsObserverAndroid webContentsObserver = |
61 new WebContentsObserverAndroid(mWebContents) { | 67 new WebContentsObserverAndroid(mWebContents) { |
62 @Override | 68 @Override |
63 public void navigationEntryCommitted() { | 69 public void navigationEntryCommitted() { |
64 // If a navigation is committed (e.g. from in-page redirect), th e data we're | 70 // If a navigation is committed (e.g. from in-page redirect), th e data we're |
65 // showing is stale so dismiss the dialog. | 71 // showing is stale so dismiss the dialog. |
66 mDialog.dismiss(); | 72 mDialog.dismiss(); |
67 } | 73 } |
68 }; | 74 }; |
69 mDialog.setOnDismissListener(new DialogInterface.OnDismissListener() { | 75 mDialog.setOnDismissListener(new DialogInterface.OnDismissListener() { |
70 @Override | 76 @Override |
71 public void onDismiss(DialogInterface dialog) { | 77 public void onDismiss(DialogInterface dialog) { |
72 assert nativeWebsiteSettingsPopup != 0; | 78 assert nativeWebsiteSettingsPopup != 0; |
73 webContentsObserver.detachFromWebContents(); | 79 webContentsObserver.detachFromWebContents(); |
74 nativeDestroy(nativeWebsiteSettingsPopup); | 80 nativeDestroy(nativeWebsiteSettingsPopup); |
75 } | 81 } |
76 }); | 82 }); |
77 } | 83 } |
78 | 84 |
79 /** Adds a section, which contains an icon, a headline, and a description. * / | 85 /** |
86 * Adds certificate section, which contains an icon, a headline, and a | |
87 * description. | |
88 */ | |
80 @CalledByNative | 89 @CalledByNative |
81 private void addSection(int enumeratedIconId, String headline, String descri ption) { | 90 private void addCertificateSection(int enumeratedIconId, String headline, St ring description) { |
91 View section = addSection(enumeratedIconId, headline, description); | |
92 mCertificateLayout = (ViewGroup) section.findViewById(R.id.website_setti ngs_text_layout); | |
David Trainor- moved to gerrit
2014/07/23 17:23:54
should we assert that this is not already set? Sa
Ian Wen
2014/07/23 18:28:26
Done.
| |
93 } | |
94 | |
95 /** | |
96 * Adds Description section, which contains an icon, a headline, and a | |
97 * description. Most likely headline for description is empty | |
98 */ | |
99 @CalledByNative | |
100 private void addDescriptionSection(int enumeratedIconId, String headline, St ring description) { | |
101 View section = addSection(enumeratedIconId, headline, description); | |
102 mDescriptionLayout = (ViewGroup) section.findViewById(R.id.website_setti ngs_text_layout); | |
103 } | |
104 | |
105 private View addSection(int enumeratedIconId, String headline, String descri ption) { | |
82 View section = LayoutInflater.from(mContext).inflate(R.layout.website_se ttings, null); | 106 View section = LayoutInflater.from(mContext).inflate(R.layout.website_se ttings, null); |
83 ImageView i = (ImageView) section.findViewById(R.id.website_settings_ico n); | 107 ImageView i = (ImageView) section.findViewById(R.id.website_settings_ico n); |
84 int drawableId = ResourceId.mapToDrawableId(enumeratedIconId); | 108 int drawableId = ResourceId.mapToDrawableId(enumeratedIconId); |
85 i.setImageResource(drawableId); | 109 i.setImageResource(drawableId); |
86 | 110 |
87 TextView h = (TextView) section.findViewById(R.id.website_settings_headl ine); | 111 TextView h = (TextView) section.findViewById(R.id.website_settings_headl ine); |
88 h.setText(headline); | 112 h.setText(headline); |
89 if (TextUtils.isEmpty(headline)) h.setVisibility(View.GONE); | 113 if (TextUtils.isEmpty(headline)) h.setVisibility(View.GONE); |
90 | 114 |
91 TextView d = (TextView) section.findViewById(R.id.website_settings_descr iption); | 115 TextView d = (TextView) section.findViewById(R.id.website_settings_descr iption); |
92 d.setText(description); | 116 d.setText(description); |
117 d.setTextSize(DESCRIPTION_TEXT_SIZE); | |
93 if (TextUtils.isEmpty(description)) d.setVisibility(View.GONE); | 118 if (TextUtils.isEmpty(description)) d.setVisibility(View.GONE); |
94 | 119 |
95 mContainer.addView(section); | 120 mContainer.addView(section); |
96 } | 121 return section; |
97 | |
98 /** Adds a horizontal dividing line to separate sections. */ | |
99 @CalledByNative | |
100 private void addDivider() { | |
101 View divider = new View(mContext); | |
102 final int dividerHeight = (int) (2 * mContext.getResources().getDisplayM etrics().density); | |
103 divider.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, divi derHeight)); | |
104 divider.setBackgroundColor(Color.GRAY); | |
105 mContainer.addView(divider); | |
106 } | 122 } |
107 | 123 |
108 @CalledByNative | 124 @CalledByNative |
109 private void setCertificateViewer(String label) { | 125 private void setCertificateViewer(String label) { |
110 assert mCertificateViewer == null; | 126 assert mCertificateViewer == null; |
111 mCertificateViewer = new TextView(mContext); | 127 mCertificateViewer = new TextView(mContext); |
David Trainor- moved to gerrit
2014/07/23 17:23:54
remove extra space?
Ian Wen
2014/07/23 18:28:25
Done.
| |
112 mCertificateViewer.setText(Html.fromHtml("<a href='#'>" + label + "</a>" )); | 128 mCertificateViewer.setText(label); |
129 mCertificateViewer.setTextColor( | |
130 mContext.getResources().getColor(R.color.website_settings_popup_ text_link)); | |
131 mCertificateViewer.setTextSize(DESCRIPTION_TEXT_SIZE); | |
113 mCertificateViewer.setOnClickListener(this); | 132 mCertificateViewer.setOnClickListener(this); |
114 mCertificateViewer.setPadding(0, 0, 0, mPadding); | 133 mCertificateViewer.setPadding(0, mPaddingWide, 0, mPaddingWide); |
115 mContainer.addView(mCertificateViewer); | 134 assert mCertificateLayout != null; |
135 mCertificateLayout.addView(mCertificateViewer); | |
116 } | 136 } |
117 | 137 |
118 @CalledByNative | 138 @CalledByNative |
119 private void addMoreInfoLink(String linkText) { | 139 private void addMoreInfoLink(String linkText) { |
120 addUrl(linkText, HELP_URL); | 140 addUrl(linkText, HELP_URL); |
121 } | 141 } |
122 | 142 |
123 /** Adds a section containing a description and a hyperlink. */ | 143 /** Adds a section containing a description and a hyperlink. */ |
124 private void addUrl(String label, String url) { | 144 private void addUrl(String label, String url) { |
125 mMoreInfoLink = new TextView(mContext); | 145 mMoreInfoLink = new TextView(mContext); |
126 mLinkUrl = url; | 146 mLinkUrl = url; |
127 mMoreInfoLink.setText(Html.fromHtml("<a href='#'>" + label + "</a>")); | 147 mMoreInfoLink.setText(label); |
128 mMoreInfoLink.setPadding(0, mPadding, 0, mPadding); | 148 mMoreInfoLink.setTextColor( |
149 mContext.getResources().getColor(R.color.website_settings_popup_ text_link)); | |
150 mMoreInfoLink.setTextSize(DESCRIPTION_TEXT_SIZE); | |
151 mMoreInfoLink.setPadding(0, mPaddingWide + mPaddingThin, 0, mPaddingWide ); | |
129 mMoreInfoLink.setOnClickListener(this); | 152 mMoreInfoLink.setOnClickListener(this); |
130 mContainer.addView(mMoreInfoLink); | 153 assert mDescriptionLayout != null; |
154 mDescriptionLayout.addView(mMoreInfoLink); | |
131 } | 155 } |
132 | 156 |
133 /** Displays the WebsiteSettingsPopup. */ | 157 /** Displays the WebsiteSettingsPopup. */ |
134 @CalledByNative | 158 @CalledByNative |
135 private void showDialog() { | 159 private void showDialog() { |
136 ScrollView scrollView = new ScrollView(mContext); | 160 ScrollView scrollView = new ScrollView(mContext); |
137 scrollView.addView(mContainer); | 161 scrollView.addView(mContainer); |
138 mDialog.addContentView(scrollView, | 162 mDialog.addContentView(scrollView, |
139 new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PA RENT, | 163 new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PA RENT, |
140 LinearLayout.LayoutParams.MATCH_PARENT)); | 164 LinearLayout.LayoutParams.MATCH_PARENT)); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
174 */ | 198 */ |
175 @SuppressWarnings("unused") | 199 @SuppressWarnings("unused") |
176 public static void show(Context context, WebContents webContents) { | 200 public static void show(Context context, WebContents webContents) { |
177 new WebsiteSettingsPopup(context, webContents); | 201 new WebsiteSettingsPopup(context, webContents); |
178 } | 202 } |
179 | 203 |
180 private static native long nativeInit(WebsiteSettingsPopup popup, WebContent s webContents); | 204 private static native long nativeInit(WebsiteSettingsPopup popup, WebContent s webContents); |
181 private native void nativeDestroy(long nativeWebsiteSettingsPopupAndroid); | 205 private native void nativeDestroy(long nativeWebsiteSettingsPopupAndroid); |
182 private native byte[][] nativeGetCertificateChain(WebContents webContents); | 206 private native byte[][] nativeGetCertificateChain(WebContents webContents); |
183 } | 207 } |
OLD | NEW |