| 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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 }; | 117 }; |
| 118 | 118 |
| 119 //////////////// | 119 //////////////// |
| 120 // ExtensionHost | 120 // ExtensionHost |
| 121 | 121 |
| 122 ExtensionHost::ExtensionHost(const Extension* extension, | 122 ExtensionHost::ExtensionHost(const Extension* extension, |
| 123 SiteInstance* site_instance, | 123 SiteInstance* site_instance, |
| 124 const GURL& url, | 124 const GURL& url, |
| 125 ViewType::Type host_type) | 125 ViewType::Type host_type) |
| 126 : extension_(extension), | 126 : extension_(extension), |
| 127 extension_id_(extension->id()), |
| 127 profile_(site_instance->browsing_instance()->profile()), | 128 profile_(site_instance->browsing_instance()->profile()), |
| 128 did_stop_loading_(false), | 129 did_stop_loading_(false), |
| 129 document_element_available_(false), | 130 document_element_available_(false), |
| 130 url_(url), | 131 url_(url), |
| 131 extension_host_type_(host_type), | 132 extension_host_type_(host_type), |
| 132 associated_tab_contents_(NULL), | 133 associated_tab_contents_(NULL), |
| 133 suppress_javascript_messages_(false) { | 134 suppress_javascript_messages_(false) { |
| 134 render_view_host_ = new RenderViewHost(site_instance, this, MSG_ROUTING_NONE, | 135 render_view_host_ = new RenderViewHost(site_instance, this, MSG_ROUTING_NONE, |
| 135 NULL); | 136 NULL); |
| 136 render_view_host_->set_is_extension_process(true); | 137 render_view_host_->set_is_extension_process(true); |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 } | 227 } |
| 227 | 228 |
| 228 gfx::NativeView ExtensionHost::GetNativeViewOfHost() { | 229 gfx::NativeView ExtensionHost::GetNativeViewOfHost() { |
| 229 return view() ? view()->native_view() : NULL; | 230 return view() ? view()->native_view() : NULL; |
| 230 } | 231 } |
| 231 | 232 |
| 232 void ExtensionHost::NavigateToURL(const GURL& url) { | 233 void ExtensionHost::NavigateToURL(const GURL& url) { |
| 233 // Prevent explicit navigation to another extension id's pages. | 234 // Prevent explicit navigation to another extension id's pages. |
| 234 // This method is only called by some APIs, so we still need to protect | 235 // This method is only called by some APIs, so we still need to protect |
| 235 // DidNavigate below (location = ""). | 236 // DidNavigate below (location = ""). |
| 236 if (url.SchemeIs(chrome::kExtensionScheme) && | 237 if (url.SchemeIs(chrome::kExtensionScheme) && url.host() != extension_id()) { |
| 237 url.host() != extension_->id()) { | |
| 238 // TODO(erikkay) communicate this back to the caller? | 238 // TODO(erikkay) communicate this back to the caller? |
| 239 return; | 239 return; |
| 240 } | 240 } |
| 241 | 241 |
| 242 url_ = url; | 242 url_ = url; |
| 243 | 243 |
| 244 if (!is_background_page() && | 244 if (!is_background_page() && |
| 245 !profile_->GetExtensionService()->IsBackgroundPageReady(extension_)) { | 245 !profile_->GetExtensionService()->IsBackgroundPageReady(extension_)) { |
| 246 // Make sure the background page loads before any others. | 246 // Make sure the background page loads before any others. |
| 247 registrar_.Add(this, NotificationType::EXTENSION_BACKGROUND_PAGE_READY, | 247 registrar_.Add(this, NotificationType::EXTENSION_BACKGROUND_PAGE_READY, |
| 248 Source<Extension>(extension_)); | 248 Source<Extension>(extension_)); |
| 249 return; | 249 return; |
| 250 } | 250 } |
| 251 | 251 |
| 252 render_view_host_->NavigateToURL(url_); | 252 render_view_host_->NavigateToURL(url_); |
| 253 } | 253 } |
| 254 | 254 |
| 255 void ExtensionHost::Observe(NotificationType type, | 255 void ExtensionHost::Observe(NotificationType type, |
| 256 const NotificationSource& source, | 256 const NotificationSource& source, |
| 257 const NotificationDetails& details) { | 257 const NotificationDetails& details) { |
| 258 switch (type.value) { | 258 switch (type.value) { |
| 259 case NotificationType::EXTENSION_BACKGROUND_PAGE_READY: | 259 case NotificationType::EXTENSION_BACKGROUND_PAGE_READY: |
| 260 DCHECK(profile_->GetExtensionService()-> | 260 DCHECK(profile_->GetExtensionService()-> |
| 261 IsBackgroundPageReady(extension_)); | 261 IsBackgroundPageReady(extension_)); |
| 262 NavigateToURL(url_); | 262 NavigateToURL(url_); |
| 263 break; | 263 break; |
| 264 case NotificationType::RENDERER_PROCESS_CREATED: | 264 case NotificationType::RENDERER_PROCESS_CREATED: |
| 265 NotificationService::current()->Notify( | 265 NotificationService::current()->Notify( |
| 266 NotificationType::EXTENSION_PROCESS_CREATED, | 266 NotificationType::EXTENSION_PROCESS_CREATED, |
| 267 Source<Profile>(profile_), | 267 Source<Profile>(profile_), |
| 268 Details<ExtensionHost>(this)); | 268 Details<ExtensionHost>(this)); |
| 269 break; | 269 break; |
| 270 case NotificationType::EXTENSION_UNLOADED: | 270 case NotificationType::EXTENSION_UNLOADED: |
| 271 // The extension object will be deleted after this notification has been | 271 // The extension object will be deleted after this notification has been |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 | 334 |
| 335 // This catches two bogus use cases: | 335 // This catches two bogus use cases: |
| 336 // (1) URLs that look like chrome-extension://somethingbogus or | 336 // (1) URLs that look like chrome-extension://somethingbogus or |
| 337 // chrome-extension://nosuchid/, in other words, no Extension would | 337 // chrome-extension://nosuchid/, in other words, no Extension would |
| 338 // be found. | 338 // be found. |
| 339 // (2) URLs that refer to a different extension than this one. | 339 // (2) URLs that refer to a different extension than this one. |
| 340 // In both cases, we preserve the old URL and reset the EFD to NULL. This | 340 // In both cases, we preserve the old URL and reset the EFD to NULL. This |
| 341 // will leave the host in kind of a bad state with poor UI and errors, but | 341 // will leave the host in kind of a bad state with poor UI and errors, but |
| 342 // it's better than the alternative. | 342 // it's better than the alternative. |
| 343 // TODO(erikkay) Perhaps we should display errors in developer mode. | 343 // TODO(erikkay) Perhaps we should display errors in developer mode. |
| 344 if (params.url.host() != extension_->id()) { | 344 if (params.url.host() != extension_id()) { |
| 345 extension_function_dispatcher_.reset(NULL); | 345 extension_function_dispatcher_.reset(NULL); |
| 346 return; | 346 return; |
| 347 } | 347 } |
| 348 | 348 |
| 349 url_ = params.url; | 349 url_ = params.url; |
| 350 extension_function_dispatcher_.reset( | 350 extension_function_dispatcher_.reset( |
| 351 ExtensionFunctionDispatcher::Create(render_view_host_, this, url_)); | 351 ExtensionFunctionDispatcher::Create(render_view_host_, this, url_)); |
| 352 } | 352 } |
| 353 | 353 |
| 354 void ExtensionHost::InsertInfobarCSS() { | 354 void ExtensionHost::InsertInfobarCSS() { |
| (...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 833 return window_id; | 833 return window_id; |
| 834 } | 834 } |
| 835 | 835 |
| 836 void ExtensionHost::OnRunFileChooser( | 836 void ExtensionHost::OnRunFileChooser( |
| 837 const ViewHostMsg_RunFileChooser_Params& params) { | 837 const ViewHostMsg_RunFileChooser_Params& params) { |
| 838 if (file_select_helper_.get() == NULL) | 838 if (file_select_helper_.get() == NULL) |
| 839 file_select_helper_.reset(new FileSelectHelper(profile())); | 839 file_select_helper_.reset(new FileSelectHelper(profile())); |
| 840 file_select_helper_->RunFileChooser(render_view_host_, | 840 file_select_helper_->RunFileChooser(render_view_host_, |
| 841 associated_tab_contents(), params); | 841 associated_tab_contents(), params); |
| 842 } | 842 } |
| OLD | NEW |