1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef UI_WEB_DIALOGS_WEB_DIALOG_WEB_CONTENTS_DELEGATE_H_
6 #define UI_WEB_DIALOGS_WEB_DIALOG_WEB_CONTENTS_DELEGATE_H_
8 #include "base/compiler_specific.h"
9 #include "content/public/browser/web_contents_delegate.h"
10 #include "ui/web_dialogs/web_dialogs_export.h"
14 // This class implements (and mostly ignores) most of
15 // content::WebContentsDelegate for use in a Web dialog. Subclasses need only
16 // override a few methods instead of the everything from
17 // content::WebContentsDelegate; this way, implementations on all platforms
18 // behave consistently.
19 class WEB_DIALOGS_EXPORT WebDialogWebContentsDelegate
20 : public content::WebContentsDelegate
{
22 // Handles OpenURLFromTab and AddNewContents for WebDialogWebContentsDelegate.
23 class WebContentsHandler
{
25 virtual ~WebContentsHandler() {}
26 virtual content::WebContents
* OpenURLFromTab(
27 content::BrowserContext
* context
,
28 content::WebContents
* source
,
29 const content::OpenURLParams
& params
) = 0;
30 virtual void AddNewContents(content::BrowserContext
* context
,
31 content::WebContents
* source
,
32 content::WebContents
* new_contents
,
33 WindowOpenDisposition disposition
,
34 const gfx::Rect
& initial_pos
,
35 bool user_gesture
) = 0;
38 // context and handler must be non-NULL.
39 // Takes the ownership of handler.
40 WebDialogWebContentsDelegate(content::BrowserContext
* context
,
41 WebContentsHandler
* handler
);
43 virtual ~WebDialogWebContentsDelegate();
45 // The returned browser context is guaranteed to be original if non-NULL.
46 content::BrowserContext
* browser_context() const {
47 return browser_context_
;
50 // Calling this causes all following events sent from the
51 // WebContents object to be ignored. It also makes all following
52 // calls to browser_context() return NULL.
55 // content::WebContentsDelegate declarations.
56 virtual content::WebContents
* OpenURLFromTab(
57 content::WebContents
* source
,
58 const content::OpenURLParams
& params
) OVERRIDE
;
59 virtual void AddNewContents(content::WebContents
* source
,
60 content::WebContents
* new_contents
,
61 WindowOpenDisposition disposition
,
62 const gfx::Rect
& initial_pos
,
64 bool* was_blocked
) OVERRIDE
;
65 virtual bool IsPopupOrPanel(
66 const content::WebContents
* source
) const OVERRIDE
;
67 virtual bool PreHandleGestureEvent(
68 content::WebContents
* source
,
69 const blink::WebGestureEvent
& event
) OVERRIDE
;
72 // Weak pointer. Always an original profile.
73 content::BrowserContext
* browser_context_
;
75 scoped_ptr
<WebContentsHandler
> handler_
;
77 DISALLOW_COPY_AND_ASSIGN(WebDialogWebContentsDelegate
);
82 #endif // UI_WEB_DIALOGS_WEB_DIALOG_WEB_CONTENTS_DELEGATE_H_