Commit 7c8d964d authored by yusufo's avatar yusufo Committed by Commit bot

Use bounds instead of size for prerender requests

This changes the pipeline that initializes prerender contents
with a size to use bounds instead. Note that not all addPrerenderX
calls are switched to use Rect since for everywhere except Android
this won't be needed. Android needs bounds instead of size to get
info about the Physical Backing Size, also the top container height
(to be used for toolbar hide on scroll). With a Rect, all these can
be initialized and we can avoid extra Resizes that happen when the
native View is properly tied to the Android View hierarcy on swap.

This change only updates the params and shouldn't be making any
functional changes. A follow up Android only patch will start setting
the value to the origin.

BUG=628302

Review-Url: https://codereview.chromium.org/2259533003
Cr-Commit-Position: refs/heads/master@{#413469}
parent c09c6c48
...@@ -11,6 +11,7 @@ import android.content.Context; ...@@ -11,6 +11,7 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.Point; import android.graphics.Point;
import android.graphics.Rect;
import android.net.ConnectivityManager; import android.net.ConnectivityManager;
import android.net.Uri; import android.net.Uri;
import android.os.AsyncTask; import android.os.AsyncTask;
...@@ -751,7 +752,8 @@ public class CustomTabsConnection { ...@@ -751,7 +752,8 @@ public class CustomTabsConnection {
} }
if (referrer == null) referrer = ""; if (referrer == null) referrer = "";
WebContents webContents = mExternalPrerenderHandler.addPrerender( WebContents webContents = mExternalPrerenderHandler.addPrerender(
Profile.getLastUsedProfile(), url, referrer, contentSize.x, contentSize.y, Profile.getLastUsedProfile(), url, referrer,
new Rect(0, 0, contentSize.x, contentSize.y),
shouldPrerenderOnCellularForSession(session)); shouldPrerenderOnCellularForSession(session));
if (webContents == null) return false; if (webContents == null) return false;
if (throttle) mClientManager.registerPrerenderRequest(uid, url); if (throttle) mClientManager.registerPrerenderRequest(uid, url);
......
...@@ -8,6 +8,7 @@ import android.app.Application; ...@@ -8,6 +8,7 @@ import android.app.Application;
import android.content.Context; import android.content.Context;
import android.content.res.Resources; import android.content.res.Resources;
import android.graphics.Point; import android.graphics.Point;
import android.graphics.Rect;
import android.view.WindowManager; import android.view.WindowManager;
import org.chromium.base.VisibleForTesting; import org.chromium.base.VisibleForTesting;
...@@ -38,17 +39,16 @@ public class ExternalPrerenderHandler { ...@@ -38,17 +39,16 @@ public class ExternalPrerenderHandler {
* @param profile The profile to use for the prerender. * @param profile The profile to use for the prerender.
* @param url The url to prerender. * @param url The url to prerender.
* @param referrer The referrer for the prerender request. * @param referrer The referrer for the prerender request.
* @param width The width for the content view (render widget host view) for the prerender. * @param bounds The bounds for the content view (render widget host view) for the prerender.
* @param height The height for the content view (render widget host view) for the prerender.
* @param prerenderOnCellular Whether the prerender should happen if the device has a cellular * @param prerenderOnCellular Whether the prerender should happen if the device has a cellular
* connection. * connection.
* @return The {@link WebContents} that is linked to this prerender. {@code null} if * @return The {@link WebContents} that is linked to this prerender. {@code null} if
* unsuccessful. * unsuccessful.
*/ */
public WebContents addPrerender(Profile profile, String url, String referrer, int width, public WebContents addPrerender(Profile profile, String url, String referrer,
int height, boolean prerenderOnCellular) { Rect bounds, boolean prerenderOnCellular) {
WebContents webContents = WebContentsFactory.createWebContents(false, false); WebContents webContents = WebContentsFactory.createWebContents(false, false);
if (addPrerender(profile, webContents, url, referrer, width, height, prerenderOnCellular)) { if (addPrerender(profile, webContents, url, referrer, bounds, prerenderOnCellular)) {
return webContents; return webContents;
} }
if (webContents != null) webContents.destroy(); if (webContents != null) webContents.destroy();
...@@ -63,16 +63,16 @@ public class ExternalPrerenderHandler { ...@@ -63,16 +63,16 @@ public class ExternalPrerenderHandler {
* @param webContents The WebContents to add the prerender to. * @param webContents The WebContents to add the prerender to.
* @param url The url to prerender. * @param url The url to prerender.
* @param referrer The referrer for the prerender request. * @param referrer The referrer for the prerender request.
* @param width The width for the content view (render widget host view) for the prerender. * @param bounds The bounds for the content view (render widget host view) for the prerender.
* @param height The height for the content view (render widget host view) for the prerender.
* @param prerenderOnCellular Whether the prerender should happen if the device has a cellular * @param prerenderOnCellular Whether the prerender should happen if the device has a cellular
* connection. * connection.
* @return Whether the prerender was successful. * @return Whether the prerender was successful.
*/ */
public boolean addPrerender(Profile profile, WebContents webContents, String url, public boolean addPrerender(Profile profile, WebContents webContents, String url,
String referrer, int width, int height, boolean prerenderOnCellular) { String referrer, Rect bounds, boolean prerenderOnCellular) {
return nativeAddPrerender(mNativeExternalPrerenderHandler, profile, webContents, return nativeAddPrerender(mNativeExternalPrerenderHandler, profile, webContents, url,
url, referrer, width, height, prerenderOnCellular); referrer, bounds.top, bounds.left, bounds.bottom, bounds.right,
prerenderOnCellular);
} }
/** /**
...@@ -148,7 +148,7 @@ public class ExternalPrerenderHandler { ...@@ -148,7 +148,7 @@ public class ExternalPrerenderHandler {
private static native boolean nativeAddPrerender( private static native boolean nativeAddPrerender(
long nativeExternalPrerenderHandlerAndroid, Profile profile, long nativeExternalPrerenderHandlerAndroid, Profile profile,
WebContents webContents, String url, String referrer, WebContents webContents, String url, String referrer,
int width, int height, boolean prerenderOnCellular); int top, int left, int bottom, int right, boolean prerenderOnCellular);
private static native boolean nativeHasPrerenderedUrl( private static native boolean nativeHasPrerenderedUrl(
Profile profile, String url, WebContents webContents); Profile profile, String url, WebContents webContents);
private static native boolean nativeHasPrerenderedAndFinishedLoadingUrl( private static native boolean nativeHasPrerenderedAndFinishedLoadingUrl(
......
...@@ -6,6 +6,7 @@ package org.chromium.chrome.browser.prerender; ...@@ -6,6 +6,7 @@ package org.chromium.chrome.browser.prerender;
import static org.chromium.base.test.util.Restriction.RESTRICTION_TYPE_NON_LOW_END_DEVICE; import static org.chromium.base.test.util.Restriction.RESTRICTION_TYPE_NON_LOW_END_DEVICE;
import android.graphics.Rect;
import android.os.Environment; import android.os.Environment;
import android.test.suitebuilder.annotation.SmallTest; import android.test.suitebuilder.annotation.SmallTest;
...@@ -114,7 +115,8 @@ public class ExternalPrerenderHandlerTest extends NativeLibraryTestBase { ...@@ -114,7 +115,8 @@ public class ExternalPrerenderHandlerTest extends NativeLibraryTestBase {
@Override @Override
public WebContents call() { public WebContents call() {
WebContents webContents = WebContents webContents =
mExternalPrerenderHandler.addPrerender(mProfile, url, "", 0, 0, false); mExternalPrerenderHandler.addPrerender(
mProfile, url, "", new Rect(), false);
assertNotNull(webContents); assertNotNull(webContents);
assertTrue(mExternalPrerenderHandler.hasPrerenderedUrl( assertTrue(mExternalPrerenderHandler.hasPrerenderedUrl(
mProfile, url, webContents)); mProfile, url, webContents));
......
...@@ -31,7 +31,7 @@ class StubPrerenderContents : public PrerenderContents { ...@@ -31,7 +31,7 @@ class StubPrerenderContents : public PrerenderContents {
~StubPrerenderContents() override; ~StubPrerenderContents() override;
void StartPrerendering( void StartPrerendering(
const gfx::Size& size, const gfx::Rect& bounds,
content::SessionStorageNamespace* session_storage_namespace) override; content::SessionStorageNamespace* session_storage_namespace) override;
void ReportStartEvent() { NotifyPrerenderStart(); } void ReportStartEvent() { NotifyPrerenderStart(); }
...@@ -53,7 +53,7 @@ StubPrerenderContents::StubPrerenderContents( ...@@ -53,7 +53,7 @@ StubPrerenderContents::StubPrerenderContents(
StubPrerenderContents::~StubPrerenderContents() {} StubPrerenderContents::~StubPrerenderContents() {}
void StubPrerenderContents::StartPrerendering( void StubPrerenderContents::StartPrerendering(
const gfx::Size& size, const gfx::Rect& bounds,
content::SessionStorageNamespace* session_storage_namespace) { content::SessionStorageNamespace* session_storage_namespace) {
prerendering_has_started_ = true; prerendering_has_started_ = true;
} }
......
...@@ -98,7 +98,8 @@ void OffscreenTab::Start(const GURL& start_url, ...@@ -98,7 +98,8 @@ void OffscreenTab::Start(const GURL& start_url,
// Set initial size, if specified. // Set initial size, if specified.
if (!initial_size.IsEmpty()) if (!initial_size.IsEmpty())
ResizeWebContents(offscreen_tab_web_contents_.get(), initial_size); ResizeWebContents(offscreen_tab_web_contents_.get(),
gfx::Rect(initial_size));
// Mute audio output. When tab capture starts, the audio will be // Mute audio output. When tab capture starts, the audio will be
// automatically unmuted, but will be captured into the MediaStream. // automatically unmuted, but will be captured into the MediaStream.
...@@ -227,7 +228,7 @@ void OffscreenTab::EnterFullscreenModeForTab(WebContents* contents, ...@@ -227,7 +228,7 @@ void OffscreenTab::EnterFullscreenModeForTab(WebContents* contents,
contents->GetRenderWidgetHostView()->GetViewBounds().size(); contents->GetRenderWidgetHostView()->GetViewBounds().size();
if (contents->GetCapturerCount() >= 0 && if (contents->GetCapturerCount() >= 0 &&
!contents->GetPreferredSize().IsEmpty()) { !contents->GetPreferredSize().IsEmpty()) {
ResizeWebContents(contents, contents->GetPreferredSize()); ResizeWebContents(contents, gfx::Rect(contents->GetPreferredSize()));
} }
} }
...@@ -237,7 +238,7 @@ void OffscreenTab::ExitFullscreenModeForTab(WebContents* contents) { ...@@ -237,7 +238,7 @@ void OffscreenTab::ExitFullscreenModeForTab(WebContents* contents) {
if (!in_fullscreen_mode()) if (!in_fullscreen_mode())
return; return;
ResizeWebContents(contents, non_fullscreen_size_); ResizeWebContents(contents, gfx::Rect(non_fullscreen_size_));
non_fullscreen_size_ = gfx::Size(); non_fullscreen_size_ = gfx::Size();
} }
......
...@@ -57,8 +57,10 @@ bool ExternalPrerenderHandlerAndroid::AddPrerender( ...@@ -57,8 +57,10 @@ bool ExternalPrerenderHandlerAndroid::AddPrerender(
const JavaParamRef<jobject>& jweb_contents, const JavaParamRef<jobject>& jweb_contents,
const JavaParamRef<jstring>& jurl, const JavaParamRef<jstring>& jurl,
const JavaParamRef<jstring>& jreferrer, const JavaParamRef<jstring>& jreferrer,
jint width, jint top,
jint height, jint left,
jint bottom,
jint right,
jboolean prerender_on_cellular) { jboolean prerender_on_cellular) {
Profile* profile = ProfileAndroid::FromProfileAndroid(jprofile); Profile* profile = ProfileAndroid::FromProfileAndroid(jprofile);
...@@ -91,12 +93,12 @@ bool ExternalPrerenderHandlerAndroid::AddPrerender( ...@@ -91,12 +93,12 @@ bool ExternalPrerenderHandlerAndroid::AddPrerender(
prerender_manager->AddPrerenderOnCellularFromExternalRequest( prerender_manager->AddPrerenderOnCellularFromExternalRequest(
url, referrer, url, referrer,
web_contents->GetController().GetDefaultSessionStorageNamespace(), web_contents->GetController().GetDefaultSessionStorageNamespace(),
gfx::Size(width, height)); gfx::Rect(top, left, bottom, right));
} else { } else {
prerender_handle_ = prerender_manager->AddPrerenderFromExternalRequest( prerender_handle_ = prerender_manager->AddPrerenderFromExternalRequest(
url, referrer, url, referrer,
web_contents->GetController().GetDefaultSessionStorageNamespace(), web_contents->GetController().GetDefaultSessionStorageNamespace(),
gfx::Size(width, height)); gfx::Rect(top, left, bottom, right));
} }
return !!prerender_handle_; return !!prerender_handle_;
......
...@@ -35,8 +35,10 @@ class ExternalPrerenderHandlerAndroid { ...@@ -35,8 +35,10 @@ class ExternalPrerenderHandlerAndroid {
const base::android::JavaParamRef<jobject>& jweb_contents, const base::android::JavaParamRef<jobject>& jweb_contents,
const base::android::JavaParamRef<jstring>& url, const base::android::JavaParamRef<jstring>& url,
const base::android::JavaParamRef<jstring>& referrer, const base::android::JavaParamRef<jstring>& referrer,
jint width, jint top,
jint height, jint left,
jint bottom,
jint right,
jboolean prerender_on_cellular); jboolean prerender_on_cellular);
// Cancel the prerender associated with the prerender_handle_ // Cancel the prerender associated with the prerender_handle_
......
...@@ -43,7 +43,7 @@ ...@@ -43,7 +43,7 @@
#include "content/public/browser/web_contents_delegate.h" #include "content/public/browser/web_contents_delegate.h"
#include "content/public/common/frame_navigate_params.h" #include "content/public/common/frame_navigate_params.h"
#include "ui/base/page_transition_types.h" #include "ui/base/page_transition_types.h"
#include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/size.h"
using content::BrowserThread; using content::BrowserThread;
using content::DownloadItem; using content::DownloadItem;
...@@ -169,7 +169,7 @@ class PrerenderContents::WebContentsDelegateImpl ...@@ -169,7 +169,7 @@ class PrerenderContents::WebContentsDelegateImpl
gfx::Size GetSizeForNewRenderView(WebContents* web_contents) const override { gfx::Size GetSizeForNewRenderView(WebContents* web_contents) const override {
// Have to set the size of the RenderView on initialization to be sure it is // Have to set the size of the RenderView on initialization to be sure it is
// set before the RenderView is hidden on all platforms (esp. Android). // set before the RenderView is hidden on all platforms (esp. Android).
return prerender_contents_->size_; return prerender_contents_->bounds_.size();
} }
private: private:
...@@ -235,17 +235,16 @@ PrerenderContents* PrerenderContents::FromWebContents( ...@@ -235,17 +235,16 @@ PrerenderContents* PrerenderContents::FromWebContents(
} }
void PrerenderContents::StartPrerendering( void PrerenderContents::StartPrerendering(
const gfx::Size& size, const gfx::Rect& bounds,
SessionStorageNamespace* session_storage_namespace) { SessionStorageNamespace* session_storage_namespace) {
DCHECK(profile_); DCHECK(profile_);
DCHECK(!size.IsEmpty()); DCHECK(!bounds.IsEmpty());
DCHECK(!prerendering_has_started_); DCHECK(!prerendering_has_started_);
DCHECK(!prerender_contents_); DCHECK(!prerender_contents_);
DCHECK(size_.IsEmpty());
DCHECK_EQ(1U, alias_urls_.size()); DCHECK_EQ(1U, alias_urls_.size());
session_storage_namespace_id_ = session_storage_namespace->id(); session_storage_namespace_id_ = session_storage_namespace->id();
size_ = size; bounds_ = bounds;
DCHECK(load_start_time_.is_null()); DCHECK(load_start_time_.is_null());
load_start_time_ = base::TimeTicks::Now(); load_start_time_ = base::TimeTicks::Now();
...@@ -270,7 +269,7 @@ void PrerenderContents::StartPrerendering( ...@@ -270,7 +269,7 @@ void PrerenderContents::StartPrerendering(
web_contents_delegate_.reset(new WebContentsDelegateImpl(this)); web_contents_delegate_.reset(new WebContentsDelegateImpl(this));
prerender_contents_.get()->SetDelegate(web_contents_delegate_.get()); prerender_contents_.get()->SetDelegate(web_contents_delegate_.get());
// Set the size of the prerender WebContents. // Set the size of the prerender WebContents.
ResizeWebContents(prerender_contents_.get(), size_); ResizeWebContents(prerender_contents_.get(), bounds_);
// TODO(davidben): This logic assumes each prerender has at most one // TODO(davidben): This logic assumes each prerender has at most one
// route. https://crbug.com/440544 // route. https://crbug.com/440544
......
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
#include "content/public/browser/notification_registrar.h" #include "content/public/browser/notification_registrar.h"
#include "content/public/browser/web_contents_observer.h" #include "content/public/browser/web_contents_observer.h"
#include "content/public/common/referrer.h" #include "content/public/common/referrer.h"
#include "ui/gfx/geometry/size.h" #include "ui/gfx/geometry/rect.h"
class Profile; class Profile;
...@@ -110,12 +110,12 @@ class PrerenderContents : public content::NotificationObserver, ...@@ -110,12 +110,12 @@ class PrerenderContents : public content::NotificationObserver,
// Start rendering the contents in the prerendered state. If // Start rendering the contents in the prerendered state. If
// |is_control_group| is true, this will go through some of the mechanics of // |is_control_group| is true, this will go through some of the mechanics of
// starting a prerender, without actually creating the RenderView. |size| // starting a prerender, without actually creating the RenderView. |bounds|
// indicates the rectangular dimensions that the prerendered page should be. // indicates the rectangle that the prerendered page should be in.
// |session_storage_namespace| indicates the namespace that the prerendered // |session_storage_namespace| indicates the namespace that the prerendered
// page should be part of. // page should be part of.
virtual void StartPrerendering( virtual void StartPrerendering(
const gfx::Size& size, const gfx::Rect& bounds,
content::SessionStorageNamespace* session_storage_namespace); content::SessionStorageNamespace* session_storage_namespace);
// Verifies that the prerendering is not using too many resources, and kills // Verifies that the prerendering is not using too many resources, and kills
...@@ -343,8 +343,8 @@ class PrerenderContents : public content::NotificationObserver, ...@@ -343,8 +343,8 @@ class PrerenderContents : public content::NotificationObserver,
// Origin for this prerender. // Origin for this prerender.
Origin origin_; Origin origin_;
// The size of the WebView from the launching page. // The bounds of the WebView from the launching page.
gfx::Size size_; gfx::Rect bounds_;
typedef std::vector<history::HistoryAddPageArgs> AddPageVector; typedef std::vector<history::HistoryAddPageArgs> AddPageVector;
......
...@@ -59,6 +59,7 @@ ...@@ -59,6 +59,7 @@
#include "content/public/browser/web_contents_delegate.h" #include "content/public/browser/web_contents_delegate.h"
#include "content/public/common/url_constants.h" #include "content/public/common/url_constants.h"
#include "extensions/common/constants.h" #include "extensions/common/constants.h"
#include "ui/gfx/geometry/rect.h"
using content::BrowserThread; using content::BrowserThread;
using content::RenderViewHost; using content::RenderViewHost;
...@@ -235,8 +236,8 @@ PrerenderManager::AddPrerenderFromLinkRelPrerender( ...@@ -235,8 +236,8 @@ PrerenderManager::AddPrerenderFromLinkRelPrerender(
source_web_contents->GetController() source_web_contents->GetController()
.GetDefaultSessionStorageNamespace(); .GetDefaultSessionStorageNamespace();
} }
return AddPrerender(
return AddPrerender(origin, url, referrer, size, session_storage_namespace); origin, url, referrer, gfx::Rect(size), session_storage_namespace);
} }
std::unique_ptr<PrerenderHandle> PrerenderManager::AddPrerenderFromOmnibox( std::unique_ptr<PrerenderHandle> PrerenderManager::AddPrerenderFromOmnibox(
...@@ -245,7 +246,7 @@ std::unique_ptr<PrerenderHandle> PrerenderManager::AddPrerenderFromOmnibox( ...@@ -245,7 +246,7 @@ std::unique_ptr<PrerenderHandle> PrerenderManager::AddPrerenderFromOmnibox(
const gfx::Size& size) { const gfx::Size& size) {
if (!IsOmniboxEnabled(profile_)) if (!IsOmniboxEnabled(profile_))
return nullptr; return nullptr;
return AddPrerender(ORIGIN_OMNIBOX, url, content::Referrer(), size, return AddPrerender(ORIGIN_OMNIBOX, url, content::Referrer(), gfx::Rect(size),
session_storage_namespace); session_storage_namespace);
} }
...@@ -254,9 +255,9 @@ PrerenderManager::AddPrerenderFromExternalRequest( ...@@ -254,9 +255,9 @@ PrerenderManager::AddPrerenderFromExternalRequest(
const GURL& url, const GURL& url,
const content::Referrer& referrer, const content::Referrer& referrer,
SessionStorageNamespace* session_storage_namespace, SessionStorageNamespace* session_storage_namespace,
const gfx::Size& size) { const gfx::Rect& bounds) {
return AddPrerender( return AddPrerender(ORIGIN_EXTERNAL_REQUEST, url, referrer,
ORIGIN_EXTERNAL_REQUEST, url, referrer, size, session_storage_namespace); bounds, session_storage_namespace);
} }
std::unique_ptr<PrerenderHandle> std::unique_ptr<PrerenderHandle>
...@@ -264,11 +265,11 @@ PrerenderManager::AddPrerenderOnCellularFromExternalRequest( ...@@ -264,11 +265,11 @@ PrerenderManager::AddPrerenderOnCellularFromExternalRequest(
const GURL& url, const GURL& url,
const content::Referrer& referrer, const content::Referrer& referrer,
SessionStorageNamespace* session_storage_namespace, SessionStorageNamespace* session_storage_namespace,
const gfx::Size& size) { const gfx::Rect& bounds) {
return AddPrerender(ORIGIN_EXTERNAL_REQUEST_FORCED_CELLULAR, return AddPrerender(ORIGIN_EXTERNAL_REQUEST_FORCED_CELLULAR,
url, url,
referrer, referrer,
size, bounds,
session_storage_namespace); session_storage_namespace);
} }
...@@ -276,7 +277,7 @@ std::unique_ptr<PrerenderHandle> PrerenderManager::AddPrerenderForInstant( ...@@ -276,7 +277,7 @@ std::unique_ptr<PrerenderHandle> PrerenderManager::AddPrerenderForInstant(
const GURL& url, const GURL& url,
content::SessionStorageNamespace* session_storage_namespace, content::SessionStorageNamespace* session_storage_namespace,
const gfx::Size& size) { const gfx::Size& size) {
return AddPrerender(ORIGIN_INSTANT, url, content::Referrer(), size, return AddPrerender(ORIGIN_INSTANT, url, content::Referrer(), gfx::Rect(size),
session_storage_namespace); session_storage_namespace);
} }
...@@ -284,7 +285,7 @@ std::unique_ptr<PrerenderHandle> PrerenderManager::AddPrerenderForOffline( ...@@ -284,7 +285,7 @@ std::unique_ptr<PrerenderHandle> PrerenderManager::AddPrerenderForOffline(
const GURL& url, const GURL& url,
content::SessionStorageNamespace* session_storage_namespace, content::SessionStorageNamespace* session_storage_namespace,
const gfx::Size& size) { const gfx::Size& size) {
return AddPrerender(ORIGIN_OFFLINE, url, content::Referrer(), size, return AddPrerender(ORIGIN_OFFLINE, url, content::Referrer(), gfx::Rect(size),
session_storage_namespace); session_storage_namespace);
} }
...@@ -853,7 +854,7 @@ std::unique_ptr<PrerenderHandle> PrerenderManager::AddPrerender( ...@@ -853,7 +854,7 @@ std::unique_ptr<PrerenderHandle> PrerenderManager::AddPrerender(
Origin origin, Origin origin,
const GURL& url_arg, const GURL& url_arg,
const content::Referrer& referrer, const content::Referrer& referrer,
const gfx::Size& size, const gfx::Rect& bounds,
SessionStorageNamespace* session_storage_namespace) { SessionStorageNamespace* session_storage_namespace) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
...@@ -954,10 +955,10 @@ std::unique_ptr<PrerenderHandle> PrerenderManager::AddPrerender( ...@@ -954,10 +955,10 @@ std::unique_ptr<PrerenderHandle> PrerenderManager::AddPrerender(
last_prerender_start_time_ = GetCurrentTimeTicks(); last_prerender_start_time_ = GetCurrentTimeTicks();
gfx::Size contents_size = gfx::Rect contents_bounds =
size.IsEmpty() ? config_.default_tab_bounds.size() : size; bounds.IsEmpty() ? config_.default_tab_bounds : bounds;
prerender_contents_ptr->StartPrerendering(contents_size, prerender_contents_ptr->StartPrerendering(contents_bounds,
session_storage_namespace); session_storage_namespace);
DCHECK(IsControlGroup() || DCHECK(IsControlGroup() ||
......
...@@ -50,6 +50,7 @@ class WebContents; ...@@ -50,6 +50,7 @@ class WebContents;
} }
namespace gfx { namespace gfx {
class Rect;
class Size; class Size;
} }
...@@ -131,7 +132,7 @@ class PrerenderManager : public base::SupportsWeakPtr<PrerenderManager>, ...@@ -131,7 +132,7 @@ class PrerenderManager : public base::SupportsWeakPtr<PrerenderManager>,
const GURL& url, const GURL& url,
const content::Referrer& referrer, const content::Referrer& referrer,
content::SessionStorageNamespace* session_storage_namespace, content::SessionStorageNamespace* session_storage_namespace,
const gfx::Size& size); const gfx::Rect& bounds);
// Adds a prerender from an external request that will prerender even on // Adds a prerender from an external request that will prerender even on
// cellular networks as long as the user setting for prerendering is ON. // cellular networks as long as the user setting for prerendering is ON.
...@@ -139,7 +140,7 @@ class PrerenderManager : public base::SupportsWeakPtr<PrerenderManager>, ...@@ -139,7 +140,7 @@ class PrerenderManager : public base::SupportsWeakPtr<PrerenderManager>,
const GURL& url, const GURL& url,
const content::Referrer& referrer, const content::Referrer& referrer,
content::SessionStorageNamespace* session_storage_namespace, content::SessionStorageNamespace* session_storage_namespace,
const gfx::Size& size); const gfx::Rect& bounds);
// Adds a prerender for Instant Search |url| if valid. The // Adds a prerender for Instant Search |url| if valid. The
// |session_storage_namespace| matches the namespace of the active tab at the // |session_storage_namespace| matches the namespace of the active tab at the
...@@ -413,14 +414,14 @@ class PrerenderManager : public base::SupportsWeakPtr<PrerenderManager>, ...@@ -413,14 +414,14 @@ class PrerenderManager : public base::SupportsWeakPtr<PrerenderManager>,
Origin origin) const; Origin origin) const;
// Adds a prerender for |url| from |referrer|. The |origin| specifies how the // Adds a prerender for |url| from |referrer|. The |origin| specifies how the
// prerender was added. If |size| is empty, then // prerender was added. If |bounds| is empty, then
// PrerenderContents::StartPrerendering will instead use a default from // PrerenderContents::StartPrerendering will instead use a default from
// PrerenderConfig. Returns a PrerenderHandle or NULL. // PrerenderConfig. Returns a PrerenderHandle or NULL.
std::unique_ptr<PrerenderHandle> AddPrerender( std::unique_ptr<PrerenderHandle> AddPrerender(
Origin origin, Origin origin,
const GURL& url, const GURL& url,
const content::Referrer& referrer, const content::Referrer& referrer,
const gfx::Size& size, const gfx::Rect& bounds,
content::SessionStorageNamespace* session_storage_namespace); content::SessionStorageNamespace* session_storage_namespace);
void StartSchedulingPeriodicCleanups(); void StartSchedulingPeriodicCleanups();
......
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include "content/public/test/test_browser_thread.h" #include "content/public/test/test_browser_thread.h"
#include "net/base/network_change_notifier.h" #include "net/base/network_change_notifier.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/size.h" #include "ui/gfx/geometry/size.h"
#include "url/gurl.h" #include "url/gurl.h"
...@@ -59,7 +60,7 @@ class DummyPrerenderContents : public PrerenderContents { ...@@ -59,7 +60,7 @@ class DummyPrerenderContents : public PrerenderContents {
~DummyPrerenderContents() override; ~DummyPrerenderContents() override;
void StartPrerendering( void StartPrerendering(
const gfx::Size& size, const gfx::Rect& bounds,
content::SessionStorageNamespace* session_storage_namespace) override; content::SessionStorageNamespace* session_storage_namespace) override;
bool GetChildId(int* child_id) const override { bool GetChildId(int* child_id) const override {
...@@ -291,7 +292,7 @@ DummyPrerenderContents::~DummyPrerenderContents() { ...@@ -291,7 +292,7 @@ DummyPrerenderContents::~DummyPrerenderContents() {
} }
void DummyPrerenderContents::StartPrerendering( void DummyPrerenderContents::StartPrerendering(
const gfx::Size& size, const gfx::Rect& bounds,
content::SessionStorageNamespace* session_storage_namespace) { content::SessionStorageNamespace* session_storage_namespace) {
// In the base PrerenderContents implementation, StartPrerendering will // In the base PrerenderContents implementation, StartPrerendering will
// be called even when the PrerenderManager is part of the control group, // be called even when the PrerenderManager is part of the control group,
...@@ -1098,7 +1099,7 @@ TEST_F(PrerenderTest, PrerenderNotAllowedOnCellularWithExternalOrigin) { ...@@ -1098,7 +1099,7 @@ TEST_F(PrerenderTest, PrerenderNotAllowedOnCellularWithExternalOrigin) {
FINAL_STATUS_MANAGER_SHUTDOWN); FINAL_STATUS_MANAGER_SHUTDOWN);
std::unique_ptr<PrerenderHandle> prerender_handle( std::unique_ptr<PrerenderHandle> prerender_handle(
prerender_manager()->AddPrerenderFromExternalRequest( prerender_manager()->AddPrerenderFromExternalRequest(
url, content::Referrer(), nullptr, kSize)); url, content::Referrer(), nullptr, gfx::Rect(kSize)));
EXPECT_FALSE(prerender_handle); EXPECT_FALSE(prerender_handle);
EXPECT_FALSE(prerender_contents->prerendering_has_started()); EXPECT_FALSE(prerender_contents->prerendering_has_started());
} }
...@@ -1128,7 +1129,7 @@ TEST_F(PrerenderTest, PrerenderAllowedForOfflineAndForcedCellular) { ...@@ -1128,7 +1129,7 @@ TEST_F(PrerenderTest, PrerenderAllowedForOfflineAndForcedCellular) {
url, origin, FINAL_STATUS_USED); url, origin, FINAL_STATUS_USED);
prerender_handle = prerender_handle =
prerender_manager()->AddPrerenderOnCellularFromExternalRequest( prerender_manager()->AddPrerenderOnCellularFromExternalRequest(
url, content::Referrer(), nullptr, kSize); url, content::Referrer(), nullptr, gfx::Rect(kSize));
} }
EXPECT_TRUE(prerender_handle); EXPECT_TRUE(prerender_handle);
EXPECT_TRUE(prerender_handle->IsPrerendering()); EXPECT_TRUE(prerender_handle->IsPrerendering());
......
...@@ -216,7 +216,7 @@ void ChromeAppDelegate::RenderViewCreated( ...@@ -216,7 +216,7 @@ void ChromeAppDelegate::RenderViewCreated(
void ChromeAppDelegate::ResizeWebContents(content::WebContents* web_contents, void ChromeAppDelegate::ResizeWebContents(content::WebContents* web_contents,
const gfx::Size& size) { const gfx::Size& size) {
::ResizeWebContents(web_contents, size); ::ResizeWebContents(web_contents, gfx::Rect(size));
} }
content::WebContents* ChromeAppDelegate::OpenURLFromTab( content::WebContents* ChromeAppDelegate::OpenURLFromTab(
......
...@@ -128,7 +128,7 @@ content::WebContents* AddRestoredTab( ...@@ -128,7 +128,7 @@ content::WebContents* AddRestoredTab(
// yet and the bounds may not be available on all platforms. // yet and the bounds may not be available on all platforms.
if (size.IsEmpty()) if (size.IsEmpty())
size = browser->window()->GetRestoredBounds().size(); size = browser->window()->GetRestoredBounds().size();
ResizeWebContents(web_contents, size); ResizeWebContents(web_contents, gfx::Rect(size));
web_contents->WasHidden(); web_contents->WasHidden();
} }
SessionService* session_service = SessionService* session_service =
......
...@@ -232,7 +232,7 @@ void FullscreenController::OnTabDetachedFromView(WebContents* old_contents) { ...@@ -232,7 +232,7 @@ void FullscreenController::OnTabDetachedFromView(WebContents* old_contents) {
old_contents->GetFullscreenRenderWidgetHostView(); old_contents->GetFullscreenRenderWidgetHostView();
if (current_fs_view) if (current_fs_view)
current_fs_view->SetSize(old_contents->GetPreferredSize()); current_fs_view->SetSize(old_contents->GetPreferredSize());
ResizeWebContents(old_contents, old_contents->GetPreferredSize()); ResizeWebContents(old_contents, gfx::Rect(old_contents->GetPreferredSize()));
} }
void FullscreenController::OnTabClosing(WebContents* web_contents) { void FullscreenController::OnTabClosing(WebContents* web_contents) {
......
...@@ -64,7 +64,7 @@ class DummyPrerenderContents : public PrerenderContents { ...@@ -64,7 +64,7 @@ class DummyPrerenderContents : public PrerenderContents {
bool call_did_finish_load); bool call_did_finish_load);
void StartPrerendering( void StartPrerendering(
const gfx::Size& size, const gfx::Rect& bounds,
content::SessionStorageNamespace* session_storage_namespace) override; content::SessionStorageNamespace* session_storage_namespace) override;
bool GetChildId(int* child_id) const override; bool GetChildId(int* child_id) const override;
bool GetRouteId(int* route_id) const override; bool GetRouteId(int* route_id) const override;
...@@ -110,7 +110,7 @@ DummyPrerenderContents::DummyPrerenderContents( ...@@ -110,7 +110,7 @@ DummyPrerenderContents::DummyPrerenderContents(
} }
void DummyPrerenderContents::StartPrerendering( void DummyPrerenderContents::StartPrerendering(
const gfx::Size& size, const gfx::Rect& bounds,
content::SessionStorageNamespace* session_storage_namespace) { content::SessionStorageNamespace* session_storage_namespace) {
content::SessionStorageNamespaceMap session_storage_namespace_map; content::SessionStorageNamespaceMap session_storage_namespace_map;
session_storage_namespace_map[std::string()] = session_storage_namespace; session_storage_namespace_map[std::string()] = session_storage_namespace;
......
...@@ -793,7 +793,8 @@ void TabStripModel::AddWebContents(WebContents* contents, ...@@ -793,7 +793,8 @@ void TabStripModel::AddWebContents(WebContents* contents,
// new background tab. // new background tab.
if (WebContents* old_contents = GetActiveWebContents()) { if (WebContents* old_contents = GetActiveWebContents()) {
if ((add_types & ADD_ACTIVE) == 0) { if ((add_types & ADD_ACTIVE) == 0) {
ResizeWebContents(contents, old_contents->GetContainerBounds().size()); ResizeWebContents(
contents, gfx::Rect(old_contents->GetContainerBounds().size()));
} }
} }
} }
......
...@@ -14,13 +14,13 @@ ...@@ -14,13 +14,13 @@
#endif #endif
void ResizeWebContents(content::WebContents* web_contents, void ResizeWebContents(content::WebContents* web_contents,
const gfx::Size& new_size) { const gfx::Rect& new_bounds) {
#if defined(USE_AURA) #if defined(USE_AURA)
aura::Window* window = web_contents->GetNativeView(); aura::Window* window = web_contents->GetNativeView();
window->SetBounds(gfx::Rect(window->bounds().origin(), new_size)); window->SetBounds(gfx::Rect(window->bounds().origin(), new_bounds.size()));
#elif defined(OS_ANDROID) #elif defined(OS_ANDROID)
content::RenderWidgetHostView* view = web_contents->GetRenderWidgetHostView(); content::RenderWidgetHostView* view = web_contents->GetRenderWidgetHostView();
if (view) if (view)
view->SetSize(new_size); view->SetSize(new_bounds.size());
#endif #endif
} }
...@@ -10,12 +10,11 @@ class WebContents; ...@@ -10,12 +10,11 @@ class WebContents;
} }
namespace gfx { namespace gfx {
class Size; class Rect;
} }
// A platform-agnostic function to resize a WebContents. The top-left corner of // A platform-agnostic function to resize a WebContents.
// the WebContents does not move during the resizing.
void ResizeWebContents(content::WebContents* web_contents, void ResizeWebContents(content::WebContents* web_contents,
const gfx::Size& size); const gfx::Rect& bounds);
#endif // CHROME_BROWSER_UI_WEB_CONTENTS_SIZER_H_ #endif // CHROME_BROWSER_UI_WEB_CONTENTS_SIZER_H_
...@@ -9,13 +9,16 @@ ...@@ -9,13 +9,16 @@
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
void ResizeWebContents(content::WebContents* web_contents, void ResizeWebContents(content::WebContents* web_contents,
const gfx::Size& new_size) { const gfx::Rect& new_bounds) {
NSView* view = web_contents->GetNativeView(); NSView* view = web_contents->GetNativeView();
NSRect old_wcv_frame = [view frame]; NSRect old_wcv_frame = [view frame];
CGFloat new_x = old_wcv_frame.origin.x; CGFloat new_x = old_wcv_frame.origin.x;
CGFloat new_y = CGFloat new_y =
old_wcv_frame.origin.y + (old_wcv_frame.size.height - new_size.height()); old_wcv_frame.origin.y
+ (old_wcv_frame.size.height - new_bounds.size().height());
NSRect new_wcv_frame = NSRect new_wcv_frame =
NSMakeRect(new_x, new_y, new_size.width(), new_size.height()); NSMakeRect(new_x, new_y,
new_bounds.size().width(),
new_bounds.size().height());
[view setFrame:new_wcv_frame]; [view setFrame:new_wcv_frame];
} }
...@@ -114,7 +114,7 @@ void ExtensionSettingsUIBrowserTest::ShrinkWebContentsView() { ...@@ -114,7 +114,7 @@ void ExtensionSettingsUIBrowserTest::ShrinkWebContentsView() {
content::WebContents* web_contents = content::WebContents* web_contents =
browser()->tab_strip_model()->GetActiveWebContents(); browser()->tab_strip_model()->GetActiveWebContents();
CHECK(web_contents); CHECK(web_contents);
ResizeWebContents(web_contents, gfx::Size(400, 400)); ResizeWebContents(web_contents, gfx::Rect(0, 0, 400, 400));
} }
const Extension* ExtensionSettingsUIBrowserTest::InstallUnpackedExtension( const Extension* ExtensionSettingsUIBrowserTest::InstallUnpackedExtension(
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
package org.chromium.chrome.test.util; package org.chromium.chrome.test.util;
import android.graphics.Rect;
import junit.framework.Assert; import junit.framework.Assert;
import org.chromium.base.ThreadUtils; import org.chromium.base.ThreadUtils;
...@@ -92,13 +94,14 @@ public class PrerenderTestHelper { ...@@ -92,13 +94,14 @@ public class PrerenderTestHelper {
@Override @Override
public ExternalPrerenderHandler call() throws Exception { public ExternalPrerenderHandler call() throws Exception {
ExternalPrerenderHandler prerenderHandler = new ExternalPrerenderHandler(); ExternalPrerenderHandler prerenderHandler = new ExternalPrerenderHandler();
boolean didPrerender = prerenderHandler.addPrerender( Rect bounds = new Rect(
currentTab.getProfile(), currentTab.getWebContents(), testUrl, null, 0, 0, currentTab.getContentViewCore().getRenderCoordinates()
currentTab.getContentViewCore().getRenderCoordinates()
.getContentWidthPixInt(), .getContentWidthPixInt(),
currentTab.getContentViewCore().getRenderCoordinates() currentTab.getContentViewCore().getRenderCoordinates()
.getContentHeightPixInt(), .getContentHeightPixInt());
false); boolean didPrerender = prerenderHandler.addPrerender(
currentTab.getProfile(), currentTab.getWebContents(), testUrl, null,
bounds, false);
Assert.assertTrue("Failed to prerender test url: " + testUrl, didPrerender); Assert.assertTrue("Failed to prerender test url: " + testUrl, didPrerender);
return prerenderHandler; return prerenderHandler;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment