OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2006, 2007, 2008, 2010 Apple Inc. All rights reserved. | 2 * Copyright (C) 2006, 2007, 2008, 2010 Apple Inc. All rights reserved. |
3 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) | 3 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
104 #include "wtf/text/WTFString.h" | 104 #include "wtf/text/WTFString.h" |
105 #include <algorithm> | 105 #include <algorithm> |
106 | 106 |
107 using std::min; | 107 using std::min; |
108 using std::max; | 108 using std::max; |
109 | 109 |
110 namespace WebCore { | 110 namespace WebCore { |
111 | 111 |
112 class PostMessageTimer FINAL : public SuspendableTimer { | 112 class PostMessageTimer FINAL : public SuspendableTimer { |
113 public: | 113 public: |
114 PostMessageTimer(DOMWindow& window, PassRefPtr<SerializedScriptValue> messag e, const String& sourceOrigin, PassRefPtrWillBeRawPtr<DOMWindow> source, PassOwn Ptr<MessagePortChannelArray> channels, SecurityOrigin* targetOrigin, PassRefPtr< ScriptCallStack> stackTrace) | 114 PostMessageTimer(DOMWindow& window, PassRefPtr<SerializedScriptValue> messag e, const String& sourceOrigin, PassRefPtrWillBeRawPtr<DOMWindow> source, PassOwn Ptr<MessagePortChannelArray> channels, SecurityOrigin* targetOrigin, PassRefPtr< ScriptCallStack> stackTrace, UserGestureToken* userGestureToken) |
115 : SuspendableTimer(window.document()) | 115 : SuspendableTimer(window.document()) |
116 , m_window(&window) | 116 , m_window(&window) |
117 , m_message(message) | 117 , m_message(message) |
118 , m_origin(sourceOrigin) | 118 , m_origin(sourceOrigin) |
119 , m_source(source) | 119 , m_source(source) |
120 , m_channels(channels) | 120 , m_channels(channels) |
121 , m_targetOrigin(targetOrigin) | 121 , m_targetOrigin(targetOrigin) |
122 , m_stackTrace(stackTrace) | 122 , m_stackTrace(stackTrace) |
123 , m_userGestureToken(userGestureToken) | |
123 { | 124 { |
124 } | 125 } |
125 | 126 |
126 PassRefPtr<MessageEvent> event() | 127 PassRefPtr<MessageEvent> event() |
127 { | 128 { |
128 return MessageEvent::create(m_channels.release(), m_message, m_origin, S tring(), m_source.get()); | 129 return MessageEvent::create(m_channels.release(), m_message, m_origin, S tring(), m_source.get()); |
129 | 130 |
130 } | 131 } |
131 SecurityOrigin* targetOrigin() const { return m_targetOrigin.get(); } | 132 SecurityOrigin* targetOrigin() const { return m_targetOrigin.get(); } |
132 ScriptCallStack* stackTrace() const { return m_stackTrace.get(); } | 133 ScriptCallStack* stackTrace() const { return m_stackTrace.get(); } |
134 UserGestureToken* userGestureToken() const { return m_userGestureToken.get() ; } | |
133 | 135 |
134 private: | 136 private: |
135 virtual void fired() OVERRIDE | 137 virtual void fired() OVERRIDE |
136 { | 138 { |
137 m_window->postMessageTimerFired(adoptPtr(this)); | 139 m_window->postMessageTimerFired(adoptPtr(this)); |
138 // This object is deleted now. | 140 // This object is deleted now. |
139 } | 141 } |
140 | 142 |
141 RefPtrWillBePersistent<DOMWindow> m_window; | 143 RefPtrWillBePersistent<DOMWindow> m_window; |
142 RefPtr<SerializedScriptValue> m_message; | 144 RefPtr<SerializedScriptValue> m_message; |
143 String m_origin; | 145 String m_origin; |
144 RefPtrWillBePersistent<DOMWindow> m_source; | 146 RefPtrWillBePersistent<DOMWindow> m_source; |
145 OwnPtr<MessagePortChannelArray> m_channels; | 147 OwnPtr<MessagePortChannelArray> m_channels; |
146 RefPtr<SecurityOrigin> m_targetOrigin; | 148 RefPtr<SecurityOrigin> m_targetOrigin; |
147 RefPtr<ScriptCallStack> m_stackTrace; | 149 RefPtr<ScriptCallStack> m_stackTrace; |
150 RefPtr<UserGestureToken> m_userGestureToken; | |
148 }; | 151 }; |
149 | 152 |
150 static void disableSuddenTermination() | 153 static void disableSuddenTermination() |
151 { | 154 { |
152 blink::Platform::current()->suddenTerminationChanged(false); | 155 blink::Platform::current()->suddenTerminationChanged(false); |
153 } | 156 } |
154 | 157 |
155 static void enableSuddenTermination() | 158 static void enableSuddenTermination() |
156 { | 159 { |
157 blink::Platform::current()->suddenTerminationChanged(true); | 160 blink::Platform::current()->suddenTerminationChanged(true); |
(...skipping 686 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
844 if (!sourceDocument) | 847 if (!sourceDocument) |
845 return; | 848 return; |
846 String sourceOrigin = sourceDocument->securityOrigin()->toString(); | 849 String sourceOrigin = sourceDocument->securityOrigin()->toString(); |
847 | 850 |
848 // Capture stack trace only when inspector front-end is loaded as it may be time consuming. | 851 // Capture stack trace only when inspector front-end is loaded as it may be time consuming. |
849 RefPtr<ScriptCallStack> stackTrace; | 852 RefPtr<ScriptCallStack> stackTrace; |
850 if (InspectorInstrumentation::consoleAgentEnabled(sourceDocument)) | 853 if (InspectorInstrumentation::consoleAgentEnabled(sourceDocument)) |
851 stackTrace = createScriptCallStack(ScriptCallStack::maxCallStackSizeToCa pture, true); | 854 stackTrace = createScriptCallStack(ScriptCallStack::maxCallStackSizeToCa pture, true); |
852 | 855 |
853 // Schedule the message. | 856 // Schedule the message. |
854 PostMessageTimer* timer = new PostMessageTimer(*this, message, sourceOrigin, source, channels.release(), target.get(), stackTrace.release()); | 857 PostMessageTimer* timer = new PostMessageTimer(*this, message, sourceOrigin, source, channels.release(), target.get(), stackTrace.release(), UserGestureIndi cator::currentToken()); |
855 timer->startOneShot(0, FROM_HERE); | 858 timer->startOneShot(0, FROM_HERE); |
856 timer->suspendIfNeeded(); | 859 timer->suspendIfNeeded(); |
857 } | 860 } |
858 | 861 |
859 void DOMWindow::postMessageTimerFired(PassOwnPtr<PostMessageTimer> t) | 862 void DOMWindow::postMessageTimerFired(PassOwnPtr<PostMessageTimer> t) |
860 { | 863 { |
861 OwnPtr<PostMessageTimer> timer(t); | 864 OwnPtr<PostMessageTimer> timer(t); |
862 | 865 |
863 if (!isCurrentlyDisplayedInFrame()) | 866 if (!isCurrentlyDisplayedInFrame()) |
864 return; | 867 return; |
865 | 868 |
866 RefPtr<MessageEvent> event = timer->event(); | 869 RefPtr<MessageEvent> event = timer->event(); |
867 | 870 |
868 // Give the embedder a chance to intercept this postMessage because this | 871 // Give the embedder a chance to intercept this postMessage because this |
869 // DOMWindow might be a proxy for another in browsers that support | 872 // DOMWindow might be a proxy for another in browsers that support |
870 // postMessage calls across WebKit instances. | 873 // postMessage calls across WebKit instances. |
871 if (m_frame->loader().client()->willCheckAndDispatchMessageEvent(timer->targ etOrigin(), event.get())) | 874 if (m_frame->loader().client()->willCheckAndDispatchMessageEvent(timer->targ etOrigin(), event.get())) |
Charlie Reis
2014/03/28 16:22:38
What about cross-process postMessage? Seems like
| |
872 return; | 875 return; |
873 | 876 |
877 UserGestureIndicator gestureIndicator(timer->userGestureToken()); | |
878 | |
874 event->entangleMessagePorts(document()); | 879 event->entangleMessagePorts(document()); |
875 dispatchMessageEventWithOriginCheck(timer->targetOrigin(), event, timer->sta ckTrace()); | 880 dispatchMessageEventWithOriginCheck(timer->targetOrigin(), event, timer->sta ckTrace()); |
876 } | 881 } |
877 | 882 |
878 void DOMWindow::dispatchMessageEventWithOriginCheck(SecurityOrigin* intendedTarg etOrigin, PassRefPtr<Event> event, PassRefPtr<ScriptCallStack> stackTrace) | 883 void DOMWindow::dispatchMessageEventWithOriginCheck(SecurityOrigin* intendedTarg etOrigin, PassRefPtr<Event> event, PassRefPtr<ScriptCallStack> stackTrace) |
879 { | 884 { |
880 if (intendedTargetOrigin) { | 885 if (intendedTargetOrigin) { |
881 // Check target origin now since the target document may have changed si nce the timer was scheduled. | 886 // Check target origin now since the target document may have changed si nce the timer was scheduled. |
882 if (!intendedTargetOrigin->isSameSchemeHostPort(document()->securityOrig in())) { | 887 if (!intendedTargetOrigin->isSameSchemeHostPort(document()->securityOrig in())) { |
883 String message = ExceptionMessages::failedToExecute("postMessage", " DOMWindow", "The target origin provided ('" + intendedTargetOrigin->toString() + "') does not match the recipient window's origin ('" + document()->securityOrig in()->toString() + "')."); | 888 String message = ExceptionMessages::failedToExecute("postMessage", " DOMWindow", "The target origin provided ('" + intendedTargetOrigin->toString() + "') does not match the recipient window's origin ('" + document()->securityOrig in()->toString() + "')."); |
(...skipping 994 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1878 visitor->trace(m_console); | 1883 visitor->trace(m_console); |
1879 visitor->trace(m_navigator); | 1884 visitor->trace(m_navigator); |
1880 visitor->trace(m_location); | 1885 visitor->trace(m_location); |
1881 visitor->trace(m_sessionStorage); | 1886 visitor->trace(m_sessionStorage); |
1882 visitor->trace(m_localStorage); | 1887 visitor->trace(m_localStorage); |
1883 visitor->trace(m_applicationCache); | 1888 visitor->trace(m_applicationCache); |
1884 visitor->trace(m_performance); | 1889 visitor->trace(m_performance); |
1885 } | 1890 } |
1886 | 1891 |
1887 } // namespace WebCore | 1892 } // namespace WebCore |
OLD | NEW |