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