Index: content/renderer/render_view_impl.cc |
diff --git a/content/renderer/render_view_impl.cc b/content/renderer/render_view_impl.cc |
index ce57e9c265a0d9a6837cd06efc513f1f67e496e5..19820fb3296a21a3a32e6b5b466cbfea87830521 100644 |
--- a/content/renderer/render_view_impl.cc |
+++ b/content/renderer/render_view_impl.cc |
@@ -26,6 +26,7 @@ |
#include "base/time.h" |
#include "base/utf_string_conversions.h" |
#include "content/common/appcache/appcache_dispatcher.h" |
+#include "content/common/child_thread.h" |
#include "content/common/clipboard_messages.h" |
#include "content/common/database_messages.h" |
#include "content/common/drag_messages.h" |
@@ -89,6 +90,8 @@ |
#include "third_party/WebKit/Source/WebKit/chromium/public/WebAccessibilityObject.h" |
#include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h" |
#include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebDOMEvent.h" |
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebDOMMessageEvent.h" |
#include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" |
#include "third_party/WebKit/Source/WebKit/chromium/public/WebFileChooserParams.h" |
#include "third_party/WebKit/Source/WebKit/chromium/public/WebFileSystemCallbacks.h" |
@@ -113,6 +116,7 @@ |
#include "third_party/WebKit/Source/WebKit/chromium/public/WebSearchableFormData.h" |
#include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" |
#include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityPolicy.h" |
+#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSerializedScriptValue.h" |
#include "third_party/WebKit/Source/WebKit/chromium/public/WebSettings.h" |
#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageNamespace.h" |
#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageQuotaCallbacks.h" |
@@ -180,6 +184,8 @@ using WebKit::WebCookieJar; |
using WebKit::WebData; |
using WebKit::WebDataSource; |
using WebKit::WebDocument; |
+using WebKit::WebDOMEvent; |
+using WebKit::WebDOMMessageEvent; |
using WebKit::WebDragData; |
using WebKit::WebDragOperation; |
using WebKit::WebDragOperationsMask; |
@@ -219,6 +225,7 @@ using WebKit::WebScriptSource; |
using WebKit::WebSearchableFormData; |
using WebKit::WebSecurityOrigin; |
using WebKit::WebSecurityPolicy; |
+using WebKit::WebSerializedScriptValue; |
using WebKit::WebSettings; |
using WebKit::WebSharedWorker; |
using WebKit::WebSize; |
@@ -333,6 +340,7 @@ RenderViewImpl::RenderViewImpl( |
int32 routing_id, |
int64 session_storage_namespace_id, |
const string16& frame_name, |
+ bool is_renderer_created, |
int32 next_page_id) |
: RenderWidget(WebKit::WebPopupTypeNone), |
webkit_preferences_(webkit_prefs), |
@@ -363,12 +371,13 @@ RenderViewImpl::RenderViewImpl( |
renderer_accessibility_(NULL), |
session_storage_namespace_id_(session_storage_namespace_id), |
handling_select_range_(false), |
+ active_content_frame_id_(-1), |
#if defined(OS_WIN) |
focused_plugin_id_(-1), |
#endif |
ALLOW_THIS_IN_INITIALIZER_LIST(pepper_delegate_(this)) { |
routing_id_ = routing_id; |
- if (opener_id != MSG_ROUTING_NONE) |
+ if (opener_id != MSG_ROUTING_NONE && is_renderer_created) |
opener_id_ = opener_id; |
// Ensure we start with a valid next_page_id_ from the browser. |
@@ -400,7 +409,7 @@ RenderViewImpl::RenderViewImpl( |
// If this is a popup, we must wait for the CreatingNew_ACK message before |
// completing initialization. Otherwise, we can finish it now. |
- if (opener_id == MSG_ROUTING_NONE) { |
+ if (opener_id_ == MSG_ROUTING_NONE) { |
did_show_ = true; |
CompleteInit(parent_hwnd); |
} |
@@ -440,6 +449,15 @@ RenderViewImpl::RenderViewImpl( |
} |
content::GetContentClient()->renderer()->RenderViewCreated(this); |
+ |
+ // If we have an opener_id but we weren't created by a renderer, then |
+ // it's the browser asking us to set our opener to another RenderView. |
+ if (opener_id != MSG_ROUTING_NONE && !is_renderer_created) { |
+ RenderViewImpl* opener_rv = |
+ static_cast<RenderViewImpl*>( |
+ ChildThread::current()->ResolveRoute(opener_id)); |
+ webview()->mainFrame()->setOpener(opener_rv->webview()->mainFrame()); |
+ } |
} |
RenderViewImpl::~RenderViewImpl() { |
@@ -510,6 +528,7 @@ RenderViewImpl* RenderViewImpl::Create( |
int32 routing_id, |
int64 session_storage_namespace_id, |
const string16& frame_name, |
+ bool is_renderer_created, |
int32 next_page_id) { |
DCHECK(routing_id != MSG_ROUTING_NONE); |
return new RenderViewImpl( |
@@ -521,6 +540,7 @@ RenderViewImpl* RenderViewImpl::Create( |
routing_id, |
session_storage_namespace_id, |
frame_name, |
+ is_renderer_created, |
next_page_id); // adds reference |
} |
@@ -698,6 +718,7 @@ bool RenderViewImpl::OnMessageReceived(const IPC::Message& message) { |
IPC_MESSAGE_HANDLER(ViewMsg_LockMouse_ACK, OnLockMouseACK) |
IPC_MESSAGE_HANDLER(ViewMsg_MouseLockLost, OnMouseLockLost) |
IPC_MESSAGE_HANDLER(JavaBridgeMsg_Init, OnJavaBridgeInit) |
+ IPC_MESSAGE_HANDLER(ViewMsg_PostMessage, OnPostMessage) |
// Have the super handle all other messages. |
IPC_MESSAGE_UNHANDLED(handled = RenderWidget::OnMessageReceived(message)) |
@@ -726,8 +747,10 @@ void RenderViewImpl::OnNavigate(const ViewMsg_Navigate_Params& params) { |
return; |
// Swap this renderer back in if necessary. |
- if (is_swapped_out_) |
+ if (is_swapped_out_) { |
SetSwappedOut(false); |
+ active_content_frame_id_ = -1; |
+ } |
history_list_offset_ = params.current_history_list_offset; |
history_list_length_ = params.current_history_list_length; |
@@ -943,6 +966,38 @@ void RenderViewImpl::OnPasteAndMatchStyle() { |
WebString::fromUTF8("PasteAndMatchStyle")); |
} |
+void RenderViewImpl::OnPostMessage(int64 frame_id, |
+ const ViewMsg_PostMessage_Params& params) { |
+ // TODO(supersat): support subframes |
+ WebFrame *frame = webview()->mainFrame(); |
+ |
+ // We need to check whether we can send this message to the frame, since the |
+ // asynchrony of postMessage means that the target frame's origin can change |
+ // in the middle of a postMessage dispatch. An empty target origin means that |
+ // "*" was passed in, and any target origin is acceptable. |
+ if (!params.targetOrigin.empty()) { |
+ WebSecurityOrigin messageSpecifiedOrigin = |
+ WebSecurityOrigin::createFromString(WebString(params.targetOrigin)); |
+ if (!frame->document().securityOrigin().canReceiveMessagesFor( |
+ &messageSpecifiedOrigin)) |
+ return; |
+ } |
+ |
+ WebDOMEvent event = frame->document().createEvent("MessageEvent"); |
+ WebDOMMessageEvent msgEvent = event.to<WebDOMMessageEvent>(); |
+ |
+ // TODO(supersat): fix the source frame parameter |
+ msgEvent.initMessageEvent("message", |
+ // canBubble and cancellable are always false |
awong
2011/12/21 01:56:07
|canBubble| and |cancellable| are always false.
supersat
2011/12/23 03:22:46
Done.
|
+ false, false, |
+ WebSerializedScriptValue::fromString(params.data), |
+ params.sourceOrigin, 0 /* source frame */, |
+ "" /* last event id, not used with postmsg */); |
+ |
+ DLOG(WARNING) << "Dispatching postMessage event"; |
+ frame->dispatchEvent(msgEvent); |
+} |
+ |
void RenderViewImpl::OnReplace(const string16& text) { |
if (!webview()) |
return; |
@@ -1347,6 +1402,7 @@ WebView* RenderViewImpl::createView( |
routing_id, |
cloned_session_storage_namespace_id, |
frame_name, |
+ true, |
1); |
view->opened_by_user_gesture_ = params.user_gesture; |
@@ -2021,6 +2077,8 @@ WebNavigationPolicy RenderViewImpl::decidePolicyForNavigation( |
WebFrame* frame, const WebURLRequest& request, WebNavigationType type, |
const WebNode&, WebNavigationPolicy default_policy, bool is_redirect) { |
// TODO(creis): Remove this when we fix OnSwapOut to not need a navigation. |
+ // TODO(supersat): This currently causes a crash when reloading an app that |
+ // opens an out-of-app window |
if (is_swapped_out_) { |
DCHECK(request.url() == GURL("about:swappedout")); |
return default_policy; |
@@ -3114,6 +3172,26 @@ void RenderViewImpl::registerIntentService( |
service.disposition())); |
} |
+bool RenderViewImpl::interceptPostMessage(WebKit::WebFrame* source, |
+ WebKit::WebSecurityOrigin targetOrig, |
+ WebKit::WebDOMMessageEvent event) { |
+ DLOG(WARNING) << "interceptPostMessage called"; |
+ |
+ if (!is_swapped_out_) |
+ return false; |
+ DCHECK_NE(active_content_frame_id_, -1); |
+ |
+ ViewMsg_PostMessage_Params params; |
+ params.data = event.data().toString(); |
+ params.sourceOrigin = event.origin(); |
+ if (!targetOrig.isNull()) |
awong
2011/12/21 01:56:07
s/targetOrig/targetOrigin/g
supersat
2011/12/23 03:22:46
Done.
|
+ params.targetOrigin = targetOrig.toString(); |
+ |
+ Send(new ViewHostMsg_SendPostMessage( |
+ active_content_frame_id_, params)); |
+ return true; |
+} |
+ |
void RenderViewImpl::dispatchIntent(WebKit::WebFrame* frame, |
const WebKit::WebIntent& intent) { |
webkit_glue::WebIntentData intent_data(intent); |
@@ -4040,6 +4118,8 @@ void RenderViewImpl::OnSwapOut(const ViewMsg_SwapOut_Params& params) { |
GURL("about:swappedout"), |
false); |
+ active_content_frame_id_ = params.content_frame_id; |
+ |
// Just echo back the params in the ACK. |
Send(new ViewHostMsg_SwapOut_ACK(routing_id_, params)); |
} |