OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/memory/singleton.h" | 9 #include "base/memory/singleton.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 // synchronously. The process creation is the real meaty part that we want | 203 // synchronously. The process creation is the real meaty part that we want |
204 // to defer. | 204 // to defer. |
205 CreateRenderViewNow(); | 205 CreateRenderViewNow(); |
206 } else { | 206 } else { |
207 ProcessCreationQueue::GetInstance()->CreateSoon(this); | 207 ProcessCreationQueue::GetInstance()->CreateSoon(this); |
208 } | 208 } |
209 } | 209 } |
210 | 210 |
211 void ExtensionHost::CreateRenderViewNow() { | 211 void ExtensionHost::CreateRenderViewNow() { |
212 render_view_host_->CreateRenderView(string16()); | 212 render_view_host_->CreateRenderView(string16()); |
| 213 if (extension_host_type_ == ViewType::EXTENSION_POPUP || |
| 214 extension_host_type_ == ViewType::EXTENSION_DIALOG || |
| 215 extension_host_type_ == ViewType::EXTENSION_INFOBAR) { |
| 216 // If the host is bound to a browser, then extract its window id. |
| 217 // Extensions hosted in ExternalTabContainer objects may not have |
| 218 // an associated browser. |
| 219 const Browser* browser = GetBrowser(); |
| 220 if (browser && render_view_host_) { |
| 221 render_view_host_->Send(new ExtensionMsg_UpdateBrowserWindowId( |
| 222 render_view_host_->routing_id(), |
| 223 ExtensionTabUtil::GetWindowId(browser))); |
| 224 } |
| 225 } |
213 NavigateToURL(url_); | 226 NavigateToURL(url_); |
214 DCHECK(IsRenderViewLive()); | 227 DCHECK(IsRenderViewLive()); |
215 if (is_background_page()) | 228 if (is_background_page()) |
216 profile_->GetExtensionService()->DidCreateRenderViewForBackgroundPage( | 229 profile_->GetExtensionService()->DidCreateRenderViewForBackgroundPage( |
217 this); | 230 this); |
218 } | 231 } |
219 | 232 |
220 const Browser* ExtensionHost::GetBrowser() const { | 233 const Browser* ExtensionHost::GetBrowser() const { |
221 return view() ? view()->browser() : NULL; | 234 return view() ? view()->browser() : NULL; |
222 } | 235 } |
(...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
782 view_->RenderViewCreated(); | 795 view_->RenderViewCreated(); |
783 | 796 |
784 if (extension_host_type_ == ViewType::EXTENSION_POPUP || | 797 if (extension_host_type_ == ViewType::EXTENSION_POPUP || |
785 extension_host_type_ == ViewType::EXTENSION_INFOBAR) { | 798 extension_host_type_ == ViewType::EXTENSION_INFOBAR) { |
786 render_view_host->Send(new ViewMsg_EnablePreferredSizeChangedMode( | 799 render_view_host->Send(new ViewMsg_EnablePreferredSizeChangedMode( |
787 render_view_host->routing_id(), | 800 render_view_host->routing_id(), |
788 kPreferredSizeWidth | kPreferredSizeHeightThisIsSlow)); | 801 kPreferredSizeWidth | kPreferredSizeHeightThisIsSlow)); |
789 } | 802 } |
790 } | 803 } |
791 | 804 |
792 int ExtensionHost::GetBrowserWindowID() const { | |
793 // Hosts not attached to any browser window have an id of -1. This includes | |
794 // those mentioned below, and background pages. | |
795 int window_id = extension_misc::kUnknownWindowId; | |
796 if (extension_host_type_ == ViewType::EXTENSION_POPUP || | |
797 extension_host_type_ == ViewType::EXTENSION_DIALOG || | |
798 extension_host_type_ == ViewType::EXTENSION_INFOBAR) { | |
799 // If the host is bound to a browser, then extract its window id. | |
800 // Extensions hosted in ExternalTabContainer objects may not have | |
801 // an associated browser. | |
802 const Browser* browser = GetBrowser(); | |
803 if (browser) | |
804 window_id = ExtensionTabUtil::GetWindowId(browser); | |
805 } else if (extension_host_type_ != ViewType::EXTENSION_BACKGROUND_PAGE) { | |
806 NOTREACHED(); | |
807 } | |
808 return window_id; | |
809 } | |
810 | |
811 void ExtensionHost::OnRunFileChooser( | 805 void ExtensionHost::OnRunFileChooser( |
812 const ViewHostMsg_RunFileChooser_Params& params) { | 806 const ViewHostMsg_RunFileChooser_Params& params) { |
813 if (file_select_helper_.get() == NULL) | 807 if (file_select_helper_.get() == NULL) |
814 file_select_helper_.reset(new FileSelectHelper(profile())); | 808 file_select_helper_.reset(new FileSelectHelper(profile())); |
815 file_select_helper_->RunFileChooser(render_view_host_, | 809 file_select_helper_->RunFileChooser(render_view_host_, |
816 GetAssociatedTabContents(), params); | 810 GetAssociatedTabContents(), params); |
817 } | 811 } |
OLD | NEW |