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