Switch global error menu icon to vectorized MD asset
[chromium-blink-merge.git] / mandoline / ui / phone_ui / phone_browser_application_delegate.cc
blobd01ac826cecea7037780add1f9c8c2c21e606251
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/view_manager/public/cpp/view.h"
9 #include "components/view_manager/public/cpp/view_tree_connection.h"
10 #include "components/view_manager/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 content_(nullptr),
26 web_view_(this),
27 default_url_("http://www.google.com/") {
30 PhoneBrowserApplicationDelegate::~PhoneBrowserApplicationDelegate() {
33 ////////////////////////////////////////////////////////////////////////////////
34 // PhoneBrowserApplicationDelegate, mojo::ApplicationDelegate implementation:
36 void PhoneBrowserApplicationDelegate::Initialize(mojo::ApplicationImpl* app) {
37 app_ = app;
39 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
40 for (const auto& arg : command_line->GetArgs()) {
41 GURL url(arg);
42 if (url.is_valid()) {
43 default_url_ = url.spec();
44 break;
47 mojo::CreateSingleViewTreeHost(app_, this, &host_);
50 bool PhoneBrowserApplicationDelegate::ConfigureIncomingConnection(
51 mojo::ApplicationConnection* connection) {
52 connection->AddService<LaunchHandler>(this);
53 return true;
56 ////////////////////////////////////////////////////////////////////////////////
57 // PhoneBrowserApplicationDelegate, LaunchHandler implementation:
59 void PhoneBrowserApplicationDelegate::LaunchURL(const mojo::String& url) {
60 mojo::URLRequestPtr request(mojo::URLRequest::New());
61 request->url = url;
62 web_view_.web_view()->LoadRequest(request.Pass());
65 ////////////////////////////////////////////////////////////////////////////////
66 // PhoneBrowserApplicationDelegate, mojo::ViewTreeDelegate implementation:
68 void PhoneBrowserApplicationDelegate::OnEmbed(mojo::View* root) {
69 root->connection()->SetEmbedRoot();
70 content_ = root->connection()->CreateView();
71 root->AddChild(content_);
72 content_->SetBounds(root->bounds());
73 content_->SetVisible(true);
75 host_->SetSize(mojo::Size::From(gfx::Size(320, 640)));
76 web_view_.Init(app_, content_);
77 LaunchURL(default_url_);
80 void PhoneBrowserApplicationDelegate::OnConnectionLost(
81 mojo::ViewTreeConnection* connection) {
84 ////////////////////////////////////////////////////////////////////////////////
85 // PhoneBrowserApplicationDelegate, mojo::ViewObserver implementation:
87 void PhoneBrowserApplicationDelegate::OnViewBoundsChanged(
88 mojo::View* view,
89 const mojo::Rect& old_bounds,
90 const mojo::Rect& new_bounds) {
91 content_->SetBounds(
92 *mojo::Rect::From(gfx::Rect(0, 0, new_bounds.width, new_bounds.height)));
95 ////////////////////////////////////////////////////////////////////////////////
96 // PhoneBrowserApplicationDelegate,
97 // web_view::mojom::WebViewClient implementation:
99 void PhoneBrowserApplicationDelegate::TopLevelNavigate(
100 mojo::URLRequestPtr request) {
101 web_view_.web_view()->LoadRequest(request.Pass());
104 void PhoneBrowserApplicationDelegate::LoadingStateChanged(bool is_loading) {
105 // ...
108 void PhoneBrowserApplicationDelegate::ProgressChanged(double progress) {
109 // ...
112 void PhoneBrowserApplicationDelegate::TitleChanged(const mojo::String& title) {
113 // ...
116 ////////////////////////////////////////////////////////////////////////////////
117 // PhoneBrowserApplicationDelegate,
118 // mojo::InterfaceFactory<LaunchHandler> implementation:
120 void PhoneBrowserApplicationDelegate::Create(
121 mojo::ApplicationConnection* connection,
122 mojo::InterfaceRequest<LaunchHandler> request) {
123 launch_handler_bindings_.AddBinding(this, request.Pass());
126 } // namespace mandoline