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/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" |
| 11 #include "base/single_thread_task_runner.h" | 11 #include "base/single_thread_task_runner.h" |
| 12 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
| 13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
| 14 #include "base/thread_task_runner_handle.h" | 14 #include "base/thread_task_runner_handle.h" |
| 15 #include "cc/blink/web_layer_impl.h" | |
| 16 #include "cc/surfaces/surface_id.h" | |
| 15 #include "components/html_viewer/ax_provider_impl.h" | 17 #include "components/html_viewer/ax_provider_impl.h" |
| 16 #include "components/html_viewer/blink_basic_type_converters.h" | 18 #include "components/html_viewer/blink_basic_type_converters.h" |
| 17 #include "components/html_viewer/blink_input_events_type_converters.h" | 19 #include "components/html_viewer/blink_input_events_type_converters.h" |
| 18 #include "components/html_viewer/blink_text_input_type_converters.h" | 20 #include "components/html_viewer/blink_text_input_type_converters.h" |
| 19 #include "components/html_viewer/blink_url_request_type_converters.h" | 21 #include "components/html_viewer/blink_url_request_type_converters.h" |
| 20 #include "components/html_viewer/devtools_agent_impl.h" | 22 #include "components/html_viewer/devtools_agent_impl.h" |
| 21 #include "components/html_viewer/geolocation_client_impl.h" | 23 #include "components/html_viewer/geolocation_client_impl.h" |
| 22 #include "components/html_viewer/global_state.h" | 24 #include "components/html_viewer/global_state.h" |
| 23 #include "components/html_viewer/html_factory.h" | 25 #include "components/html_viewer/html_factory.h" |
| 24 #include "components/html_viewer/html_frame_delegate.h" | 26 #include "components/html_viewer/html_frame_delegate.h" |
| 25 #include "components/html_viewer/html_frame_properties.h" | 27 #include "components/html_viewer/html_frame_properties.h" |
| 26 #include "components/html_viewer/html_frame_tree_manager.h" | 28 #include "components/html_viewer/html_frame_tree_manager.h" |
| 27 #include "components/html_viewer/html_widget.h" | 29 #include "components/html_viewer/html_widget.h" |
| 28 #include "components/html_viewer/media_factory.h" | 30 #include "components/html_viewer/media_factory.h" |
| 29 #include "components/html_viewer/stats_collection_controller.h" | 31 #include "components/html_viewer/stats_collection_controller.h" |
| 30 #include "components/html_viewer/touch_handler.h" | 32 #include "components/html_viewer/touch_handler.h" |
| 31 #include "components/html_viewer/web_layer_impl.h" | |
| 32 #include "components/html_viewer/web_layer_tree_view_impl.h" | 33 #include "components/html_viewer/web_layer_tree_view_impl.h" |
| 33 #include "components/html_viewer/web_storage_namespace_impl.h" | 34 #include "components/html_viewer/web_storage_namespace_impl.h" |
| 34 #include "components/html_viewer/web_url_loader_impl.h" | 35 #include "components/html_viewer/web_url_loader_impl.h" |
| 35 #include "components/mus/ids.h" | 36 #include "components/mus/ids.h" |
| 36 #include "components/mus/public/cpp/scoped_view_ptr.h" | 37 #include "components/mus/public/cpp/scoped_view_ptr.h" |
| 37 #include "components/mus/public/cpp/view.h" | 38 #include "components/mus/public/cpp/view.h" |
| 38 #include "components/mus/public/cpp/view_tree_connection.h" | 39 #include "components/mus/public/cpp/view_tree_connection.h" |
| 39 #include "mojo/application/public/cpp/application_impl.h" | 40 #include "mojo/application/public/cpp/application_impl.h" |
| 40 #include "mojo/application/public/cpp/connect.h" | 41 #include "mojo/application/public/cpp/connect.h" |
| 41 #include "mojo/application/public/interfaces/shell.mojom.h" | 42 #include "mojo/application/public/interfaces/shell.mojom.h" |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 95 } | 96 } |
| 96 } | 97 } |
| 97 | 98 |
| 98 HTMLFrame* GetPreviousSibling(HTMLFrame* frame) { | 99 HTMLFrame* GetPreviousSibling(HTMLFrame* frame) { |
| 99 DCHECK(frame->parent()); | 100 DCHECK(frame->parent()); |
| 100 auto iter = std::find(frame->parent()->children().begin(), | 101 auto iter = std::find(frame->parent()->children().begin(), |
| 101 frame->parent()->children().end(), frame); | 102 frame->parent()->children().end(), frame); |
| 102 return (iter == frame->parent()->children().begin()) ? nullptr : *(--iter); | 103 return (iter == frame->parent()->children().begin()) ? nullptr : *(--iter); |
| 103 } | 104 } |
| 104 | 105 |
| 106 // See surface_layer.h for a description of this callback. | |
| 107 void SatisfyCallback(cc::SurfaceSequence sequence) { | |
| 108 // TODO(fsamuel): Implement this. | |
| 109 } | |
| 110 | |
| 111 // See surface_layer.h for a description of this callback. | |
| 112 void RequireCallback(cc::SurfaceId surface_id, | |
| 113 cc::SurfaceSequence sequence) { | |
| 114 // TODO(fsamuel): Implement this. | |
| 115 } | |
| 116 | |
| 105 } // namespace | 117 } // namespace |
| 106 | 118 |
| 107 HTMLFrame::HTMLFrame(CreateParams* params) | 119 HTMLFrame::HTMLFrame(CreateParams* params) |
| 108 : frame_tree_manager_(params->manager), | 120 : frame_tree_manager_(params->manager), |
| 109 parent_(params->parent), | 121 parent_(params->parent), |
| 110 view_(nullptr), | 122 view_(nullptr), |
| 111 id_(params->id), | 123 id_(params->id), |
| 112 web_frame_(nullptr), | 124 web_frame_(nullptr), |
| 113 delegate_(params->delegate), | 125 delegate_(params->delegate), |
| 114 weak_factory_(this) { | 126 weak_factory_(this) { |
| (...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 560 | 572 |
| 561 HTMLFrameDelegate* delegate = delegate_; | 573 HTMLFrameDelegate* delegate = delegate_; |
| 562 delegate_ = nullptr; | 574 delegate_ = nullptr; |
| 563 | 575 |
| 564 blink::WebRemoteFrame* remote_frame = | 576 blink::WebRemoteFrame* remote_frame = |
| 565 blink::WebRemoteFrame::create(state_.tree_scope, this); | 577 blink::WebRemoteFrame::create(state_.tree_scope, this); |
| 566 remote_frame->initializeFromFrame(web_frame_->toWebLocalFrame()); | 578 remote_frame->initializeFromFrame(web_frame_->toWebLocalFrame()); |
| 567 // swap() ends up calling us back and we then close the frame, which deletes | 579 // swap() ends up calling us back and we then close the frame, which deletes |
| 568 // it. | 580 // it. |
| 569 web_frame_->swap(remote_frame); | 581 web_frame_->swap(remote_frame); |
| 570 // TODO(sky): this isn't quite right, but WebLayerImpl is temporary. | |
| 571 if (owned_view_) { | 582 if (owned_view_) { |
| 572 web_layer_.reset( | 583 surface_layer_ = |
| 573 new WebLayerImpl(owned_view_->view(), | 584 cc::SurfaceLayer::Create(cc_blink::WebLayerImpl::LayerSettings(), |
| 574 global_state()->device_pixel_ratio())); | 585 base::Bind(&SatisfyCallback), |
| 586 base::Bind(&RequireCallback)); | |
| 587 surface_layer_->SetSurfaceId(cc::SurfaceId(owned_view_->view()->id()), | |
| 588 global_state()->device_pixel_ratio(), | |
| 589 frame_size_in_pixels_); | |
|
sky
2015/09/28 15:29:09
Why do we need frame_size_in_pixels_ as a member?
Fady Samuel
2015/09/28 15:57:00
Done.
| |
| 590 | |
| 591 web_layer_.reset(new cc_blink::WebLayerImpl(surface_layer_)); | |
| 575 } | 592 } |
| 576 remote_frame->setRemoteWebLayer(web_layer_.get()); | 593 remote_frame->setRemoteWebLayer(web_layer_.get()); |
| 577 remote_frame->setReplicatedName(state_.name); | 594 remote_frame->setReplicatedName(state_.name); |
| 578 remote_frame->setReplicatedOrigin(state_.origin); | 595 remote_frame->setReplicatedOrigin(state_.origin); |
| 579 remote_frame->setReplicatedSandboxFlags(state_.sandbox_flags); | 596 remote_frame->setReplicatedSandboxFlags(state_.sandbox_flags); |
| 580 // Tell the frame that it is actually loading. This prevents its parent | 597 // Tell the frame that it is actually loading. This prevents its parent |
| 581 // from prematurely dispatching load event. | 598 // from prematurely dispatching load event. |
| 582 remote_frame->didStartLoading(); | 599 remote_frame->didStartLoading(); |
| 583 web_frame_ = remote_frame; | 600 web_frame_ = remote_frame; |
| 584 SetView(nullptr); | 601 SetView(nullptr); |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 839 event.Pass()); | 856 event.Pass()); |
| 840 } | 857 } |
| 841 | 858 |
| 842 void HTMLFrame::initializeChildFrame(const blink::WebRect& frame_rect, | 859 void HTMLFrame::initializeChildFrame(const blink::WebRect& frame_rect, |
| 843 float scale_factor) { | 860 float scale_factor) { |
| 844 // NOTE: |scale_factor| is always 1. | 861 // NOTE: |scale_factor| is always 1. |
| 845 const gfx::Rect rect_in_dip(frame_rect.x, frame_rect.y, frame_rect.width, | 862 const gfx::Rect rect_in_dip(frame_rect.x, frame_rect.y, frame_rect.width, |
| 846 frame_rect.height); | 863 frame_rect.height); |
| 847 const gfx::Rect rect_in_pixels(gfx::ConvertRectToPixel( | 864 const gfx::Rect rect_in_pixels(gfx::ConvertRectToPixel( |
| 848 global_state()->device_pixel_ratio(), rect_in_dip)); | 865 global_state()->device_pixel_ratio(), rect_in_dip)); |
| 866 frame_size_in_pixels_ = rect_in_pixels.size(); | |
| 849 const mojo::RectPtr mojo_rect_in_pixels(mojo::Rect::From(rect_in_pixels)); | 867 const mojo::RectPtr mojo_rect_in_pixels(mojo::Rect::From(rect_in_pixels)); |
| 850 view_->SetBounds(*mojo_rect_in_pixels); | 868 view_->SetBounds(*mojo_rect_in_pixels); |
| 851 } | 869 } |
| 852 | 870 |
| 853 void HTMLFrame::navigate(const blink::WebURLRequest& request, | 871 void HTMLFrame::navigate(const blink::WebURLRequest& request, |
| 854 bool should_replace_current_entry) { | 872 bool should_replace_current_entry) { |
| 855 // TODO: support |should_replace_current_entry|. | 873 // TODO: support |should_replace_current_entry|. |
| 856 NOTIMPLEMENTED(); // for |should_replace_current_entry | 874 NOTIMPLEMENTED(); // for |should_replace_current_entry |
| 857 mojo::URLRequestPtr url_request = mojo::URLRequest::From(request); | 875 mojo::URLRequestPtr url_request = mojo::URLRequest::From(request); |
| 858 GetServerFrame()->RequestNavigate( | 876 GetServerFrame()->RequestNavigate( |
| 859 web_view::mojom::NAVIGATION_TARGET_TYPE_EXISTING_FRAME, id_, | 877 web_view::mojom::NAVIGATION_TARGET_TYPE_EXISTING_FRAME, id_, |
| 860 url_request.Pass()); | 878 url_request.Pass()); |
| 861 } | 879 } |
| 862 | 880 |
| 863 void HTMLFrame::reload(bool ignore_cache, bool is_client_redirect) { | 881 void HTMLFrame::reload(bool ignore_cache, bool is_client_redirect) { |
| 864 NOTIMPLEMENTED(); | 882 NOTIMPLEMENTED(); |
| 865 } | 883 } |
| 866 | 884 |
| 867 void HTMLFrame::forwardInputEvent(const blink::WebInputEvent* event) { | 885 void HTMLFrame::frameRectsChanged(const blink::WebRect& rect) { |
| 868 NOTIMPLEMENTED(); | 886 // TODO(fsamuel): The content of the iframe should also resize. |
| 887 frame_size_in_pixels_ = | |
| 888 gfx::ScaleToCeiledSize(gfx::Size(rect.width, rect.height), | |
| 889 global_state()->device_pixel_ratio()); | |
| 890 | |
| 891 if (!surface_layer_) | |
| 892 return; | |
| 893 surface_layer_->SetSurfaceId(cc::SurfaceId(owned_view_->view()->id()), | |
| 894 global_state()->device_pixel_ratio(), | |
| 895 frame_size_in_pixels_); | |
| 869 } | 896 } |
| 870 | 897 |
| 871 } // namespace mojo | 898 } // namespace mojo |
| OLD | NEW |