Index: mandoline/ui/phone_ui/phone_browser_application_delegate.cc |
diff --git a/mandoline/ui/phone_ui/phone_browser_application_delegate.cc b/mandoline/ui/phone_ui/phone_browser_application_delegate.cc |
index d01ac826cecea7037780add1f9c8c2c21e606251..3cceb51e6b35d4d6326b3f2f955f97a3090aa63f 100644 |
--- a/mandoline/ui/phone_ui/phone_browser_application_delegate.cc |
+++ b/mandoline/ui/phone_ui/phone_browser_application_delegate.cc |
@@ -5,6 +5,7 @@ |
#include "mandoline/ui/phone_ui/phone_browser_application_delegate.h" |
#include "base/command_line.h" |
+#include "components/view_manager/public/cpp/scoped_view_ptr.h" |
#include "components/view_manager/public/cpp/view.h" |
#include "components/view_manager/public/cpp/view_tree_connection.h" |
#include "components/view_manager/public/cpp/view_tree_host_factory.h" |
@@ -22,12 +23,22 @@ namespace mandoline { |
PhoneBrowserApplicationDelegate::PhoneBrowserApplicationDelegate() |
: app_(nullptr), |
+ root_(nullptr), |
content_(nullptr), |
web_view_(this), |
- default_url_("http://www.google.com/") { |
-} |
+ default_url_("http://www.google.com/") {} |
PhoneBrowserApplicationDelegate::~PhoneBrowserApplicationDelegate() { |
+ if (root_) |
+ mojo::ScopedViewPtr::DeleteViewOrViewManager(root_); |
+} |
+ |
+bool PhoneBrowserApplicationDelegate::ShouldLaunchURLOnInitialize() const { |
+ return true; |
+} |
+ |
+gfx::Size PhoneBrowserApplicationDelegate::GetViewportSize() const { |
+ return gfx::Size(320, 640); |
} |
//////////////////////////////////////////////////////////////////////////////// |
@@ -57,6 +68,10 @@ bool PhoneBrowserApplicationDelegate::ConfigureIncomingConnection( |
// PhoneBrowserApplicationDelegate, LaunchHandler implementation: |
void PhoneBrowserApplicationDelegate::LaunchURL(const mojo::String& url) { |
+ if (!web_view_inited_) { |
+ web_view_.Init(app_, content_); |
+ web_view_inited_ = true; |
+ } |
mojo::URLRequestPtr request(mojo::URLRequest::New()); |
request->url = url; |
web_view_.web_view()->LoadRequest(request.Pass()); |
@@ -69,16 +84,19 @@ void PhoneBrowserApplicationDelegate::OnEmbed(mojo::View* root) { |
root->connection()->SetEmbedRoot(); |
content_ = root->connection()->CreateView(); |
root->AddChild(content_); |
+ root_ = root; |
content_->SetBounds(root->bounds()); |
content_->SetVisible(true); |
- host_->SetSize(mojo::Size::From(gfx::Size(320, 640))); |
- web_view_.Init(app_, content_); |
- LaunchURL(default_url_); |
+ host_->SetSize(mojo::Size::From(GetViewportSize())); |
+ if (ShouldLaunchURLOnInitialize()) |
+ LaunchURL(default_url_); |
} |
void PhoneBrowserApplicationDelegate::OnConnectionLost( |
mojo::ViewTreeConnection* connection) { |
+ root_ = nullptr; |
+ app_->Quit(); |
} |
//////////////////////////////////////////////////////////////////////////////// |