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

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

Issue 12413028: Add elevation to the managed mode navigation observer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Automatically reset tab elevation when navigating the frame to a non-special URL. Created 7 years, 9 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 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 RemoveTemporaryException(); 256 RemoveTemporaryException();
257 } 257 }
258 258
259 ManagedModeNavigationObserver::ManagedModeNavigationObserver( 259 ManagedModeNavigationObserver::ManagedModeNavigationObserver(
260 content::WebContents* web_contents) 260 content::WebContents* web_contents)
261 : WebContentsObserver(web_contents), 261 : WebContentsObserver(web_contents),
262 warn_infobar_delegate_(NULL), 262 warn_infobar_delegate_(NULL),
263 preview_infobar_delegate_(NULL), 263 preview_infobar_delegate_(NULL),
264 got_user_gesture_(false), 264 got_user_gesture_(false),
265 state_(RECORDING_URLS_BEFORE_PREVIEW), 265 state_(RECORDING_URLS_BEFORE_PREVIEW),
266 is_elevated_(false),
266 last_allowed_page_(-1) { 267 last_allowed_page_(-1) {
267 Profile* profile = 268 Profile* profile =
268 Profile::FromBrowserContext(web_contents->GetBrowserContext()); 269 Profile::FromBrowserContext(web_contents->GetBrowserContext());
269 managed_user_service_ = ManagedUserServiceFactory::GetForProfile(profile); 270 managed_user_service_ = ManagedUserServiceFactory::GetForProfile(profile);
271 if (!managed_user_service_->ProfileIsManaged())
272 is_elevated_ = true;
270 url_filter_ = managed_user_service_->GetURLFilterForUIThread(); 273 url_filter_ = managed_user_service_->GetURLFilterForUIThread();
271 } 274 }
272 275
273 void ManagedModeNavigationObserver::AddTemporaryException() { 276 void ManagedModeNavigationObserver::AddTemporaryException() {
274 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 277 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
275 DCHECK(web_contents()); 278 DCHECK(web_contents());
276 279
277 BrowserThread::PostTask( 280 BrowserThread::PostTask(
278 BrowserThread::IO, 281 BrowserThread::IO,
279 FROM_HERE, 282 FROM_HERE,
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 urls, ManagedUserService::MANUAL_ALLOW); 337 urls, ManagedUserService::MANUAL_ALLOW);
335 if (last_url_.is_valid()) { 338 if (last_url_.is_valid()) {
336 std::vector<std::string> hosts; 339 std::vector<std::string> hosts;
337 hosts.push_back(last_url_.host()); 340 hosts.push_back(last_url_.host());
338 managed_user_service_->SetManualBehaviorForHosts( 341 managed_user_service_->SetManualBehaviorForHosts(
339 hosts, ManagedUserService::MANUAL_ALLOW); 342 hosts, ManagedUserService::MANUAL_ALLOW);
340 } 343 }
341 ClearObserverState(); 344 ClearObserverState();
342 } 345 }
343 346
347 bool ManagedModeNavigationObserver::is_elevated() const {
348 return is_elevated_;
349 }
350
351 void ManagedModeNavigationObserver::set_elevated(bool is_elevated) {
352 is_elevated_ = is_elevated;
353 }
354
344 void ManagedModeNavigationObserver::AddURLToPatternList(const GURL& url) { 355 void ManagedModeNavigationObserver::AddURLToPatternList(const GURL& url) {
345 navigated_urls_.insert(url); 356 navigated_urls_.insert(url);
346 last_url_ = url; 357 last_url_ = url;
347 } 358 }
348 359
349 void ManagedModeNavigationObserver::SetStateToRecordingAfterPreview() { 360 void ManagedModeNavigationObserver::SetStateToRecordingAfterPreview() {
350 state_ = RECORDING_URLS_AFTER_PREVIEW; 361 state_ = RECORDING_URLS_AFTER_PREVIEW;
351 } 362 }
352 363
353 bool ManagedModeNavigationObserver::CanTemporarilyNavigateHost( 364 bool ManagedModeNavigationObserver::CanTemporarilyNavigateHost(
354 const GURL& url) { 365 const GURL& url) {
355 return last_url_.host() == url.host(); 366 return last_url_.host() == url.host();
356 } 367 }
357 368
369 namespace {
370 const char kChromeWebstoreURL[] = "chrome.google.com/webstore/";
Bernhard Bauer 2013/03/21 15:52:58 1. Move constant declarations to the top of the fi
Adrian Kuegel 2013/03/21 16:30:04 1. Done 2. Still some reviewers (for example Joche
Bernhard Bauer 2013/03/22 09:24:28 Meh. My take on this: if there is nothing else tha
Adrian Kuegel 2013/03/22 09:46:21 Ok, I am using this constant now.
371 }
372
373 bool ManagedModeNavigationObserver::WillStayElevatedForURL(
374 const GURL& navigation_url) {
375 // chrome:// URLs have chrome as a host type in the GURL. But all
376 // chrome URLs in url_constants.h are specified with a chrome:// prefix.
377 // Therefore we insert a ":/" between host and path for the chrome:// URLs.
378 std::string url =
379 navigation_url.host() +
380 (navigation_url.host() == "chrome" ? ":/" : "") +
381 navigation_url.path();
Bernhard Bauer 2013/03/21 15:52:58 Sorry, I don't understand this. I'm also thinking
Adrian Kuegel 2013/03/21 16:30:04 True, I can use the host. Thanks for the tip :)
382
383 // Check if any of the special urls is a prefix of url. This is the case if
384 // the special url occurs at position 0 as a substring of url.
Bernhard Bauer 2013/03/21 15:52:58 base/string_util.h declares StartsWith() methods.
Adrian Kuegel 2013/03/21 16:30:04 Ok, I used that instead. It is probably easier to
385 return url.find(kChromeWebstoreURL) == 0 ||
386 url.find(chrome::kChromeUIHistoryURL) == 0 ||
387 url.find(chrome::kChromeUIHistoryFrameURL) == 0 ||
Bernhard Bauer 2013/03/21 15:52:58 If we only call this method for main frames, why d
Adrian Kuegel 2013/03/21 16:30:04 A user could enter the subframe URL manually. But
388 url.find(chrome::kChromeUIExtensionsURL) == 0 ||
389 url.find(chrome::kChromeUIExtensionsFrameURL) == 0 ||
390 url.find(chrome::kChromeUISettingsURL) == 0 ||
391 url.find(chrome::kChromeUISettingsFrameURL) == 0;
392 }
393
358 void ManagedModeNavigationObserver::ClearObserverState() { 394 void ManagedModeNavigationObserver::ClearObserverState() {
359 if (preview_infobar_delegate_) { 395 if (preview_infobar_delegate_) {
360 InfoBarService* infobar_service = 396 InfoBarService* infobar_service =
361 InfoBarService::FromWebContents(web_contents()); 397 InfoBarService::FromWebContents(web_contents());
362 infobar_service->RemoveInfoBar(preview_infobar_delegate_); 398 infobar_service->RemoveInfoBar(preview_infobar_delegate_);
363 preview_infobar_delegate_ = NULL; 399 preview_infobar_delegate_ = NULL;
364 } 400 }
365 navigated_urls_.clear(); 401 navigated_urls_.clear();
366 last_url_ = GURL(); 402 last_url_ = GURL();
367 state_ = RECORDING_URLS_BEFORE_PREVIEW; 403 state_ = RECORDING_URLS_BEFORE_PREVIEW;
(...skipping 12 matching lines...) Expand all
380 // back to a blocked site here. 416 // back to a blocked site here.
381 if (web_contents()->GetController().GetCurrentEntryIndex() < 417 if (web_contents()->GetController().GetCurrentEntryIndex() <
382 last_allowed_page_) { 418 last_allowed_page_) {
383 ClearObserverState(); 419 ClearObserverState();
384 } 420 }
385 } 421 }
386 422
387 void ManagedModeNavigationObserver::DidNavigateMainFrame( 423 void ManagedModeNavigationObserver::DidNavigateMainFrame(
388 const content::LoadCommittedDetails& details, 424 const content::LoadCommittedDetails& details,
389 const content::FrameNavigateParams& params) { 425 const content::FrameNavigateParams& params) {
426 if (!WillStayElevatedForURL(params.url))
427 is_elevated_ = false;
390 428
391 content::RecordAction(UserMetricsAction("ManagedMode_MainFrameNavigation")); 429 content::RecordAction(UserMetricsAction("ManagedMode_MainFrameNavigation"));
392 430
393 ManagedModeURLFilter::FilteringBehavior behavior = 431 ManagedModeURLFilter::FilteringBehavior behavior =
394 url_filter_->GetFilteringBehaviorForURL(params.url); 432 url_filter_->GetFilteringBehaviorForURL(params.url);
395 433
396 UMA_HISTOGRAM_ENUMERATION("ManagedMode.FilteringBehavior", 434 UMA_HISTOGRAM_ENUMERATION("ManagedMode.FilteringBehavior",
397 behavior, 435 behavior,
398 ManagedModeURLFilter::HISTOGRAM_BOUNDING_VALUE); 436 ManagedModeURLFilter::HISTOGRAM_BOUNDING_VALUE);
399 437
(...skipping 23 matching lines...) Expand all
423 // so don't update the state yet. 461 // so don't update the state yet.
424 if (state_ == RECORDING_URLS_AFTER_PREVIEW) { 462 if (state_ == RECORDING_URLS_AFTER_PREVIEW) {
425 AddTemporaryException(); 463 AddTemporaryException();
426 } 464 }
427 465
428 // The navigation is complete, unless there is a redirect. So set the 466 // The navigation is complete, unless there is a redirect. So set the
429 // new navigation to false to detect user interaction. 467 // new navigation to false to detect user interaction.
430 got_user_gesture_ = false; 468 got_user_gesture_ = false;
431 } 469 }
432 470
433 void ManagedModeNavigationObserver::DidStartProvisionalLoadForFrame( 471 void ManagedModeNavigationObserver::DidStartProvisionalLoadForFrame(
Bernhard Bauer 2013/03/21 15:52:58 We can actually remove the whole method if we're n
Adrian Kuegel 2013/03/21 16:30:04 That is what I thought, too, but I thought maybe S
434 int64 frame_id, 472 int64 frame_id,
435 int64 parent_frame_id, 473 int64 parent_frame_id,
436 bool is_main_frame, 474 bool is_main_frame,
437 const GURL& validated_url, 475 const GURL& validated_url,
438 bool is_error_page, 476 bool is_error_page,
439 bool is_iframe_srcdoc, 477 bool is_iframe_srcdoc,
440 content::RenderViewHost* render_view_host) { 478 content::RenderViewHost* render_view_host) {
441 if (!is_main_frame)
442 return;
443 } 479 }
444 480
445 void ManagedModeNavigationObserver::ProvisionalChangeToMainFrameUrl( 481 void ManagedModeNavigationObserver::ProvisionalChangeToMainFrameUrl(
446 const GURL& url, 482 const GURL& url,
447 content::RenderViewHost* render_view_host) { 483 content::RenderViewHost* render_view_host) {
484 if (!WillStayElevatedForURL(url))
Bernhard Bauer 2013/03/21 15:52:58 Do we actually need both of these checks?
Adrian Kuegel 2013/03/21 16:30:04 Yes. There are two cases: we do a real navigation,
485 is_elevated_ = false;
486
448 // This function is the last one to be called before the resource throttle 487 // This function is the last one to be called before the resource throttle
449 // shows the interstitial if the URL must be blocked. 488 // shows the interstitial if the URL must be blocked.
450 DVLOG(1) << "ProvisionalChangeToMainFrameURL " << url.spec(); 489 DVLOG(1) << "ProvisionalChangeToMainFrameURL " << url.spec();
451 ManagedModeURLFilter::FilteringBehavior behavior = 490 ManagedModeURLFilter::FilteringBehavior behavior =
452 url_filter_->GetFilteringBehaviorForURL(url); 491 url_filter_->GetFilteringBehaviorForURL(url);
453 492
454 if (behavior != ManagedModeURLFilter::BLOCK) 493 if (behavior != ManagedModeURLFilter::BLOCK)
455 return; 494 return;
456 495
457 if (state_ == RECORDING_URLS_AFTER_PREVIEW && got_user_gesture_ && 496 if (state_ == RECORDING_URLS_AFTER_PREVIEW && got_user_gesture_ &&
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 if (behavior == ManagedModeURLFilter::ALLOW) 543 if (behavior == ManagedModeURLFilter::ALLOW)
505 last_allowed_page_ = web_contents()->GetController().GetCurrentEntryIndex(); 544 last_allowed_page_ = web_contents()->GetController().GetCurrentEntryIndex();
506 } 545 }
507 546
508 void ManagedModeNavigationObserver::DidGetUserGesture() { 547 void ManagedModeNavigationObserver::DidGetUserGesture() {
509 got_user_gesture_ = true; 548 got_user_gesture_ = true;
510 // Update the exception status so that the resource throttle knows that 549 // Update the exception status so that the resource throttle knows that
511 // there was a manual navigation. 550 // there was a manual navigation.
512 UpdateExceptionNavigationStatus(); 551 UpdateExceptionNavigationStatus();
513 } 552 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698