use of org.chromium.ui.base.ViewAndroidDelegate in project AndroidChromium by JackyAndroid.
the class OverlayPanelContent method createNewContentView.
/**
* Create a new ContentViewCore that will be managed by this panel.
*/
private void createNewContentView() {
if (mContentViewCore != null) {
// then there's no need to create a new one.
if (!mDidStartLoadingUrl)
return;
destroyContentView();
}
mContentViewCore = createContentViewCore(mActivity);
if (mContentViewClient == null) {
mContentViewClient = new ContentViewClient();
}
mContentViewCore.setContentViewClient(mContentViewClient);
ContentView cv = ContentView.createContentView(mActivity, mContentViewCore);
// Creates an initially hidden WebContents which gets shown when the panel is opened.
WebContents panelWebContents = WebContentsFactory.createWebContents(false, true);
// Dummny ViewAndroidDelegate since the container view for overlay panel is
// never added to the view hierarchy.
ViewAndroidDelegate delegate = new ViewAndroidDelegate() {
private ViewGroup mContainerView;
private ViewAndroidDelegate init(ViewGroup containerView) {
mContainerView = containerView;
return this;
}
@Override
public View acquireView() {
assert false : "Shold not reach here";
return null;
}
@Override
public void setViewPosition(View anchorView, float x, float y, float width, float height, float scale, int leftMargin, int topMargin) {
}
@Override
public void removeView(View anchorView) {
}
@Override
public ViewGroup getContainerView() {
return mContainerView;
}
}.init(cv);
mContentViewCore.initialize(delegate, cv, panelWebContents, mActivity.getWindowAndroid());
// Transfers the ownership of the WebContents to the native OverlayPanelContent.
nativeSetWebContents(mNativeOverlayPanelContentPtr, panelWebContents, mWebContentsDelegate);
mWebContentsObserver = new WebContentsObserver(panelWebContents) {
@Override
public void didStartLoading(String url) {
mContentDelegate.onContentLoadStarted(url);
}
@Override
public void navigationEntryCommitted() {
mContentDelegate.onNavigationEntryCommitted();
}
@Override
public void didStartProvisionalLoadForFrame(long frameId, long parentFrameId, boolean isMainFrame, String validatedUrl, boolean isErrorPage, boolean isIframeSrcdoc) {
if (isMainFrame) {
mContentDelegate.onMainFrameLoadStarted(validatedUrl, !TextUtils.equals(validatedUrl, mLoadedUrl));
}
}
@Override
public void didNavigateMainFrame(String url, String baseUrl, boolean isNavigationToDifferentPage, boolean isNavigationInPage, int httpResultCode) {
mIsProcessingPendingNavigation = false;
mContentDelegate.onMainFrameNavigation(url, !TextUtils.equals(url, mLoadedUrl), isHttpFailureCode(httpResultCode));
}
@Override
public void didFinishLoad(long frameId, String validatedUrl, boolean isMainFrame) {
mContentDelegate.onContentLoadFinished();
}
};
mInterceptNavigationDelegate = new InterceptNavigationDelegateImpl();
nativeSetInterceptNavigationDelegate(mNativeOverlayPanelContentPtr, mInterceptNavigationDelegate, panelWebContents);
mContentDelegate.onContentViewCreated(mContentViewCore);
}
Aggregations