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_
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;
44 class BrowserPluginEmbedder;
45 class BrowserPluginGuest;
46 class BrowserPluginGuestManager;
48 class DateTimeChooserAndroid;
50 class InterstitialPageImpl;
51 class JavaBridgeDispatcherHostManager;
52 class JavaScriptDialogManager;
53 class PowerSaveBlocker;
55 class RenderViewHostDelegateView;
56 class RenderViewHostImpl;
57 class RenderWidgetHostImpl;
58 class RenderWidgetHostViewPort;
60 class SessionStorageNamespaceImpl;
62 class TestWebContents;
63 class WebContentsDelegate;
64 class WebContentsImpl;
65 class WebContentsObserver;
66 class WebContentsViewPort;
67 class WebContentsViewDelegate;
68 struct ColorSuggestion;
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) {
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();
134 // Expose the render manager for testing.
135 RenderFrameHostManager* GetRenderManagerForTesting();
137 // Returns guest browser plugin object, or NULL if this WebContents is not a
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
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(
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
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;
209 virtual void SetParentNativeViewAccessible(
210 gfx::NativeViewAccessible accessible_parent) OVERRIDE;
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)
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,
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()
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,
334 const PageState& page_state) OVERRIDE;
335 virtual void UpdateTitle(RenderViewHost* render_view_host,
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,
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(
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(
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,
387 IPC::Message* reply_msg) OVERRIDE;
388 virtual bool AddMessageToConsole(int32 level,
389 const base::string16& message,
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,
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,
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,
454 int64 parent_frame_id,
456 const GURL& validated_url,
458 bool is_iframe_srcdoc) OVERRIDE;
459 virtual void DidFailProvisionalLoadWithError(
460 RenderFrameHostImpl* render_frame_host,
461 const FrameHostMsg_DidFailProvisionalLoadWithError_Params& params)
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,
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;
488 virtual gfx::NativeViewAccessible GetParentNativeViewAccessible() OVERRIDE;
491 // RenderFrameHostManager::Delegate ------------------------------------------
493 virtual bool CreateRenderViewForRenderManager(
494 RenderViewHost* render_view_host,
496 CrossProcessFrameConnector* frame_connector) OVERRIDE;
497 virtual void BeforeUnloadFiredFromRenderManager(
498 bool proceed, const base::TimeTicks& proceed_time,
499 bool* proceed_to_fire_unload) OVERRIDE;
500 virtual void RenderProcessGoneFromRenderManager(
501 RenderViewHost* render_view_host) OVERRIDE;
502 virtual void UpdateRenderViewSizeForRenderManager() OVERRIDE;
503 virtual void CancelModalDialogsForRenderManager() OVERRIDE;
504 virtual void NotifySwappedFromRenderManager(
505 RenderViewHost* old_host, RenderViewHost* new_host) OVERRIDE;
506 virtual int CreateOpenerRenderViewsForRenderManager(
507 SiteInstance* instance) OVERRIDE;
508 virtual NavigationControllerImpl&
509 GetControllerForRenderManager() OVERRIDE;
510 virtual WebUIImpl* CreateWebUIForRenderManager(const GURL& url) OVERRIDE;
511 virtual NavigationEntry*
512 GetLastCommittedNavigationEntryForRenderManager() OVERRIDE;
513 virtual bool FocusLocationBarByDefault() OVERRIDE;
514 virtual void SetFocusToLocationBar(bool select_all) OVERRIDE;
515 virtual void CreateViewAndSetSizeForRVH(RenderViewHost* rvh) OVERRIDE;
516 virtual bool IsHidden() OVERRIDE;
518 // NotificationObserver ------------------------------------------------------
520 virtual void Observe(int type,
521 const NotificationSource& source,
522 const NotificationDetails& details) OVERRIDE;
524 // NavigationControllerDelegate ----------------------------------------------
526 virtual WebContents* GetWebContents() OVERRIDE;
527 virtual void NotifyNavigationEntryCommitted(
528 const LoadCommittedDetails& load_details) OVERRIDE;
530 // Invoked before a form repost warning is shown.
531 virtual void NotifyBeforeFormRepostWarningShow() OVERRIDE;
533 // Activate this WebContents and show a form repost warning.
534 virtual void ActivateAndShowRepostFormWarningDialog() OVERRIDE;
536 // Updates the max page ID for the current SiteInstance in this
537 // WebContentsImpl to be at least |page_id|.
538 virtual void UpdateMaxPageID(int32 page_id) OVERRIDE;
540 // Updates the max page ID for the given SiteInstance in this WebContentsImpl
541 // to be at least |page_id|.
542 virtual void UpdateMaxPageIDForSiteInstance(SiteInstance* site_instance,
543 int32 page_id) OVERRIDE;
545 // Copy the current map of SiteInstance ID to max page ID from another tab.
546 // This is necessary when this tab adopts the NavigationEntries from
548 virtual void CopyMaxPageIDsFrom(WebContents* web_contents) OVERRIDE;
550 // Called by the NavigationController to cause the WebContentsImpl to navigate
551 // to the current pending entry. The NavigationController should be called
552 // back with RendererDidNavigate on success or DiscardPendingEntry on failure.
553 // The callbacks can be inside of this function, or at some future time.
555 // The entry has a PageID of -1 if newly created (corresponding to navigation
558 // If this method returns false, then the navigation is discarded (equivalent
559 // to calling DiscardPendingEntry on the NavigationController).
560 virtual bool NavigateToPendingEntry(
561 NavigationController::ReloadType reload_type) OVERRIDE;
563 // Sets the history for this WebContentsImpl to |history_length| entries, and
564 // moves the current page_id to the last entry in the list if it's valid.
565 // This is mainly used when a prerendered page is swapped into the current
566 // tab. The method is virtual for testing.
567 virtual void SetHistoryLengthAndPrune(
568 const SiteInstance* site_instance,
569 int merge_history_length,
570 int32 minimum_page_id) OVERRIDE;
572 // Called by InterstitialPageImpl when it creates a RenderFrameHost.
573 virtual void RenderFrameForInterstitialPageCreated(
574 RenderFrameHost* render_frame_host) OVERRIDE;
576 // Sets the passed interstitial as the currently showing interstitial.
577 // No interstitial page should already be attached.
578 virtual void AttachInterstitialPage(
579 InterstitialPageImpl* interstitial_page) OVERRIDE;
581 // Unsets the currently showing interstitial.
582 virtual void DetachInterstitialPage() OVERRIDE;
584 // Changes the IsLoading state and notifies the delegate as needed.
585 // |details| is used to provide details on the load that just finished
586 // (but can be null if not applicable).
587 virtual void SetIsLoading(RenderViewHost* render_view_host,
589 LoadNotificationDetails* details) OVERRIDE;
591 typedef base::Callback<void(WebContents*)> CreatedCallback;
594 friend class NavigationControllerImpl;
595 friend class TestNavigationObserver;
596 friend class WebContentsObserver;
597 friend class WebContents; // To implement factory methods.
599 FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest, NoJSMessageOnInterstitials);
600 FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest, UpdateTitle);
601 FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest, FindOpenerRVHWhenPending);
602 FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest,
603 CrossSiteCantPreemptAfterUnload);
604 FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest, PendingContents);
605 FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest, FrameTreeShape);
606 FRIEND_TEST_ALL_PREFIXES(FormStructureBrowserTest, HTMLFiles);
607 FRIEND_TEST_ALL_PREFIXES(NavigationControllerTest, HistoryNavigate);
608 FRIEND_TEST_ALL_PREFIXES(RenderFrameHostManagerTest, PageDoesBackAndReload);
610 // So InterstitialPageImpl can access SetIsLoading.
611 friend class InterstitialPageImpl;
613 // TODO(brettw) TestWebContents shouldn't exist!
614 friend class TestWebContents;
616 class DestructionObserver;
618 // See WebContents::Create for a description of these parameters.
619 WebContentsImpl(BrowserContext* browser_context,
620 WebContentsImpl* opener);
622 // Add and remove observers for page navigation notifications. The order in
623 // which notifications are sent to observers is undefined. Clients must be
624 // sure to remove the observer before they go away.
625 void AddObserver(WebContentsObserver* observer);
626 void RemoveObserver(WebContentsObserver* observer);
628 // Clears this tab's opener if it has been closed.
629 void OnWebContentsDestroyed(WebContentsImpl* web_contents);
631 // Creates and adds to the map a destruction observer watching |web_contents|.
632 // No-op if such an observer already exists.
633 void AddDestructionObserver(WebContentsImpl* web_contents);
635 // Deletes and removes from the map a destruction observer
636 // watching |web_contents|. No-op if there is no such observer.
637 void RemoveDestructionObserver(WebContentsImpl* web_contents);
639 // Callback function when showing JS dialogs.
640 void OnDialogClosed(RenderViewHost* rvh,
641 IPC::Message* reply_msg,
643 const base::string16& user_input);
645 // Callback function when requesting permission to access the PPAPI broker.
646 // |result| is true if permission was granted.
647 void OnPpapiBrokerPermissionResult(int routing_id, bool result);
649 bool OnMessageReceived(RenderViewHost* render_view_host,
650 RenderFrameHost* render_frame_host,
651 const IPC::Message& message);
653 // IPC message handlers.
654 void OnDidLoadResourceFromMemoryCache(const GURL& url,
655 const std::string& security_info,
656 const std::string& http_request,
657 const std::string& mime_type,
658 ResourceType::Type resource_type);
659 void OnDidDisplayInsecureContent();
660 void OnDidRunInsecureContent(const std::string& security_origin,
661 const GURL& target_url);
662 void OnDocumentLoadedInFrame(int64 frame_id);
663 void OnDidFinishLoad(int64 frame_id,
666 void OnDidFailLoadWithError(int64 frame_id,
670 const base::string16& error_description);
671 void OnGoToEntryAtOffset(int offset);
672 void OnUpdateZoomLimits(int minimum_percent,
675 void OnEnumerateDirectory(int request_id, const base::FilePath& path);
676 void OnJSOutOfMemory();
678 void OnRegisterProtocolHandler(const std::string& protocol,
680 const base::string16& title,
682 void OnFindReply(int request_id,
683 int number_of_matches,
684 const gfx::Rect& selection_rect,
685 int active_match_ordinal,
687 #if defined(OS_ANDROID)
688 void OnFindMatchRectsReply(int version,
689 const std::vector<gfx::RectF>& rects,
690 const gfx::RectF& active_rect);
692 void OnOpenDateTimeDialog(
693 const ViewHostMsg_DateTimeDialogValue_Params& value);
694 void OnJavaBridgeGetChannelHandle(IPC::Message* reply_msg);
696 void OnPepperPluginHung(int plugin_child_id,
697 const base::FilePath& path,
699 void OnPluginCrashed(const base::FilePath& plugin_path,
700 base::ProcessId plugin_pid);
701 void OnAppCacheAccessed(const GURL& manifest_url, bool blocked_by_policy);
702 void OnOpenColorChooser(int color_chooser_id,
704 const std::vector<ColorSuggestion>& suggestions);
705 void OnEndColorChooser(int color_chooser_id);
706 void OnSetSelectedColorInColorChooser(int color_chooser_id, SkColor color);
707 void OnWebUISend(const GURL& source_url,
708 const std::string& name,
709 const base::ListValue& args);
710 void OnRequestPpapiBrokerPermission(int routing_id,
712 const base::FilePath& plugin_path);
713 void OnBrowserPluginMessage(const IPC::Message& message);
714 void OnDidDownloadImage(int id,
715 int http_status_code,
716 const GURL& image_url,
717 const std::vector<SkBitmap>& bitmaps,
718 const std::vector<gfx::Size>& original_bitmap_sizes);
719 void OnUpdateFaviconURL(int32 page_id,
720 const std::vector<FaviconURL>& candidates);
721 void OnFirstVisuallyNonEmptyPaint(int32 page_id);
722 void OnMediaNotification(int64 player_cookie,
726 void OnShowValidationMessage(const gfx::Rect& anchor_in_root_view,
727 const base::string16& main_text,
728 const base::string16& sub_text);
729 void OnHideValidationMessage();
730 void OnMoveValidationMessage(const gfx::Rect& anchor_in_root_view);
733 // Called by derived classes to indicate that we're no longer waiting for a
734 // response. This won't actually update the throbber, but it will get picked
735 // up at the next animation step if the throbber is going.
736 void SetNotWaitingForResponse() { waiting_for_response_ = false; }
738 // Navigation helpers --------------------------------------------------------
740 // These functions are helpers for Navigate() and DidNavigate().
742 // Handles post-navigation tasks in DidNavigate AFTER the entry has been
743 // committed to the navigation controller. Note that the navigation entry is
744 // not provided since it may be invalid/changed after being committed. The
745 // current navigation entry is in the NavigationController at this point.
746 void DidNavigateMainFramePostCommit(
747 const LoadCommittedDetails& details,
748 const ViewHostMsg_FrameNavigate_Params& params);
749 void DidNavigateAnyFramePostCommit(
750 RenderViewHost* render_view_host,
751 const LoadCommittedDetails& details,
752 const ViewHostMsg_FrameNavigate_Params& params);
754 // Specifies whether the passed in URL should be assigned as the site of the
755 // current SiteInstance, if it does not yet have a site.
756 bool ShouldAssignSiteForURL(const GURL& url);
758 // If our controller was restored, update the max page ID associated with the
759 // given RenderViewHost to be larger than the number of restored entries.
760 // This is called in CreateRenderView before any navigations in the RenderView
761 // have begun, to prevent any races in updating RenderView::next_page_id.
762 void UpdateMaxPageIDIfNecessary(RenderViewHost* rvh);
764 // Saves the given title to the navigation entry and does associated work. It
765 // will update history and the view for the new title, and also synthesize
766 // titles for file URLs that have none (so we require that the URL of the
767 // entry already be set).
769 // This is used as the backend for state updates, which include a new title,
770 // or the dedicated set title message. It returns true if the new title is
771 // different and was therefore updated.
772 bool UpdateTitleForEntry(NavigationEntryImpl* entry,
773 const base::string16& title);
775 // Recursively creates swapped out RenderViews for this tab's opener chain
776 // (including this tab) in the given SiteInstance, allowing other tabs to send
777 // cross-process JavaScript calls to their opener(s). Returns the route ID of
778 // this tab's RenderView for |instance|.
779 int CreateOpenerRenderViews(SiteInstance* instance);
781 // Helper for CreateNewWidget/CreateNewFullscreenWidget.
782 void CreateNewWidget(int render_process_id,
785 blink::WebPopupType popup_type);
787 // Helper for ShowCreatedWidget/ShowCreatedFullscreenWidget.
788 void ShowCreatedWidget(int route_id,
790 const gfx::Rect& initial_pos);
792 // Finds the new RenderWidgetHost and returns it. Note that this can only be
793 // called once as this call also removes it from the internal map.
794 RenderWidgetHostView* GetCreatedWidget(int route_id);
796 // Finds the new WebContentsImpl by route_id, initializes it for
797 // renderer-initiated creation, and returns it. Note that this can only be
798 // called once as this call also removes it from the internal map.
799 WebContentsImpl* GetCreatedWindow(int route_id);
801 // Returns the RenderWidgetHostView that is associated with a native window
802 // and can be used in showing created widgets.
803 // If this WebContents belongs to a browser plugin guest, there is no native
804 // window 'view' associated with this WebContents. This method returns the
805 // 'view' of the embedder instead.
806 RenderWidgetHostViewPort* GetRenderWidgetHostViewPort() const;
808 // Misc non-view stuff -------------------------------------------------------
810 // Helper functions for sending notifications.
811 void NotifySwapped(RenderViewHost* old_host, RenderViewHost* new_host);
812 void NotifyDisconnected();
814 void SetEncoding(const std::string& encoding);
816 // TODO(creis): This should take in a FrameTreeNode to know which node's
817 // render manager to return. For now, we just return the root's.
818 RenderFrameHostManager* GetRenderManager() const;
820 RenderViewHostImpl* GetRenderViewHostImpl();
822 // Removes browser plugin embedder if there is one.
823 void RemoveBrowserPluginEmbedder();
825 // Clear |render_view_host|'s PowerSaveBlockers.
826 void ClearPowerSaveBlockers(RenderViewHost* render_view_host);
828 // Clear all PowerSaveBlockers, leave power_save_blocker_ empty.
829 void ClearAllPowerSaveBlockers();
831 // Helper function to invoke WebContentsDelegate::GetSizeForNewRenderView().
832 gfx::Size GetSizeForNewRenderView() const;
834 void OnFrameRemoved(RenderViewHostImpl* render_view_host, int64 frame_id);
836 // Adds/removes a callback called on creation of each new WebContents.
837 // Deprecated, about to remove.
838 static void AddCreatedCallback(const CreatedCallback& callback);
839 static void RemoveCreatedCallback(const CreatedCallback& callback);
841 // Data for core operation ---------------------------------------------------
843 // Delegate for notifying our owner about stuff. Not owned by us.
844 WebContentsDelegate* delegate_;
846 // Handles the back/forward list and loading.
847 NavigationControllerImpl controller_;
849 // The corresponding view.
850 scoped_ptr<WebContentsViewPort> view_;
852 // The view of the RVHD. Usually this is our WebContentsView implementation,
853 // but if an embedder uses a different WebContentsView, they'll need to
855 RenderViewHostDelegateView* render_view_host_delegate_view_;
857 // Tracks created WebContentsImpl objects that have not been shown yet. They
858 // are identified by the route ID passed to CreateNewWindow.
859 typedef std::map<int, WebContentsImpl*> PendingContents;
860 PendingContents pending_contents_;
862 // These maps hold on to the widgets that we created on behalf of the renderer
863 // that haven't shown yet.
864 typedef std::map<int, RenderWidgetHostView*> PendingWidgetViews;
865 PendingWidgetViews pending_widget_views_;
867 typedef std::map<WebContentsImpl*, DestructionObserver*> DestructionObservers;
868 DestructionObservers destruction_observers_;
870 // A list of observers notified when page state changes. Weak references.
871 // This MUST be listed above frame_tree_ since at destruction time the
872 // latter might cause RenderViewHost's destructor to call us and we might use
873 // the observer list then.
874 ObserverList<WebContentsObserver> observers_;
876 // The tab that opened this tab, if any. Will be set to null if the opener
878 WebContentsImpl* opener_;
881 gfx::NativeViewAccessible accessible_parent_;
884 // Helper classes ------------------------------------------------------------
886 // Maps the RenderViewHost to its media_player_cookie and PowerSaveBlocker
887 // pairs. Key is the RenderViewHost, value is the map which maps player_cookie
888 // on to PowerSaveBlocker.
889 typedef std::map<RenderViewHost*, std::map<int64, PowerSaveBlocker*> >
891 PowerSaveBlockerMap power_save_blockers_;
893 // Manages the frame tree of the page and process swaps in each node.
894 FrameTree frame_tree_;
896 #if defined(OS_ANDROID)
897 // Manages injecting Java objects into all RenderViewHosts associated with
898 // this WebContentsImpl.
899 scoped_ptr<JavaBridgeDispatcherHostManager>
900 java_bridge_dispatcher_host_manager_;
903 // SavePackage, lazily created.
904 scoped_refptr<SavePackage> save_package_;
906 // Data for loading state ----------------------------------------------------
908 // Indicates whether we're currently loading a resource.
911 // Indicates if the tab is considered crashed.
912 base::TerminationStatus crashed_status_;
913 int crashed_error_code_;
915 // Whether this WebContents is waiting for a first-response for the
916 // main resource of the page. This controls whether the throbber state is
917 // "waiting" or "loading."
918 bool waiting_for_response_;
920 // Map of SiteInstance ID to max page ID for this tab. A page ID is specific
921 // to a given tab and SiteInstance, and must be valid for the lifetime of the
923 std::map<int32, int32> max_page_ids_;
925 // The current load state and the URL associated with it.
926 net::LoadStateWithParam load_state_;
927 base::string16 load_state_host_;
928 // Upload progress, for displaying in the status bar.
929 // Set to zero when there is no significant upload happening.
931 uint64 upload_position_;
933 // Data for current page -----------------------------------------------------
935 // When a title cannot be taken from any entry, this title will be used.
936 base::string16 page_title_when_no_navigation_entry_;
938 // When a navigation occurs, we record its contents MIME type. It can be
939 // used to check whether we can do something for some special contents.
940 std::string contents_mime_type_;
942 // Character encoding.
943 std::string encoding_;
945 // True if this is a secure page which displayed insecure content.
946 bool displayed_insecure_content_;
948 // Data for misc internal state ----------------------------------------------
950 // When > 0, the WebContents is currently being captured (e.g., for
951 // screenshots or mirroring); and the underlying RenderWidgetHost should not
952 // be told it is hidden.
955 // Tracks whether RWHV should be visible once capturer_count_ becomes zero.
956 bool should_normally_be_visible_;
959 bool is_being_destroyed_;
961 // Indicates whether we should notify about disconnection of this
962 // WebContentsImpl. This is used to ensure disconnection notifications only
963 // happen if a connection notification has happened and that they happen only
965 bool notify_disconnection_;
967 // Pointer to the JavaScript dialog manager, lazily assigned. Used because the
968 // delegate of this WebContentsImpl is nulled before its destructor is called.
969 JavaScriptDialogManager* dialog_manager_;
971 // Set to true when there is an active "before unload" dialog. When true,
972 // we've forced the throbber to start in Navigate, and we need to remember to
973 // turn it off in OnJavaScriptMessageBoxClosed if the navigation is canceled.
974 bool is_showing_before_unload_dialog_;
976 // Settings that get passed to the renderer process.
977 RendererPreferences renderer_preferences_;
979 // The time that this tab was last selected.
980 base::TimeTicks last_selected_time_;
982 // See description above setter.
983 bool closed_by_user_gesture_;
985 // Minimum/maximum zoom percent.
986 int minimum_zoom_percent_;
987 int maximum_zoom_percent_;
988 // If true, the default zoom limits have been overriden for this tab, in which
989 // case we don't want saved settings to apply to it and we don't want to
991 bool temporary_zoom_settings_;
993 // The intrinsic size of the page.
994 gfx::Size preferred_size_;
996 #if defined(OS_ANDROID)
997 // Date time chooser opened by this tab.
998 // Only used in Android since all other platforms use a multi field UI.
999 scoped_ptr<DateTimeChooserAndroid> date_time_chooser_;
1002 // Color chooser that was opened by this tab.
1003 scoped_ptr<ColorChooser> color_chooser_;
1005 // A unique identifier for the current color chooser. Identifiers are unique
1006 // across a renderer process. This avoids race conditions in synchronizing
1007 // the browser and renderer processes. For example, if a renderer closes one
1008 // chooser and opens another, and simultaneously the user picks a color in the
1009 // first chooser, the IDs can be used to drop the "chose a color" message
1010 // rather than erroneously tell the renderer that the user picked a color in
1011 // the second chooser.
1012 int color_chooser_identifier_;
1014 // Manages the embedder state for browser plugins, if this WebContents is an
1015 // embedder; NULL otherwise.
1016 scoped_ptr<BrowserPluginEmbedder> browser_plugin_embedder_;
1017 // Manages the guest state for browser plugin, if this WebContents is a guest;
1019 scoped_ptr<BrowserPluginGuest> browser_plugin_guest_;
1021 // This must be at the end, or else we might get notifications and use other
1022 // member variables that are gone.
1023 NotificationRegistrar registrar_;
1025 // Used during IPC message dispatching from the RenderView so that the
1026 // handlers can get a pointer to the RVH through which the message was
1028 RenderViewHost* render_view_message_source_;
1030 // All live RenderWidgetHostImpls that are created by this object and may
1032 std::set<RenderWidgetHostImpl*> created_widgets_;
1034 // Routing id of the shown fullscreen widget or MSG_ROUTING_NONE otherwise.
1035 int fullscreen_widget_routing_id_;
1037 // Maps the ids of pending image downloads to their callbacks
1038 typedef std::map<int, ImageDownloadCallback> ImageDownloadMap;
1039 ImageDownloadMap image_download_map_;
1041 // Whether this WebContents is responsible for displaying a subframe in a
1042 // different process from its parent page.
1045 DISALLOW_COPY_AND_ASSIGN(WebContentsImpl);
1048 } // namespace content
1050 #endif // CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_IMPL_H_