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

Side by Side Diff: chrome/browser/extensions/extension_host.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_host.h" 5 #include "chrome/browser/extensions/extension_host.h"
6 6
7 #include "app/l10n_util.h"
7 #include "app/resource_bundle.h" 8 #include "app/resource_bundle.h"
9 #include "base/string_util.h"
8 #include "chrome/browser/browser.h" 10 #include "chrome/browser/browser.h"
9 #include "chrome/browser/browser_list.h" 11 #include "chrome/browser/browser_list.h"
10 #include "chrome/browser/browser_process.h" 12 #include "chrome/browser/browser_process.h"
11 #include "chrome/browser/debugger/devtools_manager.h" 13 #include "chrome/browser/debugger/devtools_manager.h"
12 #include "chrome/browser/extensions/extension_message_service.h" 14 #include "chrome/browser/extensions/extension_message_service.h"
13 #include "chrome/browser/extensions/extension_process_manager.h" 15 #include "chrome/browser/extensions/extension_process_manager.h"
14 #include "chrome/browser/profile.h" 16 #include "chrome/browser/profile.h"
15 #include "chrome/browser/renderer_host/render_view_host.h" 17 #include "chrome/browser/renderer_host/render_view_host.h"
16 #include "chrome/browser/renderer_host/render_process_host.h" 18 #include "chrome/browser/renderer_host/render_process_host.h"
17 #include "chrome/browser/renderer_host/render_widget_host.h" 19 #include "chrome/browser/renderer_host/render_widget_host.h"
18 #include "chrome/browser/renderer_host/render_widget_host_view.h" 20 #include "chrome/browser/renderer_host/render_widget_host_view.h"
21 #include "chrome/browser/tab_contents/infobar_delegate.h"
19 #include "chrome/browser/tab_contents/site_instance.h" 22 #include "chrome/browser/tab_contents/site_instance.h"
20 #include "chrome/browser/tab_contents/tab_contents.h" 23 #include "chrome/browser/tab_contents/tab_contents.h"
21 #include "chrome/browser/tab_contents/tab_contents_view.h" 24 #include "chrome/browser/tab_contents/tab_contents_view.h"
22 #include "chrome/common/extensions/extension.h" 25 #include "chrome/common/extensions/extension.h"
23 #include "chrome/common/pref_names.h" 26 #include "chrome/common/pref_names.h"
24 #include "chrome/common/pref_service.h" 27 #include "chrome/common/pref_service.h"
25 28
26 #include "grit/browser_resources.h" 29 #include "grit/browser_resources.h"
27 #include "grit/generated_resources.h" 30 #include "grit/generated_resources.h"
31 #include "grit/theme_resources.h"
28 32
29 #include "webkit/glue/context_menu.h" 33 #include "webkit/glue/context_menu.h"
30 34
35 namespace {
36
37 class CrashedExtensionInfobarDelegate : public ConfirmInfoBarDelegate {
38 public:
39 CrashedExtensionInfobarDelegate(TabContents* tab_contents,
40 ExtensionHost* extension_host)
41 : ConfirmInfoBarDelegate(tab_contents),
42 extension_host_(extension_host) {
43 }
44
45 virtual std::wstring GetMessageText() const {
46 return l10n_util::GetStringF(IDS_EXTENSION_CRASHED_INFOBAR_MESSAGE,
47 UTF8ToWide(extension_host_->extension()->name()));
48 }
49
50 virtual SkBitmap* GetIcon() const {
51 // TODO(erikkay): Create extension-specific icon. http://crbug.com/14591
52 return ResourceBundle::GetSharedInstance().GetBitmapNamed(
53 IDR_INFOBAR_PLUGIN_CRASHED);
54 }
55
56 virtual int GetButtons() const {
57 return BUTTON_OK;
58 }
59
60 virtual std::wstring GetButtonLabel(
61 ConfirmInfoBarDelegate::InfoBarButton button) const {
62 if (button == BUTTON_OK)
63 return l10n_util::GetString(IDS_EXTENSION_CRASHED_INFOBAR_RESTART_BUTTON);
64 return ConfirmInfoBarDelegate::GetButtonLabel(button);
65 }
66
67 virtual bool Accept() {
68 extension_host_->RecoverCrashedExtension();
69 return true;
70 }
71
72 private:
73 ExtensionHost* extension_host_;
74
75 DISALLOW_COPY_AND_ASSIGN(CrashedExtensionInfobarDelegate);
76 };
77
78 } // namespace
79
31 ExtensionHost::ExtensionHost(Extension* extension, SiteInstance* site_instance, 80 ExtensionHost::ExtensionHost(Extension* extension, SiteInstance* site_instance,
32 const GURL& url, ExtensionProcessManager* manager) 81 const GURL& url, ExtensionProcessManager* manager)
33 : extension_(extension), 82 : extension_(extension),
34 manager_(manager), 83 manager_(manager),
35 did_stop_loading_(false), 84 did_stop_loading_(false),
36 url_(url) { 85 url_(url) {
37 render_view_host_ = new RenderViewHost( 86 render_view_host_ = new RenderViewHost(
38 site_instance, this, MSG_ROUTING_NONE, NULL); 87 site_instance, this, MSG_ROUTING_NONE, NULL);
39 render_view_host_->AllowExtensionBindings(); 88 render_view_host_->AllowExtensionBindings();
40 } 89 }
(...skipping 17 matching lines...) Expand all
58 } 107 }
59 108
60 RenderProcessHost* ExtensionHost::render_process_host() const { 109 RenderProcessHost* ExtensionHost::render_process_host() const {
61 return render_view_host_->process(); 110 return render_view_host_->process();
62 } 111 }
63 112
64 SiteInstance* ExtensionHost::site_instance() const { 113 SiteInstance* ExtensionHost::site_instance() const {
65 return render_view_host_->site_instance(); 114 return render_view_host_->site_instance();
66 } 115 }
67 116
117 bool ExtensionHost::IsRenderViewLive() const {
118 return render_view_host_->IsRenderViewLive();
119 }
120
68 void ExtensionHost::CreateRenderView(RenderWidgetHostView* host_view) { 121 void ExtensionHost::CreateRenderView(RenderWidgetHostView* host_view) {
69 render_view_host_->set_view(host_view); 122 render_view_host_->set_view(host_view);
70 render_view_host_->CreateRenderView(); 123 render_view_host_->CreateRenderView();
71 render_view_host_->NavigateToURL(url_); 124 render_view_host_->NavigateToURL(url_);
72 } 125 }
73 126
127 void ExtensionHost::RecoverCrashedExtension() {
128 DCHECK(!IsRenderViewLive());
129 #if defined(TOOLKIT_VIEWS)
130 view_->RecoverCrashedExtension();
131 #endif
132 if (IsRenderViewLive())
133 manager_->OnExtensionProcessRestored(this);
134 }
135
74 void ExtensionHost::UpdatePreferredWidth(int pref_width) { 136 void ExtensionHost::UpdatePreferredWidth(int pref_width) {
75 #if defined(OS_WIN) 137 #if defined(OS_WIN)
76 if (view_.get()) 138 if (view_.get())
77 view_->DidContentsPreferredWidthChange(pref_width); 139 view_->DidContentsPreferredWidthChange(pref_width);
78 #endif 140 #endif
79 } 141 }
80 142
143 void ExtensionHost::RenderViewGone(RenderViewHost* render_view_host) {
144 DCHECK_EQ(render_view_host_, render_view_host);
145 TabContents* current_tab = GetBrowser()->GetSelectedTabContents();
146 DCHECK(current_tab);
147 if (current_tab) {
148 current_tab->AddInfoBar(
149 new CrashedExtensionInfobarDelegate(current_tab, this));
150 }
151 manager_->OnExtensionProcessCrashed(this);
152 }
153
81 WebPreferences ExtensionHost::GetWebkitPrefs() { 154 WebPreferences ExtensionHost::GetWebkitPrefs() {
82 PrefService* prefs = render_view_host()->process()->profile()->GetPrefs(); 155 PrefService* prefs = render_view_host()->process()->profile()->GetPrefs();
83 const bool kIsDomUI = true; 156 const bool kIsDomUI = true;
84 return RenderViewHostDelegateHelper::GetWebkitPrefs(prefs, kIsDomUI); 157 return RenderViewHostDelegateHelper::GetWebkitPrefs(prefs, kIsDomUI);
85 } 158 }
86 159
87 void ExtensionHost::RunJavaScriptMessage( 160 void ExtensionHost::RunJavaScriptMessage(
88 const std::wstring& message, 161 const std::wstring& message,
89 const std::wstring& default_prompt, 162 const std::wstring& default_prompt,
90 const GURL& frame_url, 163 const GURL& frame_url,
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 Browser* browser = BrowserList::GetLastActiveWithProfile( 287 Browser* browser = BrowserList::GetLastActiveWithProfile(
215 render_view_host()->process()->profile()); 288 render_view_host()->process()->profile());
216 // NOTE(rafaelw): This can return NULL in some circumstances. In particular, 289 // NOTE(rafaelw): This can return NULL in some circumstances. In particular,
217 // a toolstrip or background_page onload chrome.tabs api call can make it 290 // a toolstrip or background_page onload chrome.tabs api call can make it
218 // into here before the browser is sufficiently initialized to return here. 291 // into here before the browser is sufficiently initialized to return here.
219 // A similar situation may arise during shutdown. 292 // A similar situation may arise during shutdown.
220 // TODO(rafaelw): Delay creation of background_page until the browser 293 // TODO(rafaelw): Delay creation of background_page until the browser
221 // is available. http://code.google.com/p/chromium/issues/detail?id=13284 294 // is available. http://code.google.com/p/chromium/issues/detail?id=13284
222 return browser; 295 return browser;
223 } 296 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_host.h ('k') | chrome/browser/extensions/extension_process_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698