Chromium Code Reviews| 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 #import "ios/chrome/browser/tabs/tab.h" | 5 #import "ios/chrome/browser/tabs/tab.h" |
| 6 | 6 |
| 7 #import <CoreLocation/CoreLocation.h> | 7 #import <CoreLocation/CoreLocation.h> |
| 8 #import <UIKit/UIKit.h> | 8 #import <UIKit/UIKit.h> |
| 9 | 9 |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 365 | 365 |
| 366 // Handles exportable files if possible. | 366 // Handles exportable files if possible. |
| 367 - (void)handleExportableFile:(net::HttpResponseHeaders*)headers; | 367 - (void)handleExportableFile:(net::HttpResponseHeaders*)headers; |
| 368 | 368 |
| 369 // Called after the session history is replaced, useful for updating members | 369 // Called after the session history is replaced, useful for updating members |
| 370 // with new sessionID. | 370 // with new sessionID. |
| 371 - (void)didReplaceSessionHistory; | 371 - (void)didReplaceSessionHistory; |
| 372 | 372 |
| 373 // Called when the UIApplication's state becomes active. | 373 // Called when the UIApplication's state becomes active. |
| 374 - (void)applicationDidBecomeActive; | 374 - (void)applicationDidBecomeActive; |
| 375 | |
| 376 // Returns YES if popups requested by a page with |URL| should be blocked. | |
| 377 - (BOOL)shouldBlockPopupForPageWithURL:(const GURL&)URL; | |
| 378 | |
| 379 // Blocks popup for page with |popupURL|, requested by the page with | |
| 380 // |openerURL|. | |
| 381 - (void)blockPopupForURL:(const GURL&)popupURL openerURL:(const GURL&)openerURL; | |
| 382 | |
| 375 @end | 383 @end |
| 376 | 384 |
| 377 namespace { | 385 namespace { |
| 378 // TabHistoryContext is used by history to scope the lifetime of navigation | 386 // TabHistoryContext is used by history to scope the lifetime of navigation |
| 379 // entry references to Tab. | 387 // entry references to Tab. |
| 380 class TabHistoryContext : public history::Context { | 388 class TabHistoryContext : public history::Context { |
| 381 public: | 389 public: |
| 382 TabHistoryContext() {} | 390 TabHistoryContext() {} |
| 383 ~TabHistoryContext() {} | 391 ~TabHistoryContext() {} |
| 384 | 392 |
| (...skipping 1071 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1456 if (requireReloadAfterBecomingActive_) { | 1464 if (requireReloadAfterBecomingActive_) { |
| 1457 if (visible_) { | 1465 if (visible_) { |
| 1458 [self.webController reload]; | 1466 [self.webController reload]; |
| 1459 } else { | 1467 } else { |
| 1460 [self.webController requirePageReload]; | 1468 [self.webController requirePageReload]; |
| 1461 } | 1469 } |
| 1462 requireReloadAfterBecomingActive_ = NO; | 1470 requireReloadAfterBecomingActive_ = NO; |
| 1463 } | 1471 } |
| 1464 } | 1472 } |
| 1465 | 1473 |
| 1474 - (BOOL)shouldBlockPopupForPageWithURL:(const GURL&)URL { | |
|
rohitrao (ping after 24h)
2017/02/17 19:53:16
Both of these methods should eventually move out o
Eugene But (OOO till 7-30)
2017/02/17 20:48:55
Yeah, I think both are doable
| |
| 1475 HostContentSettingsMap* settingMap = | |
| 1476 ios::HostContentSettingsMapFactory::GetForBrowserState(browserState_); | |
| 1477 ContentSetting setting = settingMap->GetContentSetting( | |
| 1478 URL, URL, CONTENT_SETTINGS_TYPE_POPUPS, std::string()); | |
| 1479 return setting != CONTENT_SETTING_ALLOW; | |
| 1480 } | |
| 1481 | |
| 1482 - (void)blockPopupForURL:(const GURL&)popupURL | |
| 1483 openerURL:(const GURL&)openerURL { | |
| 1484 web::NavigationItem* item = [self navigationManager]->GetLastCommittedItem(); | |
| 1485 web::Referrer referrer(openerURL, item->GetReferrer().policy); | |
| 1486 GURL localPopupURL(popupURL); | |
| 1487 base::WeakNSObject<Tab> weakSelf(self); | |
| 1488 // TODO(crbug.com/692117): Remove |window_name| from constructor. | |
| 1489 web::BlockedPopupInfo poupInfo(popupURL, referrer, nil /* window_name */, ^{ | |
| 1490 base::scoped_nsobject<Tab> strongSelf([weakSelf retain]); | |
| 1491 if (!strongSelf) { | |
| 1492 return; | |
| 1493 } | |
| 1494 [strongSelf updateSnapshotWithOverlay:YES visibleFrameOnly:YES]; | |
| 1495 [strongSelf.get()->parentTabModel_ | |
| 1496 insertOrUpdateTabWithURL:localPopupURL | |
| 1497 referrer:referrer | |
| 1498 transition:ui::PAGE_TRANSITION_LINK | |
| 1499 windowName:nil | |
| 1500 opener:self | |
| 1501 openedByDOM:YES | |
| 1502 atIndex:TabModelConstants::kTabPositionAutomatically | |
| 1503 inBackground:NO]; | |
| 1504 }); | |
| 1505 BlockedPopupTabHelper::FromWebState(self.webState)->HandlePopup(poupInfo); | |
| 1506 } | |
| 1507 | |
| 1466 #pragma mark - | 1508 #pragma mark - |
| 1467 #pragma mark FindInPageControllerDelegate | 1509 #pragma mark FindInPageControllerDelegate |
| 1468 | 1510 |
| 1469 - (void)willAdjustScrollPosition { | 1511 - (void)willAdjustScrollPosition { |
| 1470 // Skip the next attempt to correct the scroll offset for the toolbar height. | 1512 // Skip the next attempt to correct the scroll offset for the toolbar height. |
| 1471 // Used when programatically scrolling down the y offset. | 1513 // Used when programatically scrolling down the y offset. |
| 1472 [fullScreenController_ shouldSkipNextScrollOffsetForHeader]; | 1514 [fullScreenController_ shouldSkipNextScrollOffsetForHeader]; |
| 1473 } | 1515 } |
| 1474 | 1516 |
| 1475 #pragma mark - | 1517 #pragma mark - |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1571 snapshotOverlayProvider_.reset(snapshotOverlayProvider); | 1613 snapshotOverlayProvider_.reset(snapshotOverlayProvider); |
| 1572 } | 1614 } |
| 1573 | 1615 |
| 1574 - (void)evaluateU2FResultFromURL:(const GURL&)URL { | 1616 - (void)evaluateU2FResultFromURL:(const GURL&)URL { |
| 1575 DCHECK(U2FController_); | 1617 DCHECK(U2FController_); |
| 1576 [U2FController_ evaluateU2FResultFromU2FURL:URL webState:self.webState]; | 1618 [U2FController_ evaluateU2FResultFromU2FURL:URL webState:self.webState]; |
| 1577 } | 1619 } |
| 1578 | 1620 |
| 1579 #pragma mark - CRWWebDelegate and CRWWebStateObserver protocol methods. | 1621 #pragma mark - CRWWebDelegate and CRWWebStateObserver protocol methods. |
| 1580 | 1622 |
| 1581 - (CRWWebController*)webPageOrderedOpen:(const GURL&)URL | |
| 1582 referrer:(const web::Referrer&)referrer | |
| 1583 windowName:(NSString*)windowName | |
| 1584 inBackground:(BOOL)inBackground { | |
| 1585 DCHECK(parentTabModel_); | |
| 1586 if (!inBackground) | |
| 1587 [self updateSnapshotWithOverlay:YES visibleFrameOnly:YES]; | |
| 1588 // Open a new tab or update an existing one. Tabs opened from a web page are | |
| 1589 Tab* tab = [parentTabModel_ | |
| 1590 insertOrUpdateTabWithURL:URL | |
| 1591 referrer:referrer | |
| 1592 transition:ui::PAGE_TRANSITION_LINK | |
| 1593 windowName:windowName | |
| 1594 opener:self | |
| 1595 openedByDOM:YES | |
| 1596 atIndex:TabModelConstants::kTabPositionAutomatically | |
| 1597 inBackground:inBackground]; | |
| 1598 return tab.webController; | |
| 1599 } | |
| 1600 | |
| 1601 // This can be combined with the other versions once Tab loading is separated | |
| 1602 // from creation. | |
| 1603 - (CRWWebController*)webPageOrderedOpen { | |
| 1604 [self updateSnapshotWithOverlay:YES visibleFrameOnly:YES]; | |
| 1605 | |
| 1606 Tab* tab = [parentTabModel_ | |
| 1607 insertBlankTabWithTransition:ui::PAGE_TRANSITION_LINK | |
| 1608 opener:self | |
| 1609 openedByDOM:YES | |
| 1610 atIndex:TabModelConstants::kTabPositionAutomatically | |
| 1611 inBackground:NO]; | |
| 1612 return tab.webController; | |
| 1613 } | |
| 1614 | |
| 1615 // The web page wants to close its own window. | 1623 // The web page wants to close its own window. |
| 1616 - (void)webPageOrderedClose { | 1624 - (void)webPageOrderedClose { |
| 1617 // Only allow a web page to close itself if it was opened by DOM, or if there | 1625 // Only allow a web page to close itself if it was opened by DOM, or if there |
| 1618 // are no navigation items. | 1626 // are no navigation items. |
| 1619 DCHECK([[self navigationManager]->GetSessionController() isOpenedByDOM] || | 1627 DCHECK([[self navigationManager]->GetSessionController() isOpenedByDOM] || |
| 1620 ![self navigationManager]->GetItemCount()); | 1628 ![self navigationManager]->GetItemCount()); |
| 1621 [self closeThisTab]; | 1629 [self closeThisTab]; |
| 1622 } | 1630 } |
| 1623 | 1631 |
| 1624 // This method is invoked whenever the system believes the URL is about to | 1632 // This method is invoked whenever the system believes the URL is about to |
| (...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1977 | 1985 |
| 1978 - (void)setWebUsageEnabled:(BOOL)webUsageEnabled { | 1986 - (void)setWebUsageEnabled:(BOOL)webUsageEnabled { |
| 1979 [self.webController setWebUsageEnabled:webUsageEnabled]; | 1987 [self.webController setWebUsageEnabled:webUsageEnabled]; |
| 1980 } | 1988 } |
| 1981 | 1989 |
| 1982 - (void)webControllerDidSuppressDialog:(id)webController { | 1990 - (void)webControllerDidSuppressDialog:(id)webController { |
| 1983 DCHECK(isPrerenderTab_); | 1991 DCHECK(isPrerenderTab_); |
| 1984 [delegate_ discardPrerender]; | 1992 [delegate_ discardPrerender]; |
| 1985 } | 1993 } |
| 1986 | 1994 |
| 1987 - (BOOL)webController:(CRWWebController*)webController | 1995 - (CRWWebController*)webController:(CRWWebController*)webController |
| 1988 shouldBlockPopupWithURL:(const GURL&)popupURL | 1996 createWebControllerForURL:(const GURL&)URL |
| 1989 sourceURL:(const GURL&)sourceURL { | 1997 openerURL:(const GURL&)openerURL |
| 1990 ContentSetting setting = | 1998 initiatedByUser:(BOOL)initiatedByUser { |
| 1991 ios::HostContentSettingsMapFactory::GetForBrowserState(browserState_) | 1999 BOOL shouldBlockPopUp = |
| 1992 ->GetContentSetting(sourceURL, sourceURL, | 2000 !initiatedByUser && [self shouldBlockPopupForPageWithURL:openerURL]; |
| 1993 CONTENT_SETTINGS_TYPE_POPUPS, std::string()); | |
| 1994 | 2001 |
| 1995 return setting != CONTENT_SETTING_ALLOW; | 2002 if (shouldBlockPopUp) { |
| 1996 } | 2003 [self blockPopupForURL:URL openerURL:openerURL]; |
| 2004 return nil; | |
| 2005 } | |
| 1997 | 2006 |
| 1998 - (void)webController:(CRWWebController*)webController | 2007 [self updateSnapshotWithOverlay:YES visibleFrameOnly:YES]; |
| 1999 didBlockPopup:(const web::BlockedPopupInfo&)blockedPopupInfo { | 2008 Tab* tab = [parentTabModel_ |
| 2000 BlockedPopupTabHelper::FromWebState(self.webState) | 2009 insertBlankTabWithTransition:ui::PAGE_TRANSITION_LINK |
| 2001 ->HandlePopup(blockedPopupInfo); | 2010 opener:self |
| 2011 openedByDOM:YES | |
| 2012 atIndex:TabModelConstants::kTabPositionAutomatically | |
| 2013 inBackground:NO]; | |
| 2014 return tab.webController; | |
| 2002 } | 2015 } |
| 2003 | 2016 |
| 2004 - (CGFloat)headerHeightForWebController:(CRWWebController*)webController { | 2017 - (CGFloat)headerHeightForWebController:(CRWWebController*)webController { |
| 2005 return [self.tabHeadersDelegate headerHeightForTab:self]; | 2018 return [self.tabHeadersDelegate headerHeightForTab:self]; |
| 2006 } | 2019 } |
| 2007 | 2020 |
| 2008 - (void)webControllerDidUpdateSSLStatusForCurrentNavigationItem: | 2021 - (void)webControllerDidUpdateSSLStatusForCurrentNavigationItem: |
| 2009 (CRWWebController*)webController { | 2022 (CRWWebController*)webController { |
| 2010 // Disable fullscreen if SSL cert is invalid. | 2023 // Disable fullscreen if SSL cert is invalid. |
| 2011 web::NavigationItem* item = [self navigationManager]->GetTransientItem(); | 2024 web::NavigationItem* item = [self navigationManager]->GetTransientItem(); |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2214 | 2227 |
| 2215 - (TabModel*)parentTabModel { | 2228 - (TabModel*)parentTabModel { |
| 2216 return parentTabModel_; | 2229 return parentTabModel_; |
| 2217 } | 2230 } |
| 2218 | 2231 |
| 2219 - (FormInputAccessoryViewController*)inputAccessoryViewController { | 2232 - (FormInputAccessoryViewController*)inputAccessoryViewController { |
| 2220 return inputAccessoryViewController_.get(); | 2233 return inputAccessoryViewController_.get(); |
| 2221 } | 2234 } |
| 2222 | 2235 |
| 2223 @end | 2236 @end |
| OLD | NEW |