OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/bind.h" | 9 #include "base/bind.h" |
10 #include "base/memory/singleton.h" | 10 #include "base/memory/singleton.h" |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
53 #include "ui/base/layout.h" | 53 #include "ui/base/layout.h" |
54 #include "ui/base/resource/resource_bundle.h" | 54 #include "ui/base/resource/resource_bundle.h" |
55 | 55 |
56 using WebKit::WebDragOperation; | 56 using WebKit::WebDragOperation; |
57 using WebKit::WebDragOperationsMask; | 57 using WebKit::WebDragOperationsMask; |
58 using content::NativeWebKeyboardEvent; | 58 using content::NativeWebKeyboardEvent; |
59 using content::OpenURLParams; | 59 using content::OpenURLParams; |
60 using content::RenderViewHost; | 60 using content::RenderViewHost; |
61 using content::SiteInstance; | 61 using content::SiteInstance; |
62 using content::WebContents; | 62 using content::WebContents; |
63 using extensions::ExtensionSystem; | 63 |
64 namespace extensions { | |
64 | 65 |
65 // Helper class that rate-limits the creation of renderer processes for | 66 // Helper class that rate-limits the creation of renderer processes for |
66 // ExtensionHosts, to avoid blocking the UI. | 67 // ExtensionHosts, to avoid blocking the UI. |
67 class ExtensionHost::ProcessCreationQueue { | 68 class ExtensionHost::ProcessCreationQueue { |
68 public: | 69 public: |
69 static ProcessCreationQueue* GetInstance() { | 70 static ProcessCreationQueue* GetInstance() { |
70 return Singleton<ProcessCreationQueue>::get(); | 71 return Singleton<ProcessCreationQueue>::get(); |
71 } | 72 } |
72 | 73 |
73 // Add a host to the queue for RenderView creation. | 74 // Add a host to the queue for RenderView creation. |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
115 | 116 |
116 typedef std::list<ExtensionHost*> Queue; | 117 typedef std::list<ExtensionHost*> Queue; |
117 Queue queue_; | 118 Queue queue_; |
118 bool pending_create_; | 119 bool pending_create_; |
119 base::WeakPtrFactory<ProcessCreationQueue> ptr_factory_; | 120 base::WeakPtrFactory<ProcessCreationQueue> ptr_factory_; |
120 }; | 121 }; |
121 | 122 |
122 //////////////// | 123 //////////////// |
123 // ExtensionHost | 124 // ExtensionHost |
124 | 125 |
125 ExtensionHost::ExtensionHost(const extensions::Extension* extension, | 126 ExtensionHost::ExtensionHost(const Extension* extension, |
126 SiteInstance* site_instance, | 127 SiteInstance* site_instance, |
127 const GURL& url, | 128 const GURL& url, |
128 chrome::ViewType host_type) | 129 chrome::ViewType host_type) |
129 : extension_(extension), | 130 : extension_(extension), |
130 extension_id_(extension->id()), | 131 extension_id_(extension->id()), |
131 profile_(Profile::FromBrowserContext( | 132 profile_(Profile::FromBrowserContext( |
132 site_instance->GetBrowserContext())), | 133 site_instance->GetBrowserContext())), |
133 render_view_host_(NULL), | 134 render_view_host_(NULL), |
134 did_stop_loading_(false), | 135 did_stop_loading_(false), |
135 document_element_available_(false), | 136 document_element_available_(false), |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
238 | 239 |
239 const GURL& ExtensionHost::GetURL() const { | 240 const GURL& ExtensionHost::GetURL() const { |
240 return host_contents()->GetURL(); | 241 return host_contents()->GetURL(); |
241 } | 242 } |
242 | 243 |
243 void ExtensionHost::LoadInitialURL() { | 244 void ExtensionHost::LoadInitialURL() { |
244 if (!is_background_page() && | 245 if (!is_background_page() && |
245 !profile_->GetExtensionService()->IsBackgroundPageReady(extension_)) { | 246 !profile_->GetExtensionService()->IsBackgroundPageReady(extension_)) { |
246 // Make sure the background page loads before any others. | 247 // Make sure the background page loads before any others. |
247 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_BACKGROUND_PAGE_READY, | 248 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_BACKGROUND_PAGE_READY, |
248 content::Source<extensions::Extension>(extension_)); | 249 content::Source<Extension>(extension_)); |
249 return; | 250 return; |
250 } | 251 } |
251 | 252 |
252 host_contents_->GetController().LoadURL( | 253 host_contents_->GetController().LoadURL( |
253 initial_url_, content::Referrer(), content::PAGE_TRANSITION_LINK, | 254 initial_url_, content::Referrer(), content::PAGE_TRANSITION_LINK, |
254 std::string()); | 255 std::string()); |
255 } | 256 } |
256 | 257 |
257 void ExtensionHost::Close() { | 258 void ExtensionHost::Close() { |
258 content::NotificationService::current()->Notify( | 259 content::NotificationService::current()->Notify( |
259 chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE, | 260 chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE, |
260 content::Source<Profile>(profile_), | 261 content::Source<Profile>(profile_), |
261 content::Details<ExtensionHost>(this)); | 262 content::Details<ExtensionHost>(this)); |
262 } | 263 } |
263 | 264 |
264 void ExtensionHost::Observe(int type, | 265 void ExtensionHost::Observe(int type, |
265 const content::NotificationSource& source, | 266 const content::NotificationSource& source, |
266 const content::NotificationDetails& details) { | 267 const content::NotificationDetails& details) { |
267 switch (type) { | 268 switch (type) { |
268 case chrome::NOTIFICATION_EXTENSION_BACKGROUND_PAGE_READY: | 269 case chrome::NOTIFICATION_EXTENSION_BACKGROUND_PAGE_READY: |
269 DCHECK(profile_->GetExtensionService()-> | 270 DCHECK(profile_->GetExtensionService()-> |
270 IsBackgroundPageReady(extension_)); | 271 IsBackgroundPageReady(extension_)); |
271 LoadInitialURL(); | 272 LoadInitialURL(); |
272 break; | 273 break; |
273 case chrome::NOTIFICATION_EXTENSION_UNLOADED: | 274 case chrome::NOTIFICATION_EXTENSION_UNLOADED: |
274 // The extension object will be deleted after this notification has been | 275 // The extension object will be deleted after this notification has been |
275 // sent. NULL it out so that dirty pointer issues don't arise in cases | 276 // sent. NULL it out so that dirty pointer issues don't arise in cases |
276 // when multiple ExtensionHost objects pointing to the same Extension are | 277 // when multiple ExtensionHost objects pointing to the same Extension are |
277 // present. | 278 // present. |
278 if (extension_ == | 279 if (extension_ == content::Details<UnloadedExtensionInfo>(details)-> |
not at google - send to devlin
2012/07/27 01:23:24
nit: keep line break after the ==
| |
279 content::Details<extensions::UnloadedExtensionInfo>( | 280 extension) { |
280 details)->extension) { | |
281 extension_ = NULL; | 281 extension_ = NULL; |
282 } | 282 } |
283 break; | 283 break; |
284 case content::NOTIFICATION_WEB_CONTENTS_DESTROYED: | 284 case content::NOTIFICATION_WEB_CONTENTS_DESTROYED: |
285 if (content::Source<WebContents>(source).ptr() == | 285 if (content::Source<WebContents>(source).ptr() == |
286 associated_web_contents_) { | 286 associated_web_contents_) { |
287 associated_web_contents_ = NULL; | 287 associated_web_contents_ = NULL; |
288 } | 288 } |
289 break; | 289 break; |
290 default: | 290 default: |
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
592 ExtensionTabUtil::CreateTab(new_contents, extension_id_, disposition, | 592 ExtensionTabUtil::CreateTab(new_contents, extension_id_, disposition, |
593 initial_pos, user_gesture); | 593 initial_pos, user_gesture); |
594 } | 594 } |
595 | 595 |
596 void ExtensionHost::RenderViewReady() { | 596 void ExtensionHost::RenderViewReady() { |
597 content::NotificationService::current()->Notify( | 597 content::NotificationService::current()->Notify( |
598 chrome::NOTIFICATION_EXTENSION_HOST_CREATED, | 598 chrome::NOTIFICATION_EXTENSION_HOST_CREATED, |
599 content::Source<Profile>(profile_), | 599 content::Source<Profile>(profile_), |
600 content::Details<ExtensionHost>(this)); | 600 content::Details<ExtensionHost>(this)); |
601 } | 601 } |
602 | |
603 } // namespace extensions | |
OLD | NEW |