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); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
68 } | 69 } |
69 | 70 |
70 FrameTreeClient* frame_tree_client = frame_connection->frame_tree_client(); | 71 FrameTreeClient* frame_tree_client = frame_connection->frame_tree_client(); |
71 const uint32_t content_handler_id = frame_connection->GetContentHandlerID(); | 72 const uint32_t content_handler_id = frame_connection->GetContentHandlerID(); |
72 frame_tree_.reset(new FrameTree(content_handler_id, content_, this, | 73 frame_tree_.reset(new FrameTree(content_handler_id, content_, this, |
73 frame_tree_client, frame_connection.Pass(), | 74 frame_tree_client, frame_connection.Pass(), |
74 client_properties)); | 75 client_properties)); |
75 content_->Embed(view_tree_client.Pass()); | 76 content_->Embed(view_tree_client.Pass()); |
76 } | 77 } |
77 | 78 |
79 void WebViewImpl::UpdateBackForwardEnableState() { | |
80 client_->BackForwardChanged(!back_list_.empty(), !forward_list_.empty()); | |
81 } | |
82 | |
78 //////////////////////////////////////////////////////////////////////////////// | 83 //////////////////////////////////////////////////////////////////////////////// |
79 // WebViewImpl, WebView implementation: | 84 // WebViewImpl, WebView implementation: |
80 | 85 |
81 void WebViewImpl::LoadRequest(mojo::URLRequestPtr request) { | 86 void WebViewImpl::LoadRequest(mojo::URLRequestPtr request) { |
87 if (current_page_request_) { | |
88 // TODO(erg): This doesn't deal with redirect chains. If you navigate to a | |
89 // site, and it 300s, we put both the url which caused the 300 and the | |
90 // target url here, when we should not add the redirect url to the back | |
91 // list. | |
92 back_list_.push_back(current_page_request_.Pass()); | |
93 } | |
94 UpdateBackForwardEnableState(); | |
95 | |
96 current_page_request_.reset(new URLRequestCloneable(request.Pass())); | |
97 | |
82 pending_load_.reset(new PendingWebViewLoad(this)); | 98 pending_load_.reset(new PendingWebViewLoad(this)); |
83 pending_load_->Init(request.Pass()); | 99 pending_load_->Init(current_page_request_->Clone()); |
84 } | 100 } |
85 | 101 |
86 void WebViewImpl::GetViewTreeClient( | 102 void WebViewImpl::GetViewTreeClient( |
87 mojo::InterfaceRequest<mojo::ViewTreeClient> view_tree_client) { | 103 mojo::InterfaceRequest<mojo::ViewTreeClient> view_tree_client) { |
88 mojo::ViewTreeConnection::Create(this, view_tree_client.Pass()); | 104 mojo::ViewTreeConnection::Create(this, view_tree_client.Pass()); |
89 } | 105 } |
90 | 106 |
107 void WebViewImpl::GoBack() { | |
108 if (back_list_.empty()) | |
109 return; | |
110 | |
111 // Take the current page request and put it in the forward list. | |
112 forward_list_.push_back(current_page_request_.Pass()); | |
113 | |
114 mojo::URLRequestPtr new_request = back_list_.back()->Clone(); | |
115 back_list_.resize(back_list_.size() - 1); | |
116 | |
117 UpdateBackForwardEnableState(); | |
118 client_->TopLevelNavigate(new_request.Pass()); | |
sky
2015/09/08 16:00:32
TopLevelNavigate is intended for requests from the
| |
119 } | |
120 | |
121 void WebViewImpl::GoForward() { | |
122 if (forward_list_.empty()) | |
123 return; | |
124 | |
125 back_list_.push_back(current_page_request_.Pass()); | |
126 | |
127 mojo::URLRequestPtr new_request = forward_list_.back()->Clone(); | |
128 forward_list_.resize(forward_list_.size() - 1); | |
129 | |
130 UpdateBackForwardEnableState(); | |
131 client_->TopLevelNavigate(new_request.Pass()); | |
132 } | |
133 | |
91 //////////////////////////////////////////////////////////////////////////////// | 134 //////////////////////////////////////////////////////////////////////////////// |
92 // WebViewImpl, mojo::ViewTreeDelegate implementation: | 135 // WebViewImpl, mojo::ViewTreeDelegate implementation: |
93 | 136 |
94 void WebViewImpl::OnEmbed(mojo::View* root) { | 137 void WebViewImpl::OnEmbed(mojo::View* root) { |
95 // We must have been granted embed root priviledges, otherwise we can't | 138 // We must have been granted embed root priviledges, otherwise we can't |
96 // Embed() in any descendants. | 139 // Embed() in any descendants. |
97 DCHECK(root->connection()->IsEmbedRoot()); | 140 DCHECK(root->connection()->IsEmbedRoot()); |
98 root->AddObserver(this); | 141 root->AddObserver(this); |
99 root_ = root; | 142 root_ = root; |
100 content_ = root->connection()->CreateView(); | 143 content_ = root->connection()->CreateView(); |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
171 //////////////////////////////////////////////////////////////////////////////// | 214 //////////////////////////////////////////////////////////////////////////////// |
172 // WebViewImpl, FrameDevToolsAgentDelegate implementation: | 215 // WebViewImpl, FrameDevToolsAgentDelegate implementation: |
173 | 216 |
174 void WebViewImpl::HandlePageNavigateRequest(const GURL& url) { | 217 void WebViewImpl::HandlePageNavigateRequest(const GURL& url) { |
175 mojo::URLRequestPtr request(mojo::URLRequest::New()); | 218 mojo::URLRequestPtr request(mojo::URLRequest::New()); |
176 request->url = url.spec(); | 219 request->url = url.spec(); |
177 client_->TopLevelNavigate(request.Pass()); | 220 client_->TopLevelNavigate(request.Pass()); |
178 } | 221 } |
179 | 222 |
180 } // namespace web_view | 223 } // namespace web_view |
OLD | NEW |