Java源码示例:org.chromium.chrome.browser.NativePage
示例1
/**
* Shows a native page for url if it's a valid chrome-native URL. Otherwise, does nothing.
* @param url The url of the current navigation.
* @param forceReload If true, the current native page (if any) will not be reused, even if it
* matches the URL.
* @return True, if a native page was displayed for url.
*/
boolean maybeShowNativePage(String url, boolean forceReload) {
// While detached for reparenting we don't have an owning Activity, or TabModelSelector,
// so we can't create the native page. The native page will be created once reparenting is
// completed.
if (mIsDetachedForReparenting) return false;
NativePage candidateForReuse = forceReload ? null : getNativePage();
NativePage nativePage = NativePageFactory.createNativePageForURL(url, candidateForReuse,
this, getTabModelSelector(), getActivity());
if (nativePage != null) {
showNativePage(nativePage);
notifyPageTitleChanged();
notifyFaviconChanged();
return true;
}
return false;
}
示例2
protected NativePage buildNewTabPage(ChromeActivity activity, Tab tab,
TabModelSelector tabModelSelector) {
if (FeatureUtilities.isChromeHomeEnabled()) {
if (tab.isIncognito()) {
return new ChromeHomeIncognitoNewTabPage(activity, tab, tabModelSelector,
((ChromeTabbedActivity) activity).getLayoutManager());
} else {
return new ChromeHomeNewTabPage(activity, tab, tabModelSelector,
((ChromeTabbedActivity) activity).getLayoutManager());
}
} else if (tab.isIncognito()) {
return new IncognitoNewTabPage(activity);
} else {
return new NewTabPage(activity, new TabShim(tab), tabModelSelector);
}
}
示例3
/**
* Shows a native page for url if it's a valid chrome-native URL. Otherwise, does nothing.
* @param url The url of the current navigation.
* @param forceReload If true, the current native page (if any) will not be reused, even if it
* matches the URL.
* @return True, if a native page was displayed for url.
*/
boolean maybeShowNativePage(String url, boolean forceReload) {
// While detached for reparenting we don't have an owning Activity, or TabModelSelector,
// so we can't create the native page. The native page will be created once reparenting is
// completed.
if (mIsDetached) return false;
NativePage candidateForReuse = forceReload ? null : getNativePage();
NativePage nativePage = NativePageFactory.createNativePageForURL(url, candidateForReuse,
this, getTabModelSelector(), getActivity());
if (nativePage != null) {
showNativePage(nativePage);
notifyPageTitleChanged();
notifyFaviconChanged();
return true;
}
return false;
}
示例4
private Bitmap readbackNativePage(final Tab tab, float scale) {
Bitmap bitmap = null;
NativePage page = tab.getNativePage();
if (page == null) {
return bitmap;
}
View viewToDraw = page.getView();
if (viewToDraw == null || viewToDraw.getWidth() == 0 || viewToDraw.getHeight() == 0) {
return bitmap;
}
if (page instanceof InvalidationAwareThumbnailProvider) {
if (!((InvalidationAwareThumbnailProvider) page).shouldCaptureThumbnail()) {
return null;
}
}
int overlayTranslateY = mContentOffsetProvider.getOverlayTranslateY();
try {
bitmap = Bitmap.createBitmap(
(int) (viewToDraw.getWidth() * mThumbnailScale),
(int) ((viewToDraw.getHeight() - overlayTranslateY) * mThumbnailScale),
Bitmap.Config.ARGB_8888);
} catch (OutOfMemoryError ex) {
return null;
}
Canvas c = new Canvas(bitmap);
c.scale(scale, scale);
c.translate(0.f, -overlayTranslateY);
if (page instanceof InvalidationAwareThumbnailProvider) {
((InvalidationAwareThumbnailProvider) page).captureThumbnail(c);
} else {
viewToDraw.draw(c);
}
return bitmap;
}
示例5
protected NativePage buildNewTabPage(Activity activity, Tab tab,
TabModelSelector tabModelSelector) {
if (tab.isIncognito()) {
return new IncognitoNewTabPage(activity);
} else {
return new NewTabPage(activity, tab, tabModelSelector);
}
}
示例6
private static NativePageType nativePageType(String url, NativePage candidatePage,
boolean isIncognito) {
if (url == null) return NativePageType.NONE;
Uri uri = Uri.parse(url);
if (!CHROME_NATIVE_SCHEME.equals(uri.getScheme())) {
return NativePageType.NONE;
}
String host = uri.getHost();
if (candidatePage != null && candidatePage.getHost().equals(host)) {
return NativePageType.CANDIDATE;
}
if (UrlConstants.NTP_HOST.equals(host)) {
return NativePageType.NTP;
} else if (UrlConstants.BOOKMARKS_HOST.equals(host)) {
return NativePageType.BOOKMARKS;
} else if (UrlConstants.RECENT_TABS_HOST.equals(host) && !isIncognito) {
return NativePageType.RECENT_TABS;
} else if (UrlConstants.PHYSICAL_WEB_HOST.equals(host)) {
if (ChromeFeatureList.isEnabled("PhysicalWeb")) {
return NativePageType.PHYSICAL_WEB;
} else {
return NativePageType.NONE;
}
} else {
return NativePageType.NONE;
}
}
示例7
@VisibleForTesting
static NativePage createNativePageForURL(String url, NativePage candidatePage,
Tab tab, TabModelSelector tabModelSelector, Activity activity,
boolean isIncognito) {
NativePage page;
switch (nativePageType(url, candidatePage, isIncognito)) {
case NONE:
return null;
case CANDIDATE:
page = candidatePage;
break;
case NTP:
page = sNativePageBuilder.buildNewTabPage(activity, tab, tabModelSelector);
break;
case BOOKMARKS:
page = sNativePageBuilder.buildBookmarksPage(activity, tab);
break;
case RECENT_TABS:
page = sNativePageBuilder.buildRecentTabsPage(activity, tab);
break;
case PHYSICAL_WEB:
page = sNativePageBuilder.buildPhysicalWebDiagnosticsPage(activity);
break;
default:
assert false;
return null;
}
page.updateForUrl(url);
return page;
}
示例8
private void freeze(Tab tab) {
if (tab == null) return;
NativePage pageToFreeze = tab.getNativePage();
if (pageToFreeze == null || pageToFreeze instanceof FrozenNativePage
|| pageToFreeze.getView().getParent() != null) {
return;
}
tab.freezeNativePage();
}
示例9
/**
* Shows the given {@code nativePage} if it's not already showing.
* @param nativePage The {@link NativePage} to show.
*/
private void showNativePage(NativePage nativePage) {
if (mNativePage == nativePage) return;
NativePage previousNativePage = mNativePage;
mNativePage = nativePage;
pushNativePageStateToNavigationEntry();
// Notifying of theme color change before content change because some of
// the observers depend on the theme information being correct in
// onContentChanged().
updateThemeColorIfNeeded(false);
notifyContentChanged();
destroyNativePageInternal(previousNativePage);
}
示例10
/**
* Hides the current {@link NativePage}, if any, and shows the {@link ContentViewCore}'s view.
*/
protected void showRenderedPage() {
updateTitle();
if (mNativePage == null) return;
NativePage previousNativePage = mNativePage;
mNativePage = null;
notifyContentChanged();
destroyNativePageInternal(previousNativePage);
}
示例11
/**
* Shows a native page for url if it's a valid chrome-native URL. Otherwise, does nothing.
* @param url The url of the current navigation.
* @param forceReload If true, the current native page (if any) will not be reused, even if it
* matches the URL.
* @return True, if a native page was displayed for url.
*/
boolean maybeShowNativePage(String url, boolean forceReload) {
NativePage candidateForReuse = forceReload ? null : getNativePage();
NativePage nativePage = NativePageFactory.createNativePageForURL(url, candidateForReuse,
this, getTabModelSelector(), getActivity());
if (nativePage != null) {
showNativePage(nativePage);
notifyPageTitleChanged();
notifyFaviconChanged();
return true;
}
return false;
}
示例12
/**
* Called to swap out the current view with the one passed in.
*
* @param newContentViewCore The content view that should be swapped into the tab.
* @param deleteOldNativeWebContents Whether to delete the native web
* contents of old view.
* @param didStartLoad Whether
* WebContentsObserver::DidStartProvisionalLoadForFrame() has
* already been called.
* @param didFinishLoad Whether WebContentsObserver::DidFinishLoad() has
* already been called.
*/
public void swapContentViewCore(ContentViewCore newContentViewCore,
boolean deleteOldNativeWebContents, boolean didStartLoad, boolean didFinishLoad) {
int originalWidth = 0;
int originalHeight = 0;
if (mContentViewCore != null) {
originalWidth = mContentViewCore.getViewportWidthPix();
originalHeight = mContentViewCore.getViewportHeightPix();
mContentViewCore.onHide();
}
destroyContentViewCore(deleteOldNativeWebContents);
NativePage previousNativePage = mNativePage;
mNativePage = null;
setContentViewCore(newContentViewCore);
// Size of the new ContentViewCore is zero at this point. If we don't call onSizeChanged(),
// next onShow() call would send a resize message with the current ContentViewCore size
// (zero) to the renderer process, although the new size will be set soon.
// However, this size fluttering may confuse Blink and rendered result can be broken
// (see http://crbug.com/340987).
mContentViewCore.onSizeChanged(originalWidth, originalHeight, 0, 0);
mContentViewCore.onShow();
mContentViewCore.attachImeAdapter();
// If the URL has already committed (e.g. prerendering), tell process management logic that
// it can rely on the process visibility signal for binding management.
// TODO: Call ChildProcessLauncher#determinedVisibility() at a more intuitive time.
// See crbug.com/537671
if (!mContentViewCore.getWebContents().getLastCommittedUrl().equals("")) {
ChildProcessLauncher.determinedVisibility(mContentViewCore.getCurrentRenderProcessId());
}
destroyNativePageInternal(previousNativePage);
for (TabObserver observer : mObservers) {
observer.onWebContentsSwapped(this, didStartLoad, didFinishLoad);
}
}
示例13
private boolean shouldShowCusrsorInLocationBar() {
Tab tab = mToolbarModel.getTab();
if (tab == null) return false;
NativePage nativePage = tab.getNativePage();
if (!(nativePage instanceof NewTabPage) && !(nativePage instanceof IncognitoNewTabPage)) {
return false;
}
Context context = mToolbar.getContext();
return DeviceFormFactor.isTablet(context)
&& context.getResources().getConfiguration().keyboard
== Configuration.KEYBOARD_QWERTY;
}
示例14
private Bitmap readbackNativePage(final Tab tab, float scale) {
Bitmap bitmap = null;
NativePage page = tab.getNativePage();
if (page == null) {
return bitmap;
}
View viewToDraw = page.getView();
if (viewToDraw == null || viewToDraw.getWidth() == 0 || viewToDraw.getHeight() == 0) {
return bitmap;
}
if (page instanceof InvalidationAwareThumbnailProvider) {
if (!((InvalidationAwareThumbnailProvider) page).shouldCaptureThumbnail()) {
return null;
}
}
int overlayTranslateY = mContentOffsetProvider.getOverlayTranslateY();
try {
bitmap = Bitmap.createBitmap(
(int) (viewToDraw.getWidth() * mThumbnailScale),
(int) ((viewToDraw.getHeight() - overlayTranslateY) * mThumbnailScale),
Bitmap.Config.ARGB_8888);
} catch (OutOfMemoryError ex) {
return null;
}
Canvas c = new Canvas(bitmap);
c.scale(scale, scale);
c.translate(0.f, -overlayTranslateY);
if (page instanceof InvalidationAwareThumbnailProvider) {
((InvalidationAwareThumbnailProvider) page).captureThumbnail(c);
} else {
viewToDraw.draw(c);
}
return bitmap;
}
示例15
protected NativePage buildNewTabPage(ChromeActivity activity, Tab tab,
TabModelSelector tabModelSelector) {
if (tab.isIncognito()) {
return new IncognitoNewTabPage(activity);
} else {
return new NewTabPage(activity, tab, tabModelSelector);
}
}
示例16
private static NativePageType nativePageType(String url, NativePage candidatePage,
boolean isIncognito) {
if (url == null) return NativePageType.NONE;
Uri uri = Uri.parse(url);
if (!CHROME_NATIVE_SCHEME.equals(uri.getScheme())) {
return NativePageType.NONE;
}
String host = uri.getHost();
if (candidatePage != null && candidatePage.getHost().equals(host)) {
return NativePageType.CANDIDATE;
}
if (UrlConstants.NTP_HOST.equals(host)) {
return NativePageType.NTP;
} else if (UrlConstants.BOOKMARKS_HOST.equals(host)) {
return NativePageType.BOOKMARKS;
} else if (UrlConstants.DOWNLOADS_HOST.equals(host)) {
return NativePageType.DOWNLOADS;
} else if (UrlConstants.RECENT_TABS_HOST.equals(host) && !isIncognito) {
return NativePageType.RECENT_TABS;
} else if (UrlConstants.PHYSICAL_WEB_HOST.equals(host)) {
if (ChromeFeatureList.isEnabled("PhysicalWeb")) {
return NativePageType.PHYSICAL_WEB;
} else {
return NativePageType.NONE;
}
} else {
return NativePageType.NONE;
}
}
示例17
@VisibleForTesting
static NativePage createNativePageForURL(String url, NativePage candidatePage,
Tab tab, TabModelSelector tabModelSelector, ChromeActivity activity,
boolean isIncognito) {
NativePage page;
switch (nativePageType(url, candidatePage, isIncognito)) {
case NONE:
return null;
case CANDIDATE:
page = candidatePage;
break;
case NTP:
page = sNativePageBuilder.buildNewTabPage(activity, tab, tabModelSelector);
break;
case BOOKMARKS:
page = sNativePageBuilder.buildBookmarksPage(activity, tab);
break;
case DOWNLOADS:
page = sNativePageBuilder.buildDownloadsPage(activity, tab);
break;
case RECENT_TABS:
page = sNativePageBuilder.buildRecentTabsPage(activity, tab);
break;
case PHYSICAL_WEB:
page = sNativePageBuilder.buildPhysicalWebDiagnosticsPage(activity, tab);
break;
default:
assert false;
return null;
}
page.updateForUrl(url);
return page;
}
示例18
private void freeze(Tab tab) {
if (tab == null) return;
NativePage pageToFreeze = tab.getNativePage();
if (pageToFreeze == null || pageToFreeze instanceof FrozenNativePage
|| pageToFreeze.getView().getParent() != null) {
return;
}
tab.freezeNativePage();
}
示例19
/**
* Shows the given {@code nativePage} if it's not already showing.
* @param nativePage The {@link NativePage} to show.
*/
private void showNativePage(NativePage nativePage) {
if (mNativePage == nativePage) return;
NativePage previousNativePage = mNativePage;
mNativePage = nativePage;
pushNativePageStateToNavigationEntry();
// Notifying of theme color change before content change because some of
// the observers depend on the theme information being correct in
// onContentChanged().
updateThemeColorIfNeeded(false);
notifyContentChanged();
destroyNativePageInternal(previousNativePage);
}
示例20
/**
* Hides the current {@link NativePage}, if any, and shows the {@link ContentViewCore}'s view.
*/
protected void showRenderedPage() {
updateTitle();
if (mNativePage == null) return;
NativePage previousNativePage = mNativePage;
mNativePage = null;
notifyContentChanged();
destroyNativePageInternal(previousNativePage);
}
示例21
private boolean shouldShowCusrsorInLocationBar() {
Tab tab = mToolbarModel.getTab();
if (tab == null) return false;
NativePage nativePage = tab.getNativePage();
if (!(nativePage instanceof NewTabPage) && !(nativePage instanceof IncognitoNewTabPage)) {
return false;
}
Context context = mToolbar.getContext();
return DeviceFormFactor.isTablet(context)
&& context.getResources().getConfiguration().keyboard
== Configuration.KEYBOARD_QWERTY;
}
示例22
private Bitmap readbackNativePage(final Tab tab, float scale) {
Bitmap bitmap = null;
NativePage page = tab.getNativePage();
if (page == null) {
return bitmap;
}
View viewToDraw = page.getView();
if (viewToDraw == null || viewToDraw.getWidth() == 0 || viewToDraw.getHeight() == 0) {
return bitmap;
}
if (page instanceof InvalidationAwareThumbnailProvider) {
if (!((InvalidationAwareThumbnailProvider) page).shouldCaptureThumbnail()) {
return null;
}
}
float overlayTranslateY = mContentOffsetProvider.getOverlayTranslateY();
try {
bitmap = Bitmap.createBitmap(
(int) (viewToDraw.getWidth() * mThumbnailScale),
(int) ((viewToDraw.getHeight() - overlayTranslateY) * mThumbnailScale),
Bitmap.Config.ARGB_8888);
} catch (OutOfMemoryError ex) {
return null;
}
Canvas c = new Canvas(bitmap);
c.scale(scale, scale);
c.translate(0.f, -overlayTranslateY);
if (page instanceof InvalidationAwareThumbnailProvider) {
((InvalidationAwareThumbnailProvider) page).captureThumbnail(c);
} else {
viewToDraw.draw(c);
}
return bitmap;
}
示例23
private static NativePageType nativePageType(String url, NativePage candidatePage,
boolean isIncognito) {
if (url == null) return NativePageType.NONE;
Uri uri = Uri.parse(url);
if (!UrlConstants.CHROME_NATIVE_SCHEME.equals(uri.getScheme())) {
return NativePageType.NONE;
}
String host = uri.getHost();
if (candidatePage != null && candidatePage.getHost().equals(host)) {
return NativePageType.CANDIDATE;
}
if (UrlConstants.NTP_HOST.equals(host)) {
return NativePageType.NTP;
} else if (UrlConstants.BOOKMARKS_HOST.equals(host)) {
return NativePageType.BOOKMARKS;
} else if (UrlConstants.DOWNLOADS_HOST.equals(host)) {
return NativePageType.DOWNLOADS;
} else if (UrlConstants.HISTORY_HOST.equals(host)) {
return NativePageType.HISTORY;
} else if (UrlConstants.RECENT_TABS_HOST.equals(host) && !isIncognito) {
return NativePageType.RECENT_TABS;
} else if (UrlConstants.PHYSICAL_WEB_DIAGNOSTICS_HOST.equals(host)) {
if (ChromeFeatureList.isEnabled("PhysicalWeb")) {
return NativePageType.PHYSICAL_WEB;
} else {
return NativePageType.NONE;
}
} else {
return NativePageType.NONE;
}
}
示例24
@VisibleForTesting
static NativePage createNativePageForURL(String url, NativePage candidatePage,
Tab tab, TabModelSelector tabModelSelector, ChromeActivity activity,
boolean isIncognito) {
NativePage page;
switch (nativePageType(url, candidatePage, isIncognito)) {
case NONE:
return null;
case CANDIDATE:
page = candidatePage;
break;
case NTP:
page = sNativePageBuilder.buildNewTabPage(activity, tab, tabModelSelector);
break;
case BOOKMARKS:
page = sNativePageBuilder.buildBookmarksPage(activity, tab);
break;
case DOWNLOADS:
page = sNativePageBuilder.buildDownloadsPage(activity, tab);
break;
case HISTORY:
page = sNativePageBuilder.buildHistoryPage(activity, tab);
break;
case RECENT_TABS:
page = sNativePageBuilder.buildRecentTabsPage(activity, tab);
break;
case PHYSICAL_WEB:
page = sNativePageBuilder.buildPhysicalWebDiagnosticsPage(activity, tab);
break;
default:
assert false;
return null;
}
page.updateForUrl(url);
return page;
}
示例25
private void freeze(Tab tab) {
if (tab == null) return;
NativePage pageToFreeze = tab.getNativePage();
if (pageToFreeze == null || pageToFreeze instanceof FrozenNativePage
|| pageToFreeze.getView().getParent() != null) {
return;
}
tab.freezeNativePage();
}
示例26
/**
* Shows the given {@code nativePage} if it's not already showing.
* @param nativePage The {@link NativePage} to show.
*/
private void showNativePage(NativePage nativePage) {
if (mNativePage == nativePage) return;
NativePage previousNativePage = mNativePage;
mNativePage = nativePage;
pushNativePageStateToNavigationEntry();
// Notifying of theme color change before content change because some of
// the observers depend on the theme information being correct in
// onContentChanged().
updateThemeColorIfNeeded(false);
notifyContentChanged();
destroyNativePageInternal(previousNativePage);
}
示例27
/**
* Hides the current {@link NativePage}, if any, and shows the {@link ContentViewCore}'s view.
*/
protected void showRenderedPage() {
updateTitle();
if (mNativePage == null) return;
NativePage previousNativePage = mNativePage;
mNativePage = null;
notifyContentChanged();
destroyNativePageInternal(previousNativePage);
}
示例28
/**
* Called to swap out the current view with the one passed in.
*
* @param newContentViewCore The content view that should be swapped into the tab.
* @param deleteOldNativeWebContents Whether to delete the native web
* contents of old view.
* @param didStartLoad Whether
* WebContentsObserver::DidStartProvisionalLoadForFrame() has
* already been called.
* @param didFinishLoad Whether WebContentsObserver::DidFinishLoad() has
* already been called.
*/
public void swapContentViewCore(ContentViewCore newContentViewCore,
boolean deleteOldNativeWebContents, boolean didStartLoad, boolean didFinishLoad) {
int originalWidth = 0;
int originalHeight = 0;
if (mContentViewCore != null) {
originalWidth = mContentViewCore.getViewportWidthPix();
originalHeight = mContentViewCore.getViewportHeightPix();
mContentViewCore.onHide();
}
Rect bounds = new Rect();
if (originalWidth == 0 && originalHeight == 0) {
bounds = ExternalPrerenderHandler.estimateContentSize(
(Application) getApplicationContext(), false);
originalWidth = bounds.right - bounds.left;
originalHeight = bounds.bottom - bounds.top;
}
destroyContentViewCore(deleteOldNativeWebContents);
NativePage previousNativePage = mNativePage;
mNativePage = null;
// Size of the new ContentViewCore is zero at this point. If we don't call onSizeChanged(),
// next onShow() call would send a resize message with the current ContentViewCore size
// (zero) to the renderer process, although the new size will be set soon.
// However, this size fluttering may confuse Blink and rendered result can be broken
// (see http://crbug.com/340987).
newContentViewCore.onSizeChanged(originalWidth, originalHeight, 0, 0);
if (!bounds.isEmpty()) {
nativeOnPhysicalBackingSizeChanged(mNativeTabAndroid,
newContentViewCore.getWebContents(), bounds.right, bounds.bottom);
}
newContentViewCore.onShow();
setContentViewCore(newContentViewCore);
destroyNativePageInternal(previousNativePage);
for (TabObserver observer : mObservers) {
observer.onWebContentsSwapped(this, didStartLoad, didFinishLoad);
}
}
示例29
private boolean shouldShowCusrsorInLocationBar() {
Tab tab = mToolbarModel.getTab();
if (tab == null) return false;
NativePage nativePage = tab.getNativePage();
if (!(nativePage instanceof NewTabPage) && !(nativePage instanceof IncognitoNewTabPage)) {
return false;
}
Context context = mToolbar.getContext();
return DeviceFormFactor.isTablet()
&& context.getResources().getConfiguration().keyboard
== Configuration.KEYBOARD_QWERTY;
}
示例30
public NativePageDialog(Activity ownerActivity, NativePage page) {
super(ownerActivity, R.style.DialogWhenLarge);
mPage = page;
}