Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/renderer/render_view_impl.h" | 5 #include "content/renderer/render_view_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 3887 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3898 if (frame->document().body().appendChild(element)) { | 3898 if (frame->document().body().appendChild(element)) { |
| 3899 WebFrame* subframe = WebFrame::fromFrameOwnerElement(element); | 3899 WebFrame* subframe = WebFrame::fromFrameOwnerElement(element); |
| 3900 if (subframe) | 3900 if (subframe) |
| 3901 CreateFrameTree(subframe, child); | 3901 CreateFrameTree(subframe, child); |
| 3902 } else { | 3902 } else { |
| 3903 LOG(ERROR) << "Failed to append created iframe element."; | 3903 LOG(ERROR) << "Failed to append created iframe element."; |
| 3904 } | 3904 } |
| 3905 } | 3905 } |
| 3906 } | 3906 } |
| 3907 | 3907 |
| 3908 WebKit::WebFrame* RenderViewImpl::GetFrameByMappedID(int frame_id) { | 3908 WebKit::WebFrame* RenderViewImpl::GetFrameByMappedID(int remote_frame_id) { |
| 3909 std::map<int, int>::iterator it = active_frame_id_map_.find(frame_id); | 3909 std::map<int, int>::const_iterator it = active_frame_id_map_.begin(); |
| 3910 if (it == active_frame_id_map_.end()) | 3910 for (; it != active_frame_id_map_.end(); ++it) { |
| 3911 return NULL; | 3911 if (it->second == remote_frame_id) { |
| 3912 | 3912 return FindFrameByID(webview()->mainFrame(), it->first); |
| 3913 return FindFrameByID(webview()->mainFrame(), it->second); | 3913 } |
| 3914 } | |
| 3915 return NULL; | |
| 3914 } | 3916 } |
| 3915 | 3917 |
| 3916 void RenderViewImpl::EnsureMediaStreamImpl() { | 3918 void RenderViewImpl::EnsureMediaStreamImpl() { |
| 3917 if (!RenderThreadImpl::current()) // Will be NULL during unit tests. | 3919 if (!RenderThreadImpl::current()) // Will be NULL during unit tests. |
| 3918 return; | 3920 return; |
| 3919 | 3921 |
| 3920 #if defined(ENABLE_WEBRTC) | 3922 #if defined(ENABLE_WEBRTC) |
| 3921 if (!media_stream_dispatcher_) | 3923 if (!media_stream_dispatcher_) |
| 3922 media_stream_dispatcher_ = new MediaStreamDispatcher(this); | 3924 media_stream_dispatcher_ = new MediaStreamDispatcher(this); |
| 3923 | 3925 |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4184 params.target_process_id = target_process_id_; | 4186 params.target_process_id = target_process_id_; |
| 4185 params.target_routing_id = target_routing_id_; | 4187 params.target_routing_id = target_routing_id_; |
| 4186 | 4188 |
| 4187 std::map<int,int>::iterator it = active_frame_id_map_.find( | 4189 std::map<int,int>::iterator it = active_frame_id_map_.find( |
| 4188 targetFrame->identifier()); | 4190 targetFrame->identifier()); |
| 4189 if (it != active_frame_id_map_.end()) { | 4191 if (it != active_frame_id_map_.end()) { |
| 4190 params.target_frame_id = it->second; | 4192 params.target_frame_id = it->second; |
| 4191 } else { | 4193 } else { |
| 4192 params.target_frame_id = 0; | 4194 params.target_frame_id = 0; |
| 4193 } | 4195 } |
| 4194 | |
| 4195 Send(new ViewHostMsg_RouteMessageEvent(routing_id_, params)); | 4196 Send(new ViewHostMsg_RouteMessageEvent(routing_id_, params)); |
| 4196 return true; | 4197 return true; |
| 4197 } | 4198 } |
| 4198 | 4199 |
| 4199 void RenderViewImpl::willOpenSocketStream( | 4200 void RenderViewImpl::willOpenSocketStream( |
| 4200 WebSocketStreamHandle* handle) { | 4201 WebSocketStreamHandle* handle) { |
| 4201 SocketStreamHandleData::AddToHandle(handle, routing_id_); | 4202 SocketStreamHandleData::AddToHandle(handle, routing_id_); |
| 4202 } | 4203 } |
| 4203 | 4204 |
| 4204 WebKit::WebString RenderViewImpl::userAgentOverride( | 4205 WebKit::WebString RenderViewImpl::userAgentOverride( |
| (...skipping 2085 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6290 return !!RenderThreadImpl::current()->compositor_thread(); | 6291 return !!RenderThreadImpl::current()->compositor_thread(); |
| 6291 } | 6292 } |
| 6292 | 6293 |
| 6293 void RenderViewImpl::OnJavaBridgeInit() { | 6294 void RenderViewImpl::OnJavaBridgeInit() { |
| 6294 DCHECK(!java_bridge_dispatcher_); | 6295 DCHECK(!java_bridge_dispatcher_); |
| 6295 #if defined(ENABLE_JAVA_BRIDGE) | 6296 #if defined(ENABLE_JAVA_BRIDGE) |
| 6296 java_bridge_dispatcher_ = new JavaBridgeDispatcher(this); | 6297 java_bridge_dispatcher_ = new JavaBridgeDispatcher(this); |
| 6297 #endif | 6298 #endif |
| 6298 } | 6299 } |
| 6299 | 6300 |
| 6300 void RenderViewImpl::OnUpdatedFrameTree( | 6301 void RenderViewImpl::UpdateFrameTree( |
| 6301 int process_id, | 6302 int process_id, |
| 6302 int route_id, | 6303 int route_id, |
| 6303 const std::string& frame_tree) { | 6304 const std::string& frame_tree) { |
| 6304 // We should only act on this message if we are swapped out. It's possible | 6305 // We should only act on this message if we are swapped out. It's possible |
| 6305 // for this to happen due to races. | 6306 // for this to happen due to races. |
| 6306 if (!is_swapped_out_) | |
| 6307 return; | |
| 6308 | |
| 6309 base::DictionaryValue* frames = NULL; | 6307 base::DictionaryValue* frames = NULL; |
| 6310 scoped_ptr<base::Value> tree(base::JSONReader::Read(frame_tree)); | 6308 scoped_ptr<base::Value> tree(base::JSONReader::Read(frame_tree)); |
| 6311 if (tree.get() && tree->IsType(base::Value::TYPE_DICTIONARY)) | 6309 if (tree.get() && tree->IsType(base::Value::TYPE_DICTIONARY)) { |
| 6312 tree->GetAsDictionary(&frames); | 6310 if (!tree->GetAsDictionary(&frames)) |
| 6311 return; | |
| 6312 } | |
| 6313 | 6313 |
| 6314 updating_frame_tree_ = true; | 6314 updating_frame_tree_ = true; |
| 6315 active_frame_id_map_.clear(); | 6315 active_frame_id_map_.clear(); |
| 6316 | 6316 |
| 6317 target_process_id_ = process_id; | 6317 target_process_id_ = process_id; |
| 6318 target_routing_id_ = route_id; | 6318 target_routing_id_ = route_id; |
| 6319 CreateFrameTree(webview()->mainFrame(), frames); | 6319 CreateFrameTree(webview()->mainFrame(), frames); |
| 6320 | 6320 |
| 6321 updating_frame_tree_ = false; | 6321 updating_frame_tree_ = false; |
| 6322 } | 6322 } |
| 6323 | |
| 6324 void RenderViewImpl::OnUpdatedFrameTree( | |
|
nasko
2012/10/02 17:52:31
This change might be worthwhile as a separate bug/
Fady Samuel
2012/10/02 22:04:08
Done. Leaving it here until the other patch lands.
| |
| 6325 int process_id, | |
| 6326 int route_id, | |
| 6327 const std::string& frame_tree) { | |
| 6328 if (!is_swapped_out_) | |
| 6329 return; | |
| 6330 | |
| 6331 if (frame_tree.empty()) | |
| 6332 return; | |
| 6333 // Post the task to update the frame tree on the task queue to ensure that | |
|
nasko
2012/10/02 17:52:31
nit: An empty line prior to the comment will make
| |
| 6334 // that any pending postMessage tasks are handled before the frame tree is | |
| 6335 // updated. If we navigate between the time we schedule a postMessage, and | |
| 6336 // the time we handle it, we will get a navigation that will prevent the | |
| 6337 // message from being posted. | |
| 6338 MessageLoop::current()->PostTask( | |
| 6339 FROM_HERE, | |
| 6340 base::Bind(&RenderViewImpl::UpdateFrameTree, AsWeakPtr(), | |
| 6341 process_id, route_id, frame_tree)); | |
| 6342 } | |
| OLD | NEW |