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_frame.h" |
| 6 |
| 7 #include "content/browser/frame_map.h" |
| 8 #include "content/browser/renderer_host/render_view_host.h" |
| 9 #include "content/public/browser/browser_context.h" |
| 10 |
| 11 namespace content { |
| 12 |
| 13 // This class tracks all frame loads for a top-level ContentFrame. This |
| 14 // updates the FrameMap with the current WebKitIdTuple for the ContentFrame |
| 15 // and its children. |
| 16 class ContentFrameObserver : public TabContentsObserver { |
| 17 public: |
| 18 ContentFrameObserver(ContentFrame* frame); |
| 19 // TabContentsObserver methods |
| 20 virtual void DidCommitProvisionalLoadForFrame( |
| 21 int64 frame_id, |
| 22 bool is_main_frame, |
| 23 const GURL& url, |
| 24 content::PageTransition transition_type) OVERRIDE; |
| 25 virtual void TabContentsDestroyed(TabContents* tab) OVERRIDE; |
| 26 private: |
| 27 ContentFrame* frame_; |
| 28 }; |
| 29 |
| 30 ContentFrameObserver::ContentFrameObserver( |
| 31 ContentFrame* frame) |
| 32 : TabContentsObserver(&frame->tab_contents()), |
| 33 frame_(frame) { |
| 34 } |
| 35 |
| 36 void ContentFrameObserver::DidCommitProvisionalLoadForFrame( |
| 37 int64 frame_id, |
| 38 bool is_main_frame, |
| 39 const GURL& url, |
| 40 content::PageTransition transition_type) { |
| 41 content::FrameMap* mapper = |
| 42 frame_->tab_contents_.browser_context()->frame_mapper(); |
| 43 |
| 44 if (is_main_frame) { |
| 45 mapper->UpdateFrame( |
| 46 frame_, frame_->tab_contents_.render_view_host()->process()->GetID(), |
| 47 frame_->tab_contents_.render_view_host()->routing_id(), frame_id); |
| 48 } else { |
| 49 // If we're navigating a subframe, we may need to create a ContentFrame |
| 50 // TODO(supersat): This is hack until we get proper subframe support |
| 51 ContentFrame* frame = mapper->FindRendererFrame( |
| 52 frame_->tab_contents_.render_view_host()->process()->GetID(), |
| 53 frame_id); |
| 54 |
| 55 if (!frame) { |
| 56 frame = mapper->InitializeFrame(false, frame_->tab_contents_, frame_); |
| 57 mapper->UpdateFrame(frame, |
| 58 frame_->tab_contents_.render_view_host()->process()->GetID(), |
| 59 frame_->tab_contents_.render_view_host()->routing_id(), |
| 60 frame_id); |
| 61 } |
| 62 } |
| 63 } |
| 64 |
| 65 void ContentFrameObserver::TabContentsDestroyed(TabContents* tab) { |
| 66 delete this; |
| 67 } |
| 68 |
| 69 ContentFrame::ContentFrame(int64 id, |
| 70 bool is_top_level, |
| 71 TabContents& tab_contents, |
| 72 ContentFrame* opener) |
| 73 : id_(id), |
| 74 active_webkit_frame_(WebKitFrameIdentifier(-1, -1, -1)), |
| 75 is_top_level_(is_top_level), |
| 76 tab_contents_(tab_contents), |
| 77 opener_(opener) { |
| 78 if (is_top_level) |
| 79 new ContentFrameObserver(this); |
| 80 } |
| 81 |
| 82 ContentFrame::~ContentFrame() { |
| 83 } |
| 84 |
| 85 void ContentFrame::UpdateFrame(int new_process_host_id, |
| 86 int new_route_id, |
| 87 int64 new_frame_id) { |
| 88 WebKitFrameIdentifier newWebKitId(new_process_host_id, new_route_id, |
| 89 new_frame_id); |
| 90 active_webkit_frame_ = newWebKitId; |
| 91 |
| 92 all_webkit_frames_.push_back(newWebKitId); |
| 93 } |
| 94 |
| 95 void ContentFrame::AddChildFrame(ContentFrame* child) { |
| 96 children_.push_back(child); |
| 97 } |
| 98 |
| 99 void ContentFrame::RemoveChildren() { |
| 100 children_.clear(); |
| 101 } |
| 102 |
| 103 } // namespace content |
OLD | NEW |