Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(180)

Side by Side Diff: chrome/browser/native_ui_contents.cc

Issue 479: DidNavigate refactor of doom (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 12 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/native_ui_contents.h" 5 #include "chrome/browser/native_ui_contents.h"
6 6
7 #include "chrome/browser/browser.h" 7 #include "chrome/browser/browser.h"
8 #include "chrome/browser/download_tab_view.h" 8 #include "chrome/browser/download_tab_view.h"
9 #include "chrome/browser/history_tab_ui.h" 9 #include "chrome/browser/history_tab_ui.h"
10 #include "chrome/browser/navigation_entry.h" 10 #include "chrome/browser/navigation_entry.h"
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 GetBounds(&r, false); 203 GetBounds(&r, false);
204 *out = r; 204 *out = r;
205 } 205 }
206 206
207 void NativeUIContents::SetPageState(PageState* page_state) { 207 void NativeUIContents::SetPageState(PageState* page_state) {
208 if (!page_state) 208 if (!page_state)
209 page_state = new PageState(); 209 page_state = new PageState();
210 state_.reset(page_state); 210 state_.reset(page_state);
211 NavigationController* ctrl = controller(); 211 NavigationController* ctrl = controller();
212 if (ctrl) { 212 if (ctrl) {
213 NavigationEntry* ne = ctrl->GetLastCommittedEntry(); 213 int ne_index = ctrl->GetLastCommittedEntryIndex();
214 NavigationEntry* ne = ctrl->GetEntryAtIndex(ne_index);
214 if (ne) { 215 if (ne) {
215 // NavigationEntry is null if we're being restored. 216 // NavigationEntry is null if we're being restored.
216 DCHECK(ne); 217 DCHECK(ne);
217 std::string rep; 218 std::string rep;
218 state_->GetByteRepresentation(&rep); 219 state_->GetByteRepresentation(&rep);
219 ne->set_content_state(rep); 220 ne->set_content_state(rep);
220 // This is not a WebContents, so we use a NULL SiteInstance. 221 ctrl->NotifyEntryChanged(ne, ne_index);
221 ctrl->NotifyEntryChangedByPageID(type(), NULL, ne->page_id());
222 } 222 }
223 } 223 }
224 } 224 }
225 225
226 bool NativeUIContents::Navigate(const NavigationEntry& entry, bool reload) { 226 bool NativeUIContents::NavigateToPendingEntry(bool reload) {
227 ChromeViews::RootView* root_view = GetRootView(); 227 ChromeViews::RootView* root_view = GetRootView();
228 DCHECK(root_view); 228 DCHECK(root_view);
229 229
230 if (current_ui_) { 230 if (current_ui_) {
231 current_ui_->WillBecomeInvisible(this); 231 current_ui_->WillBecomeInvisible(this);
232 root_view->RemoveChildView(current_view_); 232 root_view->RemoveChildView(current_view_);
233 current_ui_ = NULL; 233 current_ui_ = NULL;
234 current_view_ = NULL; 234 current_view_ = NULL;
235 } 235 }
236 236
237 NativeUI* new_ui = GetNativeUIForURL(entry.url()); 237 NavigationEntry* pending_entry = controller()->GetPendingEntry();
238 NativeUI* new_ui = GetNativeUIForURL(pending_entry->url());
238 if (new_ui) { 239 if (new_ui) {
239 current_ui_ = new_ui; 240 current_ui_ = new_ui;
240 is_visible_ = true; 241 is_visible_ = true;
241 current_ui_->WillBecomeVisible(this); 242 current_ui_->WillBecomeVisible(this);
242 current_view_ = new_ui->GetView(); 243 current_view_ = new_ui->GetView();
243 root_view->AddChildView(current_view_); 244 root_view->AddChildView(current_view_);
244 245
245 std::string s = entry.content_state(); 246 std::string s = pending_entry->content_state();
246 if (s.empty()) 247 if (s.empty())
247 state_->InitWithURL(entry.url()); 248 state_->InitWithURL(pending_entry->url());
248 else 249 else
249 state_->InitWithBytes(s); 250 state_->InitWithBytes(s);
250 251
251 current_ui_->Navigate(*state_); 252 current_ui_->Navigate(*state_);
252 Layout(); 253 Layout();
253 } 254 }
254 255
255 NavigationEntry* new_entry = new NavigationEntry(entry); 256 // Commit the new load in the navigation controller. If the ID of the
256 if (new_entry->page_id() == -1) 257 // NavigationEntry we were given was -1, that means this is a new load, so
257 new_entry->set_page_id(++g_next_page_id); 258 // we have to generate a new ID.
258 new_entry->set_title(GetDefaultTitle()); 259 controller()->CommitPendingEntry();
259 new_entry->favicon().set_bitmap(GetFavIcon()); 260
260 new_entry->favicon().set_is_valid(true); 261 // Populate the committed entry.
262 NavigationEntry* committed_entry = controller()->GetLastCommittedEntry();
263 committed_entry->set_title(GetDefaultTitle());
264 committed_entry->favicon().set_bitmap(GetFavIcon());
265 committed_entry->favicon().set_is_valid(true);
261 if (new_ui) { 266 if (new_ui) {
262 // Strip out the query params, they should have moved to state. 267 // Strip out the query params, they should have moved to state.
263 // TODO(sky): use GURL methods for replacements once bug is fixed. 268 // TODO(sky): use GURL methods for replacements once bug is fixed.
264 size_t scheme_end, host_end; 269 size_t scheme_end, host_end;
265 GetSchemeAndHostEnd(entry.url(), &scheme_end, &host_end); 270 GetSchemeAndHostEnd(committed_entry->url(), &scheme_end, &host_end);
266 new_entry->set_url(GURL(entry.url().spec().substr(0, host_end))); 271 committed_entry->set_url(
272 GURL(committed_entry->url().spec().substr(0, host_end)));
267 } 273 }
268 std::string content_state; 274 std::string content_state;
269 state_->GetByteRepresentation(&content_state); 275 state_->GetByteRepresentation(&content_state);
270 new_entry->set_content_state(content_state); 276 committed_entry->set_content_state(content_state);
271 const int32 page_id = new_entry->page_id();
272 277
273 // The default details is "new navigation", and that's OK with us. 278 // Broadcast the fact that we just updated all that crap.
274 NavigationController::LoadCommittedDetails details; 279 controller()->NotifyEntryChanged(
275 DidNavigateToEntry(new_entry, &details); 280 committed_entry,
276 // This is not a WebContents, so we use a NULL SiteInstance. 281 controller()->GetIndexOfEntry(committed_entry));
277 controller()->NotifyEntryChangedByPageID(type(), NULL, page_id);
278 return true; 282 return true;
279 } 283 }
280 284
281 void NativeUIContents::Layout() { 285 void NativeUIContents::Layout() {
282 if (current_view_) { 286 if (current_view_) {
283 ChromeViews::RootView* root_view = GetRootView(); 287 ChromeViews::RootView* root_view = GetRootView();
284 current_view_->SetBounds(0, 0, root_view->GetWidth(), 288 current_view_->SetBounds(0, 0, root_view->GetWidth(),
285 root_view->GetHeight()); 289 root_view->GetHeight());
286 current_view_->Layout(); 290 current_view_->Layout();
287 } 291 }
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after
662 DoSearch(); 666 DoSearch();
663 } 667 }
664 668
665 void SearchableUIContainer::DoSearch() { 669 void SearchableUIContainer::DoSearch() {
666 if (delegate_) 670 if (delegate_)
667 delegate_->DoSearch(search_field_->GetText()); 671 delegate_->DoSearch(search_field_->GetText());
668 672
669 scroll_view_->ScrollToPosition(scroll_view_->vertical_scroll_bar(), 0); 673 scroll_view_->ScrollToPosition(scroll_view_->vertical_scroll_bar(), 0);
670 } 674 }
671 675
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698