1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
// Copyright (c) 2006-2008 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 "chrome/browser/tab_contents/web_contents_view.h"
#include "chrome/browser/renderer_host/render_process_host.h"
#include "chrome/browser/renderer_host/render_widget_host.h"
#include "chrome/browser/renderer_host/render_widget_host_view.h"
#include "chrome/browser/tab_contents/tab_contents_delegate.h"
#include "chrome/browser/tab_contents/web_contents.h"
WebContentsView::WebContentsView(WebContents* web_contents)
: web_contents_(web_contents) {
}
void WebContentsView::RenderWidgetHostDestroyed(RenderWidgetHost* host) {
for (PendingWidgetViews::iterator i = pending_widget_views_.begin();
i != pending_widget_views_.end(); ++i) {
if (host->view() == i->second) {
pending_widget_views_.erase(i);
return;
}
}
}
void WebContentsView::CreateNewWindow(int route_id,
base::WaitableEvent* modal_dialog_event) {
// Create the new web contents. This will automatically create the new
// WebContentsView. In the future, we may want to create the view separately.
WebContents* new_contents =
new WebContents(web_contents()->profile(),
web_contents()->GetSiteInstance(),
route_id,
modal_dialog_event);
new_contents->SetupController(web_contents()->profile());
WebContentsView* new_view = new_contents->view();
// TODO(brettw) it seems bogus that we have to call this function on the
// newly created object and give it one of its own member variables.
new_view->CreateViewForWidget(new_contents->render_view_host());
// Save the created window associated with the route so we can show it later.
pending_contents_[route_id] = new_contents;
}
void WebContentsView::CreateNewWidget(int route_id, bool activatable) {
// Save the created widget associated with the route so we can show it later.
pending_widget_views_[route_id] = CreateNewWidgetInternal(route_id,
activatable);
}
void WebContentsView::ShowCreatedWindow(int route_id,
WindowOpenDisposition disposition,
const gfx::Rect& initial_pos,
bool user_gesture) {
PendingContents::iterator iter = pending_contents_.find(route_id);
if (iter == pending_contents_.end()) {
DCHECK(false);
return;
}
WebContents* new_web_contents = iter->second;
pending_contents_.erase(route_id);
if (!new_web_contents->render_widget_host_view() ||
!new_web_contents->process()->channel()) {
// The view has gone away or the renderer crashed. Nothing to do.
return;
}
// TODO(brettw) this seems bogus to reach into here and initialize the host.
new_web_contents->render_view_host()->Init();
web_contents()->AddNewContents(new_web_contents, disposition, initial_pos,
user_gesture);
}
void WebContentsView::ShowCreatedWidget(int route_id,
const gfx::Rect& initial_pos) {
PendingWidgetViews::iterator iter = pending_widget_views_.find(route_id);
if (iter == pending_widget_views_.end()) {
DCHECK(false);
return;
}
RenderWidgetHostView* widget_host_view = iter->second;
pending_widget_views_.erase(route_id);
ShowCreatedWidgetInternal(widget_host_view, initial_pos);
}
RenderWidgetHostView* WebContentsView::CreateNewWidgetInternal(
int route_id,
bool activatable) {
RenderWidgetHost* widget_host =
new RenderWidgetHost(web_contents_->process(), route_id);
RenderWidgetHostView* widget_view =
RenderWidgetHostView::CreateViewForWidget(widget_host);
widget_view->set_activatable(activatable);
return widget_view;
}
void WebContentsView::ShowCreatedWidgetInternal(
RenderWidgetHostView* widget_host_view,
const gfx::Rect& initial_pos) {
RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost();
if (!widget_host->process()->channel()) {
// The view has gone away or the renderer crashed. Nothing to do.
return;
}
widget_host_view->InitAsPopup(
web_contents_->render_widget_host_view(), initial_pos);
if (web_contents_->delegate())
web_contents_->delegate()->RenderWidgetShowing();
widget_host->Init();
}
|