Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1696)

Unified Diff: android_webview/native/aw_contents.cc

Issue 2650753002: Implement renderer importance API for WebView (Closed)
Patch Set: clean up unused local Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « android_webview/native/aw_contents.h ('k') | android_webview/native/aw_renderer_priority_manager.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: android_webview/native/aw_contents.cc
diff --git a/android_webview/native/aw_contents.cc b/android_webview/native/aw_contents.cc
index dfd03265d3a4b4b10f571ae05299b3f9299eb23d..050d71524defc95b328635441c0b7e8dba53a1b7 100644
--- a/android_webview/native/aw_contents.cc
+++ b/android_webview/native/aw_contents.cc
@@ -27,6 +27,7 @@
#include "android_webview/native/aw_gl_functor.h"
#include "android_webview/native/aw_pdf_exporter.h"
#include "android_webview/native/aw_picture.h"
+#include "android_webview/native/aw_renderer_priority_manager.h"
#include "android_webview/native/aw_web_contents_delegate.h"
#include "android_webview/native/java_browser_view_renderer_helper.h"
#include "android_webview/native/permission/aw_permission_request.h"
@@ -67,6 +68,8 @@
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/render_view_host.h"
+#include "content/public/browser/render_widget_host.h"
+#include "content/public/browser/render_widget_host_iterator.h"
#include "content/public/browser/ssl_status.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/mhtml_generation_params.h"
@@ -79,7 +82,6 @@
#include "ui/gfx/geometry/rect_f.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gfx/image/image.h"
-
struct AwDrawSWFunctionTable;
using autofill::ContentAutofillDriverFactory;
@@ -112,6 +114,8 @@ std::string g_locale;
std::string g_locale_list;
const void* kAwContentsUserDataKey = &kAwContentsUserDataKey;
+const void* kComputedRendererPriorityUserDataKey =
+ &kComputedRendererPriorityUserDataKey;
class AwContentsUserData : public base::SupportsUserData::Data {
public:
@@ -199,7 +203,10 @@ AwContents::AwContents(std::unique_ptr<WebContents> web_contents)
this,
BrowserThread::GetTaskRunnerForThread(BrowserThread::UI)),
web_contents_(std::move(web_contents)),
- renderer_manager_key_(GLViewRendererManager::GetInstance()->NullKey()) {
+ renderer_manager_key_(GLViewRendererManager::GetInstance()->NullKey()),
+ renderer_requested_priority_(
+ AwRendererPriorityManager::RENDERER_PRIORITY_HIGH),
+ renderer_priority_waived_when_not_visible_(false) {
base::subtle::NoBarrier_AtomicIncrement(&g_instance_count, 1);
icon_helper_.reset(new IconHelper(web_contents_.get()));
icon_helper_->SetListener(this);
@@ -228,6 +235,8 @@ AwContents::AwContents(std::unique_ptr<WebContents> web_contents)
InitAutofillIfNecessary(autofill_manager_delegate->GetSaveFormData());
content::SynchronousCompositor::SetClientForWebContents(
web_contents_.get(), &browser_view_renderer_);
+ UpdateRendererPriority();
+ web_contents_->GetRenderProcessHost()->AddObserver(this);
AwContentsLifecycleNotifier::OnWebViewCreated();
}
@@ -307,6 +316,8 @@ void AwContents::SetAwAutofillClient(const JavaRef<jobject>& client) {
AwContents::~AwContents() {
DCHECK_EQ(this, AwContents::FromWebContents(web_contents_.get()));
+ web_contents_->GetRenderProcessHost()->RemoveObserver(this);
+ UpdateRendererPriority(AwRendererPriorityManager::RENDERER_PRIORITY_WAIVED);
web_contents_->RemoveUserData(kAwContentsUserDataKey);
if (find_helper_.get())
find_helper_->SetListener(NULL);
@@ -859,6 +870,7 @@ void AwContents::SetViewVisibility(JNIEnv* env,
bool visible) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
browser_view_renderer_.SetViewVisibility(visible);
+ UpdateRendererPriority();
}
void AwContents::SetWindowVisibility(JNIEnv* env,
@@ -866,6 +878,7 @@ void AwContents::SetWindowVisibility(JNIEnv* env,
bool visible) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
browser_view_renderer_.SetWindowVisibility(visible);
+ UpdateRendererPriority();
}
void AwContents::SetIsPaused(JNIEnv* env,
@@ -873,6 +886,7 @@ void AwContents::SetIsPaused(JNIEnv* env,
bool paused) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
browser_view_renderer_.SetIsPaused(paused);
+ UpdateRendererPriority();
}
void AwContents::OnAttachedToWindow(JNIEnv* env,
@@ -881,12 +895,14 @@ void AwContents::OnAttachedToWindow(JNIEnv* env,
int h) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
browser_view_renderer_.OnAttachedToWindow(w, h);
+ UpdateRendererPriority();
}
void AwContents::OnDetachedFromWindow(JNIEnv* env,
const JavaParamRef<jobject>& obj) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
browser_view_renderer_.OnDetachedFromWindow();
+ UpdateRendererPriority();
}
bool AwContents::IsVisible(JNIEnv* env, const JavaParamRef<jobject>& obj) {
@@ -1173,6 +1189,91 @@ void AwContents::InsertVisualStateCallback(
ScopedJavaGlobalRef<jobject>(env, callback)));
}
+void AwContents::UpdateRendererPriority(
+ AwRendererPriorityManager::RendererPriority base_priority) {
+ DCHECK_CURRENTLY_ON(BrowserThread::UI);
+ content::RenderProcessHost* rph = web_contents_->GetRenderProcessHost();
+ AwRendererPriorityManager::RendererPriority computed_priority = base_priority;
+
+ std::unique_ptr<content::RenderWidgetHostIterator> widgets(
+ content::RenderWidgetHost::GetRenderWidgetHosts());
+ content::RenderWidgetHost* widget;
+ while ((widget = widgets->GetNextHost()) != nullptr &&
+ computed_priority <
+ AwRendererPriorityManager::RENDERER_PRIORITY_HIGH) {
+ content::RenderViewHost* view = content::RenderViewHost::From(widget);
+ if (view && rph == view->GetProcess()) {
+ content::WebContents* wc = content::WebContents::FromRenderViewHost(view);
+ if (wc && wc != web_contents_.get()) {
+ computed_priority =
+ std::max(FromWebContents(wc)->GetComputedRendererPriority(),
+ computed_priority);
+ }
+ }
+ }
+ GetAwRendererPriorityManager()->SetRendererPriority(computed_priority);
+}
+
+AwRendererPriorityManager::RendererPriority
+AwContents::GetComputedRendererPriority() {
+ if (renderer_priority_waived_when_not_visible_ &&
+ !browser_view_renderer_.IsClientVisible()) {
+ return AwRendererPriorityManager::RENDERER_PRIORITY_WAIVED;
+ }
+ return renderer_requested_priority_;
+}
+
+void AwContents::UpdateRendererPriority() {
+ UpdateRendererPriority(GetComputedRendererPriority());
+}
+
+AwRendererPriorityManager* AwContents::GetAwRendererPriorityManager() {
+ content::RenderProcessHost* rph = web_contents_->GetRenderProcessHost();
+ AwRendererPriorityManager* manager = static_cast<AwRendererPriorityManager*>(
+ rph->GetUserData(kComputedRendererPriorityUserDataKey));
+ if (manager == nullptr) {
+ rph->SetUserData(kComputedRendererPriorityUserDataKey,
+ manager = new AwRendererPriorityManager(rph));
+ }
+ return manager;
+}
+
+AwRendererPriorityManager::RendererPriority
+AwContents::GetCurrentRendererPriority() {
+ return GetAwRendererPriorityManager()->GetRendererPriority();
+}
+
+jint AwContents::GetRendererCurrentPriority(
+ JNIEnv* env,
+ const base::android::JavaParamRef<jobject>& obj) {
+ return GetCurrentRendererPriority();
+}
+
+jint AwContents::GetRendererRequestedPriority(
+ JNIEnv* env,
+ const base::android::JavaParamRef<jobject>& obj) {
+ return renderer_requested_priority_;
+}
+
+jboolean AwContents::GetRendererPriorityWaivedWhenNotVisible(
+ JNIEnv* env,
+ const base::android::JavaParamRef<jobject>& obj) {
+ return renderer_priority_waived_when_not_visible_;
+}
+
+void AwContents::SetRendererPriorityPolicy(
+ JNIEnv* env,
+ const JavaParamRef<jobject>& obj,
+ jint renderer_requested_priority,
+ jboolean renderer_priority_waived_when_not_visible) {
+ renderer_requested_priority_ =
+ static_cast<AwRendererPriorityManager::RendererPriority>(
+ renderer_requested_priority);
+ renderer_priority_waived_when_not_visible_ =
+ renderer_priority_waived_when_not_visible;
+ UpdateRendererPriority(renderer_requested_priority_);
+}
+
void AwContents::ClearView(JNIEnv* env, const JavaParamRef<jobject>& obj) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
browser_view_renderer_.ClearView();
@@ -1343,4 +1444,8 @@ bool AwContents::OnRenderProcessGoneDetail(int child_process_id,
child_process_id, crashed);
}
+void AwContents::RenderProcessReady(content::RenderProcessHost* host) {
+ UpdateRendererPriority();
+}
+
} // namespace android_webview
« no previous file with comments | « android_webview/native/aw_contents.h ('k') | android_webview/native/aw_renderer_priority_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698