Chromium Code Reviews| 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/prerender/prerender_contents.h" | 5 #include "chrome/browser/prerender/prerender_contents.h" |
| 6 | 6 |
| 7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
| 8 #include "chrome/browser/background_contents_service.h" | 8 #include "chrome/browser/background_contents_service.h" |
| 9 #include "chrome/browser/browsing_instance.h" | 9 #include "chrome/browser/browsing_instance.h" |
| 10 #include "chrome/browser/prerender/prerender_manager.h" | 10 #include "chrome/browser/prerender/prerender_manager.h" |
| 11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/browser/renderer_host/render_view_host.h" | 12 #include "chrome/browser/renderer_host/render_view_host.h" |
| 13 #include "chrome/browser/renderer_host/site_instance.h" | 13 #include "chrome/browser/renderer_host/site_instance.h" |
| 14 #include "chrome/browser/renderer_preferences_util.h" | 14 #include "chrome/browser/renderer_preferences_util.h" |
| 15 #include "chrome/common/extensions/extension_constants.h" | 15 #include "chrome/common/extensions/extension_constants.h" |
| 16 #include "chrome/common/notification_service.h" | 16 #include "chrome/common/notification_service.h" |
| 17 #include "chrome/common/url_constants.h" | 17 #include "chrome/common/url_constants.h" |
| 18 #include "chrome/common/view_types.h" | 18 #include "chrome/common/view_types.h" |
| 19 #include "chrome/common/render_messages.h" | |
| 19 #include "chrome/common/render_messages_params.h" | 20 #include "chrome/common/render_messages_params.h" |
| 20 #include "gfx/rect.h" | 21 #include "gfx/rect.h" |
| 21 | 22 |
| 22 PrerenderContents::PrerenderContents(PrerenderManager* prerender_manager, | 23 PrerenderContents::PrerenderContents(PrerenderManager* prerender_manager, |
| 23 Profile* profile, | 24 Profile* profile, |
| 24 const GURL& url) | 25 const GURL& url) |
| 25 : prerender_manager_(prerender_manager), | 26 : prerender_manager_(prerender_manager), |
| 26 render_view_host_(NULL), | 27 render_view_host_(NULL), |
| 27 prerender_url_(url), | 28 prerender_url_(url), |
| 28 profile_(profile), | 29 profile_(profile), |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 42 NotificationService::AllSources()); | 43 NotificationService::AllSources()); |
| 43 | 44 |
| 44 // Register for our parent profile to shutdown, so we can shut ourselves down | 45 // Register for our parent profile to shutdown, so we can shut ourselves down |
| 45 // as well (should only be called for OTR profiles, as we should receive | 46 // as well (should only be called for OTR profiles, as we should receive |
| 46 // APP_TERMINATING before non-OTR profiles are destroyed). | 47 // APP_TERMINATING before non-OTR profiles are destroyed). |
| 47 // TODO(tburkard): figure out if this is needed. | 48 // TODO(tburkard): figure out if this is needed. |
| 48 registrar_.Add(this, NotificationType::PROFILE_DESTROYED, | 49 registrar_.Add(this, NotificationType::PROFILE_DESTROYED, |
| 49 Source<Profile>(profile_)); | 50 Source<Profile>(profile_)); |
| 50 render_view_host_->CreateRenderView(string16()); | 51 render_view_host_->CreateRenderView(string16()); |
| 51 render_view_host_->NavigateToURL(prerender_url_); | 52 render_view_host_->NavigateToURL(prerender_url_); |
| 53 AddMatchingUrl(prerender_url_); | |
| 52 } | 54 } |
| 53 | 55 |
| 54 PrerenderContents::~PrerenderContents() { | 56 PrerenderContents::~PrerenderContents() { |
| 55 if (!render_view_host_) // Will be null for unit tests. | 57 if (!render_view_host_) // Will be null for unit tests. |
| 56 return; | 58 return; |
| 57 | 59 |
| 58 render_view_host_->Shutdown(); // deletes render_view_host | 60 render_view_host_->Shutdown(); // deletes render_view_host |
| 59 } | 61 } |
| 60 | 62 |
| 61 RenderViewHostDelegate::View* PrerenderContents::GetViewDelegate() { | 63 RenderViewHostDelegate::View* PrerenderContents::GetViewDelegate() { |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 80 // We only care when the outer frame changes. | 82 // We only care when the outer frame changes. |
| 81 if (!PageTransition::IsMainFrame(params.transition)) | 83 if (!PageTransition::IsMainFrame(params.transition)) |
| 82 return; | 84 return; |
| 83 | 85 |
| 84 // Store the navigation params. | 86 // Store the navigation params. |
| 85 ViewHostMsg_FrameNavigate_Params* p = new ViewHostMsg_FrameNavigate_Params(); | 87 ViewHostMsg_FrameNavigate_Params* p = new ViewHostMsg_FrameNavigate_Params(); |
| 86 *p = params; | 88 *p = params; |
| 87 navigate_params_.reset(p); | 89 navigate_params_.reset(p); |
| 88 | 90 |
| 89 url_ = params.url; | 91 url_ = params.url; |
| 92 | |
| 93 AddMatchingUrl(url_); | |
| 90 } | 94 } |
| 91 | 95 |
| 92 void PrerenderContents::UpdateTitle(RenderViewHost* render_view_host, | 96 void PrerenderContents::UpdateTitle(RenderViewHost* render_view_host, |
| 93 int32 page_id, | 97 int32 page_id, |
| 94 const std::wstring& title) { | 98 const std::wstring& title) { |
| 95 if (title.empty()) { | 99 if (title.empty()) { |
| 96 return; | 100 return; |
| 97 } | 101 } |
| 98 | 102 |
| 99 title_ = WideToUTF16Hack(title); | 103 title_ = WideToUTF16Hack(title); |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 208 } | 212 } |
| 209 | 213 |
| 210 void PrerenderContents::ShowCreatedWidget(int route_id, | 214 void PrerenderContents::ShowCreatedWidget(int route_id, |
| 211 const gfx::Rect& initial_pos) { | 215 const gfx::Rect& initial_pos) { |
| 212 NOTIMPLEMENTED(); | 216 NOTIMPLEMENTED(); |
| 213 } | 217 } |
| 214 | 218 |
| 215 void PrerenderContents::ShowCreatedFullscreenWidget(int route_id) { | 219 void PrerenderContents::ShowCreatedFullscreenWidget(int route_id) { |
| 216 NOTIMPLEMENTED(); | 220 NOTIMPLEMENTED(); |
| 217 } | 221 } |
| 222 | |
| 223 bool PrerenderContents::OnMessageReceived(const IPC::Message& message) { | |
| 224 bool handled = true; | |
| 225 bool message_is_ok = true; | |
| 226 IPC_BEGIN_MESSAGE_MAP_EX(PrerenderContents, message, message_is_ok) | |
| 227 IPC_MESSAGE_HANDLER(ViewHostMsg_DidStartProvisionalLoadForFrame, | |
| 228 OnDidStartProvisionalLoadForFrame) | |
| 229 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRedirectProvisionalLoad, | |
| 230 OnDidRedirectProvisionalLoad) | |
| 231 IPC_MESSAGE_UNHANDLED(handled = false) | |
| 232 IPC_END_MESSAGE_MAP_EX() | |
| 233 | |
| 234 return handled; | |
| 235 } | |
| 236 | |
| 237 void PrerenderContents::OnDidStartProvisionalLoadForFrame(int64 frame_id, | |
| 238 bool is_main_frame, | |
| 239 const GURL& url) { | |
| 240 if (is_main_frame) | |
| 241 AddMatchingUrl(url); | |
| 242 } | |
| 243 | |
| 244 void PrerenderContents::OnDidRedirectProvisionalLoad(int32 page_id, | |
| 245 const GURL& source_url, | |
| 246 const GURL& target_url) { | |
| 247 AddMatchingUrl(target_url); | |
| 248 } | |
| 249 | |
| 250 void PrerenderContents::AddMatchingUrl(const GURL& url) { | |
| 251 printf("\n\n*** new matching URL: %s\n\n", url.spec().c_str()); | |
|
cbentzel
2011/01/12 18:04:14
Remove printf
tburkard
2011/01/12 21:32:10
Done.
| |
| 252 matching_urls_.push_back(url); | |
| 253 } | |
| 254 | |
| 255 bool PrerenderContents::MatchesUrl(const GURL& url) { | |
| 256 for (std::vector<GURL>::iterator it = matching_urls_.begin(); | |
|
cbentzel
2011/01/12 18:04:14
Just use std::find instead of writing out the loop
tburkard
2011/01/12 21:32:10
had a more complex check in there at first.
| |
| 257 it != matching_urls_.end(); | |
| 258 ++it) { | |
| 259 if (*it == url) | |
| 260 return true; | |
| 261 } | |
| 262 return false; | |
| 263 } | |
| OLD | NEW |