web_contents_delegate.cc revision 5d1f7b1de12d16ceb2c938c56701a3e8bfa558f7
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::CanOverscrollContent() const { return false; } 31 32gfx::Rect WebContentsDelegate::GetRootWindowResizerRect() const { 33 return gfx::Rect(); 34} 35 36bool WebContentsDelegate::ShouldSuppressDialogs() { 37 return false; 38} 39 40bool WebContentsDelegate::AddMessageToConsole(WebContents* source, 41 int32 level, 42 const base::string16& message, 43 int32 line_no, 44 const base::string16& source_id) { 45 return false; 46} 47 48void WebContentsDelegate::BeforeUnloadFired(WebContents* web_contents, 49 bool proceed, 50 bool* proceed_to_fire_unload) { 51 *proceed_to_fire_unload = true; 52} 53 54bool WebContentsDelegate::ShouldFocusLocationBarByDefault(WebContents* source) { 55 return false; 56} 57 58bool WebContentsDelegate::ShouldFocusPageAfterCrash() { 59 return true; 60} 61 62bool WebContentsDelegate::TakeFocus(WebContents* source, bool reverse) { 63 return false; 64} 65 66int WebContentsDelegate::GetExtraRenderViewHeight() const { 67 return 0; 68} 69 70void WebContentsDelegate::CanDownload( 71 RenderViewHost* render_view_host, 72 int request_id, 73 const std::string& request_method, 74 const base::Callback<void(bool)>& callback) { 75 callback.Run(true); 76} 77 78bool WebContentsDelegate::HandleContextMenu( 79 const content::ContextMenuParams& params) { 80 return false; 81} 82 83void WebContentsDelegate::ViewSourceForTab(WebContents* source, 84 const GURL& page_url) { 85 // Fall back implementation based entirely on the view-source scheme. 86 // It suffers from http://crbug.com/523 and that is why browser overrides 87 // it with proper implementation. 88 GURL url = GURL(kViewSourceScheme + std::string(":") + page_url.spec()); 89 OpenURLFromTab(source, OpenURLParams(url, Referrer(), 90 NEW_FOREGROUND_TAB, 91 PAGE_TRANSITION_LINK, false)); 92} 93 94void WebContentsDelegate::ViewSourceForFrame(WebContents* source, 95 const GURL& frame_url, 96 const PageState& page_state) { 97 // Same as ViewSourceForTab, but for given subframe. 98 GURL url = GURL(kViewSourceScheme + std::string(":") + frame_url.spec()); 99 OpenURLFromTab(source, OpenURLParams(url, Referrer(), 100 NEW_FOREGROUND_TAB, 101 PAGE_TRANSITION_LINK, false)); 102} 103 104bool WebContentsDelegate::PreHandleKeyboardEvent( 105 WebContents* source, 106 const NativeWebKeyboardEvent& event, 107 bool* is_keyboard_shortcut) { 108 return false; 109} 110 111bool WebContentsDelegate::PreHandleGestureEvent( 112 WebContents* source, 113 const blink::WebGestureEvent& event) { 114 return false; 115} 116 117bool WebContentsDelegate::CanDragEnter( 118 WebContents* source, 119 const DropData& data, 120 blink::WebDragOperationsMask operations_allowed) { 121 return true; 122} 123 124bool WebContentsDelegate::OnGoToEntryOffset(int offset) { 125 return true; 126} 127 128bool WebContentsDelegate::ShouldCreateWebContents( 129 WebContents* web_contents, 130 int route_id, 131 WindowContainerType window_container_type, 132 const base::string16& frame_name, 133 const GURL& target_url, 134 const std::string& partition_id, 135 SessionStorageNamespace* session_storage_namespace) { 136 return true; 137} 138 139JavaScriptDialogManager* WebContentsDelegate::GetJavaScriptDialogManager() { 140 return NULL; 141} 142 143bool WebContentsDelegate::EmbedsFullscreenWidget() const { 144 return false; 145} 146 147bool WebContentsDelegate::IsFullscreenForTabOrPending( 148 const WebContents* web_contents) const { 149 return false; 150} 151 152content::ColorChooser* WebContentsDelegate::OpenColorChooser( 153 WebContents* web_contents, 154 SkColor color, 155 const std::vector<ColorSuggestion>& suggestions) { 156 return NULL; 157} 158 159void WebContentsDelegate::RequestMediaAccessPermission( 160 WebContents* web_contents, 161 const MediaStreamRequest& request, 162 const MediaResponseCallback& callback) { 163 callback.Run(MediaStreamDevices(), scoped_ptr<MediaStreamUI>()); 164} 165 166bool WebContentsDelegate::RequestPpapiBrokerPermission( 167 WebContents* web_contents, 168 const GURL& url, 169 const base::FilePath& plugin_path, 170 const base::Callback<void(bool)>& callback) { 171 return false; 172} 173 174WebContentsDelegate::~WebContentsDelegate() { 175 while (!attached_contents_.empty()) { 176 WebContents* web_contents = *attached_contents_.begin(); 177 web_contents->SetDelegate(NULL); 178 } 179 DCHECK(attached_contents_.empty()); 180} 181 182void WebContentsDelegate::Attach(WebContents* web_contents) { 183 DCHECK(attached_contents_.find(web_contents) == attached_contents_.end()); 184 attached_contents_.insert(web_contents); 185} 186 187void WebContentsDelegate::Detach(WebContents* web_contents) { 188 DCHECK(attached_contents_.find(web_contents) != attached_contents_.end()); 189 attached_contents_.erase(web_contents); 190} 191 192gfx::Size WebContentsDelegate::GetSizeForNewRenderView( 193 const WebContents* web_contents) const { 194 return gfx::Size(); 195} 196 197} // namespace content 198