Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(111)

Side by Side Diff: services/navigation/view_impl.cc

Issue 1981623002: Add a basic browser to mash that uses the navigation service. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « services/navigation/view_impl.h ('k') | ui/views/mus/native_widget_mus.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
7 #include "content/public/browser/navigation_controller.h" 9 #include "content/public/browser/navigation_controller.h"
8 #include "content/public/browser/web_contents.h" 10 #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"
9 #include "url/gurl.h" 15 #include "url/gurl.h"
10 16
11 namespace navigation { 17 namespace navigation {
12 18
13 ViewImpl::ViewImpl(content::BrowserContext* browser_context, 19 ViewImpl::ViewImpl(shell::Connector* connector,
20 content::BrowserContext* browser_context,
14 mojom::ViewClientPtr client, 21 mojom::ViewClientPtr client,
15 mojom::ViewRequest request, 22 mojom::ViewRequest request,
16 std::unique_ptr<shell::ShellConnectionRef> ref) 23 std::unique_ptr<shell::ShellConnectionRef> ref)
17 : binding_(this, std::move(request)), 24 : connector_(connector),
25 binding_(this, std::move(request)),
18 client_(std::move(client)), 26 client_(std::move(client)),
19 ref_(std::move(ref)) { 27 ref_(std::move(ref)),
20 web_contents_.reset(content::WebContents::Create( 28 web_view_(new views::WebView(browser_context)) {
21 content::WebContents::CreateParams(browser_context))); 29 web_view_->GetWebContents()->SetDelegate(this);
22 web_contents_->SetDelegate(this);
23 } 30 }
24 ViewImpl::~ViewImpl() {} 31 ViewImpl::~ViewImpl() {}
25 32
26 void ViewImpl::LoadUrl(const GURL& url) { 33 void ViewImpl::NavigateTo(const GURL& url) {
27 web_contents_->GetController().LoadURL( 34 web_view_->GetWebContents()->GetController().LoadURL(
28 url, content::Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 35 url, content::Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
29 } 36 }
30 37
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
31 void ViewImpl::LoadingStateChanged(content::WebContents* source, 93 void ViewImpl::LoadingStateChanged(content::WebContents* source,
32 bool to_different_document) { 94 bool to_different_document) {
33 client_->LoadingStateChanged(source->IsLoading()); 95 client_->LoadingStateChanged(source->IsLoading());
34 } 96 }
35 97
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
36 } // navigation 139 } // navigation
OLDNEW
« no previous file with comments | « services/navigation/view_impl.h ('k') | ui/views/mus/native_widget_mus.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698