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 scoped_ptr
<BluetoothChooser
> WebContentsDelegate::RunBluetoothChooser(
151 WebContents
* web_contents
,
152 const BluetoothChooser::EventHandler
& event_handler
,
153 const GURL
& origin
) {
157 bool WebContentsDelegate::EmbedsFullscreenWidget() const {
161 bool WebContentsDelegate::IsFullscreenForTabOrPending(
162 const WebContents
* web_contents
) const {
166 blink::WebDisplayMode
WebContentsDelegate::GetDisplayMode(
167 const WebContents
* web_contents
) const {
168 return blink::WebDisplayModeBrowser
;
171 content::ColorChooser
* WebContentsDelegate::OpenColorChooser(
172 WebContents
* web_contents
,
174 const std::vector
<ColorSuggestion
>& suggestions
) {
178 void WebContentsDelegate::RequestMediaAccessPermission(
179 WebContents
* web_contents
,
180 const MediaStreamRequest
& request
,
181 const MediaResponseCallback
& callback
) {
182 LOG(ERROR
) << "WebContentsDelegate::RequestMediaAccessPermission: "
184 callback
.Run(MediaStreamDevices(),
185 MEDIA_DEVICE_NOT_SUPPORTED
,
186 scoped_ptr
<MediaStreamUI
>());
189 bool WebContentsDelegate::CheckMediaAccessPermission(
190 WebContents
* web_contents
,
191 const GURL
& security_origin
,
192 MediaStreamType type
) {
193 LOG(ERROR
) << "WebContentsDelegate::CheckMediaAccessPermission: "
198 bool WebContentsDelegate::RequestPpapiBrokerPermission(
199 WebContents
* web_contents
,
201 const base::FilePath
& plugin_path
,
202 const base::Callback
<void(bool)>& callback
) {
206 WebContentsDelegate::~WebContentsDelegate() {
207 while (!attached_contents_
.empty()) {
208 WebContents
* web_contents
= *attached_contents_
.begin();
209 web_contents
->SetDelegate(nullptr);
211 DCHECK(attached_contents_
.empty());
214 void WebContentsDelegate::Attach(WebContents
* web_contents
) {
215 DCHECK(attached_contents_
.find(web_contents
) == attached_contents_
.end());
216 attached_contents_
.insert(web_contents
);
219 void WebContentsDelegate::Detach(WebContents
* web_contents
) {
220 DCHECK(attached_contents_
.find(web_contents
) != attached_contents_
.end());
221 attached_contents_
.erase(web_contents
);
224 gfx::Size
WebContentsDelegate::GetSizeForNewRenderView(
225 WebContents
* web_contents
) const {
229 bool WebContentsDelegate::IsNeverVisible(WebContents
* web_contents
) {
233 bool WebContentsDelegate::SaveFrame(const GURL
& url
, const Referrer
& referrer
) {
237 SecurityStyle
WebContentsDelegate::GetSecurityStyle(
238 WebContents
* web_contents
,
239 SecurityStyleExplanations
* security_style_explanations
) {
240 return content::SECURITY_STYLE_UNKNOWN
;
243 } // namespace content