Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(26)

Side by Side Diff: chrome/browser/extensions/extension_view.cc

Issue 126289: Graceful handling of extension process crashes (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 11 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/extensions/extension_view.h" 5 #include "chrome/browser/extensions/extension_view.h"
6 6
7 #include "chrome/browser/extensions/extension_host.h" 7 #include "chrome/browser/extensions/extension_host.h"
8 #include "chrome/browser/renderer_host/render_view_host.h" 8 #include "chrome/browser/renderer_host/render_view_host.h"
9 #include "chrome/browser/renderer_host/render_widget_host_view.h" 9 #include "chrome/browser/renderer_host/render_widget_host_view.h"
10 #if defined(OS_WIN) 10 #if defined(OS_WIN)
11 #include "chrome/browser/renderer_host/render_widget_host_view_win.h" 11 #include "chrome/browser/renderer_host/render_widget_host_view_win.h"
12 #endif 12 #endif
13 #include "views/widget/widget.h" 13 #include "views/widget/widget.h"
14 14
15 ExtensionView::ExtensionView(ExtensionHost* host, Browser* browser) 15 ExtensionView::ExtensionView(ExtensionHost* host, Browser* browser)
16 : host_(host), browser_(browser), 16 : host_(host), browser_(browser),
17 initialized_(false), pending_preferred_width_(0), container_(NULL) { 17 initialized_(false), pending_preferred_width_(0), container_(NULL) {
18 host_->set_view(this); 18 host_->set_view(this);
19 } 19 }
20 20
21 ExtensionView::~ExtensionView() { 21 ExtensionView::~ExtensionView() {
22 if (native_view()) 22 CleanUp();
23 Detach();
24 } 23 }
25 24
26 Extension* ExtensionView::extension() const { 25 Extension* ExtensionView::extension() const {
27 return host_->extension(); 26 return host_->extension();
28 } 27 }
29 28
30 RenderViewHost* ExtensionView::render_view_host() const { 29 RenderViewHost* ExtensionView::render_view_host() const {
31 return host_->render_view_host(); 30 return host_->render_view_host();
32 } 31 }
33 32
(...skipping 15 matching lines...) Expand all
49 48
50 void ExtensionView::DidChangeBounds(const gfx::Rect& previous, 49 void ExtensionView::DidChangeBounds(const gfx::Rect& previous,
51 const gfx::Rect& current) { 50 const gfx::Rect& current) {
52 View::DidChangeBounds(previous, current); 51 View::DidChangeBounds(previous, current);
53 // Propagate the new size to RenderWidgetHostView. 52 // Propagate the new size to RenderWidgetHostView.
54 // We can't send size zero because RenderWidget DCHECKs that. 53 // We can't send size zero because RenderWidget DCHECKs that.
55 if (render_view_host()->view() && !current.IsEmpty()) 54 if (render_view_host()->view() && !current.IsEmpty())
56 render_view_host()->view()->SetSize(gfx::Size(width(), height())); 55 render_view_host()->view()->SetSize(gfx::Size(width(), height()));
57 } 56 }
58 57
58 void ExtensionView::CreateWidgetHostView() {
59 DCHECK(!initialized_);
60 initialized_ = true;
61 RenderWidgetHostView* view =
62 RenderWidgetHostView::CreateViewForWidget(render_view_host());
63
64 // TODO(mpcomplete): RWHV needs a cross-platform Init function.
65 #if defined(OS_WIN)
66 // Create the HWND. Note:
67 // RenderWidgetHostHWND supports windowed plugins, but if we ever also
68 // wanted to support constrained windows with this, we would need an
69 // additional HWND to parent off of because windowed plugin HWNDs cannot
70 // exist in the same z-order as constrained windows.
71 RenderWidgetHostViewWin* view_win =
72 static_cast<RenderWidgetHostViewWin*>(view);
73 HWND hwnd = view_win->Create(GetWidget()->GetNativeView());
74 view_win->ShowWindow(SW_SHOW);
75 Attach(hwnd);
76 #else
77 NOTIMPLEMENTED();
78 #endif
79
80 host_->CreateRenderView(view);
81 SetVisible(false);
82
83 if (!pending_background_.empty()) {
84 render_view_host()->view()->SetBackground(pending_background_);
85 pending_background_.reset();
86 }
87 }
88
59 void ExtensionView::ShowIfCompletelyLoaded() { 89 void ExtensionView::ShowIfCompletelyLoaded() {
60 // We wait to show the ExtensionView until it has loaded and our parent has 90 // We wait to show the ExtensionView until it has loaded and our parent has
61 // given us a background. These can happen in different orders. 91 // given us a background. These can happen in different orders.
62 if (!IsVisible() && host_->did_stop_loading() && render_view_host()->view() && 92 if (!IsVisible() && host_->did_stop_loading() && render_view_host()->view() &&
63 !render_view_host()->view()->background().empty()) { 93 !render_view_host()->view()->background().empty()) {
64 SetVisible(true); 94 SetVisible(true);
65 DidContentsPreferredWidthChange(pending_preferred_width_); 95 DidContentsPreferredWidthChange(pending_preferred_width_);
66 } 96 }
67 } 97 }
68 98
99 void ExtensionView::CleanUp() {
100 if (!initialized_)
101 return;
102 if (native_view())
103 Detach();
104 initialized_ = false;
105 }
106
69 void ExtensionView::SetBackground(const SkBitmap& background) { 107 void ExtensionView::SetBackground(const SkBitmap& background) {
70 if (initialized_ && render_view_host()->view()) { 108 if (initialized_ && render_view_host()->view()) {
71 render_view_host()->view()->SetBackground(background); 109 render_view_host()->view()->SetBackground(background);
72 } else { 110 } else {
73 pending_background_ = background; 111 pending_background_ = background;
74 } 112 }
75 ShowIfCompletelyLoaded(); 113 ShowIfCompletelyLoaded();
76 } 114 }
77 115
78 void ExtensionView::DidContentsPreferredWidthChange(const int pref_width) { 116 void ExtensionView::DidContentsPreferredWidthChange(const int pref_width) {
79 // Don't actually do anything with this information until we have been shown. 117 // Don't actually do anything with this information until we have been shown.
80 // Size changes will not be honored by lower layers while we are hidden. 118 // Size changes will not be honored by lower layers while we are hidden.
81 if (!IsVisible()) { 119 if (!IsVisible()) {
82 pending_preferred_width_ = pref_width; 120 pending_preferred_width_ = pref_width;
83 } else if (pref_width > 0 && pref_width != GetPreferredSize().width()) { 121 } else if (pref_width > 0 && pref_width != GetPreferredSize().width()) {
84 SetPreferredSize(gfx::Size(pref_width, height())); 122 SetPreferredSize(gfx::Size(pref_width, height()));
85 } 123 }
86 } 124 }
87 125
88 void ExtensionView::ViewHierarchyChanged(bool is_add, 126 void ExtensionView::ViewHierarchyChanged(bool is_add,
89 views::View *parent, 127 views::View *parent,
90 views::View *child) { 128 views::View *child) {
91 NativeViewHost::ViewHierarchyChanged(is_add, parent, child); 129 NativeViewHost::ViewHierarchyChanged(is_add, parent, child);
92 if (is_add && GetWidget() && !initialized_) { 130 if (is_add && GetWidget() && !initialized_)
93 initialized_ = true; 131 CreateWidgetHostView();
94 RenderWidgetHostView* view = 132 }
95 RenderWidgetHostView::CreateViewForWidget(render_view_host());
96 133
97 // TODO(mpcomplete): RWHV needs a cross-platform Init function. 134 void ExtensionView::RecoverCrashedExtension() {
98 #if defined(OS_WIN) 135 CleanUp();
99 // Create the HWND. Note: 136 CreateWidgetHostView();
100 // RenderWidgetHostHWND supports windowed plugins, but if we ever also
101 // wanted to support constrained windows with this, we would need an
102 // additional HWND to parent off of because windowed plugin HWNDs cannot
103 // exist in the same z-order as constrained windows.
104 RenderWidgetHostViewWin* view_win =
105 static_cast<RenderWidgetHostViewWin*>(view);
106 HWND hwnd = view_win->Create(GetWidget()->GetNativeView());
107 view_win->ShowWindow(SW_SHOW);
108 Attach(hwnd);
109 #else
110 NOTIMPLEMENTED();
111 #endif
112
113 host_->CreateRenderView(view);
114 SetVisible(false);
115
116 if (!pending_background_.empty()) {
117 render_view_host()->view()->SetBackground(pending_background_);
118 pending_background_.reset();
119 }
120 }
121 } 137 }
122 138
123 void ExtensionView::HandleMouseEvent() { 139 void ExtensionView::HandleMouseEvent() {
124 if (container_) 140 if (container_)
125 container_->OnExtensionMouseEvent(this); 141 container_->OnExtensionMouseEvent(this);
126 } 142 }
127 143
128 void ExtensionView::HandleMouseLeave() { 144 void ExtensionView::HandleMouseLeave() {
129 if (container_) 145 if (container_)
130 container_->OnExtensionMouseLeave(this); 146 container_->OnExtensionMouseLeave(this);
131 } 147 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_view.h ('k') | chrome/browser/task_manager_resource_providers.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698