| 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" | |
| 8 #include "components/mus/public/cpp/window_tree_connection.h" | |
| 9 #include "content/public/browser/navigation_controller.h" | 7 #include "content/public/browser/navigation_controller.h" |
| 10 #include "content/public/browser/web_contents.h" | 8 #include "content/public/browser/web_contents.h" |
| 11 #include "mojo/converters/geometry/geometry_type_converters.h" | |
| 12 #include "ui/views/controls/webview/webview.h" | |
| 13 #include "ui/views/mus/native_widget_mus.h" | |
| 14 #include "ui/views/widget/widget.h" | |
| 15 #include "url/gurl.h" | 9 #include "url/gurl.h" |
| 16 | 10 |
| 17 namespace navigation { | 11 namespace navigation { |
| 18 | 12 |
| 19 ViewImpl::ViewImpl(shell::Connector* connector, | 13 ViewImpl::ViewImpl(content::BrowserContext* browser_context, |
| 20 content::BrowserContext* browser_context, | |
| 21 mojom::ViewClientPtr client, | 14 mojom::ViewClientPtr client, |
| 22 mojom::ViewRequest request, | 15 mojom::ViewRequest request, |
| 23 std::unique_ptr<shell::ShellConnectionRef> ref) | 16 std::unique_ptr<shell::ShellConnectionRef> ref) |
| 24 : connector_(connector), | 17 : binding_(this, std::move(request)), |
| 25 binding_(this, std::move(request)), | |
| 26 client_(std::move(client)), | 18 client_(std::move(client)), |
| 27 ref_(std::move(ref)), | 19 ref_(std::move(ref)) { |
| 28 web_view_(new views::WebView(browser_context)) { | 20 web_contents_.reset(content::WebContents::Create( |
| 29 web_view_->GetWebContents()->SetDelegate(this); | 21 content::WebContents::CreateParams(browser_context))); |
| 22 web_contents_->SetDelegate(this); |
| 30 } | 23 } |
| 31 ViewImpl::~ViewImpl() {} | 24 ViewImpl::~ViewImpl() {} |
| 32 | 25 |
| 33 void ViewImpl::NavigateTo(const GURL& url) { | 26 void ViewImpl::LoadUrl(const GURL& url) { |
| 34 web_view_->GetWebContents()->GetController().LoadURL( | 27 web_contents_->GetController().LoadURL( |
| 35 url, content::Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 28 url, content::Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 36 } | 29 } |
| 37 | 30 |
| 38 void ViewImpl::GoBack() { | |
| 39 web_view_->GetWebContents()->GetController().GoBack(); | |
| 40 } | |
| 41 | |
| 42 void ViewImpl::GoForward() { | |
| 43 web_view_->GetWebContents()->GetController().GoForward(); | |
| 44 } | |
| 45 | |
| 46 void ViewImpl::Reload(bool skip_cache) { | |
| 47 if (skip_cache) | |
| 48 web_view_->GetWebContents()->GetController().Reload(true); | |
| 49 else | |
| 50 web_view_->GetWebContents()->GetController().ReloadBypassingCache(true); | |
| 51 } | |
| 52 | |
| 53 void ViewImpl::Stop() { | |
| 54 web_view_->GetWebContents()->Stop(); | |
| 55 } | |
| 56 | |
| 57 void ViewImpl::GetWindowTreeClient( | |
| 58 mus::mojom::WindowTreeClientRequest request) { | |
| 59 mus::WindowTreeConnection::Create( | |
| 60 this, std::move(request), | |
| 61 mus::WindowTreeConnection::CreateType::DONT_WAIT_FOR_EMBED); | |
| 62 } | |
| 63 | |
| 64 void ViewImpl::AddNewContents(content::WebContents* source, | |
| 65 content::WebContents* new_contents, | |
| 66 WindowOpenDisposition disposition, | |
| 67 const gfx::Rect& initial_rect, | |
| 68 bool user_gesture, | |
| 69 bool* was_blocked) { | |
| 70 mojom::ViewClientPtr client; | |
| 71 mojom::ViewPtr view; | |
| 72 mojom::ViewRequest view_request = GetProxy(&view); | |
| 73 client_->ViewCreated(std::move(view), GetProxy(&client), | |
| 74 disposition == NEW_POPUP, mojo::Rect::From(initial_rect), | |
| 75 user_gesture); | |
| 76 ViewImpl* impl = | |
| 77 new ViewImpl(connector_, new_contents->GetBrowserContext(), | |
| 78 std::move(client), std::move(view_request), ref_->Clone()); | |
| 79 // TODO(beng): This is a bit crappy. should be able to create the ViewImpl | |
| 80 // with |new_contents| instead. | |
| 81 impl->web_view_->SetWebContents(new_contents); | |
| 82 impl->web_view_->GetWebContents()->SetDelegate(impl); | |
| 83 | |
| 84 // TODO(beng): this reply is currently synchronous, figure out a fix. | |
| 85 if (was_blocked) | |
| 86 *was_blocked = false; | |
| 87 } | |
| 88 | |
| 89 void ViewImpl::CloseContents(content::WebContents* source) { | |
| 90 client_->Close(); | |
| 91 } | |
| 92 | |
| 93 void ViewImpl::LoadingStateChanged(content::WebContents* source, | 31 void ViewImpl::LoadingStateChanged(content::WebContents* source, |
| 94 bool to_different_document) { | 32 bool to_different_document) { |
| 95 client_->LoadingStateChanged(source->IsLoading()); | 33 client_->LoadingStateChanged(source->IsLoading()); |
| 96 } | 34 } |
| 97 | 35 |
| 98 void ViewImpl::NavigationStateChanged(content::WebContents* source, | |
| 99 content::InvalidateTypes changed_flags) { | |
| 100 client_->NavigationStateChanged(source->GetVisibleURL(), | |
| 101 base::UTF16ToUTF8(source->GetTitle()), | |
| 102 source->GetController().CanGoBack(), | |
| 103 source->GetController().CanGoForward()); | |
| 104 } | |
| 105 | |
| 106 void ViewImpl::LoadProgressChanged(content::WebContents* source, | |
| 107 double progress) { | |
| 108 client_->LoadProgressChanged(progress); | |
| 109 } | |
| 110 | |
| 111 void ViewImpl::OnEmbed(mus::Window* root) { | |
| 112 DCHECK(!widget_.get()); | |
| 113 widget_.reset(new views::Widget); | |
| 114 views::Widget::InitParams params( | |
| 115 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); | |
| 116 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | |
| 117 params.delegate = this; | |
| 118 params.native_widget = new views::NativeWidgetMus( | |
| 119 widget_.get(), connector_, root, mus::mojom::SurfaceType::DEFAULT); | |
| 120 widget_->Init(params); | |
| 121 widget_->Show(); | |
| 122 } | |
| 123 | |
| 124 void ViewImpl::OnConnectionLost(mus::WindowTreeConnection* connection) {} | |
| 125 void ViewImpl::OnEventObserved(const ui::Event& event, mus::Window* target) {} | |
| 126 | |
| 127 views::View* ViewImpl::GetContentsView() { | |
| 128 return web_view_; | |
| 129 } | |
| 130 | |
| 131 views::Widget* ViewImpl::GetWidget() { | |
| 132 return web_view_->GetWidget(); | |
| 133 } | |
| 134 | |
| 135 const views::Widget* ViewImpl::GetWidget() const { | |
| 136 return web_view_->GetWidget(); | |
| 137 } | |
| 138 | |
| 139 } // navigation | 36 } // navigation |
| OLD | NEW |