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.h" | 5 #include "components/html_viewer/frame.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
11 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
13 #include "base/thread_task_runner_handle.h" | 13 #include "base/thread_task_runner_handle.h" |
14 #include "components/html_viewer/ax_provider_impl.h" | 14 #include "components/html_viewer/ax_provider_impl.h" |
| 15 #include "components/html_viewer/blink_basic_type_converters.h" |
15 #include "components/html_viewer/blink_input_events_type_converters.h" | 16 #include "components/html_viewer/blink_input_events_type_converters.h" |
16 #include "components/html_viewer/blink_url_request_type_converters.h" | 17 #include "components/html_viewer/blink_url_request_type_converters.h" |
17 #include "components/html_viewer/frame_tree_manager.h" | 18 #include "components/html_viewer/frame_tree_manager.h" |
18 #include "components/html_viewer/geolocation_client_impl.h" | 19 #include "components/html_viewer/geolocation_client_impl.h" |
19 #include "components/html_viewer/global_state.h" | 20 #include "components/html_viewer/global_state.h" |
20 #include "components/html_viewer/media_factory.h" | 21 #include "components/html_viewer/media_factory.h" |
21 #include "components/html_viewer/touch_handler.h" | 22 #include "components/html_viewer/touch_handler.h" |
22 #include "components/html_viewer/web_layer_impl.h" | 23 #include "components/html_viewer/web_layer_impl.h" |
23 #include "components/html_viewer/web_layer_tree_view_impl.h" | 24 #include "components/html_viewer/web_layer_tree_view_impl.h" |
24 #include "components/html_viewer/web_storage_namespace_impl.h" | 25 #include "components/html_viewer/web_storage_namespace_impl.h" |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 view_(nullptr), | 89 view_(nullptr), |
89 id_(params.id), | 90 id_(params.id), |
90 web_frame_(nullptr), | 91 web_frame_(nullptr), |
91 web_widget_(nullptr), | 92 web_widget_(nullptr), |
92 scope_(blink::WebTreeScopeType::Document), | 93 scope_(blink::WebTreeScopeType::Document), |
93 weak_factory_(this) { | 94 weak_factory_(this) { |
94 if (parent_) | 95 if (parent_) |
95 parent_->children_.push_back(this); | 96 parent_->children_.push_back(this); |
96 } | 97 } |
97 | 98 |
98 void Frame::Init(mojo::View* local_view) { | 99 void Frame::Init(mojo::View* local_view, |
99 // TODO(sky): need to plumb through scope, name and other args correctly for | 100 const blink::WebString& remote_frame_name, |
100 // frame creation. | 101 const blink::WebString& remote_origin) { |
| 102 if (local_view->id() == id_) |
| 103 SetView(local_view); |
| 104 |
| 105 // TODO(sky): need to plumb through scope and other args correctly for frame |
| 106 // creation. |
101 if (!parent_) { | 107 if (!parent_) { |
102 CreateWebWidget(); | 108 CreateWebWidget(); |
103 // This is the root of the tree (aka the main frame). | 109 // This is the root of the tree (aka the main frame). |
104 // Expected order for creating webframes is: | 110 // Expected order for creating webframes is: |
105 // . Create local webframe (first webframe must always be local). | 111 // . Create local webframe (first webframe must always be local). |
106 // . Set as main frame on WebView. | 112 // . Set as main frame on WebView. |
107 // . Swap to remote (if not local). | 113 // . Swap to remote (if not local). |
108 blink::WebLocalFrame* local_web_frame = | 114 blink::WebLocalFrame* local_web_frame = |
109 blink::WebLocalFrame::create(blink::WebTreeScopeType::Document, this); | 115 blink::WebLocalFrame::create(blink::WebTreeScopeType::Document, this); |
110 // We need to set the main frame before creating children so that state is | 116 // We need to set the main frame before creating children so that state is |
111 // properly set up in blink. | 117 // properly set up in blink. |
112 // TODO(sky): I don't like these casts. | 118 // TODO(sky): I don't like these casts. |
113 web_view()->setMainFrame(local_web_frame); | 119 web_view()->setMainFrame(local_web_frame); |
114 const gfx::Size size_in_pixels(local_view->bounds().width, | 120 const gfx::Size size_in_pixels(local_view->bounds().width, |
115 local_view->bounds().height); | 121 local_view->bounds().height); |
116 const gfx::Size size_in_dips = gfx::ConvertSizeToDIP( | 122 const gfx::Size size_in_dips = gfx::ConvertSizeToDIP( |
117 local_view->viewport_metrics().device_pixel_ratio, size_in_pixels); | 123 local_view->viewport_metrics().device_pixel_ratio, size_in_pixels); |
118 web_widget_->resize(size_in_dips); | 124 web_widget_->resize(size_in_dips); |
119 web_frame_ = local_web_frame; | 125 web_frame_ = local_web_frame; |
120 web_view()->setDeviceScaleFactor(global_state()->device_pixel_ratio()); | 126 web_view()->setDeviceScaleFactor(global_state()->device_pixel_ratio()); |
121 if (id_ != local_view->id()) { | 127 if (id_ != local_view->id()) { |
122 blink::WebRemoteFrame* remote_web_frame = blink::WebRemoteFrame::create( | 128 blink::WebRemoteFrame* remote_web_frame = blink::WebRemoteFrame::create( |
123 blink::WebTreeScopeType::Document, this); | 129 blink::WebTreeScopeType::Document, this); |
124 local_web_frame->swap(remote_web_frame); | 130 local_web_frame->swap(remote_web_frame); |
125 // local_web_frame->close(); | 131 // local_web_frame->close(); |
126 web_frame_ = remote_web_frame; | 132 web_frame_ = remote_web_frame; |
127 // TODO(sky): This needs to come from FrameTreeData. | |
128 remote_web_frame->setReplicatedOrigin( | |
129 blink::WebSecurityOrigin::createFromString("")); | |
130 } | 133 } |
131 } else if (id_ == local_view->id()) { | 134 } else if (id_ == local_view->id()) { |
132 // Frame represents the local frame. | 135 // Frame represents the local frame. |
133 Frame* previous_sibling = GetPreviousSibling(this); | 136 Frame* previous_sibling = GetPreviousSibling(this); |
134 blink::WebFrame* previous_web_frame = | 137 blink::WebFrame* previous_web_frame = |
135 previous_sibling ? previous_sibling->web_frame() : nullptr; | 138 previous_sibling ? previous_sibling->web_frame() : nullptr; |
136 DCHECK(!parent_->IsLocal()); | 139 DCHECK(!parent_->IsLocal()); |
137 web_frame_ = parent_->web_frame()->toWebRemoteFrame()->createLocalChild( | 140 web_frame_ = parent_->web_frame()->toWebRemoteFrame()->createLocalChild( |
138 blink::WebTreeScopeType::Document, "", blink::WebSandboxFlags::None, | 141 blink::WebTreeScopeType::Document, "", blink::WebSandboxFlags::None, |
139 this, previous_web_frame); | 142 this, previous_web_frame); |
140 CreateWebWidget(); | 143 CreateWebWidget(); |
141 } else if (parent_->web_frame()->isWebLocalFrame()) { | 144 } else if (parent_->web_frame()->isWebLocalFrame()) { |
142 blink::WebLocalFrame* local_web_frame = | 145 blink::WebLocalFrame* local_web_frame = |
143 blink::WebLocalFrame::create(blink::WebTreeScopeType::Document, this); | 146 blink::WebLocalFrame::create(blink::WebTreeScopeType::Document, this); |
144 parent_->web_frame()->appendChild(local_web_frame); | 147 parent_->web_frame()->appendChild(local_web_frame); |
145 blink::WebRemoteFrame* remote_web_frame = | 148 blink::WebRemoteFrame* remote_web_frame = |
146 blink::WebRemoteFrame::create(blink::WebTreeScopeType::Document, this); | 149 blink::WebRemoteFrame::create(blink::WebTreeScopeType::Document, this); |
147 // remote_web_frame->swap(local_web_frame); | 150 // remote_web_frame->swap(local_web_frame); |
148 local_web_frame->close(); | 151 local_web_frame->close(); |
149 web_frame_ = remote_web_frame; | 152 web_frame_ = remote_web_frame; |
150 } else { | 153 } else { |
151 web_frame_ = parent_->web_frame()->toWebRemoteFrame()->createRemoteChild( | 154 web_frame_ = parent_->web_frame()->toWebRemoteFrame()->createRemoteChild( |
152 blink::WebTreeScopeType::Document, "", blink::WebSandboxFlags::None, | 155 blink::WebTreeScopeType::Document, remote_frame_name, |
153 this); | 156 blink::WebSandboxFlags::None, this); |
| 157 } |
| 158 |
| 159 if (!IsLocal()) { |
| 160 blink::WebRemoteFrame* remote_web_frame = web_frame_->toWebRemoteFrame(); |
| 161 if (remote_web_frame) { |
| 162 remote_web_frame->setReplicatedName(remote_frame_name); |
| 163 remote_web_frame->setReplicatedOrigin( |
| 164 blink::WebSecurityOrigin::createFromString(remote_origin)); |
| 165 } |
154 } | 166 } |
155 } | 167 } |
156 | 168 |
157 void Frame::Close() { | 169 void Frame::Close() { |
158 if (web_widget_) { | 170 if (web_widget_) { |
159 // Closing the widget implicitly detaches the frame. | 171 // Closing the widget implicitly detaches the frame. |
160 web_widget_->close(); | 172 web_widget_->close(); |
161 } else { | 173 } else { |
162 web_frame_->detach(); | 174 web_frame_->detach(); |
163 } | 175 } |
(...skipping 28 matching lines...) Expand all Loading... |
192 parent_ = nullptr; | 204 parent_ = nullptr; |
193 | 205 |
194 frame_tree_manager_->OnFrameDestroyed(this); | 206 frame_tree_manager_->OnFrameDestroyed(this); |
195 | 207 |
196 if (view_) { | 208 if (view_) { |
197 view_->RemoveObserver(this); | 209 view_->RemoveObserver(this); |
198 view_->Destroy(); | 210 view_->Destroy(); |
199 } | 211 } |
200 } | 212 } |
201 | 213 |
| 214 void Frame::SetRemoteFrameName(const mojo::String& name) { |
| 215 if (IsLocal()) |
| 216 return; |
| 217 |
| 218 blink::WebRemoteFrame* remote_frame = web_frame_->toWebRemoteFrame(); |
| 219 if (remote_frame) |
| 220 remote_frame->setReplicatedName(name.To<blink::WebString>()); |
| 221 } |
| 222 |
202 bool Frame::IsLocal() const { | 223 bool Frame::IsLocal() const { |
203 return web_frame_->isWebLocalFrame(); | 224 return web_frame_->isWebLocalFrame(); |
204 } | 225 } |
205 | 226 |
206 void Frame::SetView(mojo::View* view) { | 227 void Frame::SetView(mojo::View* view) { |
207 DCHECK(!view_); | 228 DCHECK(!view_); |
208 view_ = view; | 229 view_ = view; |
209 view_->AddObserver(this); | 230 view_->AddObserver(this); |
210 } | 231 } |
211 | 232 |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
483 } | 504 } |
484 | 505 |
485 void Frame::didStopLoading() { | 506 void Frame::didStopLoading() { |
486 frame_tree_manager_->LoadingStopped(); | 507 frame_tree_manager_->LoadingStopped(); |
487 } | 508 } |
488 | 509 |
489 void Frame::didChangeLoadProgress(double load_progress) { | 510 void Frame::didChangeLoadProgress(double load_progress) { |
490 frame_tree_manager_->ProgressChanged(load_progress); | 511 frame_tree_manager_->ProgressChanged(load_progress); |
491 } | 512 } |
492 | 513 |
| 514 void Frame::didChangeName(blink::WebLocalFrame* frame, |
| 515 const blink::WebString& name) { |
| 516 frame_tree_manager_->OnFrameDidChangeName(this, name); |
| 517 } |
| 518 |
493 void Frame::frameDetached(blink::WebRemoteFrameClient::DetachType type) { | 519 void Frame::frameDetached(blink::WebRemoteFrameClient::DetachType type) { |
494 if (type == blink::WebRemoteFrameClient::DetachType::Swap) { | 520 if (type == blink::WebRemoteFrameClient::DetachType::Swap) { |
495 web_frame_->close(); | 521 web_frame_->close(); |
496 return; | 522 return; |
497 } | 523 } |
498 | 524 |
499 DCHECK(type == blink::WebRemoteFrameClient::DetachType::Remove); | 525 DCHECK(type == blink::WebRemoteFrameClient::DetachType::Remove); |
500 FrameDetachedImpl(web_frame_); | 526 FrameDetachedImpl(web_frame_); |
501 } | 527 } |
502 | 528 |
(...skipping 22 matching lines...) Expand all Loading... |
525 | 551 |
526 void Frame::reload(bool ignore_cache, bool is_client_redirect) { | 552 void Frame::reload(bool ignore_cache, bool is_client_redirect) { |
527 NOTIMPLEMENTED(); | 553 NOTIMPLEMENTED(); |
528 } | 554 } |
529 | 555 |
530 void Frame::forwardInputEvent(const blink::WebInputEvent* event) { | 556 void Frame::forwardInputEvent(const blink::WebInputEvent* event) { |
531 NOTIMPLEMENTED(); | 557 NOTIMPLEMENTED(); |
532 } | 558 } |
533 | 559 |
534 } // namespace mojo | 560 } // namespace mojo |
OLD | NEW |