• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
16 namespace content {
17 
WebContentsDelegate()18 WebContentsDelegate::WebContentsDelegate() {
19 }
20 
OpenURLFromTab(WebContents * source,const OpenURLParams & params)21 WebContents* WebContentsDelegate::OpenURLFromTab(WebContents* source,
22                                                  const OpenURLParams& params) {
23   return NULL;
24 }
25 
IsPopupOrPanel(const WebContents * source) const26 bool WebContentsDelegate::IsPopupOrPanel(const WebContents* source) const {
27   return false;
28 }
29 
CanOverscrollContent() const30 bool WebContentsDelegate::CanOverscrollContent() const { return false; }
31 
GetRootWindowResizerRect() const32 gfx::Rect WebContentsDelegate::GetRootWindowResizerRect() const {
33   return gfx::Rect();
34 }
35 
ShouldSuppressDialogs()36 bool WebContentsDelegate::ShouldSuppressDialogs() {
37   return false;
38 }
39 
ShouldPreserveAbortedURLs(WebContents * source)40 bool WebContentsDelegate::ShouldPreserveAbortedURLs(WebContents* source) {
41   return false;
42 }
43 
AddMessageToConsole(WebContents * source,int32 level,const base::string16 & message,int32 line_no,const base::string16 & source_id)44 bool WebContentsDelegate::AddMessageToConsole(WebContents* source,
45                                               int32 level,
46                                               const base::string16& message,
47                                               int32 line_no,
48                                               const base::string16& source_id) {
49   return false;
50 }
51 
BeforeUnloadFired(WebContents * web_contents,bool proceed,bool * proceed_to_fire_unload)52 void WebContentsDelegate::BeforeUnloadFired(WebContents* web_contents,
53                                             bool proceed,
54                                             bool* proceed_to_fire_unload) {
55   *proceed_to_fire_unload = true;
56 }
57 
ShouldFocusLocationBarByDefault(WebContents * source)58 bool WebContentsDelegate::ShouldFocusLocationBarByDefault(WebContents* source) {
59   return false;
60 }
61 
ShouldFocusPageAfterCrash()62 bool WebContentsDelegate::ShouldFocusPageAfterCrash() {
63   return true;
64 }
65 
TakeFocus(WebContents * source,bool reverse)66 bool WebContentsDelegate::TakeFocus(WebContents* source, bool reverse) {
67   return false;
68 }
69 
GetExtraRenderViewHeight() const70 int WebContentsDelegate::GetExtraRenderViewHeight() const {
71   return 0;
72 }
73 
CanDownload(RenderViewHost * render_view_host,const GURL & url,const std::string & request_method,const base::Callback<void (bool)> & callback)74 void WebContentsDelegate::CanDownload(
75     RenderViewHost* render_view_host,
76     const GURL& url,
77     const std::string& request_method,
78     const base::Callback<void(bool)>& callback) {
79   callback.Run(true);
80 }
81 
HandleContextMenu(const content::ContextMenuParams & params)82 bool WebContentsDelegate::HandleContextMenu(
83     const content::ContextMenuParams& params) {
84   return false;
85 }
86 
ViewSourceForTab(WebContents * source,const GURL & page_url)87 void WebContentsDelegate::ViewSourceForTab(WebContents* source,
88                                            const GURL& page_url) {
89   // 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                                        ui::PAGE_TRANSITION_LINK, false));
96 }
97 
ViewSourceForFrame(WebContents * source,const GURL & frame_url,const PageState & page_state)98 void 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                                        ui::PAGE_TRANSITION_LINK, false));
106 }
107 
PreHandleKeyboardEvent(WebContents * source,const NativeWebKeyboardEvent & event,bool * is_keyboard_shortcut)108 bool WebContentsDelegate::PreHandleKeyboardEvent(
109     WebContents* source,
110     const NativeWebKeyboardEvent& event,
111     bool* is_keyboard_shortcut) {
112   return false;
113 }
114 
PreHandleGestureEvent(WebContents * source,const blink::WebGestureEvent & event)115 bool WebContentsDelegate::PreHandleGestureEvent(
116     WebContents* source,
117     const blink::WebGestureEvent& event) {
118   return false;
119 }
120 
CanDragEnter(WebContents * source,const DropData & data,blink::WebDragOperationsMask operations_allowed)121 bool WebContentsDelegate::CanDragEnter(
122     WebContents* source,
123     const DropData& data,
124     blink::WebDragOperationsMask operations_allowed) {
125   return true;
126 }
127 
OnGoToEntryOffset(int offset)128 bool WebContentsDelegate::OnGoToEntryOffset(int offset) {
129   return true;
130 }
131 
ShouldCreateWebContents(WebContents * web_contents,int route_id,WindowContainerType window_container_type,const base::string16 & frame_name,const GURL & target_url,const std::string & partition_id,SessionStorageNamespace * session_storage_namespace)132 bool 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 
GetJavaScriptDialogManager()143 JavaScriptDialogManager* WebContentsDelegate::GetJavaScriptDialogManager() {
144   return NULL;
145 }
146 
EmbedsFullscreenWidget() const147 bool WebContentsDelegate::EmbedsFullscreenWidget() const {
148   return false;
149 }
150 
IsFullscreenForTabOrPending(const WebContents * web_contents) const151 bool WebContentsDelegate::IsFullscreenForTabOrPending(
152     const WebContents* web_contents) const {
153   return false;
154 }
155 
OpenColorChooser(WebContents * web_contents,SkColor color,const std::vector<ColorSuggestion> & suggestions)156 content::ColorChooser* WebContentsDelegate::OpenColorChooser(
157     WebContents* web_contents,
158     SkColor color,
159     const std::vector<ColorSuggestion>& suggestions) {
160   return NULL;
161 }
162 
RequestMediaAccessPermission(WebContents * web_contents,const MediaStreamRequest & request,const MediaResponseCallback & callback)163 void WebContentsDelegate::RequestMediaAccessPermission(
164     WebContents* web_contents,
165     const MediaStreamRequest& request,
166     const MediaResponseCallback& callback) {
167   LOG(ERROR) << "WebContentsDelegate::RequestMediaAccessPermission: "
168              << "Not supported.";
169   callback.Run(MediaStreamDevices(),
170                MEDIA_DEVICE_NOT_SUPPORTED,
171                scoped_ptr<MediaStreamUI>());
172 }
173 
CheckMediaAccessPermission(WebContents * web_contents,const GURL & security_origin,MediaStreamType type)174 bool WebContentsDelegate::CheckMediaAccessPermission(
175     WebContents* web_contents,
176     const GURL& security_origin,
177     MediaStreamType type) {
178   LOG(ERROR) << "WebContentsDelegate::CheckMediaAccessPermission: "
179              << "Not supported.";
180   return false;
181 }
182 
RequestPpapiBrokerPermission(WebContents * web_contents,const GURL & url,const base::FilePath & plugin_path,const base::Callback<void (bool)> & callback)183 bool WebContentsDelegate::RequestPpapiBrokerPermission(
184     WebContents* web_contents,
185     const GURL& url,
186     const base::FilePath& plugin_path,
187     const base::Callback<void(bool)>& callback) {
188   return false;
189 }
190 
~WebContentsDelegate()191 WebContentsDelegate::~WebContentsDelegate() {
192   while (!attached_contents_.empty()) {
193     WebContents* web_contents = *attached_contents_.begin();
194     web_contents->SetDelegate(NULL);
195   }
196   DCHECK(attached_contents_.empty());
197 }
198 
Attach(WebContents * web_contents)199 void WebContentsDelegate::Attach(WebContents* web_contents) {
200   DCHECK(attached_contents_.find(web_contents) == attached_contents_.end());
201   attached_contents_.insert(web_contents);
202 }
203 
Detach(WebContents * web_contents)204 void WebContentsDelegate::Detach(WebContents* web_contents) {
205   DCHECK(attached_contents_.find(web_contents) != attached_contents_.end());
206   attached_contents_.erase(web_contents);
207 }
208 
GetSizeForNewRenderView(WebContents * web_contents) const209 gfx::Size WebContentsDelegate::GetSizeForNewRenderView(
210    WebContents* web_contents) const {
211   return gfx::Size();
212 }
213 
IsNeverVisible(WebContents * web_contents)214 bool WebContentsDelegate::IsNeverVisible(WebContents* web_contents) {
215   return false;
216 }
217 
218 }  // namespace content
219