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/desktop_ui/browser_manager.h"
7 #include "base/command_line.h"
8 #include "components/mus/public/cpp/view.h"
9 #include "components/mus/public/cpp/view_observer.h"
10 #include "mandoline/ui/desktop_ui/browser_window.h"
16 const char kGoogleURL
[] = "http://www.google.com";
20 BrowserManager::BrowserManager()
21 : app_(nullptr), startup_time_(base::Time::Now()) {}
23 BrowserManager::~BrowserManager() {
24 DCHECK(browsers_
.empty());
27 BrowserWindow
* BrowserManager::CreateBrowser(const GURL
& default_url
) {
28 BrowserWindow
* browser
= new BrowserWindow(app_
, host_factory_
.get(), this);
29 browsers_
.insert(browser
);
30 browser
->LoadURL(default_url
);
34 void BrowserManager::BrowserWindowClosed(BrowserWindow
* browser
) {
35 DCHECK_GT(browsers_
.count(browser
), 0u);
36 browsers_
.erase(browser
);
37 if (browsers_
.empty())
41 void BrowserManager::LaunchURL(const mojo::String
& url
) {
42 DCHECK(!browsers_
.empty());
43 // TODO(fsamuel): Create a new Browser once we support multiple browser
45 (*browsers_
.begin())->LoadURL(GURL(url
));
48 void BrowserManager::Initialize(mojo::ApplicationImpl
* app
) {
51 mojo::URLRequestPtr
request(mojo::URLRequest::New());
52 request
->url
= "mojo:mus";
53 app_
->ConnectToService(request
.Pass(), &host_factory_
);
55 base::CommandLine
* command_line
= base::CommandLine::ForCurrentProcess();
56 // Create a Browser for each valid URL in the command line.
57 for (const auto& arg
: command_line
->GetArgs()) {
62 // If there were no valid URLs in the command line create a Browser with the
64 if (browsers_
.empty())
65 CreateBrowser(GURL(kGoogleURL
));
68 bool BrowserManager::ConfigureIncomingConnection(
69 mojo::ApplicationConnection
* connection
) {
70 connection
->AddService
<LaunchHandler
>(this);
74 void BrowserManager::Create(mojo::ApplicationConnection
* connection
,
75 mojo::InterfaceRequest
<LaunchHandler
> request
) {
76 launch_handler_bindings_
.AddBinding(this, request
.Pass());
79 } // namespace mandoline