| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "extensions/browser/extension_host.h" | 5 #include "extensions/browser/extension_host.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/metrics/field_trial.h" | 8 #include "base/metrics/field_trial.h" |
| 9 #include "base/metrics/histogram_macros.h" | 9 #include "base/metrics/histogram_macros.h" |
| 10 #include "base/profiler/scoped_tracker.h" | 10 #include "base/profiler/scoped_tracker.h" |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 browser_context_(site_instance->GetBrowserContext()), | 60 browser_context_(site_instance->GetBrowserContext()), |
| 61 render_view_host_(nullptr), | 61 render_view_host_(nullptr), |
| 62 has_loaded_once_(false), | 62 has_loaded_once_(false), |
| 63 document_element_available_(false), | 63 document_element_available_(false), |
| 64 initial_url_(url), | 64 initial_url_(url), |
| 65 extension_function_dispatcher_(browser_context_, this), | 65 extension_function_dispatcher_(browser_context_, this), |
| 66 extension_host_type_(host_type) { | 66 extension_host_type_(host_type) { |
| 67 // Not used for panels, see PanelHost. | 67 // Not used for panels, see PanelHost. |
| 68 DCHECK(host_type == VIEW_TYPE_EXTENSION_BACKGROUND_PAGE || | 68 DCHECK(host_type == VIEW_TYPE_EXTENSION_BACKGROUND_PAGE || |
| 69 host_type == VIEW_TYPE_EXTENSION_DIALOG || | 69 host_type == VIEW_TYPE_EXTENSION_DIALOG || |
| 70 host_type == VIEW_TYPE_EXTENSION_POPUP); | 70 host_type == VIEW_TYPE_EXTENSION_POPUP || |
| 71 host_type == VIEW_TYPE_EXTENSION_SIDEBAR); |
| 71 host_contents_.reset(WebContents::Create( | 72 host_contents_.reset(WebContents::Create( |
| 72 WebContents::CreateParams(browser_context_, site_instance))), | 73 WebContents::CreateParams(browser_context_, site_instance))); |
| 73 content::WebContentsObserver::Observe(host_contents_.get()); | 74 content::WebContentsObserver::Observe(host_contents_.get()); |
| 74 host_contents_->SetDelegate(this); | 75 host_contents_->SetDelegate(this); |
| 75 SetViewType(host_contents_.get(), host_type); | 76 SetViewType(host_contents_.get(), host_type); |
| 76 | 77 |
| 77 render_view_host_ = host_contents_->GetRenderViewHost(); | 78 render_view_host_ = host_contents_->GetRenderViewHost(); |
| 78 | 79 |
| 79 // Listen for when an extension is unloaded from the same profile, as it may | 80 // Listen for when an extension is unloaded from the same profile, as it may |
| 80 // be the same extension that this points to. | 81 // be the same extension that this points to. |
| 81 ExtensionRegistry::Get(browser_context_)->AddObserver(this); | 82 ExtensionRegistry::Get(browser_context_)->AddObserver(this); |
| 82 | 83 |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 return host_contents()->GetURL(); | 216 return host_contents()->GetURL(); |
| 216 } | 217 } |
| 217 | 218 |
| 218 void ExtensionHost::LoadInitialURL() { | 219 void ExtensionHost::LoadInitialURL() { |
| 219 load_start_.reset(new base::ElapsedTimer()); | 220 load_start_.reset(new base::ElapsedTimer()); |
| 220 host_contents_->GetController().LoadURL( | 221 host_contents_->GetController().LoadURL( |
| 221 initial_url_, content::Referrer(), ui::PAGE_TRANSITION_LINK, | 222 initial_url_, content::Referrer(), ui::PAGE_TRANSITION_LINK, |
| 222 std::string()); | 223 std::string()); |
| 223 } | 224 } |
| 224 | 225 |
| 226 void ExtensionHost::LoadURL(const GURL& url) { |
| 227 initial_url_ = url; |
| 228 LoadInitialURL(); |
| 229 } |
| 230 |
| 225 bool ExtensionHost::IsBackgroundPage() const { | 231 bool ExtensionHost::IsBackgroundPage() const { |
| 226 DCHECK_EQ(extension_host_type_, VIEW_TYPE_EXTENSION_BACKGROUND_PAGE); | 232 DCHECK_EQ(extension_host_type_, VIEW_TYPE_EXTENSION_BACKGROUND_PAGE); |
| 227 return true; | 233 return true; |
| 228 } | 234 } |
| 229 | 235 |
| 230 void ExtensionHost::OnExtensionUnloaded( | 236 void ExtensionHost::OnExtensionUnloaded( |
| 231 content::BrowserContext* browser_context, | 237 content::BrowserContext* browser_context, |
| 232 const Extension* extension, | 238 const Extension* extension, |
| 233 UnloadedExtensionInfo::Reason reason) { | 239 UnloadedExtensionInfo::Reason reason) { |
| 234 // The extension object will be deleted after this notification has been sent. | 240 // The extension object will be deleted after this notification has been sent. |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 470 } | 476 } |
| 471 } else if (extension_host_type_ == VIEW_TYPE_EXTENSION_POPUP) { | 477 } else if (extension_host_type_ == VIEW_TYPE_EXTENSION_POPUP) { |
| 472 UMA_HISTOGRAM_MEDIUM_TIMES("Extensions.PopupLoadTime2", | 478 UMA_HISTOGRAM_MEDIUM_TIMES("Extensions.PopupLoadTime2", |
| 473 load_start_->Elapsed()); | 479 load_start_->Elapsed()); |
| 474 UMA_HISTOGRAM_MEDIUM_TIMES("Extensions.PopupCreateTime", | 480 UMA_HISTOGRAM_MEDIUM_TIMES("Extensions.PopupCreateTime", |
| 475 create_start_.Elapsed()); | 481 create_start_.Elapsed()); |
| 476 } | 482 } |
| 477 } | 483 } |
| 478 | 484 |
| 479 } // namespace extensions | 485 } // namespace extensions |
| OLD | NEW |