summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpaulmeyer <paulmeyer@chromium.org>2015-01-09 16:02:45 -0800
committerCommit bot <commit-bot@chromium.org>2015-01-10 00:03:41 +0000
commit0968abadbaea59e07d039aa18bf909d01234c33c (patch)
tree7f5fcfba6f098e6520b82feafc7e9eea818f9bc2
parenta58d784e61cb8da9dd9bf684c8c606d82070c5f6 (diff)
downloadchromium_src-0968abadbaea59e07d039aa18bf909d01234c33c.zip
chromium_src-0968abadbaea59e07d039aa18bf909d01234c33c.tar.gz
chromium_src-0968abadbaea59e07d039aa18bf909d01234c33c.tar.bz2
Moved resizing of a guest view out of BrowserPluginGuest and into GuestViewBase. To facilitate this, a new base class, "GuestSizer", was created for BrowserPluginGuest that exposes an interface for external resizing. This change will allow a guest view to be resized explicitly, without autosize being the only sizing option. This new functionality will be introduced in a subsequent CL.
BUG=434226 Review URL: https://codereview.chromium.org/806703005 Cr-Commit-Position: refs/heads/master@{#310900}
-rw-r--r--content/browser/browser_plugin/browser_plugin_guest.cc13
-rw-r--r--content/browser/browser_plugin/browser_plugin_guest.h7
-rw-r--r--content/public/browser/browser_plugin_guest_delegate.h7
-rw-r--r--content/public/browser/guest_sizer.h27
-rw-r--r--extensions/browser/guest_view/guest_view_base.cc18
-rw-r--r--extensions/browser/guest_view/guest_view_base.h8
6 files changed, 66 insertions, 14 deletions
diff --git a/content/browser/browser_plugin/browser_plugin_guest.cc b/content/browser/browser_plugin/browser_plugin_guest.cc
index 4a1fc2d..16a4473 100644
--- a/content/browser/browser_plugin/browser_plugin_guest.cc
+++ b/content/browser/browser_plugin/browser_plugin_guest.cc
@@ -31,6 +31,7 @@
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_plugin_guest_manager.h"
#include "content/public/browser/content_browser_client.h"
+#include "content/public/browser/guest_sizer.h"
#include "content/public/browser/render_widget_host_view.h"
#include "content/public/browser/user_metrics.h"
#include "content/public/browser/web_contents_observer.h"
@@ -98,6 +99,11 @@ BrowserPluginGuest::BrowserPluginGuest(bool has_render_view,
web_contents->SetBrowserPluginGuest(this);
delegate->RegisterDestructionCallback(
base::Bind(&BrowserPluginGuest::WillDestroy, AsWeakPtr()));
+ delegate->SetGuestSizer(this);
+}
+
+void BrowserPluginGuest::SizeContents(const gfx::Size& new_size) {
+ GetWebContents()->GetView()->SizeContents(new_size);
}
void BrowserPluginGuest::Init() {
@@ -732,14 +738,11 @@ void BrowserPluginGuest::OnResizeGuest(
}
if (last_seen_browser_plugin_size_ != params.view_size) {
- delegate_->ElementSizeChanged(last_seen_browser_plugin_size_,
- params.view_size);
+ delegate_->ElementSizeChanged(params.view_size);
last_seen_browser_plugin_size_ = params.view_size;
}
- // Just resize the WebContents and repaint if needed.
- if (!params.view_size.IsEmpty())
- GetWebContents()->GetView()->SizeContents(params.view_size);
+ // Just repaint the WebContents if needed.
if (params.repaint)
Send(new ViewMsg_Repaint(routing_id(), params.view_size));
}
diff --git a/content/browser/browser_plugin/browser_plugin_guest.h b/content/browser/browser_plugin/browser_plugin_guest.h
index 185547a..176b41e 100644
--- a/content/browser/browser_plugin/browser_plugin_guest.h
+++ b/content/browser/browser_plugin/browser_plugin_guest.h
@@ -38,6 +38,7 @@
#include "ui/base/ime/text_input_type.h"
#include "ui/gfx/geometry/rect.h"
+class GuestSizer;
class SkBitmap;
struct BrowserPluginHostMsg_Attach_Params;
struct BrowserPluginHostMsg_ResizeGuest_Params;
@@ -80,7 +81,8 @@ struct DropData;
// A BrowserPluginGuest can also create a new unattached guest via
// CreateNewWindow. The newly created guest will live in the same partition,
// which means it can share storage and can script this guest.
-class CONTENT_EXPORT BrowserPluginGuest : public WebContentsObserver {
+class CONTENT_EXPORT BrowserPluginGuest : public GuestSizer,
+ public WebContentsObserver {
public:
~BrowserPluginGuest() override;
@@ -166,6 +168,9 @@ class CONTENT_EXPORT BrowserPluginGuest : public WebContentsObserver {
bool OnMessageReceived(const IPC::Message& message,
RenderFrameHost* render_frame_host) override;
+ // GuestSizer implementation.
+ void SizeContents(const gfx::Size& new_size) override;
+
// Exposes the protected web_contents() from WebContentsObserver.
WebContentsImpl* GetWebContents() const;
diff --git a/content/public/browser/browser_plugin_guest_delegate.h b/content/public/browser/browser_plugin_guest_delegate.h
index dd26215..8c8a10c 100644
--- a/content/public/browser/browser_plugin_guest_delegate.h
+++ b/content/public/browser/browser_plugin_guest_delegate.h
@@ -8,6 +8,7 @@
#include "base/callback_forward.h"
#include "base/process/kill.h"
#include "content/common/content_export.h"
+#include "content/public/browser/guest_sizer.h"
#include "content/public/browser/web_contents.h"
namespace base {
@@ -51,8 +52,7 @@ class CONTENT_EXPORT BrowserPluginGuestDelegate {
virtual void DidDetach() {}
// Notification that the BrowserPlugin has resized.
- virtual void ElementSizeChanged(const gfx::Size& old_size,
- const gfx::Size& new_size) {}
+ virtual void ElementSizeChanged(const gfx::Size& size) {}
// Returns the WebContents that currently owns this guest.
virtual WebContents* GetOwnerWebContents() const;
@@ -81,6 +81,9 @@ class CONTENT_EXPORT BrowserPluginGuestDelegate {
virtual bool Find(int request_id,
const base::string16& search_text,
const blink::WebFindOptions& options);
+
+ // Provides the delegate with an interface with which to size the guest.
+ virtual void SetGuestSizer(GuestSizer* guest_sizer) {}
};
} // namespace content
diff --git a/content/public/browser/guest_sizer.h b/content/public/browser/guest_sizer.h
new file mode 100644
index 0000000..d8e240b
--- /dev/null
+++ b/content/public/browser/guest_sizer.h
@@ -0,0 +1,27 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// This module provides class that serves as a public interface for a
+// derived object that can size a guest.
+
+// This class currently only serves as a base class for BrowserPluginGuest, and
+// its API can only be accessed by a BrowserPluginGuestDelegate. This module
+// will go away once the migration to RenderFrame architecture has completed
+// (http://crbug.com/330264).
+
+#ifndef CONTENT_PUBLIC_BROWSER_GUEST_SIZER_H_
+#define CONTENT_PUBLIC_BROWSER_GUEST_SIZER_H_
+
+#include "ui/gfx/geometry/size.h"
+
+namespace content {
+
+class GuestSizer {
+ public:
+ virtual void SizeContents(const gfx::Size& new_size) = 0;
+};
+
+} // namespace content
+
+#endif // CONTENT_PUBLIC_BROWSER_GUEST_SIZER_H_
diff --git a/extensions/browser/guest_view/guest_view_base.cc b/extensions/browser/guest_view/guest_view_base.cc
index 6f6befdf..88592d5 100644
--- a/extensions/browser/guest_view/guest_view_base.cc
+++ b/extensions/browser/guest_view/guest_view_base.cc
@@ -146,6 +146,7 @@ GuestViewBase::GuestViewBase(content::BrowserContext* browser_context,
element_instance_id_(guestview::kInstanceIDNone),
initialized_(false),
is_being_destroyed_(false),
+ guest_sizer_(nullptr),
auto_size_enabled_(false),
is_full_page_plugin_(false),
weak_ptr_factory_(this) {
@@ -340,9 +341,12 @@ void GuestViewBase::DidDetach() {
element_instance_id_ = guestview::kInstanceIDNone;
}
-void GuestViewBase::ElementSizeChanged(const gfx::Size& old_size,
- const gfx::Size& new_size) {
- element_size_ = new_size;
+void GuestViewBase::ElementSizeChanged(const gfx::Size& size) {
+ element_size_ = size;
+
+ // Only resize if needed.
+ if (!size.IsEmpty())
+ guest_sizer_->SizeContents(size);
}
WebContents* GuestViewBase::GetOwnerWebContents() const {
@@ -367,11 +371,13 @@ void GuestViewBase::Destroy() {
is_being_destroyed_ = true;
+ guest_sizer_ = nullptr;
+
// It is important to clear owner_web_contents_ after the call to
// StopTrackingEmbedderZoomLevel(), but before the rest of
// the statements in this function.
StopTrackingEmbedderZoomLevel();
- owner_web_contents_ = NULL;
+ owner_web_contents_ = nullptr;
DCHECK(web_contents());
@@ -417,6 +423,10 @@ void GuestViewBase::RegisterDestructionCallback(
destruction_callback_ = callback;
}
+void GuestViewBase::SetGuestSizer(content::GuestSizer* guest_sizer) {
+ guest_sizer_ = guest_sizer;
+}
+
void GuestViewBase::WillAttach(content::WebContents* embedder_web_contents,
int element_instance_id,
bool is_full_page_plugin) {
diff --git a/extensions/browser/guest_view/guest_view_base.h b/extensions/browser/guest_view/guest_view_base.h
index 7179c69..e03a9e2 100644
--- a/extensions/browser/guest_view/guest_view_base.h
+++ b/extensions/browser/guest_view/guest_view_base.h
@@ -11,6 +11,7 @@
#include "base/values.h"
#include "components/ui/zoom/zoom_observer.h"
#include "content/public/browser/browser_plugin_guest_delegate.h"
+#include "content/public/browser/guest_sizer.h"
#include "content/public/browser/render_process_host_observer.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_delegate.h"
@@ -252,12 +253,12 @@ class GuestViewBase : public content::BrowserPluginGuestDelegate,
// BrowserPluginGuestDelegate implementation.
void DidAttach(int guest_proxy_routing_id) final;
void DidDetach() final;
- void ElementSizeChanged(const gfx::Size& old_size,
- const gfx::Size& new_size) final;
+ void ElementSizeChanged(const gfx::Size& size) final;
content::WebContents* GetOwnerWebContents() const final;
void GuestSizeChanged(const gfx::Size& old_size,
const gfx::Size& new_size) final;
void RegisterDestructionCallback(const DestructionCallback& callback) final;
+ void SetGuestSizer(content::GuestSizer* guest_sizer) final;
void WillAttach(content::WebContents* embedder_web_contents,
int browser_plugin_instance_id,
bool is_full_page_plugin) final;
@@ -365,6 +366,9 @@ class GuestViewBase : public content::BrowserPluginGuestDelegate,
// element may not match the size of the guest.
gfx::Size guest_size_;
+ // A pointer to the guest_sizer.
+ content::GuestSizer* guest_sizer_;
+
// Indicates whether autosize mode is enabled or not.
bool auto_size_enabled_;