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