Commit c8157459 authored by xingliu's avatar xingliu Committed by Commit bot

Converts usage of EmbeddedContentViewActivity to CustomTabActivity.

This CL changes all call sites of EmbedContentViewActivity to use
CustomTabActivity.

Didn't delete the EmbedContentViewActivity code yet, also not sure if
we should clean the chrome strings for the titles if we don't need them.

There are a couple of details in the UI:

1. Title is now using html document title instead of chrome strings.
Not sure which one should we use here.

2. The color of the toolbar is same as EmbeddedContentViewActivity. But
the color of icons or other components depends on their own logic and
theme color of the activity, etc.

3. The url bar is not hidden for now, since the security icon color on
tablet is not correct.(Black icon on a dark background). Don't have
a spec so not sure if we would hide the url bar here and fix the icon
color logic.

Screen shots are attached in crbug.
BUG=673522

Review-Url: https://codereview.chromium.org/2571553003
Cr-Commit-Position: refs/heads/master@{#439168}
parent 8b9fa295
......@@ -5,6 +5,7 @@
package org.chromium.chrome.browser.customtabs;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
......@@ -16,6 +17,7 @@ import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.StrictMode;
import android.provider.Browser;
import android.support.customtabs.CustomTabsCallback;
import android.support.customtabs.CustomTabsIntent;
import android.support.customtabs.CustomTabsSessionToken;
......@@ -369,7 +371,7 @@ public class CustomTabActivity extends ChromeActivity {
@Override
public void finishNativeInitialization() {
FirstRunSignInProcessor.start(this);
if (!mIntentDataProvider.isInfoPage()) FirstRunSignInProcessor.start(this);
final CustomTabsConnection connection = CustomTabsConnection.getInstance(getApplication());
// If extra headers have been passed, cancel any current prerender, as
......@@ -932,7 +934,11 @@ public class CustomTabActivity extends ChromeActivity {
StrictMode.allowThreadDiskReads();
StrictMode.allowThreadDiskWrites();
try {
startActivity(intent, startActivityOptions);
if (mIntentDataProvider.isInfoPage()) {
IntentHandler.startChromeLauncherActivityForTrustedIntent(intent, this);
} else {
startActivity(intent, startActivityOptions);
}
} finally {
StrictMode.setThreadPolicy(oldPolicy);
}
......@@ -988,4 +994,29 @@ public class CustomTabActivity extends ChromeActivity {
super.initializeToolbar();
if (mIntentDataProvider.isMediaViewer()) getToolbarManager().disableShadow();
}
/**
* Show the web page with CustomTabActivity, without any navigation control.
* Used in showing the terms of services page or help pages for Chrome.
* @param context The current activity context.
* @param url The url of the web page.
*/
public static void showInfoPage(Context context, String url) {
// TODO(xingliu): The title text will be the html document title, figure out if we want to
// use Chrome strings here as EmbedContentViewActivity does.
CustomTabsIntent customTabIntent = new CustomTabsIntent.Builder()
.setShowTitle(true)
.setToolbarColor(context.getResources().getColor(R.color.dark_action_bar_color))
.build();
customTabIntent.intent.setData(Uri.parse(url));
Intent intent = ChromeLauncherActivity.createCustomTabActivityIntent(
context, customTabIntent.intent, false);
intent.setPackage(context.getPackageName());
intent.putExtra(CustomTabIntentDataProvider.EXTRA_IS_INFO_PAGE, true);
intent.putExtra(Browser.EXTRA_APPLICATION_ID, context.getPackageName());
IntentHandler.addTrustedIntentExtras(intent, context);
context.startActivity(intent);
}
}
......@@ -17,6 +17,7 @@ import org.chromium.base.VisibleForTesting;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.ChromeActivity;
import org.chromium.chrome.browser.appmenu.AppMenuPropertiesDelegate;
import org.chromium.chrome.browser.firstrun.FirstRunStatus;
import org.chromium.chrome.browser.share.ShareHelper;
import org.chromium.chrome.browser.tab.Tab;
......@@ -109,6 +110,10 @@ public class CustomTabAppMenuPropertiesDelegate extends AppMenuPropertiesDelegat
}
}
if (!FirstRunStatus.getFirstRunFlowComplete()) {
openInChromeItem.setVisible(false);
}
// Add custom menu items. Make sure they are only added once.
if (!mIsCustomEntryAdded) {
mIsCustomEntryAdded = true;
......
......@@ -58,6 +58,10 @@ public class CustomTabIntentDataProvider {
public static final String EXTRA_IS_MEDIA_VIEWER =
"org.chromium.chrome.browser.customtabs.IS_MEDIA_VIEWER";
/** Indicates that the Custom Tab should style itself as an info page. */
public static final String EXTRA_IS_INFO_PAGE =
"org.chromium.chrome.browser.customtabs.IS_INFO_PAGE";
/** Extra that defines the initial background color (RGB color stored as an integer). */
public static final String EXTRA_INITIAL_BACKGROUND_COLOR =
"org.chromium.chrome.browser.customtabs.EXTRA_INITIAL_BACKGROUND_COLOR";
......@@ -81,6 +85,7 @@ public class CustomTabIntentDataProvider {
private final Intent mKeepAliveServiceIntent;
private final int mTitleVisibilityState;
private final boolean mIsMediaViewer;
private final boolean mIsInfoPage;
private final int mInitialBackgroundColor;
private int mToolbarColor;
......@@ -162,6 +167,8 @@ public class CustomTabIntentDataProvider {
CustomTabsIntent.EXTRA_REMOTEVIEWS_PENDINGINTENT);
mIsMediaViewer = mIsTrustedIntent
&& IntentUtils.safeGetBooleanExtra(intent, EXTRA_IS_MEDIA_VIEWER, false);
mIsInfoPage = mIsTrustedIntent
&& IntentUtils.safeGetBooleanExtra(intent, EXTRA_IS_INFO_PAGE, false);
}
/**
......@@ -462,6 +469,14 @@ public class CustomTabIntentDataProvider {
return mIsMediaViewer;
}
/**
* @return If the Custom Tab is an info page.
* See {@link #EXTRA_IS_INFO_PAGE}.
*/
boolean isInfoPage() {
return mIsInfoPage;
}
/**
* See {@link #EXTRA_INITIAL_BACKGROUND_COLOR}.
* @return The color if it was specified in the Intent, Color.TRANSPARENT otherwise.
......
......@@ -18,7 +18,7 @@ import org.chromium.base.ContextUtils;
import org.chromium.base.FieldTrialList;
import org.chromium.base.metrics.RecordHistogram;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.EmbedContentViewActivity;
import org.chromium.chrome.browser.customtabs.CustomTabActivity;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.sessions.SessionTabHelper;
import org.chromium.chrome.browser.tab.Tab;
......@@ -183,8 +183,7 @@ public class DataUseTabUIManager {
learnMore.setOnClickListener(new android.view.View.OnClickListener() {
@Override
public void onClick(View v) {
EmbedContentViewActivity.show(activity,
getDataUseUIString(DataUseUIMessage.DATA_USE_LEARN_MORE_TITLE),
CustomTabActivity.showInfoPage(activity,
getDataUseUIString(DataUseUIMessage.DATA_USE_LEARN_MORE_LINK_URL));
recordDataUseUIAction(DataUsageUIAction.DIALOG_LEARN_MORE_CLICKED);
}
......
......@@ -20,7 +20,7 @@ import org.chromium.base.library_loader.ProcessInitException;
import org.chromium.base.metrics.CachedMetrics.EnumeratedHistogramSample;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.ChromeApplication;
import org.chromium.chrome.browser.EmbedContentViewActivity;
import org.chromium.chrome.browser.customtabs.CustomTabActivity;
import org.chromium.chrome.browser.customtabs.CustomTabsConnection;
import org.chromium.chrome.browser.document.ChromeLauncherActivity;
import org.chromium.chrome.browser.init.ChromeBrowserInitializer;
......@@ -546,7 +546,7 @@ public class FirstRunActivity extends AppCompatActivity implements FirstRunPageD
}
@Override
public void showEmbedContentViewActivity(int title, int url) {
EmbedContentViewActivity.show(this, title, url);
public void showInfoPage(int url) {
CustomTabActivity.showInfoPage(this, getString(url));
}
}
......@@ -75,9 +75,8 @@ public interface FirstRunPageDelegate {
void openAccountAdder(Fragment fragment);
/**
* Show an EmbedContentViewActivity with a given title and a URL.
* @param title Resource id for the title of the EmbedContentViewActivity.
* @param url Resource id for the URL of the EmbedContentViewActivity.
* Show an informational web page. The page doesn't show navigation control.
* @param url Resource id for the URL of the web page.
*/
void showEmbedContentViewActivity(int title, int url);
void showInfoPage(int url);
}
......@@ -17,7 +17,7 @@ import android.widget.TextView;
import org.chromium.base.CommandLine;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.ChromeSwitches;
import org.chromium.chrome.browser.EmbedContentViewActivity;
import org.chromium.chrome.browser.customtabs.CustomTabActivity;
import org.chromium.ui.text.NoUnderlineClickableSpan;
import org.chromium.ui.text.SpanApplier;
import org.chromium.ui.text.SpanApplier.SpanInfo;
......@@ -40,15 +40,15 @@ public class LightweightFirstRunActivity extends FirstRunActivity {
NoUnderlineClickableSpan clickableTermsSpan = new NoUnderlineClickableSpan() {
@Override
public void onClick(View widget) {
EmbedContentViewActivity.show(LightweightFirstRunActivity.this,
R.string.terms_of_service_title, R.string.chrome_terms_of_service_url);
CustomTabActivity.showInfoPage(LightweightFirstRunActivity.this,
getString(R.string.chrome_terms_of_service_url));
}
};
NoUnderlineClickableSpan clickablePrivacySpan = new NoUnderlineClickableSpan() {
@Override
public void onClick(View widget) {
EmbedContentViewActivity.show(LightweightFirstRunActivity.this,
R.string.privacy_notice_title, R.string.chrome_privacy_notice_url);
CustomTabActivity.showInfoPage(LightweightFirstRunActivity.this,
getString(R.string.chrome_privacy_notice_url));
}
};
((TextView) findViewById(R.id.lightweight_fre_tos_and_privacy))
......
......@@ -73,8 +73,7 @@ public class ToSAndUMAFirstRunFragment extends FirstRunPage {
@Override
public void onClick(View widget) {
if (!isAdded()) return;
getPageDelegate().showEmbedContentViewActivity(R.string.terms_of_service_title,
R.string.chrome_terms_of_service_url);
getPageDelegate().showInfoPage(R.string.chrome_terms_of_service_url);
}
};
......@@ -82,8 +81,7 @@ public class ToSAndUMAFirstRunFragment extends FirstRunPage {
@Override
public void onClick(View widget) {
if (!isAdded()) return;
getPageDelegate().showEmbedContentViewActivity(R.string.privacy_notice_title,
R.string.chrome_privacy_notice_url);
getPageDelegate().showInfoPage(R.string.chrome_privacy_notice_url);
}
};
mTosAndPrivacy.setText(SpanApplier.applySpans(getString(R.string.fre_tos_and_privacy),
......
......@@ -33,7 +33,7 @@ import android.widget.TextView;
import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.base.VisibleForTesting;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.EmbedContentViewActivity;
import org.chromium.chrome.browser.customtabs.CustomTabActivity;
import org.chromium.chrome.browser.payments.ui.PaymentRequestUI.PaymentRequestObserverForTest;
import org.chromium.chrome.browser.preferences.autofill.CreditCardNumberFormattingTextWatcher;
import org.chromium.chrome.browser.widget.AlwaysDismissedDialog;
......@@ -150,8 +150,7 @@ public class EditorView extends AlwaysDismissedDialog
/** Launches the Autofill help page on top of the current Context. */
public static void launchAutofillHelpPage(Context context) {
EmbedContentViewActivity.show(
context, context.getString(R.string.help), HELP_URL);
CustomTabActivity.showInfoPage(context, HELP_URL);
}
/**
......
......@@ -13,7 +13,7 @@ import android.view.View.OnClickListener;
import android.widget.TextView;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.EmbedContentViewActivity;
import org.chromium.chrome.browser.customtabs.CustomTabActivity;
/**
* A preference that navigates to an URL.
......@@ -36,7 +36,7 @@ public class HyperlinkPreference extends Preference {
@Override
protected void onClick() {
EmbedContentViewActivity.show(getContext(), mTitleResId, mUrlResId);
CustomTabActivity.showInfoPage(getContext(), getContext().getString(mUrlResId));
}
@Override
......
......@@ -13,9 +13,9 @@ import android.widget.Button;
import android.widget.TextView;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.EmbedContentViewActivity;
import org.chromium.chrome.browser.autofill.PersonalDataManager;
import org.chromium.chrome.browser.autofill.PersonalDataManager.AutofillProfile;
import org.chromium.chrome.browser.customtabs.CustomTabActivity;
/**
* Server credit card settings.
......@@ -39,8 +39,8 @@ public class AutofillServerCardEditor extends AutofillCreditCardEditor {
v.findViewById(R.id.edit_server_card).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
EmbedContentViewActivity.show(getActivity(), R.string.autofill_edit_credit_card,
R.string.autofill_manage_wallet_cards_url);
CustomTabActivity.showInfoPage(getActivity(),
getActivity().getString(R.string.autofill_manage_wallet_cards_url));
}
});
......
......@@ -4,15 +4,16 @@
package org.chromium.chrome.browser.preferences.autofill;
import android.content.Context;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceFragment;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.EmbedContentViewActivity;
import org.chromium.chrome.browser.autofill.PersonalDataManager;
import org.chromium.chrome.browser.autofill.PersonalDataManager.AutofillProfile;
import org.chromium.chrome.browser.customtabs.CustomTabActivity;
/**
* Fragment for settings page that allows user to view and edit a single server-provided address.
......@@ -55,8 +56,9 @@ public class AutofillServerProfilePreferences
@Override
public boolean onPreferenceClick(Preference preference) {
assert preference.getKey().equals(PREF_SERVER_PROFILE_EDIT_LINK);
EmbedContentViewActivity.show(preference.getContext(), R.string.autofill_edit_profile,
R.string.autofill_manage_wallet_addresses_url);
Context context = preference.getContext();
CustomTabActivity.showInfoPage(
context, context.getString(R.string.autofill_manage_wallet_addresses_url));
return true;
}
}
......@@ -6,7 +6,7 @@ package org.chromium.chrome.browser.snackbar;
import android.content.Context;
import org.chromium.chrome.browser.EmbedContentViewActivity;
import org.chromium.chrome.browser.customtabs.CustomTabActivity;
import org.chromium.chrome.browser.datausage.DataUseTabUIManager;
import org.chromium.chrome.browser.datausage.DataUseTabUIManager.DataUsageUIAction;
import org.chromium.chrome.browser.datausage.DataUseUIMessage;
......@@ -84,10 +84,9 @@ public class DataUseSnackbarController implements SnackbarManager.SnackbarContro
*/
@Override
public void onAction(Object actionData) {
EmbedContentViewActivity.show(mContext,
DataUseTabUIManager.getDataUseUIString(DataUseUIMessage.DATA_USE_LEARN_MORE_TITLE),
DataUseTabUIManager.getDataUseUIString(
DataUseUIMessage.DATA_USE_LEARN_MORE_LINK_URL));
CustomTabActivity.showInfoPage(
mContext, DataUseTabUIManager.getDataUseUIString(
DataUseUIMessage.DATA_USE_LEARN_MORE_LINK_URL));
if (actionData == null) return;
int snackbarType = (int) actionData;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment