Java Code Examples for org.chromium.content.browser.ContentViewCore#getWebContents()
The following examples show how to use
org.chromium.content.browser.ContentViewCore#getWebContents() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ContextMenuHelper.java From delion with Apache License 2.0 | 6 votes |
/** * Starts showing a context menu for {@code view} based on {@code params}. * @param contentViewCore The {@link ContentViewCore} to show the menu to. * @param params The {@link ContextMenuParams} that indicate what menu items to show. */ @CalledByNative private boolean showContextMenu(ContentViewCore contentViewCore, ContextMenuParams params) { final View view = contentViewCore.getContainerView(); if (view == null || view.getVisibility() != View.VISIBLE || view.getParent() == null) { return false; } mCurrentContextMenuParams = params; view.setOnCreateContextMenuListener(this); if (view.showContextMenu()) { WebContents webContents = contentViewCore.getWebContents(); RecordHistogram.recordBooleanHistogram( "ContextMenu.Shown", webContents != null); if (webContents != null) webContents.onContextMenuOpened(); return true; } return false; }
Example 2
Source File: ContextMenuHelper.java From AndroidChromium with Apache License 2.0 | 6 votes |
/** * Starts showing a context menu for {@code view} based on {@code params}. * @param contentViewCore The {@link ContentViewCore} to show the menu to. * @param params The {@link ContextMenuParams} that indicate what menu items to show. */ @CalledByNative private void showContextMenu(ContentViewCore contentViewCore, ContextMenuParams params) { final View view = contentViewCore.getContainerView(); if (view == null || view.getVisibility() != View.VISIBLE || view.getParent() == null) { return; } mCurrentContextMenuParams = params; view.setOnCreateContextMenuListener(this); if (view.showContextMenu()) { WebContents webContents = contentViewCore.getWebContents(); RecordHistogram.recordBooleanHistogram( "ContextMenu.Shown", webContents != null); } }
Example 3
Source File: ContextualSearchSelectionController.java From delion with Apache License 2.0 | 5 votes |
/** * Expands the current selection by the specified amounts. * @param selectionStartAdjust The start offset adjustment of the selection to use to highlight * the search term. * @param selectionEndAdjust The end offset adjustment of the selection to use to highlight * the search term. */ void adjustSelection(int selectionStartAdjust, int selectionEndAdjust) { // TODO(donnd): add code to verify that the selection is still valid before changing it. // crbug.com/508354 if (selectionStartAdjust == 0 && selectionEndAdjust == 0) return; ContentViewCore basePageContentView = getBaseContentView(); if (basePageContentView != null && basePageContentView.getWebContents() != null) { mDidExpandSelection = true; basePageContentView.getWebContents().adjustSelectionByCharacterOffset( selectionStartAdjust, selectionEndAdjust); } }
Example 4
Source File: ContextualSearchSelectionController.java From AndroidChromium with Apache License 2.0 | 5 votes |
/** * Expands the current selection by the specified amounts. * @param selectionStartAdjust The start offset adjustment of the selection to use to highlight * the search term. * @param selectionEndAdjust The end offset adjustment of the selection to use to highlight * the search term. */ void adjustSelection(int selectionStartAdjust, int selectionEndAdjust) { // TODO(donnd): add code to verify that the selection is still valid before changing it. // crbug.com/508354 if (selectionStartAdjust == 0 && selectionEndAdjust == 0) return; ContentViewCore basePageContentView = getBaseContentView(); if (basePageContentView != null && basePageContentView.getWebContents() != null) { mDidExpandSelection = true; basePageContentView.getWebContents().adjustSelectionByCharacterOffset( selectionStartAdjust, selectionEndAdjust); } }
Example 5
Source File: ContextualSearchSelectionController.java From 365browser with Apache License 2.0 | 5 votes |
/** * @return The Base Page's {@link WebContents}, or {@code null} if there is no current tab or * the current tab has no {@link ContentViewCore}. */ WebContents getBaseWebContents() { Tab currentTab = mActivity.getActivityTab(); if (currentTab == null) return null; ContentViewCore contentViewCore = currentTab.getContentViewCore(); if (contentViewCore == null) return null; return contentViewCore.getWebContents(); }
Example 6
Source File: ReaderModePanel.java From delion with Apache License 2.0 | 4 votes |
@Override public OverlayPanelContent createNewOverlayPanelContent() { OverlayContentDelegate delegate = new OverlayContentDelegate() { /** * Track if a navigation/load is the first one for this content. */ private boolean mIsInitialLoad = true; @Override public void onContentViewCreated(ContentViewCore contentView) { mContentViewDelegate.setOverlayPanelContentViewCore(contentView); WebContents distilledWebContents = contentView.getWebContents(); if (distilledWebContents == null) return; WebContents sourceWebContents = mManagerDelegate.getBasePageWebContents(); if (sourceWebContents == null) return; DomDistillerTabUtils.distillAndView(sourceWebContents, distilledWebContents); } @Override public void onContentViewDestroyed() { mContentViewDelegate.releaseOverlayPanelContentViewCore(); mIsInitialLoad = true; } @Override public boolean shouldInterceptNavigation(ExternalNavigationHandler externalNavHandler, NavigationParams navigationParams) { // The initial load will be the distilled content; don't try to open a new tab if // this is the case. All other navigations on distilled pages will come from link // clicks. if (mIsInitialLoad) { mIsInitialLoad = false; return true; } if (!navigationParams.isExternalProtocol) { mManagerDelegate.createNewTab(navigationParams.url); return false; } return true; } }; return new OverlayPanelContent(delegate, new OverlayContentProgressObserver(), mActivity); }
Example 7
Source File: ReaderModePanel.java From AndroidChromium with Apache License 2.0 | 4 votes |
@Override public OverlayPanelContent createNewOverlayPanelContent() { OverlayContentDelegate delegate = new OverlayContentDelegate() { /** * Track if a navigation/load is the first one for this content. */ private boolean mIsInitialLoad = true; @Override public void onContentViewCreated(ContentViewCore contentView) { mContentViewDelegate.setOverlayPanelContentViewCore(contentView); WebContents distilledWebContents = contentView.getWebContents(); if (distilledWebContents == null) return; WebContents sourceWebContents = mManagerDelegate.getBasePageWebContents(); if (sourceWebContents == null) return; DomDistillerTabUtils.distillAndView(sourceWebContents, distilledWebContents); } @Override public void onContentViewDestroyed() { mContentViewDelegate.releaseOverlayPanelContentViewCore(); mIsInitialLoad = true; } @Override public boolean shouldInterceptNavigation(ExternalNavigationHandler externalNavHandler, NavigationParams navigationParams) { // The initial load will be the distilled content; don't try to open a new tab if // this is the case. All other navigations on distilled pages will come from link // clicks. if (mIsInitialLoad) { mIsInitialLoad = false; return true; } if (!navigationParams.isExternalProtocol) { mManagerDelegate.createNewTab(navigationParams.url); return false; } return true; } }; return new OverlayPanelContent(delegate, new OverlayContentProgressObserver(), mActivity); }
Example 8
Source File: ContextMenuHelper.java From 365browser with Apache License 2.0 | 4 votes |
/** * Starts showing a context menu for {@code view} based on {@code params}. * @param contentViewCore The {@link ContentViewCore} to show the menu to. * @param params The {@link ContextMenuParams} that indicate what menu items to show. */ @CalledByNative private void showContextMenu(final ContentViewCore contentViewCore, ContextMenuParams params) { if (params.isFile()) return; View view = contentViewCore.getContainerView(); final WindowAndroid windowAndroid = contentViewCore.getWindowAndroid(); if (view == null || view.getVisibility() != View.VISIBLE || view.getParent() == null || windowAndroid == null || windowAndroid.getActivity().get() == null || mPopulator == null) { return; } mCurrentContextMenuParams = params; mActivity = windowAndroid.getActivity().get(); mCallback = new Callback<Integer>() { @Override public void onResult(Integer result) { mPopulator.onItemSelected( ContextMenuHelper.this, mCurrentContextMenuParams, result); } }; mOnMenuShown = new Runnable() { @Override public void run() { WebContents webContents = contentViewCore.getWebContents(); RecordHistogram.recordBooleanHistogram("ContextMenu.Shown", webContents != null); } }; mOnMenuClosed = new Runnable() { @Override public void run() { if (mNativeContextMenuHelper == 0) return; nativeOnContextMenuClosed(mNativeContextMenuHelper); } }; if (ChromeFeatureList.isEnabled(ChromeFeatureList.CUSTOM_CONTEXT_MENU)) { List<Pair<Integer, List<ContextMenuItem>>> items = mPopulator.buildContextMenu(null, mActivity, mCurrentContextMenuParams); if (items.isEmpty()) { ThreadUtils.postOnUiThread(mOnMenuClosed); return; } final ContextMenuUi menuUi = new TabularContextMenuUi(new Runnable() { @Override public void run() { shareImageDirectly(ShareHelper.getLastShareComponentName()); } }); menuUi.displayMenu(mActivity, mCurrentContextMenuParams, items, mCallback, mOnMenuShown, mOnMenuClosed); if (mCurrentContextMenuParams.isImage()) { getThumbnail(new Callback<Bitmap>() { @Override public void onResult(Bitmap result) { ((TabularContextMenuUi) menuUi).onImageThumbnailRetrieved(result); } }); } return; } // The Platform Context Menu requires the listener within this hepler since this helper and // provides context menu for us to show. view.setOnCreateContextMenuListener(this); if (view.showContextMenu()) { mOnMenuShown.run(); windowAndroid.addContextMenuCloseListener(new OnCloseContextMenuListener() { @Override public void onContextMenuClosed() { mOnMenuClosed.run(); windowAndroid.removeContextMenuCloseListener(this); } }); } }
Example 9
Source File: ReaderModePanel.java From 365browser with Apache License 2.0 | 4 votes |
@Override public OverlayPanelContent createNewOverlayPanelContent() { OverlayContentDelegate delegate = new OverlayContentDelegate() { /** * Track if a navigation/load is the first one for this content. */ private boolean mIsInitialLoad = true; @Override public void onContentViewCreated(ContentViewCore contentView) { mContentViewDelegate.setOverlayPanelContentViewCore(contentView); WebContents distilledWebContents = contentView.getWebContents(); if (distilledWebContents == null) { closePanel(StateChangeReason.UNKNOWN, false); return; } WebContents sourceWebContents = mManagerDelegate.getBasePageWebContents(); if (sourceWebContents == null) { closePanel(StateChangeReason.UNKNOWN, false); return; } DomDistillerTabUtils.distillAndView(sourceWebContents, distilledWebContents); } @Override public void onContentViewDestroyed() { mContentViewDelegate.releaseOverlayPanelContentViewCore(); mIsInitialLoad = true; } @Override public boolean shouldInterceptNavigation(ExternalNavigationHandler externalNavHandler, NavigationParams navigationParams) { // The initial load will be the distilled content; don't try to open a new tab if // this is the case. All other navigations on distilled pages will come from link // clicks. if (mIsInitialLoad) { mIsInitialLoad = false; return true; } if (!navigationParams.isExternalProtocol) { mManagerDelegate.createNewTab(navigationParams.url); return false; } return true; } }; return new OverlayPanelContent(delegate, new OverlayContentProgressObserver(), mActivity); }