OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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/ui/browser.h" | 5 #include "chrome/browser/ui/browser.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <string> | 10 #include <string> |
(...skipping 1022 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1033 window_->GetLocationBar()->SaveStateToContents(contents); | 1033 window_->GetLocationBar()->SaveStateToContents(contents); |
1034 | 1034 |
1035 if (instant_controller_) | 1035 if (instant_controller_) |
1036 instant_controller_->TabDeactivated(contents); | 1036 instant_controller_->TabDeactivated(contents); |
1037 } | 1037 } |
1038 | 1038 |
1039 void Browser::ActiveTabChanged(WebContents* old_contents, | 1039 void Browser::ActiveTabChanged(WebContents* old_contents, |
1040 WebContents* new_contents, | 1040 WebContents* new_contents, |
1041 int index, | 1041 int index, |
1042 int reason) { | 1042 int reason) { |
| 1043 // Copies the background color from an old WebContents to a new one that |
| 1044 // replaces it on the screen. This allows the new WebContents to use the |
| 1045 // old one's background color as the starting background color, before having |
| 1046 // loaded any contents. As a result, we avoid flashing white when moving to |
| 1047 // a new tab. (There is also code in RenderFrameHostManager to do something |
| 1048 // similar for intra-tab navigations.) |
| 1049 if (old_contents && new_contents) { |
| 1050 // While GetMainFrame() is guaranteed to return non-null, GetView() is not, |
| 1051 // e.g. between WebContents creation and creation of the |
| 1052 // RenderWidgetHostView. |
| 1053 RenderWidgetHostView* old_view = old_contents->GetMainFrame()->GetView(); |
| 1054 RenderWidgetHostView* new_view = new_contents->GetMainFrame()->GetView(); |
| 1055 if (old_view && new_view) |
| 1056 new_view->SetBackgroundColor(old_view->background_color()); |
| 1057 } |
| 1058 |
1043 content::RecordAction(UserMetricsAction("ActiveTabChanged")); | 1059 content::RecordAction(UserMetricsAction("ActiveTabChanged")); |
1044 | 1060 |
1045 // Update the bookmark state, since the BrowserWindow may query it during | 1061 // Update the bookmark state, since the BrowserWindow may query it during |
1046 // OnActiveTabChanged() below. | 1062 // OnActiveTabChanged() below. |
1047 UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_SWITCH); | 1063 UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_SWITCH); |
1048 | 1064 |
1049 // Let the BrowserWindow do its handling. On e.g. views this changes the | 1065 // Let the BrowserWindow do its handling. On e.g. views this changes the |
1050 // focused object, which should happen before we update the toolbar below, | 1066 // focused object, which should happen before we update the toolbar below, |
1051 // since the omnibox expects the correct element to already be focused when it | 1067 // since the omnibox expects the correct element to already be focused when it |
1052 // is updated. | 1068 // is updated. |
(...skipping 1609 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2662 // new window later, thus we need to navigate the window now. | 2678 // new window later, thus we need to navigate the window now. |
2663 if (contents) { | 2679 if (contents) { |
2664 contents->web_contents()->GetController().LoadURL( | 2680 contents->web_contents()->GetController().LoadURL( |
2665 target_url, content::Referrer(), ui::PAGE_TRANSITION_LINK, | 2681 target_url, content::Referrer(), ui::PAGE_TRANSITION_LINK, |
2666 std::string()); // No extra headers. | 2682 std::string()); // No extra headers. |
2667 } | 2683 } |
2668 } | 2684 } |
2669 | 2685 |
2670 return contents != NULL; | 2686 return contents != NULL; |
2671 } | 2687 } |
OLD | NEW |