Revert of Mandoline UI Process: Update namespaces and file names (patchset #9 id...
[chromium-blink-merge.git] / mandoline / ui / phone_ui / phone_browser_application_delegate.cc
blob93307aad9d51f0956e7db6bd9e79a584bb9fedbc
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 mojo::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, mojo::ViewTreeDelegate implementation:
71 void PhoneBrowserApplicationDelegate::OnEmbed(mojo::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 mojo::ViewTreeConnection* connection) {
89 ////////////////////////////////////////////////////////////////////////////////
90 // PhoneBrowserApplicationDelegate, mojo::ViewObserver implementation:
92 void PhoneBrowserApplicationDelegate::OnViewBoundsChanged(
93 mojo::View* view,
94 const mojo::Rect& old_bounds,
95 const mojo::Rect& new_bounds) {
96 CHECK_EQ(view, root_);
97 content_->SetBounds(
98 *mojo::Rect::From(gfx::Rect(0, 0, new_bounds.width, new_bounds.height)));
101 ////////////////////////////////////////////////////////////////////////////////
102 // PhoneBrowserApplicationDelegate,
103 // web_view::mojom::WebViewClient implementation:
105 void PhoneBrowserApplicationDelegate::TopLevelNavigate(
106 mojo::URLRequestPtr request) {
107 web_view_.web_view()->LoadRequest(request.Pass());
110 void PhoneBrowserApplicationDelegate::LoadingStateChanged(bool is_loading) {
111 // ...
114 void PhoneBrowserApplicationDelegate::ProgressChanged(double progress) {
115 // ...
119 void PhoneBrowserApplicationDelegate::BackForwardChanged(
120 web_view::mojom::ButtonState back_button,
121 web_view::mojom::ButtonState forward_button) {
122 // ...
125 void PhoneBrowserApplicationDelegate::TitleChanged(const mojo::String& title) {
126 // ...
129 ////////////////////////////////////////////////////////////////////////////////
130 // PhoneBrowserApplicationDelegate,
131 // mojo::InterfaceFactory<LaunchHandler> implementation:
133 void PhoneBrowserApplicationDelegate::Create(
134 mojo::ApplicationConnection* connection,
135 mojo::InterfaceRequest<LaunchHandler> request) {
136 launch_handler_bindings_.AddBinding(this, request.Pass());
139 } // namespace mandoline