| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/keyboard_codes.h" | 9 #include "app/keyboard_codes.h" |
| 10 #include "app/l10n_util.h" | 10 #include "app/l10n_util.h" |
| 11 #include "app/resource_bundle.h" | 11 #include "app/resource_bundle.h" |
| 12 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
| 13 #include "base/singleton.h" | 13 #include "base/singleton.h" |
| 14 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
| 15 #include "base/string_util.h" | 15 #include "base/string_util.h" |
| 16 #include "chrome/browser/browser_list.h" | 16 #include "chrome/browser/browser_list.h" |
| 17 #include "chrome/browser/browser_shutdown.h" | 17 #include "chrome/browser/browser_shutdown.h" |
| 18 #include "chrome/browser/browser_window.h" | 18 #include "chrome/browser/browser_window.h" |
| 19 #include "chrome/browser/browsing_instance.h" | 19 #include "chrome/browser/browsing_instance.h" |
| 20 #include "chrome/browser/debugger/devtools_manager.h" | 20 #include "chrome/browser/debugger/devtools_manager.h" |
| 21 #include "chrome/browser/dom_ui/dom_ui_factory.h" | 21 #include "chrome/browser/dom_ui/dom_ui_factory.h" |
| 22 #include "chrome/browser/extensions/extension_message_service.h" | 22 #include "chrome/browser/extensions/extension_message_service.h" |
| 23 #include "chrome/browser/extensions/extension_tabs_module.h" | 23 #include "chrome/browser/extensions/extension_tabs_module.h" |
| 24 #include "chrome/browser/extensions/extensions_service.h" | 24 #include "chrome/browser/extensions/extension_service.h" |
| 25 #include "chrome/browser/file_select_helper.h" | 25 #include "chrome/browser/file_select_helper.h" |
| 26 #include "chrome/browser/platform_util.h" | 26 #include "chrome/browser/platform_util.h" |
| 27 #include "chrome/browser/prefs/pref_service.h" | 27 #include "chrome/browser/prefs/pref_service.h" |
| 28 #include "chrome/browser/profiles/profile.h" | 28 #include "chrome/browser/profiles/profile.h" |
| 29 #include "chrome/browser/renderer_host/render_process_host.h" | 29 #include "chrome/browser/renderer_host/render_process_host.h" |
| 30 #include "chrome/browser/renderer_host/render_view_host.h" | 30 #include "chrome/browser/renderer_host/render_view_host.h" |
| 31 #include "chrome/browser/renderer_host/render_widget_host.h" | 31 #include "chrome/browser/renderer_host/render_widget_host.h" |
| 32 #include "chrome/browser/renderer_host/render_widget_host_view.h" | 32 #include "chrome/browser/renderer_host/render_widget_host_view.h" |
| 33 #include "chrome/browser/renderer_host/site_instance.h" | 33 #include "chrome/browser/renderer_host/site_instance.h" |
| 34 #include "chrome/browser/renderer_preferences_util.h" | 34 #include "chrome/browser/renderer_preferences_util.h" |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 } else { | 203 } else { |
| 204 ProcessCreationQueue::GetInstance()->CreateSoon(this); | 204 ProcessCreationQueue::GetInstance()->CreateSoon(this); |
| 205 } | 205 } |
| 206 } | 206 } |
| 207 | 207 |
| 208 void ExtensionHost::CreateRenderViewNow() { | 208 void ExtensionHost::CreateRenderViewNow() { |
| 209 render_view_host_->CreateRenderView(string16()); | 209 render_view_host_->CreateRenderView(string16()); |
| 210 NavigateToURL(url_); | 210 NavigateToURL(url_); |
| 211 DCHECK(IsRenderViewLive()); | 211 DCHECK(IsRenderViewLive()); |
| 212 if (is_background_page()) | 212 if (is_background_page()) |
| 213 profile_->GetExtensionsService()->DidCreateRenderViewForBackgroundPage( | 213 profile_->GetExtensionService()->DidCreateRenderViewForBackgroundPage( |
| 214 this); | 214 this); |
| 215 } | 215 } |
| 216 | 216 |
| 217 Browser* ExtensionHost::GetBrowser() const { | 217 Browser* ExtensionHost::GetBrowser() const { |
| 218 return view() ? view()->browser() : NULL; | 218 return view() ? view()->browser() : NULL; |
| 219 } | 219 } |
| 220 | 220 |
| 221 gfx::NativeView ExtensionHost::GetNativeViewOfHost() { | 221 gfx::NativeView ExtensionHost::GetNativeViewOfHost() { |
| 222 return view() ? view()->native_view() : NULL; | 222 return view() ? view()->native_view() : NULL; |
| 223 } | 223 } |
| 224 | 224 |
| 225 void ExtensionHost::NavigateToURL(const GURL& url) { | 225 void ExtensionHost::NavigateToURL(const GURL& url) { |
| 226 // Prevent explicit navigation to another extension id's pages. | 226 // Prevent explicit navigation to another extension id's pages. |
| 227 // This method is only called by some APIs, so we still need to protect | 227 // This method is only called by some APIs, so we still need to protect |
| 228 // DidNavigate below (location = ""). | 228 // DidNavigate below (location = ""). |
| 229 if (url.SchemeIs(chrome::kExtensionScheme) && | 229 if (url.SchemeIs(chrome::kExtensionScheme) && |
| 230 url.host() != extension_->id()) { | 230 url.host() != extension_->id()) { |
| 231 // TODO(erikkay) communicate this back to the caller? | 231 // TODO(erikkay) communicate this back to the caller? |
| 232 return; | 232 return; |
| 233 } | 233 } |
| 234 | 234 |
| 235 url_ = url; | 235 url_ = url; |
| 236 | 236 |
| 237 if (!is_background_page() && | 237 if (!is_background_page() && |
| 238 !profile_->GetExtensionsService()->IsBackgroundPageReady(extension_)) { | 238 !profile_->GetExtensionService()->IsBackgroundPageReady(extension_)) { |
| 239 // Make sure the background page loads before any others. | 239 // Make sure the background page loads before any others. |
| 240 registrar_.Add(this, NotificationType::EXTENSION_BACKGROUND_PAGE_READY, | 240 registrar_.Add(this, NotificationType::EXTENSION_BACKGROUND_PAGE_READY, |
| 241 Source<Extension>(extension_)); | 241 Source<Extension>(extension_)); |
| 242 return; | 242 return; |
| 243 } | 243 } |
| 244 | 244 |
| 245 render_view_host_->NavigateToURL(url_); | 245 render_view_host_->NavigateToURL(url_); |
| 246 } | 246 } |
| 247 | 247 |
| 248 void ExtensionHost::Observe(NotificationType type, | 248 void ExtensionHost::Observe(NotificationType type, |
| 249 const NotificationSource& source, | 249 const NotificationSource& source, |
| 250 const NotificationDetails& details) { | 250 const NotificationDetails& details) { |
| 251 switch (type.value) { | 251 switch (type.value) { |
| 252 case NotificationType::EXTENSION_BACKGROUND_PAGE_READY: | 252 case NotificationType::EXTENSION_BACKGROUND_PAGE_READY: |
| 253 DCHECK(profile_->GetExtensionsService()-> | 253 DCHECK(profile_->GetExtensionService()-> |
| 254 IsBackgroundPageReady(extension_)); | 254 IsBackgroundPageReady(extension_)); |
| 255 NavigateToURL(url_); | 255 NavigateToURL(url_); |
| 256 break; | 256 break; |
| 257 case NotificationType::RENDERER_PROCESS_CREATED: | 257 case NotificationType::RENDERER_PROCESS_CREATED: |
| 258 NotificationService::current()->Notify( | 258 NotificationService::current()->Notify( |
| 259 NotificationType::EXTENSION_PROCESS_CREATED, | 259 NotificationType::EXTENSION_PROCESS_CREATED, |
| 260 Source<Profile>(profile_), | 260 Source<Profile>(profile_), |
| 261 Details<ExtensionHost>(this)); | 261 Details<ExtensionHost>(this)); |
| 262 break; | 262 break; |
| 263 case NotificationType::EXTENSION_UNLOADED: | 263 case NotificationType::EXTENSION_UNLOADED: |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 } | 390 } |
| 391 | 391 |
| 392 void ExtensionHost::DocumentAvailableInMainFrame(RenderViewHost* rvh) { | 392 void ExtensionHost::DocumentAvailableInMainFrame(RenderViewHost* rvh) { |
| 393 // If the document has already been marked as available for this host, then | 393 // If the document has already been marked as available for this host, then |
| 394 // bail. No need for the redundant setup. http://crbug.com/31170 | 394 // bail. No need for the redundant setup. http://crbug.com/31170 |
| 395 if (document_element_available_) | 395 if (document_element_available_) |
| 396 return; | 396 return; |
| 397 | 397 |
| 398 document_element_available_ = true; | 398 document_element_available_ = true; |
| 399 if (is_background_page()) { | 399 if (is_background_page()) { |
| 400 profile_->GetExtensionsService()->SetBackgroundPageReady(extension_); | 400 profile_->GetExtensionService()->SetBackgroundPageReady(extension_); |
| 401 } else { | 401 } else { |
| 402 switch (extension_host_type_) { | 402 switch (extension_host_type_) { |
| 403 case ViewType::EXTENSION_INFOBAR: | 403 case ViewType::EXTENSION_INFOBAR: |
| 404 InsertInfobarCSS(); | 404 InsertInfobarCSS(); |
| 405 break; | 405 break; |
| 406 default: | 406 default: |
| 407 break; // No style sheet for other types, at the moment. | 407 break; // No style sheet for other types, at the moment. |
| 408 } | 408 } |
| 409 } | 409 } |
| 410 } | 410 } |
| (...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 794 // Extensions hosted in ExternalTabContainer objects may not have | 794 // Extensions hosted in ExternalTabContainer objects may not have |
| 795 // an associated browser. | 795 // an associated browser. |
| 796 Browser* browser = GetBrowser(); | 796 Browser* browser = GetBrowser(); |
| 797 if (browser) | 797 if (browser) |
| 798 window_id = ExtensionTabUtil::GetWindowId(browser); | 798 window_id = ExtensionTabUtil::GetWindowId(browser); |
| 799 } else if (extension_host_type_ != ViewType::EXTENSION_BACKGROUND_PAGE) { | 799 } else if (extension_host_type_ != ViewType::EXTENSION_BACKGROUND_PAGE) { |
| 800 NOTREACHED(); | 800 NOTREACHED(); |
| 801 } | 801 } |
| 802 return window_id; | 802 return window_id; |
| 803 } | 803 } |
| OLD | NEW |