OLD | NEW |
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" | |
8 #include "app/resource_bundle.h" | 7 #include "app/resource_bundle.h" |
9 #include "base/string_util.h" | 8 #include "base/string_util.h" |
10 #include "chrome/browser/browser.h" | 9 #include "chrome/browser/browser.h" |
11 #include "chrome/browser/browser_list.h" | 10 #include "chrome/browser/browser_list.h" |
12 #include "chrome/browser/debugger/devtools_manager.h" | 11 #include "chrome/browser/debugger/devtools_manager.h" |
13 #include "chrome/browser/extensions/extension_message_service.h" | 12 #include "chrome/browser/extensions/extension_message_service.h" |
14 #include "chrome/browser/extensions/extension_tabs_module.h" | 13 #include "chrome/browser/extensions/extension_tabs_module.h" |
15 #include "chrome/browser/profile.h" | 14 #include "chrome/browser/profile.h" |
16 #include "chrome/browser/renderer_host/render_view_host.h" | 15 #include "chrome/browser/renderer_host/render_view_host.h" |
17 #include "chrome/browser/renderer_host/render_process_host.h" | 16 #include "chrome/browser/renderer_host/render_process_host.h" |
18 #include "chrome/browser/renderer_host/render_widget_host.h" | 17 #include "chrome/browser/renderer_host/render_widget_host.h" |
19 #include "chrome/browser/renderer_host/render_widget_host_view.h" | 18 #include "chrome/browser/renderer_host/render_widget_host_view.h" |
20 #include "chrome/browser/renderer_host/site_instance.h" | 19 #include "chrome/browser/renderer_host/site_instance.h" |
21 #include "chrome/browser/tab_contents/infobar_delegate.h" | |
22 #include "chrome/browser/tab_contents/tab_contents.h" | |
23 #include "chrome/browser/tab_contents/tab_contents_view.h" | |
24 #include "chrome/common/bindings_policy.h" | 20 #include "chrome/common/bindings_policy.h" |
25 #include "chrome/common/extensions/extension.h" | 21 #include "chrome/common/extensions/extension.h" |
26 #include "chrome/common/notification_service.h" | 22 #include "chrome/common/notification_service.h" |
27 #include "chrome/common/pref_names.h" | 23 #include "chrome/common/pref_names.h" |
28 #include "chrome/common/pref_service.h" | 24 #include "chrome/common/pref_service.h" |
29 #include "chrome/common/view_types.h" | 25 #include "chrome/common/view_types.h" |
30 #include "chrome/common/render_messages.h" | 26 #include "chrome/common/render_messages.h" |
31 #include "chrome/common/url_constants.h" | 27 #include "chrome/common/url_constants.h" |
32 | 28 |
33 #include "grit/browser_resources.h" | 29 #include "grit/browser_resources.h" |
34 #include "grit/generated_resources.h" | |
35 #include "grit/theme_resources.h" | |
36 | 30 |
37 #include "webkit/glue/context_menu.h" | 31 #include "webkit/glue/context_menu.h" |
38 | 32 |
39 namespace { | |
40 | |
41 class CrashedExtensionInfobarDelegate : public ConfirmInfoBarDelegate { | |
42 public: | |
43 CrashedExtensionInfobarDelegate(TabContents* tab_contents, | |
44 ExtensionHost* extension_host) | |
45 : ConfirmInfoBarDelegate(tab_contents), | |
46 extension_host_(extension_host) { | |
47 } | |
48 | |
49 virtual std::wstring GetMessageText() const { | |
50 return l10n_util::GetStringF(IDS_EXTENSION_CRASHED_INFOBAR_MESSAGE, | |
51 UTF8ToWide(extension_host_->extension()->name())); | |
52 } | |
53 | |
54 virtual SkBitmap* GetIcon() const { | |
55 // TODO(erikkay): Create extension-specific icon. http://crbug.com/14591 | |
56 return ResourceBundle::GetSharedInstance().GetBitmapNamed( | |
57 IDR_INFOBAR_PLUGIN_CRASHED); | |
58 } | |
59 | |
60 virtual int GetButtons() const { | |
61 return BUTTON_OK; | |
62 } | |
63 | |
64 virtual std::wstring GetButtonLabel( | |
65 ConfirmInfoBarDelegate::InfoBarButton button) const { | |
66 if (button == BUTTON_OK) | |
67 return l10n_util::GetString(IDS_EXTENSION_CRASHED_INFOBAR_RESTART_BUTTON); | |
68 return ConfirmInfoBarDelegate::GetButtonLabel(button); | |
69 } | |
70 | |
71 virtual bool Accept() { | |
72 extension_host_->RecoverCrashedExtension(); | |
73 return true; | |
74 } | |
75 | |
76 private: | |
77 ExtensionHost* extension_host_; | |
78 | |
79 DISALLOW_COPY_AND_ASSIGN(CrashedExtensionInfobarDelegate); | |
80 }; | |
81 | |
82 } // namespace | |
83 | |
84 | |
85 // static | 33 // static |
86 bool ExtensionHost::enable_dom_automation_ = false; | 34 bool ExtensionHost::enable_dom_automation_ = false; |
87 | 35 |
88 ExtensionHost::ExtensionHost(Extension* extension, SiteInstance* site_instance, | 36 ExtensionHost::ExtensionHost(Extension* extension, SiteInstance* site_instance, |
89 const GURL& url, ViewType::Type host_type) | 37 const GURL& url, ViewType::Type host_type) |
90 : extension_(extension), | 38 : extension_(extension), |
91 profile_(site_instance->browsing_instance()->profile()), | 39 profile_(site_instance->browsing_instance()->profile()), |
92 did_stop_loading_(false), | 40 did_stop_loading_(false), |
93 document_element_available_(false), | 41 document_element_available_(false), |
94 url_(url), | 42 url_(url), |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 } | 106 } |
159 | 107 |
160 void ExtensionHost::Observe(NotificationType type, | 108 void ExtensionHost::Observe(NotificationType type, |
161 const NotificationSource& source, | 109 const NotificationSource& source, |
162 const NotificationDetails& details) { | 110 const NotificationDetails& details) { |
163 DCHECK(type == NotificationType::EXTENSION_BACKGROUND_PAGE_READY); | 111 DCHECK(type == NotificationType::EXTENSION_BACKGROUND_PAGE_READY); |
164 DCHECK(extension_->GetBackgroundPageReady()); | 112 DCHECK(extension_->GetBackgroundPageReady()); |
165 NavigateToURL(url_); | 113 NavigateToURL(url_); |
166 } | 114 } |
167 | 115 |
168 void ExtensionHost::RecoverCrashedExtension() { | |
169 DCHECK(!IsRenderViewLive()); | |
170 #if defined(TOOLKIT_VIEWS) | |
171 if (view_.get()) { | |
172 // The view should call us back to CreateRenderView, which is the place | |
173 // where we create the render process and fire notification. | |
174 view_->RecoverCrashedExtension(); | |
175 } else { | |
176 CreateRenderView(NULL); | |
177 } | |
178 #else | |
179 CreateRenderView(NULL); | |
180 #endif | |
181 } | |
182 | |
183 void ExtensionHost::UpdatePreferredWidth(int pref_width) { | 116 void ExtensionHost::UpdatePreferredWidth(int pref_width) { |
184 #if defined(TOOLKIT_VIEWS) || defined(OS_LINUX) | 117 #if defined(TOOLKIT_VIEWS) || defined(OS_LINUX) |
185 if (view_.get()) | 118 if (view_.get()) |
186 view_->UpdatePreferredWidth(pref_width); | 119 view_->UpdatePreferredWidth(pref_width); |
187 #endif | 120 #endif |
188 } | 121 } |
189 | 122 |
190 void ExtensionHost::RenderViewGone(RenderViewHost* render_view_host) { | 123 void ExtensionHost::RenderViewGone(RenderViewHost* render_view_host) { |
191 DCHECK_EQ(render_view_host_, render_view_host); | 124 DCHECK_EQ(render_view_host_, render_view_host); |
192 Browser* browser = GetBrowser(); | |
193 if (browser) { | |
194 TabContents* current_tab = browser->GetSelectedTabContents(); | |
195 if (current_tab) { | |
196 current_tab->AddInfoBar( | |
197 new CrashedExtensionInfobarDelegate(current_tab, this)); | |
198 } | |
199 } | |
200 NotificationService::current()->Notify( | 125 NotificationService::current()->Notify( |
201 NotificationType::EXTENSION_PROCESS_CRASHED, | 126 NotificationType::EXTENSION_PROCESS_CRASHED, |
202 Source<Profile>(profile_), | 127 Source<ExtensionsService>(profile_->GetExtensionsService()), |
203 Details<ExtensionHost>(this)); | 128 Details<ExtensionHost>(this)); |
204 } | 129 } |
205 | 130 |
206 void ExtensionHost::DidNavigate(RenderViewHost* render_view_host, | 131 void ExtensionHost::DidNavigate(RenderViewHost* render_view_host, |
207 const ViewHostMsg_FrameNavigate_Params& params) { | 132 const ViewHostMsg_FrameNavigate_Params& params) { |
208 // We only care when the outer frame changes. | 133 // We only care when the outer frame changes. |
209 switch (params.transition) { | 134 switch (params.transition) { |
210 case PageTransition::AUTO_SUBFRAME: | 135 case PageTransition::AUTO_SUBFRAME: |
211 case PageTransition::MANUAL_SUBFRAME: | 136 case PageTransition::MANUAL_SUBFRAME: |
212 return; | 137 return; |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 window_id = ExtensionTabUtil::GetWindowId( | 332 window_id = ExtensionTabUtil::GetWindowId( |
408 const_cast<ExtensionHost* >(this)->GetBrowser()); | 333 const_cast<ExtensionHost* >(this)->GetBrowser()); |
409 } else if (extension_host_type_ == ViewType::EXTENSION_BACKGROUND_PAGE) { | 334 } else if (extension_host_type_ == ViewType::EXTENSION_BACKGROUND_PAGE) { |
410 // Background page is not attached to any browser window, so pass -1. | 335 // Background page is not attached to any browser window, so pass -1. |
411 window_id = -1; | 336 window_id = -1; |
412 } else { | 337 } else { |
413 NOTREACHED(); | 338 NOTREACHED(); |
414 } | 339 } |
415 return window_id; | 340 return window_id; |
416 } | 341 } |
OLD | NEW |