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 "third_party/mojo/src/mojo/public/c/system/main.h" | 12 #include "third_party/mojo/src/mojo/public/c/system/main.h" |
13 #include "ui/gfx/geometry/size.h" | 13 #include "ui/gfx/geometry/size.h" |
14 | 14 |
15 namespace mandoline { | 15 namespace mandoline { |
16 | 16 |
17 Browser::Browser() | 17 Browser::Browser() |
18 : window_manager_app_(new window_manager::WindowManagerApp(this, this)), | 18 : window_manager_app_(new window_manager::WindowManagerApp(this, this)), |
19 root_(nullptr), | 19 root_(nullptr), |
20 content_(nullptr), | 20 content_(nullptr), |
| 21 omnibox_(nullptr), |
21 navigator_host_(this), | 22 navigator_host_(this), |
22 ui_(nullptr), | 23 ui_(nullptr), |
23 weak_factory_(this) { | 24 weak_factory_(this) { |
24 exposed_services_impl_.AddService(this); | 25 exposed_services_impl_.AddService(this); |
25 } | 26 } |
26 | 27 |
27 Browser::~Browser() { | 28 Browser::~Browser() { |
28 } | 29 } |
29 | 30 |
30 base::WeakPtr<Browser> Browser::GetWeakPtr() { | 31 base::WeakPtr<Browser> Browser::GetWeakPtr() { |
31 return weak_factory_.GetWeakPtr(); | 32 return weak_factory_.GetWeakPtr(); |
32 } | 33 } |
33 | 34 |
34 // Convenience method: | |
35 void Browser::ReplaceContentWithURL(const mojo::String& url) { | 35 void Browser::ReplaceContentWithURL(const mojo::String& url) { |
36 Embed(url, nullptr, nullptr); | 36 Embed(url, nullptr, nullptr); |
37 } | 37 } |
38 | 38 |
39 void Browser::Initialize(mojo::ApplicationImpl* app) { | 39 void Browser::Initialize(mojo::ApplicationImpl* app) { |
40 window_manager_app_->Initialize(app); | 40 window_manager_app_->Initialize(app); |
41 ui_.reset(BrowserUI::Create(this, app->shell())); | 41 ui_.reset(BrowserUI::Create(this, app)); |
42 | 42 |
43 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 43 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
44 base::CommandLine::StringVector args = command_line->GetArgs(); | 44 base::CommandLine::StringVector args = command_line->GetArgs(); |
45 if (args.empty()) { | 45 if (args.empty()) { |
46 default_url_ = "http://www.google.com/"; | 46 default_url_ = "http://www.google.com/"; |
47 } else { | 47 } else { |
48 #if defined(OS_WIN) | 48 #if defined(OS_WIN) |
49 default_url_ = base::WideToUTF8(args[0]); | 49 default_url_ = base::WideToUTF8(args[0]); |
50 #else | 50 #else |
51 default_url_ = args[0]; | 51 default_url_ = args[0]; |
(...skipping 18 matching lines...) Expand all Loading... |
70 mojo::InterfaceRequest<mojo::ServiceProvider> services, | 70 mojo::InterfaceRequest<mojo::ServiceProvider> services, |
71 mojo::ServiceProviderPtr exposed_services) { | 71 mojo::ServiceProviderPtr exposed_services) { |
72 // Browser does not support being embedded more than once. | 72 // Browser does not support being embedded more than once. |
73 CHECK(!root_); | 73 CHECK(!root_); |
74 | 74 |
75 // TODO(beng): still unhappy with the fact that both this class & the UI class | 75 // TODO(beng): still unhappy with the fact that both this class & the UI class |
76 // know so much about these views. Figure out how to shift more to | 76 // know so much about these views. Figure out how to shift more to |
77 // the UI class. | 77 // the UI class. |
78 root_ = root; | 78 root_ = root; |
79 content_ = root->view_manager()->CreateView(); | 79 content_ = root->view_manager()->CreateView(); |
80 ui_->Init(root_, content_); | 80 ui_->Init(root_); |
81 | 81 |
82 #if defined(OS_ANDROID) | 82 #if defined(OS_ANDROID) |
83 // Resize to match the Nexus 5 aspect ratio: | 83 // Resize to match the Nexus 5 aspect ratio: |
84 window_manager_app_->SetViewportSize(gfx::Size(320, 640)); | 84 window_manager_app_->SetViewportSize(gfx::Size(320, 640)); |
85 #else | 85 #else |
86 window_manager_app_->SetViewportSize(gfx::Size(1280, 800)); | 86 window_manager_app_->SetViewportSize(gfx::Size(1280, 800)); |
87 #endif | 87 #endif |
88 | 88 |
89 root_->AddChild(content_); | 89 root_->AddChild(content_); |
90 content_->SetVisible(true); | 90 content_->SetVisible(true); |
(...skipping 10 matching lines...) Expand all Loading... |
101 | 101 |
102 void Browser::OnViewManagerDisconnected( | 102 void Browser::OnViewManagerDisconnected( |
103 mojo::ViewManager* view_manager) { | 103 mojo::ViewManager* view_manager) { |
104 ui_.reset(); | 104 ui_.reset(); |
105 root_ = nullptr; | 105 root_ = nullptr; |
106 } | 106 } |
107 | 107 |
108 void Browser::Embed(const mojo::String& url, | 108 void Browser::Embed(const mojo::String& url, |
109 mojo::InterfaceRequest<mojo::ServiceProvider> services, | 109 mojo::InterfaceRequest<mojo::ServiceProvider> services, |
110 mojo::ServiceProviderPtr exposed_services) { | 110 mojo::ServiceProviderPtr exposed_services) { |
| 111 if (url == "mojo:omnibox") { |
| 112 ShowOmnibox(url, services.Pass(), exposed_services.Pass()); |
| 113 return; |
| 114 } |
| 115 |
111 // We can get Embed calls before we've actually been | 116 // We can get Embed calls before we've actually been |
112 // embedded into the root view and content_ is created. | 117 // embedded into the root view and content_ is created. |
113 // Just save the last url, we'll embed it when we're ready. | 118 // Just save the last url, we'll embed it when we're ready. |
114 if (!content_) { | 119 if (!content_) { |
115 pending_url_ = url; | 120 pending_url_ = url; |
116 return; | 121 return; |
117 } | 122 } |
118 | 123 |
| 124 bool changed = current_url_ != url; |
| 125 current_url_ = url; |
| 126 if (changed) |
| 127 ui_->OnURLChanged(); |
| 128 |
119 merged_service_provider_.reset( | 129 merged_service_provider_.reset( |
120 new MergedServiceProvider(exposed_services.Pass(), this)); | 130 new MergedServiceProvider(exposed_services.Pass(), this)); |
121 content_->Embed(url, services.Pass(), | 131 content_->Embed(url, services.Pass(), |
122 merged_service_provider_->GetServiceProviderPtr().Pass()); | 132 merged_service_provider_->GetServiceProviderPtr().Pass()); |
123 | 133 |
124 navigator_host_.RecordNavigation(url); | 134 navigator_host_.RecordNavigation(url); |
125 } | 135 } |
126 | 136 |
127 void Browser::OnAcceleratorPressed(mojo::View* view, | 137 void Browser::OnAcceleratorPressed(mojo::View* view, |
128 mojo::KeyboardCode keyboard_code, | 138 mojo::KeyboardCode keyboard_code, |
129 mojo::EventFlags flags) { | 139 mojo::EventFlags flags) { |
130 DCHECK_EQ(mojo::KEYBOARD_CODE_BROWSER_BACK, keyboard_code); | 140 DCHECK_EQ(mojo::KEYBOARD_CODE_BROWSER_BACK, keyboard_code); |
131 navigator_host_.RequestNavigateHistory(-1); | 141 navigator_host_.RequestNavigateHistory(-1); |
132 } | 142 } |
133 | 143 |
| 144 void Browser::OpenURL(const mojo::String& url) { |
| 145 omnibox_->SetVisible(false); |
| 146 ReplaceContentWithURL(url); |
| 147 } |
| 148 |
134 void Browser::Create(mojo::ApplicationConnection* connection, | 149 void Browser::Create(mojo::ApplicationConnection* connection, |
135 mojo::InterfaceRequest<mojo::NavigatorHost> request) { | 150 mojo::InterfaceRequest<mojo::NavigatorHost> request) { |
136 navigator_host_.Bind(request.Pass()); | 151 navigator_host_.Bind(request.Pass()); |
137 } | 152 } |
138 | 153 |
| 154 void Browser::ShowOmnibox( |
| 155 const mojo::String& url, |
| 156 mojo::InterfaceRequest<mojo::ServiceProvider> services, |
| 157 mojo::ServiceProviderPtr exposed_services) { |
| 158 if (!omnibox_) { |
| 159 omnibox_ = root_->view_manager()->CreateView(); |
| 160 root_->AddChild(omnibox_); |
| 161 omnibox_->SetVisible(true); |
| 162 omnibox_->SetBounds(root_->bounds()); |
| 163 } |
| 164 omnibox_->Embed(url, services.Pass(), exposed_services.Pass()); |
| 165 } |
| 166 |
139 } // namespace mandoline | 167 } // namespace mandoline |
OLD | NEW |