| 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 "app/resource_bundle.h" | 7 #include "app/resource_bundle.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "chrome/browser/browser.h" | 9 #include "chrome/browser/browser.h" |
| 10 #include "chrome/browser/browser_list.h" | 10 #include "chrome/browser/browser_list.h" |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 view->SetDidInsertCSS(true); | 167 view->SetDidInsertCSS(true); |
| 168 } | 168 } |
| 169 } | 169 } |
| 170 #elif defined(OS_LINUX) | 170 #elif defined(OS_LINUX) |
| 171 ExtensionViewGtk* view = view_.get(); | 171 ExtensionViewGtk* view = view_.get(); |
| 172 if (view && view->is_toolstrip()) { | 172 if (view && view->is_toolstrip()) { |
| 173 render_view_host->InsertCSSInWebFrame(L"", toolstrip_css.as_string()); | 173 render_view_host->InsertCSSInWebFrame(L"", toolstrip_css.as_string()); |
| 174 } | 174 } |
| 175 #endif | 175 #endif |
| 176 | 176 |
| 177 did_stop_loading_ = true; | 177 if (!did_stop_loading_) { |
| 178 NotificationService::current()->Notify( |
| 179 NotificationType::EXTENSION_HOST_DID_STOP_LOADING, |
| 180 Source<Profile>(profile_), |
| 181 Details<ExtensionHost>(this)); |
| 182 did_stop_loading_ = true; |
| 183 } |
| 178 } | 184 } |
| 179 | 185 |
| 180 void ExtensionHost::DocumentAvailableInMainFrame(RenderViewHost* rvh) { | 186 void ExtensionHost::DocumentAvailableInMainFrame(RenderViewHost* rvh) { |
| 181 document_element_available_ = true; | 187 document_element_available_ = true; |
| 182 if (is_background_page()) | 188 if (is_background_page()) |
| 183 extension_->SetBackgroundPageReady(); | 189 extension_->SetBackgroundPageReady(); |
| 184 } | 190 } |
| 185 | 191 |
| 186 void ExtensionHost::RunJavaScriptMessage(const std::wstring& message, | 192 void ExtensionHost::RunJavaScriptMessage(const std::wstring& message, |
| 187 const std::wstring& default_prompt, | 193 const std::wstring& default_prompt, |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 if (view_.get()) | 302 if (view_.get()) |
| 297 view_->HandleMouseLeave(); | 303 view_->HandleMouseLeave(); |
| 298 #endif | 304 #endif |
| 299 } | 305 } |
| 300 | 306 |
| 301 Browser* ExtensionHost::GetBrowser() { | 307 Browser* ExtensionHost::GetBrowser() { |
| 302 #if defined(OS_WIN) || defined(OS_LINUX) | 308 #if defined(OS_WIN) || defined(OS_LINUX) |
| 303 if (view_.get()) | 309 if (view_.get()) |
| 304 return view_->browser(); | 310 return view_->browser(); |
| 305 #endif | 311 #endif |
| 306 Browser* browser = BrowserList::GetLastActiveWithProfile( | 312 Profile* profile = render_view_host()->process()->profile(); |
| 307 render_view_host()->process()->profile()); | 313 Browser* browser = BrowserList::GetLastActiveWithProfile(profile); |
| 314 |
| 315 // It's possible for a browser to exist, but to have never been active. |
| 316 // This can happen if you launch the browser on a machine without an active |
| 317 // desktop (a headless buildbot) or if you quickly give another app focus |
| 318 // at launch time. This is easy to do with browser_tests. |
| 319 if (!browser) |
| 320 browser = BrowserList::FindBrowserWithProfile(profile); |
| 321 |
| 322 // TODO(erikkay): can this still return NULL? Is Rafael's comment still |
| 323 // valid here? |
| 308 // NOTE(rafaelw): This can return NULL in some circumstances. In particular, | 324 // NOTE(rafaelw): This can return NULL in some circumstances. In particular, |
| 309 // a toolstrip or background_page onload chrome.tabs api call can make it | 325 // a toolstrip or background_page onload chrome.tabs api call can make it |
| 310 // into here before the browser is sufficiently initialized to return here. | 326 // into here before the browser is sufficiently initialized to return here. |
| 311 // A similar situation may arise during shutdown. | 327 // A similar situation may arise during shutdown. |
| 312 // TODO(rafaelw): Delay creation of background_page until the browser | 328 // TODO(rafaelw): Delay creation of background_page until the browser |
| 313 // is available. http://code.google.com/p/chromium/issues/detail?id=13284 | 329 // is available. http://code.google.com/p/chromium/issues/detail?id=13284 |
| 314 return browser; | 330 return browser; |
| 315 } | 331 } |
| 316 | 332 |
| 317 ViewType::Type ExtensionHost::GetRenderViewType() const { | 333 ViewType::Type ExtensionHost::GetRenderViewType() const { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 333 window_id = ExtensionTabUtil::GetWindowId( | 349 window_id = ExtensionTabUtil::GetWindowId( |
| 334 const_cast<ExtensionHost* >(this)->GetBrowser()); | 350 const_cast<ExtensionHost* >(this)->GetBrowser()); |
| 335 } else if (extension_host_type_ == ViewType::EXTENSION_BACKGROUND_PAGE) { | 351 } else if (extension_host_type_ == ViewType::EXTENSION_BACKGROUND_PAGE) { |
| 336 // Background page is not attached to any browser window, so pass -1. | 352 // Background page is not attached to any browser window, so pass -1. |
| 337 window_id = -1; | 353 window_id = -1; |
| 338 } else { | 354 } else { |
| 339 NOTREACHED(); | 355 NOTREACHED(); |
| 340 } | 356 } |
| 341 return window_id; | 357 return window_id; |
| 342 } | 358 } |
| OLD | NEW |