summaryrefslogtreecommitdiffstats
path: root/mandoline
diff options
context:
space:
mode:
authorsky <sky@chromium.org>2015-11-12 08:08:02 -0800
committerCommit bot <commit-bot@chromium.org>2015-11-12 16:09:11 +0000
commit465e17803dc0cd5bd60f772ca6358c0da8a89b7a (patch)
treebac706e799aa8a7b24be3cd804ef97103d49ab9e /mandoline
parent63d398a84ab2d1d6718382b3bc60f0c7d32f3de1 (diff)
downloadchromium_src-465e17803dc0cd5bd60f772ca6358c0da8a89b7a.zip
chromium_src-465e17803dc0cd5bd60f772ca6358c0da8a89b7a.tar.gz
chromium_src-465e17803dc0cd5bd60f772ca6358c0da8a89b7a.tar.bz2
Fix crash in mandoline
BrowserWindow was setting itself as a LayoutManager. BrowserWindow can't do this as View owns it's LayoutManager, leading to double delete. BUG=554579 TEST=none R=ben@chromium.org Review URL: https://codereview.chromium.org/1441533002 Cr-Commit-Position: refs/heads/master@{#359326}
Diffstat (limited to 'mandoline')
-rw-r--r--mandoline/ui/desktop_ui/browser_window.cc88
-rw-r--r--mandoline/ui/desktop_ui/browser_window.h11
2 files changed, 56 insertions, 43 deletions
diff --git a/mandoline/ui/desktop_ui/browser_window.cc b/mandoline/ui/desktop_ui/browser_window.cc
index a78e60e..c049cf2 100644
--- a/mandoline/ui/desktop_ui/browser_window.cc
+++ b/mandoline/ui/desktop_ui/browser_window.cc
@@ -25,6 +25,7 @@
#include "ui/mojo/init/ui_init.h"
#include "ui/views/background.h"
#include "ui/views/controls/button/label_button.h"
+#include "ui/views/layout/layout_manager.h"
#include "ui/views/mus/aura_init.h"
#include "ui/views/mus/display_converter.h"
#include "ui/views/mus/native_widget_mus.h"
@@ -69,6 +70,25 @@ class ProgressView : public views::View {
DISALLOW_COPY_AND_ASSIGN(ProgressView);
};
+class BrowserWindow::LayoutManagerImpl : public views::LayoutManager {
+ public:
+ explicit LayoutManagerImpl(BrowserWindow* window) : window_(window) {}
+ ~LayoutManagerImpl() override {}
+
+ private:
+ // views::LayoutManager:
+ gfx::Size GetPreferredSize(const views::View* view) const override {
+ return gfx::Size();
+ }
+ void Layout(views::View* host) override {
+ window_->Layout(host);
+ }
+
+ BrowserWindow* window_;
+
+ DISALLOW_COPY_AND_ASSIGN(LayoutManagerImpl);
+};
+
////////////////////////////////////////////////////////////////////////////////
// BrowserWindow, public:
@@ -339,42 +359,6 @@ void BrowserWindow::Create(mojo::ApplicationConnection* connection,
}
////////////////////////////////////////////////////////////////////////////////
-// BrowserWindow, views::LayoutManager implementation:
-
-gfx::Size BrowserWindow::GetPreferredSize(const views::View* view) const {
- return gfx::Size();
-}
-
-void BrowserWindow::Layout(views::View* host) {
- // TODO(fsamuel): All bounds should be in physical pixels.
- gfx::Rect bounds_in_physical_pixels(host->bounds());
- float inverse_device_pixel_ratio =
- 1.0f / root_->viewport_metrics().device_pixel_ratio;
-
- gfx::Rect toolbar_bounds = gfx::ScaleToEnclosingRect(
- bounds_in_physical_pixels, inverse_device_pixel_ratio);
- toolbar_bounds.Inset(10, 10, 10, toolbar_bounds.height() - 40);
- toolbar_view_->SetBoundsRect(toolbar_bounds);
-
- find_bar_view_->SetBoundsRect(toolbar_bounds);
-
- gfx::Rect progress_bar_bounds(toolbar_bounds.x(), toolbar_bounds.bottom() + 2,
- toolbar_bounds.width(), 5);
-
- // The content view bounds are in physical pixels.
- gfx::Rect content_bounds(DIPSToPixels(progress_bar_bounds.x()),
- DIPSToPixels(progress_bar_bounds.bottom() + 10), 0,
- 0);
- content_bounds.set_width(DIPSToPixels(progress_bar_bounds.width()));
- content_bounds.set_height(host->bounds().height() - content_bounds.y() -
- DIPSToPixels(10));
- content_->SetBounds(content_bounds);
-
- // The omnibox view bounds are in physical pixels.
- omnibox_view_->SetBounds(bounds_in_physical_pixels);
-}
-
-////////////////////////////////////////////////////////////////////////////////
// BrowserWindow, FindBarDelegate implementation:
void BrowserWindow::OnDoFind(const std::string& find, bool forward) {
@@ -408,7 +392,8 @@ void BrowserWindow::Init(mus::Window* root) {
progress_bar_ = new ProgressView;
widget_delegate->GetContentsView()->AddChildView(toolbar_view_);
widget_delegate->GetContentsView()->AddChildView(progress_bar_);
- widget_delegate->GetContentsView()->SetLayoutManager(this);
+ widget_delegate->GetContentsView()->SetLayoutManager(
+ new LayoutManagerImpl(this));
find_bar_view_ = new FindBarView(this);
widget_delegate->GetContentsView()->AddChildView(find_bar_view_);
@@ -437,4 +422,33 @@ void BrowserWindow::EmbedOmnibox() {
omnibox_view_->MoveToFront();
}
+void BrowserWindow::Layout(views::View* host) {
+ // TODO(fsamuel): All bounds should be in physical pixels.
+ gfx::Rect bounds_in_physical_pixels(host->bounds());
+ float inverse_device_pixel_ratio =
+ 1.0f / root_->viewport_metrics().device_pixel_ratio;
+
+ gfx::Rect toolbar_bounds = gfx::ScaleToEnclosingRect(
+ bounds_in_physical_pixels, inverse_device_pixel_ratio);
+ toolbar_bounds.Inset(10, 10, 10, toolbar_bounds.height() - 40);
+ toolbar_view_->SetBoundsRect(toolbar_bounds);
+
+ find_bar_view_->SetBoundsRect(toolbar_bounds);
+
+ gfx::Rect progress_bar_bounds(toolbar_bounds.x(), toolbar_bounds.bottom() + 2,
+ toolbar_bounds.width(), 5);
+
+ // The content view bounds are in physical pixels.
+ gfx::Rect content_bounds(DIPSToPixels(progress_bar_bounds.x()),
+ DIPSToPixels(progress_bar_bounds.bottom() + 10), 0,
+ 0);
+ content_bounds.set_width(DIPSToPixels(progress_bar_bounds.width()));
+ content_bounds.set_height(host->bounds().height() - content_bounds.y() -
+ DIPSToPixels(10));
+ content_->SetBounds(content_bounds);
+
+ // The omnibox view bounds are in physical pixels.
+ omnibox_view_->SetBounds(bounds_in_physical_pixels);
+}
+
} // namespace mandoline
diff --git a/mandoline/ui/desktop_ui/browser_window.h b/mandoline/ui/desktop_ui/browser_window.h
index 5852f0e..04c5c38 100644
--- a/mandoline/ui/desktop_ui/browser_window.h
+++ b/mandoline/ui/desktop_ui/browser_window.h
@@ -15,7 +15,6 @@
#include "mandoline/ui/desktop_ui/public/interfaces/view_embedder.mojom.h"
#include "mojo/application/public/cpp/interface_factory.h"
#include "mojo/common/weak_binding_set.h"
-#include "ui/views/layout/layout_manager.h"
#include "url/gurl.h"
namespace mojo {
@@ -31,6 +30,7 @@ class UIInit;
namespace views {
class AuraInit;
+class View;
}
namespace mandoline {
@@ -45,7 +45,6 @@ class BrowserWindow : public mus::WindowTreeDelegate,
public web_view::mojom::WebViewClient,
public ViewEmbedder,
public mojo::InterfaceFactory<ViewEmbedder>,
- public views::LayoutManager,
public FindBarDelegate {
public:
BrowserWindow(mojo::ApplicationImpl* app,
@@ -61,6 +60,8 @@ class BrowserWindow : public mus::WindowTreeDelegate,
void GoForward();
private:
+ class LayoutManagerImpl;
+
~BrowserWindow() override;
float DIPSToPixels(float value) const;
@@ -93,10 +94,6 @@ class BrowserWindow : public mus::WindowTreeDelegate,
mojo::InterfaceRequest<ViewEmbedder> request) override;
- // Overridden from views::LayoutManager:
- gfx::Size GetPreferredSize(const views::View* view) const override;
- void Layout(views::View* host) override;
-
// Overridden from FindBarDelegate:
void OnDoFind(const std::string& find, bool forward) override;
void OnHideFindBar() override;
@@ -104,6 +101,8 @@ class BrowserWindow : public mus::WindowTreeDelegate,
void Init(mus::Window* root);
void EmbedOmnibox();
+ void Layout(views::View* host);
+
mojo::ApplicationImpl* app_;
scoped_ptr<ui::mojo::UIInit> ui_init_;
scoped_ptr<views::AuraInit> aura_init_;