Chromium Code Reviews| 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/common/view_messages.h" | |
| 11 | |
| 12 namespace content { | |
| 13 | |
| 14 FrameMap::FrameMap() | |
| 15 : next_frame_id_(0) { | |
| 16 } | |
| 17 | |
| 18 FrameMap::~FrameMap() { | |
| 19 } | |
| 20 | |
| 21 int64 FrameMap::AllocateFrameId() { | |
| 22 return ++next_frame_id_; | |
| 23 } | |
| 24 | |
| 25 ContentFrame* FrameMap::InitializeFrame(int64 frame_id, | |
| 26 bool is_top_level, | |
| 27 TabContents& tab_contents, | |
| 28 ContentFrame* opener) { | |
| 29 ContentFrame* frame = new ContentFrame(frame_id, is_top_level, | |
| 30 tab_contents, opener); | |
| 31 DCHECK(frame); | |
|
jam
2011/12/22 20:06:53
nit: we avoid dchecks on pointers before using the
| |
| 32 frame_id_map_.insert( | |
| 33 std::pair<int64, ContentFrame*>(frame->id(), frame)); | |
|
awong
2011/12/21 01:56:07
std::make_pair(frame->id(), frame)
| |
| 34 return frame; | |
| 35 } | |
| 36 | |
| 37 ContentFrame* FrameMap::FindFrame(int64 id) { | |
|
awong
2011/12/21 01:56:07
if you lookup a missing ID, this will segfault. Is
| |
| 38 return frame_id_map_[id]; | |
| 39 } | |
| 40 | |
| 41 ContentFrame *FrameMap::FindRendererFrame(int render_process_host_id, | |
| 42 int64 frame_id) { | |
| 43 ContentFrame::WebKitFrameIdTuple webkitFrameId( | |
| 44 render_process_host_id, -1, frame_id); | |
| 45 | |
| 46 WebKitFrameIdMap::iterator iter = webkit_frame_id_map_.find(webkitFrameId); | |
| 47 if (iter != webkit_frame_id_map_.end()) | |
| 48 return iter->second; | |
| 49 else | |
| 50 return NULL; | |
| 51 } | |
| 52 | |
| 53 ContentFrame* FrameMap::FindTopLevelFrame(int process_id, int route_id) { | |
| 54 // TODO(supersat): Make this significantly less hacky | |
| 55 FrameIdMap::iterator iter; | |
| 56 for (iter = frame_id_map_.begin(); iter != frame_id_map_.end(); iter++) { | |
| 57 ContentFrame* iterFrame = (*iter).second; | |
| 58 if (iterFrame->current_process_host_id() == process_id && | |
| 59 iterFrame->current_route_id() == route_id && | |
| 60 iterFrame->is_top_level()) { | |
| 61 return iterFrame; | |
| 62 } | |
| 63 } | |
| 64 | |
| 65 return 0; | |
|
awong
2011/12/21 01:06:38
NULL.
| |
| 66 } | |
| 67 | |
| 68 void FrameMap::UpdateFrame(ContentFrame* frame, | |
| 69 int render_process_host_id, | |
| 70 int route_id, | |
| 71 int64 frame_id) { | |
| 72 DLOG(WARNING) << "Calling UpdateFrame: " << | |
| 73 render_process_host_id << ", " << route_id << ", " << | |
| 74 frame_id; | |
| 75 | |
| 76 DCHECK(frame); | |
|
awong
2011/12/21 01:56:07
Should this be a CHECK()? If this is a production
| |
| 77 ContentFrame::WebKitFrameIdTuple webkitFrameId( | |
| 78 render_process_host_id, route_id, frame_id); | |
| 79 frame->current_webkit_frame_ = webkitFrameId; | |
| 80 webkit_frame_id_map_.insert( | |
| 81 std::pair<ContentFrame::WebKitFrameIdTuple, | |
| 82 ContentFrame*>(webkitFrameId, frame)); | |
| 83 } | |
| 84 | |
| 85 // TODO(supersat): This method might not be needed after all. | |
| 86 void FrameMap::AddSwappedOutRendererToFrame(ContentFrame* frame, | |
| 87 int render_process_host_id, | |
| 88 int route_id, | |
| 89 int64 frame_id) { | |
| 90 DLOG(WARNING) << "Calling AddSwappedOutRendererToFrame: " << | |
| 91 frame->id() << ", " << | |
| 92 render_process_host_id << ", " << route_id << ", " << | |
| 93 frame_id; | |
| 94 ContentFrame::WebKitFrameIdTuple webkitFrameId( | |
| 95 render_process_host_id, route_id, frame_id); | |
| 96 webkit_frame_id_map_.insert( | |
| 97 std::pair<ContentFrame::WebKitFrameIdTuple, | |
|
awong
2011/12/21 01:56:07
make_pair
| |
| 98 ContentFrame*>(webkitFrameId, frame)); | |
| 99 } | |
| 100 | |
| 101 void FrameMap::RemoveFrame(ContentFrame* frame) { | |
| 102 DLOG(WARNING) << "Calling RemoveFrame, id = " << frame->id(); | |
| 103 // TODO(supersat): Remove child frames when they're supported | |
| 104 frame_id_map_.erase(frame->id()); | |
| 105 const std::list<ContentFrame::WebKitFrameIdTuple>& webkit_frames = | |
| 106 frame->all_webkit_frames(); | |
| 107 std::list<ContentFrame::WebKitFrameIdTuple>::const_iterator iter; | |
|
awong
2011/12/21 01:56:07
Scope this in the for loop?
| |
| 108 for (iter = webkit_frames.begin(); iter != webkit_frames.end(); iter++) { | |
| 109 webkit_frame_id_map_.erase(*iter); | |
| 110 } | |
| 111 } | |
| 112 | |
| 113 } // namespace content | |
| OLD | NEW |