OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "mandoline/ui/phone_ui/phone_browser_application_delegate.h" | 5 #include "mandoline/ui/phone_ui/phone_browser_application_delegate.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "components/view_manager/public/cpp/scoped_view_ptr.h" |
8 #include "components/view_manager/public/cpp/view.h" | 9 #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_connection.h" |
10 #include "components/view_manager/public/cpp/view_tree_host_factory.h" | 11 #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_connection.h" |
12 #include "mojo/application/public/cpp/application_impl.h" | 13 #include "mojo/application/public/cpp/application_impl.h" |
13 #include "mojo/converters/geometry/geometry_type_converters.h" | 14 #include "mojo/converters/geometry/geometry_type_converters.h" |
14 #include "mojo/services/network/public/interfaces/url_loader.mojom.h" | 15 #include "mojo/services/network/public/interfaces/url_loader.mojom.h" |
15 #include "ui/gfx/geometry/size.h" | 16 #include "ui/gfx/geometry/size.h" |
16 #include "url/gurl.h" | 17 #include "url/gurl.h" |
17 | 18 |
18 namespace mandoline { | 19 namespace mandoline { |
19 | 20 |
20 //////////////////////////////////////////////////////////////////////////////// | 21 //////////////////////////////////////////////////////////////////////////////// |
21 // PhoneBrowserApplicationDelegate, public: | 22 // PhoneBrowserApplicationDelegate, public: |
22 | 23 |
23 PhoneBrowserApplicationDelegate::PhoneBrowserApplicationDelegate() | 24 PhoneBrowserApplicationDelegate::PhoneBrowserApplicationDelegate() |
24 : app_(nullptr), | 25 : app_(nullptr), |
| 26 root_(nullptr), |
25 content_(nullptr), | 27 content_(nullptr), |
26 web_view_(this), | 28 web_view_(this), |
27 default_url_("http://www.google.com/") { | 29 default_url_("http://www.google.com/") {} |
| 30 |
| 31 PhoneBrowserApplicationDelegate::~PhoneBrowserApplicationDelegate() { |
| 32 if (root_) |
| 33 mojo::ScopedViewPtr::DeleteViewOrViewManager(root_); |
28 } | 34 } |
29 | 35 |
30 PhoneBrowserApplicationDelegate::~PhoneBrowserApplicationDelegate() { | 36 bool PhoneBrowserApplicationDelegate::ShouldLaunchURLOnInitialize() const { |
| 37 return true; |
| 38 } |
| 39 |
| 40 gfx::Size PhoneBrowserApplicationDelegate::GetViewportSize() const { |
| 41 return gfx::Size(320, 640); |
31 } | 42 } |
32 | 43 |
33 //////////////////////////////////////////////////////////////////////////////// | 44 //////////////////////////////////////////////////////////////////////////////// |
34 // PhoneBrowserApplicationDelegate, mojo::ApplicationDelegate implementation: | 45 // PhoneBrowserApplicationDelegate, mojo::ApplicationDelegate implementation: |
35 | 46 |
36 void PhoneBrowserApplicationDelegate::Initialize(mojo::ApplicationImpl* app) { | 47 void PhoneBrowserApplicationDelegate::Initialize(mojo::ApplicationImpl* app) { |
37 app_ = app; | 48 app_ = app; |
38 | 49 |
39 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 50 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
40 for (const auto& arg : command_line->GetArgs()) { | 51 for (const auto& arg : command_line->GetArgs()) { |
41 GURL url(arg); | 52 GURL url(arg); |
42 if (url.is_valid()) { | 53 if (url.is_valid()) { |
43 default_url_ = url.spec(); | 54 default_url_ = url.spec(); |
44 break; | 55 break; |
45 } | 56 } |
46 } | 57 } |
47 mojo::CreateSingleViewTreeHost(app_, this, &host_); | 58 mojo::CreateSingleViewTreeHost(app_, this, &host_); |
48 } | 59 } |
49 | 60 |
50 bool PhoneBrowserApplicationDelegate::ConfigureIncomingConnection( | 61 bool PhoneBrowserApplicationDelegate::ConfigureIncomingConnection( |
51 mojo::ApplicationConnection* connection) { | 62 mojo::ApplicationConnection* connection) { |
52 connection->AddService<LaunchHandler>(this); | 63 connection->AddService<LaunchHandler>(this); |
53 return true; | 64 return true; |
54 } | 65 } |
55 | 66 |
56 //////////////////////////////////////////////////////////////////////////////// | 67 //////////////////////////////////////////////////////////////////////////////// |
57 // PhoneBrowserApplicationDelegate, LaunchHandler implementation: | 68 // PhoneBrowserApplicationDelegate, LaunchHandler implementation: |
58 | 69 |
59 void PhoneBrowserApplicationDelegate::LaunchURL(const mojo::String& url) { | 70 void PhoneBrowserApplicationDelegate::LaunchURL(const mojo::String& url) { |
| 71 if (!web_view_inited_) { |
| 72 web_view_.Init(app_, content_); |
| 73 web_view_inited_ = true; |
| 74 } |
60 mojo::URLRequestPtr request(mojo::URLRequest::New()); | 75 mojo::URLRequestPtr request(mojo::URLRequest::New()); |
61 request->url = url; | 76 request->url = url; |
62 web_view_.web_view()->LoadRequest(request.Pass()); | 77 web_view_.web_view()->LoadRequest(request.Pass()); |
63 } | 78 } |
64 | 79 |
65 //////////////////////////////////////////////////////////////////////////////// | 80 //////////////////////////////////////////////////////////////////////////////// |
66 // PhoneBrowserApplicationDelegate, mojo::ViewTreeDelegate implementation: | 81 // PhoneBrowserApplicationDelegate, mojo::ViewTreeDelegate implementation: |
67 | 82 |
68 void PhoneBrowserApplicationDelegate::OnEmbed(mojo::View* root) { | 83 void PhoneBrowserApplicationDelegate::OnEmbed(mojo::View* root) { |
69 root->connection()->SetEmbedRoot(); | 84 root->connection()->SetEmbedRoot(); |
70 content_ = root->connection()->CreateView(); | 85 content_ = root->connection()->CreateView(); |
71 root->AddChild(content_); | 86 root->AddChild(content_); |
| 87 root_ = root; |
72 content_->SetBounds(root->bounds()); | 88 content_->SetBounds(root->bounds()); |
73 content_->SetVisible(true); | 89 content_->SetVisible(true); |
74 | 90 |
75 host_->SetSize(mojo::Size::From(gfx::Size(320, 640))); | 91 host_->SetSize(mojo::Size::From(GetViewportSize())); |
76 web_view_.Init(app_, content_); | 92 if (ShouldLaunchURLOnInitialize()) |
77 LaunchURL(default_url_); | 93 LaunchURL(default_url_); |
78 } | 94 } |
79 | 95 |
80 void PhoneBrowserApplicationDelegate::OnConnectionLost( | 96 void PhoneBrowserApplicationDelegate::OnConnectionLost( |
81 mojo::ViewTreeConnection* connection) { | 97 mojo::ViewTreeConnection* connection) { |
| 98 root_ = nullptr; |
| 99 app_->Quit(); |
82 } | 100 } |
83 | 101 |
84 //////////////////////////////////////////////////////////////////////////////// | 102 //////////////////////////////////////////////////////////////////////////////// |
85 // PhoneBrowserApplicationDelegate, mojo::ViewObserver implementation: | 103 // PhoneBrowserApplicationDelegate, mojo::ViewObserver implementation: |
86 | 104 |
87 void PhoneBrowserApplicationDelegate::OnViewBoundsChanged( | 105 void PhoneBrowserApplicationDelegate::OnViewBoundsChanged( |
88 mojo::View* view, | 106 mojo::View* view, |
89 const mojo::Rect& old_bounds, | 107 const mojo::Rect& old_bounds, |
90 const mojo::Rect& new_bounds) { | 108 const mojo::Rect& new_bounds) { |
91 content_->SetBounds( | 109 content_->SetBounds( |
(...skipping 25 matching lines...) Expand all Loading... |
117 // PhoneBrowserApplicationDelegate, | 135 // PhoneBrowserApplicationDelegate, |
118 // mojo::InterfaceFactory<LaunchHandler> implementation: | 136 // mojo::InterfaceFactory<LaunchHandler> implementation: |
119 | 137 |
120 void PhoneBrowserApplicationDelegate::Create( | 138 void PhoneBrowserApplicationDelegate::Create( |
121 mojo::ApplicationConnection* connection, | 139 mojo::ApplicationConnection* connection, |
122 mojo::InterfaceRequest<LaunchHandler> request) { | 140 mojo::InterfaceRequest<LaunchHandler> request) { |
123 launch_handler_bindings_.AddBinding(this, request.Pass()); | 141 launch_handler_bindings_.AddBinding(this, request.Pass()); |
124 } | 142 } |
125 | 143 |
126 } // namespace mandoline | 144 } // namespace mandoline |
OLD | NEW |