OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 <list> | 7 #include <list> |
8 | 8 |
9 #include "base/memory/singleton.h" | 9 #include "base/memory/singleton.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 // Listen for when the render process' handle is available so we can add it | 150 // Listen for when the render process' handle is available so we can add it |
151 // to the task manager then. | 151 // to the task manager then. |
152 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CREATED, | 152 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CREATED, |
153 Source<RenderProcessHost>(render_process_host())); | 153 Source<RenderProcessHost>(render_process_host())); |
154 // Listen for when an extension is unloaded from the same profile, as it may | 154 // Listen for when an extension is unloaded from the same profile, as it may |
155 // be the same extension that this points to. | 155 // be the same extension that this points to. |
156 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, | 156 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, |
157 Source<Profile>(profile_)); | 157 Source<Profile>(profile_)); |
158 } | 158 } |
159 | 159 |
| 160 // This "mock" constructor should only be used by unit tests. |
| 161 ExtensionHost::ExtensionHost(const Extension* extension, |
| 162 content::ViewType host_type) |
| 163 : extension_(extension), |
| 164 extension_id_(extension->id()), |
| 165 profile_(NULL), |
| 166 render_view_host_(NULL), |
| 167 did_stop_loading_(false), |
| 168 document_element_available_(false), |
| 169 url_(GURL()), |
| 170 ALLOW_THIS_IN_INITIALIZER_LIST( |
| 171 extension_function_dispatcher_(profile_, this)), |
| 172 extension_host_type_(host_type), |
| 173 associated_tab_contents_(NULL) { |
| 174 } |
| 175 |
160 ExtensionHost::~ExtensionHost() { | 176 ExtensionHost::~ExtensionHost() { |
161 NotificationService::current()->Notify( | 177 NotificationService::current()->Notify( |
162 chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, | 178 chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, |
163 Source<Profile>(profile_), | 179 Source<Profile>(profile_), |
164 Details<ExtensionHost>(this)); | 180 Details<ExtensionHost>(this)); |
165 ProcessCreationQueue::GetInstance()->Remove(this); | 181 ProcessCreationQueue::GetInstance()->Remove(this); |
166 GetJavaScriptDialogCreatorInstance()->ResetJavaScriptState(this); | 182 GetJavaScriptDialogCreatorInstance()->ResetJavaScriptState(this); |
167 render_view_host_->Shutdown(); // deletes render_view_host | 183 // render_view_host_ may be NULL in unit tests. |
| 184 if (render_view_host_) |
| 185 render_view_host_->Shutdown(); // deletes render_view_host |
168 } | 186 } |
169 | 187 |
170 void ExtensionHost::CreateView(Browser* browser) { | 188 void ExtensionHost::CreateView(Browser* browser) { |
171 #if defined(TOOLKIT_VIEWS) | 189 #if defined(TOOLKIT_VIEWS) |
172 view_.reset(new ExtensionView(this, browser)); | 190 view_.reset(new ExtensionView(this, browser)); |
173 // We own |view_|, so don't auto delete when it's removed from the view | 191 // We own |view_|, so don't auto delete when it's removed from the view |
174 // hierarchy. | 192 // hierarchy. |
175 view_->set_parent_owned(false); | 193 view_->set_parent_owned(false); |
176 #elif defined(OS_MACOSX) | 194 #elif defined(OS_MACOSX) |
177 view_.reset(new ExtensionViewMac(this, browser)); | 195 view_.reset(new ExtensionViewMac(this, browser)); |
(...skipping 616 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
794 void ExtensionHost::RenderViewCreated(RenderViewHost* render_view_host) { | 812 void ExtensionHost::RenderViewCreated(RenderViewHost* render_view_host) { |
795 if (view_.get()) | 813 if (view_.get()) |
796 view_->RenderViewCreated(); | 814 view_->RenderViewCreated(); |
797 | 815 |
798 if (extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_POPUP || | 816 if (extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_POPUP || |
799 extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_INFOBAR) { | 817 extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_INFOBAR) { |
800 render_view_host->EnablePreferredSizeMode( | 818 render_view_host->EnablePreferredSizeMode( |
801 kPreferredSizeWidth | kPreferredSizeHeightThisIsSlow); | 819 kPreferredSizeWidth | kPreferredSizeHeightThisIsSlow); |
802 } | 820 } |
803 } | 821 } |
OLD | NEW |