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/containers/scoped_ptr_hash_map.h"
14 #include "base/gtest_prod_util.h"
15 #include "base/memory/scoped_ptr.h"
16 #include "base/observer_list.h"
17 #include "base/process/process.h"
18 #include "base/values.h"
19 #include "content/browser/frame_host/frame_tree.h"
20 #include "content/browser/frame_host/navigation_controller_delegate.h"
21 #include "content/browser/frame_host/navigation_controller_impl.h"
22 #include "content/browser/frame_host/navigator_delegate.h"
23 #include "content/browser/frame_host/render_frame_host_delegate.h"
24 #include "content/browser/frame_host/render_frame_host_manager.h"
25 #include "content/browser/renderer_host/render_view_host_delegate.h"
26 #include "content/browser/renderer_host/render_widget_host_delegate.h"
27 #include "content/common/accessibility_mode_enums.h"
28 #include "content/common/content_export.h"
29 #include "content/public/browser/color_chooser.h"
30 #include "content/public/browser/notification_observer.h"
31 #include "content/public/browser/notification_registrar.h"
32 #include "content/public/browser/web_contents.h"
33 #include "content/public/common/page_transition_types.h"
34 #include "content/public/common/renderer_preferences.h"
35 #include "content/public/common/resource_type.h"
36 #include "content/public/common/three_d_api_types.h"
37 #include "net/base/load_states.h"
38 #include "net/http/http_response_headers.h"
39 #include "third_party/WebKit/public/web/WebDragOperation.h"
40 #include "ui/gfx/rect_f.h"
41 #include "ui/gfx/size.h"
43 struct BrowserPluginHostMsg_ResizeGuest_Params;
44 struct ViewHostMsg_DateTimeDialogValue_Params;
45 struct ViewMsg_PostMessage_Params;
48 class BrowserPluginEmbedder;
49 class BrowserPluginGuest;
50 class BrowserPluginGuestManager;
51 class DateTimeChooserAndroid;
53 class GeolocationDispatcherHost;
54 class InterstitialPageImpl;
55 class JavaScriptDialogManager;
56 class MidiDispatcherHost;
57 class PowerSaveBlocker;
59 class RenderViewHostDelegateView;
60 class RenderViewHostImpl;
61 class RenderWidgetHostImpl;
63 class ScreenOrientationDispatcherHost;
65 class TestWebContents;
66 class WebContentsDelegate;
67 class WebContentsImpl;
68 class WebContentsObserver;
69 class WebContentsView;
70 class WebContentsViewDelegate;
71 struct AXEventNotificationDetails;
72 struct ColorSuggestion;
74 struct LoadNotificationDetails;
75 struct ResourceRedirectDetails;
76 struct ResourceRequestDetails;
78 #if defined(OS_ANDROID)
79 class WebContentsAndroid;
82 // Factory function for the implementations that content knows about. Takes
83 // ownership of |delegate|.
84 WebContentsView* CreateWebContentsView(
85 WebContentsImpl* web_contents,
86 WebContentsViewDelegate* delegate,
87 RenderViewHostDelegateView** render_view_host_delegate_view);
89 class CONTENT_EXPORT WebContentsImpl
90 : public NON_EXPORTED_BASE(WebContents),
91 public NON_EXPORTED_BASE(RenderFrameHostDelegate),
92 public RenderViewHostDelegate,
93 public RenderWidgetHostDelegate,
94 public RenderFrameHostManager::Delegate,
95 public NotificationObserver,
96 public NON_EXPORTED_BASE(NavigationControllerDelegate),
97 public NON_EXPORTED_BASE(NavigatorDelegate) {
99 virtual ~WebContentsImpl();
101 static WebContentsImpl* CreateWithOpener(
102 const WebContents::CreateParams& params,
103 WebContentsImpl* opener);
105 static std::vector<WebContentsImpl*> GetAllWebContents();
107 // Returns the opener WebContentsImpl, if any. This can be set to null if the
108 // opener is closed or the page clears its window.opener.
109 WebContentsImpl* opener() const { return opener_; }
111 // Creates a swapped out RenderView. This is used by the browser plugin to
112 // create a swapped out RenderView in the embedder render process for the
113 // guest, to expose the guest's window object to the embedder.
114 // This returns the routing ID of the newly created swapped out RenderView.
115 int CreateSwappedOutRenderView(SiteInstance* instance);
117 // Complex initialization here. Specifically needed to avoid having
118 // members call back into our virtual functions in the constructor.
119 virtual void Init(const WebContents::CreateParams& params);
121 // Returns the SavePackage which manages the page saving job. May be NULL.
122 SavePackage* save_package() const { return save_package_.get(); }
124 #if defined(OS_ANDROID)
125 // In Android WebView, the RenderView needs created even there is no
126 // navigation entry, this allows Android WebViews to use
127 // javascript: URLs that load into the DOMWindow before the first page
128 // load. This is not safe to do in any context that a web page could get a
129 // reference to the DOMWindow before the first page load.
130 bool CreateRenderViewForInitialEmptyDocument();
133 // Expose the render manager for testing.
134 // TODO(creis): Remove this now that we can get to it via FrameTreeNode.
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 // Gets the current fullscreen render widget's routing ID. Returns
151 // MSG_ROUTING_NONE when there is no fullscreen render widget.
152 int GetFullscreenWidgetRoutingID() const;
154 // Invoked when visible SSL state (as defined by SSLStatus) changes.
155 void DidChangeVisibleSSLState();
157 // Informs the render view host and the BrowserPluginEmbedder, if present, of
158 // a Drag Source End.
159 void DragSourceEndedAt(int client_x, int client_y, int screen_x,
160 int screen_y, blink::WebDragOperation operation);
162 // A response has been received for a resource request.
163 void DidGetResourceResponseStart(
164 const ResourceRequestDetails& details);
166 // A redirect was received while requesting a resource.
167 void DidGetRedirectForResourceRequest(
168 RenderViewHost* render_view_host,
169 const ResourceRedirectDetails& details);
171 WebContentsView* GetView() const;
173 GeolocationDispatcherHost* geolocation_dispatcher_host() {
174 return geolocation_dispatcher_host_.get();
177 ScreenOrientationDispatcherHost* screen_orientation_dispatcher_host() {
178 return screen_orientation_dispatcher_host_.get();
181 bool should_normally_be_visible() { return should_normally_be_visible_; }
183 // Broadcasts the mode change to all frames.
184 void SetAccessibilityMode(AccessibilityMode mode);
186 // Adds the given accessibility mode to the current accessibility mode
188 void AddAccessibilityMode(AccessibilityMode mode);
190 // Removes the given accessibility mode from the current accessibility
191 // mode bitmap, managing the bits that are shared with other modes such
192 // that a bit will only be turned off when all modes that depend on it
193 // have been removed.
194 void RemoveAccessibilityMode(AccessibilityMode mode);
196 // WebContents ------------------------------------------------------
197 virtual ScreenOrientationDispatcherHost* GetScreenOrientationDispatcherHost() OVERRIDE;
198 virtual WebContentsDelegate* GetDelegate() OVERRIDE;
199 virtual void SetDelegate(WebContentsDelegate* delegate) OVERRIDE;
200 virtual NavigationControllerImpl& GetController() OVERRIDE;
201 virtual const NavigationControllerImpl& GetController() const OVERRIDE;
202 virtual BrowserContext* GetBrowserContext() const OVERRIDE;
203 virtual const GURL& GetURL() const OVERRIDE;
204 virtual const GURL& GetVisibleURL() const OVERRIDE;
205 virtual const GURL& GetLastCommittedURL() const OVERRIDE;
206 virtual RenderProcessHost* GetRenderProcessHost() const OVERRIDE;
207 virtual RenderFrameHost* GetMainFrame() OVERRIDE;
208 virtual RenderFrameHost* GetFocusedFrame() OVERRIDE;
209 virtual void ForEachFrame(
210 const base::Callback<void(RenderFrameHost*)>& on_frame) OVERRIDE;
211 virtual void SendToAllFrames(IPC::Message* message) OVERRIDE;
212 virtual RenderViewHost* GetRenderViewHost() const OVERRIDE;
213 virtual int GetRoutingID() const OVERRIDE;
214 virtual RenderWidgetHostView* GetRenderWidgetHostView() const OVERRIDE;
215 virtual RenderWidgetHostView* GetFullscreenRenderWidgetHostView() const
217 virtual WebUI* CreateWebUI(const GURL& url) OVERRIDE;
218 virtual WebUI* GetWebUI() const OVERRIDE;
219 virtual WebUI* GetCommittedWebUI() const OVERRIDE;
220 virtual void SetUserAgentOverride(const std::string& override) OVERRIDE;
221 virtual const std::string& GetUserAgentOverride() const OVERRIDE;
222 virtual void EnableTreeOnlyAccessibilityMode() OVERRIDE;
223 virtual bool IsTreeOnlyAccessibilityModeForTesting() const OVERRIDE;
224 virtual bool IsFullAccessibilityModeForTesting() const OVERRIDE;
226 virtual void SetParentNativeViewAccessible(
227 gfx::NativeViewAccessible accessible_parent) OVERRIDE;
229 virtual const base::string16& GetTitle() const OVERRIDE;
230 virtual int32 GetMaxPageID() OVERRIDE;
231 virtual int32 GetMaxPageIDForSiteInstance(
232 SiteInstance* site_instance) OVERRIDE;
233 virtual SiteInstance* GetSiteInstance() const OVERRIDE;
234 virtual SiteInstance* GetPendingSiteInstance() const OVERRIDE;
235 virtual bool IsLoading() const OVERRIDE;
236 virtual bool IsLoadingToDifferentDocument() const OVERRIDE;
237 virtual bool IsWaitingForResponse() const OVERRIDE;
238 virtual const net::LoadStateWithParam& GetLoadState() const OVERRIDE;
239 virtual const base::string16& GetLoadStateHost() const OVERRIDE;
240 virtual uint64 GetUploadSize() const OVERRIDE;
241 virtual uint64 GetUploadPosition() const OVERRIDE;
242 virtual std::set<GURL> GetSitesInTab() const OVERRIDE;
243 virtual const std::string& GetEncoding() const OVERRIDE;
244 virtual bool DisplayedInsecureContent() const OVERRIDE;
245 virtual void IncrementCapturerCount(const gfx::Size& capture_size) OVERRIDE;
246 virtual void DecrementCapturerCount() OVERRIDE;
247 virtual int GetCapturerCount() const OVERRIDE;
248 virtual bool IsCrashed() const OVERRIDE;
249 virtual void SetIsCrashed(base::TerminationStatus status,
250 int error_code) OVERRIDE;
251 virtual base::TerminationStatus GetCrashedStatus() const OVERRIDE;
252 virtual bool IsBeingDestroyed() const OVERRIDE;
253 virtual void NotifyNavigationStateChanged(
254 InvalidateTypes changed_flags) OVERRIDE;
255 virtual base::TimeTicks GetLastActiveTime() const OVERRIDE;
256 virtual void WasShown() OVERRIDE;
257 virtual void WasHidden() OVERRIDE;
258 virtual bool NeedToFireBeforeUnload() OVERRIDE;
259 virtual void DispatchBeforeUnload(bool for_cross_site_transition) OVERRIDE;
260 virtual void Stop() OVERRIDE;
261 virtual WebContents* Clone() OVERRIDE;
262 virtual void ReloadFocusedFrame(bool ignore_cache) OVERRIDE;
263 virtual void Undo() OVERRIDE;
264 virtual void Redo() OVERRIDE;
265 virtual void Cut() OVERRIDE;
266 virtual void Copy() OVERRIDE;
267 virtual void CopyToFindPboard() OVERRIDE;
268 virtual void Paste() OVERRIDE;
269 virtual void PasteAndMatchStyle() OVERRIDE;
270 virtual void Delete() OVERRIDE;
271 virtual void SelectAll() OVERRIDE;
272 virtual void Unselect() OVERRIDE;
273 virtual void Replace(const base::string16& word) OVERRIDE;
274 virtual void ReplaceMisspelling(const base::string16& word) OVERRIDE;
275 virtual void NotifyContextMenuClosed(
276 const CustomContextMenuContext& context) OVERRIDE;
277 virtual void ExecuteCustomContextMenuCommand(
278 int action, const CustomContextMenuContext& context) OVERRIDE;
279 virtual gfx::NativeView GetNativeView() OVERRIDE;
280 virtual gfx::NativeView GetContentNativeView() OVERRIDE;
281 virtual gfx::NativeWindow GetTopLevelNativeWindow() OVERRIDE;
282 virtual gfx::Rect GetContainerBounds() OVERRIDE;
283 virtual gfx::Rect GetViewBounds() OVERRIDE;
284 virtual DropData* GetDropData() OVERRIDE;
285 virtual void Focus() OVERRIDE;
286 virtual void SetInitialFocus() OVERRIDE;
287 virtual void StoreFocus() OVERRIDE;
288 virtual void RestoreFocus() OVERRIDE;
289 virtual void FocusThroughTabTraversal(bool reverse) OVERRIDE;
290 virtual bool ShowingInterstitialPage() const OVERRIDE;
291 virtual InterstitialPage* GetInterstitialPage() const OVERRIDE;
292 virtual bool IsSavable() OVERRIDE;
293 virtual void OnSavePage() OVERRIDE;
294 virtual bool SavePage(const base::FilePath& main_file,
295 const base::FilePath& dir_path,
296 SavePageType save_type) OVERRIDE;
297 virtual void SaveFrame(const GURL& url,
298 const Referrer& referrer) OVERRIDE;
299 virtual void GenerateMHTML(
300 const base::FilePath& file,
301 const base::Callback<void(int64)>& callback)
303 virtual const std::string& GetContentsMimeType() const OVERRIDE;
304 virtual bool WillNotifyDisconnection() const OVERRIDE;
305 virtual void SetOverrideEncoding(const std::string& encoding) OVERRIDE;
306 virtual void ResetOverrideEncoding() OVERRIDE;
307 virtual RendererPreferences* GetMutableRendererPrefs() OVERRIDE;
308 virtual void Close() OVERRIDE;
309 virtual void SystemDragEnded() OVERRIDE;
310 virtual void UserGestureDone() OVERRIDE;
311 virtual void SetClosedByUserGesture(bool value) OVERRIDE;
312 virtual bool GetClosedByUserGesture() const OVERRIDE;
313 virtual void ViewSource() OVERRIDE;
314 virtual void ViewFrameSource(const GURL& url,
315 const PageState& page_state) OVERRIDE;
316 virtual int GetMinimumZoomPercent() const OVERRIDE;
317 virtual int GetMaximumZoomPercent() const OVERRIDE;
318 virtual gfx::Size GetPreferredSize() const OVERRIDE;
319 virtual bool GotResponseToLockMouseRequest(bool allowed) OVERRIDE;
320 virtual bool HasOpener() const OVERRIDE;
321 virtual void DidChooseColorInColorChooser(SkColor color) OVERRIDE;
322 virtual void DidEndColorChooser() OVERRIDE;
323 virtual int DownloadImage(const GURL& url,
325 uint32_t max_bitmap_size,
326 const ImageDownloadCallback& callback) OVERRIDE;
327 virtual bool IsSubframe() const OVERRIDE;
328 virtual void Find(int request_id,
329 const base::string16& search_text,
330 const blink::WebFindOptions& options) OVERRIDE;
331 virtual void StopFinding(StopFindAction action) OVERRIDE;
332 virtual void InsertCSS(const std::string& css) OVERRIDE;
333 #if defined(OS_ANDROID)
334 virtual base::android::ScopedJavaLocalRef<jobject> GetJavaWebContents()
336 virtual WebContentsAndroid* GetWebContentsAndroid();
337 #elif defined(OS_MACOSX)
338 virtual void SetAllowOverlappingViews(bool overlapping) OVERRIDE;
339 virtual bool GetAllowOverlappingViews() OVERRIDE;
340 virtual void SetAllowOtherViews(bool allow) OVERRIDE;
341 virtual bool GetAllowOtherViews() OVERRIDE;
344 // Implementation of PageNavigator.
345 virtual WebContents* OpenURL(const OpenURLParams& params) OVERRIDE;
347 // Implementation of IPC::Sender.
348 virtual bool Send(IPC::Message* message) OVERRIDE;
350 // RenderFrameHostDelegate ---------------------------------------------------
351 virtual bool OnMessageReceived(RenderFrameHost* render_frame_host,
352 const IPC::Message& message) OVERRIDE;
353 virtual const GURL& GetMainFrameLastCommittedURL() const OVERRIDE;
354 virtual void RenderFrameCreated(RenderFrameHost* render_frame_host) OVERRIDE;
355 virtual void RenderFrameDeleted(RenderFrameHost* render_frame_host) OVERRIDE;
356 virtual void DidStartLoading(RenderFrameHost* render_frame_host,
357 bool to_different_document) OVERRIDE;
358 virtual void SwappedOut(RenderFrameHost* render_frame_host) OVERRIDE;
359 virtual void DidDeferAfterResponseStarted(
360 const TransitionLayerData& transition_data) OVERRIDE;
361 virtual bool WillHandleDeferAfterResponseStarted() OVERRIDE;
362 virtual void WorkerCrashed(RenderFrameHost* render_frame_host) OVERRIDE;
363 virtual void ShowContextMenu(RenderFrameHost* render_frame_host,
364 const ContextMenuParams& params) OVERRIDE;
365 virtual void RunJavaScriptMessage(RenderFrameHost* render_frame_host,
366 const base::string16& message,
367 const base::string16& default_prompt,
368 const GURL& frame_url,
369 JavaScriptMessageType type,
370 IPC::Message* reply_msg) OVERRIDE;
371 virtual void RunBeforeUnloadConfirm(RenderFrameHost* render_frame_host,
372 const base::string16& message,
374 IPC::Message* reply_msg) OVERRIDE;
375 virtual void DidAccessInitialDocument() OVERRIDE;
376 virtual void DidDisownOpener(RenderFrameHost* render_frame_host) OVERRIDE;
377 virtual void DocumentOnLoadCompleted(
378 RenderFrameHost* render_frame_host) OVERRIDE;
379 virtual void UpdateTitle(RenderFrameHost* render_frame_host,
381 const base::string16& title,
382 base::i18n::TextDirection title_direction) OVERRIDE;
383 virtual void UpdateEncoding(RenderFrameHost* render_frame_host,
384 const std::string& encoding) OVERRIDE;
385 virtual WebContents* GetAsWebContents() OVERRIDE;
386 virtual bool IsNeverVisible() OVERRIDE;
387 virtual AccessibilityMode GetAccessibilityMode() const OVERRIDE;
388 virtual void AccessibilityEventReceived(
389 const std::vector<AXEventNotificationDetails>& details) OVERRIDE;
391 virtual gfx::NativeViewAccessible GetParentNativeViewAccessible() OVERRIDE;
394 // RenderViewHostDelegate ----------------------------------------------------
395 virtual RenderViewHostDelegateView* GetDelegateView() OVERRIDE;
396 virtual bool OnMessageReceived(RenderViewHost* render_view_host,
397 const IPC::Message& message) OVERRIDE;
398 // RenderFrameHostDelegate has the same method, so list it there because this
399 // interface is going away.
400 // virtual WebContents* GetAsWebContents() OVERRIDE;
401 virtual gfx::Rect GetRootWindowResizerRect() const OVERRIDE;
402 virtual void RenderViewCreated(RenderViewHost* render_view_host) OVERRIDE;
403 virtual void RenderViewReady(RenderViewHost* render_view_host) OVERRIDE;
404 virtual void RenderViewTerminated(RenderViewHost* render_view_host,
405 base::TerminationStatus status,
406 int error_code) OVERRIDE;
407 virtual void RenderViewDeleted(RenderViewHost* render_view_host) OVERRIDE;
408 virtual void UpdateState(RenderViewHost* render_view_host,
410 const PageState& page_state) OVERRIDE;
411 virtual void UpdateTargetURL(int32 page_id, const GURL& url) OVERRIDE;
412 virtual void Close(RenderViewHost* render_view_host) OVERRIDE;
413 virtual void RequestMove(const gfx::Rect& new_bounds) OVERRIDE;
414 virtual void DidCancelLoading() OVERRIDE;
415 virtual void DocumentAvailableInMainFrame(
416 RenderViewHost* render_view_host) OVERRIDE;
417 virtual void RouteCloseEvent(RenderViewHost* rvh) OVERRIDE;
418 virtual void RouteMessageEvent(
420 const ViewMsg_PostMessage_Params& params) OVERRIDE;
421 virtual bool AddMessageToConsole(int32 level,
422 const base::string16& message,
424 const base::string16& source_id) OVERRIDE;
425 virtual RendererPreferences GetRendererPrefs(
426 BrowserContext* browser_context) const OVERRIDE;
427 virtual WebPreferences ComputeWebkitPrefs() OVERRIDE;
428 virtual void OnUserGesture() OVERRIDE;
429 virtual void OnIgnoredUIEvent() OVERRIDE;
430 virtual void RendererUnresponsive(RenderViewHost* render_view_host,
431 bool is_during_beforeunload,
432 bool is_during_unload) OVERRIDE;
433 virtual void RendererResponsive(RenderViewHost* render_view_host) OVERRIDE;
434 virtual void LoadStateChanged(const GURL& url,
435 const net::LoadStateWithParam& load_state,
436 uint64 upload_position,
437 uint64 upload_size) OVERRIDE;
438 virtual void Activate() OVERRIDE;
439 virtual void Deactivate() OVERRIDE;
440 virtual void LostCapture() OVERRIDE;
441 virtual void HandleMouseDown() OVERRIDE;
442 virtual void HandleMouseUp() OVERRIDE;
443 virtual void HandlePointerActivate() OVERRIDE;
444 virtual void HandleGestureBegin() OVERRIDE;
445 virtual void HandleGestureEnd() OVERRIDE;
446 virtual void RunFileChooser(
447 RenderViewHost* render_view_host,
448 const FileChooserParams& params) OVERRIDE;
449 virtual void ToggleFullscreenMode(bool enter_fullscreen) OVERRIDE;
450 virtual bool IsFullscreenForCurrentTab() const OVERRIDE;
451 virtual void UpdatePreferredSize(const gfx::Size& pref_size) OVERRIDE;
452 virtual void ResizeDueToAutoResize(const gfx::Size& new_size) OVERRIDE;
453 virtual void RequestToLockMouse(bool user_gesture,
454 bool last_unlocked_by_target) OVERRIDE;
455 virtual void LostMouseLock() OVERRIDE;
456 virtual void CreateNewWindow(
457 int render_process_id,
459 int main_frame_route_id,
460 const ViewHostMsg_CreateWindow_Params& params,
461 SessionStorageNamespace* session_storage_namespace) OVERRIDE;
462 virtual void CreateNewWidget(int render_process_id,
464 blink::WebPopupType popup_type) OVERRIDE;
465 virtual void CreateNewFullscreenWidget(int render_process_id,
466 int route_id) OVERRIDE;
467 virtual void ShowCreatedWindow(int route_id,
468 WindowOpenDisposition disposition,
469 const gfx::Rect& initial_pos,
470 bool user_gesture) OVERRIDE;
471 virtual void ShowCreatedWidget(int route_id,
472 const gfx::Rect& initial_pos) OVERRIDE;
473 virtual void ShowCreatedFullscreenWidget(int route_id) OVERRIDE;
474 virtual void RequestMediaAccessPermission(
475 const MediaStreamRequest& request,
476 const MediaResponseCallback& callback) OVERRIDE;
477 virtual SessionStorageNamespace* GetSessionStorageNamespace(
478 SiteInstance* instance) OVERRIDE;
479 virtual SessionStorageNamespaceMap GetSessionStorageNamespaceMap() OVERRIDE;
480 virtual FrameTree* GetFrameTree() OVERRIDE;
482 // NavigatorDelegate ---------------------------------------------------------
484 virtual void DidStartProvisionalLoad(
485 RenderFrameHostImpl* render_frame_host,
486 const GURL& validated_url,
488 bool is_iframe_srcdoc) OVERRIDE;
489 virtual void DidStartNavigationTransition(
490 RenderFrameHostImpl* render_frame_host) OVERRIDE;
491 virtual void DidFailProvisionalLoadWithError(
492 RenderFrameHostImpl* render_frame_host,
493 const FrameHostMsg_DidFailProvisionalLoadWithError_Params& params)
495 virtual void DidFailLoadWithError(
496 RenderFrameHostImpl* render_frame_host,
499 const base::string16& error_description) OVERRIDE;
500 virtual void DidRedirectProvisionalLoad(
501 RenderFrameHostImpl* render_frame_host,
502 const GURL& validated_target_url) OVERRIDE;
503 virtual void DidCommitProvisionalLoad(
504 RenderFrameHostImpl* render_frame_host,
506 PageTransition transition_type) OVERRIDE;
507 virtual void DidNavigateMainFramePreCommit(
508 bool navigation_is_within_page) OVERRIDE;
509 virtual void DidNavigateMainFramePostCommit(
510 const LoadCommittedDetails& details,
511 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) OVERRIDE;
512 virtual void DidNavigateAnyFramePostCommit(
513 RenderFrameHostImpl* render_frame_host,
514 const LoadCommittedDetails& details,
515 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) OVERRIDE;
516 virtual void SetMainFrameMimeType(const std::string& mime_type) OVERRIDE;
517 virtual bool CanOverscrollContent() const OVERRIDE;
518 virtual void NotifyChangedNavigationState(
519 InvalidateTypes changed_flags) OVERRIDE;
520 virtual void AboutToNavigateRenderFrame(
521 RenderFrameHostImpl* render_frame_host) OVERRIDE;
522 virtual void DidStartNavigationToPendingEntry(
523 RenderFrameHostImpl* render_frame_host,
525 NavigationController::ReloadType reload_type) OVERRIDE;
526 virtual void RequestOpenURL(RenderFrameHostImpl* render_frame_host,
527 const OpenURLParams& params) OVERRIDE;
528 virtual bool ShouldPreserveAbortedURLs() OVERRIDE;
530 // RenderWidgetHostDelegate --------------------------------------------------
532 virtual void RenderWidgetDeleted(
533 RenderWidgetHostImpl* render_widget_host) OVERRIDE;
534 virtual bool PreHandleKeyboardEvent(
535 const NativeWebKeyboardEvent& event,
536 bool* is_keyboard_shortcut) OVERRIDE;
537 virtual void HandleKeyboardEvent(
538 const NativeWebKeyboardEvent& event) OVERRIDE;
539 virtual bool HandleWheelEvent(
540 const blink::WebMouseWheelEvent& event) OVERRIDE;
541 virtual bool PreHandleGestureEvent(
542 const blink::WebGestureEvent& event) OVERRIDE;
543 virtual bool HandleGestureEvent(
544 const blink::WebGestureEvent& event) OVERRIDE;
545 virtual void DidSendScreenRects(RenderWidgetHostImpl* rwh) OVERRIDE;
546 virtual void OnTouchEmulationEnabled(bool enabled) OVERRIDE;
547 virtual BrowserAccessibilityManager* GetRootBrowserAccessibilityManager()
549 virtual BrowserAccessibilityManager*
550 GetOrCreateRootBrowserAccessibilityManager() OVERRIDE;
552 // RenderFrameHostManager::Delegate ------------------------------------------
554 virtual bool CreateRenderViewForRenderManager(
555 RenderViewHost* render_view_host,
557 int proxy_routing_id,
558 bool for_main_frame_navigation) OVERRIDE;
559 virtual bool CreateRenderFrameForRenderManager(
560 RenderFrameHost* render_frame_host,
561 int parent_routing_id) OVERRIDE;
562 virtual void BeforeUnloadFiredFromRenderManager(
563 bool proceed, const base::TimeTicks& proceed_time,
564 bool* proceed_to_fire_unload) OVERRIDE;
565 virtual void RenderProcessGoneFromRenderManager(
566 RenderViewHost* render_view_host) OVERRIDE;
567 virtual void UpdateRenderViewSizeForRenderManager() OVERRIDE;
568 virtual void CancelModalDialogsForRenderManager() OVERRIDE;
569 virtual void NotifySwappedFromRenderManager(RenderFrameHost* old_host,
570 RenderFrameHost* new_host,
571 bool is_main_frame) OVERRIDE;
572 virtual int CreateOpenerRenderViewsForRenderManager(
573 SiteInstance* instance) OVERRIDE;
574 virtual NavigationControllerImpl&
575 GetControllerForRenderManager() OVERRIDE;
576 virtual WebUIImpl* CreateWebUIForRenderManager(const GURL& url) OVERRIDE;
577 virtual NavigationEntry*
578 GetLastCommittedNavigationEntryForRenderManager() OVERRIDE;
579 virtual bool FocusLocationBarByDefault() OVERRIDE;
580 virtual void SetFocusToLocationBar(bool select_all) OVERRIDE;
581 virtual void CreateViewAndSetSizeForRVH(RenderViewHost* rvh) OVERRIDE;
582 virtual bool IsHidden() OVERRIDE;
584 // NotificationObserver ------------------------------------------------------
586 virtual void Observe(int type,
587 const NotificationSource& source,
588 const NotificationDetails& details) OVERRIDE;
590 // NavigationControllerDelegate ----------------------------------------------
592 virtual WebContents* GetWebContents() OVERRIDE;
593 virtual void NotifyNavigationEntryCommitted(
594 const LoadCommittedDetails& load_details) OVERRIDE;
596 // Invoked before a form repost warning is shown.
597 virtual void NotifyBeforeFormRepostWarningShow() OVERRIDE;
599 // Activate this WebContents and show a form repost warning.
600 virtual void ActivateAndShowRepostFormWarningDialog() OVERRIDE;
602 // Whether the initial empty page of this view has been accessed by another
603 // page, making it unsafe to show the pending URL. Always false after the
605 virtual bool HasAccessedInitialDocument() OVERRIDE;
607 // Updates the max page ID for the current SiteInstance in this
608 // WebContentsImpl to be at least |page_id|.
609 virtual void UpdateMaxPageID(int32 page_id) OVERRIDE;
611 // Updates the max page ID for the given SiteInstance in this WebContentsImpl
612 // to be at least |page_id|.
613 virtual void UpdateMaxPageIDForSiteInstance(SiteInstance* site_instance,
614 int32 page_id) OVERRIDE;
616 // Copy the current map of SiteInstance ID to max page ID from another tab.
617 // This is necessary when this tab adopts the NavigationEntries from
619 virtual void CopyMaxPageIDsFrom(WebContents* web_contents) OVERRIDE;
621 // Called by the NavigationController to cause the WebContentsImpl to navigate
622 // to the current pending entry. The NavigationController should be called
623 // back with RendererDidNavigate on success or DiscardPendingEntry on failure.
624 // The callbacks can be inside of this function, or at some future time.
626 // The entry has a PageID of -1 if newly created (corresponding to navigation
629 // If this method returns false, then the navigation is discarded (equivalent
630 // to calling DiscardPendingEntry on the NavigationController).
631 virtual bool NavigateToPendingEntry(
632 NavigationController::ReloadType reload_type) OVERRIDE;
634 // Sets the history for this WebContentsImpl to |history_length| entries, and
635 // moves the current page_id to the last entry in the list if it's valid.
636 // This is mainly used when a prerendered page is swapped into the current
637 // tab. The method is virtual for testing.
638 virtual void SetHistoryLengthAndPrune(
639 const SiteInstance* site_instance,
640 int merge_history_length,
641 int32 minimum_page_id) OVERRIDE;
643 // Called by InterstitialPageImpl when it creates a RenderFrameHost.
644 virtual void RenderFrameForInterstitialPageCreated(
645 RenderFrameHost* render_frame_host) OVERRIDE;
647 // Sets the passed interstitial as the currently showing interstitial.
648 // No interstitial page should already be attached.
649 virtual void AttachInterstitialPage(
650 InterstitialPageImpl* interstitial_page) OVERRIDE;
652 // Unsets the currently showing interstitial.
653 virtual void DetachInterstitialPage() OVERRIDE;
655 // Changes the IsLoading state and notifies the delegate as needed.
656 // |details| is used to provide details on the load that just finished
657 // (but can be null if not applicable).
658 virtual void SetIsLoading(RenderViewHost* render_view_host,
660 bool to_different_document,
661 LoadNotificationDetails* details) OVERRIDE;
663 typedef base::Callback<void(WebContents*)> CreatedCallback;
665 // Requests the renderer to select the region between two points in the
666 // currently focused frame.
667 void SelectRange(const gfx::Point& start, const gfx::Point& end);
669 // Notifies the main frame that it can continue navigation (if it was deferred
670 // immediately at first response).
671 void ResumeResponseDeferredAtStart();
674 friend class TestNavigationObserver;
675 friend class WebContentsAddedObserver;
676 friend class WebContentsObserver;
677 friend class WebContents; // To implement factory methods.
679 FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest, NoJSMessageOnInterstitials);
680 FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest, UpdateTitle);
681 FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest, FindOpenerRVHWhenPending);
682 FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest,
683 CrossSiteCantPreemptAfterUnload);
684 FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest, PendingContents);
685 FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest, FrameTreeShape);
686 FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest, GetLastActiveTime);
687 FRIEND_TEST_ALL_PREFIXES(FormStructureBrowserTest, HTMLFiles);
688 FRIEND_TEST_ALL_PREFIXES(NavigationControllerTest, HistoryNavigate);
689 FRIEND_TEST_ALL_PREFIXES(RenderFrameHostManagerTest, PageDoesBackAndReload);
690 FRIEND_TEST_ALL_PREFIXES(SitePerProcessBrowserTest, CrossSiteIframe);
692 // So InterstitialPageImpl can access SetIsLoading.
693 friend class InterstitialPageImpl;
695 // TODO(brettw) TestWebContents shouldn't exist!
696 friend class TestWebContents;
698 class DestructionObserver;
700 // See WebContents::Create for a description of these parameters.
701 WebContentsImpl(BrowserContext* browser_context,
702 WebContentsImpl* opener);
704 // Add and remove observers for page navigation notifications. The order in
705 // which notifications are sent to observers is undefined. Clients must be
706 // sure to remove the observer before they go away.
707 void AddObserver(WebContentsObserver* observer);
708 void RemoveObserver(WebContentsObserver* observer);
710 // Clears this tab's opener if it has been closed.
711 void OnWebContentsDestroyed(WebContentsImpl* web_contents);
713 // Creates and adds to the map a destruction observer watching |web_contents|.
714 // No-op if such an observer already exists.
715 void AddDestructionObserver(WebContentsImpl* web_contents);
717 // Deletes and removes from the map a destruction observer
718 // watching |web_contents|. No-op if there is no such observer.
719 void RemoveDestructionObserver(WebContentsImpl* web_contents);
721 // Traverses all the RenderFrameHosts in the FrameTree and creates a set
722 // all the unique RenderWidgetHostViews.
723 std::set<RenderWidgetHostView*> GetRenderWidgetHostViewsInTree();
725 // Callback function when showing JavaScript dialogs. Takes in a routing ID
726 // pair to identify the RenderFrameHost that opened the dialog, because it's
727 // possible for the RenderFrameHost to be deleted by the time this is called.
728 void OnDialogClosed(int render_process_id,
730 IPC::Message* reply_msg,
731 bool dialog_was_suppressed,
733 const base::string16& user_input);
735 // Callback function when requesting permission to access the PPAPI broker.
736 // |result| is true if permission was granted.
737 void OnPpapiBrokerPermissionResult(int routing_id, bool result);
739 bool OnMessageReceived(RenderViewHost* render_view_host,
740 RenderFrameHost* render_frame_host,
741 const IPC::Message& message);
743 // IPC message handlers.
744 void OnThemeColorChanged(SkColor theme_color);
745 void OnDidLoadResourceFromMemoryCache(const GURL& url,
746 const std::string& security_info,
747 const std::string& http_request,
748 const std::string& mime_type,
749 ResourceType resource_type);
750 void OnDidDisplayInsecureContent();
751 void OnDidRunInsecureContent(const std::string& security_origin,
752 const GURL& target_url);
753 void OnDocumentLoadedInFrame();
754 void OnDidFinishLoad(const GURL& url);
755 void OnDidStartLoading(bool to_different_document);
756 void OnDidStopLoading();
757 void OnDidChangeLoadProgress(double load_progress);
758 void OnGoToEntryAtOffset(int offset);
759 void OnUpdateZoomLimits(int minimum_percent,
760 int maximum_percent);
761 void OnEnumerateDirectory(int request_id, const base::FilePath& path);
763 void OnRegisterProtocolHandler(const std::string& protocol,
765 const base::string16& title,
767 void OnUnregisterProtocolHandler(const std::string& protocol,
770 void OnFindReply(int request_id,
771 int number_of_matches,
772 const gfx::Rect& selection_rect,
773 int active_match_ordinal,
775 #if defined(OS_ANDROID)
776 void OnFindMatchRectsReply(int version,
777 const std::vector<gfx::RectF>& rects,
778 const gfx::RectF& active_rect);
780 void OnOpenDateTimeDialog(
781 const ViewHostMsg_DateTimeDialogValue_Params& value);
783 void OnPepperPluginHung(int plugin_child_id,
784 const base::FilePath& path,
786 void OnPluginCrashed(const base::FilePath& plugin_path,
787 base::ProcessId plugin_pid);
788 void OnDomOperationResponse(const std::string& json_string,
790 void OnAppCacheAccessed(const GURL& manifest_url, bool blocked_by_policy);
791 void OnOpenColorChooser(int color_chooser_id,
793 const std::vector<ColorSuggestion>& suggestions);
794 void OnEndColorChooser(int color_chooser_id);
795 void OnSetSelectedColorInColorChooser(int color_chooser_id, SkColor color);
796 void OnWebUISend(const GURL& source_url,
797 const std::string& name,
798 const base::ListValue& args);
799 void OnRequestPpapiBrokerPermission(int routing_id,
801 const base::FilePath& plugin_path);
802 void OnBrowserPluginMessage(const IPC::Message& message);
803 void OnDidDownloadImage(int id,
804 int http_status_code,
805 const GURL& image_url,
806 const std::vector<SkBitmap>& bitmaps,
807 const std::vector<gfx::Size>& original_bitmap_sizes);
808 void OnUpdateFaviconURL(const std::vector<FaviconURL>& candidates);
809 void OnFirstVisuallyNonEmptyPaint();
810 void OnMediaPlayingNotification(int64 player_cookie,
813 void OnMediaPausedNotification(int64 player_cookie);
814 void OnShowValidationMessage(const gfx::Rect& anchor_in_root_view,
815 const base::string16& main_text,
816 const base::string16& sub_text);
817 void OnHideValidationMessage();
818 void OnMoveValidationMessage(const gfx::Rect& anchor_in_root_view);
820 // Called by derived classes to indicate that we're no longer waiting for a
821 // response. This won't actually update the throbber, but it will get picked
822 // up at the next animation step if the throbber is going.
823 void SetNotWaitingForResponse() { waiting_for_response_ = false; }
825 // Navigation helpers --------------------------------------------------------
827 // These functions are helpers for Navigate() and DidNavigate().
829 // Handles post-navigation tasks in DidNavigate AFTER the entry has been
830 // committed to the navigation controller. Note that the navigation entry is
831 // not provided since it may be invalid/changed after being committed. The
832 // current navigation entry is in the NavigationController at this point.
834 // If our controller was restored, update the max page ID associated with the
835 // given RenderViewHost to be larger than the number of restored entries.
836 // This is called in CreateRenderView before any navigations in the RenderView
837 // have begun, to prevent any races in updating RenderView::next_page_id.
838 void UpdateMaxPageIDIfNecessary(RenderViewHost* rvh);
840 // Saves the given title to the navigation entry and does associated work. It
841 // will update history and the view for the new title, and also synthesize
842 // titles for file URLs that have none (so we require that the URL of the
843 // entry already be set).
845 // This is used as the backend for state updates, which include a new title,
846 // or the dedicated set title message. It returns true if the new title is
847 // different and was therefore updated.
848 bool UpdateTitleForEntry(NavigationEntryImpl* entry,
849 const base::string16& title);
851 // Recursively creates swapped out RenderViews for this tab's opener chain
852 // (including this tab) in the given SiteInstance, allowing other tabs to send
853 // cross-process JavaScript calls to their opener(s). Returns the route ID of
854 // this tab's RenderView for |instance|.
855 int CreateOpenerRenderViews(SiteInstance* instance);
857 // Helper for CreateNewWidget/CreateNewFullscreenWidget.
858 void CreateNewWidget(int render_process_id,
861 blink::WebPopupType popup_type);
863 // Helper for ShowCreatedWidget/ShowCreatedFullscreenWidget.
864 void ShowCreatedWidget(int route_id,
866 const gfx::Rect& initial_pos);
868 // Finds the new RenderWidgetHost and returns it. Note that this can only be
869 // called once as this call also removes it from the internal map.
870 RenderWidgetHostView* GetCreatedWidget(int route_id);
872 // Finds the new WebContentsImpl by route_id, initializes it for
873 // renderer-initiated creation, and returns it. Note that this can only be
874 // called once as this call also removes it from the internal map.
875 WebContentsImpl* GetCreatedWindow(int route_id);
877 // Tracking loading progress -------------------------------------------------
879 // Resets the tracking state of the current load.
880 void ResetLoadProgressState();
882 // Calculates the progress of the current load and notifies the delegate.
883 void SendLoadProgressChanged();
885 // Called once when the last frame on the page has stopped loading.
886 void DidStopLoading(RenderFrameHost* render_frame_host);
888 // Misc non-view stuff -------------------------------------------------------
890 // Helper functions for sending notifications.
891 void NotifyViewSwapped(RenderViewHost* old_host, RenderViewHost* new_host);
892 void NotifyFrameSwapped(RenderFrameHost* old_host, RenderFrameHost* new_host);
893 void NotifyDisconnected();
895 void SetEncoding(const std::string& encoding);
897 // TODO(creis): This should take in a FrameTreeNode to know which node's
898 // render manager to return. For now, we just return the root's.
899 RenderFrameHostManager* GetRenderManager() const;
901 RenderViewHostImpl* GetRenderViewHostImpl();
903 // Removes browser plugin embedder if there is one.
904 void RemoveBrowserPluginEmbedder();
906 // Clear |render_frame_host|'s PowerSaveBlockers.
907 void ClearPowerSaveBlockers(RenderFrameHost* render_frame_host);
909 // Clear all PowerSaveBlockers, leave |power_save_blocker_| empty.
910 void ClearAllPowerSaveBlockers();
912 // Helper function to invoke WebContentsDelegate::GetSizeForNewRenderView().
913 gfx::Size GetSizeForNewRenderView();
915 void OnFrameRemoved(RenderFrameHost* render_frame_host);
917 // Helper method that's called whenever |preferred_size_| or
918 // |preferred_size_for_capture_| changes, to propagate the new value to the
920 void OnPreferredSizeChanged(const gfx::Size& old_size);
922 // Adds/removes a callback called on creation of each new WebContents.
923 // Deprecated, about to remove.
924 static void AddCreatedCallback(const CreatedCallback& callback);
925 static void RemoveCreatedCallback(const CreatedCallback& callback);
927 // Data for core operation ---------------------------------------------------
929 // Delegate for notifying our owner about stuff. Not owned by us.
930 WebContentsDelegate* delegate_;
932 // Handles the back/forward list and loading.
933 NavigationControllerImpl controller_;
935 // The corresponding view.
936 scoped_ptr<WebContentsView> view_;
938 // The view of the RVHD. Usually this is our WebContentsView implementation,
939 // but if an embedder uses a different WebContentsView, they'll need to
941 RenderViewHostDelegateView* render_view_host_delegate_view_;
943 // Tracks created WebContentsImpl objects that have not been shown yet. They
944 // are identified by the route ID passed to CreateNewWindow.
945 typedef std::map<int, WebContentsImpl*> PendingContents;
946 PendingContents pending_contents_;
948 // These maps hold on to the widgets that we created on behalf of the renderer
949 // that haven't shown yet.
950 typedef std::map<int, RenderWidgetHostView*> PendingWidgetViews;
951 PendingWidgetViews pending_widget_views_;
953 typedef std::map<WebContentsImpl*, DestructionObserver*> DestructionObservers;
954 DestructionObservers destruction_observers_;
956 // A list of observers notified when page state changes. Weak references.
957 // This MUST be listed above frame_tree_ since at destruction time the
958 // latter might cause RenderViewHost's destructor to call us and we might use
959 // the observer list then.
960 ObserverList<WebContentsObserver> observers_;
962 // The tab that opened this tab, if any. Will be set to null if the opener
964 WebContentsImpl* opener_;
966 // True if this tab was opened by another tab. This is not unset if the opener
968 bool created_with_opener_;
971 gfx::NativeViewAccessible accessible_parent_;
974 // Helper classes ------------------------------------------------------------
976 #if !defined(OS_CHROMEOS)
977 // Maps the RenderFrameHost to its media_player_cookie and PowerSaveBlocker
978 // pairs. Key is the RenderFrameHost, value is the map which maps
979 // player_cookie on to PowerSaveBlocker.
981 // ChromeOS does its own detection of audio and video.
982 typedef base::ScopedPtrHashMap<int64, PowerSaveBlocker>
983 PowerSaveBlockerMapEntry;
984 typedef base::ScopedPtrHashMap<uintptr_t, PowerSaveBlockerMapEntry>
986 PowerSaveBlockerMap power_save_blockers_;
989 // Manages the frame tree of the page and process swaps in each node.
990 FrameTree frame_tree_;
992 // SavePackage, lazily created.
993 scoped_refptr<SavePackage> save_package_;
995 // Data for loading state ----------------------------------------------------
997 // Indicates whether we're currently loading a resource.
1000 // Indicates whether the current load is to a different document. Only valid
1001 // if is_loading_ is true.
1002 bool is_load_to_different_document_;
1004 // Indicates if the tab is considered crashed.
1005 base::TerminationStatus crashed_status_;
1006 int crashed_error_code_;
1008 // Whether this WebContents is waiting for a first-response for the
1009 // main resource of the page. This controls whether the throbber state is
1010 // "waiting" or "loading."
1011 bool waiting_for_response_;
1013 // Map of SiteInstance ID to max page ID for this tab. A page ID is specific
1014 // to a given tab and SiteInstance, and must be valid for the lifetime of the
1016 std::map<int32, int32> max_page_ids_;
1018 // The current load state and the URL associated with it.
1019 net::LoadStateWithParam load_state_;
1020 base::string16 load_state_host_;
1022 // LoadingProgressMap maps FrameTreeNode IDs to a double representing that
1023 // frame's completion (from 0 to 1).
1024 typedef base::hash_map<int64, double> LoadingProgressMap;
1025 LoadingProgressMap loading_progresses_;
1026 double loading_total_progress_;
1028 base::TimeTicks loading_last_progress_update_;
1030 base::WeakPtrFactory<WebContentsImpl> loading_weak_factory_;
1032 // Counter to track how many frames have sent start notifications but not
1033 // stop notifications.
1034 int loading_frames_in_progress_;
1036 // Upload progress, for displaying in the status bar.
1037 // Set to zero when there is no significant upload happening.
1038 uint64 upload_size_;
1039 uint64 upload_position_;
1041 // Data for current page -----------------------------------------------------
1043 // When a title cannot be taken from any entry, this title will be used.
1044 base::string16 page_title_when_no_navigation_entry_;
1046 // When a navigation occurs, we record its contents MIME type. It can be
1047 // used to check whether we can do something for some special contents.
1048 std::string contents_mime_type_;
1050 // The last reported character encoding, not canonicalized.
1051 std::string last_reported_encoding_;
1053 // The canonicalized character encoding.
1054 std::string canonical_encoding_;
1056 // True if this is a secure page which displayed insecure content.
1057 bool displayed_insecure_content_;
1059 // Whether the initial empty page has been accessed by another page, making it
1060 // unsafe to show the pending URL. Usually false unless another window tries
1061 // to modify the blank page. Always false after the first commit.
1062 bool has_accessed_initial_document_;
1064 // Data for misc internal state ----------------------------------------------
1066 // When > 0, the WebContents is currently being captured (e.g., for
1067 // screenshots or mirroring); and the underlying RenderWidgetHost should not
1068 // be told it is hidden.
1069 int capturer_count_;
1071 // Tracks whether RWHV should be visible once capturer_count_ becomes zero.
1072 bool should_normally_be_visible_;
1074 // See getter above.
1075 bool is_being_destroyed_;
1077 // Indicates whether we should notify about disconnection of this
1078 // WebContentsImpl. This is used to ensure disconnection notifications only
1079 // happen if a connection notification has happened and that they happen only
1081 bool notify_disconnection_;
1083 // Pointer to the JavaScript dialog manager, lazily assigned. Used because the
1084 // delegate of this WebContentsImpl is nulled before its destructor is called.
1085 JavaScriptDialogManager* dialog_manager_;
1087 // Set to true when there is an active "before unload" dialog. When true,
1088 // we've forced the throbber to start in Navigate, and we need to remember to
1089 // turn it off in OnJavaScriptMessageBoxClosed if the navigation is canceled.
1090 bool is_showing_before_unload_dialog_;
1092 // Settings that get passed to the renderer process.
1093 RendererPreferences renderer_preferences_;
1095 // The time that this WebContents was last made active. The initial value is
1096 // the WebContents creation time.
1097 base::TimeTicks last_active_time_;
1099 // See description above setter.
1100 bool closed_by_user_gesture_;
1102 // Minimum/maximum zoom percent.
1103 int minimum_zoom_percent_;
1104 int maximum_zoom_percent_;
1106 // The raw accumulated zoom value and the actual zoom increments made for an
1107 // an in-progress pinch gesture.
1108 float totalPinchGestureAmount_;
1109 int currentPinchZoomStepDelta_;
1111 // The intrinsic size of the page.
1112 gfx::Size preferred_size_;
1114 // The preferred size for content screen capture. When |capturer_count_| > 0,
1115 // this overrides |preferred_size_|.
1116 gfx::Size preferred_size_for_capture_;
1118 #if defined(OS_ANDROID)
1119 // Date time chooser opened by this tab.
1120 // Only used in Android since all other platforms use a multi field UI.
1121 scoped_ptr<DateTimeChooserAndroid> date_time_chooser_;
1124 // Holds information about a current color chooser dialog, if one is visible.
1125 struct ColorChooserInfo {
1126 ColorChooserInfo(int render_process_id,
1127 int render_frame_id,
1128 ColorChooser* chooser,
1130 ~ColorChooserInfo();
1132 int render_process_id;
1133 int render_frame_id;
1135 // Color chooser that was opened by this tab.
1136 scoped_ptr<ColorChooser> chooser;
1138 // A unique identifier for the current color chooser. Identifiers are
1139 // unique across a renderer process. This avoids race conditions in
1140 // synchronizing the browser and renderer processes. For example, if a
1141 // renderer closes one chooser and opens another, and simultaneously the
1142 // user picks a color in the first chooser, the IDs can be used to drop the
1143 // "chose a color" message rather than erroneously tell the renderer that
1144 // the user picked a color in the second chooser.
1148 scoped_ptr<ColorChooserInfo> color_chooser_info_;
1150 // Manages the embedder state for browser plugins, if this WebContents is an
1151 // embedder; NULL otherwise.
1152 scoped_ptr<BrowserPluginEmbedder> browser_plugin_embedder_;
1153 // Manages the guest state for browser plugin, if this WebContents is a guest;
1155 scoped_ptr<BrowserPluginGuest> browser_plugin_guest_;
1157 // This must be at the end, or else we might get notifications and use other
1158 // member variables that are gone.
1159 NotificationRegistrar registrar_;
1161 // Used during IPC message dispatching from the RenderView/RenderFrame so that
1162 // the handlers can get a pointer to the RVH through which the message was
1164 RenderViewHost* render_view_message_source_;
1165 RenderFrameHost* render_frame_message_source_;
1167 // All live RenderWidgetHostImpls that are created by this object and may
1169 std::set<RenderWidgetHostImpl*> created_widgets_;
1171 // Routing id of the shown fullscreen widget or MSG_ROUTING_NONE otherwise.
1172 int fullscreen_widget_routing_id_;
1174 // At the time the fullscreen widget was being shut down, did it have focus?
1175 // This is used to restore focus to the WebContentsView after both: 1) the
1176 // fullscreen widget is destroyed, and 2) the WebContentsDelegate has
1177 // completed making layout changes to effect an exit from fullscreen mode.
1178 bool fullscreen_widget_had_focus_at_shutdown_;
1180 // Maps the ids of pending image downloads to their callbacks
1181 typedef std::map<int, ImageDownloadCallback> ImageDownloadMap;
1182 ImageDownloadMap image_download_map_;
1184 // Whether this WebContents is responsible for displaying a subframe in a
1185 // different process from its parent page.
1188 // Whether touch emulation is enabled in RenderWidgetHost.
1189 bool touch_emulation_enabled_;
1191 // Whether the last JavaScript dialog shown was suppressed. Used for testing.
1192 bool last_dialog_suppressed_;
1194 scoped_ptr<GeolocationDispatcherHost> geolocation_dispatcher_host_;
1196 scoped_ptr<MidiDispatcherHost> midi_dispatcher_host_;
1198 scoped_ptr<ScreenOrientationDispatcherHost>
1199 screen_orientation_dispatcher_host_;
1201 // The accessibility mode for all frames. This is queried when each frame
1202 // is created, and broadcast to all frames when it changes.
1203 AccessibilityMode accessibility_mode_;
1205 DISALLOW_COPY_AND_ASSIGN(WebContentsImpl);
1208 } // namespace content
1210 #endif // CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_IMPL_H_