| 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" |
| 11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
| 12 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
| 13 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
| 14 #include "base/string_util.h" | 14 #include "base/string_util.h" |
| 15 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
| 16 #include "chrome/browser/browser_shutdown.h" | 16 #include "chrome/browser/browser_shutdown.h" |
| 17 #include "chrome/browser/extensions/extension_event_router.h" |
| 17 #include "chrome/browser/extensions/extension_process_manager.h" | 18 #include "chrome/browser/extensions/extension_process_manager.h" |
| 18 #include "chrome/browser/extensions/extension_service.h" | 19 #include "chrome/browser/extensions/extension_service.h" |
| 19 #include "chrome/browser/extensions/extension_system.h" | 20 #include "chrome/browser/extensions/extension_system.h" |
| 20 #include "chrome/browser/extensions/extension_tab_util.h" | 21 #include "chrome/browser/extensions/extension_tab_util.h" |
| 21 #include "chrome/browser/profiles/profile.h" | 22 #include "chrome/browser/profiles/profile.h" |
| 22 #include "chrome/browser/ui/app_modal_dialogs/message_box_handler.h" | 23 #include "chrome/browser/ui/app_modal_dialogs/message_box_handler.h" |
| 23 #include "chrome/browser/ui/browser.h" | 24 #include "chrome/browser/ui/browser.h" |
| 24 #include "chrome/browser/ui/browser_list.h" | 25 #include "chrome/browser/ui/browser_list.h" |
| 25 #include "chrome/browser/ui/browser_window.h" | 26 #include "chrome/browser/ui/browser_window.h" |
| 26 #include "chrome/browser/ui/prefs/prefs_tab_helper.h" | 27 #include "chrome/browser/ui/prefs/prefs_tab_helper.h" |
| (...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 463 return; | 464 return; |
| 464 } | 465 } |
| 465 } | 466 } |
| 466 UnhandledKeyboardEvent(event); | 467 UnhandledKeyboardEvent(event); |
| 467 } | 468 } |
| 468 | 469 |
| 469 bool ExtensionHost::OnMessageReceived(const IPC::Message& message) { | 470 bool ExtensionHost::OnMessageReceived(const IPC::Message& message) { |
| 470 bool handled = true; | 471 bool handled = true; |
| 471 IPC_BEGIN_MESSAGE_MAP(ExtensionHost, message) | 472 IPC_BEGIN_MESSAGE_MAP(ExtensionHost, message) |
| 472 IPC_MESSAGE_HANDLER(ExtensionHostMsg_Request, OnRequest) | 473 IPC_MESSAGE_HANDLER(ExtensionHostMsg_Request, OnRequest) |
| 474 IPC_MESSAGE_HANDLER(ExtensionHostMsg_EventAck, OnEventAck) |
| 475 IPC_MESSAGE_HANDLER(ExtensionHostMsg_IncrementLazyKeepaliveCount, |
| 476 OnIncrementLazyKeepaliveCount) |
| 477 IPC_MESSAGE_HANDLER(ExtensionHostMsg_DecrementLazyKeepaliveCount, |
| 478 OnDecrementLazyKeepaliveCount) |
| 473 IPC_MESSAGE_UNHANDLED(handled = false) | 479 IPC_MESSAGE_UNHANDLED(handled = false) |
| 474 IPC_END_MESSAGE_MAP() | 480 IPC_END_MESSAGE_MAP() |
| 475 return handled; | 481 return handled; |
| 476 } | 482 } |
| 477 | 483 |
| 478 void ExtensionHost::OnRequest(const ExtensionHostMsg_Request_Params& params) { | 484 void ExtensionHost::OnRequest(const ExtensionHostMsg_Request_Params& params) { |
| 479 extension_function_dispatcher_.Dispatch(params, render_view_host()); | 485 extension_function_dispatcher_.Dispatch(params, render_view_host()); |
| 480 } | 486 } |
| 481 | 487 |
| 488 void ExtensionHost::OnEventAck() { |
| 489 ExtensionEventRouter* router = ExtensionSystem::Get(profile_)->event_router(); |
| 490 if (router) |
| 491 router->OnEventAck(profile_, extension_id()); |
| 492 } |
| 493 |
| 494 void ExtensionHost::OnIncrementLazyKeepaliveCount() { |
| 495 ExtensionProcessManager* pm = |
| 496 ExtensionSystem::Get(profile_)->process_manager(); |
| 497 if (pm) |
| 498 pm->IncrementLazyKeepaliveCount(extension()); |
| 499 } |
| 500 |
| 501 void ExtensionHost::OnDecrementLazyKeepaliveCount() { |
| 502 ExtensionProcessManager* pm = |
| 503 ExtensionSystem::Get(profile_)->process_manager(); |
| 504 if (pm) |
| 505 pm->DecrementLazyKeepaliveCount(extension()); |
| 506 } |
| 507 |
| 508 |
| 482 void ExtensionHost::RenderViewCreated(RenderViewHost* render_view_host) { | 509 void ExtensionHost::RenderViewCreated(RenderViewHost* render_view_host) { |
| 483 render_view_host_ = render_view_host; | 510 render_view_host_ = render_view_host; |
| 484 | 511 |
| 485 if (view_.get()) | 512 if (view_.get()) |
| 486 view_->RenderViewCreated(); | 513 view_->RenderViewCreated(); |
| 487 | 514 |
| 488 // If the host is bound to a browser, then extract its window id. | 515 // If the host is bound to a browser, then extract its window id. |
| 489 // Extensions hosted in ExternalTabContainer objects may not have | 516 // Extensions hosted in ExternalTabContainer objects may not have |
| 490 // an associated browser. | 517 // an associated browser. |
| 491 const Browser* browser = GetBrowser(); | 518 const Browser* browser = GetBrowser(); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 565 params.user_gesture = user_gesture; | 592 params.user_gesture = user_gesture; |
| 566 browser::Navigate(¶ms); | 593 browser::Navigate(¶ms); |
| 567 } | 594 } |
| 568 | 595 |
| 569 void ExtensionHost::RenderViewReady() { | 596 void ExtensionHost::RenderViewReady() { |
| 570 content::NotificationService::current()->Notify( | 597 content::NotificationService::current()->Notify( |
| 571 chrome::NOTIFICATION_EXTENSION_HOST_CREATED, | 598 chrome::NOTIFICATION_EXTENSION_HOST_CREATED, |
| 572 content::Source<Profile>(profile_), | 599 content::Source<Profile>(profile_), |
| 573 content::Details<ExtensionHost>(this)); | 600 content::Details<ExtensionHost>(this)); |
| 574 } | 601 } |
| OLD | NEW |