| 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/html_viewer/frame_tree_manager.h" | 5 #include "components/html_viewer/frame_tree_manager.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "components/html_viewer/blink_basic_type_converters.h" |
| 11 #include "components/html_viewer/blink_url_request_type_converters.h" | 12 #include "components/html_viewer/blink_url_request_type_converters.h" |
| 12 #include "components/html_viewer/frame.h" | 13 #include "components/html_viewer/frame.h" |
| 13 #include "components/html_viewer/frame_tree_manager_delegate.h" | 14 #include "components/html_viewer/frame_tree_manager_delegate.h" |
| 14 #include "components/html_viewer/global_state.h" | 15 #include "components/html_viewer/global_state.h" |
| 15 #include "components/view_manager/public/cpp/view_manager.h" | 16 #include "components/view_manager/public/cpp/view_manager.h" |
| 16 #include "mojo/application/public/cpp/application_connection.h" | 17 #include "mojo/application/public/cpp/application_connection.h" |
| 17 #include "mojo/application/public/cpp/application_impl.h" | 18 #include "mojo/application/public/cpp/application_impl.h" |
| 18 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 19 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| 19 #include "third_party/WebKit/public/web/WebRemoteFrame.h" | 20 #include "third_party/WebKit/public/web/WebRemoteFrame.h" |
| 20 #include "third_party/WebKit/public/web/WebTreeScopeType.h" | 21 #include "third_party/WebKit/public/web/WebTreeScopeType.h" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 48 if (request.extraData()) | 49 if (request.extraData()) |
| 49 return true; | 50 return true; |
| 50 | 51 |
| 51 // Otherwise we don't know if we're the right app to handle this request. Ask | 52 // Otherwise we don't know if we're the right app to handle this request. Ask |
| 52 // host to do the navigation for us. | 53 // host to do the navigation for us. |
| 53 return false; | 54 return false; |
| 54 } | 55 } |
| 55 | 56 |
| 56 // Creates a Frame per FrameData element in |frame_data|. | 57 // Creates a Frame per FrameData element in |frame_data|. |
| 57 Frame* BuildFrameTree(FrameTreeManager* frame_tree_manager, | 58 Frame* BuildFrameTree(FrameTreeManager* frame_tree_manager, |
| 58 const mojo::Array<mandoline::FrameDataPtr>& frame_data) { | 59 const mojo::Array<mandoline::FrameDataPtr>& frame_data, |
| 60 uint32_t local_frame_id, |
| 61 mojo::View* local_view) { |
| 59 std::vector<Frame*> parents; | 62 std::vector<Frame*> parents; |
| 60 Frame* root = nullptr; | 63 Frame* root = nullptr; |
| 61 Frame* last_frame = nullptr; | 64 Frame* last_frame = nullptr; |
| 62 for (size_t i = 0; i < frame_data.size(); ++i) { | 65 for (size_t i = 0; i < frame_data.size(); ++i) { |
| 63 if (last_frame && frame_data[i]->parent_id == last_frame->id()) { | 66 if (last_frame && frame_data[i]->parent_id == last_frame->id()) { |
| 64 parents.push_back(last_frame); | 67 parents.push_back(last_frame); |
| 65 } else if (!parents.empty()) { | 68 } else if (!parents.empty()) { |
| 66 while (parents.back()->id() != frame_data[i]->parent_id) | 69 while (parents.back()->id() != frame_data[i]->parent_id) |
| 67 parents.pop_back(); | 70 parents.pop_back(); |
| 68 } | 71 } |
| 69 Frame::CreateParams params(frame_tree_manager, | 72 Frame::CreateParams params(frame_tree_manager, |
| 70 !parents.empty() ? parents.back() : nullptr, | 73 !parents.empty() ? parents.back() : nullptr, |
| 71 frame_data[i]->frame_id); | 74 frame_data[i]->frame_id); |
| 72 Frame* frame = new Frame(params); | 75 Frame* frame = new Frame(params); |
| 73 if (!last_frame) | 76 if (!last_frame) |
| 74 root = frame; | 77 root = frame; |
| 75 else | 78 else |
| 76 DCHECK(frame->parent()); | 79 DCHECK(frame->parent()); |
| 77 last_frame = frame; | 80 last_frame = frame; |
| 81 |
| 82 frame->Init(local_view, frame_data[i]->name.To<blink::WebString>(), |
| 83 frame_data[i]->origin.To<blink::WebString>()); |
| 78 } | 84 } |
| 79 return root; | 85 return root; |
| 80 } | 86 } |
| 81 | 87 |
| 82 } // namespace | 88 } // namespace |
| 83 | 89 |
| 84 FrameTreeManager::FrameTreeManager(GlobalState* global_state, | 90 FrameTreeManager::FrameTreeManager(GlobalState* global_state, |
| 85 mojo::ApplicationImpl* app, | 91 mojo::ApplicationImpl* app, |
| 86 mojo::ApplicationConnection* app_connection, | 92 mojo::ApplicationConnection* app_connection, |
| 87 uint32_t local_frame_id, | 93 uint32_t local_frame_id, |
| 88 mandoline::FrameTreeServerPtr server) | 94 mandoline::FrameTreeServerPtr server) |
| 89 : global_state_(global_state), | 95 : global_state_(global_state), |
| 90 app_(app), | 96 app_(app), |
| 91 delegate_(nullptr), | 97 delegate_(nullptr), |
| 92 local_frame_id_(local_frame_id), | 98 local_frame_id_(local_frame_id), |
| 93 server_(server.Pass()), | 99 server_(server.Pass()), |
| 94 navigator_host_(app_connection->GetServiceProvider()), | 100 navigator_host_(app_connection->GetServiceProvider()), |
| 95 root_(nullptr) { | 101 root_(nullptr) { |
| 96 } | 102 } |
| 97 | 103 |
| 98 FrameTreeManager::~FrameTreeManager() { | 104 FrameTreeManager::~FrameTreeManager() { |
| 99 if (root_) | 105 if (root_) |
| 100 root_->Close(); // This should call back to OnFrameDestroyed(). | 106 root_->Close(); // This should call back to OnFrameDestroyed(). |
| 101 DCHECK(!root_); | 107 DCHECK(!root_); |
| 102 } | 108 } |
| 103 | 109 |
| 104 void FrameTreeManager::Init(mojo::View* local_view, | 110 void FrameTreeManager::Init(mojo::View* local_view, |
| 105 mojo::Array<mandoline::FrameDataPtr> frame_data) { | 111 mojo::Array<mandoline::FrameDataPtr> frame_data) { |
| 106 root_ = BuildFrameTree(this, frame_data); | 112 root_ = BuildFrameTree(this, frame_data, local_frame_id_, local_view); |
| 107 CHECK(root_); | |
| 108 Frame* local_frame = root_->FindFrame(local_frame_id_); | 113 Frame* local_frame = root_->FindFrame(local_frame_id_); |
| 109 CHECK(local_frame); | 114 CHECK(local_frame); |
| 110 local_frame->SetView(local_view); | |
| 111 InitFrames(local_view, root_); | |
| 112 local_frame->UpdateFocus(); | 115 local_frame->UpdateFocus(); |
| 113 } | 116 } |
| 114 | 117 |
| 115 Frame* FrameTreeManager::GetLocalFrame() { | 118 Frame* FrameTreeManager::GetLocalFrame() { |
| 116 return root_->FindFrame(local_frame_id_); | 119 return root_->FindFrame(local_frame_id_); |
| 117 } | 120 } |
| 118 | 121 |
| 119 blink::WebLocalFrame* FrameTreeManager::GetLocalWebFrame() { | 122 blink::WebLocalFrame* FrameTreeManager::GetLocalWebFrame() { |
| 120 return GetLocalFrame()->web_frame()->toWebLocalFrame(); | 123 return GetLocalFrame()->web_frame()->toWebLocalFrame(); |
| 121 } | 124 } |
| 122 | 125 |
| 123 blink::WebView* FrameTreeManager::GetWebView() { | 126 blink::WebView* FrameTreeManager::GetWebView() { |
| 124 return root_->web_view(); | 127 return root_->web_view(); |
| 125 } | 128 } |
| 126 | 129 |
| 127 void FrameTreeManager::InitFrames(mojo::View* local_view, Frame* frame) { | |
| 128 frame->Init(local_view); | |
| 129 | |
| 130 for (Frame* child_frame : frame->children()) | |
| 131 InitFrames(local_view, child_frame); | |
| 132 } | |
| 133 | |
| 134 blink::WebNavigationPolicy FrameTreeManager::DecidePolicyForNavigation( | 130 blink::WebNavigationPolicy FrameTreeManager::DecidePolicyForNavigation( |
| 135 Frame* frame, | 131 Frame* frame, |
| 136 const blink::WebFrameClient::NavigationPolicyInfo& info) { | 132 const blink::WebFrameClient::NavigationPolicyInfo& info) { |
| 137 if (info.frame == frame->web_frame() && frame == root_ && delegate_ && | 133 if (info.frame == frame->web_frame() && frame == root_ && delegate_ && |
| 138 delegate_->ShouldNavigateLocallyInMainFrame()) { | 134 delegate_->ShouldNavigateLocallyInMainFrame()) { |
| 139 return info.defaultPolicy; | 135 return info.defaultPolicy; |
| 140 } | 136 } |
| 141 | 137 |
| 142 if (CanNavigateLocally(info.frame, info.urlRequest)) | 138 if (CanNavigateLocally(info.frame, info.urlRequest)) |
| 143 return info.defaultPolicy; | 139 return info.defaultPolicy; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 166 } | 162 } |
| 167 | 163 |
| 168 void FrameTreeManager::OnFrameDestroyed(Frame* frame) { | 164 void FrameTreeManager::OnFrameDestroyed(Frame* frame) { |
| 169 if (frame == root_) { | 165 if (frame == root_) { |
| 170 root_ = nullptr; | 166 root_ = nullptr; |
| 171 // Shortly after this HTMLDocumentOOPIF should get ViewManagerDestroyed() | 167 // Shortly after this HTMLDocumentOOPIF should get ViewManagerDestroyed() |
| 172 // and delete us. | 168 // and delete us. |
| 173 } | 169 } |
| 174 } | 170 } |
| 175 | 171 |
| 172 void FrameTreeManager::OnFrameDidChangeName(Frame* frame, |
| 173 const blink::WebString& name) { |
| 174 if (frame != GetLocalFrame()) |
| 175 return; |
| 176 |
| 177 mojo::String mojo_name; |
| 178 if (!name.isNull()) |
| 179 mojo_name = name.utf8(); |
| 180 server_->SetFrameName(mojo_name); |
| 181 } |
| 182 |
| 176 void FrameTreeManager::OnConnect( | 183 void FrameTreeManager::OnConnect( |
| 177 mandoline::FrameTreeServerPtr server, | 184 mandoline::FrameTreeServerPtr server, |
| 178 mojo::Array<mandoline::FrameDataPtr> frame_data) { | 185 mojo::Array<mandoline::FrameDataPtr> frame_data) { |
| 179 // OnConnection() is only sent once, and has been received (by | 186 // OnConnection() is only sent once, and has been received (by |
| 180 // DocumentResourceWaiter) by the time we get here. | 187 // DocumentResourceWaiter) by the time we get here. |
| 181 NOTREACHED(); | 188 NOTREACHED(); |
| 182 } | 189 } |
| 183 | 190 |
| 184 void FrameTreeManager::LoadingStarted() { | 191 void FrameTreeManager::LoadingStarted() { |
| 185 server_->LoadingStarted(); | 192 server_->LoadingStarted(); |
| 186 } | 193 } |
| 187 | 194 |
| 188 void FrameTreeManager::LoadingStopped() { | 195 void FrameTreeManager::LoadingStopped() { |
| 189 server_->LoadingStopped(); | 196 server_->LoadingStopped(); |
| 190 } | 197 } |
| 191 | 198 |
| 192 void FrameTreeManager::ProgressChanged(double progress) { | 199 void FrameTreeManager::ProgressChanged(double progress) { |
| 193 server_->ProgressChanged(progress); | 200 server_->ProgressChanged(progress); |
| 194 } | 201 } |
| 195 | 202 |
| 196 void FrameTreeManager::OnFrameAdded(mandoline::FrameDataPtr frame_data) { | 203 void FrameTreeManager::OnFrameAdded(mandoline::FrameDataPtr frame_data) { |
| 197 NOTIMPLEMENTED(); | 204 NOTIMPLEMENTED(); |
| 198 } | 205 } |
| 199 | 206 |
| 200 void FrameTreeManager::OnFrameRemoved(uint32_t frame_id) { | 207 void FrameTreeManager::OnFrameRemoved(uint32_t frame_id) { |
| 201 NOTIMPLEMENTED(); | 208 NOTIMPLEMENTED(); |
| 202 } | 209 } |
| 203 | 210 |
| 211 void FrameTreeManager::OnFrameNameChanged(uint32_t frame_id, |
| 212 const mojo::String& name) { |
| 213 Frame* frame = root_->FindFrame(frame_id); |
| 214 if (frame) |
| 215 frame->SetRemoteFrameName(name); |
| 216 } |
| 217 |
| 204 } // namespace mojo | 218 } // namespace mojo |
| OLD | NEW |