Commit 6dfe6172 authored by ben's avatar ben Committed by Commit bot

Add a debug view to the browser that allows various navigation features to be used.

Adds a simple Interstitial API.

R=sky@chromium.org

Review-Url: https://codereview.chromium.org/2039613002
Cr-Commit-Position: refs/heads/master@{#397866}
parent e76a92ef
......@@ -13,6 +13,8 @@ source_set("lib") {
sources = [
"browser.cc",
"browser.h",
"debug_view.cc",
"debug_view.h",
]
deps = [
......
......@@ -13,6 +13,7 @@
#include "base/timer/timer.h"
#include "components/mus/public/cpp/window.h"
#include "components/mus/public/cpp/window_tree_client.h"
#include "mash/browser/debug_view.h"
#include "mash/public/interfaces/launchable.mojom.h"
#include "mojo/public/c/system/main.h"
#include "services/navigation/public/interfaces/view.mojom.h"
......@@ -130,8 +131,11 @@ class UI : public views::WidgetDelegateView,
reload_button_(
new views::LabelButton(this, base::ASCIIToUTF16("Reload"))),
prompt_(new views::Textfield),
debug_button_(
new views::LabelButton(this, base::ASCIIToUTF16("DV"))),
throbber_(new Throbber),
progress_bar_(new ProgressBar),
debug_view_(new DebugView),
view_(std::move(view)),
view_client_binding_(this, std::move(request)) {
set_background(views::Background::CreateStandardPanelBackground());
......@@ -143,8 +147,11 @@ class UI : public views::WidgetDelegateView,
AddChildView(forward_button_);
AddChildView(reload_button_);
AddChildView(prompt_);
AddChildView(debug_button_);
AddChildView(throbber_);
AddChildView(progress_bar_);
AddChildView(debug_view_);
debug_view_->set_view(view_.get());
}
~UI() override { browser_->RemoveWindow(GetWidget()); }
......@@ -177,6 +184,8 @@ class UI : public views::WidgetDelegateView,
view_->Stop();
else
view_->Reload(false);
} else if (sender == debug_button_) {
ToggleDebugView();
}
}
......@@ -199,28 +208,43 @@ class UI : public views::WidgetDelegateView,
ps.height()));
ps = prompt_->GetPreferredSize();
int throbber_size = ps.height();
gfx::Size debug_ps = debug_button_->GetPreferredSize();
int prompt_y =
bounds.y() + (reload_button_->bounds().height() - ps.height()) / 2;
int width =
bounds.width() - reload_button_->bounds().right() - ps.height() - 10;
bounds.width() - reload_button_->bounds().right() - throbber_size - 15 -
debug_ps.width();
prompt_->SetBoundsRect(gfx::Rect(reload_button_->bounds().right() + 5,
prompt_y, width, ps.height()));
throbber_->SetBoundsRect(gfx::Rect(prompt_->bounds().right() + 5,
prompt_->bounds().y(), ps.height(),
ps.height()));
debug_button_->SetBoundsRect(
gfx::Rect(prompt_->bounds().right() + 5,
prompt_->bounds().y(), debug_ps.width(), debug_ps.height()));
throbber_->SetBoundsRect(gfx::Rect(debug_button_->bounds().right() + 5,
prompt_->bounds().y(), throbber_size,
throbber_size));
gfx::Rect progress_bar_rect(local_bounds.x(),
back_button_->bounds().bottom() + 5,
local_bounds.width(), 2);
progress_bar_->SetBoundsRect(progress_bar_rect);
int debug_view_height = 0;
if (showing_debug_view_)
debug_view_height = debug_view_->GetPreferredSize().height();
debug_view_->SetBoundsRect(
gfx::Rect(local_bounds.x(), local_bounds.height() - debug_view_height,
local_bounds.width(), debug_view_height));
if (content_area_) {
int x = local_bounds.x();
int y = type_ == Type::POPUP ? 0 : progress_bar_->bounds().bottom();
gfx::Point offset(x, y);
ConvertPointToWidget(this, &offset);
int width = local_bounds.width();
int height = local_bounds.height() - y;
int height = local_bounds.height() - y - debug_view_height;
content_area_->SetBounds(
gfx::Rect(offset.x(), offset.y(), width, height));
}
......@@ -290,6 +314,11 @@ class UI : public views::WidgetDelegateView,
}
void Close() override { GetWidget()->Close(); }
void ToggleDebugView() {
showing_debug_view_ = !showing_debug_view_;
Layout();
}
Browser* browser_;
Type type_;
......@@ -298,17 +327,22 @@ class UI : public views::WidgetDelegateView,
views::LabelButton* forward_button_;
views::LabelButton* reload_button_;
views::Textfield* prompt_;
views::LabelButton* debug_button_;
Throbber* throbber_;
ProgressBar* progress_bar_;
mus::Window* content_area_ = nullptr;
DebugView* debug_view_;
navigation::mojom::ViewPtr view_;
mojo::Binding<navigation::mojom::ViewClient> view_client_binding_;
bool is_loading_ = false;
base::string16 current_title_;
bool showing_debug_view_ = false;
DISALLOW_COPY_AND_ASSIGN(UI);
};
......
// Copyright 2016 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.
#include "mash/browser/debug_view.h"
#include "base/strings/utf_string_conversions.h"
#include "ui/gfx/canvas.h"
#include "ui/views/background.h"
#include "ui/views/controls/button/label_button.h"
#include "ui/views/controls/label.h"
#include "ui/views/controls/textfield/textfield.h"
#include "ui/views/layout/box_layout.h"
#include "ui/views/layout/fill_layout.h"
namespace mash {
namespace browser {
DebugView::DebugView()
: interstitial_container_(new views::View),
interstitial_label_(
new views::Label(base::ASCIIToUTF16("Interstitial: "))),
interstitial_show_(
new views::LabelButton(this, base::ASCIIToUTF16("Show"))),
interstitial_hide_(
new views::LabelButton(this, base::ASCIIToUTF16("Hide"))),
interstitial_content_(new views::Textfield) {
AddChildView(interstitial_container_);
interstitial_container_->AddChildView(interstitial_label_);
interstitial_container_->AddChildView(interstitial_show_);
interstitial_container_->AddChildView(interstitial_hide_);
interstitial_container_->AddChildView(interstitial_content_);
views::BoxLayout* layout =
new views::BoxLayout(views::BoxLayout::kHorizontal, 5, 5, 5);
interstitial_container_->SetLayoutManager(layout);
layout->set_main_axis_alignment(views::BoxLayout::MAIN_AXIS_ALIGNMENT_START);
layout->set_cross_axis_alignment(
views::BoxLayout::CROSS_AXIS_ALIGNMENT_STRETCH);
layout->SetDefaultFlex(0);
layout->SetFlexForView(interstitial_content_, 1);
set_background(views::Background::CreateStandardPanelBackground());
SetLayoutManager(new views::FillLayout);
}
DebugView::~DebugView() {}
gfx::Size DebugView::GetPreferredSize() const {
return interstitial_container_->GetPreferredSize();
}
void DebugView::OnPaint(gfx::Canvas* canvas) {
gfx::Rect stroke_rect = GetLocalBounds();
stroke_rect.set_height(1);
canvas->FillRect(stroke_rect, SK_ColorGRAY);
}
void DebugView::ButtonPressed(views::Button* sender, const ui::Event& event) {
DCHECK(view_);
if (sender == interstitial_show_) {
view_->ShowInterstitial(base::UTF16ToUTF8(interstitial_content_->text()));
} else if (sender == interstitial_hide_) {
view_->HideInterstitial();
}
}
} // namespace browser
} // namespace mash
// Copyright 2016 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.
#ifndef MASH_BROWSER_DEBUG_VIEW_H_
#define MASH_BROWSER_DEBUG_VIEW_H_
#include "services/navigation/public/interfaces/view.mojom.h"
#include "ui/views/controls/button/button.h"
#include "ui/views/view.h"
namespace views {
class Label;
class LabelButton;
class Textfield;
} // namespace views
namespace mash {
namespace browser {
// A panel that shows some controls for compelling the content area of the
// browser to do specific things.
class DebugView : public views::View,
public views::ButtonListener {
public:
DebugView();
~DebugView() override;
DebugView(const DebugView&) = delete;
void operator=(const DebugView&) = delete;
void set_view(navigation::mojom::View* view) { view_ = view; }
gfx::Size GetPreferredSize() const override;
private:
void OnPaint(gfx::Canvas* canvas) override;
void ButtonPressed(views::Button* sender, const ui::Event& event) override;
navigation::mojom::View* view_ = nullptr;
views::View* interstitial_container_;
views::Label* interstitial_label_;
views::LabelButton* interstitial_show_;
views::LabelButton* interstitial_hide_;
views::Textfield* interstitial_content_;
};
} // namespace browser
} // namespace mash
#endif // MASH_BROWSER_DEBUG_VIEW_H_
......@@ -39,4 +39,7 @@ interface View {
// Obtains a Mus WindowTreeClient for the View, so it can be embedded in a
// UI.
GetWindowTreeClient(mus.mojom.WindowTreeClient& client);
ShowInterstitial(string html);
HideInterstitial();
};
......@@ -6,6 +6,8 @@
#include "base/strings/utf_string_conversions.h"
#include "components/mus/public/cpp/window_tree_client.h"
#include "content/public/browser/interstitial_page.h"
#include "content/public/browser/interstitial_page_delegate.h"
#include "content/public/browser/navigation_controller.h"
#include "content/public/browser/web_contents.h"
#include "ui/views/controls/webview/webview.h"
......@@ -14,6 +16,26 @@
#include "url/gurl.h"
namespace navigation {
namespace {
class InterstitialPageDelegate : public content::InterstitialPageDelegate {
public:
explicit InterstitialPageDelegate(const std::string& html) : html_(html) {}
~InterstitialPageDelegate() override {}
InterstitialPageDelegate(const InterstitialPageDelegate&) = delete;
void operator=(const InterstitialPageDelegate&) = delete;
private:
// content::InterstitialPageDelegate:
std::string GetHTMLContents() override {
return html_;
}
const std::string html_;
};
} // namespace
ViewImpl::ViewImpl(shell::Connector* connector,
content::BrowserContext* browser_context,
......@@ -58,6 +80,21 @@ void ViewImpl::GetWindowTreeClient(
new mus::WindowTreeClient(this, nullptr, std::move(request));
}
void ViewImpl::ShowInterstitial(const mojo::String& html) {
content::InterstitialPage* interstitial =
content::InterstitialPage::Create(web_view_->GetWebContents(),
false,
GURL(),
new InterstitialPageDelegate(html));
interstitial->Show();
}
void ViewImpl::HideInterstitial() {
// TODO(beng): this is not quite right.
if (web_view_->GetWebContents()->ShowingInterstitialPage())
web_view_->GetWebContents()->GetInterstitialPage()->Proceed();
}
void ViewImpl::AddNewContents(content::WebContents* source,
content::WebContents* new_contents,
WindowOpenDisposition disposition,
......
......@@ -44,6 +44,8 @@ class ViewImpl : public mojom::View,
void Stop() override;
void GetWindowTreeClient(
mus::mojom::WindowTreeClientRequest request) override;
void ShowInterstitial(const mojo::String& html) override;
void HideInterstitial() override;
// content::WebContentsDelegate:
void AddNewContents(content::WebContents* source,
......
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