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 "components/web_view/web_view_impl.h" | 5 #include "components/web_view/web_view_impl.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "components/devtools_service/public/cpp/switches.h" | 8 #include "components/devtools_service/public/cpp/switches.h" |
9 #include "components/view_manager/public/cpp/scoped_view_ptr.h" | 9 #include "components/view_manager/public/cpp/scoped_view_ptr.h" |
10 #include "components/view_manager/public/cpp/view.h" | 10 #include "components/view_manager/public/cpp/view.h" |
11 #include "components/view_manager/public/cpp/view_tree_connection.h" | 11 #include "components/view_manager/public/cpp/view_tree_connection.h" |
12 #include "components/web_view/frame.h" | 12 #include "components/web_view/frame.h" |
13 #include "components/web_view/frame_connection.h" | 13 #include "components/web_view/frame_connection.h" |
14 #include "components/web_view/frame_devtools_agent.h" | 14 #include "components/web_view/frame_devtools_agent.h" |
15 #include "components/web_view/frame_tree.h" | 15 #include "components/web_view/frame_tree.h" |
16 #include "components/web_view/pending_web_view_load.h" | 16 #include "components/web_view/pending_web_view_load.h" |
17 #include "components/web_view/url_request_cloneable.h" | |
18 #include "mojo/application/public/cpp/application_impl.h" | 17 #include "mojo/application/public/cpp/application_impl.h" |
19 #include "mojo/converters/geometry/geometry_type_converters.h" | 18 #include "mojo/converters/geometry/geometry_type_converters.h" |
20 #include "url/gurl.h" | 19 #include "url/gurl.h" |
21 | 20 |
22 namespace web_view { | 21 namespace web_view { |
23 namespace { | 22 namespace { |
24 | 23 |
25 bool EnableRemoteDebugging() { | 24 bool EnableRemoteDebugging() { |
26 return base::CommandLine::ForCurrentProcess()->HasSwitch( | 25 return base::CommandLine::ForCurrentProcess()->HasSwitch( |
27 devtools_service::kRemoteDebuggingPort); | 26 devtools_service::kRemoteDebuggingPort); |
28 } | 27 } |
29 | 28 |
30 } // namespace | 29 } // namespace |
31 | 30 |
32 using web_view::mojom::ButtonState; | |
33 | |
34 //////////////////////////////////////////////////////////////////////////////// | 31 //////////////////////////////////////////////////////////////////////////////// |
35 // WebViewImpl, public: | 32 // WebViewImpl, public: |
36 | 33 |
37 WebViewImpl::WebViewImpl(mojo::ApplicationImpl* app, | 34 WebViewImpl::WebViewImpl(mojo::ApplicationImpl* app, |
38 mojom::WebViewClientPtr client, | 35 mojom::WebViewClientPtr client, |
39 mojo::InterfaceRequest<mojom::WebView> request) | 36 mojo::InterfaceRequest<mojom::WebView> request) |
40 : app_(app), | 37 : app_(app), |
41 client_(client.Pass()), | 38 client_(client.Pass()), |
42 binding_(this, request.Pass()), | 39 binding_(this, request.Pass()), |
43 root_(nullptr), | 40 root_(nullptr), |
(...skipping 26 matching lines...) Expand all Loading... |
70 devtools_agent_->AttachFrame(forward_agent.Pass(), &client_properties); | 67 devtools_agent_->AttachFrame(forward_agent.Pass(), &client_properties); |
71 } | 68 } |
72 | 69 |
73 FrameTreeClient* frame_tree_client = frame_connection->frame_tree_client(); | 70 FrameTreeClient* frame_tree_client = frame_connection->frame_tree_client(); |
74 const uint32_t content_handler_id = frame_connection->GetContentHandlerID(); | 71 const uint32_t content_handler_id = frame_connection->GetContentHandlerID(); |
75 frame_tree_.reset(new FrameTree( | 72 frame_tree_.reset(new FrameTree( |
76 content_handler_id, content_, view_tree_client.Pass(), this, | 73 content_handler_id, content_, view_tree_client.Pass(), this, |
77 frame_tree_client, frame_connection.Pass(), client_properties)); | 74 frame_tree_client, frame_connection.Pass(), client_properties)); |
78 } | 75 } |
79 | 76 |
80 void WebViewImpl::LoadRequestImpl(mojo::URLRequestPtr request) { | |
81 client_->BackForwardChanged( | |
82 back_list_.empty() ? ButtonState::BUTTON_STATE_DISABLED | |
83 : ButtonState::BUTTON_STATE_ENABLED, | |
84 forward_list_.empty() ? ButtonState::BUTTON_STATE_DISABLED | |
85 : ButtonState::BUTTON_STATE_ENABLED); | |
86 | |
87 current_page_request_.reset(new URLRequestCloneable(request.Pass())); | |
88 pending_load_.reset(new PendingWebViewLoad(this)); | |
89 pending_load_->Init(current_page_request_->Clone()); | |
90 } | |
91 | |
92 //////////////////////////////////////////////////////////////////////////////// | 77 //////////////////////////////////////////////////////////////////////////////// |
93 // WebViewImpl, WebView implementation: | 78 // WebViewImpl, WebView implementation: |
94 | 79 |
95 void WebViewImpl::LoadRequest(mojo::URLRequestPtr request) { | 80 void WebViewImpl::LoadRequest(mojo::URLRequestPtr request) { |
96 // Clear the forward list when performing a top level load request. | 81 pending_load_.reset(new PendingWebViewLoad(this)); |
97 forward_list_.clear(); | 82 pending_load_->Init(request.Pass()); |
98 | |
99 if (current_page_request_) { | |
100 // TODO(erg): This doesn't deal with redirect chains. If you navigate to a | |
101 // site, and it 300s, we put both the url which caused the 300 and the | |
102 // target url here, when we should not add the redirect url to the back | |
103 // list. | |
104 back_list_.push_back(current_page_request_.Pass()); | |
105 } | |
106 | |
107 LoadRequestImpl(request.Pass()); | |
108 } | 83 } |
109 | 84 |
110 void WebViewImpl::GetViewTreeClient( | 85 void WebViewImpl::GetViewTreeClient( |
111 mojo::InterfaceRequest<mojo::ViewTreeClient> view_tree_client) { | 86 mojo::InterfaceRequest<mojo::ViewTreeClient> view_tree_client) { |
112 mojo::ViewTreeConnection::Create(this, view_tree_client.Pass()); | 87 mojo::ViewTreeConnection::Create(this, view_tree_client.Pass()); |
113 } | 88 } |
114 | 89 |
115 void WebViewImpl::GoBack() { | |
116 if (back_list_.empty()) | |
117 return; | |
118 | |
119 // Take the current page request and put it in the forward list. | |
120 forward_list_.push_back(current_page_request_.Pass()); | |
121 | |
122 mojo::URLRequestPtr new_request = back_list_.back()->Clone(); | |
123 back_list_.resize(back_list_.size() - 1); | |
124 | |
125 LoadRequestImpl(new_request.Pass()); | |
126 } | |
127 | |
128 void WebViewImpl::GoForward() { | |
129 if (forward_list_.empty()) | |
130 return; | |
131 | |
132 back_list_.push_back(current_page_request_.Pass()); | |
133 | |
134 mojo::URLRequestPtr new_request = forward_list_.back()->Clone(); | |
135 forward_list_.resize(forward_list_.size() - 1); | |
136 | |
137 LoadRequestImpl(new_request.Pass()); | |
138 } | |
139 | |
140 //////////////////////////////////////////////////////////////////////////////// | 90 //////////////////////////////////////////////////////////////////////////////// |
141 // WebViewImpl, mojo::ViewTreeDelegate implementation: | 91 // WebViewImpl, mojo::ViewTreeDelegate implementation: |
142 | 92 |
143 void WebViewImpl::OnEmbed(mojo::View* root) { | 93 void WebViewImpl::OnEmbed(mojo::View* root) { |
144 // We must have been granted embed root priviledges, otherwise we can't | 94 // We must have been granted embed root priviledges, otherwise we can't |
145 // Embed() in any descendants. | 95 // Embed() in any descendants. |
146 DCHECK(root->connection()->IsEmbedRoot()); | 96 DCHECK(root->connection()->IsEmbedRoot()); |
147 root->AddObserver(this); | 97 root->AddObserver(this); |
148 root_ = root; | 98 root_ = root; |
149 content_ = root->connection()->CreateView(); | 99 content_ = root->connection()->CreateView(); |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 //////////////////////////////////////////////////////////////////////////////// | 170 //////////////////////////////////////////////////////////////////////////////// |
221 // WebViewImpl, FrameDevToolsAgentDelegate implementation: | 171 // WebViewImpl, FrameDevToolsAgentDelegate implementation: |
222 | 172 |
223 void WebViewImpl::HandlePageNavigateRequest(const GURL& url) { | 173 void WebViewImpl::HandlePageNavigateRequest(const GURL& url) { |
224 mojo::URLRequestPtr request(mojo::URLRequest::New()); | 174 mojo::URLRequestPtr request(mojo::URLRequest::New()); |
225 request->url = url.spec(); | 175 request->url = url.spec(); |
226 client_->TopLevelNavigate(request.Pass()); | 176 client_->TopLevelNavigate(request.Pass()); |
227 } | 177 } |
228 | 178 |
229 } // namespace web_view | 179 } // namespace web_view |
OLD | NEW |