blob: dde6a6521517da133b5e55d4c64ac8a5af8e2cb5 [file] [log] [blame]
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <CoreGraphics/CoreGraphics.h>
#include "base/callback.h"
#include "base/macros.h"
#include "ios/web/public/web_state/web_state_observer.h"
#import "ios/web/public/web_state/web_state_user_data.h"
@protocol RepostFormTabHelperDelegate;
// Allows presenting a repost form dialog. Listens to web::WebState activity
// and dismisses the dialog when necessary.
class RepostFormTabHelper : public web::WebStateUserData<RepostFormTabHelper>,
public web::WebStateObserver {
~RepostFormTabHelper() override;
// Creates TabHelper. |delegate| is not retained by TabHelper and must not be
// null.
static void CreateForWebState(web::WebState* web_state,
id<RepostFormTabHelperDelegate> delegate);
// Presents a repost form dialog at the given |location|. |callback| is called
// with true if the repost was confirmed and with false if it was cancelled.
void PresentDialog(CGPoint location, base::OnceCallback<void(bool)> callback);
RepostFormTabHelper(web::WebState* web_state,
id<RepostFormTabHelperDelegate> delegate);
// Called to dismiss the repost form dialog.
void DismissReportFormDialog();
// web::WebStateObserver overrides:
void DidStartNavigation(web::WebState* web_state,
web::NavigationContext* navigation_context) override;
void WebStateDestroyed(web::WebState* web_state) override;
// The WebState this instance is observing. Will be null after
// WebStateDestroyed has been called.
web::WebState* web_state_ = nullptr;
__weak id<RepostFormTabHelperDelegate> delegate_ = nil;
// true if form repost dialog is currently being presented.
bool is_presenting_dialog_ = false;