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/browser/browser_manager.h"
7 #include "base/command_line.h"
8 #include "components/view_manager/public/cpp/view.h"
9 #include "components/view_manager/public/cpp/view_observer.h"
10 #include "mandoline/ui/browser/browser.h"
16 const char kGoogleURL
[] = "http://www.google.com";
20 BrowserManager::BrowserManager()
24 BrowserManager::~BrowserManager() {
25 DCHECK(browsers_
.empty());
28 Browser
* BrowserManager::CreateBrowser(const GURL
& default_url
) {
30 Browser
* browser
= new Browser(app_
, this, default_url
);
31 browsers_
.insert(browser
);
35 void BrowserManager::LaunchURL(const mojo::String
& url
) {
36 DCHECK(!browsers_
.empty());
37 mojo::URLRequestPtr
request(mojo::URLRequest::New());
39 // TODO(fsamuel): Create a new Browser once we support multiple browser
41 (*browsers_
.begin())->ReplaceContentWithRequest(request
.Pass());
44 void BrowserManager::Initialize(mojo::ApplicationImpl
* app
) {
46 base::CommandLine
* command_line
= base::CommandLine::ForCurrentProcess();
47 // Create a Browser for each valid URL in the command line.
48 for (const auto& arg
: command_line
->GetArgs()) {
53 // If there were no valid URLs in the command line create a Browser with the
55 if (browsers_
.empty())
56 CreateBrowser(GURL(kGoogleURL
));
59 bool BrowserManager::ConfigureIncomingConnection(
60 mojo::ApplicationConnection
* connection
) {
61 connection
->AddService
<LaunchHandler
>(this);
65 void BrowserManager::BrowserClosed(Browser
* browser
) {
66 scoped_ptr
<Browser
> browser_owner(browser
);
67 DCHECK_GT(browsers_
.count(browser
), 0u);
68 browsers_
.erase(browser
);
69 if (browsers_
.empty())
73 void BrowserManager::InitUIIfNecessary(Browser
* browser
, mojo::View
* view
) {
74 DCHECK_GT(view
->viewport_metrics().device_pixel_ratio
, 0);
77 aura_init_
.reset(new AuraInit(view
, app_
->shell()));
81 void BrowserManager::Create(mojo::ApplicationConnection
* connection
,
82 mojo::InterfaceRequest
<LaunchHandler
> request
) {
83 launch_handler_bindings_
.AddBinding(this, request
.Pass());
86 } // namespace mandoline