| 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/mus/public/cpp/scoped_view_ptr.h" | 9 #include "components/mus/public/cpp/scoped_view_ptr.h" |
| 10 #include "components/mus/public/cpp/view.h" | 10 #include "components/mus/public/cpp/view.h" |
| 11 #include "components/mus/public/cpp/view_tree_connection.h" | 11 #include "components/mus/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 // Clear the forward list when performing a top level load request. |
| 82 pending_load_->Init(request.Pass()); | 97 forward_list_.clear(); |
| 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()); |
| 83 } | 108 } |
| 84 | 109 |
| 85 void WebViewImpl::GetViewTreeClient( | 110 void WebViewImpl::GetViewTreeClient( |
| 86 mojo::InterfaceRequest<mojo::ViewTreeClient> view_tree_client) { | 111 mojo::InterfaceRequest<mojo::ViewTreeClient> view_tree_client) { |
| 87 mojo::ViewTreeConnection::Create(this, view_tree_client.Pass()); | 112 mojo::ViewTreeConnection::Create(this, view_tree_client.Pass()); |
| 88 } | 113 } |
| 89 | 114 |
| 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 |
| 90 //////////////////////////////////////////////////////////////////////////////// | 140 //////////////////////////////////////////////////////////////////////////////// |
| 91 // WebViewImpl, mojo::ViewTreeDelegate implementation: | 141 // WebViewImpl, mojo::ViewTreeDelegate implementation: |
| 92 | 142 |
| 93 void WebViewImpl::OnEmbed(mojo::View* root) { | 143 void WebViewImpl::OnEmbed(mojo::View* root) { |
| 94 // We must have been granted embed root priviledges, otherwise we can't | 144 // We must have been granted embed root priviledges, otherwise we can't |
| 95 // Embed() in any descendants. | 145 // Embed() in any descendants. |
| 96 DCHECK(root->connection()->IsEmbedRoot()); | 146 DCHECK(root->connection()->IsEmbedRoot()); |
| 97 root->AddObserver(this); | 147 root->AddObserver(this); |
| 98 root_ = root; | 148 root_ = root; |
| 99 content_ = root->connection()->CreateView(); | 149 content_ = root->connection()->CreateView(); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 //////////////////////////////////////////////////////////////////////////////// | 220 //////////////////////////////////////////////////////////////////////////////// |
| 171 // WebViewImpl, FrameDevToolsAgentDelegate implementation: | 221 // WebViewImpl, FrameDevToolsAgentDelegate implementation: |
| 172 | 222 |
| 173 void WebViewImpl::HandlePageNavigateRequest(const GURL& url) { | 223 void WebViewImpl::HandlePageNavigateRequest(const GURL& url) { |
| 174 mojo::URLRequestPtr request(mojo::URLRequest::New()); | 224 mojo::URLRequestPtr request(mojo::URLRequest::New()); |
| 175 request->url = url.spec(); | 225 request->url = url.spec(); |
| 176 client_->TopLevelNavigate(request.Pass()); | 226 client_->TopLevelNavigate(request.Pass()); |
| 177 } | 227 } |
| 178 | 228 |
| 179 } // namespace web_view | 229 } // namespace web_view |
| OLD | NEW |