web_contents_delegate.cc revision a3f7b4e666c476898878fa745f637129375cd889
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.
4
5#include "content/public/browser/web_contents_delegate.h"
6
7#include "base/compiler_specific.h"
8#include "base/logging.h"
9#include "base/memory/singleton.h"
10#include "content/public/browser/render_view_host.h"
11#include "content/public/browser/web_contents.h"
12#include "content/public/common/url_constants.h"
13#include "content/public/common/bindings_policy.h"
14#include "ui/gfx/rect.h"
15
16namespace content {
17
18WebContentsDelegate::WebContentsDelegate() {
19}
20
21WebContents* WebContentsDelegate::OpenURLFromTab(WebContents* source,
22                                                 const OpenURLParams& params) {
23  return NULL;
24}
25
26bool WebContentsDelegate::IsPopupOrPanel(const WebContents* source) const {
27  return false;
28}
29
30bool WebContentsDelegate::CanLoadDataURLsInWebUI() const { return false; }
31
32bool WebContentsDelegate::CanOverscrollContent() const { return false; }
33
34gfx::Rect WebContentsDelegate::GetRootWindowResizerRect() const {
35  return gfx::Rect();
36}
37
38bool WebContentsDelegate::ShouldSuppressDialogs() {
39  return false;
40}
41
42bool WebContentsDelegate::AddMessageToConsole(WebContents* source,
43                                              int32 level,
44                                              const string16& message,
45                                              int32 line_no,
46                                              const string16& source_id) {
47  return false;
48}
49
50void WebContentsDelegate::BeforeUnloadFired(WebContents* web_contents,
51                                            bool proceed,
52                                            bool* proceed_to_fire_unload) {
53  *proceed_to_fire_unload = true;
54}
55
56bool WebContentsDelegate::ShouldFocusLocationBarByDefault(WebContents* source) {
57  return false;
58}
59
60bool WebContentsDelegate::ShouldFocusPageAfterCrash() {
61  return true;
62}
63
64bool WebContentsDelegate::TakeFocus(WebContents* source, bool reverse) {
65  return false;
66}
67
68int WebContentsDelegate::GetExtraRenderViewHeight() const {
69  return 0;
70}
71
72void WebContentsDelegate::CanDownload(
73    RenderViewHost* render_view_host,
74    int request_id,
75    const std::string& request_method,
76    const base::Callback<void(bool)>& callback) {
77  callback.Run(true);
78}
79
80bool WebContentsDelegate::HandleContextMenu(
81    const content::ContextMenuParams& params) {
82  return false;
83}
84
85void WebContentsDelegate::ViewSourceForTab(WebContents* source,
86                                           const GURL& page_url) {
87  // Fall back implementation based entirely on the view-source scheme.
88  // It suffers from http://crbug.com/523 and that is why browser overrides
89  // it with proper implementation.
90  GURL url = GURL(kViewSourceScheme + std::string(":") + page_url.spec());
91  OpenURLFromTab(source, OpenURLParams(url, Referrer(),
92                                       NEW_FOREGROUND_TAB,
93                                       PAGE_TRANSITION_LINK, false));
94}
95
96void WebContentsDelegate::ViewSourceForFrame(WebContents* source,
97                                             const GURL& frame_url,
98                                             const PageState& page_state) {
99  // Same as ViewSourceForTab, but for given subframe.
100  GURL url = GURL(kViewSourceScheme + std::string(":") + frame_url.spec());
101  OpenURLFromTab(source, OpenURLParams(url, Referrer(),
102                                       NEW_FOREGROUND_TAB,
103                                       PAGE_TRANSITION_LINK, false));
104}
105
106bool WebContentsDelegate::PreHandleKeyboardEvent(
107    WebContents* source,
108    const NativeWebKeyboardEvent& event,
109    bool* is_keyboard_shortcut) {
110  return false;
111}
112
113bool WebContentsDelegate::CanDragEnter(
114    WebContents* source,
115    const DropData& data,
116    WebKit::WebDragOperationsMask operations_allowed) {
117  return true;
118}
119
120bool WebContentsDelegate::OnGoToEntryOffset(int offset) {
121  return true;
122}
123
124bool WebContentsDelegate::ShouldCreateWebContents(
125    WebContents* web_contents,
126    int route_id,
127    WindowContainerType window_container_type,
128    const string16& frame_name,
129    const GURL& target_url,
130    const Referrer& referrer,
131    WindowOpenDisposition disposition,
132    const WebKit::WebWindowFeatures& features,
133    bool user_gesture,
134    bool opener_suppressed) {
135  return true;
136}
137
138JavaScriptDialogManager* WebContentsDelegate::GetJavaScriptDialogManager() {
139  return NULL;
140}
141
142bool WebContentsDelegate::IsFullscreenForTabOrPending(
143    const WebContents* web_contents) const {
144  return false;
145}
146
147content::ColorChooser* WebContentsDelegate::OpenColorChooser(
148    WebContents* web_contents, SkColor color) {
149  return NULL;
150}
151
152bool WebContentsDelegate::RequestPpapiBrokerPermission(
153    WebContents* web_contents,
154    const GURL& url,
155    const base::FilePath& plugin_path,
156    const base::Callback<void(bool)>& callback) {
157  return false;
158}
159
160WebContentsDelegate::~WebContentsDelegate() {
161  while (!attached_contents_.empty()) {
162    WebContents* web_contents = *attached_contents_.begin();
163    web_contents->SetDelegate(NULL);
164  }
165  DCHECK(attached_contents_.empty());
166}
167
168void WebContentsDelegate::Attach(WebContents* web_contents) {
169  DCHECK(attached_contents_.find(web_contents) == attached_contents_.end());
170  attached_contents_.insert(web_contents);
171}
172
173void WebContentsDelegate::Detach(WebContents* web_contents) {
174  DCHECK(attached_contents_.find(web_contents) != attached_contents_.end());
175  attached_contents_.erase(web_contents);
176}
177
178}  // namespace content
179