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