OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "content/browser/frame_map.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 #include "content/browser/content_frame.h" |
| 9 #include "content/browser/renderer_host/render_view_host.h" |
| 10 #include "content/browser/webkit_frame_identifier.h" |
| 11 #include "content/common/view_messages.h" |
| 12 |
| 13 namespace content { |
| 14 |
| 15 FrameMap::FrameMap() |
| 16 : next_frame_id_(0) { |
| 17 } |
| 18 |
| 19 FrameMap::~FrameMap() { |
| 20 } |
| 21 |
| 22 ContentFrame* FrameMap::InitializeFrame(bool is_top_level, |
| 23 TabContents& tab_contents, |
| 24 ContentFrame* opener) { |
| 25 ContentFrame* frame = new ContentFrame(++next_frame_id_, is_top_level, |
| 26 tab_contents, opener); |
| 27 DCHECK(frame); |
| 28 frame_id_map_.insert( |
| 29 std::pair<int64, ContentFrame*>(frame->id(), frame)); |
| 30 return frame; |
| 31 } |
| 32 |
| 33 ContentFrame* FrameMap::FindFrame(int64 id) { |
| 34 return frame_id_map_[id]; |
| 35 } |
| 36 |
| 37 ContentFrame *FrameMap::FindRendererFrame(int render_process_host_id, |
| 38 int64 frame_id) { |
| 39 WebKitFrameIdentifier webkitFrameId(render_process_host_id, -1, frame_id); |
| 40 |
| 41 WebKitFrameIdMap::iterator iter = webkit_frame_id_map_.find(webkitFrameId); |
| 42 if (iter != webkit_frame_id_map_.end()) |
| 43 return iter->second; |
| 44 else |
| 45 return NULL; |
| 46 } |
| 47 |
| 48 ContentFrame* FrameMap::FindTopLevelFrame(int process_id, 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 ContentFrame* iterFrame = (*iter).second; |
| 53 const WebKitFrameIdentifier webkitFrame = iterFrame->active_webkit_frame(); |
| 54 if (webkitFrame.process_host_id == process_id && |
| 55 webkitFrame.route_id == route_id && |
| 56 iterFrame->is_top_level()) { |
| 57 return iterFrame; |
| 58 } |
| 59 } |
| 60 |
| 61 return 0; |
| 62 } |
| 63 |
| 64 void FrameMap::UpdateFrame(ContentFrame* frame, |
| 65 int render_process_host_id, |
| 66 int route_id, |
| 67 int64 frame_id) { |
| 68 DCHECK(frame); |
| 69 WebKitFrameIdentifier webkitFrameId( |
| 70 render_process_host_id, route_id, frame_id); |
| 71 frame->active_webkit_frame_ = webkitFrameId; |
| 72 webkit_frame_id_map_.insert( |
| 73 std::pair<WebKitFrameIdentifier, |
| 74 ContentFrame*>(webkitFrameId, frame)); |
| 75 } |
| 76 |
| 77 // TODO(supersat): This method might not be needed after all. |
| 78 void FrameMap::AddSwappedOutRendererToFrame(ContentFrame* frame, |
| 79 int render_process_host_id, |
| 80 int route_id, |
| 81 int64 frame_id) { |
| 82 WebKitFrameIdentifier webkitFrameId( |
| 83 render_process_host_id, route_id, frame_id); |
| 84 webkit_frame_id_map_.insert( |
| 85 std::pair<WebKitFrameIdentifier, |
| 86 ContentFrame*>(webkitFrameId, frame)); |
| 87 } |
| 88 |
| 89 void FrameMap::RemoveFrame(ContentFrame* frame) { |
| 90 // TODO(supersat): Remove child frames when they're supported |
| 91 frame_id_map_.erase(frame->id()); |
| 92 const std::list<WebKitFrameIdentifier>& webkit_frames = |
| 93 frame->all_webkit_frames(); |
| 94 std::list<WebKitFrameIdentifier>::const_iterator iter; |
| 95 for (iter = webkit_frames.begin(); iter != webkit_frames.end(); iter++) { |
| 96 webkit_frame_id_map_.erase(*iter); |
| 97 } |
| 98 } |
| 99 |
| 100 } // namespace content |
OLD | NEW |