OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/tabs/tab_strip_model.h" | 5 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
11 | 11 |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
14 #include "base/metrics/histogram_macros.h" | 14 #include "base/metrics/histogram_macros.h" |
15 #include "chrome/app/chrome_command_ids.h" | 15 #include "chrome/app/chrome_command_ids.h" |
16 #include "chrome/browser/browser_shutdown.h" | 16 #include "chrome/browser/browser_shutdown.h" |
17 #include "chrome/browser/defaults.h" | 17 #include "chrome/browser/defaults.h" |
18 #include "chrome/browser/extensions/tab_helper.h" | 18 #include "chrome/browser/extensions/tab_helper.h" |
19 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
20 #include "chrome/browser/ui/tab_contents/core_tab_helper.h" | 20 #include "chrome/browser/ui/tab_contents/core_tab_helper.h" |
21 #include "chrome/browser/ui/tab_contents/core_tab_helper_delegate.h" | 21 #include "chrome/browser/ui/tab_contents/core_tab_helper_delegate.h" |
22 #include "chrome/browser/ui/tabs/tab_strip_model_delegate.h" | 22 #include "chrome/browser/ui/tabs/tab_strip_model_delegate.h" |
23 #include "chrome/browser/ui/tabs/tab_strip_model_order_controller.h" | 23 #include "chrome/browser/ui/tabs/tab_strip_model_order_controller.h" |
24 #include "chrome/browser/ui/tabs/tab_utils.h" | 24 #include "chrome/browser/ui/tabs/tab_utils.h" |
25 #include "chrome/browser/ui/web_contents_sizer.h" | 25 #include "chrome/browser/ui/web_contents_sizer.h" |
26 #include "chrome/common/url_constants.h" | 26 #include "chrome/common/url_constants.h" |
27 #include "components/web_modal/web_contents_modal_dialog_manager.h" | 27 #include "components/web_modal/web_contents_modal_dialog_manager.h" |
| 28 #include "components/zoom/zoom_controller.h" |
28 #include "content/public/browser/render_process_host.h" | 29 #include "content/public/browser/render_process_host.h" |
29 #include "content/public/browser/user_metrics.h" | 30 #include "content/public/browser/user_metrics.h" |
30 #include "content/public/browser/web_contents.h" | 31 #include "content/public/browser/web_contents.h" |
31 #include "content/public/browser/web_contents_observer.h" | 32 #include "content/public/browser/web_contents_observer.h" |
32 using base::UserMetricsAction; | 33 using base::UserMetricsAction; |
33 using content::WebContents; | 34 using content::WebContents; |
34 | 35 |
35 namespace { | 36 namespace { |
36 | 37 |
37 // Returns true if the specified transition is one of the types that cause the | 38 // Returns true if the specified transition is one of the types that cause the |
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
335 WebContents* new_contents) { | 336 WebContents* new_contents) { |
336 delegate_->WillAddWebContents(new_contents); | 337 delegate_->WillAddWebContents(new_contents); |
337 | 338 |
338 DCHECK(ContainsIndex(index)); | 339 DCHECK(ContainsIndex(index)); |
339 WebContents* old_contents = GetWebContentsAtImpl(index); | 340 WebContents* old_contents = GetWebContentsAtImpl(index); |
340 | 341 |
341 FixOpenersAndGroupsReferencing(index); | 342 FixOpenersAndGroupsReferencing(index); |
342 | 343 |
343 contents_data_[index]->SetWebContents(new_contents); | 344 contents_data_[index]->SetWebContents(new_contents); |
344 | 345 |
| 346 // Notify the ZoomController of the replacement of its WebContents so that it |
| 347 // may clone any per-tab zoom information. |
| 348 zoom::ZoomController* zoom_controller = |
| 349 zoom::ZoomController::FromWebContents(old_contents); |
| 350 if (zoom_controller) |
| 351 zoom_controller->WebContentsReplaced(new_contents); |
| 352 |
345 for (auto& observer : observers_) | 353 for (auto& observer : observers_) |
346 observer.TabReplacedAt(this, old_contents, new_contents, index); | 354 observer.TabReplacedAt(this, old_contents, new_contents, index); |
347 | 355 |
348 // When the active WebContents is replaced send out a selection notification | 356 // When the active WebContents is replaced send out a selection notification |
349 // too. We do this as nearly all observers need to treat a replacement of the | 357 // too. We do this as nearly all observers need to treat a replacement of the |
350 // selected contents as the selection changing. | 358 // selected contents as the selection changing. |
351 if (active_index() == index) { | 359 if (active_index() == index) { |
352 for (auto& observer : observers_) | 360 for (auto& observer : observers_) |
353 observer.ActiveTabChanged(old_contents, new_contents, active_index(), | 361 observer.ActiveTabChanged(old_contents, new_contents, active_index(), |
354 TabStripModelObserver::CHANGE_REASON_REPLACED); | 362 TabStripModelObserver::CHANGE_REASON_REPLACED); |
(...skipping 1007 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1362 | 1370 |
1363 void TabStripModel::FixOpenersAndGroupsReferencing(int index) { | 1371 void TabStripModel::FixOpenersAndGroupsReferencing(int index) { |
1364 WebContents* old_contents = GetWebContentsAtImpl(index); | 1372 WebContents* old_contents = GetWebContentsAtImpl(index); |
1365 for (auto& data : contents_data_) { | 1373 for (auto& data : contents_data_) { |
1366 if (data->group() == old_contents) | 1374 if (data->group() == old_contents) |
1367 data->set_group(contents_data_[index]->group()); | 1375 data->set_group(contents_data_[index]->group()); |
1368 if (data->opener() == old_contents) | 1376 if (data->opener() == old_contents) |
1369 data->set_opener(contents_data_[index]->opener()); | 1377 data->set_opener(contents_data_[index]->opener()); |
1370 } | 1378 } |
1371 } | 1379 } |
OLD | NEW |