Commit 16da2603 authored by John Lin's avatar John Lin Committed by Commit Bot

Add setTopBarView in ActivityHostImpl.

Bug: 882404
Change-Id: I8a72e73be43f9cc9183c1716323dffa44894a4e5
Reviewed-on: https://chromium-review.googlesource.com/1221627Reviewed-by: default avatarTed Choc <tedchoc@chromium.org>
Reviewed-by: default avatarMichael van Ouwerkerk <mvanouwerkerk@chromium.org>
Reviewed-by: default avatarChris Palmer <palmer@chromium.org>
Commit-Queue: John Lin <chuanl@google.com>
Cr-Commit-Position: refs/heads/master@{#595115}
parent 2f699614
......@@ -586,7 +586,7 @@ deps = {
Var('chromium_git') + '/catapult.git' + '@' + Var('catapult_revision'),
'src/third_party/cct_dynamic_module/src': {
'url': Var('chromium_git') + '/dynamicmodule' + '@' + 'dd6520c2ecc1b41c435a2ccf822b302489de0016',
'url': Var('chromium_git') + '/dynamicmodule' + '@' + 'b89f5147c1fdf1d02850932ecd1ff16b8c0be545',
'condition': 'checkout_android',
},
......
......@@ -42,5 +42,12 @@
android:layout_marginEnd="@dimen/find_in_page_popup_margin_end"
android:layout_gravity="end|top"
android:layout="@layout/find_toolbar" />
<ViewStub
android:id="@+id/topbar_stub"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="start|top"
android:inflatedId="@+id/topbar"
android:layout="@layout/custom_tabs_topbar" />
</view>
</org.chromium.chrome.browser.toolbar.ToolbarControlContainer>
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2018 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. -->
<org.chromium.ui.widget.OptimizedFrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
......@@ -155,6 +155,7 @@ public class CustomTabActivity extends ChromeActivity<CustomTabActivityComponent
private BrowserSessionContentHandler mBrowserSessionContentHandler;
private Tab mMainTab;
private CustomTabBottomBarDelegate mBottomBarDelegate;
private CustomTabTopBarDelegate mTopBarDelegate;
private CustomTabTabPersistencePolicy mTabPersistencePolicy;
// This is to give the right package name while using the client's resources during an
......@@ -437,6 +438,11 @@ public class CustomTabActivity extends ChromeActivity<CustomTabActivityComponent
loadUrlInTab(mMainTab, new LoadUrlParams(uri.toString()), SystemClock.elapsedRealtime());
}
public void setTopBarContentView(View view) {
mTopBarDelegate.setTopBarContentView(view);
mTopBarDelegate.showTopBarIfNecessary();
}
@Override
public boolean shouldAllocateChildConnection() {
return !mHasCreatedTabEarly && !mHasSpeculated
......@@ -475,6 +481,7 @@ public class CustomTabActivity extends ChromeActivity<CustomTabActivityComponent
mBottomBarDelegate = new CustomTabBottomBarDelegate(this, mIntentDataProvider,
getFullscreenManager());
mBottomBarDelegate.showBottomBarIfNecessary();
mTopBarDelegate = new CustomTabTopBarDelegate(this);
}
@Override
......
// Copyright 2018 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.customtabs;
import android.support.annotation.Nullable;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewStub;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.ChromeActivity;
/**
* Delegate that manages top bar area inside of {@link CustomTabActivity}.
*/
class CustomTabTopBarDelegate {
private ChromeActivity mActivity;
private ViewGroup mTopBarView;
@Nullable
private View mTopBarContentView;
public CustomTabTopBarDelegate(ChromeActivity activity) {
mActivity = activity;
}
/**
* Makes the top bar area to show, if any.
*/
public void showTopBarIfNecessary() {
if (mTopBarContentView != null && mTopBarContentView.getParent() == null) {
getTopBarView().addView(mTopBarContentView);
}
}
/**
* Sets the content of the top bar.
*/
public void setTopBarContentView(View view) {
mTopBarContentView = view;
}
/**
* Gets the {@link ViewGroup} of the top bar. If it has not been inflated, inflate it first.
*/
private ViewGroup getTopBarView() {
if (mTopBarView == null) {
ViewStub topBarStub = ((ViewStub) mActivity.findViewById(R.id.topbar_stub));
mTopBarView = (ViewGroup) topBarStub.inflate();
}
return mTopBarView;
}
}
......@@ -43,4 +43,9 @@ public class ActivityHostImpl extends BaseActivityHost {
public void loadUri(Uri uri) {
mActivity.loadUri(uri);
}
@Override
public void setTopBarView(IObjectWrapper topBarView) {
mActivity.setTopBarContentView(ObjectWrapper.unwrap(topBarView, View.class));
}
}
......@@ -379,6 +379,7 @@ chrome_java_sources = [
"java/src/org/chromium/chrome/browser/customtabs/CustomTabNavigationEventObserver.java",
"java/src/org/chromium/chrome/browser/customtabs/CustomTabObserver.java",
"java/src/org/chromium/chrome/browser/customtabs/CustomTabTabPersistencePolicy.java",
"java/src/org/chromium/chrome/browser/customtabs/CustomTabTopBarDelegate.java",
"java/src/org/chromium/chrome/browser/customtabs/CustomTabsConnection.java",
"java/src/org/chromium/chrome/browser/customtabs/CustomTabsConnectionService.java",
"java/src/org/chromium/chrome/browser/customtabs/FirstMeaningfulPaintObserver.java",
......
......@@ -1110,6 +1110,39 @@ public class CustomTabActivityTest {
}
}
@Test
@SmallTest
@RetryOnFailure
public void testSetTopBarContentView() throws Exception {
Intent intent = createMinimalCustomTabIntent();
mCustomTabActivityTestRule.startCustomTabActivityWithIntent(intent);
ThreadUtils.runOnUiThread(() -> {
CustomTabActivity cctActivity = mCustomTabActivityTestRule.getActivity();
View anyView = new View(cctActivity);
cctActivity.setTopBarContentView(anyView);
ViewGroup topBar = cctActivity.findViewById(R.id.topbar);
Assert.assertNotNull(topBar);
Assert.assertThat(anyView.getParent(), equalTo(topBar));
});
}
@Test
@SmallTest
@RetryOnFailure
public void testSetTopBarContentView_secondCallIsNoOp() throws Exception {
Intent intent = createMinimalCustomTabIntent();
mCustomTabActivityTestRule.startCustomTabActivityWithIntent(intent);
ThreadUtils.runOnUiThread(() -> {
CustomTabActivity cctActivity = mCustomTabActivityTestRule.getActivity();
View anyView = new View(cctActivity);
cctActivity.setTopBarContentView(anyView);
// Second call will not crash.
cctActivity.setTopBarContentView(anyView);
});
}
@Test
@SmallTest
@Feature({"UiCatalogue"})
......
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