Index: content/browser/frame_map.cc |
diff --git a/content/browser/frame_map.cc b/content/browser/frame_map.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..bb908fb702302a4787972595e5267a62f2207317 |
--- /dev/null |
+++ b/content/browser/frame_map.cc |
@@ -0,0 +1,113 @@ |
+// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "content/browser/frame_map.h" |
+ |
+#include "base/logging.h" |
+#include "content/browser/content_frame.h" |
+#include "content/browser/renderer_host/render_view_host.h" |
+#include "content/common/view_messages.h" |
+ |
+namespace content { |
+ |
+FrameMap::FrameMap() |
+ : next_frame_id_(0) { |
+} |
+ |
+FrameMap::~FrameMap() { |
+} |
+ |
+int64 FrameMap::AllocateFrameId() { |
+ return ++next_frame_id_; |
+} |
+ |
+ContentFrame* FrameMap::InitializeFrame(int64 frame_id, |
+ bool is_top_level, |
+ TabContents& tab_contents, |
+ ContentFrame* opener) { |
+ ContentFrame* frame = new ContentFrame(frame_id, is_top_level, |
+ tab_contents, opener); |
+ DCHECK(frame); |
jam
2011/12/22 20:06:53
nit: we avoid dchecks on pointers before using the
|
+ frame_id_map_.insert( |
+ std::pair<int64, ContentFrame*>(frame->id(), frame)); |
awong
2011/12/21 01:56:07
std::make_pair(frame->id(), frame)
|
+ return frame; |
+} |
+ |
+ContentFrame* FrameMap::FindFrame(int64 id) { |
awong
2011/12/21 01:56:07
if you lookup a missing ID, this will segfault. Is
|
+ return frame_id_map_[id]; |
+} |
+ |
+ContentFrame *FrameMap::FindRendererFrame(int render_process_host_id, |
+ int64 frame_id) { |
+ ContentFrame::WebKitFrameIdTuple webkitFrameId( |
+ render_process_host_id, -1, frame_id); |
+ |
+ WebKitFrameIdMap::iterator iter = webkit_frame_id_map_.find(webkitFrameId); |
+ if (iter != webkit_frame_id_map_.end()) |
+ return iter->second; |
+ else |
+ return NULL; |
+} |
+ |
+ContentFrame* FrameMap::FindTopLevelFrame(int process_id, int route_id) { |
+ // TODO(supersat): Make this significantly less hacky |
+ FrameIdMap::iterator iter; |
+ for (iter = frame_id_map_.begin(); iter != frame_id_map_.end(); iter++) { |
+ ContentFrame* iterFrame = (*iter).second; |
+ if (iterFrame->current_process_host_id() == process_id && |
+ iterFrame->current_route_id() == route_id && |
+ iterFrame->is_top_level()) { |
+ return iterFrame; |
+ } |
+ } |
+ |
+ return 0; |
awong
2011/12/21 01:06:38
NULL.
|
+} |
+ |
+void FrameMap::UpdateFrame(ContentFrame* frame, |
+ int render_process_host_id, |
+ int route_id, |
+ int64 frame_id) { |
+ DLOG(WARNING) << "Calling UpdateFrame: " << |
+ render_process_host_id << ", " << route_id << ", " << |
+ frame_id; |
+ |
+ DCHECK(frame); |
awong
2011/12/21 01:56:07
Should this be a CHECK()? If this is a production
|
+ ContentFrame::WebKitFrameIdTuple webkitFrameId( |
+ render_process_host_id, route_id, frame_id); |
+ frame->current_webkit_frame_ = webkitFrameId; |
+ webkit_frame_id_map_.insert( |
+ std::pair<ContentFrame::WebKitFrameIdTuple, |
+ ContentFrame*>(webkitFrameId, frame)); |
+} |
+ |
+// TODO(supersat): This method might not be needed after all. |
+void FrameMap::AddSwappedOutRendererToFrame(ContentFrame* frame, |
+ int render_process_host_id, |
+ int route_id, |
+ int64 frame_id) { |
+ DLOG(WARNING) << "Calling AddSwappedOutRendererToFrame: " << |
+ frame->id() << ", " << |
+ render_process_host_id << ", " << route_id << ", " << |
+ frame_id; |
+ ContentFrame::WebKitFrameIdTuple webkitFrameId( |
+ render_process_host_id, route_id, frame_id); |
+ webkit_frame_id_map_.insert( |
+ std::pair<ContentFrame::WebKitFrameIdTuple, |
awong
2011/12/21 01:56:07
make_pair
|
+ ContentFrame*>(webkitFrameId, frame)); |
+} |
+ |
+void FrameMap::RemoveFrame(ContentFrame* frame) { |
+ DLOG(WARNING) << "Calling RemoveFrame, id = " << frame->id(); |
+ // TODO(supersat): Remove child frames when they're supported |
+ frame_id_map_.erase(frame->id()); |
+ const std::list<ContentFrame::WebKitFrameIdTuple>& webkit_frames = |
+ frame->all_webkit_frames(); |
+ std::list<ContentFrame::WebKitFrameIdTuple>::const_iterator iter; |
awong
2011/12/21 01:56:07
Scope this in the for loop?
|
+ for (iter = webkit_frames.begin(); iter != webkit_frames.end(); iter++) { |
+ webkit_frame_id_map_.erase(*iter); |
+ } |
+} |
+ |
+} // namespace content |