1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
// 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.
#ifndef UI_WEB_DIALOGS_WEB_DIALOG_WEB_CONTENTS_DELEGATE_H_
#define UI_WEB_DIALOGS_WEB_DIALOG_WEB_CONTENTS_DELEGATE_H_
#include "base/compiler_specific.h"
#include "content/public/browser/web_contents_delegate.h"
#include "ui/web_dialogs/web_dialogs_export.h"
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 {
public:
// Handles OpenURLFromTab and AddNewContents for WebDialogWebContentsDelegate.
class WebContentsHandler {
public:
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;
private:
// Weak pointer. Always an original profile.
content::BrowserContext* browser_context_;
scoped_ptr<WebContentsHandler> handler_;
DISALLOW_COPY_AND_ASSIGN(WebDialogWebContentsDelegate);
};
} // namespace ui
#endif // UI_WEB_DIALOGS_WEB_DIALOG_WEB_CONTENTS_DELEGATE_H_
|