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 "components/view_manager/public/cpp/view.h" | 9 #include "components/view_manager/public/cpp/view.h" |
10 #include "components/view_manager/public/cpp/view_manager_init.h" | 10 #include "components/view_manager/public/cpp/view_manager_init.h" |
(...skipping 28 matching lines...) Expand all Loading... |
39 exposed_services_impl_.AddService<mojo::NavigatorHost>(this); | 39 exposed_services_impl_.AddService<mojo::NavigatorHost>(this); |
40 } | 40 } |
41 | 41 |
42 Browser::~Browser() { | 42 Browser::~Browser() { |
43 // Destruct ui_ manually while |this| is alive and reset the pointer first. | 43 // Destruct ui_ manually while |this| is alive and reset the pointer first. |
44 // This is to avoid a double delete when OnViewManagerDisconnected gets | 44 // This is to avoid a double delete when OnViewManagerDisconnected gets |
45 // called. | 45 // called. |
46 delete ui_.release(); | 46 delete ui_.release(); |
47 } | 47 } |
48 | 48 |
49 void Browser::ReplaceContentWithURL(const mojo::String& url) { | 49 void Browser::ReplaceContentWithRequest(mojo::URLRequestPtr request) { |
50 Embed(url, nullptr, nullptr); | 50 Embed(request.Pass(), nullptr, nullptr); |
51 } | 51 } |
52 | 52 |
53 void Browser::Initialize(mojo::ApplicationImpl* app) { | 53 void Browser::Initialize(mojo::ApplicationImpl* app) { |
54 view_manager_init_.reset(new mojo::ViewManagerInit(app, this, this)); | 54 view_manager_init_.reset(new mojo::ViewManagerInit(app, this, this)); |
55 | 55 |
56 ui_.reset(BrowserUI::Create(this, app)); | 56 ui_.reset(BrowserUI::Create(this, app)); |
57 | 57 |
58 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 58 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
59 base::CommandLine::StringVector args = command_line->GetArgs(); | 59 base::CommandLine::StringVector args = command_line->GetArgs(); |
60 if (args.empty()) { | 60 if (args.empty()) { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 view_manager_init_->view_manager_root()->SetViewportSize( | 97 view_manager_init_->view_manager_root()->SetViewportSize( |
98 mojo::Size::From(GetInitialViewportSize())); | 98 mojo::Size::From(GetInitialViewportSize())); |
99 | 99 |
100 root_->AddChild(content_); | 100 root_->AddChild(content_); |
101 content_->SetVisible(true); | 101 content_->SetVisible(true); |
102 | 102 |
103 view_manager_init_->view_manager_root()->AddAccelerator( | 103 view_manager_init_->view_manager_root()->AddAccelerator( |
104 mojo::KEYBOARD_CODE_BROWSER_BACK, mojo::EVENT_FLAGS_NONE); | 104 mojo::KEYBOARD_CODE_BROWSER_BACK, mojo::EVENT_FLAGS_NONE); |
105 | 105 |
106 // Now that we're ready, either load a pending url or the default url. | 106 // Now that we're ready, either load a pending url or the default url. |
107 if (!pending_url_.empty()) | 107 if (pending_request_) { |
108 Embed(pending_url_, services.Pass(), exposed_services.Pass()); | 108 Embed(pending_request_.Pass(), services.Pass(), exposed_services.Pass()); |
109 else if (!default_url_.empty()) | 109 } else if (!default_url_.empty()) { |
110 Embed(default_url_, services.Pass(), exposed_services.Pass()); | 110 mojo::URLRequestPtr request(mojo::URLRequest::New()); |
| 111 request->url = mojo::String::From(default_url_); |
| 112 Embed(request.Pass(), services.Pass(), exposed_services.Pass()); |
| 113 } |
111 } | 114 } |
112 | 115 |
113 void Browser::OnViewManagerDisconnected( | 116 void Browser::OnViewManagerDisconnected( |
114 mojo::ViewManager* view_manager) { | 117 mojo::ViewManager* view_manager) { |
115 ui_.reset(); | 118 ui_.reset(); |
116 root_ = nullptr; | 119 root_ = nullptr; |
117 } | 120 } |
118 | 121 |
119 void Browser::OnAccelerator(mojo::EventPtr event) { | 122 void Browser::OnAccelerator(mojo::EventPtr event) { |
120 DCHECK_EQ(mojo::KEYBOARD_CODE_BROWSER_BACK, | 123 DCHECK_EQ(mojo::KEYBOARD_CODE_BROWSER_BACK, |
121 event->key_data->windows_key_code); | 124 event->key_data->windows_key_code); |
122 navigator_host_.RequestNavigateHistory(-1); | 125 navigator_host_.RequestNavigateHistory(-1); |
123 } | 126 } |
124 | 127 |
125 void Browser::OpenURL(const mojo::String& url) { | 128 void Browser::OpenURL(const mojo::String& url) { |
126 omnibox_->SetVisible(false); | 129 omnibox_->SetVisible(false); |
127 ReplaceContentWithURL(url); | 130 mojo::URLRequestPtr request(mojo::URLRequest::New()); |
| 131 request->url = mojo::String::From(url); |
| 132 ReplaceContentWithRequest(request.Pass()); |
128 } | 133 } |
129 | 134 |
130 void Browser::Embed(const mojo::String& url, | 135 void Browser::Embed(mojo::URLRequestPtr request, |
131 mojo::InterfaceRequest<mojo::ServiceProvider> services, | 136 mojo::InterfaceRequest<mojo::ServiceProvider> services, |
132 mojo::ServiceProviderPtr exposed_services) { | 137 mojo::ServiceProviderPtr exposed_services) { |
133 if (url == "mojo:omnibox") { | 138 std::string string_url = request->url.To<std::string>(); |
134 ShowOmnibox(url, services.Pass(), exposed_services.Pass()); | 139 if (string_url == "mojo:omnibox") { |
| 140 ShowOmnibox(request.Pass(), services.Pass(), exposed_services.Pass()); |
135 return; | 141 return; |
136 } | 142 } |
137 | 143 |
138 // We can get Embed calls before we've actually been | 144 // We can get Embed calls before we've actually been |
139 // embedded into the root view and content_ is created. | 145 // embedded into the root view and content_ is created. |
140 // Just save the last url, we'll embed it when we're ready. | 146 // Just save the last url, we'll embed it when we're ready. |
141 if (!content_) { | 147 if (!content_) { |
142 pending_url_ = url; | 148 pending_request_ = request.Pass(); |
143 return; | 149 return; |
144 } | 150 } |
145 | 151 |
146 GURL gurl(url.To<base::string16>()); | 152 GURL gurl(string_url); |
147 bool changed = current_url_ != gurl; | 153 bool changed = current_url_ != gurl; |
148 current_url_ = gurl; | 154 current_url_ = gurl; |
149 if (changed) | 155 if (changed) |
150 ui_->OnURLChanged(); | 156 ui_->OnURLChanged(); |
151 | 157 |
152 merged_service_provider_.reset( | 158 merged_service_provider_.reset( |
153 new MergedServiceProvider(exposed_services.Pass(), this)); | 159 new MergedServiceProvider(exposed_services.Pass(), this)); |
154 content_->Embed(url, services.Pass(), | 160 content_->Embed(request.Pass(), services.Pass(), |
155 merged_service_provider_->GetServiceProviderPtr().Pass()); | 161 merged_service_provider_->GetServiceProviderPtr().Pass()); |
156 | 162 |
157 navigator_host_.RecordNavigation(url); | 163 navigator_host_.RecordNavigation(gurl.spec()); |
158 } | 164 } |
159 | 165 |
160 void Browser::Create(mojo::ApplicationConnection* connection, | 166 void Browser::Create(mojo::ApplicationConnection* connection, |
161 mojo::InterfaceRequest<mojo::NavigatorHost> request) { | 167 mojo::InterfaceRequest<mojo::NavigatorHost> request) { |
162 navigator_host_.Bind(request.Pass()); | 168 navigator_host_.Bind(request.Pass()); |
163 } | 169 } |
164 | 170 |
165 void Browser::Create(mojo::ApplicationConnection* connection, | 171 void Browser::Create(mojo::ApplicationConnection* connection, |
166 mojo::InterfaceRequest<ViewEmbedder> request) { | 172 mojo::InterfaceRequest<ViewEmbedder> request) { |
167 view_embedder_bindings_.AddBinding(this, request.Pass()); | 173 view_embedder_bindings_.AddBinding(this, request.Pass()); |
168 } | 174 } |
169 | 175 |
170 void Browser::ShowOmnibox( | 176 void Browser::ShowOmnibox( |
171 const mojo::String& url, | 177 mojo::URLRequestPtr request, |
172 mojo::InterfaceRequest<mojo::ServiceProvider> services, | 178 mojo::InterfaceRequest<mojo::ServiceProvider> services, |
173 mojo::ServiceProviderPtr exposed_services) { | 179 mojo::ServiceProviderPtr exposed_services) { |
174 if (!omnibox_) { | 180 if (!omnibox_) { |
175 omnibox_ = root_->view_manager()->CreateView(); | 181 omnibox_ = root_->view_manager()->CreateView(); |
176 root_->AddChild(omnibox_); | 182 root_->AddChild(omnibox_); |
177 omnibox_->SetVisible(true); | 183 omnibox_->SetVisible(true); |
178 omnibox_->SetBounds(root_->bounds()); | 184 omnibox_->SetBounds(root_->bounds()); |
179 } | 185 } |
180 omnibox_->Embed(url, services.Pass(), exposed_services.Pass()); | 186 omnibox_->Embed(request.Pass(), services.Pass(), exposed_services.Pass()); |
181 } | 187 } |
182 | 188 |
183 } // namespace mandoline | 189 } // namespace mandoline |
OLD | NEW |