OLD | NEW |
(Empty) | |
| 1 // Copyright 2011 Google Inc. All Rights Reserved. |
| 2 // Author: supersat@google.com (Karl Koscher) |
| 3 |
| 4 #include "frame_mapper.h" |
| 5 #include "browsing_instance_frame_id.h" |
| 6 #include "base/logging.h" |
| 7 |
| 8 namespace content { |
| 9 |
| 10 FrameMapper::FrameMapper() { |
| 11 } |
| 12 |
| 13 FrameMapper::~FrameMapper() { |
| 14 } |
| 15 |
| 16 int64 FrameMapper::AllocateFrameId() { |
| 17 return next_frame_id_.GetNext() + 1; |
| 18 } |
| 19 |
| 20 BrowsingInstanceFrame* FrameMapper::InitializeFrameId(int64 frame_id, |
| 21 bool is_top_level) { |
| 22 BrowsingInstanceFrame* frameId = new BrowsingInstanceFrame(frame_id, |
| 23 is_top_level); |
| 24 frame_id_map_.insert( |
| 25 std::pair<int64, BrowsingInstanceFrame*>(frameId->id(), frameId)); |
| 26 return frameId; |
| 27 } |
| 28 |
| 29 BrowsingInstanceFrame* FrameMapper::AllocateNewTopLevelFrameId() { |
| 30 return InitializeFrameId(AllocateFrameId(), true); |
| 31 } |
| 32 |
| 33 BrowsingInstanceFrame* FrameMapper::FindById(int64 id) { |
| 34 return frame_id_map_[id]; |
| 35 } |
| 36 |
| 37 BrowsingInstanceFrame *FrameMapper::FindByWebKitId(int render_process_host_id, |
| 38 int64 frame_id) { |
| 39 BrowsingInstanceFrame::WebKitFrameIdTuple webkitFrameId( |
| 40 render_process_host_id, frame_id); |
| 41 |
| 42 BrowsingInstanceFrame* retVal = webkit_frame_id_map_[webkitFrameId]; |
| 43 DCHECK(retVal); |
| 44 return retVal; |
| 45 } |
| 46 |
| 47 BrowsingInstanceFrame* FrameMapper::FindTopLevelFrameByProcessAndRoute(int proce
ss_id, |
| 48 int route
_id) { |
| 49 // TODO(supersat): Make this significantly less hacky |
| 50 FrameIdMap::iterator iter; |
| 51 for (iter = frame_id_map_.begin(); iter != frame_id_map_.end(); iter++) { |
| 52 BrowsingInstanceFrame* iterFrame = (*iter).second; |
| 53 if (iterFrame->current_process_host_id() == process_id && |
| 54 iterFrame->current_route_id() == route_id && |
| 55 iterFrame->is_top_level()) { |
| 56 return iterFrame; |
| 57 } |
| 58 } |
| 59 |
| 60 return 0; |
| 61 } |
| 62 |
| 63 void FrameMapper::UpdateFrame(BrowsingInstanceFrame* frame, |
| 64 int render_process_host_id, |
| 65 int route_id, |
| 66 int64 frame_id) { |
| 67 DLOG(WARNING) << "Calling UpdateFrame: " << |
| 68 render_process_host_id << ", " << route_id << ", " << |
| 69 frame_id; |
| 70 |
| 71 DCHECK(frame); |
| 72 BrowsingInstanceFrame::WebKitFrameIdTuple webkitFrameId( |
| 73 render_process_host_id, frame_id); |
| 74 frame->current_webkit_frame_ = webkitFrameId; |
| 75 frame->current_route_id_ = route_id; |
| 76 webkit_frame_id_map_.insert( |
| 77 std::pair<BrowsingInstanceFrame::WebKitFrameIdTuple, |
| 78 BrowsingInstanceFrame*>(webkitFrameId, frame)); |
| 79 } |
| 80 |
| 81 void FrameMapper::RemoveFrame(BrowsingInstanceFrame* frame) |
| 82 { |
| 83 DLOG(WARNING) << "Calling RemoveFrame"; |
| 84 // TODO(supersat): Remove child frames when they're supported |
| 85 frame_id_map_.erase(frame->id()); |
| 86 webkit_frame_id_map_.erase(frame->current_webkit_frame()); |
| 87 } |
| 88 |
| 89 } // namespace content |
OLD | NEW |