| 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/browser/browser_manager.h" | 5 #include "mandoline/ui/browser/browser_manager.h" |
| 6 | 6 |
| 7 #include "components/view_manager/public/cpp/view.h" | 7 #include "components/view_manager/public/cpp/view.h" |
| 8 #include "components/view_manager/public/cpp/view_observer.h" | 8 #include "components/view_manager/public/cpp/view_observer.h" |
| 9 #include "mandoline/ui/browser/browser.h" | 9 #include "mandoline/ui/browser/browser.h" |
| 10 | 10 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 DCHECK(browsers_.empty()); | 58 DCHECK(browsers_.empty()); |
| 59 } | 59 } |
| 60 | 60 |
| 61 Browser* BrowserManager::CreateBrowser() { | 61 Browser* BrowserManager::CreateBrowser() { |
| 62 DCHECK(app_); | 62 DCHECK(app_); |
| 63 Browser* browser = new Browser(app_, this); | 63 Browser* browser = new Browser(app_, this); |
| 64 browsers_.insert(browser); | 64 browsers_.insert(browser); |
| 65 return browser; | 65 return browser; |
| 66 } | 66 } |
| 67 | 67 |
| 68 void BrowserManager::BrowserClosed(Browser* browser) { | |
| 69 scoped_ptr<Browser> browser_owner(browser); | |
| 70 DCHECK_GT(browsers_.count(browser), 0u); | |
| 71 browsers_.erase(browser); | |
| 72 if (browsers_.empty()) | |
| 73 app_->Terminate(); | |
| 74 } | |
| 75 | |
| 76 bool BrowserManager::InitUIIfNecessary(Browser* browser, mojo::View* view) { | |
| 77 if (view->viewport_metrics().device_pixel_ratio > 0) { | |
| 78 #if defined(USE_AURA) | |
| 79 if (!aura_init_) | |
| 80 aura_init_.reset(new AuraInit(view, app_->shell())); | |
| 81 #endif | |
| 82 return true; | |
| 83 } | |
| 84 DCHECK(!device_pixel_ratio_waiter_.get()); | |
| 85 device_pixel_ratio_waiter_.reset( | |
| 86 new DevicePixelRatioWaiter(this, browser, view)); | |
| 87 return false; | |
| 88 } | |
| 89 | |
| 90 void BrowserManager::OnDevicePixelRatioAvailable(Browser* browser, | 68 void BrowserManager::OnDevicePixelRatioAvailable(Browser* browser, |
| 91 mojo::View* view) { | 69 mojo::View* view) { |
| 92 device_pixel_ratio_waiter_.reset(); | 70 device_pixel_ratio_waiter_.reset(); |
| 93 #if defined(USE_AURA) | 71 #if defined(USE_AURA) |
| 94 DCHECK(!aura_init_.get()); | 72 DCHECK(!aura_init_.get()); |
| 95 aura_init_.reset(new AuraInit(view, app_->shell())); | 73 aura_init_.reset(new AuraInit(view, app_->shell())); |
| 96 #endif | 74 #endif |
| 97 browser->OnDevicePixelRatioAvailable(); | 75 browser->OnDevicePixelRatioAvailable(); |
| 98 } | 76 } |
| 99 | 77 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 110 app_ = app; | 88 app_ = app; |
| 111 CreateBrowser(); | 89 CreateBrowser(); |
| 112 } | 90 } |
| 113 | 91 |
| 114 bool BrowserManager::ConfigureIncomingConnection( | 92 bool BrowserManager::ConfigureIncomingConnection( |
| 115 mojo::ApplicationConnection* connection) { | 93 mojo::ApplicationConnection* connection) { |
| 116 connection->AddService<LaunchHandler>(this); | 94 connection->AddService<LaunchHandler>(this); |
| 117 return true; | 95 return true; |
| 118 } | 96 } |
| 119 | 97 |
| 98 void BrowserManager::BrowserClosed(Browser* browser) { |
| 99 scoped_ptr<Browser> browser_owner(browser); |
| 100 DCHECK_GT(browsers_.count(browser), 0u); |
| 101 browsers_.erase(browser); |
| 102 if (browsers_.empty()) |
| 103 app_->Terminate(); |
| 104 } |
| 105 |
| 106 bool BrowserManager::InitUIIfNecessary(Browser* browser, mojo::View* view) { |
| 107 if (view->viewport_metrics().device_pixel_ratio > 0) { |
| 108 #if defined(USE_AURA) |
| 109 if (!aura_init_) |
| 110 aura_init_.reset(new AuraInit(view, app_->shell())); |
| 111 #endif |
| 112 return true; |
| 113 } |
| 114 DCHECK(!device_pixel_ratio_waiter_.get()); |
| 115 device_pixel_ratio_waiter_.reset( |
| 116 new DevicePixelRatioWaiter(this, browser, view)); |
| 117 return false; |
| 118 } |
| 119 |
| 120 void BrowserManager::Create(mojo::ApplicationConnection* connection, | 120 void BrowserManager::Create(mojo::ApplicationConnection* connection, |
| 121 mojo::InterfaceRequest<LaunchHandler> request) { | 121 mojo::InterfaceRequest<LaunchHandler> request) { |
| 122 launch_handler_bindings_.AddBinding(this, request.Pass()); | 122 launch_handler_bindings_.AddBinding(this, request.Pass()); |
| 123 } | 123 } |
| 124 | 124 |
| 125 } // namespace mandoline | 125 } // namespace mandoline |
| OLD | NEW |