OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "services/navigation/view_impl.h" | 5 #include "services/navigation/view_impl.h" |
6 | 6 |
7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "content/public/browser/browser_context.h" | 8 #include "content/public/browser/browser_context.h" |
9 #include "content/public/browser/interstitial_page.h" | 9 #include "content/public/browser/interstitial_page.h" |
10 #include "content/public/browser/interstitial_page_delegate.h" | 10 #include "content/public/browser/interstitial_page_delegate.h" |
11 #include "content/public/browser/navigation_controller.h" | 11 #include "content/public/browser/navigation_controller.h" |
12 #include "content/public/browser/navigation_details.h" | 12 #include "content/public/browser/navigation_details.h" |
13 #include "content/public/browser/navigation_entry.h" | 13 #include "content/public/browser/navigation_entry.h" |
14 #include "content/public/browser/notification_details.h" | 14 #include "content/public/browser/notification_details.h" |
15 #include "content/public/browser/notification_source.h" | 15 #include "content/public/browser/notification_source.h" |
16 #include "content/public/browser/notification_types.h" | 16 #include "content/public/browser/notification_types.h" |
17 #include "content/public/browser/web_contents.h" | 17 #include "content/public/browser/web_contents.h" |
18 #include "services/shell/public/cpp/connector.h" | |
19 #include "services/ui/public/cpp/window_tree_client.h" | 18 #include "services/ui/public/cpp/window_tree_client.h" |
20 #include "ui/views/controls/webview/webview.h" | 19 #include "ui/views/controls/webview/webview.h" |
21 #include "ui/views/mus/native_widget_mus.h" | 20 #include "ui/views/mus/native_widget_mus.h" |
22 #include "ui/views/widget/widget.h" | 21 #include "ui/views/widget/widget.h" |
23 #include "url/gurl.h" | 22 #include "url/gurl.h" |
24 | 23 |
25 namespace navigation { | 24 namespace navigation { |
26 namespace { | 25 namespace { |
27 | 26 |
28 class InterstitialPageDelegate : public content::InterstitialPageDelegate { | 27 class InterstitialPageDelegate : public content::InterstitialPageDelegate { |
(...skipping 21 matching lines...) Expand all Loading... |
50 mojom::NavigationEntryPtr entry_ptr(mojom::NavigationEntry::New()); | 49 mojom::NavigationEntryPtr entry_ptr(mojom::NavigationEntry::New()); |
51 entry_ptr->id = entry.GetUniqueID(); | 50 entry_ptr->id = entry.GetUniqueID(); |
52 entry_ptr->url = entry.GetURL(); | 51 entry_ptr->url = entry.GetURL(); |
53 entry_ptr->title = base::UTF16ToUTF8(entry.GetTitle()); | 52 entry_ptr->title = base::UTF16ToUTF8(entry.GetTitle()); |
54 entry_ptr->redirect_chain = entry.GetRedirectChain(); | 53 entry_ptr->redirect_chain = entry.GetRedirectChain(); |
55 return entry_ptr; | 54 return entry_ptr; |
56 } | 55 } |
57 | 56 |
58 } // namespace | 57 } // namespace |
59 | 58 |
60 ViewImpl::ViewImpl(std::unique_ptr<shell::Connector> connector, | 59 ViewImpl::ViewImpl(shell::Connector* connector, |
61 const std::string& client_user_id, | 60 const std::string& client_user_id, |
62 mojom::ViewClientPtr client, | 61 mojom::ViewClientPtr client, |
63 mojom::ViewRequest request, | 62 mojom::ViewRequest request, |
64 std::unique_ptr<shell::ServiceContextRef> ref) | 63 std::unique_ptr<shell::ServiceContextRef> ref) |
65 : connector_(std::move(connector)), | 64 : connector_(connector), |
66 binding_(this, std::move(request)), | 65 binding_(this, std::move(request)), |
67 client_(std::move(client)), | 66 client_(std::move(client)), |
68 ref_(std::move(ref)), | 67 ref_(std::move(ref)), |
69 web_view_(new views::WebView( | 68 web_view_(new views::WebView( |
70 content::BrowserContext::GetBrowserContextForShellUserId( | 69 content::BrowserContext::GetBrowserContextForShellUserId( |
71 client_user_id))) { | 70 client_user_id))) { |
72 web_view_->GetWebContents()->SetDelegate(this); | 71 web_view_->GetWebContents()->SetDelegate(this); |
73 const content::NavigationController* controller = | 72 const content::NavigationController* controller = |
74 &web_view_->GetWebContents()->GetController(); | 73 &web_view_->GetWebContents()->GetController(); |
75 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_PENDING, | 74 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_PENDING, |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 bool* was_blocked) { | 141 bool* was_blocked) { |
143 mojom::ViewClientPtr client; | 142 mojom::ViewClientPtr client; |
144 mojom::ViewPtr view; | 143 mojom::ViewPtr view; |
145 mojom::ViewRequest view_request = GetProxy(&view); | 144 mojom::ViewRequest view_request = GetProxy(&view); |
146 client_->ViewCreated(std::move(view), GetProxy(&client), | 145 client_->ViewCreated(std::move(view), GetProxy(&client), |
147 disposition == NEW_POPUP, initial_rect, user_gesture); | 146 disposition == NEW_POPUP, initial_rect, user_gesture); |
148 | 147 |
149 const std::string new_user_id = | 148 const std::string new_user_id = |
150 content::BrowserContext::GetShellUserIdFor( | 149 content::BrowserContext::GetShellUserIdFor( |
151 new_contents->GetBrowserContext()); | 150 new_contents->GetBrowserContext()); |
152 ViewImpl* impl = new ViewImpl( | 151 ViewImpl* impl = new ViewImpl(connector_, new_user_id, std::move(client), |
153 connector_->Clone(), new_user_id, std::move(client), | 152 std::move(view_request), ref_->Clone()); |
154 std::move(view_request), ref_->Clone()); | |
155 // TODO(beng): This is a bit crappy. should be able to create the ViewImpl | 153 // TODO(beng): This is a bit crappy. should be able to create the ViewImpl |
156 // with |new_contents| instead. | 154 // with |new_contents| instead. |
157 impl->web_view_->SetWebContents(new_contents); | 155 impl->web_view_->SetWebContents(new_contents); |
158 impl->web_view_->GetWebContents()->SetDelegate(impl); | 156 impl->web_view_->GetWebContents()->SetDelegate(impl); |
159 | 157 |
160 // TODO(beng): this reply is currently synchronous, figure out a fix. | 158 // TODO(beng): this reply is currently synchronous, figure out a fix. |
161 if (was_blocked) | 159 if (was_blocked) |
162 *was_blocked = false; | 160 *was_blocked = false; |
163 } | 161 } |
164 | 162 |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 } | 265 } |
268 | 266 |
269 void ViewImpl::OnEmbed(ui::Window* root) { | 267 void ViewImpl::OnEmbed(ui::Window* root) { |
270 DCHECK(!widget_.get()); | 268 DCHECK(!widget_.get()); |
271 widget_.reset(new views::Widget); | 269 widget_.reset(new views::Widget); |
272 views::Widget::InitParams params( | 270 views::Widget::InitParams params( |
273 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); | 271 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
274 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 272 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
275 params.delegate = this; | 273 params.delegate = this; |
276 params.native_widget = new views::NativeWidgetMus( | 274 params.native_widget = new views::NativeWidgetMus( |
277 widget_.get(), connector_.get(), root, ui::mojom::SurfaceType::DEFAULT); | 275 widget_.get(), connector_, root, ui::mojom::SurfaceType::DEFAULT); |
278 widget_->Init(params); | 276 widget_->Init(params); |
279 widget_->Show(); | 277 widget_->Show(); |
280 } | 278 } |
281 | 279 |
282 void ViewImpl::OnDidDestroyClient(ui::WindowTreeClient* client) {} | 280 void ViewImpl::OnDidDestroyClient(ui::WindowTreeClient* client) {} |
283 void ViewImpl::OnEventObserved(const ui::Event& event, ui::Window* target) {} | 281 void ViewImpl::OnEventObserved(const ui::Event& event, ui::Window* target) {} |
284 | 282 |
285 views::View* ViewImpl::GetContentsView() { | 283 views::View* ViewImpl::GetContentsView() { |
286 return web_view_; | 284 return web_view_; |
287 } | 285 } |
288 | 286 |
289 views::Widget* ViewImpl::GetWidget() { | 287 views::Widget* ViewImpl::GetWidget() { |
290 return web_view_->GetWidget(); | 288 return web_view_->GetWidget(); |
291 } | 289 } |
292 | 290 |
293 const views::Widget* ViewImpl::GetWidget() const { | 291 const views::Widget* ViewImpl::GetWidget() const { |
294 return web_view_->GetWidget(); | 292 return web_view_->GetWidget(); |
295 } | 293 } |
296 | 294 |
297 } // navigation | 295 } // navigation |
OLD | NEW |