Chromium Code Reviews| 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.h" | 5 #include "mandoline/ui/browser/browser.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "mandoline/ui/browser/browser_ui.h" | 9 #include "mandoline/ui/browser/browser_ui.h" |
| 10 #include "mandoline/ui/browser/merged_service_provider.h" | 10 #include "mandoline/ui/browser/merged_service_provider.h" |
| 11 #include "mojo/application/application_runner_chromium.h" | 11 #include "mojo/application/application_runner_chromium.h" |
| 12 #include "mojo/converters/geometry/geometry_type_converters.h" | |
| 12 #include "third_party/mojo/src/mojo/public/c/system/main.h" | 13 #include "third_party/mojo/src/mojo/public/c/system/main.h" |
| 14 #include "ui/gfx/geometry/rect.h" | |
| 13 #include "ui/gfx/geometry/size.h" | 15 #include "ui/gfx/geometry/size.h" |
| 14 | 16 |
| 15 namespace mandoline { | 17 namespace mandoline { |
| 16 | 18 |
| 17 Browser::Browser() | 19 Browser::Browser() |
| 18 : window_manager_app_(new window_manager::WindowManagerApp(this, this)), | 20 : window_manager_app_(new window_manager::WindowManagerApp(this, this)), |
| 19 root_(nullptr), | 21 root_(nullptr), |
| 20 content_(nullptr), | 22 content_(nullptr), |
| 21 navigator_host_(this), | 23 navigator_host_(this), |
| 22 ui_(nullptr), | 24 ui_(nullptr), |
| 23 weak_factory_(this) { | 25 weak_factory_(this) { |
| 24 exposed_services_impl_.AddService(this); | 26 exposed_services_impl_.AddService(this); |
| 25 } | 27 } |
| 26 | 28 |
| 27 Browser::~Browser() { | 29 Browser::~Browser() { |
| 30 if (root_) { | |
| 31 root_->RemoveObserver(this); | |
| 32 root_ = nullptr; | |
| 33 } | |
| 28 } | 34 } |
| 29 | 35 |
| 30 base::WeakPtr<Browser> Browser::GetWeakPtr() { | 36 base::WeakPtr<Browser> Browser::GetWeakPtr() { |
| 31 return weak_factory_.GetWeakPtr(); | 37 return weak_factory_.GetWeakPtr(); |
| 32 } | 38 } |
| 33 | 39 |
| 40 // Convenience method: | |
| 41 void Browser::ReplaceContentWithURL(const mojo::String& url) { | |
|
sky
2015/05/11 22:01:27
I moved a couple of things to match declaration or
| |
| 42 Embed(url, nullptr, nullptr); | |
| 43 } | |
| 44 | |
| 34 void Browser::Initialize(mojo::ApplicationImpl* app) { | 45 void Browser::Initialize(mojo::ApplicationImpl* app) { |
| 35 window_manager_app_->Initialize(app); | 46 window_manager_app_->Initialize(app); |
| 36 ui_.reset(BrowserUI::Create(this, app->shell())); | 47 ui_.reset(BrowserUI::Create(this, app->shell())); |
| 37 | 48 |
| 38 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 49 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 39 base::CommandLine::StringVector args = command_line->GetArgs(); | 50 base::CommandLine::StringVector args = command_line->GetArgs(); |
| 40 if (args.empty()) { | 51 if (args.empty()) { |
| 41 default_url_ = "http://www.google.com/"; | 52 default_url_ = "http://www.google.com/"; |
| 42 } else { | 53 } else { |
| 43 #if defined(OS_WIN) | 54 #if defined(OS_WIN) |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 64 mojo::View* root, | 75 mojo::View* root, |
| 65 mojo::InterfaceRequest<mojo::ServiceProvider> services, | 76 mojo::InterfaceRequest<mojo::ServiceProvider> services, |
| 66 mojo::ServiceProviderPtr exposed_services) { | 77 mojo::ServiceProviderPtr exposed_services) { |
| 67 // Browser does not support being embedded more than once. | 78 // Browser does not support being embedded more than once. |
| 68 CHECK(!root_); | 79 CHECK(!root_); |
| 69 | 80 |
| 70 // TODO(beng): still unhappy with the fact that both this class & the UI class | 81 // TODO(beng): still unhappy with the fact that both this class & the UI class |
| 71 // know so much about these views. Figure out how to shift more to | 82 // know so much about these views. Figure out how to shift more to |
| 72 // the UI class. | 83 // the UI class. |
| 73 root_ = root; | 84 root_ = root; |
| 85 root_->AddObserver(this); | |
| 74 content_ = root->view_manager()->CreateView(); | 86 content_ = root->view_manager()->CreateView(); |
| 75 ui_->Init(root_, content_); | 87 ui_->Init(root_, content_); |
| 76 | 88 |
| 77 #if defined(OS_ANDROID) | 89 #if defined(OS_ANDROID) |
| 78 // Resize to match the Nexus 5 aspect ratio: | 90 // Resize to match the Nexus 5 aspect ratio: |
| 79 window_manager_app_->SetViewportSize(gfx::Size(320, 640)); | 91 window_manager_app_->SetViewportSize(gfx::Size(320, 640)); |
| 80 #else | 92 #else |
| 81 window_manager_app_->SetViewportSize(gfx::Size(1280, 800)); | 93 window_manager_app_->SetViewportSize(gfx::Size(1280, 800)); |
| 82 #endif | 94 #endif |
| 83 | 95 |
| 84 root_->AddChild(content_); | 96 root_->AddChild(content_); |
| 85 content_->SetVisible(true); | 97 content_->SetVisible(true); |
| 86 | 98 |
| 87 window_manager_app_->AddAccelerator(mojo::KEYBOARD_CODE_BROWSER_BACK, | 99 window_manager_app_->AddAccelerator(mojo::KEYBOARD_CODE_BROWSER_BACK, |
| 88 mojo::EVENT_FLAGS_NONE); | 100 mojo::EVENT_FLAGS_NONE); |
| 89 | 101 |
| 90 // Now that we're ready, either load a pending url or the default url. | 102 // Now that we're ready, either load a pending url or the default url. |
| 91 if (!pending_url_.empty()) | 103 if (!pending_url_.empty()) |
| 92 Embed(pending_url_, services.Pass(), exposed_services.Pass()); | 104 Embed(pending_url_, services.Pass(), exposed_services.Pass()); |
| 93 else if (!default_url_.empty()) | 105 else if (!default_url_.empty()) |
| 94 Embed(default_url_, services.Pass(), exposed_services.Pass()); | 106 Embed(default_url_, services.Pass(), exposed_services.Pass()); |
| 95 } | 107 } |
| 96 | 108 |
| 109 void Browser::OnViewManagerDisconnected( | |
| 110 mojo::ViewManager* view_manager) { | |
| 111 root_->RemoveObserver(this); | |
| 112 root_ = nullptr; | |
| 113 } | |
| 114 | |
| 97 void Browser::Embed(const mojo::String& url, | 115 void Browser::Embed(const mojo::String& url, |
| 98 mojo::InterfaceRequest<mojo::ServiceProvider> services, | 116 mojo::InterfaceRequest<mojo::ServiceProvider> services, |
| 99 mojo::ServiceProviderPtr exposed_services) { | 117 mojo::ServiceProviderPtr exposed_services) { |
| 100 // We can get Embed calls before we've actually been | 118 // We can get Embed calls before we've actually been |
| 101 // embedded into the root view and content_ is created. | 119 // embedded into the root view and content_ is created. |
| 102 // Just save the last url, we'll embed it when we're ready. | 120 // Just save the last url, we'll embed it when we're ready. |
| 103 if (!content_) { | 121 if (!content_) { |
| 104 pending_url_ = url; | 122 pending_url_ = url; |
| 105 return; | 123 return; |
| 106 } | 124 } |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 118 mojo::EventFlags flags) { | 136 mojo::EventFlags flags) { |
| 119 DCHECK_EQ(mojo::KEYBOARD_CODE_BROWSER_BACK, keyboard_code); | 137 DCHECK_EQ(mojo::KEYBOARD_CODE_BROWSER_BACK, keyboard_code); |
| 120 navigator_host_.RequestNavigateHistory(-1); | 138 navigator_host_.RequestNavigateHistory(-1); |
| 121 } | 139 } |
| 122 | 140 |
| 123 void Browser::Create(mojo::ApplicationConnection* connection, | 141 void Browser::Create(mojo::ApplicationConnection* connection, |
| 124 mojo::InterfaceRequest<mojo::NavigatorHost> request) { | 142 mojo::InterfaceRequest<mojo::NavigatorHost> request) { |
| 125 navigator_host_.Bind(request.Pass()); | 143 navigator_host_.Bind(request.Pass()); |
| 126 } | 144 } |
| 127 | 145 |
| 128 void Browser::OnViewManagerDisconnected( | 146 void Browser::OnViewBoundsChanged(mojo::View* view, |
| 129 mojo::ViewManager* view_manager) { | 147 const mojo::Rect& old_bounds, |
| 130 root_ = nullptr; | 148 const mojo::Rect& new_bounds) { |
| 131 } | 149 content_->SetBounds( |
| 132 | 150 *mojo::Rect::From(gfx::Rect(0, 0, new_bounds.width, new_bounds.height))); |
| 133 // Convenience method: | |
| 134 void Browser::ReplaceContentWithURL(const mojo::String& url) { | |
| 135 Embed(url, nullptr, nullptr); | |
| 136 } | 151 } |
| 137 | 152 |
| 138 } // namespace mandoline | 153 } // namespace mandoline |
| OLD | NEW |