Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / mandoline / ui / phone_ui / phone_browser_application_delegate.cc
blob616f0a78a8a28af870f6976377834b55eee89580
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "mandoline/ui/phone_ui/phone_browser_application_delegate.h"
7 #include "base/command_line.h"
8 #include "components/mus/public/cpp/view.h"
9 #include "components/mus/public/cpp/view_tree_connection.h"
10 #include "components/mus/public/cpp/view_tree_host_factory.h"
11 #include "mojo/application/public/cpp/application_connection.h"
12 #include "mojo/application/public/cpp/application_impl.h"
13 #include "mojo/converters/geometry/geometry_type_converters.h"
14 #include "mojo/services/network/public/interfaces/url_loader.mojom.h"
15 #include "ui/gfx/geometry/size.h"
16 #include "url/gurl.h"
18 namespace mandoline {
20 ////////////////////////////////////////////////////////////////////////////////
21 // PhoneBrowserApplicationDelegate, public:
23 PhoneBrowserApplicationDelegate::PhoneBrowserApplicationDelegate()
24 : app_(nullptr),
25 root_(nullptr),
26 content_(nullptr),
27 web_view_(this),
28 default_url_("http://www.google.com/") {
31 PhoneBrowserApplicationDelegate::~PhoneBrowserApplicationDelegate() {
32 if (root_)
33 root_->RemoveObserver(this);
36 ////////////////////////////////////////////////////////////////////////////////
37 // PhoneBrowserApplicationDelegate, mojo::ApplicationDelegate implementation:
39 void PhoneBrowserApplicationDelegate::Initialize(mojo::ApplicationImpl* app) {
40 app_ = app;
42 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
43 for (const auto& arg : command_line->GetArgs()) {
44 GURL url(arg);
45 if (url.is_valid()) {
46 default_url_ = url.spec();
47 break;
50 mus::CreateSingleViewTreeHost(app_, this, &host_);
53 bool PhoneBrowserApplicationDelegate::ConfigureIncomingConnection(
54 mojo::ApplicationConnection* connection) {
55 connection->AddService<LaunchHandler>(this);
56 return true;
59 ////////////////////////////////////////////////////////////////////////////////
60 // PhoneBrowserApplicationDelegate, LaunchHandler implementation:
62 void PhoneBrowserApplicationDelegate::LaunchURL(const mojo::String& url) {
63 mojo::URLRequestPtr request(mojo::URLRequest::New());
64 request->url = url;
65 web_view_.web_view()->LoadRequest(request.Pass());
68 ////////////////////////////////////////////////////////////////////////////////
69 // PhoneBrowserApplicationDelegate, mus::ViewTreeDelegate implementation:
71 void PhoneBrowserApplicationDelegate::OnEmbed(mus::View* root) {
72 CHECK(!root_);
73 root_ = root;
74 content_ = root->connection()->CreateView();
75 root->AddChild(content_);
76 content_->SetBounds(root->bounds());
77 content_->SetVisible(true);
78 root->AddObserver(this);
80 host_->SetSize(mojo::Size::From(gfx::Size(320, 640)));
81 web_view_.Init(app_, content_);
82 LaunchURL(default_url_);
85 void PhoneBrowserApplicationDelegate::OnConnectionLost(
86 mus::ViewTreeConnection* connection) {}
88 ////////////////////////////////////////////////////////////////////////////////
89 // PhoneBrowserApplicationDelegate, mus::ViewObserver implementation:
91 void PhoneBrowserApplicationDelegate::OnViewBoundsChanged(
92 mus::View* view,
93 const mojo::Rect& old_bounds,
94 const mojo::Rect& new_bounds) {
95 CHECK_EQ(view, root_);
96 content_->SetBounds(
97 *mojo::Rect::From(gfx::Rect(0, 0, new_bounds.width, new_bounds.height)));
100 ////////////////////////////////////////////////////////////////////////////////
101 // PhoneBrowserApplicationDelegate,
102 // web_view::mojom::WebViewClient implementation:
104 void PhoneBrowserApplicationDelegate::TopLevelNavigate(
105 mojo::URLRequestPtr request) {
106 web_view_.web_view()->LoadRequest(request.Pass());
109 void PhoneBrowserApplicationDelegate::LoadingStateChanged(bool is_loading,
110 double progress) {}
112 void PhoneBrowserApplicationDelegate::BackForwardChanged(
113 web_view::mojom::ButtonState back_button,
114 web_view::mojom::ButtonState forward_button) {
115 // ...
118 void PhoneBrowserApplicationDelegate::TitleChanged(const mojo::String& title) {
119 // ...
122 ////////////////////////////////////////////////////////////////////////////////
123 // PhoneBrowserApplicationDelegate,
124 // mojo::InterfaceFactory<LaunchHandler> implementation:
126 void PhoneBrowserApplicationDelegate::Create(
127 mojo::ApplicationConnection* connection,
128 mojo::InterfaceRequest<LaunchHandler> request) {
129 launch_handler_bindings_.AddBinding(this, request.Pass());
132 } // namespace mandoline