| 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 <list> | 7 #include <list> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 #include "content/public/browser/notification_source.h" | 22 #include "content/public/browser/notification_source.h" |
| 23 #include "content/public/browser/notification_types.h" | 23 #include "content/public/browser/notification_types.h" |
| 24 #include "content/public/browser/render_process_host.h" | 24 #include "content/public/browser/render_process_host.h" |
| 25 #include "content/public/browser/render_view_host.h" | 25 #include "content/public/browser/render_view_host.h" |
| 26 #include "content/public/browser/render_widget_host_view.h" | 26 #include "content/public/browser/render_widget_host_view.h" |
| 27 #include "content/public/browser/site_instance.h" | 27 #include "content/public/browser/site_instance.h" |
| 28 #include "content/public/browser/web_contents.h" | 28 #include "content/public/browser/web_contents.h" |
| 29 #include "extensions/browser/event_router.h" | 29 #include "extensions/browser/event_router.h" |
| 30 #include "extensions/browser/extension_error.h" | 30 #include "extensions/browser/extension_error.h" |
| 31 #include "extensions/browser/extension_host_delegate.h" | 31 #include "extensions/browser/extension_host_delegate.h" |
| 32 #include "extensions/browser/extension_host_observer.h" |
| 32 #include "extensions/browser/extension_system.h" | 33 #include "extensions/browser/extension_system.h" |
| 33 #include "extensions/browser/extensions_browser_client.h" | 34 #include "extensions/browser/extensions_browser_client.h" |
| 34 #include "extensions/browser/notification_types.h" | 35 #include "extensions/browser/notification_types.h" |
| 35 #include "extensions/browser/process_manager.h" | 36 #include "extensions/browser/process_manager.h" |
| 36 #include "extensions/browser/runtime_data.h" | 37 #include "extensions/browser/runtime_data.h" |
| 37 #include "extensions/browser/view_type_utils.h" | 38 #include "extensions/browser/view_type_utils.h" |
| 38 #include "extensions/common/extension.h" | 39 #include "extensions/common/extension.h" |
| 39 #include "extensions/common/extension_messages.h" | 40 #include "extensions/common/extension_messages.h" |
| 40 #include "extensions/common/extension_urls.h" | 41 #include "extensions/common/extension_urls.h" |
| 41 #include "extensions/common/feature_switch.h" | 42 #include "extensions/common/feature_switch.h" |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 ExtensionHost::~ExtensionHost() { | 153 ExtensionHost::~ExtensionHost() { |
| 153 if (extension_host_type_ == VIEW_TYPE_EXTENSION_BACKGROUND_PAGE && | 154 if (extension_host_type_ == VIEW_TYPE_EXTENSION_BACKGROUND_PAGE && |
| 154 extension_ && BackgroundInfo::HasLazyBackgroundPage(extension_)) { | 155 extension_ && BackgroundInfo::HasLazyBackgroundPage(extension_)) { |
| 155 UMA_HISTOGRAM_LONG_TIMES("Extensions.EventPageActiveTime", | 156 UMA_HISTOGRAM_LONG_TIMES("Extensions.EventPageActiveTime", |
| 156 since_created_.Elapsed()); | 157 since_created_.Elapsed()); |
| 157 } | 158 } |
| 158 content::NotificationService::current()->Notify( | 159 content::NotificationService::current()->Notify( |
| 159 extensions::NOTIFICATION_EXTENSION_HOST_DESTROYED, | 160 extensions::NOTIFICATION_EXTENSION_HOST_DESTROYED, |
| 160 content::Source<BrowserContext>(browser_context_), | 161 content::Source<BrowserContext>(browser_context_), |
| 161 content::Details<ExtensionHost>(this)); | 162 content::Details<ExtensionHost>(this)); |
| 163 FOR_EACH_OBSERVER(ExtensionHostObserver, observer_list_, |
| 164 OnExtensionHostDestroyed(this)); |
| 162 ProcessCreationQueue::GetInstance()->Remove(this); | 165 ProcessCreationQueue::GetInstance()->Remove(this); |
| 163 } | 166 } |
| 164 | 167 |
| 165 content::RenderProcessHost* ExtensionHost::render_process_host() const { | 168 content::RenderProcessHost* ExtensionHost::render_process_host() const { |
| 166 return render_view_host()->GetProcess(); | 169 return render_view_host()->GetProcess(); |
| 167 } | 170 } |
| 168 | 171 |
| 169 RenderViewHost* ExtensionHost::render_view_host() const { | 172 RenderViewHost* ExtensionHost::render_view_host() const { |
| 170 // TODO(mpcomplete): This can be NULL. How do we handle that? | 173 // TODO(mpcomplete): This can be NULL. How do we handle that? |
| 171 return render_view_host_; | 174 return render_view_host_; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 198 extension_)) || | 201 extension_)) || |
| 199 group_name == "ThrottleAll") { | 202 group_name == "ThrottleAll") { |
| 200 host_contents_->WasHidden(); | 203 host_contents_->WasHidden(); |
| 201 } | 204 } |
| 202 } | 205 } |
| 203 // Connect orphaned dev-tools instances. | 206 // Connect orphaned dev-tools instances. |
| 204 delegate_->OnRenderViewCreatedForBackgroundPage(this); | 207 delegate_->OnRenderViewCreatedForBackgroundPage(this); |
| 205 } | 208 } |
| 206 } | 209 } |
| 207 | 210 |
| 211 void ExtensionHost::AddObserver(ExtensionHostObserver* observer) { |
| 212 observer_list_.AddObserver(observer); |
| 213 } |
| 214 |
| 215 void ExtensionHost::RemoveObserver(ExtensionHostObserver* observer) { |
| 216 observer_list_.RemoveObserver(observer); |
| 217 } |
| 218 |
| 219 void ExtensionHost::OnMessageDispatched(const std::string& event_name, |
| 220 int message_id) { |
| 221 FOR_EACH_OBSERVER(ExtensionHostObserver, observer_list_, |
| 222 OnExtensionMessageDispatched(this, event_name, message_id)); |
| 223 } |
| 224 |
| 225 void ExtensionHost::OnNetworkRequestStarted(uint64 request_id) { |
| 226 FOR_EACH_OBSERVER(ExtensionHostObserver, observer_list_, |
| 227 OnNetworkRequestStarted(this, request_id)); |
| 228 } |
| 229 |
| 230 void ExtensionHost::OnNetworkRequestDone(uint64 request_id) { |
| 231 FOR_EACH_OBSERVER(ExtensionHostObserver, observer_list_, |
| 232 OnNetworkRequestDone(this, request_id)); |
| 233 } |
| 234 |
| 208 const GURL& ExtensionHost::GetURL() const { | 235 const GURL& ExtensionHost::GetURL() const { |
| 209 return host_contents()->GetURL(); | 236 return host_contents()->GetURL(); |
| 210 } | 237 } |
| 211 | 238 |
| 212 void ExtensionHost::LoadInitialURL() { | 239 void ExtensionHost::LoadInitialURL() { |
| 213 host_contents_->GetController().LoadURL( | 240 host_contents_->GetController().LoadURL( |
| 214 initial_url_, content::Referrer(), ui::PAGE_TRANSITION_LINK, | 241 initial_url_, content::Referrer(), ui::PAGE_TRANSITION_LINK, |
| 215 std::string()); | 242 std::string()); |
| 216 } | 243 } |
| 217 | 244 |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 OnDecrementLazyKeepaliveCount) | 373 OnDecrementLazyKeepaliveCount) |
| 347 IPC_MESSAGE_UNHANDLED(handled = false) | 374 IPC_MESSAGE_UNHANDLED(handled = false) |
| 348 IPC_END_MESSAGE_MAP() | 375 IPC_END_MESSAGE_MAP() |
| 349 return handled; | 376 return handled; |
| 350 } | 377 } |
| 351 | 378 |
| 352 void ExtensionHost::OnRequest(const ExtensionHostMsg_Request_Params& params) { | 379 void ExtensionHost::OnRequest(const ExtensionHostMsg_Request_Params& params) { |
| 353 extension_function_dispatcher_.Dispatch(params, render_view_host()); | 380 extension_function_dispatcher_.Dispatch(params, render_view_host()); |
| 354 } | 381 } |
| 355 | 382 |
| 356 void ExtensionHost::OnEventAck() { | 383 void ExtensionHost::OnEventAck(int message_id) { |
| 357 EventRouter* router = EventRouter::Get(browser_context_); | 384 EventRouter* router = EventRouter::Get(browser_context_); |
| 358 if (router) | 385 if (router) |
| 359 router->OnEventAck(browser_context_, extension_id()); | 386 router->OnEventAck(browser_context_, extension_id()); |
| 387 |
| 388 FOR_EACH_OBSERVER(ExtensionHostObserver, observer_list_, |
| 389 OnExtensionMessageAcked(this, message_id)); |
| 360 } | 390 } |
| 361 | 391 |
| 362 void ExtensionHost::OnIncrementLazyKeepaliveCount() { | 392 void ExtensionHost::OnIncrementLazyKeepaliveCount() { |
| 363 ProcessManager::Get(browser_context_) | 393 ProcessManager::Get(browser_context_) |
| 364 ->IncrementLazyKeepaliveCount(extension()); | 394 ->IncrementLazyKeepaliveCount(extension()); |
| 365 } | 395 } |
| 366 | 396 |
| 367 void ExtensionHost::OnDecrementLazyKeepaliveCount() { | 397 void ExtensionHost::OnDecrementLazyKeepaliveCount() { |
| 368 ProcessManager::Get(browser_context_) | 398 ProcessManager::Get(browser_context_) |
| 369 ->DecrementLazyKeepaliveCount(extension()); | 399 ->DecrementLazyKeepaliveCount(extension()); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 443 return delegate_->CheckMediaAccessPermission( | 473 return delegate_->CheckMediaAccessPermission( |
| 444 web_contents, security_origin, type, extension()); | 474 web_contents, security_origin, type, extension()); |
| 445 } | 475 } |
| 446 | 476 |
| 447 bool ExtensionHost::IsNeverVisible(content::WebContents* web_contents) { | 477 bool ExtensionHost::IsNeverVisible(content::WebContents* web_contents) { |
| 448 ViewType view_type = extensions::GetViewType(web_contents); | 478 ViewType view_type = extensions::GetViewType(web_contents); |
| 449 return view_type == extensions::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE; | 479 return view_type == extensions::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE; |
| 450 } | 480 } |
| 451 | 481 |
| 452 } // namespace extensions | 482 } // namespace extensions |
| OLD | NEW |