| 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/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/memory/singleton.h" | 11 #include "base/memory/singleton.h" |
| 12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
| 14 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
| 15 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
| 16 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
| 17 #include "chrome/browser/chrome_notification_types.h" | 17 #include "chrome/browser/chrome_notification_types.h" |
| 18 #include "chrome/browser/extensions/error_console/error_console.h" | 18 #include "chrome/browser/extensions/error_console/error_console.h" |
| 19 #include "chrome/browser/extensions/extension_service.h" | 19 #include "chrome/browser/extensions/extension_service.h" |
| 20 #include "chrome/browser/extensions/extension_system.h" | |
| 21 #include "chrome/browser/extensions/extension_tab_util.h" | 20 #include "chrome/browser/extensions/extension_tab_util.h" |
| 22 #include "chrome/browser/extensions/extension_web_contents_observer.h" | 21 #include "chrome/browser/extensions/extension_web_contents_observer.h" |
| 23 #include "chrome/browser/media/media_capture_devices_dispatcher.h" | 22 #include "chrome/browser/media/media_capture_devices_dispatcher.h" |
| 24 #include "chrome/common/chrome_constants.h" | 23 #include "chrome/common/chrome_constants.h" |
| 25 #include "chrome/common/extensions/extension_constants.h" | 24 #include "chrome/common/extensions/extension_constants.h" |
| 26 #include "chrome/common/extensions/extension_messages.h" | 25 #include "chrome/common/extensions/extension_messages.h" |
| 27 #include "chrome/common/render_messages.h" | 26 #include "chrome/common/render_messages.h" |
| 28 #include "chrome/common/url_constants.h" | 27 #include "chrome/common/url_constants.h" |
| 29 #include "content/public/browser/browser_context.h" | 28 #include "content/public/browser/browser_context.h" |
| 30 #include "content/public/browser/content_browser_client.h" | 29 #include "content/public/browser/content_browser_client.h" |
| 31 #include "content/public/browser/native_web_keyboard_event.h" | 30 #include "content/public/browser/native_web_keyboard_event.h" |
| 32 #include "content/public/browser/notification_service.h" | 31 #include "content/public/browser/notification_service.h" |
| 33 #include "content/public/browser/notification_source.h" | 32 #include "content/public/browser/notification_source.h" |
| 34 #include "content/public/browser/notification_types.h" | 33 #include "content/public/browser/notification_types.h" |
| 35 #include "content/public/browser/render_process_host.h" | 34 #include "content/public/browser/render_process_host.h" |
| 36 #include "content/public/browser/render_view_host.h" | 35 #include "content/public/browser/render_view_host.h" |
| 37 #include "content/public/browser/render_widget_host_view.h" | 36 #include "content/public/browser/render_widget_host_view.h" |
| 38 #include "content/public/browser/site_instance.h" | 37 #include "content/public/browser/site_instance.h" |
| 39 #include "content/public/browser/web_contents.h" | 38 #include "content/public/browser/web_contents.h" |
| 40 #include "extensions/browser/event_router.h" | 39 #include "extensions/browser/event_router.h" |
| 41 #include "extensions/browser/extension_error.h" | 40 #include "extensions/browser/extension_error.h" |
| 41 #include "extensions/browser/extension_system.h" |
| 42 #include "extensions/browser/extensions_browser_client.h" | 42 #include "extensions/browser/extensions_browser_client.h" |
| 43 #include "extensions/browser/process_manager.h" | 43 #include "extensions/browser/process_manager.h" |
| 44 #include "extensions/browser/runtime_data.h" | 44 #include "extensions/browser/runtime_data.h" |
| 45 #include "extensions/browser/view_type_utils.h" | 45 #include "extensions/browser/view_type_utils.h" |
| 46 #include "extensions/common/extension.h" | 46 #include "extensions/common/extension.h" |
| 47 #include "extensions/common/extension_urls.h" | 47 #include "extensions/common/extension_urls.h" |
| 48 #include "extensions/common/feature_switch.h" | 48 #include "extensions/common/feature_switch.h" |
| 49 #include "extensions/common/manifest_handlers/background_info.h" | 49 #include "extensions/common/manifest_handlers/background_info.h" |
| 50 #include "ui/base/l10n/l10n_util.h" | 50 #include "ui/base/l10n/l10n_util.h" |
| 51 #include "ui/base/window_open_disposition.h" | 51 #include "ui/base/window_open_disposition.h" |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 LoadInitialURL(); | 196 LoadInitialURL(); |
| 197 if (!IsBackgroundPage()) { | 197 if (!IsBackgroundPage()) { |
| 198 DCHECK(IsRenderViewLive()); | 198 DCHECK(IsRenderViewLive()); |
| 199 ExtensionService* service = GetExtensionService(); | 199 ExtensionService* service = GetExtensionService(); |
| 200 if (service) | 200 if (service) |
| 201 service->DidCreateRenderViewForBackgroundPage(this); | 201 service->DidCreateRenderViewForBackgroundPage(this); |
| 202 } | 202 } |
| 203 } | 203 } |
| 204 | 204 |
| 205 ExtensionService* ExtensionHost::GetExtensionService() { | 205 ExtensionService* ExtensionHost::GetExtensionService() { |
| 206 return ExtensionSystem::GetForBrowserContext(browser_context_) | 206 return ExtensionSystem::Get(browser_context_)->extension_service(); |
| 207 ->extension_service(); | |
| 208 } | 207 } |
| 209 | 208 |
| 210 const GURL& ExtensionHost::GetURL() const { | 209 const GURL& ExtensionHost::GetURL() const { |
| 211 return host_contents()->GetURL(); | 210 return host_contents()->GetURL(); |
| 212 } | 211 } |
| 213 | 212 |
| 214 void ExtensionHost::LoadInitialURL() { | 213 void ExtensionHost::LoadInitialURL() { |
| 215 host_contents_->GetController().LoadURL( | 214 host_contents_->GetController().LoadURL( |
| 216 initial_url_, content::Referrer(), content::PAGE_TRANSITION_LINK, | 215 initial_url_, content::Referrer(), content::PAGE_TRANSITION_LINK, |
| 217 std::string()); | 216 std::string()); |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 317 // If the document has already been marked as available for this host, then | 316 // If the document has already been marked as available for this host, then |
| 318 // bail. No need for the redundant setup. http://crbug.com/31170 | 317 // bail. No need for the redundant setup. http://crbug.com/31170 |
| 319 if (document_element_available_) | 318 if (document_element_available_) |
| 320 return; | 319 return; |
| 321 document_element_available_ = true; | 320 document_element_available_ = true; |
| 322 OnDocumentAvailable(); | 321 OnDocumentAvailable(); |
| 323 } | 322 } |
| 324 | 323 |
| 325 void ExtensionHost::OnDocumentAvailable() { | 324 void ExtensionHost::OnDocumentAvailable() { |
| 326 DCHECK(extension_host_type_ == VIEW_TYPE_EXTENSION_BACKGROUND_PAGE); | 325 DCHECK(extension_host_type_ == VIEW_TYPE_EXTENSION_BACKGROUND_PAGE); |
| 327 ExtensionSystem::GetForBrowserContext(browser_context_) | 326 ExtensionSystem::Get(browser_context_) |
| 328 ->runtime_data() | 327 ->runtime_data() |
| 329 ->SetBackgroundPageReady(extension_, true); | 328 ->SetBackgroundPageReady(extension_, true); |
| 330 content::NotificationService::current()->Notify( | 329 content::NotificationService::current()->Notify( |
| 331 chrome::NOTIFICATION_EXTENSION_BACKGROUND_PAGE_READY, | 330 chrome::NOTIFICATION_EXTENSION_BACKGROUND_PAGE_READY, |
| 332 content::Source<const Extension>(extension_), | 331 content::Source<const Extension>(extension_), |
| 333 content::NotificationService::NoDetails()); | 332 content::NotificationService::NoDetails()); |
| 334 } | 333 } |
| 335 | 334 |
| 336 void ExtensionHost::CloseContents(WebContents* contents) { | 335 void ExtensionHost::CloseContents(WebContents* contents) { |
| 337 Close(); | 336 Close(); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 351 IPC_MESSAGE_UNHANDLED(handled = false) | 350 IPC_MESSAGE_UNHANDLED(handled = false) |
| 352 IPC_END_MESSAGE_MAP() | 351 IPC_END_MESSAGE_MAP() |
| 353 return handled; | 352 return handled; |
| 354 } | 353 } |
| 355 | 354 |
| 356 void ExtensionHost::OnRequest(const ExtensionHostMsg_Request_Params& params) { | 355 void ExtensionHost::OnRequest(const ExtensionHostMsg_Request_Params& params) { |
| 357 extension_function_dispatcher_.Dispatch(params, render_view_host()); | 356 extension_function_dispatcher_.Dispatch(params, render_view_host()); |
| 358 } | 357 } |
| 359 | 358 |
| 360 void ExtensionHost::OnEventAck() { | 359 void ExtensionHost::OnEventAck() { |
| 361 EventRouter* router = | 360 EventRouter* router = ExtensionSystem::Get(browser_context_)->event_router(); |
| 362 ExtensionSystem::GetForBrowserContext(browser_context_)->event_router(); | |
| 363 if (router) | 361 if (router) |
| 364 router->OnEventAck(browser_context_, extension_id()); | 362 router->OnEventAck(browser_context_, extension_id()); |
| 365 } | 363 } |
| 366 | 364 |
| 367 void ExtensionHost::OnIncrementLazyKeepaliveCount() { | 365 void ExtensionHost::OnIncrementLazyKeepaliveCount() { |
| 368 ProcessManager* pm = ExtensionSystem::GetForBrowserContext( | 366 ProcessManager* pm = ExtensionSystem::Get( |
| 369 browser_context_)->process_manager(); | 367 browser_context_)->process_manager(); |
| 370 if (pm) | 368 if (pm) |
| 371 pm->IncrementLazyKeepaliveCount(extension()); | 369 pm->IncrementLazyKeepaliveCount(extension()); |
| 372 } | 370 } |
| 373 | 371 |
| 374 void ExtensionHost::OnDecrementLazyKeepaliveCount() { | 372 void ExtensionHost::OnDecrementLazyKeepaliveCount() { |
| 375 ProcessManager* pm = ExtensionSystem::GetForBrowserContext( | 373 ProcessManager* pm = ExtensionSystem::Get( |
| 376 browser_context_)->process_manager(); | 374 browser_context_)->process_manager(); |
| 377 if (pm) | 375 if (pm) |
| 378 pm->DecrementLazyKeepaliveCount(extension()); | 376 pm->DecrementLazyKeepaliveCount(extension()); |
| 379 } | 377 } |
| 380 | 378 |
| 381 void ExtensionHost::OnDetailedConsoleMessageAdded( | 379 void ExtensionHost::OnDetailedConsoleMessageAdded( |
| 382 const base::string16& message, | 380 const base::string16& message, |
| 383 const base::string16& source, | 381 const base::string16& source, |
| 384 const StackTrace& stack_trace, | 382 const StackTrace& stack_trace, |
| 385 int32 severity_level) { | 383 int32 severity_level) { |
| 386 if (!IsSourceFromAnExtension(source)) | 384 if (!IsSourceFromAnExtension(source)) |
| 387 return; | 385 return; |
| 388 | 386 |
| 389 GURL context_url; | 387 GURL context_url; |
| 390 WebContents* associated_contents = GetAssociatedWebContents(); | 388 WebContents* associated_contents = GetAssociatedWebContents(); |
| 391 if (associated_contents) | 389 if (associated_contents) |
| 392 context_url = associated_contents->GetLastCommittedURL(); | 390 context_url = associated_contents->GetLastCommittedURL(); |
| 393 else if (host_contents_.get()) | 391 else if (host_contents_.get()) |
| 394 context_url = host_contents_->GetLastCommittedURL(); | 392 context_url = host_contents_->GetLastCommittedURL(); |
| 395 | 393 |
| 396 ErrorConsole* console = | 394 ErrorConsole* console = |
| 397 ExtensionSystem::GetForBrowserContext(browser_context_)->error_console(); | 395 ExtensionSystem::Get(browser_context_)->error_console(); |
| 398 if (!console) | 396 if (!console) |
| 399 return; | 397 return; |
| 400 | 398 |
| 401 console->ReportError( | 399 console->ReportError( |
| 402 scoped_ptr<ExtensionError>(new RuntimeError( | 400 scoped_ptr<ExtensionError>(new RuntimeError( |
| 403 extension_id_, | 401 extension_id_, |
| 404 browser_context_->IsOffTheRecord(), | 402 browser_context_->IsOffTheRecord(), |
| 405 source, | 403 source, |
| 406 message, | 404 message, |
| 407 stack_trace, | 405 stack_trace, |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 471 | 469 |
| 472 void ExtensionHost::RequestMediaAccessPermission( | 470 void ExtensionHost::RequestMediaAccessPermission( |
| 473 content::WebContents* web_contents, | 471 content::WebContents* web_contents, |
| 474 const content::MediaStreamRequest& request, | 472 const content::MediaStreamRequest& request, |
| 475 const content::MediaResponseCallback& callback) { | 473 const content::MediaResponseCallback& callback) { |
| 476 MediaCaptureDevicesDispatcher::GetInstance()->ProcessMediaAccessRequest( | 474 MediaCaptureDevicesDispatcher::GetInstance()->ProcessMediaAccessRequest( |
| 477 web_contents, request, callback, extension()); | 475 web_contents, request, callback, extension()); |
| 478 } | 476 } |
| 479 | 477 |
| 480 } // namespace extensions | 478 } // namespace extensions |
| OLD | NEW |