web_contents_delegate.cc revision 0529e5d033099cbfc42635f6f6183833b09dff6e
15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/web_contents_delegate.h" 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/compiler_specific.h" 85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/logging.h" 95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/memory/singleton.h" 105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/render_view_host.h" 112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "content/public/browser/web_contents.h" 12cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "content/public/common/url_constants.h" 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/common/bindings_policy.h" 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/gfx/rect.h" 15c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 16c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)namespace content { 175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)WebContentsDelegate::WebContentsDelegate() { 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)WebContents* WebContentsDelegate::OpenURLFromTab(WebContents* source, 222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const OpenURLParams& params) { 23a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) return NULL; 242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 26c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)bool WebContentsDelegate::IsPopupOrPanel(const WebContents* source) const { 272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return false; 28c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)} 295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool WebContentsDelegate::CanOverscrollContent() const { return false; } 315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)gfx::Rect WebContentsDelegate::GetRootWindowResizerRect() const { 335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return gfx::Rect(); 345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool WebContentsDelegate::ShouldSuppressDialogs() { 375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return false; 385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool WebContentsDelegate::ShouldPreserveAbortedURLs(WebContents* source) { 415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return false; 42a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)} 43a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool WebContentsDelegate::AddMessageToConsole(WebContents* source, 455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int32 level, 465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const base::string16& message, 475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int32 line_no, 485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const base::string16& source_id) { 495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return false; 505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void WebContentsDelegate::BeforeUnloadFired(WebContents* web_contents, 535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool proceed, 545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool* proceed_to_fire_unload) { 552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) *proceed_to_fire_unload = true; 565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool WebContentsDelegate::ShouldFocusLocationBarByDefault(WebContents* source) { 595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return false; 605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool WebContentsDelegate::ShouldFocusPageAfterCrash() { 637dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch return true; 645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)bool WebContentsDelegate::TakeFocus(WebContents* source, bool reverse) { 672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return false; 682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 70cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)int WebContentsDelegate::GetExtraRenderViewHeight() const { 715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return 0; 725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void WebContentsDelegate::CanDownload( 755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) RenderViewHost* render_view_host, 765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int request_id, 775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const std::string& request_method, 785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const base::Callback<void(bool)>& callback) { 795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) callback.Run(true); 805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 82a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)bool WebContentsDelegate::HandleContextMenu( 83a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) const content::ContextMenuParams& params) { 845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return false; 855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void WebContentsDelegate::ViewSourceForTab(WebContents* source, 885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const GURL& page_url) { 895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // 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(), 94 NEW_FOREGROUND_TAB, 95 PAGE_TRANSITION_LINK, false)); 96} 97 98void 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(), 104 NEW_FOREGROUND_TAB, 105 PAGE_TRANSITION_LINK, false)); 106} 107 108bool WebContentsDelegate::PreHandleKeyboardEvent( 109 WebContents* source, 110 const NativeWebKeyboardEvent& event, 111 bool* is_keyboard_shortcut) { 112 return false; 113} 114 115bool WebContentsDelegate::PreHandleGestureEvent( 116 WebContents* source, 117 const blink::WebGestureEvent& event) { 118 return false; 119} 120 121bool WebContentsDelegate::CanDragEnter( 122 WebContents* source, 123 const DropData& data, 124 blink::WebDragOperationsMask operations_allowed) { 125 return true; 126} 127 128bool WebContentsDelegate::OnGoToEntryOffset(int offset) { 129 return true; 130} 131 132bool WebContentsDelegate::ShouldCreateWebContents( 133 WebContents* web_contents, 134 int route_id, 135 WindowContainerType window_container_type, 136 const base::string16& frame_name, 137 const GURL& target_url, 138 const std::string& partition_id, 139 SessionStorageNamespace* session_storage_namespace) { 140 return true; 141} 142 143JavaScriptDialogManager* WebContentsDelegate::GetJavaScriptDialogManager() { 144 return NULL; 145} 146 147bool WebContentsDelegate::EmbedsFullscreenWidget() const { 148 return false; 149} 150 151bool WebContentsDelegate::IsFullscreenForTabOrPending( 152 const WebContents* web_contents) const { 153 return false; 154} 155 156content::ColorChooser* WebContentsDelegate::OpenColorChooser( 157 WebContents* web_contents, 158 SkColor color, 159 const std::vector<ColorSuggestion>& suggestions) { 160 return NULL; 161} 162 163void WebContentsDelegate::RequestMediaAccessPermission( 164 WebContents* web_contents, 165 const MediaStreamRequest& request, 166 const MediaResponseCallback& callback) { 167 callback.Run(MediaStreamDevices(), 168 MEDIA_DEVICE_INVALID_STATE, 169 scoped_ptr<MediaStreamUI>()); 170} 171 172bool WebContentsDelegate::RequestPpapiBrokerPermission( 173 WebContents* web_contents, 174 const GURL& url, 175 const base::FilePath& plugin_path, 176 const base::Callback<void(bool)>& callback) { 177 return false; 178} 179 180WebContentsDelegate::~WebContentsDelegate() { 181 while (!attached_contents_.empty()) { 182 WebContents* web_contents = *attached_contents_.begin(); 183 web_contents->SetDelegate(NULL); 184 } 185 DCHECK(attached_contents_.empty()); 186} 187 188void WebContentsDelegate::Attach(WebContents* web_contents) { 189 DCHECK(attached_contents_.find(web_contents) == attached_contents_.end()); 190 attached_contents_.insert(web_contents); 191} 192 193void WebContentsDelegate::Detach(WebContents* web_contents) { 194 DCHECK(attached_contents_.find(web_contents) != attached_contents_.end()); 195 attached_contents_.erase(web_contents); 196} 197 198gfx::Size WebContentsDelegate::GetSizeForNewRenderView( 199 const WebContents* web_contents) const { 200 return gfx::Size(); 201} 202 203bool WebContentsDelegate::IsNeverVisible(WebContents* web_contents) { 204 return false; 205} 206 207} // namespace content 208