| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "mash/browser/browser.h" | 5 #include "mash/browser/browser.h" |
| 6 | 6 |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 9 #include "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 839 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 850 ProgressBar* progress_bar_; | 850 ProgressBar* progress_bar_; |
| 851 | 851 |
| 852 aura::Window* content_area_ = nullptr; | 852 aura::Window* content_area_ = nullptr; |
| 853 | 853 |
| 854 DebugView* debug_view_; | 854 DebugView* debug_view_; |
| 855 bool showing_debug_view_ = false; | 855 bool showing_debug_view_ = false; |
| 856 | 856 |
| 857 DISALLOW_COPY_AND_ASSIGN(UI); | 857 DISALLOW_COPY_AND_ASSIGN(UI); |
| 858 }; | 858 }; |
| 859 | 859 |
| 860 Browser::Browser() {} | 860 Browser::Browser() { |
| 861 registry_.AddInterface<mojom::Launchable>(this); |
| 862 } |
| 861 Browser::~Browser() {} | 863 Browser::~Browser() {} |
| 862 | 864 |
| 863 void Browser::AddWindow(views::Widget* window) { | 865 void Browser::AddWindow(views::Widget* window) { |
| 864 windows_.push_back(window); | 866 windows_.push_back(window); |
| 865 } | 867 } |
| 866 | 868 |
| 867 void Browser::RemoveWindow(views::Widget* window) { | 869 void Browser::RemoveWindow(views::Widget* window) { |
| 868 auto it = std::find(windows_.begin(), windows_.end(), window); | 870 auto it = std::find(windows_.begin(), windows_.end(), window); |
| 869 DCHECK(it != windows_.end()); | 871 DCHECK(it != windows_.end()); |
| 870 windows_.erase(it); | 872 windows_.erase(it); |
| 871 if (windows_.empty()) | 873 if (windows_.empty()) |
| 872 base::MessageLoop::current()->QuitWhenIdle(); | 874 base::MessageLoop::current()->QuitWhenIdle(); |
| 873 } | 875 } |
| 874 | 876 |
| 875 std::unique_ptr<navigation::View> Browser::CreateView() { | 877 std::unique_ptr<navigation::View> Browser::CreateView() { |
| 876 navigation::mojom::ViewFactoryPtr factory; | 878 navigation::mojom::ViewFactoryPtr factory; |
| 877 context()->connector()->BindInterface(content::mojom::kBrowserServiceName, | 879 context()->connector()->BindInterface(content::mojom::kBrowserServiceName, |
| 878 &factory); | 880 &factory); |
| 879 return base::MakeUnique<navigation::View>(std::move(factory)); | 881 return base::MakeUnique<navigation::View>(std::move(factory)); |
| 880 } | 882 } |
| 881 | 883 |
| 882 void Browser::OnStart() { | 884 void Browser::OnStart() { |
| 883 tracing_.Initialize(context()->connector(), context()->identity().name()); | 885 tracing_.Initialize(context()->connector(), context()->identity().name()); |
| 884 | 886 |
| 885 aura_init_ = base::MakeUnique<views::AuraInit>( | 887 aura_init_ = base::MakeUnique<views::AuraInit>( |
| 886 context()->connector(), context()->identity(), "views_mus_resources.pak", | 888 context()->connector(), context()->identity(), "views_mus_resources.pak", |
| 887 std::string(), nullptr, views::AuraInit::Mode::AURA_MUS); | 889 std::string(), nullptr, views::AuraInit::Mode::AURA_MUS); |
| 888 } | 890 } |
| 889 | 891 |
| 890 bool Browser::OnConnect(const service_manager::ServiceInfo& remote_info, | 892 void Browser::OnBindInterface(const service_manager::ServiceInfo& source_info, |
| 891 service_manager::InterfaceRegistry* registry) { | 893 const std::string& interface_name, |
| 892 registry->AddInterface<mojom::Launchable>(this); | 894 mojo::ScopedMessagePipeHandle interface_pipe) { |
| 893 return true; | 895 registry_.BindInterface(source_info.identity, interface_name, |
| 896 std::move(interface_pipe)); |
| 894 } | 897 } |
| 895 | 898 |
| 896 void Browser::Launch(uint32_t what, mojom::LaunchMode how) { | 899 void Browser::Launch(uint32_t what, mojom::LaunchMode how) { |
| 897 bool reuse = | 900 bool reuse = |
| 898 how == mojom::LaunchMode::REUSE || how == mojom::LaunchMode::DEFAULT; | 901 how == mojom::LaunchMode::REUSE || how == mojom::LaunchMode::DEFAULT; |
| 899 if (reuse && !windows_.empty()) { | 902 if (reuse && !windows_.empty()) { |
| 900 windows_.back()->Activate(); | 903 windows_.back()->Activate(); |
| 901 return; | 904 return; |
| 902 } | 905 } |
| 903 | 906 |
| 904 UI* ui = new UI(this, UI::Type::WINDOW, CreateView()); | 907 UI* ui = new UI(this, UI::Type::WINDOW, CreateView()); |
| 905 views::Widget* window = views::Widget::CreateWindowWithContextAndBounds( | 908 views::Widget* window = views::Widget::CreateWindowWithContextAndBounds( |
| 906 ui, nullptr, gfx::Rect(10, 10, 1024, 600)); | 909 ui, nullptr, gfx::Rect(10, 10, 1024, 600)); |
| 907 ui->NavigateTo(GURL("http://www.google.com/")); | 910 ui->NavigateTo(GURL("http://www.google.com/")); |
| 908 window->Show(); | 911 window->Show(); |
| 909 AddWindow(window); | 912 AddWindow(window); |
| 910 } | 913 } |
| 911 | 914 |
| 912 void Browser::Create(const service_manager::Identity& remote_identity, | 915 void Browser::Create(const service_manager::Identity& remote_identity, |
| 913 mojom::LaunchableRequest request) { | 916 mojom::LaunchableRequest request) { |
| 914 bindings_.AddBinding(this, std::move(request)); | 917 bindings_.AddBinding(this, std::move(request)); |
| 915 } | 918 } |
| 916 | 919 |
| 917 } // namespace browser | 920 } // namespace browser |
| 918 } // namespace mash | 921 } // namespace mash |
| OLD | NEW |