use of org.chromium.content_public.browser.WebContentsObserver 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);
}
use of org.chromium.content_public.browser.WebContentsObserver in project AndroidChromium by JackyAndroid.
the class MediaSessionTabHelper method createWebContentsObserver.
private WebContentsObserver createWebContentsObserver(WebContents webContents) {
return new WebContentsObserver(webContents) {
@Override
public void destroy() {
hideNotification();
super.destroy();
}
@Override
public void mediaSessionStateChanged(boolean isControllable, boolean isPaused, MediaMetadata metadata) {
if (!isControllable) {
hideNotification();
return;
}
mFallbackMetadata = null;
// metadata.
if (metadata == null || TextUtils.isEmpty(metadata.getTitle())) {
mFallbackMetadata = new MediaMetadata(sanitizeMediaTitle(mTab.getTitle()), metadata == null ? "" : metadata.getArtist(), metadata == null ? "" : metadata.getAlbum());
metadata = mFallbackMetadata;
}
Intent contentIntent = Tab.createBringTabToFrontIntent(mTab.getId());
if (contentIntent != null) {
contentIntent.putExtra(MediaNotificationUma.INTENT_EXTRA_NAME, MediaNotificationUma.SOURCE_MEDIA);
}
mNotificationInfoBuilder = new MediaNotificationInfo.Builder().setMetadata(metadata).setPaused(isPaused).setOrigin(mOrigin).setTabId(mTab.getId()).setPrivate(mTab.isIncognito()).setIcon(R.drawable.audio_playing).setLargeIcon(mFavicon).setDefaultLargeIcon(R.drawable.audio_playing_square).setActions(MediaNotificationInfo.ACTION_PLAY_PAUSE | MediaNotificationInfo.ACTION_SWIPEAWAY).setContentIntent(contentIntent).setId(R.id.media_playback_notification).setListener(mControlsListener);
MediaNotificationManager.show(ContextUtils.getApplicationContext(), mNotificationInfoBuilder.build());
Activity activity = getActivityFromTab(mTab);
if (activity != null) {
activity.setVolumeControlStream(AudioManager.STREAM_MUSIC);
}
}
};
}
use of org.chromium.content_public.browser.WebContentsObserver in project AndroidChromium by JackyAndroid.
the class ReaderModeManager method createWebContentsObserver.
protected WebContentsObserver createWebContentsObserver(WebContents webContents) {
final int readerTabId = mTabModelSelector.getCurrentTabId();
if (readerTabId == Tab.INVALID_TAB_ID)
return null;
return new WebContentsObserver(webContents) {
@Override
public void didStartProvisionalLoadForFrame(long frameId, long parentFrameId, boolean isMainFrame, String validatedUrl, boolean isErrorPage, boolean isIframeSrcdoc) {
if (!isMainFrame)
return;
// once the distillability test is successful.
if (readerTabId == mTabModelSelector.getCurrentTabId()) {
closeReaderPanel(StateChangeReason.TAB_NAVIGATION, false);
}
// Make sure the tab was not destroyed.
ReaderModeTabInfo tabInfo = mTabStatusMap.get(readerTabId);
if (tabInfo == null)
return;
tabInfo.setUrl(validatedUrl);
if (DomDistillerUrlUtils.isDistilledPage(validatedUrl)) {
tabInfo.setStatus(STARTED);
mReaderModePageUrl = validatedUrl;
}
}
@Override
public void didNavigateMainFrame(String url, String baseUrl, boolean isNavigationToDifferentPage, boolean isNavigationInPage, int statusCode) {
// (like those from history.replaceState()).
if (isNavigationInPage)
return;
if (DomDistillerUrlUtils.isDistilledPage(url))
return;
// Make sure the tab was not destroyed.
ReaderModeTabInfo tabInfo = mTabStatusMap.get(readerTabId);
if (tabInfo == null)
return;
tabInfo.setStatus(POSSIBLE);
if (!TextUtils.equals(url, DomDistillerUrlUtils.getOriginalUrlFromDistillerUrl(mReaderModePageUrl))) {
tabInfo.setStatus(NOT_POSSIBLE);
mIsUmaRecorded = false;
}
mReaderModePageUrl = null;
if (tabInfo.getStatus() != POSSIBLE) {
closeReaderPanel(StateChangeReason.UNKNOWN, false);
} else {
requestReaderPanelShow(StateChangeReason.UNKNOWN);
}
}
@Override
public void navigationEntryCommitted() {
// Make sure the tab was not destroyed.
ReaderModeTabInfo tabInfo = mTabStatusMap.get(readerTabId);
if (tabInfo == null)
return;
// Reset closed state of reader mode in this tab once we know a navigation is
// happening.
tabInfo.setIsDismissed(false);
// If the panel was not shown for the previous navigation, record it now.
Tab curTab = mTabModelSelector.getTabById(readerTabId);
if (curTab != null && !curTab.isNativePage() && !curTab.isBeingRestored()) {
recordPanelVisibilityForNavigation(false);
}
tabInfo.setIsPanelShowRecorded(false);
}
};
}
use of org.chromium.content_public.browser.WebContentsObserver in project AndroidChromium by JackyAndroid.
the class FullScreenActivity method createTab.
/**
* Creates the {@link Tab} used by the FullScreenActivity.
* If the {@code savedInstanceState} exists, then the user did not intentionally close the app
* by swiping it away in the recent tasks list. In that case, we try to restore the tab from
* disk.
*/
private Tab createTab() {
Tab tab = null;
boolean unfreeze = false;
int tabId = Tab.INVALID_TAB_ID;
String tabUrl = null;
if (getSavedInstanceState() != null) {
tabId = getSavedInstanceState().getInt(BUNDLE_TAB_ID, Tab.INVALID_TAB_ID);
tabUrl = getSavedInstanceState().getString(BUNDLE_TAB_URL);
}
if (tabId != Tab.INVALID_TAB_ID && tabUrl != null && getActivityDirectory() != null) {
// Restore the tab.
TabState tabState = TabState.restoreTabState(getActivityDirectory(), tabId);
tab = new Tab(tabId, Tab.INVALID_TAB_ID, false, this, getWindowAndroid(), TabLaunchType.FROM_RESTORE, TabCreationState.FROZEN_ON_RESTORE, tabState);
unfreeze = true;
}
if (tab == null) {
tab = new Tab(Tab.INVALID_TAB_ID, Tab.INVALID_TAB_ID, false, this, getWindowAndroid(), TabLaunchType.FROM_CHROME_UI, null, null);
}
tab.initialize(null, getTabContentManager(), createTabDelegateFactory(), false, unfreeze);
mWebContentsObserver = new WebContentsObserver(tab.getWebContents()) {
@Override
public void didCommitProvisionalLoadForFrame(long frameId, boolean isMainFrame, String url, int transitionType) {
if (isMainFrame) {
// Notify the renderer to permanently hide the top controls since they do
// not apply to fullscreen content views.
getActivityTab().updateTopControlsState(getActivityTab().getTopControlsStateConstraints(), true);
}
}
};
return tab;
}
Aggregations