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/security_style_explanations.h"
12 #include "content/public/browser/web_contents.h"
13 #include "content/public/common/bindings_policy.h"
14 #include "content/public/common/security_style.h"
15 #include "content/public/common/url_constants.h"
16 #include "ui/gfx/geometry/rect.h"
20 WebContentsDelegate::WebContentsDelegate() {
23 WebContents
* WebContentsDelegate::OpenURLFromTab(WebContents
* source
,
24 const OpenURLParams
& params
) {
28 bool WebContentsDelegate::IsPopupOrPanel(const WebContents
* source
) const {
32 bool WebContentsDelegate::CanOverscrollContent() const { return false; }
34 gfx::Rect
WebContentsDelegate::GetRootWindowResizerRect() const {
38 bool WebContentsDelegate::ShouldSuppressDialogs(WebContents
* source
) {
42 bool WebContentsDelegate::ShouldPreserveAbortedURLs(WebContents
* source
) {
46 bool WebContentsDelegate::AddMessageToConsole(WebContents
* source
,
48 const base::string16
& message
,
50 const base::string16
& source_id
) {
54 void WebContentsDelegate::BeforeUnloadFired(WebContents
* web_contents
,
56 bool* proceed_to_fire_unload
) {
57 *proceed_to_fire_unload
= true;
60 bool WebContentsDelegate::ShouldFocusLocationBarByDefault(WebContents
* source
) {
64 bool WebContentsDelegate::ShouldFocusPageAfterCrash() {
68 bool WebContentsDelegate::ShouldResumeRequestsForCreatedWindow() {
72 bool WebContentsDelegate::TakeFocus(WebContents
* source
, bool reverse
) {
76 void WebContentsDelegate::CanDownload(
78 const std::string
& request_method
,
79 const base::Callback
<void(bool)>& callback
) {
83 bool WebContentsDelegate::HandleContextMenu(
84 const content::ContextMenuParams
& params
) {
88 void WebContentsDelegate::ViewSourceForTab(WebContents
* source
,
89 const GURL
& page_url
) {
90 // Fall back implementation based entirely on the view-source scheme.
91 // It suffers from http://crbug.com/523 and that is why browser overrides
92 // it with proper implementation.
93 GURL url
= GURL(kViewSourceScheme
+ std::string(":") + page_url
.spec());
94 OpenURLFromTab(source
, OpenURLParams(url
, Referrer(),
96 ui::PAGE_TRANSITION_LINK
, false));
99 void WebContentsDelegate::ViewSourceForFrame(WebContents
* source
,
100 const GURL
& frame_url
,
101 const PageState
& page_state
) {
102 // Same as ViewSourceForTab, but for given subframe.
103 GURL url
= GURL(kViewSourceScheme
+ std::string(":") + frame_url
.spec());
104 OpenURLFromTab(source
, OpenURLParams(url
, Referrer(),
106 ui::PAGE_TRANSITION_LINK
, false));
109 bool WebContentsDelegate::PreHandleKeyboardEvent(
111 const NativeWebKeyboardEvent
& event
,
112 bool* is_keyboard_shortcut
) {
116 bool WebContentsDelegate::PreHandleGestureEvent(
118 const blink::WebGestureEvent
& event
) {
122 bool WebContentsDelegate::CanDragEnter(
124 const DropData
& data
,
125 blink::WebDragOperationsMask operations_allowed
) {
129 bool WebContentsDelegate::OnGoToEntryOffset(int offset
) {
133 bool WebContentsDelegate::ShouldCreateWebContents(
134 WebContents
* web_contents
,
136 int main_frame_route_id
,
137 WindowContainerType window_container_type
,
138 const std::string
& frame_name
,
139 const GURL
& target_url
,
140 const std::string
& partition_id
,
141 SessionStorageNamespace
* session_storage_namespace
) {
145 JavaScriptDialogManager
* WebContentsDelegate::GetJavaScriptDialogManager(
146 WebContents
* source
) {
150 bool WebContentsDelegate::EmbedsFullscreenWidget() const {
154 bool WebContentsDelegate::IsFullscreenForTabOrPending(
155 const WebContents
* web_contents
) const {
159 blink::WebDisplayMode
WebContentsDelegate::GetDisplayMode(
160 const WebContents
* web_contents
) const {
161 return blink::WebDisplayModeBrowser
;
164 content::ColorChooser
* WebContentsDelegate::OpenColorChooser(
165 WebContents
* web_contents
,
167 const std::vector
<ColorSuggestion
>& suggestions
) {
171 void WebContentsDelegate::RequestMediaAccessPermission(
172 WebContents
* web_contents
,
173 const MediaStreamRequest
& request
,
174 const MediaResponseCallback
& callback
) {
175 LOG(ERROR
) << "WebContentsDelegate::RequestMediaAccessPermission: "
177 callback
.Run(MediaStreamDevices(),
178 MEDIA_DEVICE_NOT_SUPPORTED
,
179 scoped_ptr
<MediaStreamUI
>());
182 bool WebContentsDelegate::CheckMediaAccessPermission(
183 WebContents
* web_contents
,
184 const GURL
& security_origin
,
185 MediaStreamType type
) {
186 LOG(ERROR
) << "WebContentsDelegate::CheckMediaAccessPermission: "
191 bool WebContentsDelegate::RequestPpapiBrokerPermission(
192 WebContents
* web_contents
,
194 const base::FilePath
& plugin_path
,
195 const base::Callback
<void(bool)>& callback
) {
199 WebContentsDelegate::~WebContentsDelegate() {
200 while (!attached_contents_
.empty()) {
201 WebContents
* web_contents
= *attached_contents_
.begin();
202 web_contents
->SetDelegate(nullptr);
204 DCHECK(attached_contents_
.empty());
207 void WebContentsDelegate::Attach(WebContents
* web_contents
) {
208 DCHECK(attached_contents_
.find(web_contents
) == attached_contents_
.end());
209 attached_contents_
.insert(web_contents
);
212 void WebContentsDelegate::Detach(WebContents
* web_contents
) {
213 DCHECK(attached_contents_
.find(web_contents
) != attached_contents_
.end());
214 attached_contents_
.erase(web_contents
);
217 gfx::Size
WebContentsDelegate::GetSizeForNewRenderView(
218 WebContents
* web_contents
) const {
222 bool WebContentsDelegate::IsNeverVisible(WebContents
* web_contents
) {
226 bool WebContentsDelegate::SaveFrame(const GURL
& url
, const Referrer
& referrer
) {
230 SecurityStyle
WebContentsDelegate::GetSecurityStyle(
231 WebContents
* web_contents
,
232 SecurityStyleExplanations
* security_style_explanations
) {
233 return content::SECURITY_STYLE_UNKNOWN
;
236 } // namespace content