OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/page_load_metrics/metrics_web_contents_observer.h" | 5 #include "chrome/browser/page_load_metrics/metrics_web_contents_observer.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <ostream> | 8 #include <ostream> |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 } | 171 } |
172 | 172 |
173 if (!ShouldTrackNavigation(navigation_handle)) | 173 if (!ShouldTrackNavigation(navigation_handle)) |
174 return; | 174 return; |
175 | 175 |
176 // Pass in the last committed url to the PageLoadTracker. If the MWCO has | 176 // Pass in the last committed url to the PageLoadTracker. If the MWCO has |
177 // never observed a committed load, use the last committed url from this | 177 // never observed a committed load, use the last committed url from this |
178 // WebContent's opener. This is more accurate than using referrers due to | 178 // WebContent's opener. This is more accurate than using referrers due to |
179 // referrer sanitizing and origin referrers. Note that this could potentially | 179 // referrer sanitizing and origin referrers. Note that this could potentially |
180 // be inaccurate if the opener has since navigated. | 180 // be inaccurate if the opener has since navigated. |
181 content::WebContents* opener = web_contents()->GetOpener(); | 181 content::RenderFrameHost* opener = web_contents()->GetOpener(); |
182 const GURL& opener_url = | 182 const GURL& opener_url = !has_navigated_ && opener |
183 !has_navigated_ && opener | 183 ? opener->GetLastCommittedURL() |
184 ? web_contents()->GetOpener()->GetLastCommittedURL() | 184 : GURL::EmptyGURL(); |
185 : GURL::EmptyGURL(); | |
186 const GURL& currently_committed_url = | 185 const GURL& currently_committed_url = |
187 committed_load_ ? committed_load_->url() : opener_url; | 186 committed_load_ ? committed_load_->url() : opener_url; |
188 has_navigated_ = true; | 187 has_navigated_ = true; |
189 | 188 |
190 // We can have two provisional loads in some cases. E.g. a same-site | 189 // We can have two provisional loads in some cases. E.g. a same-site |
191 // navigation can have a concurrent cross-process navigation started | 190 // navigation can have a concurrent cross-process navigation started |
192 // from the omnibox. | 191 // from the omnibox. |
193 DCHECK_GT(2ul, provisional_loads_.size()); | 192 DCHECK_GT(2ul, provisional_loads_.size()); |
194 // Passing raw pointers to observers_ and embedder_interface_ is safe because | 193 // Passing raw pointers to observers_ and embedder_interface_ is safe because |
195 // the MetricsWebContentsObserver owns them both list and they are torn down | 194 // the MetricsWebContentsObserver owns them both list and they are torn down |
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
642 observer_->RemoveTestingObserver(this); | 641 observer_->RemoveTestingObserver(this); |
643 observer_ = nullptr; | 642 observer_ = nullptr; |
644 } | 643 } |
645 } | 644 } |
646 | 645 |
647 void MetricsWebContentsObserver::TestingObserver::OnGoingAway() { | 646 void MetricsWebContentsObserver::TestingObserver::OnGoingAway() { |
648 observer_ = nullptr; | 647 observer_ = nullptr; |
649 } | 648 } |
650 | 649 |
651 } // namespace page_load_metrics | 650 } // namespace page_load_metrics |
OLD | NEW |