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(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) OVERRIDE;
308 virtual void DidStopLoading(RenderFrameHost* render_frame_host) OVERRIDE;
309 virtual void WorkerCrashed(RenderFrameHost* render_frame_host) OVERRIDE;
310 virtual void ShowContextMenu(RenderFrameHost* render_frame_host,
311 const ContextMenuParams& params) OVERRIDE;
312 virtual WebContents* GetAsWebContents() OVERRIDE;
314 // RenderViewHostDelegate ----------------------------------------------------
315 virtual RenderViewHostDelegateView* GetDelegateView() OVERRIDE;
316 virtual RenderViewHostDelegate::RendererManagement*
317 GetRendererManagementDelegate() 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 SwappedOut(RenderViewHost* render_view_host) OVERRIDE;
346 virtual void DidCancelLoading() OVERRIDE;
347 virtual void DidChangeLoadProgress(double progress) OVERRIDE;
348 virtual void DidDisownOpener(RenderViewHost* rvh) OVERRIDE;
349 virtual void DidAccessInitialDocument() OVERRIDE;
350 virtual void DocumentAvailableInMainFrame(
351 RenderViewHost* render_view_host) OVERRIDE;
352 virtual void DocumentOnLoadCompletedInMainFrame(
353 RenderViewHost* render_view_host,
354 int32 page_id) OVERRIDE;
355 virtual void RequestOpenURL(RenderViewHost* rvh,
357 const Referrer& referrer,
358 WindowOpenDisposition disposition,
359 int64 source_frame_id,
360 bool should_replace_current_entry,
361 bool user_gesture) OVERRIDE;
362 virtual void RequestTransferURL(
364 const std::vector<GURL>& redirect_chain,
365 const Referrer& referrer,
366 PageTransition page_transition,
367 WindowOpenDisposition disposition,
368 int64 source_frame_id,
369 const GlobalRequestID& transferred_global_request_id,
370 bool should_replace_current_entry,
371 bool user_gesture) OVERRIDE;
372 virtual void RouteCloseEvent(RenderViewHost* rvh) OVERRIDE;
373 virtual void RouteMessageEvent(
375 const ViewMsg_PostMessage_Params& params) OVERRIDE;
376 virtual void RunJavaScriptMessage(RenderViewHost* rvh,
377 const base::string16& message,
378 const base::string16& default_prompt,
379 const GURL& frame_url,
380 JavaScriptMessageType type,
381 IPC::Message* reply_msg,
382 bool* did_suppress_message) OVERRIDE;
383 virtual void RunBeforeUnloadConfirm(RenderViewHost* rvh,
384 const base::string16& message,
386 IPC::Message* reply_msg) OVERRIDE;
387 virtual bool AddMessageToConsole(int32 level,
388 const base::string16& message,
390 const base::string16& source_id) OVERRIDE;
391 virtual RendererPreferences GetRendererPrefs(
392 BrowserContext* browser_context) const OVERRIDE;
393 virtual WebPreferences GetWebkitPrefs() OVERRIDE;
394 virtual void OnUserGesture() OVERRIDE;
395 virtual void OnIgnoredUIEvent() OVERRIDE;
396 virtual void RendererUnresponsive(RenderViewHost* render_view_host,
397 bool is_during_beforeunload,
398 bool is_during_unload) OVERRIDE;
399 virtual void RendererResponsive(RenderViewHost* render_view_host) OVERRIDE;
400 virtual void LoadStateChanged(const GURL& url,
401 const net::LoadStateWithParam& load_state,
402 uint64 upload_position,
403 uint64 upload_size) OVERRIDE;
404 virtual void Activate() OVERRIDE;
405 virtual void Deactivate() OVERRIDE;
406 virtual void LostCapture() OVERRIDE;
407 virtual void HandleMouseDown() OVERRIDE;
408 virtual void HandleMouseUp() OVERRIDE;
409 virtual void HandlePointerActivate() OVERRIDE;
410 virtual void HandleGestureBegin() OVERRIDE;
411 virtual void HandleGestureEnd() OVERRIDE;
412 virtual void RunFileChooser(
413 RenderViewHost* render_view_host,
414 const FileChooserParams& params) OVERRIDE;
415 virtual void ToggleFullscreenMode(bool enter_fullscreen) OVERRIDE;
416 virtual bool IsFullscreenForCurrentTab() const OVERRIDE;
417 virtual void UpdatePreferredSize(const gfx::Size& pref_size) OVERRIDE;
418 virtual void ResizeDueToAutoResize(const gfx::Size& new_size) OVERRIDE;
419 virtual void RequestToLockMouse(bool user_gesture,
420 bool last_unlocked_by_target) OVERRIDE;
421 virtual void LostMouseLock() OVERRIDE;
422 virtual void CreateNewWindow(
423 int render_process_id,
425 int main_frame_route_id,
426 const ViewHostMsg_CreateWindow_Params& params,
427 SessionStorageNamespace* session_storage_namespace) OVERRIDE;
428 virtual void CreateNewWidget(int render_process_id,
430 blink::WebPopupType popup_type) OVERRIDE;
431 virtual void CreateNewFullscreenWidget(int render_process_id,
432 int route_id) OVERRIDE;
433 virtual void ShowCreatedWindow(int route_id,
434 WindowOpenDisposition disposition,
435 const gfx::Rect& initial_pos,
436 bool user_gesture) OVERRIDE;
437 virtual void ShowCreatedWidget(int route_id,
438 const gfx::Rect& initial_pos) OVERRIDE;
439 virtual void ShowCreatedFullscreenWidget(int route_id) OVERRIDE;
440 virtual void RequestMediaAccessPermission(
441 const MediaStreamRequest& request,
442 const MediaResponseCallback& callback) OVERRIDE;
443 virtual SessionStorageNamespace* GetSessionStorageNamespace(
444 SiteInstance* instance) OVERRIDE;
445 virtual FrameTree* GetFrameTree() OVERRIDE;
447 // NavigatorDelegate ---------------------------------------------------------
449 virtual void DidStartProvisionalLoad(
450 RenderFrameHostImpl* render_frame_host,
452 int64 parent_frame_id,
454 const GURL& validated_url,
456 bool is_iframe_srcdoc) OVERRIDE;
457 virtual void DidFailProvisionalLoadWithError(
458 RenderFrameHostImpl* render_frame_host,
459 const FrameHostMsg_DidFailProvisionalLoadWithError_Params& params)
461 virtual void DidFailLoadWithError(
462 RenderFrameHostImpl* render_frame_host,
467 const base::string16& error_description) OVERRIDE;
468 virtual void DidRedirectProvisionalLoad(
469 RenderFrameHostImpl* render_frame_host,
470 const GURL& validated_target_url) OVERRIDE;
471 virtual void DidCommitProvisionalLoad(
473 const base::string16& frame_unique_name,
476 PageTransition transition_type,
477 RenderFrameHostImpl* render_frame_host) OVERRIDE;
478 virtual void DidNavigateMainFramePostCommit(
479 const LoadCommittedDetails& details,
480 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) OVERRIDE;
481 virtual void DidNavigateAnyFramePostCommit(
482 RenderFrameHostImpl* render_frame_host,
483 const LoadCommittedDetails& details,
484 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) OVERRIDE;
485 virtual void SetMainFrameMimeType(const std::string& mime_type) OVERRIDE;
486 virtual bool CanOverscrollContent() OVERRIDE;
487 virtual void NotifyChangedNavigationState(
488 InvalidateTypes changed_flags) OVERRIDE;
489 virtual void AboutToNavigateRenderFrame(
490 RenderFrameHostImpl* render_frame_host) OVERRIDE;
491 virtual void DidStartNavigationToPendingEntry(
492 RenderFrameHostImpl* render_frame_host,
494 NavigationController::ReloadType reload_type) OVERRIDE;
496 // RenderWidgetHostDelegate --------------------------------------------------
498 virtual void RenderWidgetDeleted(
499 RenderWidgetHostImpl* render_widget_host) OVERRIDE;
500 virtual bool PreHandleKeyboardEvent(
501 const NativeWebKeyboardEvent& event,
502 bool* is_keyboard_shortcut) OVERRIDE;
503 virtual void HandleKeyboardEvent(
504 const NativeWebKeyboardEvent& event) OVERRIDE;
505 virtual bool PreHandleWheelEvent(
506 const blink::WebMouseWheelEvent& event) OVERRIDE;
507 virtual bool PreHandleGestureEvent(
508 const blink::WebGestureEvent& event) OVERRIDE;
509 virtual void DidSendScreenRects(RenderWidgetHostImpl* rwh) OVERRIDE;
511 virtual gfx::NativeViewAccessible GetParentNativeViewAccessible() OVERRIDE;
514 // RenderFrameHostManager::Delegate ------------------------------------------
516 virtual bool CreateRenderViewForRenderManager(
517 RenderViewHost* render_view_host,
519 CrossProcessFrameConnector* frame_connector) OVERRIDE;
520 virtual void BeforeUnloadFiredFromRenderManager(
521 bool proceed, const base::TimeTicks& proceed_time,
522 bool* proceed_to_fire_unload) OVERRIDE;
523 virtual void RenderProcessGoneFromRenderManager(
524 RenderViewHost* render_view_host) OVERRIDE;
525 virtual void UpdateRenderViewSizeForRenderManager() OVERRIDE;
526 virtual void CancelModalDialogsForRenderManager() OVERRIDE;
527 virtual void NotifySwappedFromRenderManager(
528 RenderViewHost* old_host, RenderViewHost* new_host) OVERRIDE;
529 virtual int CreateOpenerRenderViewsForRenderManager(
530 SiteInstance* instance) OVERRIDE;
531 virtual NavigationControllerImpl&
532 GetControllerForRenderManager() OVERRIDE;
533 virtual WebUIImpl* CreateWebUIForRenderManager(const GURL& url) OVERRIDE;
534 virtual NavigationEntry*
535 GetLastCommittedNavigationEntryForRenderManager() OVERRIDE;
536 virtual bool FocusLocationBarByDefault() OVERRIDE;
537 virtual void SetFocusToLocationBar(bool select_all) OVERRIDE;
538 virtual void CreateViewAndSetSizeForRVH(RenderViewHost* rvh) OVERRIDE;
539 virtual bool IsHidden() OVERRIDE;
541 // NotificationObserver ------------------------------------------------------
543 virtual void Observe(int type,
544 const NotificationSource& source,
545 const NotificationDetails& details) OVERRIDE;
547 // NavigationControllerDelegate ----------------------------------------------
549 virtual WebContents* GetWebContents() OVERRIDE;
550 virtual void NotifyNavigationEntryCommitted(
551 const LoadCommittedDetails& load_details) OVERRIDE;
553 // Invoked before a form repost warning is shown.
554 virtual void NotifyBeforeFormRepostWarningShow() OVERRIDE;
556 // Activate this WebContents and show a form repost warning.
557 virtual void ActivateAndShowRepostFormWarningDialog() OVERRIDE;
559 // Updates the max page ID for the current SiteInstance in this
560 // WebContentsImpl to be at least |page_id|.
561 virtual void UpdateMaxPageID(int32 page_id) OVERRIDE;
563 // Updates the max page ID for the given SiteInstance in this WebContentsImpl
564 // to be at least |page_id|.
565 virtual void UpdateMaxPageIDForSiteInstance(SiteInstance* site_instance,
566 int32 page_id) OVERRIDE;
568 // Copy the current map of SiteInstance ID to max page ID from another tab.
569 // This is necessary when this tab adopts the NavigationEntries from
571 virtual void CopyMaxPageIDsFrom(WebContents* web_contents) OVERRIDE;
573 // Called by the NavigationController to cause the WebContentsImpl to navigate
574 // to the current pending entry. The NavigationController should be called
575 // back with RendererDidNavigate on success or DiscardPendingEntry on failure.
576 // The callbacks can be inside of this function, or at some future time.
578 // The entry has a PageID of -1 if newly created (corresponding to navigation
581 // If this method returns false, then the navigation is discarded (equivalent
582 // to calling DiscardPendingEntry on the NavigationController).
583 virtual bool NavigateToPendingEntry(
584 NavigationController::ReloadType reload_type) OVERRIDE;
586 // Sets the history for this WebContentsImpl to |history_length| entries, and
587 // moves the current page_id to the last entry in the list if it's valid.
588 // This is mainly used when a prerendered page is swapped into the current
589 // tab. The method is virtual for testing.
590 virtual void SetHistoryLengthAndPrune(
591 const SiteInstance* site_instance,
592 int merge_history_length,
593 int32 minimum_page_id) OVERRIDE;
595 // Called by InterstitialPageImpl when it creates a RenderFrameHost.
596 virtual void RenderFrameForInterstitialPageCreated(
597 RenderFrameHost* render_frame_host) OVERRIDE;
599 // Sets the passed interstitial as the currently showing interstitial.
600 // No interstitial page should already be attached.
601 virtual void AttachInterstitialPage(
602 InterstitialPageImpl* interstitial_page) OVERRIDE;
604 // Unsets the currently showing interstitial.
605 virtual void DetachInterstitialPage() OVERRIDE;
607 // Changes the IsLoading state and notifies the delegate as needed.
608 // |details| is used to provide details on the load that just finished
609 // (but can be null if not applicable).
610 virtual void SetIsLoading(RenderViewHost* render_view_host,
612 LoadNotificationDetails* details) OVERRIDE;
614 typedef base::Callback<void(WebContents*)> CreatedCallback;
617 friend class NavigationControllerImpl;
618 friend class TestNavigationObserver;
619 friend class WebContentsObserver;
620 friend class WebContents; // To implement factory methods.
622 FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest, NoJSMessageOnInterstitials);
623 FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest, UpdateTitle);
624 FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest, FindOpenerRVHWhenPending);
625 FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest,
626 CrossSiteCantPreemptAfterUnload);
627 FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest, PendingContents);
628 FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest, FrameTreeShape);
629 FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest, GetLastActiveTime);
630 FRIEND_TEST_ALL_PREFIXES(FormStructureBrowserTest, HTMLFiles);
631 FRIEND_TEST_ALL_PREFIXES(NavigationControllerTest, HistoryNavigate);
632 FRIEND_TEST_ALL_PREFIXES(RenderFrameHostManagerTest, PageDoesBackAndReload);
634 // So InterstitialPageImpl can access SetIsLoading.
635 friend class InterstitialPageImpl;
637 // TODO(brettw) TestWebContents shouldn't exist!
638 friend class TestWebContents;
640 class DestructionObserver;
642 // See WebContents::Create for a description of these parameters.
643 WebContentsImpl(BrowserContext* browser_context,
644 WebContentsImpl* opener);
646 // Add and remove observers for page navigation notifications. The order in
647 // which notifications are sent to observers is undefined. Clients must be
648 // sure to remove the observer before they go away.
649 void AddObserver(WebContentsObserver* observer);
650 void RemoveObserver(WebContentsObserver* observer);
652 // Clears this tab's opener if it has been closed.
653 void OnWebContentsDestroyed(WebContentsImpl* web_contents);
655 // Creates and adds to the map a destruction observer watching |web_contents|.
656 // No-op if such an observer already exists.
657 void AddDestructionObserver(WebContentsImpl* web_contents);
659 // Deletes and removes from the map a destruction observer
660 // watching |web_contents|. No-op if there is no such observer.
661 void RemoveDestructionObserver(WebContentsImpl* web_contents);
663 // Callback function when showing JS dialogs.
664 void OnDialogClosed(RenderViewHost* rvh,
665 IPC::Message* reply_msg,
667 const base::string16& user_input);
669 // Callback function when requesting permission to access the PPAPI broker.
670 // |result| is true if permission was granted.
671 void OnPpapiBrokerPermissionResult(int routing_id, bool result);
673 bool OnMessageReceived(RenderViewHost* render_view_host,
674 RenderFrameHost* render_frame_host,
675 const IPC::Message& message);
677 // IPC message handlers.
678 void OnDidLoadResourceFromMemoryCache(const GURL& url,
679 const std::string& security_info,
680 const std::string& http_request,
681 const std::string& mime_type,
682 ResourceType::Type resource_type);
683 void OnDidDisplayInsecureContent();
684 void OnDidRunInsecureContent(const std::string& security_origin,
685 const GURL& target_url);
686 void OnDocumentLoadedInFrame(int64 frame_id);
687 void OnDidFinishLoad(int64 frame_id,
690 void OnGoToEntryAtOffset(int offset);
691 void OnUpdateZoomLimits(int minimum_percent,
694 void OnEnumerateDirectory(int request_id, const base::FilePath& path);
695 void OnJSOutOfMemory();
697 void OnRegisterProtocolHandler(const std::string& protocol,
699 const base::string16& title,
701 void OnFindReply(int request_id,
702 int number_of_matches,
703 const gfx::Rect& selection_rect,
704 int active_match_ordinal,
706 #if defined(OS_ANDROID)
707 void OnFindMatchRectsReply(int version,
708 const std::vector<gfx::RectF>& rects,
709 const gfx::RectF& active_rect);
711 void OnOpenDateTimeDialog(
712 const ViewHostMsg_DateTimeDialogValue_Params& value);
713 void OnJavaBridgeGetChannelHandle(IPC::Message* reply_msg);
715 void OnPepperPluginHung(int plugin_child_id,
716 const base::FilePath& path,
718 void OnPluginCrashed(const base::FilePath& plugin_path,
719 base::ProcessId plugin_pid);
720 void OnAppCacheAccessed(const GURL& manifest_url, bool blocked_by_policy);
721 void OnOpenColorChooser(int color_chooser_id,
723 const std::vector<ColorSuggestion>& suggestions);
724 void OnEndColorChooser(int color_chooser_id);
725 void OnSetSelectedColorInColorChooser(int color_chooser_id, SkColor color);
726 void OnWebUISend(const GURL& source_url,
727 const std::string& name,
728 const base::ListValue& args);
729 void OnRequestPpapiBrokerPermission(int routing_id,
731 const base::FilePath& plugin_path);
732 void OnBrowserPluginMessage(const IPC::Message& message);
733 void OnDidDownloadImage(int id,
734 int http_status_code,
735 const GURL& image_url,
736 const std::vector<SkBitmap>& bitmaps,
737 const std::vector<gfx::Size>& original_bitmap_sizes);
738 void OnUpdateFaviconURL(int32 page_id,
739 const std::vector<FaviconURL>& candidates);
740 void OnFirstVisuallyNonEmptyPaint(int32 page_id);
741 void OnMediaPlayingNotification(int64 player_cookie,
744 void OnMediaPausedNotification(int64 player_cookie);
745 void OnShowValidationMessage(const gfx::Rect& anchor_in_root_view,
746 const base::string16& main_text,
747 const base::string16& sub_text);
748 void OnHideValidationMessage();
749 void OnMoveValidationMessage(const gfx::Rect& anchor_in_root_view);
752 // Called by derived classes to indicate that we're no longer waiting for a
753 // response. This won't actually update the throbber, but it will get picked
754 // up at the next animation step if the throbber is going.
755 void SetNotWaitingForResponse() { waiting_for_response_ = false; }
757 // Navigation helpers --------------------------------------------------------
759 // These functions are helpers for Navigate() and DidNavigate().
761 // Handles post-navigation tasks in DidNavigate AFTER the entry has been
762 // committed to the navigation controller. Note that the navigation entry is
763 // not provided since it may be invalid/changed after being committed. The
764 // current navigation entry is in the NavigationController at this point.
766 // If our controller was restored, update the max page ID associated with the
767 // given RenderViewHost to be larger than the number of restored entries.
768 // This is called in CreateRenderView before any navigations in the RenderView
769 // have begun, to prevent any races in updating RenderView::next_page_id.
770 void UpdateMaxPageIDIfNecessary(RenderViewHost* rvh);
772 // Saves the given title to the navigation entry and does associated work. It
773 // will update history and the view for the new title, and also synthesize
774 // titles for file URLs that have none (so we require that the URL of the
775 // entry already be set).
777 // This is used as the backend for state updates, which include a new title,
778 // or the dedicated set title message. It returns true if the new title is
779 // different and was therefore updated.
780 bool UpdateTitleForEntry(NavigationEntryImpl* entry,
781 const base::string16& title);
783 // Recursively creates swapped out RenderViews for this tab's opener chain
784 // (including this tab) in the given SiteInstance, allowing other tabs to send
785 // cross-process JavaScript calls to their opener(s). Returns the route ID of
786 // this tab's RenderView for |instance|.
787 int CreateOpenerRenderViews(SiteInstance* instance);
789 // Helper for CreateNewWidget/CreateNewFullscreenWidget.
790 void CreateNewWidget(int render_process_id,
793 blink::WebPopupType popup_type);
795 // Helper for ShowCreatedWidget/ShowCreatedFullscreenWidget.
796 void ShowCreatedWidget(int route_id,
798 const gfx::Rect& initial_pos);
800 // Finds the new RenderWidgetHost and returns it. Note that this can only be
801 // called once as this call also removes it from the internal map.
802 RenderWidgetHostView* GetCreatedWidget(int route_id);
804 // Finds the new WebContentsImpl by route_id, initializes it for
805 // renderer-initiated creation, and returns it. Note that this can only be
806 // called once as this call also removes it from the internal map.
807 WebContentsImpl* GetCreatedWindow(int route_id);
809 // Returns the RenderWidgetHostView that is associated with a native window
810 // and can be used in showing created widgets.
811 // If this WebContents belongs to a browser plugin guest, there is no native
812 // window 'view' associated with this WebContents. This method returns the
813 // 'view' of the embedder instead.
814 RenderWidgetHostViewPort* GetRenderWidgetHostViewPort() const;
816 // Misc non-view stuff -------------------------------------------------------
818 // Helper functions for sending notifications.
819 void NotifySwapped(RenderViewHost* old_host, RenderViewHost* new_host);
820 void NotifyDisconnected();
822 void SetEncoding(const std::string& encoding);
824 // TODO(creis): This should take in a FrameTreeNode to know which node's
825 // render manager to return. For now, we just return the root's.
826 RenderFrameHostManager* GetRenderManager() const;
828 RenderViewHostImpl* GetRenderViewHostImpl();
830 // Removes browser plugin embedder if there is one.
831 void RemoveBrowserPluginEmbedder();
833 // Clear |render_view_host|'s PowerSaveBlockers.
834 void ClearPowerSaveBlockers(RenderViewHost* render_view_host);
836 // Clear all PowerSaveBlockers, leave power_save_blocker_ empty.
837 void ClearAllPowerSaveBlockers();
839 // Helper function to invoke WebContentsDelegate::GetSizeForNewRenderView().
840 gfx::Size GetSizeForNewRenderView() const;
842 void OnFrameRemoved(RenderViewHostImpl* render_view_host, int64 frame_id);
844 // Helper method that's called whenever |preferred_size_| or
845 // |preferred_size_for_capture_| changes, to propagate the new value to the
847 void OnPreferredSizeChanged(const gfx::Size& old_size);
849 // Adds/removes a callback called on creation of each new WebContents.
850 // Deprecated, about to remove.
851 static void AddCreatedCallback(const CreatedCallback& callback);
852 static void RemoveCreatedCallback(const CreatedCallback& callback);
854 // Data for core operation ---------------------------------------------------
856 // Delegate for notifying our owner about stuff. Not owned by us.
857 WebContentsDelegate* delegate_;
859 // Handles the back/forward list and loading.
860 NavigationControllerImpl controller_;
862 // The corresponding view.
863 scoped_ptr<WebContentsViewPort> view_;
865 // The view of the RVHD. Usually this is our WebContentsView implementation,
866 // but if an embedder uses a different WebContentsView, they'll need to
868 RenderViewHostDelegateView* render_view_host_delegate_view_;
870 // Tracks created WebContentsImpl objects that have not been shown yet. They
871 // are identified by the route ID passed to CreateNewWindow.
872 typedef std::map<int, WebContentsImpl*> PendingContents;
873 PendingContents pending_contents_;
875 // These maps hold on to the widgets that we created on behalf of the renderer
876 // that haven't shown yet.
877 typedef std::map<int, RenderWidgetHostView*> PendingWidgetViews;
878 PendingWidgetViews pending_widget_views_;
880 typedef std::map<WebContentsImpl*, DestructionObserver*> DestructionObservers;
881 DestructionObservers destruction_observers_;
883 // A list of observers notified when page state changes. Weak references.
884 // This MUST be listed above frame_tree_ since at destruction time the
885 // latter might cause RenderViewHost's destructor to call us and we might use
886 // the observer list then.
887 ObserverList<WebContentsObserver> observers_;
889 // The tab that opened this tab, if any. Will be set to null if the opener
891 WebContentsImpl* opener_;
894 gfx::NativeViewAccessible accessible_parent_;
897 // Helper classes ------------------------------------------------------------
899 // Maps the RenderViewHost to its media_player_cookie and PowerSaveBlocker
900 // pairs. Key is the RenderViewHost, value is the map which maps player_cookie
901 // on to PowerSaveBlocker.
902 typedef std::map<RenderViewHost*, std::map<int64, PowerSaveBlocker*> >
904 PowerSaveBlockerMap power_save_blockers_;
906 // Manages the frame tree of the page and process swaps in each node.
907 FrameTree frame_tree_;
909 #if defined(OS_ANDROID)
910 // Manages injecting Java objects into all RenderViewHosts associated with
911 // this WebContentsImpl.
912 scoped_ptr<JavaBridgeDispatcherHostManager>
913 java_bridge_dispatcher_host_manager_;
916 // SavePackage, lazily created.
917 scoped_refptr<SavePackage> save_package_;
919 // Data for loading state ----------------------------------------------------
921 // Indicates whether we're currently loading a resource.
924 // Indicates if the tab is considered crashed.
925 base::TerminationStatus crashed_status_;
926 int crashed_error_code_;
928 // Whether this WebContents is waiting for a first-response for the
929 // main resource of the page. This controls whether the throbber state is
930 // "waiting" or "loading."
931 bool waiting_for_response_;
933 // Map of SiteInstance ID to max page ID for this tab. A page ID is specific
934 // to a given tab and SiteInstance, and must be valid for the lifetime of the
936 std::map<int32, int32> max_page_ids_;
938 // The current load state and the URL associated with it.
939 net::LoadStateWithParam load_state_;
940 base::string16 load_state_host_;
941 // Upload progress, for displaying in the status bar.
942 // Set to zero when there is no significant upload happening.
944 uint64 upload_position_;
946 // Data for current page -----------------------------------------------------
948 // When a title cannot be taken from any entry, this title will be used.
949 base::string16 page_title_when_no_navigation_entry_;
951 // When a navigation occurs, we record its contents MIME type. It can be
952 // used to check whether we can do something for some special contents.
953 std::string contents_mime_type_;
955 // Character encoding.
956 std::string encoding_;
958 // True if this is a secure page which displayed insecure content.
959 bool displayed_insecure_content_;
961 // Data for misc internal state ----------------------------------------------
963 // When > 0, the WebContents is currently being captured (e.g., for
964 // screenshots or mirroring); and the underlying RenderWidgetHost should not
965 // be told it is hidden.
968 // Tracks whether RWHV should be visible once capturer_count_ becomes zero.
969 bool should_normally_be_visible_;
972 bool is_being_destroyed_;
974 // Indicates whether we should notify about disconnection of this
975 // WebContentsImpl. This is used to ensure disconnection notifications only
976 // happen if a connection notification has happened and that they happen only
978 bool notify_disconnection_;
980 // Pointer to the JavaScript dialog manager, lazily assigned. Used because the
981 // delegate of this WebContentsImpl is nulled before its destructor is called.
982 JavaScriptDialogManager* dialog_manager_;
984 // Set to true when there is an active "before unload" dialog. When true,
985 // we've forced the throbber to start in Navigate, and we need to remember to
986 // turn it off in OnJavaScriptMessageBoxClosed if the navigation is canceled.
987 bool is_showing_before_unload_dialog_;
989 // Settings that get passed to the renderer process.
990 RendererPreferences renderer_preferences_;
992 // The time that this WebContents was last made active. The initial value is
993 // the WebContents creation time.
994 base::TimeTicks last_active_time_;
996 // See description above setter.
997 bool closed_by_user_gesture_;
999 // Minimum/maximum zoom percent.
1000 int minimum_zoom_percent_;
1001 int maximum_zoom_percent_;
1002 // If true, the default zoom limits have been overriden for this tab, in which
1003 // case we don't want saved settings to apply to it and we don't want to
1005 bool temporary_zoom_settings_;
1007 // The intrinsic size of the page.
1008 gfx::Size preferred_size_;
1010 // The preferred size for content screen capture. When |capturer_count_| > 0,
1011 // this overrides |preferred_size_|.
1012 gfx::Size preferred_size_for_capture_;
1014 #if defined(OS_ANDROID)
1015 // Date time chooser opened by this tab.
1016 // Only used in Android since all other platforms use a multi field UI.
1017 scoped_ptr<DateTimeChooserAndroid> date_time_chooser_;
1020 // Color chooser that was opened by this tab.
1021 scoped_ptr<ColorChooser> color_chooser_;
1023 // A unique identifier for the current color chooser. Identifiers are unique
1024 // across a renderer process. This avoids race conditions in synchronizing
1025 // the browser and renderer processes. For example, if a renderer closes one
1026 // chooser and opens another, and simultaneously the user picks a color in the
1027 // first chooser, the IDs can be used to drop the "chose a color" message
1028 // rather than erroneously tell the renderer that the user picked a color in
1029 // the second chooser.
1030 int color_chooser_identifier_;
1032 // Manages the embedder state for browser plugins, if this WebContents is an
1033 // embedder; NULL otherwise.
1034 scoped_ptr<BrowserPluginEmbedder> browser_plugin_embedder_;
1035 // Manages the guest state for browser plugin, if this WebContents is a guest;
1037 scoped_ptr<BrowserPluginGuest> browser_plugin_guest_;
1039 // This must be at the end, or else we might get notifications and use other
1040 // member variables that are gone.
1041 NotificationRegistrar registrar_;
1043 // Used during IPC message dispatching from the RenderView/RenderFrame so that
1044 // the handlers can get a pointer to the RVH through which the message was
1046 RenderViewHost* render_view_message_source_;
1047 RenderFrameHost* render_frame_message_source_;
1049 // All live RenderWidgetHostImpls that are created by this object and may
1051 std::set<RenderWidgetHostImpl*> created_widgets_;
1053 // Routing id of the shown fullscreen widget or MSG_ROUTING_NONE otherwise.
1054 int fullscreen_widget_routing_id_;
1056 // Maps the ids of pending image downloads to their callbacks
1057 typedef std::map<int, ImageDownloadCallback> ImageDownloadMap;
1058 ImageDownloadMap image_download_map_;
1060 // Whether this WebContents is responsible for displaying a subframe in a
1061 // different process from its parent page.
1064 DISALLOW_COPY_AND_ASSIGN(WebContentsImpl);
1067 } // namespace content
1069 #endif // CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_IMPL_H_