Commit 3c960e0c authored by stkhapugin@chromium.org's avatar stkhapugin@chromium.org Committed by Commit Bot

Implement ToolbarModelDelegateIOS::IsOfflinePage().

Now that we have offline pages on iOS with reading list, it makes
sense to implement IsOfflinePage() and use it to determine the offline
status of the page.

Bug: None
Cq-Include-Trybots: luci.chromium.try:ios-simulator-full-configs;master.tryserver.chromium.mac:ios-simulator-cronet
Change-Id: I062ae21b5f995574a65d5b3a4a64bae56ef4c4c0
Reviewed-on: https://chromium-review.googlesource.com/1071655
Commit-Queue: Stepan Khapugin <stkhapugin@chromium.org>
Reviewed-by: default avatarRohit Rao <rohitrao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#561935}
parent a2b39089
......@@ -192,7 +192,7 @@
return nil;
}
if ([self isCurrentPageOffline]) {
if (self.toolbarModel->IsOfflinePage()) {
return [self imageForOfflinePage];
}
......@@ -210,15 +210,4 @@
return [UIImage imageNamed:@"location_bar_offline"];
}
- (BOOL)isCurrentPageOffline {
if (!self.webState)
return false;
auto* navigationManager = self.webState->GetNavigationManager();
auto* visibleItem = navigationManager->GetVisibleItem();
if (!visibleItem)
return false;
const GURL& url = visibleItem->GetURL();
return url.SchemeIs(kChromeUIScheme) && url.host() == kChromeUIOfflineHost;
}
@end
......@@ -65,18 +65,6 @@ bool DoesCurrentPageHaveCertInfo(web::WebState* webState) {
SSLStatus.security_style != web::SECURITY_STYLE_UNKNOWN;
}
// Returns whether the |webState| is presenting an offline page.
bool IsCurrentPageOffline(web::WebState* webState) {
if (!webState)
return false;
auto* navigationManager = webState->GetNavigationManager();
auto* visibleItem = navigationManager->GetVisibleItem();
if (!visibleItem)
return false;
const GURL& url = visibleItem->GetURL();
return url.SchemeIs(kChromeUIScheme) && url.host() == kChromeUIOfflineHost;
}
} // namespace
......@@ -179,14 +167,15 @@ void LocationBarControllerImpl::OnAutocompleteAccept(
}
void LocationBarControllerImpl::OnChanged() {
const bool page_is_offline = IsCurrentPageOffline(GetWebState());
ToolbarModel* toolbarModel = [delegate_ toolbarModel];
const bool page_is_offline =
toolbarModel ? toolbarModel->IsOfflinePage() : false;
const int resource_id = edit_view_->GetIcon(page_is_offline);
[location_bar_view_ setPlaceholderImage:resource_id];
// TODO(rohitrao): Can we get focus information from somewhere other than the
// model?
if (!IsIPadIdiom() && !edit_view_->model()->has_focus()) {
ToolbarModel* toolbarModel = [delegate_ toolbarModel];
if (toolbarModel) {
bool show_icon_for_state = security_state::ShouldAlwaysShowIcon(
toolbarModel->GetSecurityLevel(false));
......@@ -230,8 +219,10 @@ void LocationBarControllerImpl::OnKillFocus() {
[location_bar_view_ setLeadingButtonEnabled:YES];
// Update the placeholder icon.
const int resource_id =
edit_view_->GetIcon(IsCurrentPageOffline(GetWebState()));
ToolbarModel* toolbarModel = [delegate_ toolbarModel];
const bool page_is_offline =
toolbarModel ? toolbarModel->IsOfflinePage() : false;
const int resource_id = edit_view_->GetIcon(page_is_offline);
[location_bar_view_ setPlaceholderImage:resource_id];
// Show the placeholder text on iPad.
......@@ -255,8 +246,10 @@ void LocationBarControllerImpl::OnSetFocus() {
[location_bar_view_ setLeadingButtonEnabled:NO];
// Update the placeholder icon.
const int resource_id =
edit_view_->GetIcon(IsCurrentPageOffline(GetWebState()));
ToolbarModel* toolbarModel = [delegate_ toolbarModel];
const bool page_is_offline =
toolbarModel ? toolbarModel->IsOfflinePage() : false;
const int resource_id = edit_view_->GetIcon(page_is_offline);
[location_bar_view_ setPlaceholderImage:resource_id];
// Hide the placeholder text on iPad.
......
......@@ -111,5 +111,13 @@ const gfx::VectorIcon* ToolbarModelDelegateIOS::GetVectorIconOverride() const {
}
bool ToolbarModelDelegateIOS::IsOfflinePage() const {
return false;
web::WebState* web_state = GetActiveWebState();
if (!web_state)
return false;
auto* navigationManager = web_state->GetNavigationManager();
auto* visibleItem = navigationManager->GetVisibleItem();
if (!visibleItem)
return false;
const GURL& url = visibleItem->GetURL();
return url.SchemeIs(kChromeUIScheme) && url.host() == kChromeUIOfflineHost;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment