Skip to content

Commit

Permalink
aw: Page visiblity behind switch
Browse files Browse the repository at this point in the history
Enable page visibility behind a command line switch. There should be
no change in behavior if enable-page-visibility switch is missing.

When it's added:
* Visibility is changed to
  (view visible) && (!attached or window visible) && (!onPause-ed)
  The existing implementation is simply !onPaused.
* Pass page visibility signal into blink, and in turn, the compositor.

BUG=520089

Review URL: https://codereview.chromium.org/1291653004

Cr-Commit-Position: refs/heads/master@{#343396}
  • Loading branch information
boliu authored and Commit bot committed Aug 14, 2015
1 parent b125651 commit 7b59e50
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 5 deletions.
1 change: 1 addition & 0 deletions android_webview/common/aw_switches.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

namespace switches {

const char kEnablePageVisibility[] = "enable-page-visibility";
const char kUseInProcCommandBuffer[] = "use-in-proc-command-buffer";

} // namespace switches
1 change: 1 addition & 0 deletions android_webview/common/aw_switches.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace switches {

extern const char kEnablePageVisibility[];
extern const char kUseInProcCommandBuffer[];

} // namespace switches
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@

import org.chromium.android_webview.permission.AwGeolocationCallback;
import org.chromium.android_webview.permission.AwPermissionRequest;
import org.chromium.base.CommandLine;
import org.chromium.base.LocaleUtils;
import org.chromium.base.ThreadUtils;
import org.chromium.base.TraceEvent;
Expand Down Expand Up @@ -106,6 +107,9 @@ public class AwContents implements SmartClipProvider,
private static final boolean FORCE_AUXILIARY_BITMAP_RENDERING =
"goldfish".equals(Build.HARDWARE);

// Matches kEnablePageVisibility.
private static final String ENABLE_PAGE_VISIBILITY = "enable-page-visibility";

/**
* WebKit hit test related data structure. These are used to implement
* getHitTestResult, requestFocusNodeHref, requestImageRef methods in WebView.
Expand Down Expand Up @@ -233,10 +237,15 @@ public abstract static class VisualStateCallback {
private final AwSettings mSettings;
private final ScrollAccessibilityHelper mScrollAccessibilityHelper;

// Visibility related state.
private final boolean mEnablePageVisibility;
private boolean mIsPaused;
private boolean mIsViewVisible;
private boolean mIsWindowVisible;
private boolean mIsAttachedToWindow;
// Visiblity state of |mContentViewCore|.
private boolean mIsContentViewCoreVisible;

private Bitmap mFavicon;
private boolean mHasRequestedVisitedHistoryFromClient;
// TODO(boliu): This should be in a global context, not per webview.
Expand Down Expand Up @@ -716,6 +725,7 @@ public void onGestureZoomSupportChanged(
mScrollOffsetManager = dependencyFactory.createScrollOffsetManager(
new AwScrollOffsetManagerDelegate(), new OverScroller(mContext));
mScrollAccessibilityHelper = new ScrollAccessibilityHelper(mContainerView);
mEnablePageVisibility = CommandLine.getInstance().hasSwitch(ENABLE_PAGE_VISIBILITY);

setOverScrollMode(mContainerView.getOverScrollMode());
setScrollBarStyle(mInternalAccessAdapter.super_getScrollBarStyle());
Expand Down Expand Up @@ -963,7 +973,7 @@ mInternalAccessAdapter, webContents, new AwGestureStateListener(),
installWebContentsObserver();
mSettings.setWebContents(webContents);
nativeSetDipScale(mNativeAwContents, (float) mDIPScale);
mContentViewCore.onShow();
updateContentViewCoreVisibility();

// The native side object has been bound to this java instance, so now is the time to
// bind all the native->java relationships.
Expand Down Expand Up @@ -1763,7 +1773,7 @@ public void onPause() {
if (mIsPaused || isDestroyed()) return;
mIsPaused = true;
nativeSetIsPaused(mNativeAwContents, mIsPaused);
mContentViewCore.onHide();
updateContentViewCoreVisibility();
}

/**
Expand All @@ -1774,7 +1784,7 @@ public void onResume() {
if (!mIsPaused || isDestroyed()) return;
mIsPaused = false;
nativeSetIsPaused(mNativeAwContents, mIsPaused);
mContentViewCore.onShow();
updateContentViewCoreVisibility();
}

/**
Expand Down Expand Up @@ -2274,13 +2284,30 @@ public void onWindowVisibilityChanged(int visibility) {
private void setViewVisibilityInternal(boolean visible) {
mIsViewVisible = visible;
if (!isDestroyed()) nativeSetViewVisibility(mNativeAwContents, mIsViewVisible);
updateContentViewCoreVisibility();
}

private void setWindowVisibilityInternal(boolean visible) {
mInvalidateRootViewOnNextDraw |= Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP
&& visible && !mIsWindowVisible;
mIsWindowVisible = visible;
if (!isDestroyed()) nativeSetWindowVisibility(mNativeAwContents, mIsWindowVisible);
updateContentViewCoreVisibility();
}

private void updateContentViewCoreVisibility() {
if (isDestroyed()) return;
boolean contentViewCoreVisible = !mIsPaused;
if (mEnablePageVisibility) {
contentViewCoreVisible = contentViewCoreVisible && mIsWindowVisible && mIsViewVisible;
}

if (contentViewCoreVisible && !mIsContentViewCoreVisible) {
mContentViewCore.onShow();
} else if (!contentViewCoreVisible && mIsContentViewCoreVisible) {
mContentViewCore.onHide();
}
mIsContentViewCoreVisible = contentViewCoreVisible;
}

/**
Expand Down
10 changes: 8 additions & 2 deletions android_webview/renderer/aw_content_renderer_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <vector>

#include "android_webview/common/aw_resource.h"
#include "android_webview/common/aw_switches.h"
#include "android_webview/common/render_view_messages.h"
#include "android_webview/common/url_constants.h"
#include "android_webview/grit/aw_resources.h"
Expand All @@ -18,6 +19,7 @@
#include "android_webview/renderer/aw_render_frame_ext.h"
#include "android_webview/renderer/aw_render_view_ext.h"
#include "android_webview/renderer/print_render_frame_observer.h"
#include "base/command_line.h"
#include "base/i18n/rtl.h"
#include "base/message_loop/message_loop.h"
#include "base/strings/string_util.h"
Expand Down Expand Up @@ -47,8 +49,9 @@ using content::RenderThread;

namespace android_webview {

AwContentRendererClient::AwContentRendererClient() {
}
AwContentRendererClient::AwContentRendererClient()
: enable_page_visibility_(base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kEnablePageVisibility)) {}

AwContentRendererClient::~AwContentRendererClient() {
}
Expand Down Expand Up @@ -171,6 +174,9 @@ void AwContentRendererClient::AddKeySystems(
bool AwContentRendererClient::ShouldOverridePageVisibilityState(
const content::RenderFrame* render_frame,
blink::WebPageVisibilityState* override_state) {
if (enable_page_visibility_)
return false;

// webview is always visible due to rendering requirements.
*override_state = blink::WebPageVisibilityStateVisible;
return true;
Expand Down
1 change: 1 addition & 0 deletions android_webview/renderer/aw_content_renderer_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class AwContentRendererClient : public content::ContentRendererClient {
private:
scoped_ptr<AwRenderProcessObserver> aw_render_process_observer_;
scoped_ptr<visitedlink::VisitedLinkSlave> visited_link_slave_;
const bool enable_page_visibility_;
};

} // namespace android_webview
Expand Down

0 comments on commit 7b59e50

Please sign in to comment.