Clang roll script: fix error when GYP_DEFINES isn't defined
[chromium-blink-merge.git] / content / browser / web_contents / web_contents_impl.h
blobf5cfd31522d91731e0996f447482aeb0c1382dbd
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 #ifndef CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_IMPL_H_
6 #define CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_IMPL_H_
8 #include <map>
9 #include <set>
10 #include <string>
12 #include "base/compiler_specific.h"
13 #include "base/gtest_prod_util.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/observer_list.h"
16 #include "base/process/process.h"
17 #include "base/values.h"
18 #include "content/browser/frame_host/frame_tree.h"
19 #include "content/browser/frame_host/navigation_controller_delegate.h"
20 #include "content/browser/frame_host/navigation_controller_impl.h"
21 #include "content/browser/frame_host/navigator_delegate.h"
22 #include "content/browser/frame_host/render_frame_host_delegate.h"
23 #include "content/browser/frame_host/render_frame_host_manager.h"
24 #include "content/browser/renderer_host/render_view_host_delegate.h"
25 #include "content/browser/renderer_host/render_widget_host_delegate.h"
26 #include "content/common/content_export.h"
27 #include "content/public/browser/notification_observer.h"
28 #include "content/public/browser/notification_registrar.h"
29 #include "content/public/browser/web_contents.h"
30 #include "content/public/common/page_transition_types.h"
31 #include "content/public/common/renderer_preferences.h"
32 #include "content/public/common/three_d_api_types.h"
33 #include "net/base/load_states.h"
34 #include "third_party/WebKit/public/web/WebDragOperation.h"
35 #include "ui/gfx/rect_f.h"
36 #include "ui/gfx/size.h"
37 #include "webkit/common/resource_type.h"
39 struct BrowserPluginHostMsg_ResizeGuest_Params;
40 struct ViewHostMsg_DateTimeDialogValue_Params;
41 struct ViewMsg_PostMessage_Params;
43 namespace content {
44 class BrowserPluginEmbedder;
45 class BrowserPluginGuest;
46 class BrowserPluginGuestManager;
47 class ColorChooser;
48 class DateTimeChooserAndroid;
49 class DownloadItem;
50 class InterstitialPageImpl;
51 class JavaBridgeDispatcherHostManager;
52 class JavaScriptDialogManager;
53 class PowerSaveBlocker;
54 class RenderViewHost;
55 class RenderViewHostDelegateView;
56 class RenderViewHostImpl;
57 class RenderWidgetHostImpl;
58 class RenderWidgetHostViewPort;
59 class SavePackage;
60 class SessionStorageNamespaceImpl;
61 class SiteInstance;
62 class TestWebContents;
63 class WebContentsDelegate;
64 class WebContentsImpl;
65 class WebContentsObserver;
66 class WebContentsViewPort;
67 class WebContentsViewDelegate;
68 struct ColorSuggestion;
69 struct FaviconURL;
70 struct LoadNotificationDetails;
71 struct ResourceRedirectDetails;
72 struct ResourceRequestDetails;
74 // Factory function for the implementations that content knows about. Takes
75 // ownership of |delegate|.
76 WebContentsViewPort* CreateWebContentsView(
77 WebContentsImpl* web_contents,
78 WebContentsViewDelegate* delegate,
79 RenderViewHostDelegateView** render_view_host_delegate_view);
81 class CONTENT_EXPORT WebContentsImpl
82 : public NON_EXPORTED_BASE(WebContents),
83 public NON_EXPORTED_BASE(RenderFrameHostDelegate),
84 public RenderViewHostDelegate,
85 public RenderWidgetHostDelegate,
86 public RenderFrameHostManager::Delegate,
87 public NotificationObserver,
88 public NON_EXPORTED_BASE(NavigationControllerDelegate),
89 public NON_EXPORTED_BASE(NavigatorDelegate) {
90 public:
91 virtual ~WebContentsImpl();
93 static WebContentsImpl* CreateWithOpener(
94 const WebContents::CreateParams& params,
95 WebContentsImpl* opener);
97 // Returns the opener WebContentsImpl, if any. This can be set to null if the
98 // opener is closed or the page clears its window.opener.
99 WebContentsImpl* opener() const { return opener_; }
101 // Creates a WebContents to be used as a browser plugin guest.
102 static BrowserPluginGuest* CreateGuest(
103 BrowserContext* browser_context,
104 content::SiteInstance* site_instance,
105 int guest_instance_id,
106 scoped_ptr<base::DictionaryValue> extra_params);
108 // Creates a swapped out RenderView. This is used by the browser plugin to
109 // create a swapped out RenderView in the embedder render process for the
110 // guest, to expose the guest's window object to the embedder.
111 // This returns the routing ID of the newly created swapped out RenderView.
112 int CreateSwappedOutRenderView(SiteInstance* instance);
114 // Complex initialization here. Specifically needed to avoid having
115 // members call back into our virtual functions in the constructor.
116 virtual void Init(const WebContents::CreateParams& params);
118 // Returns the SavePackage which manages the page saving job. May be NULL.
119 SavePackage* save_package() const { return save_package_.get(); }
121 #if defined(OS_ANDROID)
122 JavaBridgeDispatcherHostManager* java_bridge_dispatcher_host_manager() const {
123 return java_bridge_dispatcher_host_manager_.get();
126 // In Android WebView, the RenderView needs created even there is no
127 // navigation entry, this allows Android WebViews to use
128 // javascript: URLs that load into the DOMWindow before the first page
129 // load. This is not safe to do in any context that a web page could get a
130 // reference to the DOMWindow before the first page load.
131 bool CreateRenderViewForInitialEmptyDocument();
132 #endif
134 // Expose the render manager for testing.
135 RenderFrameHostManager* GetRenderManagerForTesting();
137 // Returns guest browser plugin object, or NULL if this WebContents is not a
138 // guest.
139 BrowserPluginGuest* GetBrowserPluginGuest() const;
141 // Sets a BrowserPluginGuest object for this WebContents. If this WebContents
142 // has a BrowserPluginGuest then that implies that it is being hosted by
143 // a BrowserPlugin object in an embedder renderer process.
144 void SetBrowserPluginGuest(BrowserPluginGuest* guest);
146 // Returns embedder browser plugin object, or NULL if this WebContents is not
147 // an embedder.
148 BrowserPluginEmbedder* GetBrowserPluginEmbedder() const;
150 // Returns the BrowserPluginGuestManager object, or NULL if this web contents
151 // does not have a BrowserPluginGuestManager.
152 BrowserPluginGuestManager* GetBrowserPluginGuestManager() const;
154 // Gets the current fullscreen render widget's routing ID. Returns
155 // MSG_ROUTING_NONE when there is no fullscreen render widget.
156 int GetFullscreenWidgetRoutingID() const;
158 // Invoked when visible SSL state (as defined by SSLStatus) changes.
159 void DidChangeVisibleSSLState();
161 // Informs the render view host and the BrowserPluginEmbedder, if present, of
162 // a Drag Source End.
163 void DragSourceEndedAt(int client_x, int client_y, int screen_x,
164 int screen_y, blink::WebDragOperation operation);
166 // Informs the render view host and the BrowserPluginEmbedder, if present, of
167 // a Drag Source Move.
168 void DragSourceMovedTo(int client_x, int client_y,
169 int screen_x, int screen_y);
171 // A response has been received for a resource request.
172 void DidGetResourceResponseStart(
173 const ResourceRequestDetails& details);
175 // A redirect was received while requesting a resource.
176 void DidGetRedirectForResourceRequest(
177 RenderViewHost* render_view_host,
178 const ResourceRedirectDetails& details);
180 // WebContents ------------------------------------------------------
181 virtual WebContentsDelegate* GetDelegate() OVERRIDE;
182 virtual void SetDelegate(WebContentsDelegate* delegate) OVERRIDE;
183 virtual NavigationControllerImpl& GetController() OVERRIDE;
184 virtual const NavigationControllerImpl& GetController() const OVERRIDE;
185 virtual BrowserContext* GetBrowserContext() const OVERRIDE;
186 virtual RenderProcessHost* GetRenderProcessHost() const OVERRIDE;
187 virtual RenderFrameHost* GetMainFrame() OVERRIDE;
188 virtual void ForEachFrame(
189 const base::Callback<void(RenderFrameHost*)>& on_frame) OVERRIDE;
190 virtual void SendToAllFrames(IPC::Message* message) OVERRIDE;
191 virtual RenderViewHost* GetRenderViewHost() const OVERRIDE;
192 virtual void GetRenderViewHostAtPosition(
193 int x,
194 int y,
195 const GetRenderViewHostCallback& callback) OVERRIDE;
196 virtual WebContents* GetEmbedderWebContents() const OVERRIDE;
197 virtual int GetEmbeddedInstanceID() const OVERRIDE;
198 virtual int GetRoutingID() const OVERRIDE;
199 virtual RenderWidgetHostView* GetRenderWidgetHostView() const OVERRIDE;
200 virtual RenderWidgetHostView* GetFullscreenRenderWidgetHostView() const
201 OVERRIDE;
202 virtual WebContentsView* GetView() const OVERRIDE;
203 virtual WebUI* CreateWebUI(const GURL& url) OVERRIDE;
204 virtual WebUI* GetWebUI() const OVERRIDE;
205 virtual WebUI* GetCommittedWebUI() const OVERRIDE;
206 virtual void SetUserAgentOverride(const std::string& override) OVERRIDE;
207 virtual const std::string& GetUserAgentOverride() const OVERRIDE;
208 #if defined(OS_WIN)
209 virtual void SetParentNativeViewAccessible(
210 gfx::NativeViewAccessible accessible_parent) OVERRIDE;
211 #endif
212 virtual const base::string16& GetTitle() const OVERRIDE;
213 virtual int32 GetMaxPageID() OVERRIDE;
214 virtual int32 GetMaxPageIDForSiteInstance(
215 SiteInstance* site_instance) OVERRIDE;
216 virtual SiteInstance* GetSiteInstance() const OVERRIDE;
217 virtual SiteInstance* GetPendingSiteInstance() const OVERRIDE;
218 virtual bool IsLoading() const OVERRIDE;
219 virtual bool IsWaitingForResponse() const OVERRIDE;
220 virtual const net::LoadStateWithParam& GetLoadState() const OVERRIDE;
221 virtual const base::string16& GetLoadStateHost() const OVERRIDE;
222 virtual uint64 GetUploadSize() const OVERRIDE;
223 virtual uint64 GetUploadPosition() const OVERRIDE;
224 virtual std::set<GURL> GetSitesInTab() const OVERRIDE;
225 virtual const std::string& GetEncoding() const OVERRIDE;
226 virtual bool DisplayedInsecureContent() const OVERRIDE;
227 virtual void IncrementCapturerCount() OVERRIDE;
228 virtual void DecrementCapturerCount() OVERRIDE;
229 virtual int GetCapturerCount() const OVERRIDE;
230 virtual bool IsCrashed() const OVERRIDE;
231 virtual void SetIsCrashed(base::TerminationStatus status,
232 int error_code) OVERRIDE;
233 virtual base::TerminationStatus GetCrashedStatus() const OVERRIDE;
234 virtual bool IsBeingDestroyed() const OVERRIDE;
235 virtual void NotifyNavigationStateChanged(unsigned changed_flags) OVERRIDE;
236 virtual base::TimeTicks GetLastSelectedTime() const OVERRIDE;
237 virtual void WasShown() OVERRIDE;
238 virtual void WasHidden() OVERRIDE;
239 virtual bool NeedToFireBeforeUnload() OVERRIDE;
240 virtual void Stop() OVERRIDE;
241 virtual WebContents* Clone() OVERRIDE;
242 virtual void FocusThroughTabTraversal(bool reverse) OVERRIDE;
243 virtual bool ShowingInterstitialPage() const OVERRIDE;
244 virtual InterstitialPage* GetInterstitialPage() const OVERRIDE;
245 virtual bool IsSavable() OVERRIDE;
246 virtual void OnSavePage() OVERRIDE;
247 virtual bool SavePage(const base::FilePath& main_file,
248 const base::FilePath& dir_path,
249 SavePageType save_type) OVERRIDE;
250 virtual void SaveFrame(const GURL& url,
251 const Referrer& referrer) OVERRIDE;
252 virtual void GenerateMHTML(
253 const base::FilePath& file,
254 const base::Callback<void(int64)>& callback)
255 OVERRIDE;
256 virtual bool IsActiveEntry(int32 page_id) OVERRIDE;
258 virtual const std::string& GetContentsMimeType() const OVERRIDE;
259 virtual bool WillNotifyDisconnection() const OVERRIDE;
260 virtual void SetOverrideEncoding(const std::string& encoding) OVERRIDE;
261 virtual void ResetOverrideEncoding() OVERRIDE;
262 virtual RendererPreferences* GetMutableRendererPrefs() OVERRIDE;
263 virtual void Close() OVERRIDE;
264 virtual void SystemDragEnded() OVERRIDE;
265 virtual void UserGestureDone() OVERRIDE;
266 virtual void SetClosedByUserGesture(bool value) OVERRIDE;
267 virtual bool GetClosedByUserGesture() const OVERRIDE;
268 virtual double GetZoomLevel() const OVERRIDE;
269 virtual int GetZoomPercent(bool* enable_increment,
270 bool* enable_decrement) const OVERRIDE;
271 virtual void ViewSource() OVERRIDE;
272 virtual void ViewFrameSource(const GURL& url,
273 const PageState& page_state) OVERRIDE;
274 virtual int GetMinimumZoomPercent() const OVERRIDE;
275 virtual int GetMaximumZoomPercent() const OVERRIDE;
276 virtual gfx::Size GetPreferredSize() const OVERRIDE;
277 virtual bool GotResponseToLockMouseRequest(bool allowed) OVERRIDE;
278 virtual bool HasOpener() const OVERRIDE;
279 virtual void DidChooseColorInColorChooser(SkColor color) OVERRIDE;
280 virtual void DidEndColorChooser() OVERRIDE;
281 virtual int DownloadImage(const GURL& url,
282 bool is_favicon,
283 uint32_t max_bitmap_size,
284 const ImageDownloadCallback& callback) OVERRIDE;
285 virtual bool IsSubframe() const OVERRIDE;
286 virtual void Find(int request_id,
287 const base::string16& search_text,
288 const blink::WebFindOptions& options) OVERRIDE;
289 virtual void SetZoomLevel(double level) OVERRIDE;
290 virtual void StopFinding(StopFindAction action) OVERRIDE;
291 #if defined(OS_ANDROID)
292 virtual base::android::ScopedJavaLocalRef<jobject> GetJavaWebContents()
293 OVERRIDE;
294 #endif
296 // Implementation of PageNavigator.
297 virtual WebContents* OpenURL(const OpenURLParams& params) OVERRIDE;
299 // Implementation of IPC::Sender.
300 virtual bool Send(IPC::Message* message) OVERRIDE;
302 // RenderFrameHostDelegate ---------------------------------------------------
303 virtual bool OnMessageReceived(RenderFrameHost* render_frame_host,
304 const IPC::Message& message) OVERRIDE;
305 virtual void RenderFrameCreated(RenderFrameHost* render_frame_host) OVERRIDE;
306 virtual void RenderFrameDeleted(RenderFrameHost* render_frame_host) OVERRIDE;
307 virtual void WorkerCrashed() OVERRIDE;
308 virtual WebContents* GetAsWebContents() OVERRIDE;
310 // RenderViewHostDelegate ----------------------------------------------------
311 virtual RenderViewHostDelegateView* GetDelegateView() OVERRIDE;
312 virtual RenderViewHostDelegate::RendererManagement*
313 GetRendererManagementDelegate() OVERRIDE;
314 virtual bool OnMessageReceived(RenderViewHost* render_view_host,
315 const IPC::Message& message) OVERRIDE;
316 virtual const GURL& GetURL() const OVERRIDE;
317 virtual const GURL& GetVisibleURL() const OVERRIDE;
318 virtual const GURL& GetLastCommittedURL() const OVERRIDE;
319 // RenderFrameHostDelegate has the same method, so list it there because this
320 // interface is going away.
321 // virtual WebContents* GetAsWebContents() OVERRIDE;
322 virtual gfx::Rect GetRootWindowResizerRect() const OVERRIDE;
323 virtual void RenderViewCreated(RenderViewHost* render_view_host) OVERRIDE;
324 virtual void RenderViewReady(RenderViewHost* render_view_host) OVERRIDE;
325 virtual void RenderViewTerminated(RenderViewHost* render_view_host,
326 base::TerminationStatus status,
327 int error_code) OVERRIDE;
328 virtual void RenderViewDeleted(RenderViewHost* render_view_host) OVERRIDE;
329 virtual void DidNavigate(
330 RenderViewHost* render_view_host,
331 const ViewHostMsg_FrameNavigate_Params& params) OVERRIDE;
332 virtual void UpdateState(RenderViewHost* render_view_host,
333 int32 page_id,
334 const PageState& page_state) OVERRIDE;
335 virtual void UpdateTitle(RenderViewHost* render_view_host,
336 int32 page_id,
337 const base::string16& title,
338 base::i18n::TextDirection title_direction) OVERRIDE;
339 virtual void UpdateEncoding(RenderViewHost* render_view_host,
340 const std::string& encoding) OVERRIDE;
341 virtual void UpdateTargetURL(int32 page_id, const GURL& url) OVERRIDE;
342 virtual void Close(RenderViewHost* render_view_host) OVERRIDE;
343 virtual void RequestMove(const gfx::Rect& new_bounds) OVERRIDE;
344 virtual void SwappedOut(RenderViewHost* render_view_host) OVERRIDE;
345 virtual void DidStartLoading(RenderViewHost* render_view_host) OVERRIDE;
346 virtual void DidStopLoading(RenderViewHost* render_view_host) OVERRIDE;
347 virtual void DidCancelLoading() OVERRIDE;
348 virtual void DidChangeLoadProgress(double progress) OVERRIDE;
349 virtual void DidDisownOpener(RenderViewHost* rvh) OVERRIDE;
350 virtual void DidAccessInitialDocument() OVERRIDE;
351 virtual void DocumentAvailableInMainFrame(
352 RenderViewHost* render_view_host) OVERRIDE;
353 virtual void DocumentOnLoadCompletedInMainFrame(
354 RenderViewHost* render_view_host,
355 int32 page_id) OVERRIDE;
356 virtual void RequestOpenURL(RenderViewHost* rvh,
357 const GURL& url,
358 const Referrer& referrer,
359 WindowOpenDisposition disposition,
360 int64 source_frame_id,
361 bool should_replace_current_entry,
362 bool user_gesture) OVERRIDE;
363 virtual void RequestTransferURL(
364 const GURL& url,
365 const std::vector<GURL>& redirect_chain,
366 const Referrer& referrer,
367 PageTransition page_transition,
368 WindowOpenDisposition disposition,
369 int64 source_frame_id,
370 const GlobalRequestID& transferred_global_request_id,
371 bool should_replace_current_entry,
372 bool user_gesture) OVERRIDE;
373 virtual void RouteCloseEvent(RenderViewHost* rvh) OVERRIDE;
374 virtual void RouteMessageEvent(
375 RenderViewHost* rvh,
376 const ViewMsg_PostMessage_Params& params) OVERRIDE;
377 virtual void RunJavaScriptMessage(RenderViewHost* rvh,
378 const base::string16& message,
379 const base::string16& default_prompt,
380 const GURL& frame_url,
381 JavaScriptMessageType type,
382 IPC::Message* reply_msg,
383 bool* did_suppress_message) OVERRIDE;
384 virtual void RunBeforeUnloadConfirm(RenderViewHost* rvh,
385 const base::string16& message,
386 bool is_reload,
387 IPC::Message* reply_msg) OVERRIDE;
388 virtual bool AddMessageToConsole(int32 level,
389 const base::string16& message,
390 int32 line_no,
391 const base::string16& source_id) OVERRIDE;
392 virtual RendererPreferences GetRendererPrefs(
393 BrowserContext* browser_context) const OVERRIDE;
394 virtual WebPreferences GetWebkitPrefs() OVERRIDE;
395 virtual void OnUserGesture() OVERRIDE;
396 virtual void OnIgnoredUIEvent() OVERRIDE;
397 virtual void RendererUnresponsive(RenderViewHost* render_view_host,
398 bool is_during_beforeunload,
399 bool is_during_unload) OVERRIDE;
400 virtual void RendererResponsive(RenderViewHost* render_view_host) OVERRIDE;
401 virtual void LoadStateChanged(const GURL& url,
402 const net::LoadStateWithParam& load_state,
403 uint64 upload_position,
404 uint64 upload_size) OVERRIDE;
405 virtual void Activate() OVERRIDE;
406 virtual void Deactivate() OVERRIDE;
407 virtual void LostCapture() OVERRIDE;
408 virtual void HandleMouseDown() OVERRIDE;
409 virtual void HandleMouseUp() OVERRIDE;
410 virtual void HandlePointerActivate() OVERRIDE;
411 virtual void HandleGestureBegin() OVERRIDE;
412 virtual void HandleGestureEnd() OVERRIDE;
413 virtual void RunFileChooser(
414 RenderViewHost* render_view_host,
415 const FileChooserParams& params) OVERRIDE;
416 virtual void ToggleFullscreenMode(bool enter_fullscreen) OVERRIDE;
417 virtual bool IsFullscreenForCurrentTab() const OVERRIDE;
418 virtual void UpdatePreferredSize(const gfx::Size& pref_size) OVERRIDE;
419 virtual void ResizeDueToAutoResize(const gfx::Size& new_size) OVERRIDE;
420 virtual void RequestToLockMouse(bool user_gesture,
421 bool last_unlocked_by_target) OVERRIDE;
422 virtual void LostMouseLock() OVERRIDE;
423 virtual void CreateNewWindow(
424 int render_process_id,
425 int route_id,
426 int main_frame_route_id,
427 const ViewHostMsg_CreateWindow_Params& params,
428 SessionStorageNamespace* session_storage_namespace) OVERRIDE;
429 virtual void CreateNewWidget(int render_process_id,
430 int route_id,
431 blink::WebPopupType popup_type) OVERRIDE;
432 virtual void CreateNewFullscreenWidget(int render_process_id,
433 int route_id) OVERRIDE;
434 virtual void ShowCreatedWindow(int route_id,
435 WindowOpenDisposition disposition,
436 const gfx::Rect& initial_pos,
437 bool user_gesture) OVERRIDE;
438 virtual void ShowCreatedWidget(int route_id,
439 const gfx::Rect& initial_pos) OVERRIDE;
440 virtual void ShowCreatedFullscreenWidget(int route_id) OVERRIDE;
441 virtual void ShowContextMenu(const ContextMenuParams& params) OVERRIDE;
442 virtual void RequestMediaAccessPermission(
443 const MediaStreamRequest& request,
444 const MediaResponseCallback& callback) OVERRIDE;
445 virtual SessionStorageNamespace* GetSessionStorageNamespace(
446 SiteInstance* instance) OVERRIDE;
447 virtual FrameTree* GetFrameTree() OVERRIDE;
449 // NavigatorDelegate ---------------------------------------------------------
451 virtual void DidStartProvisionalLoad(
452 RenderFrameHostImpl* render_frame_host,
453 int64 frame_id,
454 int64 parent_frame_id,
455 bool is_main_frame,
456 const GURL& validated_url,
457 bool is_error_page,
458 bool is_iframe_srcdoc) OVERRIDE;
459 virtual void DidFailProvisionalLoadWithError(
460 RenderFrameHostImpl* render_frame_host,
461 const FrameHostMsg_DidFailProvisionalLoadWithError_Params& params)
462 OVERRIDE;
463 virtual void DidRedirectProvisionalLoad(
464 RenderFrameHostImpl* render_frame_host,
465 const GURL& validated_target_url) OVERRIDE;
466 virtual void NotifyChangedNavigationState(
467 InvalidateTypes changed_flags) OVERRIDE;
468 virtual void AboutToNavigateRenderFrame(
469 RenderFrameHostImpl* render_frame_host) OVERRIDE;
470 virtual void DidStartNavigationToPendingEntry(
471 RenderFrameHostImpl* render_frame_host,
472 const GURL& url,
473 NavigationController::ReloadType reload_type) OVERRIDE;
475 // RenderWidgetHostDelegate --------------------------------------------------
477 virtual void RenderWidgetDeleted(
478 RenderWidgetHostImpl* render_widget_host) OVERRIDE;
479 virtual bool PreHandleKeyboardEvent(
480 const NativeWebKeyboardEvent& event,
481 bool* is_keyboard_shortcut) OVERRIDE;
482 virtual void HandleKeyboardEvent(
483 const NativeWebKeyboardEvent& event) OVERRIDE;
484 virtual bool PreHandleWheelEvent(
485 const blink::WebMouseWheelEvent& event) OVERRIDE;
486 virtual void DidSendScreenRects(RenderWidgetHostImpl* rwh) OVERRIDE;
487 #if defined(OS_WIN)
488 virtual gfx::NativeViewAccessible GetParentNativeViewAccessible() OVERRIDE;
489 #endif
491 // RenderFrameHostManager::Delegate ------------------------------------------
493 virtual bool CreateRenderViewForRenderManager(
494 RenderViewHost* render_view_host, int opener_route_id) OVERRIDE;
495 virtual void BeforeUnloadFiredFromRenderManager(
496 bool proceed, const base::TimeTicks& proceed_time,
497 bool* proceed_to_fire_unload) OVERRIDE;
498 virtual void RenderProcessGoneFromRenderManager(
499 RenderViewHost* render_view_host) OVERRIDE;
500 virtual void UpdateRenderViewSizeForRenderManager() OVERRIDE;
501 virtual void CancelModalDialogsForRenderManager() OVERRIDE;
502 virtual void NotifySwappedFromRenderManager(
503 RenderViewHost* old_host, RenderViewHost* new_host) OVERRIDE;
504 virtual int CreateOpenerRenderViewsForRenderManager(
505 SiteInstance* instance) OVERRIDE;
506 virtual NavigationControllerImpl&
507 GetControllerForRenderManager() OVERRIDE;
508 virtual WebUIImpl* CreateWebUIForRenderManager(const GURL& url) OVERRIDE;
509 virtual NavigationEntry*
510 GetLastCommittedNavigationEntryForRenderManager() OVERRIDE;
511 virtual bool FocusLocationBarByDefault() OVERRIDE;
512 virtual void SetFocusToLocationBar(bool select_all) OVERRIDE;
513 virtual void CreateViewAndSetSizeForRVH(RenderViewHost* rvh) OVERRIDE;
514 virtual bool IsHidden() OVERRIDE;
516 // NotificationObserver ------------------------------------------------------
518 virtual void Observe(int type,
519 const NotificationSource& source,
520 const NotificationDetails& details) OVERRIDE;
522 // NavigationControllerDelegate ----------------------------------------------
524 virtual WebContents* GetWebContents() OVERRIDE;
525 virtual void NotifyNavigationEntryCommitted(
526 const LoadCommittedDetails& load_details) OVERRIDE;
528 // Invoked before a form repost warning is shown.
529 virtual void NotifyBeforeFormRepostWarningShow() OVERRIDE;
531 // Activate this WebContents and show a form repost warning.
532 virtual void ActivateAndShowRepostFormWarningDialog() OVERRIDE;
534 // Updates the max page ID for the current SiteInstance in this
535 // WebContentsImpl to be at least |page_id|.
536 virtual void UpdateMaxPageID(int32 page_id) OVERRIDE;
538 // Updates the max page ID for the given SiteInstance in this WebContentsImpl
539 // to be at least |page_id|.
540 virtual void UpdateMaxPageIDForSiteInstance(SiteInstance* site_instance,
541 int32 page_id) OVERRIDE;
543 // Copy the current map of SiteInstance ID to max page ID from another tab.
544 // This is necessary when this tab adopts the NavigationEntries from
545 // |web_contents|.
546 virtual void CopyMaxPageIDsFrom(WebContents* web_contents) OVERRIDE;
548 // Called by the NavigationController to cause the WebContentsImpl to navigate
549 // to the current pending entry. The NavigationController should be called
550 // back with RendererDidNavigate on success or DiscardPendingEntry on failure.
551 // The callbacks can be inside of this function, or at some future time.
553 // The entry has a PageID of -1 if newly created (corresponding to navigation
554 // to a new URL).
556 // If this method returns false, then the navigation is discarded (equivalent
557 // to calling DiscardPendingEntry on the NavigationController).
558 virtual bool NavigateToPendingEntry(
559 NavigationController::ReloadType reload_type) OVERRIDE;
561 // Sets the history for this WebContentsImpl to |history_length| entries, and
562 // moves the current page_id to the last entry in the list if it's valid.
563 // This is mainly used when a prerendered page is swapped into the current
564 // tab. The method is virtual for testing.
565 virtual void SetHistoryLengthAndPrune(
566 const SiteInstance* site_instance,
567 int merge_history_length,
568 int32 minimum_page_id) OVERRIDE;
570 // Called by InterstitialPageImpl when it creates a RenderFrameHost.
571 virtual void RenderFrameForInterstitialPageCreated(
572 RenderFrameHost* render_frame_host) OVERRIDE;
574 // Sets the passed interstitial as the currently showing interstitial.
575 // No interstitial page should already be attached.
576 virtual void AttachInterstitialPage(
577 InterstitialPageImpl* interstitial_page) OVERRIDE;
579 // Unsets the currently showing interstitial.
580 virtual void DetachInterstitialPage() OVERRIDE;
582 // Changes the IsLoading state and notifies the delegate as needed.
583 // |details| is used to provide details on the load that just finished
584 // (but can be null if not applicable).
585 virtual void SetIsLoading(RenderViewHost* render_view_host,
586 bool is_loading,
587 LoadNotificationDetails* details) OVERRIDE;
589 typedef base::Callback<void(WebContents*)> CreatedCallback;
591 private:
592 friend class NavigationControllerImpl;
593 friend class TestNavigationObserver;
594 friend class WebContentsObserver;
595 friend class WebContents; // To implement factory methods.
597 FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest, NoJSMessageOnInterstitials);
598 FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest, UpdateTitle);
599 FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest, FindOpenerRVHWhenPending);
600 FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest,
601 CrossSiteCantPreemptAfterUnload);
602 FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest, PendingContents);
603 FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest, FrameTreeShape);
604 FRIEND_TEST_ALL_PREFIXES(FormStructureBrowserTest, HTMLFiles);
605 FRIEND_TEST_ALL_PREFIXES(NavigationControllerTest, HistoryNavigate);
606 FRIEND_TEST_ALL_PREFIXES(RenderFrameHostManagerTest, PageDoesBackAndReload);
608 // So InterstitialPageImpl can access SetIsLoading.
609 friend class InterstitialPageImpl;
611 // TODO(brettw) TestWebContents shouldn't exist!
612 friend class TestWebContents;
614 class DestructionObserver;
616 // See WebContents::Create for a description of these parameters.
617 WebContentsImpl(BrowserContext* browser_context,
618 WebContentsImpl* opener);
620 // Add and remove observers for page navigation notifications. The order in
621 // which notifications are sent to observers is undefined. Clients must be
622 // sure to remove the observer before they go away.
623 void AddObserver(WebContentsObserver* observer);
624 void RemoveObserver(WebContentsObserver* observer);
626 // Clears this tab's opener if it has been closed.
627 void OnWebContentsDestroyed(WebContentsImpl* web_contents);
629 // Creates and adds to the map a destruction observer watching |web_contents|.
630 // No-op if such an observer already exists.
631 void AddDestructionObserver(WebContentsImpl* web_contents);
633 // Deletes and removes from the map a destruction observer
634 // watching |web_contents|. No-op if there is no such observer.
635 void RemoveDestructionObserver(WebContentsImpl* web_contents);
637 // Callback function when showing JS dialogs.
638 void OnDialogClosed(RenderViewHost* rvh,
639 IPC::Message* reply_msg,
640 bool success,
641 const base::string16& user_input);
643 // Callback function when requesting permission to access the PPAPI broker.
644 // |result| is true if permission was granted.
645 void OnPpapiBrokerPermissionResult(int routing_id, bool result);
647 bool OnMessageReceived(RenderViewHost* render_view_host,
648 RenderFrameHost* render_frame_host,
649 const IPC::Message& message);
651 // IPC message handlers.
652 void OnDidLoadResourceFromMemoryCache(const GURL& url,
653 const std::string& security_info,
654 const std::string& http_request,
655 const std::string& mime_type,
656 ResourceType::Type resource_type);
657 void OnDidDisplayInsecureContent();
658 void OnDidRunInsecureContent(const std::string& security_origin,
659 const GURL& target_url);
660 void OnDocumentLoadedInFrame(int64 frame_id);
661 void OnDidFinishLoad(int64 frame_id,
662 const GURL& url,
663 bool is_main_frame);
664 void OnDidFailLoadWithError(int64 frame_id,
665 const GURL& url,
666 bool is_main_frame,
667 int error_code,
668 const base::string16& error_description);
669 void OnGoToEntryAtOffset(int offset);
670 void OnUpdateZoomLimits(int minimum_percent,
671 int maximum_percent,
672 bool remember);
673 void OnEnumerateDirectory(int request_id, const base::FilePath& path);
674 void OnJSOutOfMemory();
676 void OnRegisterProtocolHandler(const std::string& protocol,
677 const GURL& url,
678 const base::string16& title,
679 bool user_gesture);
680 void OnFindReply(int request_id,
681 int number_of_matches,
682 const gfx::Rect& selection_rect,
683 int active_match_ordinal,
684 bool final_update);
685 #if defined(OS_ANDROID)
686 void OnFindMatchRectsReply(int version,
687 const std::vector<gfx::RectF>& rects,
688 const gfx::RectF& active_rect);
690 void OnOpenDateTimeDialog(
691 const ViewHostMsg_DateTimeDialogValue_Params& value);
692 void OnJavaBridgeGetChannelHandle(IPC::Message* reply_msg);
693 #endif
694 void OnPepperPluginHung(int plugin_child_id,
695 const base::FilePath& path,
696 bool is_hung);
697 void OnPluginCrashed(const base::FilePath& plugin_path,
698 base::ProcessId plugin_pid);
699 void OnAppCacheAccessed(const GURL& manifest_url, bool blocked_by_policy);
700 void OnOpenColorChooser(int color_chooser_id,
701 SkColor color,
702 const std::vector<ColorSuggestion>& suggestions);
703 void OnEndColorChooser(int color_chooser_id);
704 void OnSetSelectedColorInColorChooser(int color_chooser_id, SkColor color);
705 void OnWebUISend(const GURL& source_url,
706 const std::string& name,
707 const base::ListValue& args);
708 void OnRequestPpapiBrokerPermission(int routing_id,
709 const GURL& url,
710 const base::FilePath& plugin_path);
711 void OnBrowserPluginMessage(const IPC::Message& message);
712 void OnDidDownloadImage(int id,
713 int http_status_code,
714 const GURL& image_url,
715 const std::vector<SkBitmap>& bitmaps,
716 const std::vector<gfx::Size>& original_bitmap_sizes);
717 void OnUpdateFaviconURL(int32 page_id,
718 const std::vector<FaviconURL>& candidates);
719 void OnFirstVisuallyNonEmptyPaint(int32 page_id);
720 void OnMediaNotification(int64 player_cookie,
721 bool has_video,
722 bool has_audio,
723 bool is_playing);
724 void OnShowValidationMessage(const gfx::Rect& anchor_in_root_view,
725 const base::string16& main_text,
726 const base::string16& sub_text);
727 void OnHideValidationMessage();
728 void OnMoveValidationMessage(const gfx::Rect& anchor_in_root_view);
731 // Called by derived classes to indicate that we're no longer waiting for a
732 // response. This won't actually update the throbber, but it will get picked
733 // up at the next animation step if the throbber is going.
734 void SetNotWaitingForResponse() { waiting_for_response_ = false; }
736 // Navigation helpers --------------------------------------------------------
738 // These functions are helpers for Navigate() and DidNavigate().
740 // Handles post-navigation tasks in DidNavigate AFTER the entry has been
741 // committed to the navigation controller. Note that the navigation entry is
742 // not provided since it may be invalid/changed after being committed. The
743 // current navigation entry is in the NavigationController at this point.
744 void DidNavigateMainFramePostCommit(
745 const LoadCommittedDetails& details,
746 const ViewHostMsg_FrameNavigate_Params& params);
747 void DidNavigateAnyFramePostCommit(
748 RenderViewHost* render_view_host,
749 const LoadCommittedDetails& details,
750 const ViewHostMsg_FrameNavigate_Params& params);
752 // Specifies whether the passed in URL should be assigned as the site of the
753 // current SiteInstance, if it does not yet have a site.
754 bool ShouldAssignSiteForURL(const GURL& url);
756 // If our controller was restored, update the max page ID associated with the
757 // given RenderViewHost to be larger than the number of restored entries.
758 // This is called in CreateRenderView before any navigations in the RenderView
759 // have begun, to prevent any races in updating RenderView::next_page_id.
760 void UpdateMaxPageIDIfNecessary(RenderViewHost* rvh);
762 // Saves the given title to the navigation entry and does associated work. It
763 // will update history and the view for the new title, and also synthesize
764 // titles for file URLs that have none (so we require that the URL of the
765 // entry already be set).
767 // This is used as the backend for state updates, which include a new title,
768 // or the dedicated set title message. It returns true if the new title is
769 // different and was therefore updated.
770 bool UpdateTitleForEntry(NavigationEntryImpl* entry,
771 const base::string16& title);
773 // Recursively creates swapped out RenderViews for this tab's opener chain
774 // (including this tab) in the given SiteInstance, allowing other tabs to send
775 // cross-process JavaScript calls to their opener(s). Returns the route ID of
776 // this tab's RenderView for |instance|.
777 int CreateOpenerRenderViews(SiteInstance* instance);
779 // Helper for CreateNewWidget/CreateNewFullscreenWidget.
780 void CreateNewWidget(int render_process_id,
781 int route_id,
782 bool is_fullscreen,
783 blink::WebPopupType popup_type);
785 // Helper for ShowCreatedWidget/ShowCreatedFullscreenWidget.
786 void ShowCreatedWidget(int route_id,
787 bool is_fullscreen,
788 const gfx::Rect& initial_pos);
790 // Finds the new RenderWidgetHost and returns it. Note that this can only be
791 // called once as this call also removes it from the internal map.
792 RenderWidgetHostView* GetCreatedWidget(int route_id);
794 // Finds the new WebContentsImpl by route_id, initializes it for
795 // renderer-initiated creation, and returns it. Note that this can only be
796 // called once as this call also removes it from the internal map.
797 WebContentsImpl* GetCreatedWindow(int route_id);
799 // Returns the RenderWidgetHostView that is associated with a native window
800 // and can be used in showing created widgets.
801 // If this WebContents belongs to a browser plugin guest, there is no native
802 // window 'view' associated with this WebContents. This method returns the
803 // 'view' of the embedder instead.
804 RenderWidgetHostViewPort* GetRenderWidgetHostViewPort() const;
806 // Misc non-view stuff -------------------------------------------------------
808 // Helper functions for sending notifications.
809 void NotifySwapped(RenderViewHost* old_host, RenderViewHost* new_host);
810 void NotifyDisconnected();
812 void SetEncoding(const std::string& encoding);
814 // TODO(creis): This should take in a FrameTreeNode to know which node's
815 // render manager to return. For now, we just return the root's.
816 RenderFrameHostManager* GetRenderManager() const;
818 RenderViewHostImpl* GetRenderViewHostImpl();
820 // Removes browser plugin embedder if there is one.
821 void RemoveBrowserPluginEmbedder();
823 // Clear |render_view_host|'s PowerSaveBlockers.
824 void ClearPowerSaveBlockers(RenderViewHost* render_view_host);
826 // Clear all PowerSaveBlockers, leave power_save_blocker_ empty.
827 void ClearAllPowerSaveBlockers();
829 // Helper function to invoke WebContentsDelegate::GetSizeForNewRenderView().
830 gfx::Size GetSizeForNewRenderView() const;
832 void OnFrameRemoved(RenderViewHostImpl* render_view_host, int64 frame_id);
834 // Adds/removes a callback called on creation of each new WebContents.
835 // Deprecated, about to remove.
836 static void AddCreatedCallback(const CreatedCallback& callback);
837 static void RemoveCreatedCallback(const CreatedCallback& callback);
839 // Data for core operation ---------------------------------------------------
841 // Delegate for notifying our owner about stuff. Not owned by us.
842 WebContentsDelegate* delegate_;
844 // Handles the back/forward list and loading.
845 NavigationControllerImpl controller_;
847 // The corresponding view.
848 scoped_ptr<WebContentsViewPort> view_;
850 // The view of the RVHD. Usually this is our WebContentsView implementation,
851 // but if an embedder uses a different WebContentsView, they'll need to
852 // provide this.
853 RenderViewHostDelegateView* render_view_host_delegate_view_;
855 // Tracks created WebContentsImpl objects that have not been shown yet. They
856 // are identified by the route ID passed to CreateNewWindow.
857 typedef std::map<int, WebContentsImpl*> PendingContents;
858 PendingContents pending_contents_;
860 // These maps hold on to the widgets that we created on behalf of the renderer
861 // that haven't shown yet.
862 typedef std::map<int, RenderWidgetHostView*> PendingWidgetViews;
863 PendingWidgetViews pending_widget_views_;
865 typedef std::map<WebContentsImpl*, DestructionObserver*> DestructionObservers;
866 DestructionObservers destruction_observers_;
868 // A list of observers notified when page state changes. Weak references.
869 // This MUST be listed above frame_tree_ since at destruction time the
870 // latter might cause RenderViewHost's destructor to call us and we might use
871 // the observer list then.
872 ObserverList<WebContentsObserver> observers_;
874 // The tab that opened this tab, if any. Will be set to null if the opener
875 // is closed.
876 WebContentsImpl* opener_;
878 #if defined(OS_WIN)
879 gfx::NativeViewAccessible accessible_parent_;
880 #endif
882 // Helper classes ------------------------------------------------------------
884 // Maps the RenderViewHost to its media_player_cookie and PowerSaveBlocker
885 // pairs. Key is the RenderViewHost, value is the map which maps player_cookie
886 // on to PowerSaveBlocker.
887 typedef std::map<RenderViewHost*, std::map<int64, PowerSaveBlocker*> >
888 PowerSaveBlockerMap;
889 PowerSaveBlockerMap power_save_blockers_;
891 // Manages the frame tree of the page and process swaps in each node.
892 FrameTree frame_tree_;
894 #if defined(OS_ANDROID)
895 // Manages injecting Java objects into all RenderViewHosts associated with
896 // this WebContentsImpl.
897 scoped_ptr<JavaBridgeDispatcherHostManager>
898 java_bridge_dispatcher_host_manager_;
899 #endif
901 // SavePackage, lazily created.
902 scoped_refptr<SavePackage> save_package_;
904 // Data for loading state ----------------------------------------------------
906 // Indicates whether we're currently loading a resource.
907 bool is_loading_;
909 // Indicates if the tab is considered crashed.
910 base::TerminationStatus crashed_status_;
911 int crashed_error_code_;
913 // Whether this WebContents is waiting for a first-response for the
914 // main resource of the page. This controls whether the throbber state is
915 // "waiting" or "loading."
916 bool waiting_for_response_;
918 // Map of SiteInstance ID to max page ID for this tab. A page ID is specific
919 // to a given tab and SiteInstance, and must be valid for the lifetime of the
920 // WebContentsImpl.
921 std::map<int32, int32> max_page_ids_;
923 // The current load state and the URL associated with it.
924 net::LoadStateWithParam load_state_;
925 base::string16 load_state_host_;
926 // Upload progress, for displaying in the status bar.
927 // Set to zero when there is no significant upload happening.
928 uint64 upload_size_;
929 uint64 upload_position_;
931 // Data for current page -----------------------------------------------------
933 // When a title cannot be taken from any entry, this title will be used.
934 base::string16 page_title_when_no_navigation_entry_;
936 // When a navigation occurs, we record its contents MIME type. It can be
937 // used to check whether we can do something for some special contents.
938 std::string contents_mime_type_;
940 // Character encoding.
941 std::string encoding_;
943 // True if this is a secure page which displayed insecure content.
944 bool displayed_insecure_content_;
946 // Data for misc internal state ----------------------------------------------
948 // When > 0, the WebContents is currently being captured (e.g., for
949 // screenshots or mirroring); and the underlying RenderWidgetHost should not
950 // be told it is hidden.
951 int capturer_count_;
953 // Tracks whether RWHV should be visible once capturer_count_ becomes zero.
954 bool should_normally_be_visible_;
956 // See getter above.
957 bool is_being_destroyed_;
959 // Indicates whether we should notify about disconnection of this
960 // WebContentsImpl. This is used to ensure disconnection notifications only
961 // happen if a connection notification has happened and that they happen only
962 // once.
963 bool notify_disconnection_;
965 // Pointer to the JavaScript dialog manager, lazily assigned. Used because the
966 // delegate of this WebContentsImpl is nulled before its destructor is called.
967 JavaScriptDialogManager* dialog_manager_;
969 // Set to true when there is an active "before unload" dialog. When true,
970 // we've forced the throbber to start in Navigate, and we need to remember to
971 // turn it off in OnJavaScriptMessageBoxClosed if the navigation is canceled.
972 bool is_showing_before_unload_dialog_;
974 // Settings that get passed to the renderer process.
975 RendererPreferences renderer_preferences_;
977 // The time that this tab was last selected.
978 base::TimeTicks last_selected_time_;
980 // See description above setter.
981 bool closed_by_user_gesture_;
983 // Minimum/maximum zoom percent.
984 int minimum_zoom_percent_;
985 int maximum_zoom_percent_;
986 // If true, the default zoom limits have been overriden for this tab, in which
987 // case we don't want saved settings to apply to it and we don't want to
988 // remember it.
989 bool temporary_zoom_settings_;
991 // The intrinsic size of the page.
992 gfx::Size preferred_size_;
994 #if defined(OS_ANDROID)
995 // Date time chooser opened by this tab.
996 // Only used in Android since all other platforms use a multi field UI.
997 scoped_ptr<DateTimeChooserAndroid> date_time_chooser_;
998 #endif
1000 // Color chooser that was opened by this tab.
1001 scoped_ptr<ColorChooser> color_chooser_;
1003 // A unique identifier for the current color chooser. Identifiers are unique
1004 // across a renderer process. This avoids race conditions in synchronizing
1005 // the browser and renderer processes. For example, if a renderer closes one
1006 // chooser and opens another, and simultaneously the user picks a color in the
1007 // first chooser, the IDs can be used to drop the "chose a color" message
1008 // rather than erroneously tell the renderer that the user picked a color in
1009 // the second chooser.
1010 int color_chooser_identifier_;
1012 // Manages the embedder state for browser plugins, if this WebContents is an
1013 // embedder; NULL otherwise.
1014 scoped_ptr<BrowserPluginEmbedder> browser_plugin_embedder_;
1015 // Manages the guest state for browser plugin, if this WebContents is a guest;
1016 // NULL otherwise.
1017 scoped_ptr<BrowserPluginGuest> browser_plugin_guest_;
1019 // This must be at the end, or else we might get notifications and use other
1020 // member variables that are gone.
1021 NotificationRegistrar registrar_;
1023 // Used during IPC message dispatching from the RenderView so that the
1024 // handlers can get a pointer to the RVH through which the message was
1025 // received.
1026 RenderViewHost* render_view_message_source_;
1028 // All live RenderWidgetHostImpls that are created by this object and may
1029 // outlive it.
1030 std::set<RenderWidgetHostImpl*> created_widgets_;
1032 // Routing id of the shown fullscreen widget or MSG_ROUTING_NONE otherwise.
1033 int fullscreen_widget_routing_id_;
1035 // Maps the ids of pending image downloads to their callbacks
1036 typedef std::map<int, ImageDownloadCallback> ImageDownloadMap;
1037 ImageDownloadMap image_download_map_;
1039 // Whether this WebContents is responsible for displaying a subframe in a
1040 // different process from its parent page.
1041 bool is_subframe_;
1043 DISALLOW_COPY_AND_ASSIGN(WebContentsImpl);
1046 } // namespace content
1048 #endif // CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_IMPL_H_