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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
43 #include "mojo/common/common_type_converters.h" | 43 #include "mojo/common/common_type_converters.h" |
44 #include "mojo/converters/geometry/geometry_type_converters.h" | 44 #include "mojo/converters/geometry/geometry_type_converters.h" |
45 #include "skia/ext/refptr.h" | 45 #include "skia/ext/refptr.h" |
46 #include "third_party/WebKit/public/platform/Platform.h" | 46 #include "third_party/WebKit/public/platform/Platform.h" |
47 #include "third_party/WebKit/public/platform/WebHTTPHeaderVisitor.h" | 47 #include "third_party/WebKit/public/platform/WebHTTPHeaderVisitor.h" |
48 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h" | 48 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h" |
49 #include "third_party/WebKit/public/platform/WebSize.h" | 49 #include "third_party/WebKit/public/platform/WebSize.h" |
50 #include "third_party/WebKit/public/web/WebConsoleMessage.h" | 50 #include "third_party/WebKit/public/web/WebConsoleMessage.h" |
51 #include "third_party/WebKit/public/web/WebDocument.h" | 51 #include "third_party/WebKit/public/web/WebDocument.h" |
52 #include "third_party/WebKit/public/web/WebElement.h" | 52 #include "third_party/WebKit/public/web/WebElement.h" |
53 #include "third_party/WebKit/public/web/WebFindOptions.h" | |
53 #include "third_party/WebKit/public/web/WebInputEvent.h" | 54 #include "third_party/WebKit/public/web/WebInputEvent.h" |
54 #include "third_party/WebKit/public/web/WebKit.h" | 55 #include "third_party/WebKit/public/web/WebKit.h" |
55 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 56 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
56 #include "third_party/WebKit/public/web/WebNavigationPolicy.h" | 57 #include "third_party/WebKit/public/web/WebNavigationPolicy.h" |
57 #include "third_party/WebKit/public/web/WebRemoteFrame.h" | 58 #include "third_party/WebKit/public/web/WebRemoteFrame.h" |
58 #include "third_party/WebKit/public/web/WebRemoteFrameClient.h" | 59 #include "third_party/WebKit/public/web/WebRemoteFrameClient.h" |
59 #include "third_party/WebKit/public/web/WebScriptSource.h" | 60 #include "third_party/WebKit/public/web/WebScriptSource.h" |
60 #include "third_party/WebKit/public/web/WebView.h" | 61 #include "third_party/WebKit/public/web/WebView.h" |
61 #include "third_party/mojo/src/mojo/public/cpp/system/data_pipe.h" | 62 #include "third_party/mojo/src/mojo/public/cpp/system/data_pipe.h" |
62 #include "third_party/skia/include/core/SkCanvas.h" | 63 #include "third_party/skia/include/core/SkCanvas.h" |
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
496 blink::WebTextDirection direction) { | 497 blink::WebTextDirection direction) { |
497 // TODO(beng): handle |direction|. | 498 // TODO(beng): handle |direction|. |
498 mojo::String formatted; | 499 mojo::String formatted; |
499 if (!title.isNull()) { | 500 if (!title.isNull()) { |
500 formatted = | 501 formatted = |
501 mojo::String::From(base::string16(title).substr(0, kMaxTitleChars)); | 502 mojo::String::From(base::string16(title).substr(0, kMaxTitleChars)); |
502 } | 503 } |
503 server_->TitleChanged(formatted); | 504 server_->TitleChanged(formatted); |
504 } | 505 } |
505 | 506 |
507 void HTMLFrame::reportFindInFrameMatchCount(int identifier, | |
508 int count, | |
509 bool finalUpdate) { | |
510 server_->OnReportFindInFrameMatchCount(identifier, count, finalUpdate); | |
511 } | |
512 | |
513 void HTMLFrame::reportFindInPageSelection(int identifier, | |
514 int activeMatchOrdinal, | |
515 const blink::WebRect& selection) { | |
516 server_->OnReportFindInPageSelection(identifier, activeMatchOrdinal); | |
517 } | |
518 | |
506 void HTMLFrame::Bind( | 519 void HTMLFrame::Bind( |
507 web_view::mojom::FramePtr frame, | 520 web_view::mojom::FramePtr frame, |
508 mojo::InterfaceRequest<web_view::mojom::FrameClient> frame_client_request) { | 521 mojo::InterfaceRequest<web_view::mojom::FrameClient> frame_client_request) { |
509 DCHECK(IsLocal()); | 522 DCHECK(IsLocal()); |
510 server_ = frame.Pass(); | 523 server_ = frame.Pass(); |
511 server_.set_connection_error_handler( | 524 server_.set_connection_error_handler( |
512 base::Bind(&HTMLFrame::Close, base::Unretained(this))); | 525 base::Bind(&HTMLFrame::Close, base::Unretained(this))); |
513 frame_client_binding_.reset(new mojo::Binding<web_view::mojom::FrameClient>( | 526 frame_client_binding_.reset(new mojo::Binding<web_view::mojom::FrameClient>( |
514 this, frame_client_request.Pass())); | 527 this, frame_client_request.Pass())); |
515 } | 528 } |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
655 web_layer_.reset(); | 668 web_layer_.reset(); |
656 } | 669 } |
657 | 670 |
658 void HTMLFrame::SwapDelegate(HTMLFrameDelegate* delegate) { | 671 void HTMLFrame::SwapDelegate(HTMLFrameDelegate* delegate) { |
659 DCHECK(IsLocal()); | 672 DCHECK(IsLocal()); |
660 HTMLFrameDelegate* old_delegate = delegate_; | 673 HTMLFrameDelegate* old_delegate = delegate_; |
661 delegate_ = delegate; | 674 delegate_ = delegate; |
662 delegate->OnSwap(this, old_delegate); | 675 delegate->OnSwap(this, old_delegate); |
663 } | 676 } |
664 | 677 |
678 blink::WebElement HTMLFrame::GetFocusedElement() { | |
679 if (!web_view()) | |
680 return blink::WebElement(); | |
681 | |
682 HTMLFrame* frame = this; | |
683 while (frame) { | |
684 if (frame->web_view()) { | |
685 if (frame->web_view()->focusedFrame() == web_frame_) { | |
686 blink::WebDocument doc = web_frame_->document(); | |
687 if (!doc.isNull()) | |
688 return doc.focusedElement(); | |
689 } | |
690 return blink::WebElement(); | |
691 } | |
692 frame = frame->parent(); | |
693 } | |
694 | |
695 return blink::WebElement(); | |
696 } | |
697 | |
665 HTMLFrame* HTMLFrame::FindFrameWithWebFrame(blink::WebFrame* web_frame) { | 698 HTMLFrame* HTMLFrame::FindFrameWithWebFrame(blink::WebFrame* web_frame) { |
666 if (web_frame_ == web_frame) | 699 if (web_frame_ == web_frame) |
667 return this; | 700 return this; |
668 for (HTMLFrame* child_frame : children_) { | 701 for (HTMLFrame* child_frame : children_) { |
669 HTMLFrame* result = child_frame->FindFrameWithWebFrame(web_frame); | 702 HTMLFrame* result = child_frame->FindFrameWithWebFrame(web_frame); |
670 if (result) | 703 if (result) |
671 return result; | 704 return result; |
672 } | 705 } |
673 return nullptr; | 706 return nullptr; |
674 } | 707 } |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
850 frame->web_frame_->toWebRemoteFrame()->didStopLoading(); | 883 frame->web_frame_->toWebRemoteFrame()->didStopLoading(); |
851 } | 884 } |
852 } | 885 } |
853 | 886 |
854 void HTMLFrame::OnDispatchFrameLoadEvent(uint32_t frame_id) { | 887 void HTMLFrame::OnDispatchFrameLoadEvent(uint32_t frame_id) { |
855 HTMLFrame* frame = frame_tree_manager_->root_->FindFrame(frame_id); | 888 HTMLFrame* frame = frame_tree_manager_->root_->FindFrame(frame_id); |
856 if (frame && !frame->IsLocal()) | 889 if (frame && !frame->IsLocal()) |
857 frame->web_frame_->toWebRemoteFrame()->DispatchLoadEventForFrameOwner(); | 890 frame->web_frame_->toWebRemoteFrame()->DispatchLoadEventForFrameOwner(); |
858 } | 891 } |
859 | 892 |
893 void HTMLFrame::Find(int32 request_id, | |
894 const mojo::String& search_text, | |
sky
2015/10/05 15:55:08
What should happen if search_text is empty? Either
Elliot Glaysher
2015/10/05 20:43:50
When search text is empty (this happens all the ti
| |
895 const FindCallback& callback) { | |
896 // TODO(erg): We need to synchronize whether we're a singleton frame here | |
897 // with the parent; we can't trust our state. | |
898 bool wrap_within_frame = false; | |
899 | |
900 blink::WebFindOptions options; | |
901 blink::WebRect selection_rect; | |
902 bool result = web_frame_->find(request_id, search_text.To<blink::WebString>(), | |
903 options, wrap_within_frame, &selection_rect); | |
904 if (!result) { | |
905 // don't leave text selected as you move to the next frame. | |
906 web_frame_->executeCommand(blink::WebString::fromUTF8("Unselect"), | |
907 GetFocusedElement()); | |
908 } | |
909 | |
910 callback.Run(result); | |
911 } | |
912 | |
913 void HTMLFrame::StopFinding(bool clear_selection) { | |
914 // TODO(erg): |clear_selection| isn't correct; this should be a state enum | |
915 // that lets us STOP_FIND_ACTION_ACTIVATE_SELECTION, too. | |
916 if (clear_selection) { | |
917 web_frame_->executeCommand(blink::WebString::fromUTF8("Unselect"), | |
sky
2015/10/05 15:55:08
What happens if Find() was invoked, something was
Elliot Glaysher
2015/10/05 20:43:50
Added check to ensure focused element is part of w
| |
918 GetFocusedElement()); | |
919 } | |
920 | |
921 web_frame_->stopFinding(clear_selection); | |
922 } | |
923 | |
924 void HTMLFrame::ScopeStringMatches(int32_t request_id, | |
925 const mojo::String& search_text, | |
926 bool reset) { | |
927 blink::WebFindOptions options; | |
928 web_frame_->scopeStringMatches(request_id, search_text.To<blink::WebString>(), | |
929 options, reset); | |
930 } | |
931 | |
932 void HTMLFrame::CancelPendingScopingEffort() { | |
933 web_frame_->resetMatchCount(); | |
934 web_frame_->cancelPendingScopingEffort(); | |
935 } | |
936 | |
860 void HTMLFrame::frameDetached(blink::WebRemoteFrameClient::DetachType type) { | 937 void HTMLFrame::frameDetached(blink::WebRemoteFrameClient::DetachType type) { |
861 if (type == blink::WebRemoteFrameClient::DetachType::Swap) { | 938 if (type == blink::WebRemoteFrameClient::DetachType::Swap) { |
862 web_frame_->close(); | 939 web_frame_->close(); |
863 return; | 940 return; |
864 } | 941 } |
865 | 942 |
866 DCHECK(type == blink::WebRemoteFrameClient::DetachType::Remove); | 943 DCHECK(type == blink::WebRemoteFrameClient::DetachType::Remove); |
867 FrameDetachedImpl(web_frame_); | 944 FrameDetachedImpl(web_frame_); |
868 } | 945 } |
869 | 946 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
930 if (!surface_layer_) | 1007 if (!surface_layer_) |
931 return; | 1008 return; |
932 | 1009 |
933 surface_layer_->SetSurfaceId( | 1010 surface_layer_->SetSurfaceId( |
934 cc::SurfaceId(owned_view_->view()->id()), | 1011 cc::SurfaceId(owned_view_->view()->id()), |
935 global_state()->device_pixel_ratio(), | 1012 global_state()->device_pixel_ratio(), |
936 owned_view_->view()->bounds().To<gfx::Rect>().size()); | 1013 owned_view_->view()->bounds().To<gfx::Rect>().size()); |
937 } | 1014 } |
938 | 1015 |
939 } // namespace mojo | 1016 } // namespace mojo |
OLD | NEW |