Search in sources :

Example 1 with ContentView

use of org.chromium.content.browser.ContentView 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);
}
Also used : WebContents(org.chromium.content_public.browser.WebContents) ContentView(org.chromium.content.browser.ContentView) ViewGroup(android.view.ViewGroup) ViewAndroidDelegate(org.chromium.ui.base.ViewAndroidDelegate) View(android.view.View) ContentView(org.chromium.content.browser.ContentView) ContentViewClient(org.chromium.content.browser.ContentViewClient) WebContentsObserver(org.chromium.content_public.browser.WebContentsObserver)

Example 2 with ContentView

use of org.chromium.content.browser.ContentView in project AndroidChromium by JackyAndroid.

the class Tab method swapWebContents.

/** This is currently called when committing a pre-rendered page. */
@VisibleForTesting
@CalledByNative
public void swapWebContents(WebContents webContents, boolean didStartLoad, boolean didFinishLoad) {
    ContentViewCore cvc = new ContentViewCore(mThemedApplicationContext, PRODUCT_VERSION);
    ContentView cv = ContentView.createContentView(mThemedApplicationContext, cvc);
    cv.setContentDescription(mThemedApplicationContext.getResources().getString(R.string.accessibility_content_view));
    cvc.initialize(ViewAndroidDelegate.createBasicDelegate(cv), cv, webContents, getWindowAndroid());
    swapContentViewCore(cvc, false, didStartLoad, didFinishLoad);
}
Also used : ContentViewCore(org.chromium.content.browser.ContentViewCore) ContentView(org.chromium.content.browser.ContentView) VisibleForTesting(org.chromium.base.VisibleForTesting) CalledByNative(org.chromium.base.annotations.CalledByNative)

Example 3 with ContentView

use of org.chromium.content.browser.ContentView in project AndroidChromium by JackyAndroid.

the class Tab method initContentViewCore.

/**
     * Creates and initializes the {@link ContentViewCore}.
     *
     * @param webContents The WebContents object that will be used to build the
     *                    {@link ContentViewCore}.
     */
protected void initContentViewCore(WebContents webContents) {
    ContentViewCore cvc = new ContentViewCore(mThemedApplicationContext, PRODUCT_VERSION);
    ContentView cv = ContentView.createContentView(mThemedApplicationContext, cvc);
    cv.setContentDescription(mThemedApplicationContext.getResources().getString(R.string.accessibility_content_view));
    cvc.initialize(ViewAndroidDelegate.createBasicDelegate(cv), cv, webContents, getWindowAndroid());
    setContentViewCore(cvc);
    if (getTabModelSelector() instanceof SingleTabModelSelector) {
        getContentViewCore().setFullscreenRequiredForOrientationLock(false);
    }
}
Also used : ContentViewCore(org.chromium.content.browser.ContentViewCore) ContentView(org.chromium.content.browser.ContentView) SingleTabModelSelector(org.chromium.chrome.browser.tabmodel.SingleTabModelSelector)

Example 4 with ContentView

use of org.chromium.content.browser.ContentView in project AndroidChromium by JackyAndroid.

the class Tab method showSadTab.

/**
     * Constructs and shows a sad tab (Aw, Snap!).
     */
protected void showSadTab() {
    if (getContentViewCore() != null) {
        OnClickListener suggestionAction = new OnClickListener() {

            @Override
            public void onClick(View view) {
                Activity activity = mWindowAndroid.getActivity().get();
                assert activity != null;
                HelpAndFeedback.getInstance(activity).show(activity, activity.getString(R.string.help_context_sad_tab), Profile.getLastUsedProfile(), null);
            }
        };
        OnClickListener reloadButtonAction = new OnClickListener() {

            @Override
            public void onClick(View view) {
                reload();
            }
        };
        // Make sure we are not adding the "Aw, snap" view over an existing one.
        assert mSadTabView == null;
        mSadTabView = SadTabViewFactory.createSadTabView(mThemedApplicationContext, suggestionAction, reloadButtonAction);
        // Show the sad tab inside ContentView.
        getContentViewCore().getContainerView().addView(mSadTabView, new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
        notifyContentChanged();
    }
    FullscreenManager fullscreenManager = getFullscreenManager();
    if (fullscreenManager != null) {
        fullscreenManager.setPositionsForTabToNonFullscreen();
    }
}
Also used : FullscreenManager(org.chromium.chrome.browser.fullscreen.FullscreenManager) LayoutParams(android.widget.FrameLayout.LayoutParams) FrameLayout(android.widget.FrameLayout) OnClickListener(android.view.View.OnClickListener) ChromeLauncherActivity(org.chromium.chrome.browser.document.ChromeLauncherActivity) ChromeActivity(org.chromium.chrome.browser.ChromeActivity) CustomTabActivity(org.chromium.chrome.browser.customtabs.CustomTabActivity) Activity(android.app.Activity) ContentView(org.chromium.content.browser.ContentView) View(android.view.View)

Aggregations

ContentView (org.chromium.content.browser.ContentView)4 View (android.view.View)2 ContentViewCore (org.chromium.content.browser.ContentViewCore)2 Activity (android.app.Activity)1 OnClickListener (android.view.View.OnClickListener)1 ViewGroup (android.view.ViewGroup)1 FrameLayout (android.widget.FrameLayout)1 LayoutParams (android.widget.FrameLayout.LayoutParams)1 VisibleForTesting (org.chromium.base.VisibleForTesting)1 CalledByNative (org.chromium.base.annotations.CalledByNative)1 ChromeActivity (org.chromium.chrome.browser.ChromeActivity)1 CustomTabActivity (org.chromium.chrome.browser.customtabs.CustomTabActivity)1 ChromeLauncherActivity (org.chromium.chrome.browser.document.ChromeLauncherActivity)1 FullscreenManager (org.chromium.chrome.browser.fullscreen.FullscreenManager)1 SingleTabModelSelector (org.chromium.chrome.browser.tabmodel.SingleTabModelSelector)1 ContentViewClient (org.chromium.content.browser.ContentViewClient)1 WebContents (org.chromium.content_public.browser.WebContents)1 WebContentsObserver (org.chromium.content_public.browser.WebContentsObserver)1 ViewAndroidDelegate (org.chromium.ui.base.ViewAndroidDelegate)1