blob: c9e04b5fc410bac55d818fa15a3ee1f513db47ec [file] [log] [blame]
// Copyright (c) 2012 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 "base/compiler_specific.h"
#include "base/macros.h"
#include "content/public/browser/web_contents_delegate.h"
#include "ui/web_dialogs/web_dialogs_export.h"
namespace content {
class BrowserContext;
namespace ui {
// This class implements (and mostly ignores) most of
// content::WebContentsDelegate for use in a Web dialog. Subclasses need only
// override a few methods instead of the everything from
// content::WebContentsDelegate; this way, implementations on all platforms
// behave consistently.
class WEB_DIALOGS_EXPORT WebDialogWebContentsDelegate
: public content::WebContentsDelegate {
// Handles OpenURLFromTab and AddNewContents for WebDialogWebContentsDelegate.
class WebContentsHandler {
virtual ~WebContentsHandler() {}
virtual content::WebContents* OpenURLFromTab(
content::BrowserContext* context,
content::WebContents* source,
const content::OpenURLParams& params) = 0;
virtual void AddNewContents(content::BrowserContext* context,
content::WebContents* source,
content::WebContents* new_contents,
WindowOpenDisposition disposition,
const gfx::Rect& initial_rect,
bool user_gesture) = 0;
// context and handler must be non-NULL.
// Takes the ownership of handler.
WebDialogWebContentsDelegate(content::BrowserContext* context,
WebContentsHandler* handler);
~WebDialogWebContentsDelegate() override;
// The returned browser context is guaranteed to be original if non-NULL.
content::BrowserContext* browser_context() const {
return browser_context_;
// Calling this causes all following events sent from the
// WebContents object to be ignored. It also makes all following
// calls to browser_context() return NULL.
void Detach();
// content::WebContentsDelegate declarations.
content::WebContents* OpenURLFromTab(
content::WebContents* source,
const content::OpenURLParams& params) override;
void AddNewContents(content::WebContents* source,
content::WebContents* new_contents,
WindowOpenDisposition disposition,
const gfx::Rect& initial_rect,
bool user_gesture,
bool* was_blocked) override;
bool IsPopupOrPanel(const content::WebContents* source) const override;
bool PreHandleGestureEvent(content::WebContents* source,
const blink::WebGestureEvent& event) override;
// Weak pointer. Always an original profile.
content::BrowserContext* browser_context_;
std::unique_ptr<WebContentsHandler> handler_;
} // namespace ui