OLD | NEW |
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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 "app/l10n_util.h" | 9 #include "app/l10n_util.h" |
10 #include "app/resource_bundle.h" | 10 #include "app/resource_bundle.h" |
(...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
532 #endif | 532 #endif |
533 } | 533 } |
534 | 534 |
535 void ExtensionHost::HandleMouseLeave() { | 535 void ExtensionHost::HandleMouseLeave() { |
536 #if defined(OS_WIN) | 536 #if defined(OS_WIN) |
537 if (view_.get()) | 537 if (view_.get()) |
538 view_->HandleMouseLeave(); | 538 view_->HandleMouseLeave(); |
539 #endif | 539 #endif |
540 } | 540 } |
541 | 541 |
542 Browser* ExtensionHost::GetBrowser() { | 542 Browser* ExtensionHost::GetBrowser() const { |
543 if (view_.get()) | 543 if (view_.get()) |
544 return view_->browser(); | 544 return view_->browser(); |
545 | 545 |
546 Profile* profile = render_view_host()->process()->profile(); | 546 Profile* profile = render_view_host()->process()->profile(); |
547 Browser* browser = BrowserList::GetLastActiveWithProfile(profile); | 547 Browser* browser = BrowserList::GetLastActiveWithProfile(profile); |
548 | 548 |
549 // It's possible for a browser to exist, but to have never been active. | 549 // It's possible for a browser to exist, but to have never been active. |
550 // This can happen if you launch the browser on a machine without an active | 550 // This can happen if you launch the browser on a machine without an active |
551 // desktop (a headless buildbot) or if you quickly give another app focus | 551 // desktop (a headless buildbot) or if you quickly give another app focus |
552 // at launch time. This is easy to do with browser_tests. | 552 // at launch time. This is easy to do with browser_tests. |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
587 LOG(INFO) << "(RenderViewCreated) Resetting EFD to " << url_.spec() << " for " | 587 LOG(INFO) << "(RenderViewCreated) Resetting EFD to " << url_.spec() << " for " |
588 << extension_->name(); | 588 << extension_->name(); |
589 extension_function_dispatcher_.reset( | 589 extension_function_dispatcher_.reset( |
590 new ExtensionFunctionDispatcher(render_view_host, this, url_)); | 590 new ExtensionFunctionDispatcher(render_view_host, this, url_)); |
591 | 591 |
592 render_view_host->Send(new ViewMsg_EnablePreferredSizeChangedMode( | 592 render_view_host->Send(new ViewMsg_EnablePreferredSizeChangedMode( |
593 render_view_host->routing_id())); | 593 render_view_host->routing_id())); |
594 } | 594 } |
595 | 595 |
596 int ExtensionHost::GetBrowserWindowID() const { | 596 int ExtensionHost::GetBrowserWindowID() const { |
| 597 // Hosts not attached to any browser window have an id of -1. This includes |
| 598 // those mentioned below, and background pages. |
597 int window_id = -1; | 599 int window_id = -1; |
598 if (extension_host_type_ == ViewType::EXTENSION_TOOLSTRIP || | 600 if (extension_host_type_ == ViewType::EXTENSION_TOOLSTRIP || |
599 extension_host_type_ == ViewType::EXTENSION_MOLE || | 601 extension_host_type_ == ViewType::EXTENSION_MOLE || |
600 extension_host_type_ == ViewType::EXTENSION_POPUP) { | 602 extension_host_type_ == ViewType::EXTENSION_POPUP) { |
601 window_id = ExtensionTabUtil::GetWindowId( | 603 // If the host is bound to a browser, then extract its window id. |
602 const_cast<ExtensionHost* >(this)->GetBrowser()); | 604 // Extensions hosted in ExternalTabContainer objects may not have |
603 } else if (extension_host_type_ == ViewType::EXTENSION_BACKGROUND_PAGE) { | 605 // an associated browser. |
604 // Background page is not attached to any browser window, so pass -1. | 606 Browser* browser = GetBrowser(); |
605 window_id = -1; | 607 if (browser) |
606 } else { | 608 window_id = ExtensionTabUtil::GetWindowId(browser); |
| 609 } else if (extension_host_type_ != ViewType::EXTENSION_BACKGROUND_PAGE) { |
607 NOTREACHED(); | 610 NOTREACHED(); |
608 } | 611 } |
609 return window_id; | 612 return window_id; |
610 } | 613 } |
OLD | NEW |