import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
-import android.content.Intent;
import android.graphics.Color;
-import android.provider.Browser;
-import android.text.TextUtils;
+import android.graphics.drawable.ColorDrawable;
+import android.text.Spannable;
+import android.text.SpannableStringBuilder;
+import android.text.style.ForegroundColorSpan;
+import android.text.style.StrikethroughSpan;
+import android.text.style.StyleSpan;
+import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
+import android.view.View.MeasureSpec;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.Window;
+import android.widget.AdapterView;
+import android.widget.AdapterView.OnItemSelectedListener;
+import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ScrollView;
+import android.widget.Spinner;
import android.widget.TextView;
-import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.base.CalledByNative;
+import org.chromium.base.CommandLine;
+import org.chromium.chrome.ChromeSwitches;
import org.chromium.chrome.R;
-import org.chromium.content.browser.WebContentsObserverAndroid;
+import org.chromium.chrome.browser.toolbar.ToolbarModel;
+import org.chromium.chrome.browser.ui.toolbar.ToolbarModelSecurityLevel;
+import org.chromium.content.browser.WebContentsObserver;
import org.chromium.content_public.browser.WebContents;
+import org.chromium.ui.base.Clipboard;
+import org.chromium.ui.base.DeviceFormFactor;
+import java.net.URI;
import java.net.URISyntaxException;
+import java.util.Arrays;
+import java.util.List;
/**
* Java side of Android implementation of the website settings UI.
+ * TODO(sashab): Rename this, and all its resources, to PageInfo* and page_info_* instead of
+ * WebsiteSettings* and website_settings_*. Do this on the C++ side as well.
*/
-public class WebsiteSettingsPopup implements OnClickListener {
- private static final String HELP_URL =
- "http://www.google.com/support/chrome/bin/answer.py?answer=95617";
- private static final int DESCRIPTION_TEXT_SIZE_SP = 12;
+public class WebsiteSettingsPopup implements OnClickListener, OnItemSelectedListener {
+ /**
+ * An entry in the settings dropdown for a given permission. There are two options for each
+ * permission: Allow and Block.
+ */
+ private static final class PageInfoPermissionEntry {
+ public final String name;
+ public final int type;
+ public final int value;
+
+ PageInfoPermissionEntry(String name, int type, int value) {
+ this.name = name;
+ this.type = type;
+ this.value = value;
+ }
+
+ @Override
+ public String toString() {
+ return name;
+ }
+ }
+
+ private static final int MAX_TABLET_DIALOG_WIDTH_DP = 400;
+
private final Context mContext;
- private final Dialog mDialog;
- private final LinearLayout mContainer;
private final WebContents mWebContents;
- private final int mPaddingWide, mPaddingThin;
+
+ // A pointer to the C++ object for this UI.
private final long mNativeWebsiteSettingsPopup;
- private TextView mCertificateViewer, mMoreInfoLink;
- private ViewGroup mCertificateLayout, mDescriptionLayout;
- private Button mResetCertDecisionsButton;
- private String mLinkUrl;
+ // The outer container, filled with the layout from website_settings.xml.
+ private final LinearLayout mContainer;
+
+ // UI elements in the dialog.
+ private final TextView mUrlTitle;
+ private final TextView mUrlConnectionMessage;
+ private final LinearLayout mPermissionsList;
+ private final Button mCopyUrlButton;
+ private final Button mSiteSettingsButton;
+
+ private final View mHorizontalSeparator;
+ private final View mLowerDialogArea;
+
+ // The dialog the container is placed in.
+ private final Dialog mDialog;
+
+ // The full URL from the URL bar, which is copied to the user's clipboard when they select 'Copy
+ // URL'.
+ private String mFullUrl;
+
+ /**
+ * Creates the WebsiteSettingsPopup, but does not display it. Also initializes the corresponding
+ * C++ object and saves a pointer to it.
+ *
+ * @param context Context which is used for launching a dialog.
+ * @param webContents The WebContents for which to show Website information. This information is
+ * retrieved for the visible entry.
+ */
private WebsiteSettingsPopup(Context context, WebContents webContents) {
mContext = context;
mWebContents = webContents;
- mContainer = new LinearLayout(mContext);
- mContainer.setOrientation(LinearLayout.VERTICAL);
- mContainer.setBackgroundColor(Color.WHITE);
- mPaddingWide = (int) context.getResources().getDimension(
- R.dimen.certificate_viewer_padding_wide);
- mPaddingThin = (int) context.getResources().getDimension(
- R.dimen.certificate_viewer_padding_thin);
- mContainer.setPadding(mPaddingWide, mPaddingWide + mPaddingThin, mPaddingWide,
- mPaddingWide);
+ // Find the container and all it's important subviews.
+ mContainer = (LinearLayout) LayoutInflater.from(mContext).inflate(
+ R.layout.website_settings, null);
+
+ mUrlTitle = (TextView) mContainer
+ .findViewById(R.id.website_settings_url);
+ mUrlConnectionMessage = (TextView) mContainer
+ .findViewById(R.id.website_settings_connection_message);
+ mPermissionsList = (LinearLayout) mContainer
+ .findViewById(R.id.website_settings_permissions_list);
+ mCopyUrlButton = (Button) mContainer.findViewById(R.id.website_settings_copy_url_button);
+ mCopyUrlButton.setOnClickListener(this);
+
+ mSiteSettingsButton = (Button) mContainer
+ .findViewById(R.id.website_settings_site_settings_button);
+ mSiteSettingsButton.setOnClickListener(this);
+ // Hide the Site Settings button until there's a link to take it to.
+ // TODO(sashab,finnur): Make this button visible for well-formed, non-internal URLs.
+ mSiteSettingsButton.setVisibility(View.GONE);
+
+ mHorizontalSeparator = mContainer
+ .findViewById(R.id.website_settings_horizontal_separator);
+ mLowerDialogArea = mContainer.findViewById(R.id.website_settings_lower_dialog_area);
+
+ // Hide the horizontal separator for sites with no permissions.
+ // TODO(sashab,finnur): Show this for all sites with either the site settings button or
+ // permissions (ie when the bottom area of the dialog is not empty).
+ setVisibilityOfLowerDialogArea(false);
+
+ // Create the dialog.
mDialog = new Dialog(mContext);
mDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
mDialog.setCanceledOnTouchOutside(true);
+
+ // On smaller screens, place the dialog at the top of the screen, and remove its border.
+ if (!DeviceFormFactor.isTablet(mContext)) {
+ Window window = mDialog.getWindow();
+ window.setGravity(Gravity.TOP);
+ window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
+ }
+
// This needs to come after other member initialization.
mNativeWebsiteSettingsPopup = nativeInit(this, webContents);
- final WebContentsObserverAndroid webContentsObserver =
- new WebContentsObserverAndroid(mWebContents) {
+ final WebContentsObserver webContentsObserver = new WebContentsObserver(mWebContents) {
@Override
public void navigationEntryCommitted() {
- // If a navigation is committed (e.g. from in-page redirect), the data we're
- // showing is stale so dismiss the dialog.
+ // If a navigation is committed (e.g. from in-page redirect), the data we're showing
+ // is stale so dismiss the dialog.
mDialog.dismiss();
}
};
}
/**
- * Adds certificate section, which contains an icon, a headline, a
- * description and a label for certificate info link.
+ * Sets the visibility of the lower area of the dialog (containing the permissions and 'Site
+ * Settings' button).
+ *
+ * @param isVisible Whether to show or hide the dialog area.
*/
- @CalledByNative
- private void addCertificateSection(int enumeratedIconId, String headline, String description,
- String label) {
- View section = addSection(enumeratedIconId, headline, description);
- assert mCertificateLayout == null;
- mCertificateLayout = (ViewGroup) section.findViewById(R.id.website_settings_text_layout);
- if (label != null && !label.isEmpty()) {
- setCertificateViewer(label);
+ private void setVisibilityOfLowerDialogArea(boolean isVisible) {
+ mHorizontalSeparator.setVisibility(isVisible ? View.VISIBLE : View.GONE);
+ mLowerDialogArea.setVisibility(isVisible ? View.VISIBLE : View.GONE);
+ }
+
+ /**
+ * Finds the Image resource of the icon to use for the given permission.
+ *
+ * @param permission A valid ContentSettingsType that can be displayed in the PageInfo dialog to
+ * retrieve the image for.
+ * @return The resource ID of the icon to use for that permission.
+ */
+ private int getImageResourceForPermission(int permission) {
+ switch (permission) {
+ case ContentSettingsType.CONTENT_SETTINGS_TYPE_IMAGES:
+ return R.drawable.permission_images;
+ case ContentSettingsType.CONTENT_SETTINGS_TYPE_JAVASCRIPT:
+ return R.drawable.permission_javascript;
+ case ContentSettingsType.CONTENT_SETTINGS_TYPE_GEOLOCATION:
+ return R.drawable.permission_location;
+ case ContentSettingsType.CONTENT_SETTINGS_TYPE_MEDIASTREAM:
+ return R.drawable.permission_media;
+ case ContentSettingsType.CONTENT_SETTINGS_TYPE_PUSH_MESSAGING:
+ return R.drawable.permission_push_notification;
+ case ContentSettingsType.CONTENT_SETTINGS_TYPE_POPUPS:
+ return R.drawable.permission_popups;
+ default:
+ assert false : "Icon requested for invalid permission: " + permission;
+ return -1;
}
}
/**
- * Adds Description section, which contains an icon, a headline, and a
- * description. Most likely headline for description is empty
+ * Gets the color to use for the scheme in the URL title for the given security level. Does not
+ * apply to internal pages.
+ *
+ * @param toolbarModelSecurityLevel A valid ToolbarModelSecurityLevel, which is the security
+ * level of the page.
+ * @return The color ID to color the scheme in the URL title.
*/
- @CalledByNative
- private void addDescriptionSection(int enumeratedIconId, String headline, String description) {
- View section = addSection(enumeratedIconId, headline, description);
- assert mDescriptionLayout == null;
- mDescriptionLayout = (ViewGroup) section.findViewById(R.id.website_settings_text_layout);
+ private int getSchemeColorId(int toolbarModelSecurityLevel) {
+ switch (toolbarModelSecurityLevel) {
+ case ToolbarModelSecurityLevel.NONE:
+ return R.color.website_settings_popup_url_scheme_http;
+ case ToolbarModelSecurityLevel.SECURE:
+ case ToolbarModelSecurityLevel.EV_SECURE:
+ return R.color.website_settings_popup_url_scheme_https;
+ case ToolbarModelSecurityLevel.SECURITY_WARNING:
+ case ToolbarModelSecurityLevel.SECURITY_POLICY_WARNING:
+ return R.color.website_settings_popup_url_scheme_mixed;
+ case ToolbarModelSecurityLevel.SECURITY_ERROR:
+ return R.color.website_settings_popup_url_scheme_broken;
+ default:
+ assert false : "Invalid security level specified: " + toolbarModelSecurityLevel;
+ return R.color.website_settings_popup_url_scheme_http;
+ }
}
- private View addSection(int enumeratedIconId, 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);
- int drawableId = ResourceId.mapToDrawableId(enumeratedIconId);
- i.setImageResource(drawableId);
+ /**
+ * Gets the message to display in the connection message box for the given security level. Does
+ * not apply to SECURITY_ERROR pages, since these have their own coloured/formatted message.
+ *
+ * @param toolbarModelSecurityLevel A valid ToolbarModelSecurityLevel, which is the security
+ * level of the page.
+ * @return The ID of the message to display in the connection message box.
+ */
+ private int getConnectionMessageId(int toolbarModelSecurityLevel) {
+ switch (toolbarModelSecurityLevel) {
+ case ToolbarModelSecurityLevel.NONE:
+ return R.string.page_info_connection_http;
+ case ToolbarModelSecurityLevel.SECURE:
+ case ToolbarModelSecurityLevel.EV_SECURE:
+ return R.string.page_info_connection_https;
+ case ToolbarModelSecurityLevel.SECURITY_WARNING:
+ case ToolbarModelSecurityLevel.SECURITY_POLICY_WARNING:
+ return R.string.page_info_connection_mixed;
+ default:
+ assert false : "Invalid security level specified: " + toolbarModelSecurityLevel;
+ return R.string.page_info_connection_http;
+ }
+ }
- TextView h = (TextView) section.findViewById(R.id.website_settings_headline);
- h.setText(headline);
- if (TextUtils.isEmpty(headline)) h.setVisibility(View.GONE);
+ /**
+ * Updates the details (URL title and connection message) displayed in the popup.
+ *
+ * @param isInternalPage Whether or not this page is an internal chrome page (e.g. the
+ * chrome://settings page).
+ */
+ @CalledByNative
+ private void updatePageDetails(boolean isInternalPage) {
+ mFullUrl = mWebContents.getVisibleUrl();
+ int securityLevel = ToolbarModel.getSecurityLevelForWebContents(mWebContents);
- TextView d = (TextView) section.findViewById(R.id.website_settings_description);
- d.setText(description);
- d.setTextSize(DESCRIPTION_TEXT_SIZE_SP);
- if (TextUtils.isEmpty(description)) d.setVisibility(View.GONE);
+ URI parsedUrl;
+ try {
+ parsedUrl = new URI(mFullUrl);
+ } catch (URISyntaxException e) {
+ parsedUrl = null;
+ }
- mContainer.addView(section);
- return section;
- }
+ if (parsedUrl != null) {
+ // The URL is valid - color the scheme (and other components) for the security level.
+ SpannableStringBuilder sb = new SpannableStringBuilder();
- private void setCertificateViewer(String label) {
- assert mCertificateViewer == null;
- mCertificateViewer = new TextView(mContext);
- mCertificateViewer.setText(label);
- mCertificateViewer.setTextColor(
- mContext.getResources().getColor(R.color.website_settings_popup_text_link));
- mCertificateViewer.setTextSize(DESCRIPTION_TEXT_SIZE_SP);
- mCertificateViewer.setOnClickListener(this);
- mCertificateViewer.setPadding(0, mPaddingWide, 0, mPaddingWide);
- mCertificateLayout.addView(mCertificateViewer);
- }
+ int schemeColorId = R.color.website_settings_popup_url_scheme_http;
+ if (!isInternalPage) {
+ schemeColorId = getSchemeColorId(securityLevel);
+ }
- @CalledByNative
- private void addResetCertDecisionsButton(String label) {
- assert mNativeWebsiteSettingsPopup != 0;
- assert mResetCertDecisionsButton == null;
-
- mResetCertDecisionsButton = new Button(mContext);
- mResetCertDecisionsButton.setText(label);
- ApiCompatibilityUtils.setBackgroundForView(mResetCertDecisionsButton,
- mContext.getResources().getDrawable(
- R.drawable.website_settings_reset_cert_decisions));
- mResetCertDecisionsButton.setTextColor(
- mContext.getResources().getColor(
- R.color.website_settings_popup_reset_cert_decisions_button));
- mResetCertDecisionsButton.setTextSize(DESCRIPTION_TEXT_SIZE_SP);
- mResetCertDecisionsButton.setOnClickListener(this);
-
- LinearLayout container = new LinearLayout(mContext);
- container.setOrientation(LinearLayout.VERTICAL);
- container.addView(mResetCertDecisionsButton);
- container.setPadding(0, 0, 0, mPaddingWide);
- mContainer.addView(container);
+ String parsedUrlString = parsedUrl.toString();
+ sb.append(parsedUrlString);
+ final ForegroundColorSpan schemeColorSpan = new ForegroundColorSpan(
+ mContext.getResources().getColor(schemeColorId));
+ sb.setSpan(schemeColorSpan, 0, parsedUrl.getScheme().length(),
+ Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
+ if (securityLevel == ToolbarModelSecurityLevel.SECURITY_ERROR) {
+ sb.setSpan(new StrikethroughSpan(), 0, parsedUrl.getScheme().length(),
+ Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
+ }
+
+ // The domain does not include the '://'.
+ String originToDisplay = UrlUtilities.getOriginForDisplay(parsedUrl, false);
+ int originBegin = parsedUrlString.indexOf(originToDisplay,
+ parsedUrl.getScheme().length());
+ int originEnd = originBegin + originToDisplay.length();
+
+ // In some cases (e.g. 'about:blank') UrlUtilities.getOriginForDisplay will return the
+ // entire URL. In these cases originBegin will now be -1.
+ if (originBegin < 0) {
+ originBegin = parsedUrl.getScheme().length();
+ // Don't include the ':' in the origin for highlighting if present (it should always
+ // be there but check to be sure).
+ if (originBegin < parsedUrlString.length()) originBegin++;
+
+ originEnd = parsedUrlString.length();
+ }
+
+ final ForegroundColorSpan domainColorSpan = new ForegroundColorSpan(
+ mContext.getResources().getColor(R.color.website_settings_popup_url_domain));
+ sb.setSpan(domainColorSpan, originBegin, originEnd, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
+
+ mUrlTitle.setText(sb);
+ } else {
+ // The URL is invalid - still display it in the title, but don't apply any coloring.
+ mUrlTitle.setText(mFullUrl);
+ }
+
+ // Display the appropriate connection message.
+ SpannableStringBuilder messageBuilder = new SpannableStringBuilder();
+ if (securityLevel != ToolbarModelSecurityLevel.SECURITY_ERROR) {
+ messageBuilder.append(mContext.getResources().getString(
+ getConnectionMessageId(securityLevel)));
+ } else {
+ String originToDisplay;
+ if (parsedUrl != null) {
+ originToDisplay = UrlUtilities.getOriginForDisplay(parsedUrl, false);
+ } else {
+ // The URL is invalid - just display the full URL.
+ originToDisplay = mFullUrl;
+ }
+
+ String leadingText = mContext.getResources().getString(
+ R.string.page_info_connection_broken_leading_text);
+ String followingText = mContext.getResources().getString(
+ R.string.page_info_connection_broken_following_text, originToDisplay);
+ messageBuilder.append(leadingText + " " + followingText);
+ final ForegroundColorSpan redSpan = new ForegroundColorSpan(mContext.getResources()
+ .getColor(R.color.website_settings_popup_url_scheme_broken));
+ final StyleSpan boldSpan = new StyleSpan(android.graphics.Typeface.BOLD);
+ messageBuilder.setSpan(redSpan, 0, leadingText.length(),
+ Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
+ messageBuilder.setSpan(boldSpan, 0, leadingText.length(),
+ Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
+ }
+ mUrlConnectionMessage.setText(messageBuilder);
}
+ /**
+ * Adds a new row for the given permission.
+ *
+ * @param name The title of the permission to display to the user.
+ * @param type The ContentSettingsType of the permission.
+ * @param currentSetting The ContentSetting of the currently selected setting.
+ */
@CalledByNative
- private void addMoreInfoLink(String linkText) {
- addUrl(linkText, HELP_URL);
- }
+ private void addPermissionSection(String name, int type, int currentSetting) {
+ // We have at least one permission, so show the lower permissions area.
+ setVisibilityOfLowerDialogArea(true);
+
+ LinearLayout permissionRow = (LinearLayout) LayoutInflater.from(mContext).inflate(
+ R.layout.website_settings_permission_row, null);
- /** Adds a section containing a description and a hyperlink. */
- private void addUrl(String label, String url) {
- mMoreInfoLink = new TextView(mContext);
- mLinkUrl = url;
- mMoreInfoLink.setText(label);
- mMoreInfoLink.setTextColor(
- mContext.getResources().getColor(R.color.website_settings_popup_text_link));
- mMoreInfoLink.setTextSize(DESCRIPTION_TEXT_SIZE_SP);
- mMoreInfoLink.setPadding(0, mPaddingWide + mPaddingThin, 0, mPaddingWide);
- mMoreInfoLink.setOnClickListener(this);
- mDescriptionLayout.addView(mMoreInfoLink);
+ ImageView permission_icon = (ImageView) permissionRow.findViewById(
+ R.id.website_settings_permission_icon);
+ permission_icon.setImageResource(getImageResourceForPermission(type));
+
+ TextView permission_name = (TextView) permissionRow.findViewById(
+ R.id.website_settings_permission_name);
+ permission_name.setText(name);
+
+ Spinner permission_spinner = (Spinner) permissionRow.findViewById(
+ R.id.website_settings_permission_spinner);
+
+ // Work out the index of the currently selected setting.
+ int selectedSettingIndex = -1;
+ switch (currentSetting) {
+ case ContentSetting.ALLOW:
+ selectedSettingIndex = 0;
+ break;
+ case ContentSetting.BLOCK:
+ selectedSettingIndex = 1;
+ break;
+ default:
+ assert false : "Invalid setting " + currentSetting + " for permission " + type;
+ }
+
+ List<PageInfoPermissionEntry> settingsChoices = Arrays.asList(
+ new PageInfoPermissionEntry(mContext.getResources().getString(
+ R.string.page_info_permission_allow), type, ContentSetting.ALLOW),
+ new PageInfoPermissionEntry(mContext.getResources().getString(
+ R.string.page_info_permission_block), type, ContentSetting.BLOCK));
+ ArrayAdapter<PageInfoPermissionEntry> adapter = new ArrayAdapter<PageInfoPermissionEntry>(
+ mContext, R.drawable.website_settings_permission_spinner_item, settingsChoices);
+ adapter.setDropDownViewResource(
+ R.drawable.website_settings_permission_spinner_dropdown_item);
+ permission_spinner.setAdapter(adapter);
+ permission_spinner.setSelection(selectedSettingIndex, false);
+ permission_spinner.setOnItemSelectedListener(this);
+ mPermissionsList.addView(permissionRow);
}
- /** Displays the WebsiteSettingsPopup. */
+ /**
+ * Displays the WebsiteSettingsPopup.
+ */
@CalledByNative
private void showDialog() {
- ScrollView scrollView = new ScrollView(mContext);
- scrollView.addView(mContainer);
- mDialog.addContentView(scrollView,
- new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
- LinearLayout.LayoutParams.MATCH_PARENT));
+ if (!DeviceFormFactor.isTablet(mContext)) {
+ // On smaller screens, make the dialog fill the width of the screen.
+ ScrollView scrollView = new ScrollView(mContext);
+ scrollView.addView(mContainer);
+ mDialog.addContentView(scrollView, new LinearLayout.LayoutParams(
+ LinearLayout.LayoutParams.MATCH_PARENT,
+ LinearLayout.LayoutParams.MATCH_PARENT));
+
+ // This must be called after addContentView, or it won't fully fill to the edge.
+ Window window = mDialog.getWindow();
+ window.setLayout(ViewGroup.LayoutParams.MATCH_PARENT,
+ ViewGroup.LayoutParams.WRAP_CONTENT);
+ } else {
+ // On larger screens, make the dialog centered in the screen and have a maximum width.
+ ScrollView scrollView = new ScrollView(mContext) {
+ @Override
+ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
+ final int maxDialogWidthInPx = (int) (MAX_TABLET_DIALOG_WIDTH_DP
+ * mContext.getResources().getDisplayMetrics().density);
+ if (MeasureSpec.getSize(widthMeasureSpec) > maxDialogWidthInPx) {
+ widthMeasureSpec = MeasureSpec.makeMeasureSpec(maxDialogWidthInPx,
+ MeasureSpec.EXACTLY);
+ }
+ super.onMeasure(widthMeasureSpec, heightMeasureSpec);
+ }
+ };
+
+ scrollView.addView(mContainer);
+ mDialog.addContentView(scrollView, new LinearLayout.LayoutParams(
+ LinearLayout.LayoutParams.WRAP_CONTENT,
+ LinearLayout.LayoutParams.MATCH_PARENT));
+ }
+
mDialog.show();
}
@Override
- public void onClick(View v) {
- mDialog.dismiss();
- if (mResetCertDecisionsButton == v) {
- nativeResetCertDecisions(mNativeWebsiteSettingsPopup, mWebContents);
- } else if (mCertificateViewer == v) {
- byte[][] certChain = nativeGetCertificateChain(mWebContents);
- if (certChain == null) {
- // The WebContents may have been destroyed/invalidated. If so,
- // ignore this request.
- return;
- }
- CertificateViewer.showCertificateChain(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) {
- // Do nothing intentionally.
- }
+ public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
+ PageInfoPermissionEntry entry = (PageInfoPermissionEntry) parent.getItemAtPosition(pos);
+ nativeOnPermissionSettingChanged(mNativeWebsiteSettingsPopup, entry.type, entry.value);
+ }
+
+ @Override
+ public void onNothingSelected(AdapterView<?> parent) {
+ // Do nothing intentionally.
+ }
+
+ @Override
+ public void onClick(View view) {
+ if (view == mCopyUrlButton) {
+ new Clipboard(mContext).setText(mFullUrl, mFullUrl);
+ mDialog.dismiss();
+ } else if (view == mSiteSettingsButton) {
+ // TODO(sashab,finnur): Make this open the Website Settings dialog.
+ assert false : "No Website Settings here!";
+ mDialog.dismiss();
}
}
/**
- * Shows a WebsiteSettings dialog for the provided WebContents.
- *
- * The popup adds itself to the view hierarchy which owns the reference while it's
- * visible.
+ * Shows a WebsiteSettings dialog for the provided WebContents. The popup adds itself to the
+ * view hierarchy which owns the reference while it's visible.
*
* @param context Context which is used for launching a dialog.
- * @param webContents The WebContents for which to show Website information. This
- * information is retrieved for the visible entry.
+ * @param webContents The WebContents for which to show Website information. This information is
+ * retrieved for the visible entry.
*/
@SuppressWarnings("unused")
public static void show(Context context, WebContents webContents) {
- new WebsiteSettingsPopup(context, webContents);
+ if (!CommandLine.getInstance().hasSwitch(ChromeSwitches.DISABLE_NEW_WEBSITE_SETTINGS)) {
+ new WebsiteSettingsPopup(context, webContents);
+ } else {
+ WebsiteSettingsPopupLegacy.show(context, webContents);
+ }
}
private static native long nativeInit(WebsiteSettingsPopup popup, WebContents webContents);
+
private native void nativeDestroy(long nativeWebsiteSettingsPopupAndroid);
- private native void nativeResetCertDecisions(
- long nativeWebsiteSettingsPopupAndroid, WebContents webContents);
- private native byte[][] nativeGetCertificateChain(WebContents webContents);
+
+ private native void nativeOnPermissionSettingChanged(long nativeWebsiteSettingsPopupAndroid,
+ int type, int setting);
}