| 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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 render_view_host_->CreateRenderView(); | 91 render_view_host_->CreateRenderView(); |
| 92 NavigateToURL(url_); | 92 NavigateToURL(url_); |
| 93 DCHECK(IsRenderViewLive()); | 93 DCHECK(IsRenderViewLive()); |
| 94 NotificationService::current()->Notify( | 94 NotificationService::current()->Notify( |
| 95 NotificationType::EXTENSION_PROCESS_CREATED, | 95 NotificationType::EXTENSION_PROCESS_CREATED, |
| 96 Source<Profile>(profile_), | 96 Source<Profile>(profile_), |
| 97 Details<ExtensionHost>(this)); | 97 Details<ExtensionHost>(this)); |
| 98 } | 98 } |
| 99 | 99 |
| 100 void ExtensionHost::NavigateToURL(const GURL& url) { | 100 void ExtensionHost::NavigateToURL(const GURL& url) { |
| 101 // Prevent explicit navigation to another extension id's pages. |
| 102 // This method is only called by some APIs, so we still need to protect |
| 103 // DidNavigate below (location = ""). |
| 104 if (url.SchemeIs(chrome::kExtensionScheme) && |
| 105 url.host() != extension_->id()) { |
| 106 // TODO(erikkay) communicate this back to the caller? |
| 107 return; |
| 108 } |
| 109 |
| 101 url_ = url; | 110 url_ = url; |
| 102 | 111 |
| 103 if (!is_background_page() && !extension_->GetBackgroundPageReady()) { | 112 if (!is_background_page() && !extension_->GetBackgroundPageReady()) { |
| 104 // Make sure the background page loads before any others. | 113 // Make sure the background page loads before any others. |
| 105 registrar_.Add(this, NotificationType::EXTENSION_BACKGROUND_PAGE_READY, | 114 registrar_.Add(this, NotificationType::EXTENSION_BACKGROUND_PAGE_READY, |
| 106 Source<Extension>(extension_)); | 115 Source<Extension>(extension_)); |
| 107 return; | 116 return; |
| 108 } | 117 } |
| 109 render_view_host_->NavigateToURL(url_); | 118 render_view_host_->NavigateToURL(url_); |
| 110 } | 119 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 134 | 143 |
| 135 void ExtensionHost::DidNavigate(RenderViewHost* render_view_host, | 144 void ExtensionHost::DidNavigate(RenderViewHost* render_view_host, |
| 136 const ViewHostMsg_FrameNavigate_Params& params) { | 145 const ViewHostMsg_FrameNavigate_Params& params) { |
| 137 // We only care when the outer frame changes. | 146 // We only care when the outer frame changes. |
| 138 switch (params.transition) { | 147 switch (params.transition) { |
| 139 case PageTransition::AUTO_SUBFRAME: | 148 case PageTransition::AUTO_SUBFRAME: |
| 140 case PageTransition::MANUAL_SUBFRAME: | 149 case PageTransition::MANUAL_SUBFRAME: |
| 141 return; | 150 return; |
| 142 } | 151 } |
| 143 | 152 |
| 144 url_ = params.url; | 153 if (!params.url.SchemeIs(chrome::kExtensionScheme)) { |
| 145 if (!url_.SchemeIs(chrome::kExtensionScheme)) { | 154 extension_function_dispatcher_.reset(NULL); |
| 155 url_ = params.url; |
| 156 return; |
| 157 } |
| 158 |
| 159 // This catches two bogus use cases: |
| 160 // (1) URLs that look like chrome-extension://somethingbogus or |
| 161 // chrome-extension://nosuchid/, in other words, no Extension would |
| 162 // be found. |
| 163 // (2) URLs that refer to a different extension than this one. |
| 164 // In both cases, we preserve the old URL and reset the EFD to NULL. This |
| 165 // will leave the host in kind of a bad state with poor UI and errors, but |
| 166 // it's better than the alternative. |
| 167 // TODO(erikkay) Perhaps we should display log errors or display a big 404 |
| 168 // in the toolstrip or something like that. |
| 169 if (params.url.host() != extension_->id()) { |
| 146 extension_function_dispatcher_.reset(NULL); | 170 extension_function_dispatcher_.reset(NULL); |
| 147 return; | 171 return; |
| 148 } | 172 } |
| 173 |
| 174 url_ = params.url; |
| 149 extension_function_dispatcher_.reset( | 175 extension_function_dispatcher_.reset( |
| 150 new ExtensionFunctionDispatcher(render_view_host_, this, url_)); | 176 new ExtensionFunctionDispatcher(render_view_host_, this, url_)); |
| 151 } | 177 } |
| 152 | 178 |
| 153 void ExtensionHost::DidStopLoading(RenderViewHost* render_view_host) { | 179 void ExtensionHost::DidStopLoading(RenderViewHost* render_view_host) { |
| 154 static const base::StringPiece toolstrip_css( | 180 static const base::StringPiece toolstrip_css( |
| 155 ResourceBundle::GetSharedInstance().GetRawDataResource( | 181 ResourceBundle::GetSharedInstance().GetRawDataResource( |
| 156 IDR_EXTENSIONS_TOOLSTRIP_CSS)); | 182 IDR_EXTENSIONS_TOOLSTRIP_CSS)); |
| 157 #if defined(TOOLKIT_VIEWS) | 183 #if defined(TOOLKIT_VIEWS) |
| 158 ExtensionView* view = view_.get(); | 184 ExtensionView* view = view_.get(); |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 window_id = ExtensionTabUtil::GetWindowId( | 382 window_id = ExtensionTabUtil::GetWindowId( |
| 357 const_cast<ExtensionHost* >(this)->GetBrowser()); | 383 const_cast<ExtensionHost* >(this)->GetBrowser()); |
| 358 } else if (extension_host_type_ == ViewType::EXTENSION_BACKGROUND_PAGE) { | 384 } else if (extension_host_type_ == ViewType::EXTENSION_BACKGROUND_PAGE) { |
| 359 // Background page is not attached to any browser window, so pass -1. | 385 // Background page is not attached to any browser window, so pass -1. |
| 360 window_id = -1; | 386 window_id = -1; |
| 361 } else { | 387 } else { |
| 362 NOTREACHED(); | 388 NOTREACHED(); |
| 363 } | 389 } |
| 364 return window_id; | 390 return window_id; |
| 365 } | 391 } |
| OLD | NEW |