| 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/html_frame.h" | 5 #include "components/html_viewer/html_frame.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <limits> | 8 #include <limits> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 #include "ui/gfx/geometry/dip_util.h" | 64 #include "ui/gfx/geometry/dip_util.h" |
| 65 #include "ui/gfx/geometry/size.h" | 65 #include "ui/gfx/geometry/size.h" |
| 66 #include "url/gurl.h" | 66 #include "url/gurl.h" |
| 67 #include "url/origin.h" | 67 #include "url/origin.h" |
| 68 #include "url/url_constants.h" | 68 #include "url/url_constants.h" |
| 69 | 69 |
| 70 using mojo::AxProvider; | 70 using mojo::AxProvider; |
| 71 using mojo::Rect; | 71 using mojo::Rect; |
| 72 using mojo::ServiceProviderPtr; | 72 using mojo::ServiceProviderPtr; |
| 73 using mojo::URLResponsePtr; | 73 using mojo::URLResponsePtr; |
| 74 using mojo::View; | 74 using mus::View; |
| 75 using web_view::HTMLMessageEvent; | 75 using web_view::HTMLMessageEvent; |
| 76 using web_view::HTMLMessageEventPtr; | 76 using web_view::HTMLMessageEventPtr; |
| 77 | 77 |
| 78 namespace html_viewer { | 78 namespace html_viewer { |
| 79 namespace { | 79 namespace { |
| 80 | 80 |
| 81 const size_t kMaxTitleChars = 4 * 1024; | 81 const size_t kMaxTitleChars = 4 * 1024; |
| 82 | 82 |
| 83 web_view::NavigationTargetType WebNavigationPolicyToNavigationTarget( | 83 web_view::NavigationTargetType WebNavigationPolicyToNavigationTarget( |
| 84 blink::WebNavigationPolicy policy) { | 84 blink::WebNavigationPolicy policy) { |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 } | 268 } |
| 269 parent_ = nullptr; | 269 parent_ = nullptr; |
| 270 | 270 |
| 271 frame_tree_manager_->OnFrameDestroyed(this); | 271 frame_tree_manager_->OnFrameDestroyed(this); |
| 272 | 272 |
| 273 if (delegate_) | 273 if (delegate_) |
| 274 delegate_->OnFrameDestroyed(); | 274 delegate_->OnFrameDestroyed(); |
| 275 | 275 |
| 276 if (view_) { | 276 if (view_) { |
| 277 view_->RemoveObserver(this); | 277 view_->RemoveObserver(this); |
| 278 mojo::ScopedViewPtr::DeleteViewOrViewManager(view_); | 278 mus::ScopedViewPtr::DeleteViewOrViewManager(view_); |
| 279 } | 279 } |
| 280 } | 280 } |
| 281 | 281 |
| 282 blink::WebMediaPlayer* HTMLFrame::createMediaPlayer( | 282 blink::WebMediaPlayer* HTMLFrame::createMediaPlayer( |
| 283 blink::WebLocalFrame* frame, | 283 blink::WebLocalFrame* frame, |
| 284 const blink::WebURL& url, | 284 const blink::WebURL& url, |
| 285 blink::WebMediaPlayerClient* client, | 285 blink::WebMediaPlayerClient* client, |
| 286 blink::WebMediaPlayerEncryptedMediaClient* encrypted_client, | 286 blink::WebMediaPlayerEncryptedMediaClient* encrypted_client, |
| 287 blink::WebContentDecryptionModule* initial_cdm) { | 287 blink::WebContentDecryptionModule* initial_cdm) { |
| 288 return global_state()->media_factory()->CreateMediaPlayer( | 288 return global_state()->media_factory()->CreateMediaPlayer( |
| 289 frame, url, client, encrypted_client, initial_cdm, | 289 frame, url, client, encrypted_client, initial_cdm, |
| 290 GetLocalRootApp()->shell()); | 290 GetLocalRootApp()->shell()); |
| 291 } | 291 } |
| 292 | 292 |
| 293 blink::WebFrame* HTMLFrame::createChildFrame( | 293 blink::WebFrame* HTMLFrame::createChildFrame( |
| 294 blink::WebLocalFrame* parent, | 294 blink::WebLocalFrame* parent, |
| 295 blink::WebTreeScopeType scope, | 295 blink::WebTreeScopeType scope, |
| 296 const blink::WebString& frame_name, | 296 const blink::WebString& frame_name, |
| 297 blink::WebSandboxFlags sandbox_flags) { | 297 blink::WebSandboxFlags sandbox_flags) { |
| 298 DCHECK(IsLocal()); // Can't create children of remote frames. | 298 DCHECK(IsLocal()); // Can't create children of remote frames. |
| 299 DCHECK_EQ(parent, web_frame_); | 299 DCHECK_EQ(parent, web_frame_); |
| 300 DCHECK(view_); // If we're local we have to have a view. | 300 DCHECK(view_); // If we're local we have to have a view. |
| 301 // Create the view that will house the frame now. We embed once we know the | 301 // Create the view that will house the frame now. We embed once we know the |
| 302 // url (see decidePolicyForNavigation()). | 302 // url (see decidePolicyForNavigation()). |
| 303 mojo::View* child_view = view_->connection()->CreateView(); | 303 mus::View* child_view = view_->connection()->CreateView(); |
| 304 ReplicatedFrameState child_state; | 304 ReplicatedFrameState child_state; |
| 305 child_state.name = frame_name; | 305 child_state.name = frame_name; |
| 306 child_state.tree_scope = scope; | 306 child_state.tree_scope = scope; |
| 307 child_state.sandbox_flags = sandbox_flags; | 307 child_state.sandbox_flags = sandbox_flags; |
| 308 mojo::Map<mojo::String, mojo::Array<uint8_t>> client_properties; | 308 mojo::Map<mojo::String, mojo::Array<uint8_t>> client_properties; |
| 309 client_properties.mark_non_null(); | 309 client_properties.mark_non_null(); |
| 310 ClientPropertiesFromReplicatedFrameState(child_state, &client_properties); | 310 ClientPropertiesFromReplicatedFrameState(child_state, &client_properties); |
| 311 | 311 |
| 312 child_view->SetVisible(true); | 312 child_view->SetVisible(true); |
| 313 view_->AddChild(child_view); | 313 view_->AddChild(child_view); |
| 314 | 314 |
| 315 GetLocalRoot()->server_->OnCreatedFrame(id_, child_view->id(), | 315 GetLocalRoot()->server_->OnCreatedFrame(id_, child_view->id(), |
| 316 client_properties.Pass()); | 316 client_properties.Pass()); |
| 317 | 317 |
| 318 HTMLFrame::CreateParams params(frame_tree_manager_, this, child_view->id(), | 318 HTMLFrame::CreateParams params(frame_tree_manager_, this, child_view->id(), |
| 319 child_view, client_properties, nullptr); | 319 child_view, client_properties, nullptr); |
| 320 params.allow_local_shared_frame = true; | 320 params.allow_local_shared_frame = true; |
| 321 HTMLFrame* child_frame = | 321 HTMLFrame* child_frame = |
| 322 GetLocalRoot()->delegate_->GetHTMLFactory()->CreateHTMLFrame(¶ms); | 322 GetLocalRoot()->delegate_->GetHTMLFactory()->CreateHTMLFrame(¶ms); |
| 323 child_frame->owned_view_.reset(new mojo::ScopedViewPtr(child_view)); | 323 child_frame->owned_view_.reset(new mus::ScopedViewPtr(child_view)); |
| 324 return child_frame->web_frame_; | 324 return child_frame->web_frame_; |
| 325 } | 325 } |
| 326 | 326 |
| 327 void HTMLFrame::frameDetached(blink::WebFrame* web_frame, | 327 void HTMLFrame::frameDetached(blink::WebFrame* web_frame, |
| 328 blink::WebFrameClient::DetachType type) { | 328 blink::WebFrameClient::DetachType type) { |
| 329 if (type == blink::WebFrameClient::DetachType::Swap) { | 329 if (type == blink::WebFrameClient::DetachType::Swap) { |
| 330 web_frame->close(); | 330 web_frame->close(); |
| 331 return; | 331 return; |
| 332 } | 332 } |
| 333 | 333 |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 487 // Prefer the local root. | 487 // Prefer the local root. |
| 488 HTMLFrame* local_root = GetLocalRoot(); | 488 HTMLFrame* local_root = GetLocalRoot(); |
| 489 if (local_root) | 489 if (local_root) |
| 490 return local_root->server_.get(); | 490 return local_root->server_.get(); |
| 491 | 491 |
| 492 // No local root. This means we're a remote frame with no local frame | 492 // No local root. This means we're a remote frame with no local frame |
| 493 // ancestors. Use the local frame from the FrameTreeServer. | 493 // ancestors. Use the local frame from the FrameTreeServer. |
| 494 return frame_tree_manager_->local_root_->server_.get(); | 494 return frame_tree_manager_->local_root_->server_.get(); |
| 495 } | 495 } |
| 496 | 496 |
| 497 void HTMLFrame::SetView(mojo::View* view) { | 497 void HTMLFrame::SetView(mus::View* view) { |
| 498 if (view_) | 498 if (view_) |
| 499 view_->RemoveObserver(this); | 499 view_->RemoveObserver(this); |
| 500 view_ = view; | 500 view_ = view; |
| 501 if (view_) | 501 if (view_) |
| 502 view_->AddObserver(this); | 502 view_->AddObserver(this); |
| 503 } | 503 } |
| 504 | 504 |
| 505 void HTMLFrame::CreateRootWebWidget() { | 505 void HTMLFrame::CreateRootWebWidget() { |
| 506 DCHECK(!html_widget_); | 506 DCHECK(!html_widget_); |
| 507 if (view_) { | 507 if (view_) { |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 554 remote_frame->setReplicatedOrigin(state_.origin); | 554 remote_frame->setReplicatedOrigin(state_.origin); |
| 555 remote_frame->setReplicatedSandboxFlags(state_.sandbox_flags); | 555 remote_frame->setReplicatedSandboxFlags(state_.sandbox_flags); |
| 556 web_frame_ = remote_frame; | 556 web_frame_ = remote_frame; |
| 557 SetView(nullptr); | 557 SetView(nullptr); |
| 558 if (delegate) | 558 if (delegate) |
| 559 delegate->OnFrameSwappedToRemote(); | 559 delegate->OnFrameSwappedToRemote(); |
| 560 } | 560 } |
| 561 | 561 |
| 562 void HTMLFrame::SwapToLocal( | 562 void HTMLFrame::SwapToLocal( |
| 563 HTMLFrameDelegate* delegate, | 563 HTMLFrameDelegate* delegate, |
| 564 mojo::View* view, | 564 mus::View* view, |
| 565 const mojo::Map<mojo::String, mojo::Array<uint8_t>>& properties) { | 565 const mojo::Map<mojo::String, mojo::Array<uint8_t>>& properties) { |
| 566 CHECK(!IsLocal()); | 566 CHECK(!IsLocal()); |
| 567 // It doesn't make sense for the root to swap to local. | 567 // It doesn't make sense for the root to swap to local. |
| 568 CHECK(parent_); | 568 CHECK(parent_); |
| 569 delegate_ = delegate; | 569 delegate_ = delegate; |
| 570 SetView(view); | 570 SetView(view); |
| 571 SetReplicatedFrameStateFromClientProperties(properties, &state_); | 571 SetReplicatedFrameStateFromClientProperties(properties, &state_); |
| 572 blink::WebLocalFrame* local_web_frame = | 572 blink::WebLocalFrame* local_web_frame = |
| 573 blink::WebLocalFrame::create(state_.tree_scope, this); | 573 blink::WebLocalFrame::create(state_.tree_scope, this); |
| 574 local_web_frame->initializeToReplaceRemoteFrame( | 574 local_web_frame->initializeToReplaceRemoteFrame( |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 655 | 655 |
| 656 if (!web_widget) | 656 if (!web_widget) |
| 657 return; | 657 return; |
| 658 | 658 |
| 659 scoped_ptr<blink::WebInputEvent> web_event = | 659 scoped_ptr<blink::WebInputEvent> web_event = |
| 660 event.To<scoped_ptr<blink::WebInputEvent>>(); | 660 event.To<scoped_ptr<blink::WebInputEvent>>(); |
| 661 if (web_event) | 661 if (web_event) |
| 662 web_widget->handleInputEvent(*web_event); | 662 web_widget->handleInputEvent(*web_event); |
| 663 } | 663 } |
| 664 | 664 |
| 665 void HTMLFrame::OnViewFocusChanged(mojo::View* gained_focus, | 665 void HTMLFrame::OnViewFocusChanged(mus::View* gained_focus, |
| 666 mojo::View* lost_focus) { | 666 mus::View* lost_focus) { |
| 667 UpdateFocus(); | 667 UpdateFocus(); |
| 668 } | 668 } |
| 669 | 669 |
| 670 void HTMLFrame::OnConnect(web_view::FrameTreeServerPtr server, | 670 void HTMLFrame::OnConnect(web_view::FrameTreeServerPtr server, |
| 671 uint32_t change_id, | 671 uint32_t change_id, |
| 672 uint32_t view_id, | 672 uint32_t view_id, |
| 673 web_view::ViewConnectType view_connect_type, | 673 web_view::ViewConnectType view_connect_type, |
| 674 mojo::Array<web_view::FrameDataPtr> frame_data, | 674 mojo::Array<web_view::FrameDataPtr> frame_data, |
| 675 const OnConnectCallback& callback) { | 675 const OnConnectCallback& callback) { |
| 676 // OnConnect() is only sent once, and has been received (by | 676 // OnConnect() is only sent once, and has been received (by |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 806 | 806 |
| 807 void HTMLFrame::reload(bool ignore_cache, bool is_client_redirect) { | 807 void HTMLFrame::reload(bool ignore_cache, bool is_client_redirect) { |
| 808 NOTIMPLEMENTED(); | 808 NOTIMPLEMENTED(); |
| 809 } | 809 } |
| 810 | 810 |
| 811 void HTMLFrame::forwardInputEvent(const blink::WebInputEvent* event) { | 811 void HTMLFrame::forwardInputEvent(const blink::WebInputEvent* event) { |
| 812 NOTIMPLEMENTED(); | 812 NOTIMPLEMENTED(); |
| 813 } | 813 } |
| 814 | 814 |
| 815 } // namespace mojo | 815 } // namespace mojo |
| OLD | NEW |