| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/web_contents.h" | 5 #include "chrome/browser/web_contents.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/file_version_info.h" | 8 #include "base/file_version_info.h" |
| 9 #include "chrome/app/locales/locale_settings.h" | 9 #include "chrome/app/locales/locale_settings.h" |
| 10 #include "chrome/browser/bookmark_bar_model.h" | 10 #include "chrome/browser/bookmark_bar_model.h" |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 const int kPrefsToObserveLength = arraysize(kPrefsToObserve); | 97 const int kPrefsToObserveLength = arraysize(kPrefsToObserve); |
| 98 | 98 |
| 99 void InitWebContentsClass() { | 99 void InitWebContentsClass() { |
| 100 static bool web_contents_class_initialized = false; | 100 static bool web_contents_class_initialized = false; |
| 101 if (!web_contents_class_initialized) { | 101 if (!web_contents_class_initialized) { |
| 102 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 102 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 103 web_contents_class_initialized = true; | 103 web_contents_class_initialized = true; |
| 104 } | 104 } |
| 105 } | 105 } |
| 106 | 106 |
| 107 GURL GURLWithoutRef(const GURL& url) { | |
| 108 url_canon::Replacements<char> replacements; | |
| 109 replacements.ClearRef(); | |
| 110 return url.ReplaceComponents(replacements); | |
| 111 } | |
| 112 | |
| 113 } // namespace | 107 } // namespace |
| 114 | 108 |
| 115 /////////////////////////////////////////////////////////////////////////////// | 109 /////////////////////////////////////////////////////////////////////////////// |
| 116 // WebContents | 110 // WebContents |
| 117 | 111 |
| 118 class WebContents::GearsCreateShortcutCallbackFunctor { | 112 class WebContents::GearsCreateShortcutCallbackFunctor { |
| 119 public: | 113 public: |
| 120 explicit GearsCreateShortcutCallbackFunctor(WebContents* contents) | 114 explicit GearsCreateShortcutCallbackFunctor(WebContents* contents) |
| 121 : contents_(contents) {} | 115 : contents_(contents) {} |
| 122 | 116 |
| (...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 563 // handler. It does this by asynchronously calling the OnCrossSiteResponse | 557 // handler. It does this by asynchronously calling the OnCrossSiteResponse |
| 564 // method of WebContents on the UI thread, which sends a ClosePage message | 558 // method of WebContents on the UI thread, which sends a ClosePage message |
| 565 // to the current RVH. | 559 // to the current RVH. |
| 566 // - Once the onunload handler is finished, a ClosePage_ACK message is sent to | 560 // - Once the onunload handler is finished, a ClosePage_ACK message is sent to |
| 567 // the ResourceDispatcherHost, who unpauses the response. Data is then sent | 561 // the ResourceDispatcherHost, who unpauses the response. Data is then sent |
| 568 // to the pending RVH. | 562 // to the pending RVH. |
| 569 // - The pending renderer sends a FrameNavigate message that invokes the | 563 // - The pending renderer sends a FrameNavigate message that invokes the |
| 570 // DidNavigate method. This replaces the current RVH with the | 564 // DidNavigate method. This replaces the current RVH with the |
| 571 // pending RVH and goes back to the NORMAL RendererState. | 565 // pending RVH and goes back to the NORMAL RendererState. |
| 572 | 566 |
| 573 bool WebContents::Navigate(const NavigationEntry& entry, bool reload) { | 567 bool WebContents::NavigateToPendingEntry(bool reload) { |
| 574 RenderViewHost* dest_render_view_host = render_manager_.Navigate(entry); | 568 NavigationEntry* entry = controller()->GetPendingEntry(); |
| 569 RenderViewHost* dest_render_view_host = render_manager_.Navigate(*entry); |
| 575 | 570 |
| 576 // Used for page load time metrics. | 571 // Used for page load time metrics. |
| 577 current_load_start_ = TimeTicks::Now(); | 572 current_load_start_ = TimeTicks::Now(); |
| 578 | 573 |
| 579 // Navigate in the desired RenderViewHost | 574 // Navigate in the desired RenderViewHost. |
| 580 dest_render_view_host->NavigateToEntry(entry, reload); | 575 dest_render_view_host->NavigateToEntry(*entry, reload); |
| 581 | 576 |
| 582 if (entry.page_id() == -1) { | 577 if (entry->page_id() == -1) { |
| 583 // HACK!! This code suppresses javascript: URLs from being added to | 578 // HACK!! This code suppresses javascript: URLs from being added to |
| 584 // session history, which is what we want to do for javascript: URLs that | 579 // session history, which is what we want to do for javascript: URLs that |
| 585 // do not generate content. What we really need is a message from the | 580 // do not generate content. What we really need is a message from the |
| 586 // renderer telling us that a new page was not created. The same message | 581 // renderer telling us that a new page was not created. The same message |
| 587 // could be used for mailto: URLs and the like. | 582 // could be used for mailto: URLs and the like. |
| 588 if (entry.url().SchemeIs("javascript")) | 583 if (entry->url().SchemeIs("javascript")) |
| 589 return false; | 584 return false; |
| 590 } | 585 } |
| 591 | 586 |
| 592 if (reload && !profile()->IsOffTheRecord()) { | 587 if (reload && !profile()->IsOffTheRecord()) { |
| 593 HistoryService* history = | 588 HistoryService* history = |
| 594 profile()->GetHistoryService(Profile::IMPLICIT_ACCESS); | 589 profile()->GetHistoryService(Profile::IMPLICIT_ACCESS); |
| 595 if (history) | 590 if (history) |
| 596 history->SetFavIconOutOfDateForPage(entry.url()); | 591 history->SetFavIconOutOfDateForPage(entry->url()); |
| 597 } | 592 } |
| 598 | 593 |
| 599 return true; | 594 return true; |
| 600 } | 595 } |
| 601 | 596 |
| 602 void WebContents::Stop() { | 597 void WebContents::Stop() { |
| 603 render_manager_.Stop(); | 598 render_manager_.Stop(); |
| 604 printing_.Stop(); | 599 printing_.Stop(); |
| 605 } | 600 } |
| 606 | 601 |
| (...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1013 | 1008 |
| 1014 PluginInstaller* WebContents::GetPluginInstaller() { | 1009 PluginInstaller* WebContents::GetPluginInstaller() { |
| 1015 if (plugin_installer_.get() == NULL) | 1010 if (plugin_installer_.get() == NULL) |
| 1016 plugin_installer_.reset(new PluginInstaller(this)); | 1011 plugin_installer_.reset(new PluginInstaller(this)); |
| 1017 return plugin_installer_.get(); | 1012 return plugin_installer_.get(); |
| 1018 } | 1013 } |
| 1019 | 1014 |
| 1020 bool WebContents::IsActiveEntry(int32 page_id) { | 1015 bool WebContents::IsActiveEntry(int32 page_id) { |
| 1021 NavigationEntry* active_entry = controller()->GetActiveEntry(); | 1016 NavigationEntry* active_entry = controller()->GetActiveEntry(); |
| 1022 return (active_entry != NULL && | 1017 return (active_entry != NULL && |
| 1023 active_entry->site_instance() == site_instance() && | 1018 active_entry->site_instance() == GetSiteInstance() && |
| 1024 active_entry->page_id() == page_id); | 1019 active_entry->page_id() == page_id); |
| 1025 } | 1020 } |
| 1026 | 1021 |
| 1027 /////////////////////////////////////////////////////////////////////////////// | 1022 /////////////////////////////////////////////////////////////////////////////// |
| 1028 // RenderViewHostDelegate implementation: | 1023 // RenderViewHostDelegate implementation: |
| 1029 | 1024 |
| 1030 RenderViewHostDelegate::FindInPage* WebContents::GetFindInPageDelegate() { | 1025 RenderViewHostDelegate::FindInPage* WebContents::GetFindInPageDelegate() { |
| 1031 // The find in page controller implements this interface for us. Our return | 1026 // The find in page controller implements this interface for us. Our return |
| 1032 // value can be NULL, so it's fine if the find in controller doesn't exist. | 1027 // value can be NULL, so it's fine if the find in controller doesn't exist. |
| 1033 return find_in_page_controller_.get(); | 1028 return find_in_page_controller_.get(); |
| 1034 } | 1029 } |
| 1035 | 1030 |
| 1036 Profile* WebContents::GetProfile() const { | 1031 Profile* WebContents::GetProfile() const { |
| 1037 return profile(); | 1032 return profile(); |
| 1038 } | 1033 } |
| 1039 | 1034 |
| 1040 void WebContents::CreateView(int route_id, HANDLE modal_dialog_event) { | 1035 void WebContents::CreateView(int route_id, HANDLE modal_dialog_event) { |
| 1041 WebContents* new_view = new WebContents(profile(), | 1036 WebContents* new_view = new WebContents(profile(), |
| 1042 site_instance(), | 1037 GetSiteInstance(), |
| 1043 render_view_factory_, | 1038 render_view_factory_, |
| 1044 route_id, | 1039 route_id, |
| 1045 modal_dialog_event); | 1040 modal_dialog_event); |
| 1046 new_view->SetupController(profile()); | 1041 new_view->SetupController(profile()); |
| 1047 // TODO(beng) | 1042 // TODO(beng) |
| 1048 // The intention here is to create background tabs, which should ideally | 1043 // The intention here is to create background tabs, which should ideally |
| 1049 // be parented to NULL. However doing that causes the corresponding view | 1044 // be parented to NULL. However doing that causes the corresponding view |
| 1050 // container windows to show up as overlapped windows, which causes | 1045 // container windows to show up as overlapped windows, which causes |
| 1051 // other issues. We should fix this. | 1046 // other issues. We should fix this. |
| 1052 HWND new_view_parent_window = ::GetAncestor(GetHWND(), GA_ROOT); | 1047 HWND new_view_parent_window = ::GetAncestor(GetHWND(), GA_ROOT); |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1172 // Hide any visible hung renderer warning for this web contents' process. | 1167 // Hide any visible hung renderer warning for this web contents' process. |
| 1173 HungRendererWarning::HideForWebContents(this); | 1168 HungRendererWarning::HideForWebContents(this); |
| 1174 } | 1169 } |
| 1175 | 1170 |
| 1176 void WebContents::DidNavigate(RenderViewHost* rvh, | 1171 void WebContents::DidNavigate(RenderViewHost* rvh, |
| 1177 const ViewHostMsg_FrameNavigate_Params& params) { | 1172 const ViewHostMsg_FrameNavigate_Params& params) { |
| 1178 if (PageTransition::IsMainFrame(params.transition)) | 1173 if (PageTransition::IsMainFrame(params.transition)) |
| 1179 render_manager_.DidNavigateMainFrame(rvh); | 1174 render_manager_.DidNavigateMainFrame(rvh); |
| 1180 | 1175 |
| 1181 // In the case of interstitial, we don't mess with the navigation entries. | 1176 // In the case of interstitial, we don't mess with the navigation entries. |
| 1177 // TODO(brettw) this seems like a bug. What happens if the page goes and |
| 1178 // does something on its own (or something that just got delayed), then |
| 1179 // we won't have a navigation entry for that stuff when the interstitial |
| 1180 // is hidden. |
| 1182 if (render_manager_.showing_interstitial_page()) | 1181 if (render_manager_.showing_interstitial_page()) |
| 1183 return; | 1182 return; |
| 1184 | 1183 |
| 1185 // Check for navigations we don't expect. | 1184 // We can't do anything about navigations when we're inactive. |
| 1186 if (!controller() || !is_active_ || params.page_id == -1) { | 1185 if (!controller() || !is_active_) |
| 1187 if (params.page_id == -1) { | 1186 return; |
| 1188 DCHECK(controller()->GetActiveEntry() == NULL) | |
| 1189 << "The renderer is permitted to send a FrameNavigate event for an " | |
| 1190 "invalid |page_id| if, and only if, this is the initial blank " | |
| 1191 "page for a main frame."; | |
| 1192 } | |
| 1193 BroadcastProvisionalLoadCommit(rvh, params); | |
| 1194 return; | |
| 1195 } | |
| 1196 | |
| 1197 // Generate the details for the notification. | |
| 1198 // TODO(brettw) bug 1343146: Move into the NavigationController. | |
| 1199 NavigationController::LoadCommittedDetails details; | |
| 1200 // WebKit doesn't set the "auto" transition on meta refreshes properly (bug | |
| 1201 // 1051891) so we manually set it for redirects which we normally treat as | |
| 1202 // "non-user-gestures" where we want to update stuff after navigations. | |
| 1203 // | |
| 1204 // Note that the redirect check also checks for a pending entry to | |
| 1205 // differentiate real redirects from browser initiated navigations to a | |
| 1206 // redirected entry. This happens when you hit back to go to a page that was | |
| 1207 // the destination of a redirect, we don't want to treat it as a redirect | |
| 1208 // even though that's what its transition will be. See bug 1117048. | |
| 1209 // | |
| 1210 // TODO(brettw) write a test for this complicated logic. | |
| 1211 details.is_auto = (PageTransition::IsRedirect(params.transition) && | |
| 1212 !controller()->GetPendingEntry()) || | |
| 1213 params.gesture == NavigationGestureAuto; | |
| 1214 details.is_in_page = IsInPageNavigation(params.url); | |
| 1215 details.is_main_frame = PageTransition::IsMainFrame(params.transition); | |
| 1216 | |
| 1217 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Don't make me come over there! | |
| 1218 // ======================================================================= | |
| 1219 // Add your code to DidNavigateAnyFramePostCommit if you have a helper object | |
| 1220 // that needs to know about all navigations. If it needs to do it only for | |
| 1221 // main frame or sub-frame navigations, add your code to | |
| 1222 // DidNavigate*PostCommit. | |
| 1223 | |
| 1224 // Create the new navigation entry for this navigation and do work specific to | |
| 1225 // this frame type. The main frame / sub frame functions will do additional | |
| 1226 // updates to the NavigationEntry appropriate for the navigation type (in | |
| 1227 // addition to a lot of other stuff). | |
| 1228 scoped_ptr<NavigationEntry> entry(CreateNavigationEntryForCommit(params)); | |
| 1229 | |
| 1230 // Commit the entry to the navigation controller. | |
| 1231 DidNavigateToEntry(entry.release(), &details); | |
| 1232 // WARNING: NavigationController will have taken ownership of entry at this | |
| 1233 // point, and may have deleted it. As such, do NOT use entry after this. | |
| 1234 | |
| 1235 // Run post-commit tasks. | |
| 1236 if (details.is_main_frame) | |
| 1237 DidNavigateMainFramePostCommit(details, params); | |
| 1238 DidNavigateAnyFramePostCommit(rvh, details, params); | |
| 1239 } | |
| 1240 | |
| 1241 // TODO(brettw) bug 1343146: This logic should be moved to NavigationController. | |
| 1242 NavigationEntry* WebContents::CreateNavigationEntryForCommit( | |
| 1243 const ViewHostMsg_FrameNavigate_Params& params) { | |
| 1244 // This new navigation entry will represent the navigation. Note that we | |
| 1245 // don't set the URL. This will happen in the DidNavigateMainFrame/SubFrame | |
| 1246 // because the entry's URL should represent the toplevel frame only. | |
| 1247 NavigationEntry* entry = new NavigationEntry(type()); | |
| 1248 if (PageTransition::IsMainFrame(params.transition)) | |
| 1249 entry->set_url(params.url); | |
| 1250 entry->set_page_id(params.page_id); | |
| 1251 entry->set_transition_type(params.transition); | |
| 1252 entry->set_site_instance(site_instance()); | |
| 1253 | |
| 1254 // Now that we've assigned a SiteInstance to this entry, we need to | |
| 1255 // assign it to the NavigationController's pending entry as well. This | |
| 1256 // allows us to find it via GetEntryWithPageID, etc. | |
| 1257 if (controller()->GetPendingEntry()) | |
| 1258 controller()->GetPendingEntry()->set_site_instance(entry->site_instance()); | |
| 1259 | 1187 |
| 1260 // Update the site of the SiteInstance if it doesn't have one yet, unless we | 1188 // Update the site of the SiteInstance if it doesn't have one yet, unless we |
| 1261 // are showing an interstitial page. If we are, we should wait until the | 1189 // are showing an interstitial page. If we are, we should wait until the |
| 1262 // real page commits. | 1190 // real page commits. |
| 1263 // | 1191 // |
| 1264 // TODO(brettw) the old code only checked for INTERSTIAL, this new code also | 1192 // TODO(brettw) the old code only checked for INTERSTIAL, this new code also |
| 1265 // checks for LEAVING_INTERSTITIAL mode in the manager. Is this difference | 1193 // checks for LEAVING_INTERSTITIAL mode in the manager. Is this difference |
| 1266 // important? | 1194 // important? |
| 1267 if (!site_instance()->has_site() && | 1195 if (!GetSiteInstance()->has_site() && |
| 1268 !render_manager_.showing_interstitial_page()) | 1196 !render_manager_.showing_interstitial_page()) |
| 1269 site_instance()->SetSite(params.url); | 1197 GetSiteInstance()->SetSite(params.url); |
| 1270 | 1198 |
| 1271 // When the navigation is just a change in ref or a sub-frame navigation, the | 1199 NavigationController::LoadCommittedDetails details; |
| 1272 // new page should inherit the existing entry's title and favicon, since it | 1200 if (!controller()->RendererDidNavigate( |
| 1273 // will be the same. A change in ref also inherits the security style and SSL | 1201 params, |
| 1274 // associated info. | 1202 render_manager_.IsRenderViewInterstitial(rvh), |
| 1275 bool in_page_nav; | 1203 &details)) |
| 1276 if ((in_page_nav = IsInPageNavigation(params.url)) || | 1204 return; // No navigation happened. |
| 1277 !PageTransition::IsMainFrame(params.transition)) { | |
| 1278 // In the case of a sub-frame navigation within a window that was created | |
| 1279 // without an URL (via window.open), we may not have a committed entry yet! | |
| 1280 NavigationEntry* old_entry = controller()->GetLastCommittedEntry(); | |
| 1281 if (old_entry) { | |
| 1282 entry->set_title(old_entry->title()); | |
| 1283 entry->favicon() = old_entry->favicon(); | |
| 1284 if (in_page_nav) | |
| 1285 entry->ssl() = old_entry->ssl(); | |
| 1286 } | |
| 1287 } | |
| 1288 | 1205 |
| 1289 if (PageTransition::IsMainFrame(params.transition)) { | 1206 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen |
| 1290 NavigationEntry* pending = controller()->GetPendingEntry(); | 1207 // for the appropriate notification (best) or you can add it to |
| 1291 if (pending) { | 1208 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if |
| 1292 // Copy fields from the pending NavigationEntry into the actual | 1209 // necessary, please). |
| 1293 // NavigationEntry that we're committing to. | |
| 1294 entry->set_user_typed_url(pending->user_typed_url()); | |
| 1295 if (pending->has_display_url()) | |
| 1296 entry->set_display_url(pending->display_url()); | |
| 1297 if (pending->url().SchemeIsFile()) | |
| 1298 entry->set_title(pending->title()); | |
| 1299 entry->set_content_state(pending->content_state()); | |
| 1300 } | |
| 1301 entry->set_has_post_data(params.is_post); | |
| 1302 } else { | |
| 1303 NavigationEntry* last_committed = controller()->GetLastCommittedEntry(); | |
| 1304 if (last_committed) { | |
| 1305 // In the case of a sub-frame navigation within a window that was created | |
| 1306 // without an URL (window.open), we may not have a committed entry yet! | |
| 1307 | 1210 |
| 1308 // Reset entry state to match that of the pending entry. | 1211 // Run post-commit tasks. |
| 1309 entry->set_unique_id(last_committed->unique_id()); | 1212 if (details.is_main_frame) |
| 1310 entry->set_url(last_committed->url()); | 1213 DidNavigateMainFramePostCommit(details, params); |
| 1311 entry->set_transition_type(last_committed->transition_type()); | 1214 DidNavigateAnyFramePostCommit(rvh, details, params); |
| 1312 entry->set_user_typed_url(last_committed->user_typed_url()); | |
| 1313 entry->set_content_state(last_committed->content_state()); | |
| 1314 | |
| 1315 // TODO(jcampan): when navigating to an insecure/unsafe inner frame, the | |
| 1316 // main entry is the one that gets notified of the mixed/unsafe contents | |
| 1317 // (see SSLPolicy::OnRequestStarted()). Here we are just transferring | |
| 1318 // that state. We should find a better way to do this. Note that it is OK | |
| 1319 // that the mixed/unsafe contents is set on the wrong navigation entry, as | |
| 1320 // that state is reset when navigating back to it. | |
| 1321 DCHECK(entry->ssl().content_status() == 0) << "We should never " | |
| 1322 "be setting the status bits from 1 to 0 on navigate."; | |
| 1323 entry->ssl() = last_committed->ssl(); | |
| 1324 } | |
| 1325 } | |
| 1326 | |
| 1327 return entry; | |
| 1328 } | 1215 } |
| 1329 | 1216 |
| 1330 void WebContents::DidNavigateMainFramePostCommit( | 1217 void WebContents::DidNavigateMainFramePostCommit( |
| 1331 const NavigationController::LoadCommittedDetails& details, | 1218 const NavigationController::LoadCommittedDetails& details, |
| 1332 const ViewHostMsg_FrameNavigate_Params& params) { | 1219 const ViewHostMsg_FrameNavigate_Params& params) { |
| 1333 // Hide the download shelf if all the following conditions are true: | 1220 // Hide the download shelf if all the following conditions are true: |
| 1334 // - there are no active downloads. | 1221 // - there are no active downloads. |
| 1335 // - this is a navigation to a different TLD. | 1222 // - this is a navigation to a different TLD. |
| 1336 // - at least 5 seconds have elapsed since the download shelf was shown. | 1223 // - at least 5 seconds have elapsed since the download shelf was shown. |
| 1337 // TODO(jcampan): bug 1156075 when user gestures are reliable, they should | 1224 // TODO(jcampan): bug 1156075 when user gestures are reliable, they should |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1406 // Update history. Note that this needs to happen after the entry is complete, | 1293 // Update history. Note that this needs to happen after the entry is complete, |
| 1407 // which WillNavigate[Main,Sub]Frame will do before this function is called. | 1294 // which WillNavigate[Main,Sub]Frame will do before this function is called. |
| 1408 if (params.should_update_history) { | 1295 if (params.should_update_history) { |
| 1409 // Most of the time, the displayURL matches the loaded URL, but for about: | 1296 // Most of the time, the displayURL matches the loaded URL, but for about: |
| 1410 // URLs, we use a data: URL as the real value. We actually want to save | 1297 // URLs, we use a data: URL as the real value. We actually want to save |
| 1411 // the about: URL to the history db and keep the data: URL hidden. This is | 1298 // the about: URL to the history db and keep the data: URL hidden. This is |
| 1412 // what the TabContents' URL getter does. | 1299 // what the TabContents' URL getter does. |
| 1413 UpdateHistoryForNavigation(GetURL(), params); | 1300 UpdateHistoryForNavigation(GetURL(), params); |
| 1414 } | 1301 } |
| 1415 | 1302 |
| 1416 // Have the controller save the current session. | |
| 1417 controller()->NotifyEntryChangedByPageID(type(), site_instance(), | |
| 1418 details.entry->page_id()); | |
| 1419 | |
| 1420 // Notify the password manager of the navigation or form submit. | 1303 // Notify the password manager of the navigation or form submit. |
| 1421 // TODO(brettw) bug 1343111: Password manager stuff in here needs to be | 1304 // TODO(brettw) bug 1343111: Password manager stuff in here needs to be |
| 1422 // cleaned up and covered by tests. | 1305 // cleaned up and covered by tests. |
| 1423 if (params.password_form.origin.is_valid()) | 1306 if (params.password_form.origin.is_valid()) |
| 1424 GetPasswordManager()->ProvisionallySavePassword(params.password_form); | 1307 GetPasswordManager()->ProvisionallySavePassword(params.password_form); |
| 1425 | |
| 1426 BroadcastProvisionalLoadCommit(render_view_host, params); | |
| 1427 } | 1308 } |
| 1428 | 1309 |
| 1429 bool WebContents::IsWebApplicationActive() const { | 1310 bool WebContents::IsWebApplicationActive() const { |
| 1430 if (!web_app_.get()) | 1311 if (!web_app_.get()) |
| 1431 return false; | 1312 return false; |
| 1432 | 1313 |
| 1433 // If we are inside an application, the application is always active. For | 1314 // If we are inside an application, the application is always active. For |
| 1434 // example, this allows us to display the GMail icon even when we are bounced | 1315 // example, this allows us to display the GMail icon even when we are bounced |
| 1435 // the login page. | 1316 // the login page. |
| 1436 if (delegate() && delegate()->IsApplication()) | 1317 if (delegate() && delegate()->IsApplication()) |
| 1437 return true; | 1318 return true; |
| 1438 | 1319 |
| 1439 return (GetURL() == web_app_->url()); | 1320 return (GetURL() == web_app_->url()); |
| 1440 } | 1321 } |
| 1441 | 1322 |
| 1442 void WebContents::WebAppImagesChanged(WebApp* web_app) { | 1323 void WebContents::WebAppImagesChanged(WebApp* web_app) { |
| 1443 DCHECK(web_app == web_app_.get()); | 1324 DCHECK(web_app == web_app_.get()); |
| 1444 if (delegate() && IsWebApplicationActive()) | 1325 if (delegate() && IsWebApplicationActive()) |
| 1445 delegate()->NavigationStateChanged(this, TabContents::INVALIDATE_FAVICON); | 1326 delegate()->NavigationStateChanged(this, TabContents::INVALIDATE_FAVICON); |
| 1446 } | 1327 } |
| 1447 | 1328 |
| 1448 void WebContents::BroadcastProvisionalLoadCommit( | |
| 1449 RenderViewHost* render_view_host, | |
| 1450 const ViewHostMsg_FrameNavigate_Params& params) { | |
| 1451 ProvisionalLoadDetails details( | |
| 1452 PageTransition::IsMainFrame(params.transition), | |
| 1453 render_manager_.IsRenderViewInterstitial(render_view_host), | |
| 1454 IsInPageNavigation(params.url), | |
| 1455 params.url, params.security_info); | |
| 1456 NotificationService::current()-> | |
| 1457 Notify(NOTIFY_FRAME_PROVISIONAL_LOAD_COMMITTED, | |
| 1458 Source<NavigationController>(controller()), | |
| 1459 Details<ProvisionalLoadDetails>(&details)); | |
| 1460 } | |
| 1461 | |
| 1462 void WebContents::UpdateStarredStateForCurrentURL() { | 1329 void WebContents::UpdateStarredStateForCurrentURL() { |
| 1463 BookmarkBarModel* model = profile()->GetBookmarkBarModel(); | 1330 BookmarkBarModel* model = profile()->GetBookmarkBarModel(); |
| 1464 const bool old_state = is_starred_; | 1331 const bool old_state = is_starred_; |
| 1465 is_starred_ = (model && model->GetNodeByURL(GetURL())); | 1332 is_starred_ = (model && model->GetNodeByURL(GetURL())); |
| 1466 | 1333 |
| 1467 if (is_starred_ != old_state && delegate()) | 1334 if (is_starred_ != old_state && delegate()) |
| 1468 delegate()->URLStarredChanged(this, is_starred_); | 1335 delegate()->URLStarredChanged(this, is_starred_); |
| 1469 } | 1336 } |
| 1470 | 1337 |
| 1471 void WebContents::UpdateAlternateErrorPageURL() { | 1338 void WebContents::UpdateAlternateErrorPageURL() { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1504 | 1371 |
| 1505 if (!controller()) | 1372 if (!controller()) |
| 1506 return; | 1373 return; |
| 1507 | 1374 |
| 1508 // We must be prepared to handle state updates for any page, these occur | 1375 // We must be prepared to handle state updates for any page, these occur |
| 1509 // when the user is scrolling and entering form data, as well as when we're | 1376 // when the user is scrolling and entering form data, as well as when we're |
| 1510 // leaving a page, in which case our state may have already been moved to | 1377 // leaving a page, in which case our state may have already been moved to |
| 1511 // the next page. The navigation controller will look up the appropriate | 1378 // the next page. The navigation controller will look up the appropriate |
| 1512 // NavigationEntry and update it when it is notified via the delegate. | 1379 // NavigationEntry and update it when it is notified via the delegate. |
| 1513 | 1380 |
| 1514 NavigationEntry* entry = controller()->GetEntryWithPageID( | 1381 int entry_index = controller()->GetEntryIndexWithPageID( |
| 1515 type(), site_instance(), page_id); | 1382 type(), GetSiteInstance(), page_id); |
| 1516 if (!entry) | 1383 if (entry_index < 0) |
| 1517 return; | 1384 return; |
| 1518 | 1385 NavigationEntry* entry = controller()->GetEntryAtIndex(entry_index); |
| 1519 unsigned changed_flags = 0; | 1386 unsigned changed_flags = 0; |
| 1520 | 1387 |
| 1521 // Update the URL. | 1388 // Update the URL. |
| 1522 if (url != entry->url()) { | 1389 if (url != entry->url()) { |
| 1523 changed_flags |= INVALIDATE_URL; | 1390 changed_flags |= INVALIDATE_URL; |
| 1524 if (entry == controller()->GetActiveEntry()) | 1391 if (entry == controller()->GetActiveEntry()) |
| 1525 fav_icon_helper_.FetchFavIcon(url); | 1392 fav_icon_helper_.FetchFavIcon(url); |
| 1526 entry->set_url(url); | 1393 entry->set_url(url); |
| 1527 } | 1394 } |
| 1528 | 1395 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1551 ::SetWindowText(view()->GetPluginHWND(), title.c_str()); | 1418 ::SetWindowText(view()->GetPluginHWND(), title.c_str()); |
| 1552 } | 1419 } |
| 1553 | 1420 |
| 1554 // Update the state (forms, etc.). | 1421 // Update the state (forms, etc.). |
| 1555 if (state != entry->content_state()) | 1422 if (state != entry->content_state()) |
| 1556 entry->set_content_state(state); | 1423 entry->set_content_state(state); |
| 1557 | 1424 |
| 1558 // Notify everybody of the changes (only when the current page changed). | 1425 // Notify everybody of the changes (only when the current page changed). |
| 1559 if (changed_flags && entry == controller()->GetActiveEntry()) | 1426 if (changed_flags && entry == controller()->GetActiveEntry()) |
| 1560 NotifyNavigationStateChanged(changed_flags); | 1427 NotifyNavigationStateChanged(changed_flags); |
| 1561 controller()->NotifyEntryChangedByPageID(type(), site_instance(), page_id); | 1428 controller()->NotifyEntryChanged(entry, entry_index); |
| 1562 } | 1429 } |
| 1563 | 1430 |
| 1564 void WebContents::UpdateTitle(RenderViewHost* rvh, | 1431 void WebContents::UpdateTitle(RenderViewHost* rvh, |
| 1565 int32 page_id, const std::wstring& title) { | 1432 int32 page_id, const std::wstring& title) { |
| 1566 if (!controller()) | 1433 if (!controller()) |
| 1567 return; | 1434 return; |
| 1568 | 1435 |
| 1569 // If we have a title, that's a pretty good indication that we've started | 1436 // If we have a title, that's a pretty good indication that we've started |
| 1570 // getting useful data. | 1437 // getting useful data. |
| 1571 response_started_ = false; | 1438 response_started_ = false; |
| 1572 | 1439 |
| 1573 NavigationEntry* entry; | 1440 NavigationEntry* entry; |
| 1574 if (render_manager_.showing_interstitial_page() && | 1441 if (render_manager_.showing_interstitial_page() && |
| 1575 (rvh == render_view_host())) { | 1442 (rvh == render_view_host())) { |
| 1576 // We are showing an interstitial page in a different RenderViewHost, so | 1443 // We are showing an interstitial page in a different RenderViewHost, so |
| 1577 // the page_id is not sufficient to find the entry from the controller. | 1444 // the page_id is not sufficient to find the entry from the controller. |
| 1578 // (both RenderViewHost page_ids overlap). We know it is the last entry, | 1445 // (both RenderViewHost page_ids overlap). We know it is the last entry, |
| 1579 // so just use that. | 1446 // so just use that. |
| 1580 entry = controller()->GetLastCommittedEntry(); | 1447 entry = controller()->GetLastCommittedEntry(); |
| 1581 } else { | 1448 } else { |
| 1582 entry = controller()->GetEntryWithPageID(type(), site_instance(), page_id); | 1449 entry = controller()->GetEntryWithPageID(type(), GetSiteInstance(), |
| 1450 page_id); |
| 1583 } | 1451 } |
| 1584 | 1452 |
| 1585 if (!entry) | 1453 if (!entry) |
| 1586 return; | 1454 return; |
| 1587 | 1455 |
| 1588 std::wstring trimmed_title; | 1456 std::wstring trimmed_title; |
| 1589 TrimWhitespace(title, TRIM_ALL, &trimmed_title); | 1457 TrimWhitespace(title, TRIM_ALL, &trimmed_title); |
| 1590 if (title == entry->title()) | 1458 if (title == entry->title()) |
| 1591 return; // Title did not change, do nothing. | 1459 return; // Title did not change, do nothing. |
| 1592 | 1460 |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1687 SetIsLoading(false, details.get()); | 1555 SetIsLoading(false, details.get()); |
| 1688 } | 1556 } |
| 1689 | 1557 |
| 1690 void WebContents::DidStartProvisionalLoadForFrame( | 1558 void WebContents::DidStartProvisionalLoadForFrame( |
| 1691 RenderViewHost* render_view_host, | 1559 RenderViewHost* render_view_host, |
| 1692 bool is_main_frame, | 1560 bool is_main_frame, |
| 1693 const GURL& url) { | 1561 const GURL& url) { |
| 1694 ProvisionalLoadDetails details( | 1562 ProvisionalLoadDetails details( |
| 1695 is_main_frame, | 1563 is_main_frame, |
| 1696 render_manager_.IsRenderViewInterstitial(render_view_host), | 1564 render_manager_.IsRenderViewInterstitial(render_view_host), |
| 1697 IsInPageNavigation(url), | 1565 controller()->IsURLInPageNavigation(url), |
| 1698 url, std::string()); | 1566 url, std::string()); |
| 1699 NotificationService::current()-> | 1567 NotificationService::current()-> |
| 1700 Notify(NOTIFY_FRAME_PROVISIONAL_LOAD_START, | 1568 Notify(NOTIFY_FRAME_PROVISIONAL_LOAD_START, |
| 1701 Source<NavigationController>(controller()), | 1569 Source<NavigationController>(controller()), |
| 1702 Details<ProvisionalLoadDetails>(&details)); | 1570 Details<ProvisionalLoadDetails>(&details)); |
| 1703 } | 1571 } |
| 1704 | 1572 |
| 1705 void WebContents::DidRedirectProvisionalLoad(int32 page_id, | 1573 void WebContents::DidRedirectProvisionalLoad(int32 page_id, |
| 1706 const GURL& source_url, | 1574 const GURL& source_url, |
| 1707 const GURL& target_url) { | 1575 const GURL& target_url) { |
| 1708 NavigationEntry* entry; | 1576 NavigationEntry* entry; |
| 1709 if (page_id == -1) | 1577 if (page_id == -1) { |
| 1710 entry = controller()->GetPendingEntry(); | 1578 entry = controller()->GetPendingEntry(); |
| 1711 else | 1579 } else { |
| 1712 entry = controller()->GetEntryWithPageID(type(), site_instance(), page_id); | 1580 entry = controller()->GetEntryWithPageID(type(), GetSiteInstance(), |
| 1581 page_id); |
| 1582 } |
| 1713 if (!entry || entry->tab_type() != type() || entry->url() != source_url) | 1583 if (!entry || entry->tab_type() != type() || entry->url() != source_url) |
| 1714 return; | 1584 return; |
| 1715 entry->set_url(target_url); | 1585 entry->set_url(target_url); |
| 1716 } | 1586 } |
| 1717 | 1587 |
| 1718 void WebContents::DidLoadResourceFromMemoryCache( | 1588 void WebContents::DidLoadResourceFromMemoryCache( |
| 1719 const GURL& url, | 1589 const GURL& url, |
| 1720 const std::string& security_info) { | 1590 const std::string& security_info) { |
| 1721 if (!controller()) | 1591 if (!controller()) |
| 1722 return; | 1592 return; |
| 1723 | 1593 |
| 1724 // Send out a notification that we loaded a resource from our memory cache. | 1594 // Send out a notification that we loaded a resource from our memory cache. |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1752 if (pending_entry && pending_entry->url() == url) | 1622 if (pending_entry && pending_entry->url() == url) |
| 1753 controller()->DiscardPendingEntry(); | 1623 controller()->DiscardPendingEntry(); |
| 1754 | 1624 |
| 1755 render_manager_.RendererAbortedProvisionalLoad(render_view_host); | 1625 render_manager_.RendererAbortedProvisionalLoad(render_view_host); |
| 1756 } | 1626 } |
| 1757 | 1627 |
| 1758 // Send out a notification that we failed a provisional load with an error. | 1628 // Send out a notification that we failed a provisional load with an error. |
| 1759 ProvisionalLoadDetails details( | 1629 ProvisionalLoadDetails details( |
| 1760 is_main_frame, | 1630 is_main_frame, |
| 1761 render_manager_.IsRenderViewInterstitial(render_view_host), | 1631 render_manager_.IsRenderViewInterstitial(render_view_host), |
| 1762 IsInPageNavigation(url), | 1632 controller()->IsURLInPageNavigation(url), |
| 1763 url, std::string()); | 1633 url, std::string()); |
| 1764 details.set_error_code(error_code); | 1634 details.set_error_code(error_code); |
| 1765 | 1635 |
| 1766 render_manager_.set_showing_repost_interstitial(showing_repost_interstitial); | 1636 render_manager_.set_showing_repost_interstitial(showing_repost_interstitial); |
| 1767 | 1637 |
| 1768 NotificationService::current()-> | 1638 NotificationService::current()-> |
| 1769 Notify(NOTIFY_FAIL_PROVISIONAL_LOAD_WITH_ERROR, | 1639 Notify(NOTIFY_FAIL_PROVISIONAL_LOAD_WITH_ERROR, |
| 1770 Source<NavigationController>(controller()), | 1640 Source<NavigationController>(controller()), |
| 1771 Details<ProvisionalLoadDetails>(&details)); | 1641 Details<ProvisionalLoadDetails>(&details)); |
| 1772 } | 1642 } |
| (...skipping 687 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2460 } | 2330 } |
| 2461 | 2331 |
| 2462 void WebContents::FileSelectionCanceled(void* params) { | 2332 void WebContents::FileSelectionCanceled(void* params) { |
| 2463 // If the user cancels choosing a file to upload we need to pass back the | 2333 // If the user cancels choosing a file to upload we need to pass back the |
| 2464 // empty string. | 2334 // empty string. |
| 2465 render_view_host()->FileSelected(std::wstring()); | 2335 render_view_host()->FileSelected(std::wstring()); |
| 2466 } | 2336 } |
| 2467 | 2337 |
| 2468 /////////////////////////////////////////////////////////////////////////////// | 2338 /////////////////////////////////////////////////////////////////////////////// |
| 2469 | 2339 |
| 2470 bool WebContents::IsInPageNavigation(const GURL& url) const { | |
| 2471 // We compare to the last committed entry and not the active entry as the | |
| 2472 // active entry is the current pending entry (if any). | |
| 2473 // When this method is called when a navigation initiated from the browser | |
| 2474 // (ex: when typing the URL in the location bar) is committed, the pending | |
| 2475 // entry URL is the same as |url|. | |
| 2476 NavigationEntry* entry = controller()->GetLastCommittedEntry(); | |
| 2477 return (entry && url.has_ref() && | |
| 2478 (url != entry->url()) && // Test for reload of a URL with a ref. | |
| 2479 GURLWithoutRef(entry->url()) == GURLWithoutRef(url)); | |
| 2480 } | |
| 2481 | |
| 2482 SkBitmap WebContents::GetFavIcon() { | 2340 SkBitmap WebContents::GetFavIcon() { |
| 2483 if (web_app_.get() && IsWebApplicationActive()) { | 2341 if (web_app_.get() && IsWebApplicationActive()) { |
| 2484 SkBitmap app_icon = web_app_->GetFavIcon(); | 2342 SkBitmap app_icon = web_app_->GetFavIcon(); |
| 2485 if (!app_icon.isNull()) | 2343 if (!app_icon.isNull()) |
| 2486 return app_icon; | 2344 return app_icon; |
| 2487 } | 2345 } |
| 2488 return TabContents::GetFavIcon(); | 2346 return TabContents::GetFavIcon(); |
| 2489 } | 2347 } |
| 2490 | 2348 |
| 2491 std::wstring WebContents::GetStatusText() const { | 2349 std::wstring WebContents::GetStatusText() const { |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2583 | 2441 |
| 2584 BOOL WebContents::EnumPluginWindowsCallback(HWND window, LPARAM) { | 2442 BOOL WebContents::EnumPluginWindowsCallback(HWND window, LPARAM) { |
| 2585 if (WebPluginDelegateImpl::IsPluginDelegateWindow(window)) { | 2443 if (WebPluginDelegateImpl::IsPluginDelegateWindow(window)) { |
| 2586 ::ShowWindow(window, SW_HIDE); | 2444 ::ShowWindow(window, SW_HIDE); |
| 2587 SetParent(window, NULL); | 2445 SetParent(window, NULL); |
| 2588 } | 2446 } |
| 2589 | 2447 |
| 2590 return TRUE; | 2448 return TRUE; |
| 2591 } | 2449 } |
| 2592 | 2450 |
| OLD | NEW |