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 #include "content/public/browser/web_contents_delegate.h"
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/bindings_policy.h"
13 #include "content/public/common/url_constants.h"
14 #include "ui/gfx/geometry/rect.h"
18 WebContentsDelegate::WebContentsDelegate() {
21 WebContents
* WebContentsDelegate::OpenURLFromTab(WebContents
* source
,
22 const OpenURLParams
& params
) {
26 bool WebContentsDelegate::IsPopupOrPanel(const WebContents
* source
) const {
30 bool WebContentsDelegate::CanOverscrollContent() const { return false; }
32 gfx::Rect
WebContentsDelegate::GetRootWindowResizerRect() const {
36 bool WebContentsDelegate::ShouldSuppressDialogs(WebContents
* source
) {
40 bool WebContentsDelegate::ShouldPreserveAbortedURLs(WebContents
* source
) {
44 bool WebContentsDelegate::AddMessageToConsole(WebContents
* source
,
46 const base::string16
& message
,
48 const base::string16
& source_id
) {
52 void WebContentsDelegate::BeforeUnloadFired(WebContents
* web_contents
,
54 bool* proceed_to_fire_unload
) {
55 *proceed_to_fire_unload
= true;
58 bool WebContentsDelegate::ShouldFocusLocationBarByDefault(WebContents
* source
) {
62 bool WebContentsDelegate::ShouldFocusPageAfterCrash() {
66 bool WebContentsDelegate::TakeFocus(WebContents
* source
, bool reverse
) {
70 int WebContentsDelegate::GetExtraRenderViewHeight() const {
74 void WebContentsDelegate::CanDownload(
75 RenderViewHost
* render_view_host
,
77 const std::string
& request_method
,
78 const base::Callback
<void(bool)>& callback
) {
82 bool WebContentsDelegate::HandleContextMenu(
83 const content::ContextMenuParams
& params
) {
87 void WebContentsDelegate::ViewSourceForTab(WebContents
* source
,
88 const GURL
& page_url
) {
89 // Fall back implementation based entirely on the view-source scheme.
90 // It suffers from http://crbug.com/523 and that is why browser overrides
91 // it with proper implementation.
92 GURL url
= GURL(kViewSourceScheme
+ std::string(":") + page_url
.spec());
93 OpenURLFromTab(source
, OpenURLParams(url
, Referrer(),
95 ui::PAGE_TRANSITION_LINK
, false));
98 void WebContentsDelegate::ViewSourceForFrame(WebContents
* source
,
99 const GURL
& frame_url
,
100 const PageState
& page_state
) {
101 // Same as ViewSourceForTab, but for given subframe.
102 GURL url
= GURL(kViewSourceScheme
+ std::string(":") + frame_url
.spec());
103 OpenURLFromTab(source
, OpenURLParams(url
, Referrer(),
105 ui::PAGE_TRANSITION_LINK
, false));
108 bool WebContentsDelegate::PreHandleKeyboardEvent(
110 const NativeWebKeyboardEvent
& event
,
111 bool* is_keyboard_shortcut
) {
115 bool WebContentsDelegate::PreHandleGestureEvent(
117 const blink::WebGestureEvent
& event
) {
121 bool WebContentsDelegate::CanDragEnter(
123 const DropData
& data
,
124 blink::WebDragOperationsMask operations_allowed
) {
128 bool WebContentsDelegate::OnGoToEntryOffset(int offset
) {
132 bool WebContentsDelegate::ShouldCreateWebContents(
133 WebContents
* web_contents
,
135 int main_frame_route_id
,
136 WindowContainerType window_container_type
,
137 const base::string16
& frame_name
,
138 const GURL
& target_url
,
139 const std::string
& partition_id
,
140 SessionStorageNamespace
* session_storage_namespace
) {
144 JavaScriptDialogManager
* WebContentsDelegate::GetJavaScriptDialogManager(
145 WebContents
* source
) {
149 bool WebContentsDelegate::EmbedsFullscreenWidget() const {
153 bool WebContentsDelegate::IsFullscreenForTabOrPending(
154 const WebContents
* web_contents
) const {
158 content::ColorChooser
* WebContentsDelegate::OpenColorChooser(
159 WebContents
* web_contents
,
161 const std::vector
<ColorSuggestion
>& suggestions
) {
165 void WebContentsDelegate::RequestMediaAccessPermission(
166 WebContents
* web_contents
,
167 const MediaStreamRequest
& request
,
168 const MediaResponseCallback
& callback
) {
169 LOG(ERROR
) << "WebContentsDelegate::RequestMediaAccessPermission: "
171 callback
.Run(MediaStreamDevices(),
172 MEDIA_DEVICE_NOT_SUPPORTED
,
173 scoped_ptr
<MediaStreamUI
>());
176 bool WebContentsDelegate::CheckMediaAccessPermission(
177 WebContents
* web_contents
,
178 const GURL
& security_origin
,
179 MediaStreamType type
) {
180 LOG(ERROR
) << "WebContentsDelegate::CheckMediaAccessPermission: "
185 bool WebContentsDelegate::RequestPpapiBrokerPermission(
186 WebContents
* web_contents
,
188 const base::FilePath
& plugin_path
,
189 const base::Callback
<void(bool)>& callback
) {
193 WebContentsDelegate::~WebContentsDelegate() {
194 while (!attached_contents_
.empty()) {
195 WebContents
* web_contents
= *attached_contents_
.begin();
196 web_contents
->SetDelegate(nullptr);
198 DCHECK(attached_contents_
.empty());
201 void WebContentsDelegate::Attach(WebContents
* web_contents
) {
202 DCHECK(attached_contents_
.find(web_contents
) == attached_contents_
.end());
203 attached_contents_
.insert(web_contents
);
206 void WebContentsDelegate::Detach(WebContents
* web_contents
) {
207 DCHECK(attached_contents_
.find(web_contents
) != attached_contents_
.end());
208 attached_contents_
.erase(web_contents
);
211 gfx::Size
WebContentsDelegate::GetSizeForNewRenderView(
212 WebContents
* web_contents
) const {
216 bool WebContentsDelegate::IsNeverVisible(WebContents
* web_contents
) {
220 bool WebContentsDelegate::SaveFrame(const GURL
& url
, const Referrer
& referrer
) {
224 } // namespace content