Skip to content

Commit

Permalink
[ios] Add InterstitialPageDelegate::OverrideItem to mirror Desktop.
Browse files Browse the repository at this point in the history
On iOS transient navigation item is updated in Tab after presenting
SSL interstitial. On Destop it is done in InterstitialPageImpl::Show by
calling InterstitialPageDelegate::OverrideItem, delegating the change
to SSLBlockingPage.

This CL makes iOS follow the same approach as other platforms.
Downstream CL: https://chromereviews.googleplex.com/396387014

BUG=602298

Review URL: https://codereview.chromium.org/1878053002

Cr-Commit-Position: refs/heads/master@{#386920}
  • Loading branch information
eugenebut authored and Commit bot committed Apr 13, 2016
1 parent 41fc117 commit a6914d6
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 0 deletions.
1 change: 1 addition & 0 deletions ios/chrome/browser/DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -102,5 +102,6 @@ include_rules = [
# Strings and resources.
"+components/grit",
"+components/strings/grit",
"+grit/components_strings.h",
"+ios/chrome/grit",
]
1 change: 1 addition & 0 deletions ios/chrome/browser/ssl/ios_ssl_blocking_page.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class IOSSSLBlockingPage : public IOSSecurityInterstitialPage {
void CommandReceived(const std::string& command) override;
void OnProceed() override;
void OnDontProceed() override;
void OverrideItem(web::NavigationItem* item) override;

// SecurityInterstitialPage implementation:
bool ShouldCreateNewNavigation() const override;
Expand Down
17 changes: 17 additions & 0 deletions ios/chrome/browser/ssl/ios_ssl_blocking_page.mm
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,15 @@
#include "base/strings/utf_string_conversions.h"
#include "components/security_interstitials/core/metrics_helper.h"
#include "components/security_interstitials/core/ssl_error_ui.h"
#include "grit/components_strings.h"
#include "ios/chrome/browser/browser_state/chrome_browser_state.h"
#include "ios/chrome/browser/interstitials/ios_chrome_controller_client.h"
#include "ios/chrome/browser/interstitials/ios_chrome_metrics_helper.h"
#include "ios/chrome/grit/ios_strings.h"
#include "ios/public/provider/chrome/browser/browser_constants.h"
#include "ios/web/public/cert_store.h"
#import "ios/web/public/navigation_item.h"
#include "ios/web/public/ssl_status.h"
#include "ios/web/public/web_state/web_state.h"
#include "net/base/net_errors.h"
#include "ui/base/l10n/l10n_util.h"
Expand Down Expand Up @@ -180,6 +184,19 @@ void RecordSSLExpirationPageEventState(bool expired_but_previously_allowed,
NotifyDenyCertificate();
}

void IOSSSLBlockingPage::OverrideItem(web::NavigationItem* item) {
item->SetTitle(l10n_util::GetStringUTF16(IDS_SSL_V2_TITLE));

item->GetSSL().security_style = web::SECURITY_STYLE_AUTHENTICATION_BROKEN;
item->GetSSL().cert_status = ssl_info_.cert_status;
// On iOS cert may be null when it is not provided by API callback or can not
// be parsed.
if (ssl_info_.cert) {
item->GetSSL().cert_id = web::CertStore::GetInstance()->StoreCert(
ssl_info_.cert.get(), web_state()->GetCertGroupId());
}
}

void IOSSSLBlockingPage::NotifyDenyCertificate() {
// It's possible that callback_ may not exist if the user clicks "Proceed"
// followed by pressing the back button before the interstitial is hidden.
Expand Down
3 changes: 3 additions & 0 deletions ios/web/interstitials/web_interstitial_impl.mm
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@
CRWSessionController* sessionController =
navigation_manager_->GetSessionController();
[sessionController addTransientEntryWithURL:url_];

// Give delegates a chance to set some states on the navigation item.
GetDelegate()->OverrideItem(navigation_manager_->GetTransientItem());
}
}

Expand Down
9 changes: 9 additions & 0 deletions ios/web/public/interstitials/web_interstitial_delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

namespace web {

class NavigationItem;

// Superclass for delegates that provide data to a WebInterstitial. After the
// WebInterstitial is shown, it takes ownership of its delegate.
class WebInterstitialDelegate {
Expand All @@ -23,6 +25,13 @@ class WebInterstitialDelegate {
// on WebInterstitial, since navigations etc may cancel them.
virtual void OnProceed() {}
virtual void OnDontProceed() {}

// Called with the NavigationItem that is going to be added to the navigation
// manager.
// Gives an opportunity to delegates to set states on the |item|.
// Note that this is only called if the WebInterstitial was constructed with
// |new_navigation| set to true.
virtual void OverrideItem(NavigationItem* item) {}
};

// Provides HTML to an HTMLWebInterstitialImpl.
Expand Down
1 change: 1 addition & 0 deletions ios/web/public/test/test_web_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class TestWebState : public WebState {
CRWWebViewProxyType GetWebViewProxy() const override;
bool IsShowingWebInterstitial() const override;
WebInterstitial* GetWebInterstitial() const override;
int GetCertGroupId() const override;
void AddObserver(WebStateObserver* observer) override {}
void RemoveObserver(WebStateObserver* observer) override {}
void AddPolicyDecider(WebStatePolicyDecider* decider) override {}
Expand Down
4 changes: 4 additions & 0 deletions ios/web/public/test/test_web_state.mm
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@
return nullptr;
}

int TestWebState::GetCertGroupId() const {
return 0;
}

void TestWebState::SetContentIsHTML(bool content_is_html) {
content_is_html_ = content_is_html;
}
Expand Down
3 changes: 3 additions & 0 deletions ios/web/public/web_state/web_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ class WebState : public base::SupportsUserData {
// Returns the currently visible WebInterstitial if one is shown.
virtual WebInterstitial* GetWebInterstitial() const = 0;

// Returns the unique ID to use with web::CertStore.
virtual int GetCertGroupId() const = 0;

// Callback used to handle script commands.
// The callback must return true if the command was handled, and false
// otherwise.
Expand Down
1 change: 1 addition & 0 deletions ios/web/web_state/web_state_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ class WebStateImpl : public WebState, public NavigationManagerDelegate {
void ShowTransientContentView(CRWContentView* content_view) override;
bool IsShowingWebInterstitial() const override;
WebInterstitial* GetWebInterstitial() const override;
int GetCertGroupId() const override;
void AddScriptCommandCallback(const ScriptCommandCallback& callback,
const std::string& command_prefix) override;
void RemoveScriptCommandCallback(const std::string& command_prefix) override;
Expand Down
4 changes: 4 additions & 0 deletions ios/web/web_state/web_state_impl.mm
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,10 @@
return interstitial_;
}

int WebStateImpl::GetCertGroupId() const {
return request_tracker_->identifier();
}

net::HttpResponseHeaders* WebStateImpl::GetHttpResponseHeaders() const {
return http_response_headers_.get();
}
Expand Down

0 comments on commit a6914d6

Please sign in to comment.