| 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 211 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  222     CreateRenderViewNow(); |  222     CreateRenderViewNow(); | 
|  223   } else { |  223   } else { | 
|  224     ProcessCreationQueue::GetInstance()->CreateSoon(this); |  224     ProcessCreationQueue::GetInstance()->CreateSoon(this); | 
|  225   } |  225   } | 
|  226 } |  226 } | 
|  227  |  227  | 
|  228 void ExtensionHost::CreateRenderViewNow() { |  228 void ExtensionHost::CreateRenderViewNow() { | 
|  229   LoadInitialURL(); |  229   LoadInitialURL(); | 
|  230   if (is_background_page()) { |  230   if (is_background_page()) { | 
|  231     DCHECK(IsRenderViewLive()); |  231     DCHECK(IsRenderViewLive()); | 
|  232     profile_->GetExtensionService()->DidCreateRenderViewForBackgroundPage(this); |  232     extensions::ExtensionSystem::Get(profile_)->extension_service()-> | 
 |  233         DidCreateRenderViewForBackgroundPage(this); | 
|  233   } |  234   } | 
|  234 } |  235 } | 
|  235  |  236  | 
|  236 extensions::WindowController* |  237 extensions::WindowController* | 
|  237 ExtensionHost::GetExtensionWindowController() const { |  238 ExtensionHost::GetExtensionWindowController() const { | 
|  238   return view() && view()->browser() ? |  239   return view() && view()->browser() ? | 
|  239       view()->browser()->extension_window_controller() : NULL; |  240       view()->browser()->extension_window_controller() : NULL; | 
|  240 } |  241 } | 
|  241  |  242  | 
|  242 const GURL& ExtensionHost::GetURL() const { |  243 const GURL& ExtensionHost::GetURL() const { | 
|  243   return host_contents()->GetURL(); |  244   return host_contents()->GetURL(); | 
|  244 } |  245 } | 
|  245  |  246  | 
|  246 void ExtensionHost::LoadInitialURL() { |  247 void ExtensionHost::LoadInitialURL() { | 
|  247   if (!is_background_page() && |  248   if (!is_background_page() && | 
|  248       !profile_->GetExtensionService()->IsBackgroundPageReady(extension_)) { |  249       !extensions::ExtensionSystem::Get(profile_)->extension_service()-> | 
 |  250           IsBackgroundPageReady(extension_)) { | 
|  249     // Make sure the background page loads before any others. |  251     // Make sure the background page loads before any others. | 
|  250     registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_BACKGROUND_PAGE_READY, |  252     registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_BACKGROUND_PAGE_READY, | 
|  251                    content::Source<Extension>(extension_)); |  253                    content::Source<Extension>(extension_)); | 
|  252     return; |  254     return; | 
|  253   } |  255   } | 
|  254  |  256  | 
|  255   host_contents_->GetController().LoadURL( |  257   host_contents_->GetController().LoadURL( | 
|  256       initial_url_, content::Referrer(), content::PAGE_TRANSITION_LINK, |  258       initial_url_, content::Referrer(), content::PAGE_TRANSITION_LINK, | 
|  257       std::string()); |  259       std::string()); | 
|  258 } |  260 } | 
|  259  |  261  | 
|  260 void ExtensionHost::Close() { |  262 void ExtensionHost::Close() { | 
|  261   content::NotificationService::current()->Notify( |  263   content::NotificationService::current()->Notify( | 
|  262       chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE, |  264       chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE, | 
|  263       content::Source<Profile>(profile_), |  265       content::Source<Profile>(profile_), | 
|  264       content::Details<ExtensionHost>(this)); |  266       content::Details<ExtensionHost>(this)); | 
|  265 } |  267 } | 
|  266  |  268  | 
|  267 void ExtensionHost::Observe(int type, |  269 void ExtensionHost::Observe(int type, | 
|  268                             const content::NotificationSource& source, |  270                             const content::NotificationSource& source, | 
|  269                             const content::NotificationDetails& details) { |  271                             const content::NotificationDetails& details) { | 
|  270   switch (type) { |  272   switch (type) { | 
|  271     case chrome::NOTIFICATION_EXTENSION_BACKGROUND_PAGE_READY: |  273     case chrome::NOTIFICATION_EXTENSION_BACKGROUND_PAGE_READY: | 
|  272       DCHECK(profile_->GetExtensionService()-> |  274       DCHECK(extensions::ExtensionSystem::Get(profile_)->extension_service()-> | 
|  273           IsBackgroundPageReady(extension_)); |  275           IsBackgroundPageReady(extension_)); | 
|  274       LoadInitialURL(); |  276       LoadInitialURL(); | 
|  275       break; |  277       break; | 
|  276     case chrome::NOTIFICATION_EXTENSION_UNLOADED: |  278     case chrome::NOTIFICATION_EXTENSION_UNLOADED: | 
|  277       // The extension object will be deleted after this notification has been |  279       // The extension object will be deleted after this notification has been | 
|  278       // sent. NULL it out so that dirty pointer issues don't arise in cases |  280       // sent. NULL it out so that dirty pointer issues don't arise in cases | 
|  279       // when multiple ExtensionHost objects pointing to the same Extension are |  281       // when multiple ExtensionHost objects pointing to the same Extension are | 
|  280       // present. |  282       // present. | 
|  281       if (extension_ == content::Details<UnloadedExtensionInfo>(details)-> |  283       if (extension_ == content::Details<UnloadedExtensionInfo>(details)-> | 
|  282           extension) { |  284           extension) { | 
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  380 } |  382 } | 
|  381  |  383  | 
|  382 void ExtensionHost::DocumentAvailableInMainFrame() { |  384 void ExtensionHost::DocumentAvailableInMainFrame() { | 
|  383   // If the document has already been marked as available for this host, then |  385   // If the document has already been marked as available for this host, then | 
|  384   // bail. No need for the redundant setup. http://crbug.com/31170 |  386   // bail. No need for the redundant setup. http://crbug.com/31170 | 
|  385   if (document_element_available_) |  387   if (document_element_available_) | 
|  386     return; |  388     return; | 
|  387  |  389  | 
|  388   document_element_available_ = true; |  390   document_element_available_ = true; | 
|  389   if (is_background_page()) { |  391   if (is_background_page()) { | 
|  390     profile_->GetExtensionService()->SetBackgroundPageReady(extension_); |  392     extensions::ExtensionSystem::Get(profile_)->extension_service()-> | 
 |  393         SetBackgroundPageReady(extension_); | 
|  391   } else { |  394   } else { | 
|  392     switch (extension_host_type_) { |  395     switch (extension_host_type_) { | 
|  393       case chrome::VIEW_TYPE_EXTENSION_INFOBAR: |  396       case chrome::VIEW_TYPE_EXTENSION_INFOBAR: | 
|  394         InsertInfobarCSS(); |  397         InsertInfobarCSS(); | 
|  395         break; |  398         break; | 
|  396       default: |  399       default: | 
|  397         break;  // No style sheet for other types, at the moment. |  400         break;  // No style sheet for other types, at the moment. | 
|  398     } |  401     } | 
|  399   } |  402   } | 
|  400 } |  403 } | 
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  645 void ExtensionHost::RequestMediaAccessPermission( |  648 void ExtensionHost::RequestMediaAccessPermission( | 
|  646     content::WebContents* web_contents, |  649     content::WebContents* web_contents, | 
|  647     const content::MediaStreamRequest* request, |  650     const content::MediaStreamRequest* request, | 
|  648     const content::MediaResponseCallback& callback) { |  651     const content::MediaResponseCallback& callback) { | 
|  649   // For tab capture device, we require the tabCapture permission. |  652   // For tab capture device, we require the tabCapture permission. | 
|  650   RequestMediaAccessPermissionHelper::AuthorizeRequest( |  653   RequestMediaAccessPermissionHelper::AuthorizeRequest( | 
|  651       request, callback, extension(), false); |  654       request, callback, extension(), false); | 
|  652 } |  655 } | 
|  653  |  656  | 
|  654 }  // namespace extensions |  657 }  // namespace extensions | 
| OLD | NEW |