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"
20 ////////////////////////////////////////////////////////////////////////////////
21 // PhoneBrowserApplicationDelegate, public:
23 PhoneBrowserApplicationDelegate::PhoneBrowserApplicationDelegate()
28 default_url_("http://www.google.com/") {
31 PhoneBrowserApplicationDelegate::~PhoneBrowserApplicationDelegate() {
33 root_
->RemoveObserver(this);
36 ////////////////////////////////////////////////////////////////////////////////
37 // PhoneBrowserApplicationDelegate, mojo::ApplicationDelegate implementation:
39 void PhoneBrowserApplicationDelegate::Initialize(mojo::ApplicationImpl
* app
) {
42 base::CommandLine
* command_line
= base::CommandLine::ForCurrentProcess();
43 for (const auto& arg
: command_line
->GetArgs()) {
46 default_url_
= url
.spec();
50 mus::CreateSingleViewTreeHost(app_
, this, &host_
);
53 bool PhoneBrowserApplicationDelegate::ConfigureIncomingConnection(
54 mojo::ApplicationConnection
* connection
) {
55 connection
->AddService
<LaunchHandler
>(this);
59 ////////////////////////////////////////////////////////////////////////////////
60 // PhoneBrowserApplicationDelegate, LaunchHandler implementation:
62 void PhoneBrowserApplicationDelegate::LaunchURL(const mojo::String
& url
) {
63 mojo::URLRequestPtr
request(mojo::URLRequest::New());
65 web_view_
.web_view()->LoadRequest(request
.Pass());
68 ////////////////////////////////////////////////////////////////////////////////
69 // PhoneBrowserApplicationDelegate, mus::ViewTreeDelegate implementation:
71 void PhoneBrowserApplicationDelegate::OnEmbed(mus::View
* 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(
93 const mojo::Rect
& old_bounds
,
94 const mojo::Rect
& new_bounds
) {
95 CHECK_EQ(view
, root_
);
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
,
112 void PhoneBrowserApplicationDelegate::BackForwardChanged(
113 web_view::mojom::ButtonState back_button
,
114 web_view::mojom::ButtonState forward_button
) {
118 void PhoneBrowserApplicationDelegate::TitleChanged(const mojo::String
& title
) {
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