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/desktop_ui/browser_manager.h" | 5 #include "mandoline/ui/desktop_ui/browser_manager.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "components/mus/public/cpp/window.h" | 10 #include "components/mus/public/cpp/window.h" |
11 #include "components/mus/public/cpp/window_observer.h" | 11 #include "components/mus/public/cpp/window_observer.h" |
12 #include "mandoline/ui/desktop_ui/browser_window.h" | 12 #include "mandoline/ui/desktop_ui/browser_window.h" |
| 13 #include "mojo/shell/public/cpp/shell.h" |
13 | 14 |
14 namespace mandoline { | 15 namespace mandoline { |
15 | 16 |
16 namespace { | 17 namespace { |
17 | 18 |
18 const char kGoogleURL[] = "http://www.google.com"; | 19 const char kGoogleURL[] = "http://www.google.com"; |
19 | 20 |
20 } // namespace | 21 } // namespace |
21 | 22 |
22 BrowserManager::BrowserManager() | 23 BrowserManager::BrowserManager() |
23 : app_(nullptr), startup_ticks_(base::TimeTicks::Now()) {} | 24 : shell_(nullptr), startup_ticks_(base::TimeTicks::Now()) {} |
24 | 25 |
25 BrowserManager::~BrowserManager() { | 26 BrowserManager::~BrowserManager() { |
26 while (!browsers_.empty()) | 27 while (!browsers_.empty()) |
27 (*browsers_.begin())->Close(); | 28 (*browsers_.begin())->Close(); |
28 DCHECK(browsers_.empty()); | 29 DCHECK(browsers_.empty()); |
29 } | 30 } |
30 | 31 |
31 BrowserWindow* BrowserManager::CreateBrowser(const GURL& default_url) { | 32 BrowserWindow* BrowserManager::CreateBrowser(const GURL& default_url) { |
32 BrowserWindow* browser = new BrowserWindow(app_, host_factory_.get(), this); | 33 BrowserWindow* browser = new BrowserWindow(shell_, host_factory_.get(), this); |
33 browsers_.insert(browser); | 34 browsers_.insert(browser); |
34 browser->LoadURL(default_url); | 35 browser->LoadURL(default_url); |
35 return browser; | 36 return browser; |
36 } | 37 } |
37 | 38 |
38 void BrowserManager::BrowserWindowClosed(BrowserWindow* browser) { | 39 void BrowserManager::BrowserWindowClosed(BrowserWindow* browser) { |
39 DCHECK_GT(browsers_.count(browser), 0u); | 40 DCHECK_GT(browsers_.count(browser), 0u); |
40 browsers_.erase(browser); | 41 browsers_.erase(browser); |
41 if (browsers_.empty()) | 42 if (browsers_.empty()) |
42 app_->Quit(); | 43 shell_->Quit(); |
43 } | 44 } |
44 | 45 |
45 void BrowserManager::LaunchURL(const mojo::String& url) { | 46 void BrowserManager::LaunchURL(const mojo::String& url) { |
46 DCHECK(!browsers_.empty()); | 47 DCHECK(!browsers_.empty()); |
47 // TODO(fsamuel): Create a new Browser once we support multiple browser | 48 // TODO(fsamuel): Create a new Browser once we support multiple browser |
48 // windows. | 49 // windows. |
49 (*browsers_.begin())->LoadURL(GURL(url.get())); | 50 (*browsers_.begin())->LoadURL(GURL(url.get())); |
50 } | 51 } |
51 | 52 |
52 void BrowserManager::Initialize(mojo::ApplicationImpl* app) { | 53 void BrowserManager::Initialize(mojo::Shell* shell, const std::string& url, |
53 app_ = app; | 54 uint32_t id) { |
54 tracing_.Initialize(app); | 55 shell_ = shell; |
| 56 tracing_.Initialize(shell, url); |
55 | 57 |
56 app_->ConnectToService("mojo:mus", &host_factory_); | 58 shell_->ConnectToService("mojo:mus", &host_factory_); |
57 | 59 |
58 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 60 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
59 // Create a Browser for each valid URL in the command line. | 61 // Create a Browser for each valid URL in the command line. |
60 for (const auto& arg : command_line->GetArgs()) { | 62 for (const auto& arg : command_line->GetArgs()) { |
61 GURL url(arg); | 63 GURL url(arg); |
62 if (url.is_valid()) | 64 if (url.is_valid()) |
63 CreateBrowser(url); | 65 CreateBrowser(url); |
64 } | 66 } |
65 // If there were no valid URLs in the command line create a Browser with the | 67 // If there were no valid URLs in the command line create a Browser with the |
66 // default URL. | 68 // default URL. |
67 if (browsers_.empty()) | 69 if (browsers_.empty()) |
68 CreateBrowser(GURL(kGoogleURL)); | 70 CreateBrowser(GURL(kGoogleURL)); |
69 } | 71 } |
70 | 72 |
71 bool BrowserManager::AcceptConnection( | 73 bool BrowserManager::AcceptConnection( |
72 mojo::ApplicationConnection* connection) { | 74 mojo::ApplicationConnection* connection) { |
73 connection->AddService<LaunchHandler>(this); | 75 connection->AddService<LaunchHandler>(this); |
74 return true; | 76 return true; |
75 } | 77 } |
76 | 78 |
77 void BrowserManager::Create(mojo::ApplicationConnection* connection, | 79 void BrowserManager::Create(mojo::ApplicationConnection* connection, |
78 mojo::InterfaceRequest<LaunchHandler> request) { | 80 mojo::InterfaceRequest<LaunchHandler> request) { |
79 launch_handler_bindings_.AddBinding(this, std::move(request)); | 81 launch_handler_bindings_.AddBinding(this, std::move(request)); |
80 } | 82 } |
81 | 83 |
82 } // namespace mandoline | 84 } // namespace mandoline |
OLD | NEW |