Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(162)

Side by Side Diff: components/html_viewer/html_frame.cc

Issue 1270313006: Connects PostMessage() for OOPIFs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix windows Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/html_viewer/html_frame.h ('k') | components/html_viewer/html_frame_apptest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 28 matching lines...) Expand all
39 #include "skia/ext/refptr.h" 39 #include "skia/ext/refptr.h"
40 #include "third_party/WebKit/public/platform/Platform.h" 40 #include "third_party/WebKit/public/platform/Platform.h"
41 #include "third_party/WebKit/public/platform/WebHTTPHeaderVisitor.h" 41 #include "third_party/WebKit/public/platform/WebHTTPHeaderVisitor.h"
42 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h" 42 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h"
43 #include "third_party/WebKit/public/platform/WebSize.h" 43 #include "third_party/WebKit/public/platform/WebSize.h"
44 #include "third_party/WebKit/public/web/WebConsoleMessage.h" 44 #include "third_party/WebKit/public/web/WebConsoleMessage.h"
45 #include "third_party/WebKit/public/web/WebDocument.h" 45 #include "third_party/WebKit/public/web/WebDocument.h"
46 #include "third_party/WebKit/public/web/WebElement.h" 46 #include "third_party/WebKit/public/web/WebElement.h"
47 #include "third_party/WebKit/public/web/WebFrameWidget.h" 47 #include "third_party/WebKit/public/web/WebFrameWidget.h"
48 #include "third_party/WebKit/public/web/WebInputEvent.h" 48 #include "third_party/WebKit/public/web/WebInputEvent.h"
49 #include "third_party/WebKit/public/web/WebKit.h"
49 #include "third_party/WebKit/public/web/WebLocalFrame.h" 50 #include "third_party/WebKit/public/web/WebLocalFrame.h"
50 #include "third_party/WebKit/public/web/WebNavigationPolicy.h" 51 #include "third_party/WebKit/public/web/WebNavigationPolicy.h"
51 #include "third_party/WebKit/public/web/WebRemoteFrame.h" 52 #include "third_party/WebKit/public/web/WebRemoteFrame.h"
52 #include "third_party/WebKit/public/web/WebRemoteFrameClient.h" 53 #include "third_party/WebKit/public/web/WebRemoteFrameClient.h"
53 #include "third_party/WebKit/public/web/WebScriptSource.h" 54 #include "third_party/WebKit/public/web/WebScriptSource.h"
54 #include "third_party/WebKit/public/web/WebSettings.h" 55 #include "third_party/WebKit/public/web/WebSettings.h"
55 #include "third_party/WebKit/public/web/WebView.h" 56 #include "third_party/WebKit/public/web/WebView.h"
56 #include "third_party/mojo/src/mojo/public/cpp/system/data_pipe.h" 57 #include "third_party/mojo/src/mojo/public/cpp/system/data_pipe.h"
57 #include "third_party/skia/include/core/SkCanvas.h" 58 #include "third_party/skia/include/core/SkCanvas.h"
58 #include "third_party/skia/include/core/SkColor.h" 59 #include "third_party/skia/include/core/SkColor.h"
59 #include "third_party/skia/include/core/SkDevice.h" 60 #include "third_party/skia/include/core/SkDevice.h"
60 #include "ui/gfx/geometry/dip_util.h" 61 #include "ui/gfx/geometry/dip_util.h"
61 #include "ui/gfx/geometry/size.h" 62 #include "ui/gfx/geometry/size.h"
62 #include "url/origin.h" 63 #include "url/origin.h"
63 64
65 using mandoline::HTMLMessageEvent;
66 using mandoline::HTMLMessageEventPtr;
64 using mojo::AxProvider; 67 using mojo::AxProvider;
65 using mojo::Rect; 68 using mojo::Rect;
66 using mojo::ServiceProviderPtr; 69 using mojo::ServiceProviderPtr;
67 using mojo::URLResponsePtr; 70 using mojo::URLResponsePtr;
68 using mojo::View; 71 using mojo::View;
69 using mojo::WeakBindToRequest; 72 using mojo::WeakBindToRequest;
70 73
71 namespace mojo { 74 namespace mojo {
72 75
73 #define TEXT_INPUT_TYPE_ASSERT(NAME, Name) \ 76 #define TEXT_INPUT_TYPE_ASSERT(NAME, Name) \
(...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after
567 frame_tree_manager_->ProcessOnFrameRemoved(this, change_id, frame_id); 570 frame_tree_manager_->ProcessOnFrameRemoved(this, change_id, frame_id);
568 } 571 }
569 572
570 void HTMLFrame::OnFrameClientPropertyChanged(uint32_t frame_id, 573 void HTMLFrame::OnFrameClientPropertyChanged(uint32_t frame_id,
571 const mojo::String& name, 574 const mojo::String& name,
572 mojo::Array<uint8_t> new_value) { 575 mojo::Array<uint8_t> new_value) {
573 frame_tree_manager_->ProcessOnFrameClientPropertyChanged(this, frame_id, name, 576 frame_tree_manager_->ProcessOnFrameClientPropertyChanged(this, frame_id, name,
574 new_value.Pass()); 577 new_value.Pass());
575 } 578 }
576 579
580 void HTMLFrame::PostMessage(uint32_t source_frame_id,
581 uint32_t target_frame_id,
582 HTMLMessageEventPtr serialized_event) {
583 NOTIMPLEMENTED(); // For message ports.
584
585 HTMLFrame* target = frame_tree_manager_->root_->FindFrame(target_frame_id);
586 HTMLFrame* source = frame_tree_manager_->root_->FindFrame(source_frame_id);
587 if (!target || !source) {
588 DVLOG(1) << "Invalid source or target for PostMessage";
589 return;
590 }
591
592 if (!target->IsLocal()) {
593 DVLOG(1) << "Target for PostMessage is not lot local";
594 return;
595 }
596
597 blink::WebFrame* target_web_frame = target->web_frame_;
598
599 blink::WebSerializedScriptValue serialized_script_value;
600 serialized_script_value = blink::WebSerializedScriptValue::fromString(
601 serialized_event->data.To<blink::WebString>());
602
603 blink::WebMessagePortChannelArray channels;
604
605 // Create an event with the message. The next-to-last parameter to
606 // initMessageEvent is the last event ID, which is not used with postMessage.
607 blink::WebDOMEvent event =
608 target_web_frame->document().createEvent("MessageEvent");
609 blink::WebDOMMessageEvent msg_event = event.to<blink::WebDOMMessageEvent>();
610 msg_event.initMessageEvent(
611 "message",
612 // |canBubble| and |cancellable| are always false
613 false, false, serialized_script_value,
614 serialized_event->source_origin.To<blink::WebString>(),
615 source->web_frame_, "", channels);
616
617 // We must pass in the target_origin to do the security check on this side,
618 // since it may have changed since the original postMessage call was made.
619 blink::WebSecurityOrigin target_origin;
620 if (!serialized_event->target_origin.is_null()) {
621 target_origin = blink::WebSecurityOrigin::createFromString(
622 serialized_event->target_origin.To<blink::WebString>());
623 }
624 target_web_frame->dispatchMessageEventWithOriginCheck(target_origin,
625 msg_event);
626 }
627
577 blink::WebStorageNamespace* HTMLFrame::createSessionStorageNamespace() { 628 blink::WebStorageNamespace* HTMLFrame::createSessionStorageNamespace() {
578 return new WebStorageNamespaceImpl(); 629 return new WebStorageNamespaceImpl();
579 } 630 }
580 631
581 void HTMLFrame::didCancelCompositionOnSelectionChange() { 632 void HTMLFrame::didCancelCompositionOnSelectionChange() {
582 // TODO(penghuang): Update text input state. 633 // TODO(penghuang): Update text input state.
583 } 634 }
584 635
585 void HTMLFrame::didChangeContents() { 636 void HTMLFrame::didChangeContents() {
586 // TODO(penghuang): Update text input state. 637 // TODO(penghuang): Update text input state.
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
823 state->selection_end = new_info.selectionEnd; 874 state->selection_end = new_info.selectionEnd;
824 state->composition_start = new_info.compositionStart; 875 state->composition_start = new_info.compositionStart;
825 state->composition_end = new_info.compositionEnd; 876 state->composition_end = new_info.compositionEnd;
826 if (show_ime) 877 if (show_ime)
827 view_->SetImeVisibility(true, state.Pass()); 878 view_->SetImeVisibility(true, state.Pass());
828 else 879 else
829 view_->SetTextInputState(state.Pass()); 880 view_->SetTextInputState(state.Pass());
830 } 881 }
831 } 882 }
832 883
833 void HTMLFrame::postMessageEvent(blink::WebLocalFrame* source_frame, 884 void HTMLFrame::postMessageEvent(blink::WebLocalFrame* source_web_frame,
834 blink::WebRemoteFrame* target_frame, 885 blink::WebRemoteFrame* target_web_frame,
835 blink::WebSecurityOrigin target_origin, 886 blink::WebSecurityOrigin target_origin,
836 blink::WebDOMMessageEvent event) { 887 blink::WebDOMMessageEvent web_event) {
837 NOTIMPLEMENTED(); 888 NOTIMPLEMENTED(); // message_ports aren't implemented yet.
889
890 HTMLFrame* source_frame =
891 frame_tree_manager_->root_->FindFrameWithWebFrame(source_web_frame);
892 DCHECK(source_frame);
893 HTMLFrame* target_frame =
894 frame_tree_manager_->root_->FindFrameWithWebFrame(target_web_frame);
895 DCHECK(target_frame);
896
897 HTMLMessageEventPtr event(HTMLMessageEvent::New());
898 event->data = mojo::Array<uint8_t>::From(web_event.data().toString());
899 event->source_origin = mojo::String::From(web_event.origin());
900 if (!target_origin.isNull())
901 event->target_origin = mojo::String::From(target_origin.toString());
902
903 GetFrameTreeServer()->PostMessageEventToFrame(
904 source_frame->id_, target_frame->id_, event.Pass());
838 } 905 }
839 906
840 void HTMLFrame::initializeChildFrame(const blink::WebRect& frame_rect, 907 void HTMLFrame::initializeChildFrame(const blink::WebRect& frame_rect,
841 float scale_factor) { 908 float scale_factor) {
842 // TODO(sky): frame_rect is in dips. Need to convert. 909 // TODO(sky): frame_rect is in dips. Need to convert.
843 mojo::Rect rect; 910 mojo::Rect rect;
844 rect.x = frame_rect.x; 911 rect.x = frame_rect.x;
845 rect.y = frame_rect.y; 912 rect.y = frame_rect.y;
846 rect.width = frame_rect.width; 913 rect.width = frame_rect.width;
847 rect.height = frame_rect.height; 914 rect.height = frame_rect.height;
(...skipping 12 matching lines...) Expand all
860 927
861 void HTMLFrame::reload(bool ignore_cache, bool is_client_redirect) { 928 void HTMLFrame::reload(bool ignore_cache, bool is_client_redirect) {
862 NOTIMPLEMENTED(); 929 NOTIMPLEMENTED();
863 } 930 }
864 931
865 void HTMLFrame::forwardInputEvent(const blink::WebInputEvent* event) { 932 void HTMLFrame::forwardInputEvent(const blink::WebInputEvent* event) {
866 NOTIMPLEMENTED(); 933 NOTIMPLEMENTED();
867 } 934 }
868 935
869 } // namespace mojo 936 } // namespace mojo
OLDNEW
« no previous file with comments | « components/html_viewer/html_frame.h ('k') | components/html_viewer/html_frame_apptest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698