Popular sites on the NTP: Try to keep the ordering constant
[chromium-blink-merge.git] / content / public / browser / web_contents_delegate.cc
blob016097b3ab17b8ea94dac0a1a4a43789d0b306e7
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"
18 namespace content {
20 WebContentsDelegate::WebContentsDelegate() {
23 WebContents* WebContentsDelegate::OpenURLFromTab(WebContents* source,
24 const OpenURLParams& params) {
25 return nullptr;
28 bool WebContentsDelegate::IsPopupOrPanel(const WebContents* source) const {
29 return false;
32 bool WebContentsDelegate::CanOverscrollContent() const { return false; }
34 gfx::Rect WebContentsDelegate::GetRootWindowResizerRect() const {
35 return gfx::Rect();
38 bool WebContentsDelegate::ShouldSuppressDialogs(WebContents* source) {
39 return false;
42 bool WebContentsDelegate::ShouldPreserveAbortedURLs(WebContents* source) {
43 return false;
46 bool WebContentsDelegate::AddMessageToConsole(WebContents* source,
47 int32 level,
48 const base::string16& message,
49 int32 line_no,
50 const base::string16& source_id) {
51 return false;
54 void WebContentsDelegate::BeforeUnloadFired(WebContents* web_contents,
55 bool proceed,
56 bool* proceed_to_fire_unload) {
57 *proceed_to_fire_unload = true;
60 bool WebContentsDelegate::ShouldFocusLocationBarByDefault(WebContents* source) {
61 return false;
64 bool WebContentsDelegate::ShouldFocusPageAfterCrash() {
65 return true;
68 bool WebContentsDelegate::ShouldResumeRequestsForCreatedWindow() {
69 return true;
72 bool WebContentsDelegate::TakeFocus(WebContents* source, bool reverse) {
73 return false;
76 void WebContentsDelegate::CanDownload(
77 const GURL& url,
78 const std::string& request_method,
79 const base::Callback<void(bool)>& callback) {
80 callback.Run(true);
83 bool WebContentsDelegate::HandleContextMenu(
84 const content::ContextMenuParams& params) {
85 return false;
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(),
95 NEW_FOREGROUND_TAB,
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(),
105 NEW_FOREGROUND_TAB,
106 ui::PAGE_TRANSITION_LINK, false));
109 bool WebContentsDelegate::PreHandleKeyboardEvent(
110 WebContents* source,
111 const NativeWebKeyboardEvent& event,
112 bool* is_keyboard_shortcut) {
113 return false;
116 bool WebContentsDelegate::PreHandleGestureEvent(
117 WebContents* source,
118 const blink::WebGestureEvent& event) {
119 return false;
122 bool WebContentsDelegate::CanDragEnter(
123 WebContents* source,
124 const DropData& data,
125 blink::WebDragOperationsMask operations_allowed) {
126 return true;
129 bool WebContentsDelegate::OnGoToEntryOffset(int offset) {
130 return true;
133 bool WebContentsDelegate::ShouldCreateWebContents(
134 WebContents* web_contents,
135 int route_id,
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) {
142 return true;
145 JavaScriptDialogManager* WebContentsDelegate::GetJavaScriptDialogManager(
146 WebContents* source) {
147 return nullptr;
150 bool WebContentsDelegate::EmbedsFullscreenWidget() const {
151 return false;
154 bool WebContentsDelegate::IsFullscreenForTabOrPending(
155 const WebContents* web_contents) const {
156 return false;
159 blink::WebDisplayMode WebContentsDelegate::GetDisplayMode(
160 const WebContents* web_contents) const {
161 return blink::WebDisplayModeBrowser;
164 content::ColorChooser* WebContentsDelegate::OpenColorChooser(
165 WebContents* web_contents,
166 SkColor color,
167 const std::vector<ColorSuggestion>& suggestions) {
168 return nullptr;
171 void WebContentsDelegate::RequestMediaAccessPermission(
172 WebContents* web_contents,
173 const MediaStreamRequest& request,
174 const MediaResponseCallback& callback) {
175 LOG(ERROR) << "WebContentsDelegate::RequestMediaAccessPermission: "
176 << "Not supported.";
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: "
187 << "Not supported.";
188 return false;
191 bool WebContentsDelegate::RequestPpapiBrokerPermission(
192 WebContents* web_contents,
193 const GURL& url,
194 const base::FilePath& plugin_path,
195 const base::Callback<void(bool)>& callback) {
196 return false;
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 {
219 return gfx::Size();
222 bool WebContentsDelegate::IsNeverVisible(WebContents* web_contents) {
223 return false;
226 bool WebContentsDelegate::SaveFrame(const GURL& url, const Referrer& referrer) {
227 return false;
230 SecurityStyle WebContentsDelegate::GetSecurityStyle(
231 WebContents* web_contents,
232 SecurityStyleExplanations* security_style_explanations) {
233 return content::SECURITY_STYLE_UNKNOWN;
236 } // namespace content