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/ax_event_notification_details.h"
28 #include "content/public/browser/notification_observer.h"
29 #include "content/public/browser/notification_registrar.h"
30 #include "content/public/browser/web_contents.h"
31 #include "content/public/common/page_transition_types.h"
32 #include "content/public/common/renderer_preferences.h"
33 #include "content/public/common/three_d_api_types.h"
34 #include "net/base/load_states.h"
35 #include "third_party/WebKit/public/web/WebDragOperation.h"
36 #include "ui/gfx/rect_f.h"
37 #include "ui/gfx/size.h"
38 #include "webkit/common/resource_type.h"
40 struct BrowserPluginHostMsg_ResizeGuest_Params;
41 struct ViewHostMsg_DateTimeDialogValue_Params;
42 struct ViewMsg_PostMessage_Params;
45 class BrowserPluginEmbedder;
46 class BrowserPluginGuest;
47 class BrowserPluginGuestManager;
49 class DateTimeChooserAndroid;
51 class InterstitialPageImpl;
52 class JavaBridgeDispatcherHostManager;
53 class JavaScriptDialogManager;
54 class PowerSaveBlocker;
56 class RenderViewHostDelegateView;
57 class RenderViewHostImpl;
58 class RenderWidgetHostImpl;
59 class RenderWidgetHostViewPort;
61 class SessionStorageNamespaceImpl;
63 class TestWebContents;
64 class WebContentsDelegate;
65 class WebContentsImpl;
66 class WebContentsObserver;
67 class WebContentsViewPort;
68 class WebContentsViewDelegate;
69 struct AXEventNotificationDetails;
70 struct ColorSuggestion;
72 struct LoadNotificationDetails;
73 struct ResourceRedirectDetails;
74 struct ResourceRequestDetails;
76 // Factory function for the implementations that content knows about. Takes
77 // ownership of |delegate|.
78 WebContentsViewPort* CreateWebContentsView(
79 WebContentsImpl* web_contents,
80 WebContentsViewDelegate* delegate,
81 RenderViewHostDelegateView** render_view_host_delegate_view);
83 class CONTENT_EXPORT WebContentsImpl
84 : public NON_EXPORTED_BASE(WebContents),
85 public NON_EXPORTED_BASE(RenderFrameHostDelegate),
86 public RenderViewHostDelegate,
87 public RenderWidgetHostDelegate,
88 public RenderFrameHostManager::Delegate,
89 public NotificationObserver,
90 public NON_EXPORTED_BASE(NavigationControllerDelegate),
91 public NON_EXPORTED_BASE(NavigatorDelegate) {
93 virtual ~WebContentsImpl();
95 static WebContentsImpl* CreateWithOpener(
96 const WebContents::CreateParams& params,
97 WebContentsImpl* opener);
99 // Returns the opener WebContentsImpl, if any. This can be set to null if the
100 // opener is closed or the page clears its window.opener.
101 WebContentsImpl* opener() const { return opener_; }
103 // Creates a WebContents to be used as a browser plugin guest.
104 static BrowserPluginGuest* CreateGuest(
105 BrowserContext* browser_context,
106 content::SiteInstance* site_instance,
107 int guest_instance_id,
108 scoped_ptr<base::DictionaryValue> extra_params);
110 // Creates a swapped out RenderView. This is used by the browser plugin to
111 // create a swapped out RenderView in the embedder render process for the
112 // guest, to expose the guest's window object to the embedder.
113 // This returns the routing ID of the newly created swapped out RenderView.
114 int CreateSwappedOutRenderView(SiteInstance* instance);
116 // Complex initialization here. Specifically needed to avoid having
117 // members call back into our virtual functions in the constructor.
118 virtual void Init(const WebContents::CreateParams& params);
120 // Returns the SavePackage which manages the page saving job. May be NULL.
121 SavePackage* save_package() const { return save_package_.get(); }
123 #if defined(OS_ANDROID)
124 JavaBridgeDispatcherHostManager* java_bridge_dispatcher_host_manager() const {
125 return java_bridge_dispatcher_host_manager_.get();
128 // In Android WebView, the RenderView needs created even there is no
129 // navigation entry, this allows Android WebViews to use
130 // javascript: URLs that load into the DOMWindow before the first page
131 // load. This is not safe to do in any context that a web page could get a
132 // reference to the DOMWindow before the first page load.
133 bool CreateRenderViewForInitialEmptyDocument();
136 // Expose the render manager for testing.
137 // TODO(creis): Remove this now that we can get to it via FrameTreeNode.
138 RenderFrameHostManager* GetRenderManagerForTesting();
140 // Returns guest browser plugin object, or NULL if this WebContents is not a
142 BrowserPluginGuest* GetBrowserPluginGuest() const;
144 // Sets a BrowserPluginGuest object for this WebContents. If this WebContents
145 // has a BrowserPluginGuest then that implies that it is being hosted by
146 // a BrowserPlugin object in an embedder renderer process.
147 void SetBrowserPluginGuest(BrowserPluginGuest* guest);
149 // Returns embedder browser plugin object, or NULL if this WebContents is not
151 BrowserPluginEmbedder* GetBrowserPluginEmbedder() const;
153 // Returns the BrowserPluginGuestManager object, or NULL if this web contents
154 // does not have a BrowserPluginGuestManager.
155 BrowserPluginGuestManager* GetBrowserPluginGuestManager() const;
157 // Gets the current fullscreen render widget's routing ID. Returns
158 // MSG_ROUTING_NONE when there is no fullscreen render widget.
159 int GetFullscreenWidgetRoutingID() const;
161 // Invoked when visible SSL state (as defined by SSLStatus) changes.
162 void DidChangeVisibleSSLState();
164 // Informs the render view host and the BrowserPluginEmbedder, if present, of
165 // a Drag Source End.
166 void DragSourceEndedAt(int client_x, int client_y, int screen_x,
167 int screen_y, blink::WebDragOperation operation);
169 // Informs the render view host and the BrowserPluginEmbedder, if present, of
170 // a Drag Source Move.
171 void DragSourceMovedTo(int client_x, int client_y,
172 int screen_x, int screen_y);
174 // A response has been received for a resource request.
175 void DidGetResourceResponseStart(
176 const ResourceRequestDetails& details);
178 // A redirect was received while requesting a resource.
179 void DidGetRedirectForResourceRequest(
180 RenderViewHost* render_view_host,
181 const ResourceRedirectDetails& details);
183 // WebContents ------------------------------------------------------
184 virtual WebContentsDelegate* GetDelegate() OVERRIDE;
185 virtual void SetDelegate(WebContentsDelegate* delegate) OVERRIDE;
186 virtual NavigationControllerImpl& GetController() OVERRIDE;
187 virtual const NavigationControllerImpl& GetController() const OVERRIDE;
188 virtual BrowserContext* GetBrowserContext() const OVERRIDE;
189 virtual RenderProcessHost* GetRenderProcessHost() const OVERRIDE;
190 virtual RenderFrameHost* GetMainFrame() OVERRIDE;
191 virtual RenderFrameHost* GetFocusedFrame() OVERRIDE;
192 virtual void ForEachFrame(
193 const base::Callback<void(RenderFrameHost*)>& on_frame) OVERRIDE;
194 virtual void SendToAllFrames(IPC::Message* message) OVERRIDE;
195 virtual RenderViewHost* GetRenderViewHost() const 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(const gfx::Size& capture_size) 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 GetLastActiveTime() 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 DidStartLoading(RenderFrameHost* render_frame_host,
308 bool to_different_document) OVERRIDE;
309 virtual void DidStopLoading(RenderFrameHost* render_frame_host) OVERRIDE;
310 virtual void SwappedOut(RenderFrameHost* render_frame_host) OVERRIDE;
311 virtual void WorkerCrashed(RenderFrameHost* render_frame_host) OVERRIDE;
312 virtual void ShowContextMenu(RenderFrameHost* render_frame_host,
313 const ContextMenuParams& params) OVERRIDE;
314 virtual WebContents* GetAsWebContents() OVERRIDE;
316 // RenderViewHostDelegate ----------------------------------------------------
317 virtual RenderViewHostDelegateView* GetDelegateView() OVERRIDE;
318 virtual bool OnMessageReceived(RenderViewHost* render_view_host,
319 const IPC::Message& message) OVERRIDE;
320 virtual const GURL& GetURL() const OVERRIDE;
321 virtual const GURL& GetVisibleURL() const OVERRIDE;
322 virtual const GURL& GetLastCommittedURL() const OVERRIDE;
323 // RenderFrameHostDelegate has the same method, so list it there because this
324 // interface is going away.
325 // virtual WebContents* GetAsWebContents() OVERRIDE;
326 virtual gfx::Rect GetRootWindowResizerRect() const OVERRIDE;
327 virtual void RenderViewCreated(RenderViewHost* render_view_host) OVERRIDE;
328 virtual void RenderViewReady(RenderViewHost* render_view_host) OVERRIDE;
329 virtual void RenderViewTerminated(RenderViewHost* render_view_host,
330 base::TerminationStatus status,
331 int error_code) OVERRIDE;
332 virtual void RenderViewDeleted(RenderViewHost* render_view_host) OVERRIDE;
333 virtual void UpdateState(RenderViewHost* render_view_host,
335 const PageState& page_state) OVERRIDE;
336 virtual void UpdateTitle(RenderViewHost* render_view_host,
338 const base::string16& title,
339 base::i18n::TextDirection title_direction) OVERRIDE;
340 virtual void UpdateEncoding(RenderViewHost* render_view_host,
341 const std::string& encoding) OVERRIDE;
342 virtual void UpdateTargetURL(int32 page_id, const GURL& url) OVERRIDE;
343 virtual void Close(RenderViewHost* render_view_host) OVERRIDE;
344 virtual void RequestMove(const gfx::Rect& new_bounds) OVERRIDE;
345 virtual void DidCancelLoading() OVERRIDE;
346 virtual void DidChangeLoadProgress(double progress) OVERRIDE;
347 virtual void DidDisownOpener(RenderViewHost* rvh) OVERRIDE;
348 virtual void DidAccessInitialDocument() OVERRIDE;
349 virtual void DocumentAvailableInMainFrame(
350 RenderViewHost* render_view_host) OVERRIDE;
351 virtual void DocumentOnLoadCompletedInMainFrame(
352 RenderViewHost* render_view_host,
353 int32 page_id) OVERRIDE;
354 virtual void RouteCloseEvent(RenderViewHost* rvh) OVERRIDE;
355 virtual void RouteMessageEvent(
357 const ViewMsg_PostMessage_Params& params) OVERRIDE;
358 virtual void RunJavaScriptMessage(RenderViewHost* rvh,
359 const base::string16& message,
360 const base::string16& default_prompt,
361 const GURL& frame_url,
362 JavaScriptMessageType type,
363 IPC::Message* reply_msg,
364 bool* did_suppress_message) OVERRIDE;
365 virtual void RunBeforeUnloadConfirm(RenderViewHost* rvh,
366 const base::string16& message,
368 IPC::Message* reply_msg) OVERRIDE;
369 virtual bool AddMessageToConsole(int32 level,
370 const base::string16& message,
372 const base::string16& source_id) OVERRIDE;
373 virtual RendererPreferences GetRendererPrefs(
374 BrowserContext* browser_context) const OVERRIDE;
375 virtual WebPreferences GetWebkitPrefs() OVERRIDE;
376 virtual void OnUserGesture() OVERRIDE;
377 virtual void OnIgnoredUIEvent() OVERRIDE;
378 virtual void RendererUnresponsive(RenderViewHost* render_view_host,
379 bool is_during_beforeunload,
380 bool is_during_unload) OVERRIDE;
381 virtual void RendererResponsive(RenderViewHost* render_view_host) OVERRIDE;
382 virtual void LoadStateChanged(const GURL& url,
383 const net::LoadStateWithParam& load_state,
384 uint64 upload_position,
385 uint64 upload_size) OVERRIDE;
386 virtual void Activate() OVERRIDE;
387 virtual void Deactivate() OVERRIDE;
388 virtual void LostCapture() OVERRIDE;
389 virtual void HandleMouseDown() OVERRIDE;
390 virtual void HandleMouseUp() OVERRIDE;
391 virtual void HandlePointerActivate() OVERRIDE;
392 virtual void HandleGestureBegin() OVERRIDE;
393 virtual void HandleGestureEnd() OVERRIDE;
394 virtual void RunFileChooser(
395 RenderViewHost* render_view_host,
396 const FileChooserParams& params) OVERRIDE;
397 virtual void ToggleFullscreenMode(bool enter_fullscreen) OVERRIDE;
398 virtual bool IsFullscreenForCurrentTab() const OVERRIDE;
399 virtual void UpdatePreferredSize(const gfx::Size& pref_size) OVERRIDE;
400 virtual void ResizeDueToAutoResize(const gfx::Size& new_size) OVERRIDE;
401 virtual void RequestToLockMouse(bool user_gesture,
402 bool last_unlocked_by_target) OVERRIDE;
403 virtual void LostMouseLock() OVERRIDE;
404 virtual void CreateNewWindow(
405 int render_process_id,
407 int main_frame_route_id,
408 const ViewHostMsg_CreateWindow_Params& params,
409 SessionStorageNamespace* session_storage_namespace) OVERRIDE;
410 virtual void CreateNewWidget(int render_process_id,
412 blink::WebPopupType popup_type) OVERRIDE;
413 virtual void CreateNewFullscreenWidget(int render_process_id,
414 int route_id) OVERRIDE;
415 virtual void ShowCreatedWindow(int route_id,
416 WindowOpenDisposition disposition,
417 const gfx::Rect& initial_pos,
418 bool user_gesture) OVERRIDE;
419 virtual void ShowCreatedWidget(int route_id,
420 const gfx::Rect& initial_pos) OVERRIDE;
421 virtual void ShowCreatedFullscreenWidget(int route_id) OVERRIDE;
422 virtual void RequestMediaAccessPermission(
423 const MediaStreamRequest& request,
424 const MediaResponseCallback& callback) OVERRIDE;
425 virtual SessionStorageNamespace* GetSessionStorageNamespace(
426 SiteInstance* instance) OVERRIDE;
427 virtual FrameTree* GetFrameTree() OVERRIDE;
428 virtual void AccessibilityEventReceived(
429 const std::vector<AXEventNotificationDetails>& details) OVERRIDE;
431 // NavigatorDelegate ---------------------------------------------------------
433 virtual void DidStartProvisionalLoad(
434 RenderFrameHostImpl* render_frame_host,
435 int parent_routing_id,
436 const GURL& validated_url,
438 bool is_iframe_srcdoc) OVERRIDE;
439 virtual void DidFailProvisionalLoadWithError(
440 RenderFrameHostImpl* render_frame_host,
441 const FrameHostMsg_DidFailProvisionalLoadWithError_Params& params)
443 virtual void DidFailLoadWithError(
444 RenderFrameHostImpl* render_frame_host,
447 const base::string16& error_description) OVERRIDE;
448 virtual void DidRedirectProvisionalLoad(
449 RenderFrameHostImpl* render_frame_host,
450 const GURL& validated_target_url) OVERRIDE;
451 virtual void DidCommitProvisionalLoad(
452 RenderFrameHostImpl* render_frame_host,
453 const base::string16& frame_unique_name,
456 PageTransition transition_type) OVERRIDE;
457 virtual void DidNavigateMainFramePostCommit(
458 const LoadCommittedDetails& details,
459 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) OVERRIDE;
460 virtual void DidNavigateAnyFramePostCommit(
461 RenderFrameHostImpl* render_frame_host,
462 const LoadCommittedDetails& details,
463 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) OVERRIDE;
464 virtual void SetMainFrameMimeType(const std::string& mime_type) OVERRIDE;
465 virtual bool CanOverscrollContent() 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;
474 virtual void RequestOpenURL(RenderFrameHostImpl* render_frame_host,
475 const OpenURLParams& params) OVERRIDE;
477 // RenderWidgetHostDelegate --------------------------------------------------
479 virtual void RenderWidgetDeleted(
480 RenderWidgetHostImpl* render_widget_host) OVERRIDE;
481 virtual bool PreHandleKeyboardEvent(
482 const NativeWebKeyboardEvent& event,
483 bool* is_keyboard_shortcut) OVERRIDE;
484 virtual void HandleKeyboardEvent(
485 const NativeWebKeyboardEvent& event) OVERRIDE;
486 virtual bool HandleWheelEvent(
487 const blink::WebMouseWheelEvent& event) OVERRIDE;
488 virtual bool PreHandleGestureEvent(
489 const blink::WebGestureEvent& event) OVERRIDE;
490 virtual void DidSendScreenRects(RenderWidgetHostImpl* rwh) OVERRIDE;
492 virtual gfx::NativeViewAccessible GetParentNativeViewAccessible() OVERRIDE;
495 // RenderFrameHostManager::Delegate ------------------------------------------
497 virtual bool CreateRenderViewForRenderManager(
498 RenderViewHost* render_view_host,
500 CrossProcessFrameConnector* frame_connector) OVERRIDE;
501 virtual void BeforeUnloadFiredFromRenderManager(
502 bool proceed, const base::TimeTicks& proceed_time,
503 bool* proceed_to_fire_unload) OVERRIDE;
504 virtual void RenderProcessGoneFromRenderManager(
505 RenderViewHost* render_view_host) OVERRIDE;
506 virtual void UpdateRenderViewSizeForRenderManager() OVERRIDE;
507 virtual void CancelModalDialogsForRenderManager() OVERRIDE;
508 virtual void NotifySwappedFromRenderManager(
509 RenderViewHost* old_host, RenderViewHost* new_host) OVERRIDE;
510 virtual int CreateOpenerRenderViewsForRenderManager(
511 SiteInstance* instance) OVERRIDE;
512 virtual NavigationControllerImpl&
513 GetControllerForRenderManager() OVERRIDE;
514 virtual WebUIImpl* CreateWebUIForRenderManager(const GURL& url) OVERRIDE;
515 virtual NavigationEntry*
516 GetLastCommittedNavigationEntryForRenderManager() OVERRIDE;
517 virtual bool FocusLocationBarByDefault() OVERRIDE;
518 virtual void SetFocusToLocationBar(bool select_all) OVERRIDE;
519 virtual void CreateViewAndSetSizeForRVH(RenderViewHost* rvh) OVERRIDE;
520 virtual bool IsHidden() OVERRIDE;
522 // NotificationObserver ------------------------------------------------------
524 virtual void Observe(int type,
525 const NotificationSource& source,
526 const NotificationDetails& details) OVERRIDE;
528 // NavigationControllerDelegate ----------------------------------------------
530 virtual WebContents* GetWebContents() OVERRIDE;
531 virtual void NotifyNavigationEntryCommitted(
532 const LoadCommittedDetails& load_details) OVERRIDE;
534 // Invoked before a form repost warning is shown.
535 virtual void NotifyBeforeFormRepostWarningShow() OVERRIDE;
537 // Activate this WebContents and show a form repost warning.
538 virtual void ActivateAndShowRepostFormWarningDialog() OVERRIDE;
540 // Updates the max page ID for the current SiteInstance in this
541 // WebContentsImpl to be at least |page_id|.
542 virtual void UpdateMaxPageID(int32 page_id) OVERRIDE;
544 // Updates the max page ID for the given SiteInstance in this WebContentsImpl
545 // to be at least |page_id|.
546 virtual void UpdateMaxPageIDForSiteInstance(SiteInstance* site_instance,
547 int32 page_id) OVERRIDE;
549 // Copy the current map of SiteInstance ID to max page ID from another tab.
550 // This is necessary when this tab adopts the NavigationEntries from
552 virtual void CopyMaxPageIDsFrom(WebContents* web_contents) OVERRIDE;
554 // Called by the NavigationController to cause the WebContentsImpl to navigate
555 // to the current pending entry. The NavigationController should be called
556 // back with RendererDidNavigate on success or DiscardPendingEntry on failure.
557 // The callbacks can be inside of this function, or at some future time.
559 // The entry has a PageID of -1 if newly created (corresponding to navigation
562 // If this method returns false, then the navigation is discarded (equivalent
563 // to calling DiscardPendingEntry on the NavigationController).
564 virtual bool NavigateToPendingEntry(
565 NavigationController::ReloadType reload_type) OVERRIDE;
567 // Sets the history for this WebContentsImpl to |history_length| entries, and
568 // moves the current page_id to the last entry in the list if it's valid.
569 // This is mainly used when a prerendered page is swapped into the current
570 // tab. The method is virtual for testing.
571 virtual void SetHistoryLengthAndPrune(
572 const SiteInstance* site_instance,
573 int merge_history_length,
574 int32 minimum_page_id) OVERRIDE;
576 // Called by InterstitialPageImpl when it creates a RenderFrameHost.
577 virtual void RenderFrameForInterstitialPageCreated(
578 RenderFrameHost* render_frame_host) OVERRIDE;
580 // Sets the passed interstitial as the currently showing interstitial.
581 // No interstitial page should already be attached.
582 virtual void AttachInterstitialPage(
583 InterstitialPageImpl* interstitial_page) OVERRIDE;
585 // Unsets the currently showing interstitial.
586 virtual void DetachInterstitialPage() OVERRIDE;
588 // Changes the IsLoading state and notifies the delegate as needed.
589 // |details| is used to provide details on the load that just finished
590 // (but can be null if not applicable).
591 virtual void SetIsLoading(RenderViewHost* render_view_host,
593 bool to_different_document,
594 LoadNotificationDetails* details) OVERRIDE;
596 typedef base::Callback<void(WebContents*)> CreatedCallback;
599 friend class NavigationControllerImpl;
600 friend class TestNavigationObserver;
601 friend class WebContentsObserver;
602 friend class WebContents; // To implement factory methods.
604 FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest, NoJSMessageOnInterstitials);
605 FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest, UpdateTitle);
606 FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest, FindOpenerRVHWhenPending);
607 FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest,
608 CrossSiteCantPreemptAfterUnload);
609 FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest, PendingContents);
610 FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest, FrameTreeShape);
611 FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest, GetLastActiveTime);
612 FRIEND_TEST_ALL_PREFIXES(FormStructureBrowserTest, HTMLFiles);
613 FRIEND_TEST_ALL_PREFIXES(NavigationControllerTest, HistoryNavigate);
614 FRIEND_TEST_ALL_PREFIXES(RenderFrameHostManagerTest, PageDoesBackAndReload);
616 // So InterstitialPageImpl can access SetIsLoading.
617 friend class InterstitialPageImpl;
619 // TODO(brettw) TestWebContents shouldn't exist!
620 friend class TestWebContents;
622 class DestructionObserver;
624 // See WebContents::Create for a description of these parameters.
625 WebContentsImpl(BrowserContext* browser_context,
626 WebContentsImpl* opener);
628 // Add and remove observers for page navigation notifications. The order in
629 // which notifications are sent to observers is undefined. Clients must be
630 // sure to remove the observer before they go away.
631 void AddObserver(WebContentsObserver* observer);
632 void RemoveObserver(WebContentsObserver* observer);
634 // Clears this tab's opener if it has been closed.
635 void OnWebContentsDestroyed(WebContentsImpl* web_contents);
637 // Creates and adds to the map a destruction observer watching |web_contents|.
638 // No-op if such an observer already exists.
639 void AddDestructionObserver(WebContentsImpl* web_contents);
641 // Deletes and removes from the map a destruction observer
642 // watching |web_contents|. No-op if there is no such observer.
643 void RemoveDestructionObserver(WebContentsImpl* web_contents);
645 // Callback function when showing JS dialogs.
646 void OnDialogClosed(RenderViewHost* rvh,
647 IPC::Message* reply_msg,
649 const base::string16& user_input);
651 // Callback function when requesting permission to access the PPAPI broker.
652 // |result| is true if permission was granted.
653 void OnPpapiBrokerPermissionResult(int routing_id, bool result);
655 bool OnMessageReceived(RenderViewHost* render_view_host,
656 RenderFrameHost* render_frame_host,
657 const IPC::Message& message);
659 // IPC message handlers.
660 void OnDidLoadResourceFromMemoryCache(const GURL& url,
661 const std::string& security_info,
662 const std::string& http_request,
663 const std::string& mime_type,
664 ResourceType::Type resource_type);
665 void OnDidDisplayInsecureContent();
666 void OnDidRunInsecureContent(const std::string& security_origin,
667 const GURL& target_url);
668 void OnDocumentLoadedInFrame();
669 void OnDidFinishLoad(const GURL& url);
670 void OnGoToEntryAtOffset(int offset);
671 void OnUpdateZoomLimits(int minimum_percent,
674 void OnEnumerateDirectory(int request_id, const base::FilePath& path);
676 void OnRegisterProtocolHandler(const std::string& protocol,
678 const base::string16& title,
680 void OnFindReply(int request_id,
681 int number_of_matches,
682 const gfx::Rect& selection_rect,
683 int active_match_ordinal,
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);
694 void OnPepperPluginHung(int plugin_child_id,
695 const base::FilePath& path,
697 void OnPluginCrashed(const base::FilePath& plugin_path,
698 base::ProcessId plugin_pid);
699 void OnDomOperationResponse(const std::string& json_string,
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 OnMediaPlayingNotification(int64 player_cookie,
725 void OnMediaPausedNotification(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.
747 // If our controller was restored, update the max page ID associated with the
748 // given RenderViewHost to be larger than the number of restored entries.
749 // This is called in CreateRenderView before any navigations in the RenderView
750 // have begun, to prevent any races in updating RenderView::next_page_id.
751 void UpdateMaxPageIDIfNecessary(RenderViewHost* rvh);
753 // Saves the given title to the navigation entry and does associated work. It
754 // will update history and the view for the new title, and also synthesize
755 // titles for file URLs that have none (so we require that the URL of the
756 // entry already be set).
758 // This is used as the backend for state updates, which include a new title,
759 // or the dedicated set title message. It returns true if the new title is
760 // different and was therefore updated.
761 bool UpdateTitleForEntry(NavigationEntryImpl* entry,
762 const base::string16& title);
764 // Recursively creates swapped out RenderViews for this tab's opener chain
765 // (including this tab) in the given SiteInstance, allowing other tabs to send
766 // cross-process JavaScript calls to their opener(s). Returns the route ID of
767 // this tab's RenderView for |instance|.
768 int CreateOpenerRenderViews(SiteInstance* instance);
770 // Helper for CreateNewWidget/CreateNewFullscreenWidget.
771 void CreateNewWidget(int render_process_id,
774 blink::WebPopupType popup_type);
776 // Helper for ShowCreatedWidget/ShowCreatedFullscreenWidget.
777 void ShowCreatedWidget(int route_id,
779 const gfx::Rect& initial_pos);
781 // Finds the new RenderWidgetHost and returns it. Note that this can only be
782 // called once as this call also removes it from the internal map.
783 RenderWidgetHostView* GetCreatedWidget(int route_id);
785 // Finds the new WebContentsImpl by route_id, initializes it for
786 // renderer-initiated creation, and returns it. Note that this can only be
787 // called once as this call also removes it from the internal map.
788 WebContentsImpl* GetCreatedWindow(int route_id);
790 // Returns the RenderWidgetHostView that is associated with a native window
791 // and can be used in showing created widgets.
792 // If this WebContents belongs to a browser plugin guest, there is no native
793 // window 'view' associated with this WebContents. This method returns the
794 // 'view' of the embedder instead.
795 RenderWidgetHostViewPort* GetRenderWidgetHostViewPort() const;
797 // Misc non-view stuff -------------------------------------------------------
799 // Helper functions for sending notifications.
800 void NotifySwapped(RenderViewHost* old_host, RenderViewHost* new_host);
801 void NotifyDisconnected();
803 void SetEncoding(const std::string& encoding);
805 // TODO(creis): This should take in a FrameTreeNode to know which node's
806 // render manager to return. For now, we just return the root's.
807 RenderFrameHostManager* GetRenderManager() const;
809 RenderViewHostImpl* GetRenderViewHostImpl();
811 // Removes browser plugin embedder if there is one.
812 void RemoveBrowserPluginEmbedder();
814 // Clear |render_view_host|'s PowerSaveBlockers.
815 void ClearPowerSaveBlockers(RenderViewHost* render_view_host);
817 // Clear all PowerSaveBlockers, leave power_save_blocker_ empty.
818 void ClearAllPowerSaveBlockers();
820 // Helper function to invoke WebContentsDelegate::GetSizeForNewRenderView().
821 gfx::Size GetSizeForNewRenderView() const;
823 void OnFrameRemoved(RenderViewHostImpl* render_view_host,
824 int frame_routing_id);
826 // Helper method that's called whenever |preferred_size_| or
827 // |preferred_size_for_capture_| changes, to propagate the new value to the
829 void OnPreferredSizeChanged(const gfx::Size& old_size);
831 // Adds/removes a callback called on creation of each new WebContents.
832 // Deprecated, about to remove.
833 static void AddCreatedCallback(const CreatedCallback& callback);
834 static void RemoveCreatedCallback(const CreatedCallback& callback);
836 // Data for core operation ---------------------------------------------------
838 // Delegate for notifying our owner about stuff. Not owned by us.
839 WebContentsDelegate* delegate_;
841 // Handles the back/forward list and loading.
842 NavigationControllerImpl controller_;
844 // The corresponding view.
845 scoped_ptr<WebContentsViewPort> view_;
847 // The view of the RVHD. Usually this is our WebContentsView implementation,
848 // but if an embedder uses a different WebContentsView, they'll need to
850 RenderViewHostDelegateView* render_view_host_delegate_view_;
852 // Tracks created WebContentsImpl objects that have not been shown yet. They
853 // are identified by the route ID passed to CreateNewWindow.
854 typedef std::map<int, WebContentsImpl*> PendingContents;
855 PendingContents pending_contents_;
857 // These maps hold on to the widgets that we created on behalf of the renderer
858 // that haven't shown yet.
859 typedef std::map<int, RenderWidgetHostView*> PendingWidgetViews;
860 PendingWidgetViews pending_widget_views_;
862 typedef std::map<WebContentsImpl*, DestructionObserver*> DestructionObservers;
863 DestructionObservers destruction_observers_;
865 // A list of observers notified when page state changes. Weak references.
866 // This MUST be listed above frame_tree_ since at destruction time the
867 // latter might cause RenderViewHost's destructor to call us and we might use
868 // the observer list then.
869 ObserverList<WebContentsObserver> observers_;
871 // The tab that opened this tab, if any. Will be set to null if the opener
873 WebContentsImpl* opener_;
876 gfx::NativeViewAccessible accessible_parent_;
879 // Helper classes ------------------------------------------------------------
881 // Maps the RenderViewHost to its media_player_cookie and PowerSaveBlocker
882 // pairs. Key is the RenderViewHost, value is the map which maps player_cookie
883 // on to PowerSaveBlocker.
884 typedef std::map<RenderViewHost*, std::map<int64, PowerSaveBlocker*> >
886 PowerSaveBlockerMap power_save_blockers_;
888 // Manages the frame tree of the page and process swaps in each node.
889 FrameTree frame_tree_;
891 #if defined(OS_ANDROID)
892 // Manages injecting Java objects into all RenderViewHosts associated with
893 // this WebContentsImpl.
894 scoped_ptr<JavaBridgeDispatcherHostManager>
895 java_bridge_dispatcher_host_manager_;
898 // SavePackage, lazily created.
899 scoped_refptr<SavePackage> save_package_;
901 // Data for loading state ----------------------------------------------------
903 // Indicates whether we're currently loading a resource.
906 // Indicates if the tab is considered crashed.
907 base::TerminationStatus crashed_status_;
908 int crashed_error_code_;
910 // Whether this WebContents is waiting for a first-response for the
911 // main resource of the page. This controls whether the throbber state is
912 // "waiting" or "loading."
913 bool waiting_for_response_;
915 // Map of SiteInstance ID to max page ID for this tab. A page ID is specific
916 // to a given tab and SiteInstance, and must be valid for the lifetime of the
918 std::map<int32, int32> max_page_ids_;
920 // The current load state and the URL associated with it.
921 net::LoadStateWithParam load_state_;
922 base::string16 load_state_host_;
923 // Upload progress, for displaying in the status bar.
924 // Set to zero when there is no significant upload happening.
926 uint64 upload_position_;
928 // Data for current page -----------------------------------------------------
930 // When a title cannot be taken from any entry, this title will be used.
931 base::string16 page_title_when_no_navigation_entry_;
933 // When a navigation occurs, we record its contents MIME type. It can be
934 // used to check whether we can do something for some special contents.
935 std::string contents_mime_type_;
937 // Character encoding.
938 std::string encoding_;
940 // True if this is a secure page which displayed insecure content.
941 bool displayed_insecure_content_;
943 // Data for misc internal state ----------------------------------------------
945 // When > 0, the WebContents is currently being captured (e.g., for
946 // screenshots or mirroring); and the underlying RenderWidgetHost should not
947 // be told it is hidden.
950 // Tracks whether RWHV should be visible once capturer_count_ becomes zero.
951 bool should_normally_be_visible_;
954 bool is_being_destroyed_;
956 // Indicates whether we should notify about disconnection of this
957 // WebContentsImpl. This is used to ensure disconnection notifications only
958 // happen if a connection notification has happened and that they happen only
960 bool notify_disconnection_;
962 // Pointer to the JavaScript dialog manager, lazily assigned. Used because the
963 // delegate of this WebContentsImpl is nulled before its destructor is called.
964 JavaScriptDialogManager* dialog_manager_;
966 // Set to true when there is an active "before unload" dialog. When true,
967 // we've forced the throbber to start in Navigate, and we need to remember to
968 // turn it off in OnJavaScriptMessageBoxClosed if the navigation is canceled.
969 bool is_showing_before_unload_dialog_;
971 // Settings that get passed to the renderer process.
972 RendererPreferences renderer_preferences_;
974 // The time that this WebContents was last made active. The initial value is
975 // the WebContents creation time.
976 base::TimeTicks last_active_time_;
978 // See description above setter.
979 bool closed_by_user_gesture_;
981 // Minimum/maximum zoom percent.
982 int minimum_zoom_percent_;
983 int maximum_zoom_percent_;
984 // If true, the default zoom limits have been overriden for this tab, in which
985 // case we don't want saved settings to apply to it and we don't want to
987 bool temporary_zoom_settings_;
989 // The intrinsic size of the page.
990 gfx::Size preferred_size_;
992 // The preferred size for content screen capture. When |capturer_count_| > 0,
993 // this overrides |preferred_size_|.
994 gfx::Size preferred_size_for_capture_;
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/RenderFrame so that
1026 // the handlers can get a pointer to the RVH through which the message was
1028 RenderViewHost* render_view_message_source_;
1029 RenderFrameHost* render_frame_message_source_;
1031 // All live RenderWidgetHostImpls that are created by this object and may
1033 std::set<RenderWidgetHostImpl*> created_widgets_;
1035 // Routing id of the shown fullscreen widget or MSG_ROUTING_NONE otherwise.
1036 int fullscreen_widget_routing_id_;
1038 // Maps the ids of pending image downloads to their callbacks
1039 typedef std::map<int, ImageDownloadCallback> ImageDownloadMap;
1040 ImageDownloadMap image_download_map_;
1042 // Whether this WebContents is responsible for displaying a subframe in a
1043 // different process from its parent page.
1046 DISALLOW_COPY_AND_ASSIGN(WebContentsImpl);
1049 } // namespace content
1051 #endif // CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_IMPL_H_