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

Side by Side Diff: chrome/browser/managed_mode/managed_mode_navigation_observer.cc

Issue 14518005: Add TabWebContentsTracker (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 8 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) 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/managed_mode/managed_mode_navigation_observer.h" 5 #include "chrome/browser/managed_mode/managed_mode_navigation_observer.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/i18n/rtl.h" 8 #include "base/i18n/rtl.h"
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "base/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 ManagedModeNavigationObserver* observer = 249 ManagedModeNavigationObserver* observer =
250 ManagedModeNavigationObserver::FromWebContents(web_contents()); 250 ManagedModeNavigationObserver::FromWebContents(web_contents());
251 observer->PreviewInfobarDismissed(); 251 observer->PreviewInfobarDismissed();
252 } 252 }
253 253
254 } // namespace 254 } // namespace
255 255
256 DEFINE_WEB_CONTENTS_USER_DATA_KEY(ManagedModeNavigationObserver); 256 DEFINE_WEB_CONTENTS_USER_DATA_KEY(ManagedModeNavigationObserver);
257 257
258 ManagedModeNavigationObserver::~ManagedModeNavigationObserver() { 258 ManagedModeNavigationObserver::~ManagedModeNavigationObserver() {
259 TabWebContentsTracker::RemoveObserver(this);
259 RemoveTemporaryException(); 260 RemoveTemporaryException();
260 } 261 }
261 262
262 ManagedModeNavigationObserver::ManagedModeNavigationObserver( 263 ManagedModeNavigationObserver::ManagedModeNavigationObserver(
263 content::WebContents* web_contents) 264 content::WebContents* web_contents)
264 : WebContentsObserver(web_contents), 265 : WebContentsObserver(web_contents),
265 warn_infobar_delegate_(NULL), 266 warn_infobar_delegate_(NULL),
266 preview_infobar_delegate_(NULL), 267 preview_infobar_delegate_(NULL),
267 state_(RECORDING_URLS_BEFORE_PREVIEW), 268 state_(RECORDING_URLS_BEFORE_PREVIEW),
268 is_elevated_(false), 269 is_elevated_(false),
269 last_allowed_page_(-1), 270 last_allowed_page_(-1),
271 observer_state_cleared_(false),
270 finished_redirects_(false) { 272 finished_redirects_(false) {
271 Profile* profile = 273 Profile* profile =
272 Profile::FromBrowserContext(web_contents->GetBrowserContext()); 274 Profile::FromBrowserContext(web_contents->GetBrowserContext());
273 managed_user_service_ = ManagedUserServiceFactory::GetForProfile(profile); 275 managed_user_service_ = ManagedUserServiceFactory::GetForProfile(profile);
274 if (!managed_user_service_->ProfileIsManaged()) 276 if (!managed_user_service_->ProfileIsManaged())
275 is_elevated_ = true; 277 is_elevated_ = true;
276 url_filter_ = managed_user_service_->GetURLFilterForUIThread(); 278 url_filter_ = managed_user_service_->GetURLFilterForUIThread();
279 TabWebContentsTracker::AddObserver(this);
280 }
281
282 void ManagedModeNavigationObserver::OnTabReplacedAt(
283 TabStripModel* tab_strip_model,
284 content::WebContents* old_contents,
285 content::WebContents* new_contents,
286 int index) {
287 if (new_contents == web_contents()) {
Bernhard Bauer 2013/04/26 16:30:10 Early-return otherwise?
288 // First, copy over some data of the old navigation observer. This only
Bernhard Bauer 2013/04/26 16:30:10 This seems...brittle. I'm okay with it, but I coul
Adrian Kuegel 2013/04/29 08:11:15 But if I copy the whole object over, it would stil
Bernhard Bauer 2013/04/29 08:39:38 Like I said, I'm okay with this, I just want to ke
289 // applies if the ClearObserverState function was not called on the new
Adrian Kuegel 2013/04/26 15:52:27 Reassigning the ManagedModeNavigationObserver to a
290 // navigation observer, because that would reset the data we are about to
291 // copy.
292 if (!observer_state_cleared_) {
293 ManagedModeNavigationObserver* observer =
294 ManagedModeNavigationObserver::FromWebContents(old_contents);
295 navigated_urls_.insert(observer->navigated_urls_.begin(),
296 observer->navigated_urls_.end());
297 if (last_allowed_page_ < 0)
298 last_allowed_page_ = observer->last_allowed_page_;
299 if (observer->warn_infobar_delegate_ && !warn_infobar_delegate_) {
300 warn_infobar_delegate_ = ManagedModeWarningInfobarDelegate::Create(
301 InfoBarService::FromWebContents(web_contents()),
302 last_allowed_page_);
303 }
304 if (observer->preview_infobar_delegate_ && !preview_infobar_delegate_) {
305 preview_infobar_delegate_ = ManagedModePreviewInfobarDelegate::Create(
Bernhard Bauer 2013/04/26 16:30:10 Doesn't InfobarTabHelper or something similar take
Adrian Kuegel 2013/04/29 08:11:15 Yes, that is possible. I guess I can remove that c
306 InfoBarService::FromWebContents(web_contents()));
307 }
308 // We don't need to copy |state_| and |finished_redirects_|, because that
309 // should be up-to-date.
310 }
311 }
277 } 312 }
278 313
279 void ManagedModeNavigationObserver::AddTemporaryException() { 314 void ManagedModeNavigationObserver::AddTemporaryException() {
280 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 315 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
281 DCHECK(web_contents()); 316 DCHECK(web_contents());
282 317
283 BrowserThread::PostTask( 318 BrowserThread::PostTask(
284 BrowserThread::IO, 319 BrowserThread::IO,
285 FROM_HERE, 320 FROM_HERE,
286 base::Bind(&ManagedModeResourceThrottle::AddTemporaryException, 321 base::Bind(&ManagedModeResourceThrottle::AddTemporaryException,
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 StartsWithASCII(url, extension_urls::kGalleryBrowsePrefix, false); 415 StartsWithASCII(url, extension_urls::kGalleryBrowsePrefix, false);
381 } 416 }
382 417
383 void ManagedModeNavigationObserver::ClearObserverState() { 418 void ManagedModeNavigationObserver::ClearObserverState() {
384 if (preview_infobar_delegate_) { 419 if (preview_infobar_delegate_) {
385 InfoBarService* infobar_service = 420 InfoBarService* infobar_service =
386 InfoBarService::FromWebContents(web_contents()); 421 InfoBarService::FromWebContents(web_contents());
387 infobar_service->RemoveInfoBar(preview_infobar_delegate_); 422 infobar_service->RemoveInfoBar(preview_infobar_delegate_);
388 preview_infobar_delegate_ = NULL; 423 preview_infobar_delegate_ = NULL;
389 } 424 }
425 observer_state_cleared_ = true;
Bernhard Bauer 2013/04/26 16:30:10 So you set this to true when we have cleared obser
Adrian Kuegel 2013/04/29 08:11:15 Yes, but that is exactly as expected. This variabl
390 navigated_urls_.clear(); 426 navigated_urls_.clear();
391 last_url_ = GURL(); 427 last_url_ = GURL();
392 state_ = RECORDING_URLS_BEFORE_PREVIEW; 428 state_ = RECORDING_URLS_BEFORE_PREVIEW;
393 // TODO(sergiu): Remove these logging calls once this is stable. 429 // TODO(sergiu): Remove these logging calls once this is stable.
394 DVLOG(1) << "Clearing observer state"; 430 DVLOG(1) << "Clearing observer state";
395 RemoveTemporaryException(); 431 RemoveTemporaryException();
396 } 432 }
397 433
398 void ManagedModeNavigationObserver::NavigateToPendingEntry( 434 void ManagedModeNavigationObserver::NavigateToPendingEntry(
399 const GURL& url, 435 const GURL& url,
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
567 HistoryService* history_service = 603 HistoryService* history_service =
568 HistoryServiceFactory::GetForProfile(profile, Profile::IMPLICIT_ACCESS); 604 HistoryServiceFactory::GetForProfile(profile, Profile::IMPLICIT_ACCESS);
569 605
570 // |history_service| is null if saving history is disabled. 606 // |history_service| is null if saving history is disabled.
571 if (history_service) 607 if (history_service)
572 history_service->AddPage(add_page_args); 608 history_service->AddPage(add_page_args);
573 609
574 // Show the interstitial. 610 // Show the interstitial.
575 new ManagedModeInterstitial(web_contents, url, callback); 611 new ManagedModeInterstitial(web_contents, url, callback);
576 } 612 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698