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/media/audio_stream_monitor.h"
26 #include "content/browser/renderer_host/render_view_host_delegate.h"
27 #include "content/browser/renderer_host/render_widget_host_delegate.h"
28 #include "content/common/accessibility_mode_enums.h"
29 #include "content/common/content_export.h"
30 #include "content/public/browser/color_chooser.h"
31 #include "content/public/browser/notification_observer.h"
32 #include "content/public/browser/notification_registrar.h"
33 #include "content/public/browser/web_contents.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/base/page_transition_types.h"
41 #include "ui/gfx/rect_f.h"
42 #include "ui/gfx/size.h"
44 struct BrowserPluginHostMsg_ResizeGuest_Params;
45 struct ViewHostMsg_DateTimeDialogValue_Params;
46 struct ViewMsg_PostMessage_Params;
49 class BrowserPluginEmbedder;
50 class BrowserPluginGuest;
51 class BrowserPluginGuestManager;
52 class DateTimeChooserAndroid;
54 class GeolocationDispatcherHost;
55 class InterstitialPageImpl;
56 class JavaScriptDialogManager;
57 class ManifestManagerHost;
58 class MidiDispatcherHost;
59 class PowerSaveBlocker;
61 class RenderViewHostDelegateView;
62 class RenderViewHostImpl;
63 class RenderWidgetHostImpl;
65 class ScreenOrientationDispatcherHost;
67 class TestWebContents;
68 class WebContentsAudioMuter;
69 class WebContentsDelegate;
70 class WebContentsImpl;
71 class WebContentsObserver;
72 class WebContentsView;
73 class WebContentsViewDelegate;
74 struct AXEventNotificationDetails;
75 struct ColorSuggestion;
77 struct LoadNotificationDetails;
78 struct ResourceRedirectDetails;
79 struct ResourceRequestDetails;
81 #if defined(OS_ANDROID)
82 class WebContentsAndroid;
85 // Factory function for the implementations that content knows about. Takes
86 // ownership of |delegate|.
87 WebContentsView* CreateWebContentsView(
88 WebContentsImpl* web_contents,
89 WebContentsViewDelegate* delegate,
90 RenderViewHostDelegateView** render_view_host_delegate_view);
92 class CONTENT_EXPORT WebContentsImpl
93 : public NON_EXPORTED_BASE(WebContents),
94 public NON_EXPORTED_BASE(RenderFrameHostDelegate),
95 public RenderViewHostDelegate,
96 public RenderWidgetHostDelegate,
97 public RenderFrameHostManager::Delegate,
98 public NotificationObserver,
99 public NON_EXPORTED_BASE(NavigationControllerDelegate),
100 public NON_EXPORTED_BASE(NavigatorDelegate) {
102 virtual ~WebContentsImpl();
104 static WebContentsImpl* CreateWithOpener(
105 const WebContents::CreateParams& params,
106 WebContentsImpl* opener);
108 static std::vector<WebContentsImpl*> GetAllWebContents();
110 // Returns the opener WebContentsImpl, if any. This can be set to null if the
111 // opener is closed or the page clears its window.opener.
112 WebContentsImpl* opener() const { return opener_; }
114 // Creates a swapped out RenderView. This is used by the browser plugin to
115 // create a swapped out RenderView in the embedder render process for the
116 // guest, to expose the guest's window object to the embedder.
117 // This returns the routing ID of the newly created swapped out RenderView.
118 int CreateSwappedOutRenderView(SiteInstance* instance);
120 // Complex initialization here. Specifically needed to avoid having
121 // members call back into our virtual functions in the constructor.
122 virtual void Init(const WebContents::CreateParams& params);
124 // Returns the SavePackage which manages the page saving job. May be NULL.
125 SavePackage* save_package() const { return save_package_.get(); }
127 #if defined(OS_ANDROID)
128 // In Android WebView, the RenderView needs created even there is no
129 // navigation entry, this allows Android WebViews to use
130 // javascript: URLs that load into the DOMWindow before the first page
131 // load. This is not safe to do in any context that a web page could get a
132 // reference to the DOMWindow before the first page load.
133 bool CreateRenderViewForInitialEmptyDocument();
136 // Expose the render manager for testing.
137 // TODO(creis): Remove this now that we can get to it via FrameTreeNode.
138 RenderFrameHostManager* GetRenderManagerForTesting();
140 // Returns guest browser plugin object, or NULL if this WebContents is not a
142 BrowserPluginGuest* GetBrowserPluginGuest() const;
144 // Sets a BrowserPluginGuest object for this WebContents. If this WebContents
145 // has a BrowserPluginGuest then that implies that it is being hosted by
146 // a BrowserPlugin object in an embedder renderer process.
147 void SetBrowserPluginGuest(BrowserPluginGuest* guest);
149 // Returns embedder browser plugin object, or NULL if this WebContents is not
151 BrowserPluginEmbedder* GetBrowserPluginEmbedder() const;
153 // Gets the current fullscreen render widget's routing ID. Returns
154 // MSG_ROUTING_NONE when there is no fullscreen render widget.
155 int GetFullscreenWidgetRoutingID() const;
157 // Invoked when visible SSL state (as defined by SSLStatus) changes.
158 void DidChangeVisibleSSLState();
160 // Informs the render view host and the BrowserPluginEmbedder, if present, of
161 // a Drag Source End.
162 void DragSourceEndedAt(int client_x, int client_y, int screen_x,
163 int screen_y, blink::WebDragOperation operation);
165 // A response has been received for a resource request.
166 void DidGetResourceResponseStart(
167 const ResourceRequestDetails& details);
169 // A redirect was received while requesting a resource.
170 void DidGetRedirectForResourceRequest(
171 RenderViewHost* render_view_host,
172 const ResourceRedirectDetails& details);
174 WebContentsView* GetView() const;
176 GeolocationDispatcherHost* geolocation_dispatcher_host() {
177 return geolocation_dispatcher_host_.get();
180 ScreenOrientationDispatcherHost* screen_orientation_dispatcher_host() {
181 return screen_orientation_dispatcher_host_.get();
184 bool should_normally_be_visible() { return should_normally_be_visible_; }
186 // Broadcasts the mode change to all frames.
187 void SetAccessibilityMode(AccessibilityMode mode);
189 // Adds the given accessibility mode to the current accessibility mode
191 void AddAccessibilityMode(AccessibilityMode mode);
193 // Removes the given accessibility mode from the current accessibility
194 // mode bitmap, managing the bits that are shared with other modes such
195 // that a bit will only be turned off when all modes that depend on it
196 // have been removed.
197 void RemoveAccessibilityMode(AccessibilityMode mode);
199 // WebContents ------------------------------------------------------
200 virtual ScreenOrientationDispatcherHost* GetScreenOrientationDispatcherHost() OVERRIDE;
201 virtual WebContentsDelegate* GetDelegate() OVERRIDE;
202 virtual void SetDelegate(WebContentsDelegate* delegate) OVERRIDE;
203 virtual NavigationControllerImpl& GetController() OVERRIDE;
204 virtual const NavigationControllerImpl& GetController() const OVERRIDE;
205 virtual BrowserContext* GetBrowserContext() const OVERRIDE;
206 virtual const GURL& GetURL() const OVERRIDE;
207 virtual const GURL& GetVisibleURL() const OVERRIDE;
208 virtual const GURL& GetLastCommittedURL() const OVERRIDE;
209 virtual RenderProcessHost* GetRenderProcessHost() const OVERRIDE;
210 virtual RenderFrameHost* GetMainFrame() OVERRIDE;
211 virtual RenderFrameHost* GetFocusedFrame() OVERRIDE;
212 virtual void ForEachFrame(
213 const base::Callback<void(RenderFrameHost*)>& on_frame) OVERRIDE;
214 virtual void SendToAllFrames(IPC::Message* message) OVERRIDE;
215 virtual RenderViewHost* GetRenderViewHost() const OVERRIDE;
216 virtual int GetRoutingID() const OVERRIDE;
217 virtual RenderWidgetHostView* GetRenderWidgetHostView() const OVERRIDE;
218 virtual RenderWidgetHostView* GetFullscreenRenderWidgetHostView() const
220 virtual WebUI* CreateWebUI(const GURL& url) OVERRIDE;
221 virtual WebUI* GetWebUI() const OVERRIDE;
222 virtual WebUI* GetCommittedWebUI() const OVERRIDE;
223 virtual void SetUserAgentOverride(const std::string& override) OVERRIDE;
224 virtual const std::string& GetUserAgentOverride() const OVERRIDE;
225 virtual void EnableTreeOnlyAccessibilityMode() OVERRIDE;
226 virtual bool IsTreeOnlyAccessibilityModeForTesting() const OVERRIDE;
227 virtual bool IsFullAccessibilityModeForTesting() const OVERRIDE;
229 virtual void SetParentNativeViewAccessible(
230 gfx::NativeViewAccessible accessible_parent) OVERRIDE;
232 virtual const base::string16& GetTitle() const OVERRIDE;
233 virtual int32 GetMaxPageID() OVERRIDE;
234 virtual int32 GetMaxPageIDForSiteInstance(
235 SiteInstance* site_instance) OVERRIDE;
236 virtual SiteInstance* GetSiteInstance() const OVERRIDE;
237 virtual SiteInstance* GetPendingSiteInstance() const OVERRIDE;
238 virtual bool IsLoading() const OVERRIDE;
239 virtual bool IsLoadingToDifferentDocument() const OVERRIDE;
240 virtual bool IsWaitingForResponse() const OVERRIDE;
241 virtual const net::LoadStateWithParam& GetLoadState() const OVERRIDE;
242 virtual const base::string16& GetLoadStateHost() const OVERRIDE;
243 virtual uint64 GetUploadSize() const OVERRIDE;
244 virtual uint64 GetUploadPosition() const OVERRIDE;
245 virtual std::set<GURL> GetSitesInTab() const OVERRIDE;
246 virtual const std::string& GetEncoding() const OVERRIDE;
247 virtual bool DisplayedInsecureContent() const OVERRIDE;
248 virtual void IncrementCapturerCount(const gfx::Size& capture_size) OVERRIDE;
249 virtual void DecrementCapturerCount() OVERRIDE;
250 virtual int GetCapturerCount() const OVERRIDE;
251 virtual bool IsAudioMuted() const OVERRIDE;
252 virtual void SetAudioMuted(bool mute) OVERRIDE;
253 virtual bool IsCrashed() const OVERRIDE;
254 virtual void SetIsCrashed(base::TerminationStatus status,
255 int error_code) OVERRIDE;
256 virtual base::TerminationStatus GetCrashedStatus() const OVERRIDE;
257 virtual bool IsBeingDestroyed() const OVERRIDE;
258 virtual void NotifyNavigationStateChanged(
259 InvalidateTypes changed_flags) OVERRIDE;
260 virtual base::TimeTicks GetLastActiveTime() const OVERRIDE;
261 virtual void WasShown() OVERRIDE;
262 virtual void WasHidden() OVERRIDE;
263 virtual bool NeedToFireBeforeUnload() OVERRIDE;
264 virtual void DispatchBeforeUnload(bool for_cross_site_transition) OVERRIDE;
265 virtual void Stop() OVERRIDE;
266 virtual WebContents* Clone() OVERRIDE;
267 virtual void ReloadFocusedFrame(bool ignore_cache) OVERRIDE;
268 virtual void Undo() OVERRIDE;
269 virtual void Redo() OVERRIDE;
270 virtual void Cut() OVERRIDE;
271 virtual void Copy() OVERRIDE;
272 virtual void CopyToFindPboard() OVERRIDE;
273 virtual void Paste() OVERRIDE;
274 virtual void PasteAndMatchStyle() OVERRIDE;
275 virtual void Delete() OVERRIDE;
276 virtual void SelectAll() OVERRIDE;
277 virtual void Unselect() OVERRIDE;
278 virtual void Replace(const base::string16& word) OVERRIDE;
279 virtual void ReplaceMisspelling(const base::string16& word) OVERRIDE;
280 virtual void NotifyContextMenuClosed(
281 const CustomContextMenuContext& context) OVERRIDE;
282 virtual void ExecuteCustomContextMenuCommand(
283 int action, const CustomContextMenuContext& context) OVERRIDE;
284 virtual gfx::NativeView GetNativeView() OVERRIDE;
285 virtual gfx::NativeView GetContentNativeView() OVERRIDE;
286 virtual gfx::NativeWindow GetTopLevelNativeWindow() OVERRIDE;
287 virtual gfx::Rect GetContainerBounds() OVERRIDE;
288 virtual gfx::Rect GetViewBounds() OVERRIDE;
289 virtual DropData* GetDropData() OVERRIDE;
290 virtual void Focus() OVERRIDE;
291 virtual void SetInitialFocus() OVERRIDE;
292 virtual void StoreFocus() OVERRIDE;
293 virtual void RestoreFocus() OVERRIDE;
294 virtual void FocusThroughTabTraversal(bool reverse) OVERRIDE;
295 virtual bool ShowingInterstitialPage() const OVERRIDE;
296 virtual InterstitialPage* GetInterstitialPage() const OVERRIDE;
297 virtual bool IsSavable() OVERRIDE;
298 virtual void OnSavePage() OVERRIDE;
299 virtual bool SavePage(const base::FilePath& main_file,
300 const base::FilePath& dir_path,
301 SavePageType save_type) OVERRIDE;
302 virtual void SaveFrame(const GURL& url,
303 const Referrer& referrer) OVERRIDE;
304 virtual void GenerateMHTML(
305 const base::FilePath& file,
306 const base::Callback<void(int64)>& callback)
308 virtual const std::string& GetContentsMimeType() const OVERRIDE;
309 virtual bool WillNotifyDisconnection() const OVERRIDE;
310 virtual void SetOverrideEncoding(const std::string& encoding) OVERRIDE;
311 virtual void ResetOverrideEncoding() OVERRIDE;
312 virtual RendererPreferences* GetMutableRendererPrefs() OVERRIDE;
313 virtual void Close() OVERRIDE;
314 virtual void SystemDragEnded() OVERRIDE;
315 virtual void UserGestureDone() OVERRIDE;
316 virtual void SetClosedByUserGesture(bool value) OVERRIDE;
317 virtual bool GetClosedByUserGesture() const OVERRIDE;
318 virtual void ViewSource() OVERRIDE;
319 virtual void ViewFrameSource(const GURL& url,
320 const PageState& page_state) OVERRIDE;
321 virtual int GetMinimumZoomPercent() const OVERRIDE;
322 virtual int GetMaximumZoomPercent() const OVERRIDE;
323 virtual gfx::Size GetPreferredSize() const OVERRIDE;
324 virtual bool GotResponseToLockMouseRequest(bool allowed) OVERRIDE;
325 virtual bool HasOpener() const OVERRIDE;
326 virtual void DidChooseColorInColorChooser(SkColor color) OVERRIDE;
327 virtual void DidEndColorChooser() OVERRIDE;
328 virtual int DownloadImage(const GURL& url,
330 uint32_t max_bitmap_size,
331 const ImageDownloadCallback& callback) OVERRIDE;
332 virtual bool IsSubframe() const OVERRIDE;
333 virtual void Find(int request_id,
334 const base::string16& search_text,
335 const blink::WebFindOptions& options) OVERRIDE;
336 virtual void StopFinding(StopFindAction action) OVERRIDE;
337 virtual void InsertCSS(const std::string& css) OVERRIDE;
338 virtual bool WasRecentlyAudible() OVERRIDE;
339 virtual void GetManifest(const GetManifestCallback&) OVERRIDE;
340 #if defined(OS_ANDROID)
341 virtual base::android::ScopedJavaLocalRef<jobject> GetJavaWebContents()
343 virtual WebContentsAndroid* GetWebContentsAndroid();
344 #elif defined(OS_MACOSX)
345 virtual void SetAllowOtherViews(bool allow) OVERRIDE;
346 virtual bool GetAllowOtherViews() OVERRIDE;
349 // Implementation of PageNavigator.
350 virtual WebContents* OpenURL(const OpenURLParams& params) OVERRIDE;
352 // Implementation of IPC::Sender.
353 virtual bool Send(IPC::Message* message) OVERRIDE;
355 // RenderFrameHostDelegate ---------------------------------------------------
356 virtual bool OnMessageReceived(RenderFrameHost* render_frame_host,
357 const IPC::Message& message) OVERRIDE;
358 virtual const GURL& GetMainFrameLastCommittedURL() const OVERRIDE;
359 virtual void RenderFrameCreated(RenderFrameHost* render_frame_host) OVERRIDE;
360 virtual void RenderFrameDeleted(RenderFrameHost* render_frame_host) OVERRIDE;
361 virtual void DidStartLoading(RenderFrameHost* render_frame_host,
362 bool to_different_document) OVERRIDE;
363 virtual void SwappedOut(RenderFrameHost* render_frame_host) OVERRIDE;
364 virtual void DidDeferAfterResponseStarted(
365 const TransitionLayerData& transition_data) OVERRIDE;
366 virtual bool WillHandleDeferAfterResponseStarted() OVERRIDE;
367 virtual void WorkerCrashed(RenderFrameHost* render_frame_host) OVERRIDE;
368 virtual void ShowContextMenu(RenderFrameHost* render_frame_host,
369 const ContextMenuParams& params) OVERRIDE;
370 virtual void RunJavaScriptMessage(RenderFrameHost* render_frame_host,
371 const base::string16& message,
372 const base::string16& default_prompt,
373 const GURL& frame_url,
374 JavaScriptMessageType type,
375 IPC::Message* reply_msg) OVERRIDE;
376 virtual void RunBeforeUnloadConfirm(RenderFrameHost* render_frame_host,
377 const base::string16& message,
379 IPC::Message* reply_msg) OVERRIDE;
380 virtual void DidAccessInitialDocument() OVERRIDE;
381 virtual void DidDisownOpener(RenderFrameHost* render_frame_host) OVERRIDE;
382 virtual void DocumentOnLoadCompleted(
383 RenderFrameHost* render_frame_host) OVERRIDE;
384 virtual void UpdateTitle(RenderFrameHost* render_frame_host,
386 const base::string16& title,
387 base::i18n::TextDirection title_direction) OVERRIDE;
388 virtual void UpdateEncoding(RenderFrameHost* render_frame_host,
389 const std::string& encoding) OVERRIDE;
390 virtual WebContents* GetAsWebContents() OVERRIDE;
391 virtual bool IsNeverVisible() OVERRIDE;
392 virtual AccessibilityMode GetAccessibilityMode() const OVERRIDE;
393 virtual void AccessibilityEventReceived(
394 const std::vector<AXEventNotificationDetails>& details) OVERRIDE;
395 virtual RenderFrameHost* GetGuestByInstanceID(int browser_plugin_instance_id)
398 virtual gfx::NativeViewAccessible GetParentNativeViewAccessible() OVERRIDE;
401 // RenderViewHostDelegate ----------------------------------------------------
402 virtual RenderViewHostDelegateView* GetDelegateView() OVERRIDE;
403 virtual bool OnMessageReceived(RenderViewHost* render_view_host,
404 const IPC::Message& message) OVERRIDE;
405 // RenderFrameHostDelegate has the same method, so list it there because this
406 // interface is going away.
407 // virtual WebContents* GetAsWebContents() OVERRIDE;
408 virtual gfx::Rect GetRootWindowResizerRect() const OVERRIDE;
409 virtual void RenderViewCreated(RenderViewHost* render_view_host) OVERRIDE;
410 virtual void RenderViewReady(RenderViewHost* render_view_host) OVERRIDE;
411 virtual void RenderViewTerminated(RenderViewHost* render_view_host,
412 base::TerminationStatus status,
413 int error_code) OVERRIDE;
414 virtual void RenderViewDeleted(RenderViewHost* render_view_host) OVERRIDE;
415 virtual void UpdateState(RenderViewHost* render_view_host,
417 const PageState& page_state) OVERRIDE;
418 virtual void UpdateTargetURL(const GURL& url) OVERRIDE;
419 virtual void Close(RenderViewHost* render_view_host) OVERRIDE;
420 virtual void RequestMove(const gfx::Rect& new_bounds) OVERRIDE;
421 virtual void DidCancelLoading() OVERRIDE;
422 virtual void DocumentAvailableInMainFrame(
423 RenderViewHost* render_view_host) OVERRIDE;
424 virtual void RouteCloseEvent(RenderViewHost* rvh) OVERRIDE;
425 virtual void RouteMessageEvent(
427 const ViewMsg_PostMessage_Params& params) OVERRIDE;
428 virtual bool AddMessageToConsole(int32 level,
429 const base::string16& message,
431 const base::string16& source_id) OVERRIDE;
432 virtual RendererPreferences GetRendererPrefs(
433 BrowserContext* browser_context) const OVERRIDE;
434 virtual WebPreferences ComputeWebkitPrefs() OVERRIDE;
435 virtual void OnUserGesture() OVERRIDE;
436 virtual void OnIgnoredUIEvent() OVERRIDE;
437 virtual void RendererUnresponsive(RenderViewHost* render_view_host,
438 bool is_during_beforeunload,
439 bool is_during_unload) OVERRIDE;
440 virtual void RendererResponsive(RenderViewHost* render_view_host) OVERRIDE;
441 virtual void LoadStateChanged(const GURL& url,
442 const net::LoadStateWithParam& load_state,
443 uint64 upload_position,
444 uint64 upload_size) OVERRIDE;
445 virtual void Activate() OVERRIDE;
446 virtual void Deactivate() OVERRIDE;
447 virtual void LostCapture() OVERRIDE;
448 virtual void HandleMouseDown() OVERRIDE;
449 virtual void HandleMouseUp() OVERRIDE;
450 virtual void HandlePointerActivate() OVERRIDE;
451 virtual void HandleGestureBegin() OVERRIDE;
452 virtual void HandleGestureEnd() OVERRIDE;
453 virtual void RunFileChooser(
454 RenderViewHost* render_view_host,
455 const FileChooserParams& params) OVERRIDE;
456 virtual void ToggleFullscreenMode(bool enter_fullscreen) OVERRIDE;
457 virtual bool IsFullscreenForCurrentTab() const OVERRIDE;
458 virtual void UpdatePreferredSize(const gfx::Size& pref_size) OVERRIDE;
459 virtual void ResizeDueToAutoResize(const gfx::Size& new_size) OVERRIDE;
460 virtual void RequestToLockMouse(bool user_gesture,
461 bool last_unlocked_by_target) OVERRIDE;
462 virtual void LostMouseLock() OVERRIDE;
463 virtual void CreateNewWindow(
464 int render_process_id,
466 int main_frame_route_id,
467 const ViewHostMsg_CreateWindow_Params& params,
468 SessionStorageNamespace* session_storage_namespace) OVERRIDE;
469 virtual void CreateNewWidget(int render_process_id,
471 blink::WebPopupType popup_type) OVERRIDE;
472 virtual void CreateNewFullscreenWidget(int render_process_id,
473 int route_id) OVERRIDE;
474 virtual void ShowCreatedWindow(int route_id,
475 WindowOpenDisposition disposition,
476 const gfx::Rect& initial_pos,
477 bool user_gesture) OVERRIDE;
478 virtual void ShowCreatedWidget(int route_id,
479 const gfx::Rect& initial_pos) OVERRIDE;
480 virtual void ShowCreatedFullscreenWidget(int route_id) OVERRIDE;
481 virtual void RequestMediaAccessPermission(
482 const MediaStreamRequest& request,
483 const MediaResponseCallback& callback) OVERRIDE;
484 virtual bool CheckMediaAccessPermission(const GURL& security_origin,
485 MediaStreamType type) OVERRIDE;
486 virtual SessionStorageNamespace* GetSessionStorageNamespace(
487 SiteInstance* instance) OVERRIDE;
488 virtual SessionStorageNamespaceMap GetSessionStorageNamespaceMap() OVERRIDE;
489 virtual FrameTree* GetFrameTree() OVERRIDE;
491 // NavigatorDelegate ---------------------------------------------------------
493 virtual void DidStartProvisionalLoad(
494 RenderFrameHostImpl* render_frame_host,
495 const GURL& validated_url,
497 bool is_iframe_srcdoc) OVERRIDE;
498 virtual void DidStartNavigationTransition(
499 RenderFrameHostImpl* render_frame_host) OVERRIDE;
500 virtual void DidFailProvisionalLoadWithError(
501 RenderFrameHostImpl* render_frame_host,
502 const FrameHostMsg_DidFailProvisionalLoadWithError_Params& params)
504 virtual void DidFailLoadWithError(
505 RenderFrameHostImpl* render_frame_host,
508 const base::string16& error_description) OVERRIDE;
509 virtual void DidCommitProvisionalLoad(
510 RenderFrameHostImpl* render_frame_host,
512 ui::PageTransition transition_type) OVERRIDE;
513 virtual void DidNavigateMainFramePreCommit(
514 bool navigation_is_within_page) OVERRIDE;
515 virtual void DidNavigateMainFramePostCommit(
516 const LoadCommittedDetails& details,
517 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) OVERRIDE;
518 virtual void DidNavigateAnyFramePostCommit(
519 RenderFrameHostImpl* render_frame_host,
520 const LoadCommittedDetails& details,
521 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) OVERRIDE;
522 virtual void SetMainFrameMimeType(const std::string& mime_type) OVERRIDE;
523 virtual bool CanOverscrollContent() const OVERRIDE;
524 virtual void NotifyChangedNavigationState(
525 InvalidateTypes changed_flags) OVERRIDE;
526 virtual void AboutToNavigateRenderFrame(
527 RenderFrameHostImpl* render_frame_host) OVERRIDE;
528 virtual void DidStartNavigationToPendingEntry(
529 RenderFrameHostImpl* render_frame_host,
531 NavigationController::ReloadType reload_type) OVERRIDE;
532 virtual void RequestOpenURL(RenderFrameHostImpl* render_frame_host,
533 const OpenURLParams& params) OVERRIDE;
534 virtual bool ShouldPreserveAbortedURLs() OVERRIDE;
536 // RenderWidgetHostDelegate --------------------------------------------------
538 virtual void RenderWidgetDeleted(
539 RenderWidgetHostImpl* render_widget_host) OVERRIDE;
540 virtual bool PreHandleKeyboardEvent(
541 const NativeWebKeyboardEvent& event,
542 bool* is_keyboard_shortcut) OVERRIDE;
543 virtual void HandleKeyboardEvent(
544 const NativeWebKeyboardEvent& event) OVERRIDE;
545 virtual bool HandleWheelEvent(
546 const blink::WebMouseWheelEvent& event) OVERRIDE;
547 virtual bool PreHandleGestureEvent(
548 const blink::WebGestureEvent& event) OVERRIDE;
549 virtual bool HandleGestureEvent(
550 const blink::WebGestureEvent& event) OVERRIDE;
551 virtual void DidSendScreenRects(RenderWidgetHostImpl* rwh) OVERRIDE;
552 virtual BrowserAccessibilityManager* GetRootBrowserAccessibilityManager()
554 virtual BrowserAccessibilityManager*
555 GetOrCreateRootBrowserAccessibilityManager() OVERRIDE;
557 // RenderFrameHostManager::Delegate ------------------------------------------
559 virtual bool CreateRenderViewForRenderManager(
560 RenderViewHost* render_view_host,
562 int proxy_routing_id,
563 bool for_main_frame_navigation) OVERRIDE;
564 virtual bool CreateRenderFrameForRenderManager(
565 RenderFrameHost* render_frame_host,
566 int parent_routing_id) OVERRIDE;
567 virtual void BeforeUnloadFiredFromRenderManager(
568 bool proceed, const base::TimeTicks& proceed_time,
569 bool* proceed_to_fire_unload) OVERRIDE;
570 virtual void RenderProcessGoneFromRenderManager(
571 RenderViewHost* render_view_host) OVERRIDE;
572 virtual void UpdateRenderViewSizeForRenderManager() OVERRIDE;
573 virtual void CancelModalDialogsForRenderManager() OVERRIDE;
574 virtual void NotifySwappedFromRenderManager(RenderFrameHost* old_host,
575 RenderFrameHost* new_host,
576 bool is_main_frame) OVERRIDE;
577 virtual int CreateOpenerRenderViewsForRenderManager(
578 SiteInstance* instance) OVERRIDE;
579 virtual NavigationControllerImpl&
580 GetControllerForRenderManager() OVERRIDE;
581 virtual WebUIImpl* CreateWebUIForRenderManager(const GURL& url) OVERRIDE;
582 virtual NavigationEntry*
583 GetLastCommittedNavigationEntryForRenderManager() OVERRIDE;
584 virtual bool FocusLocationBarByDefault() OVERRIDE;
585 virtual void SetFocusToLocationBar(bool select_all) OVERRIDE;
586 virtual void CreateViewAndSetSizeForRVH(RenderViewHost* rvh) OVERRIDE;
587 virtual bool IsHidden() OVERRIDE;
589 // NotificationObserver ------------------------------------------------------
591 virtual void Observe(int type,
592 const NotificationSource& source,
593 const NotificationDetails& details) OVERRIDE;
595 // NavigationControllerDelegate ----------------------------------------------
597 virtual WebContents* GetWebContents() OVERRIDE;
598 virtual void NotifyNavigationEntryCommitted(
599 const LoadCommittedDetails& load_details) OVERRIDE;
601 // Invoked before a form repost warning is shown.
602 virtual void NotifyBeforeFormRepostWarningShow() OVERRIDE;
604 // Activate this WebContents and show a form repost warning.
605 virtual void ActivateAndShowRepostFormWarningDialog() OVERRIDE;
607 // Whether the initial empty page of this view has been accessed by another
608 // page, making it unsafe to show the pending URL. Always false after the
610 virtual bool HasAccessedInitialDocument() OVERRIDE;
612 // Updates the max page ID for the current SiteInstance in this
613 // WebContentsImpl to be at least |page_id|.
614 virtual void UpdateMaxPageID(int32 page_id) OVERRIDE;
616 // Updates the max page ID for the given SiteInstance in this WebContentsImpl
617 // to be at least |page_id|.
618 virtual void UpdateMaxPageIDForSiteInstance(SiteInstance* site_instance,
619 int32 page_id) OVERRIDE;
621 // Copy the current map of SiteInstance ID to max page ID from another tab.
622 // This is necessary when this tab adopts the NavigationEntries from
624 virtual void CopyMaxPageIDsFrom(WebContents* web_contents) OVERRIDE;
626 // Called by the NavigationController to cause the WebContentsImpl to navigate
627 // to the current pending entry. The NavigationController should be called
628 // back with RendererDidNavigate on success or DiscardPendingEntry on failure.
629 // The callbacks can be inside of this function, or at some future time.
631 // The entry has a PageID of -1 if newly created (corresponding to navigation
634 // If this method returns false, then the navigation is discarded (equivalent
635 // to calling DiscardPendingEntry on the NavigationController).
636 virtual bool NavigateToPendingEntry(
637 NavigationController::ReloadType reload_type) OVERRIDE;
639 // Sets the history for this WebContentsImpl to |history_length| entries, and
640 // moves the current page_id to the last entry in the list if it's valid.
641 // This is mainly used when a prerendered page is swapped into the current
642 // tab. The method is virtual for testing.
643 virtual void SetHistoryLengthAndPrune(
644 const SiteInstance* site_instance,
645 int merge_history_length,
646 int32 minimum_page_id) OVERRIDE;
648 // Called by InterstitialPageImpl when it creates a RenderFrameHost.
649 virtual void RenderFrameForInterstitialPageCreated(
650 RenderFrameHost* render_frame_host) OVERRIDE;
652 // Sets the passed interstitial as the currently showing interstitial.
653 // No interstitial page should already be attached.
654 virtual void AttachInterstitialPage(
655 InterstitialPageImpl* interstitial_page) OVERRIDE;
657 // Unsets the currently showing interstitial.
658 virtual void DetachInterstitialPage() OVERRIDE;
660 // Changes the IsLoading state and notifies the delegate as needed.
661 // |details| is used to provide details on the load that just finished
662 // (but can be null if not applicable).
663 virtual void SetIsLoading(RenderViewHost* render_view_host,
665 bool to_different_document,
666 LoadNotificationDetails* details) OVERRIDE;
668 typedef base::Callback<void(WebContents*)> CreatedCallback;
670 // Requests the renderer to select the region between two points in the
671 // currently focused frame.
672 void SelectRange(const gfx::Point& start, const gfx::Point& end);
674 // Notifies the main frame that it can continue navigation (if it was deferred
675 // immediately at first response).
676 void ResumeResponseDeferredAtStart();
678 // Forces overscroll to be disabled (used by touch emulation).
679 void SetForceDisableOverscrollContent(bool force_disable);
681 AudioStreamMonitor* audio_stream_monitor() {
682 return &audio_stream_monitor_;
685 bool has_audio_power_save_blocker_for_testing() const {
686 return audio_power_save_blocker_;
689 bool has_video_power_save_blocker_for_testing() const {
690 return video_power_save_blocker_;
694 friend class TestNavigationObserver;
695 friend class WebContentsAddedObserver;
696 friend class WebContentsObserver;
697 friend class WebContents; // To implement factory methods.
699 FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest, NoJSMessageOnInterstitials);
700 FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest, UpdateTitle);
701 FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest, FindOpenerRVHWhenPending);
702 FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest,
703 CrossSiteCantPreemptAfterUnload);
704 FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest, PendingContents);
705 FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest, FrameTreeShape);
706 FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest, GetLastActiveTime);
707 FRIEND_TEST_ALL_PREFIXES(FormStructureBrowserTest, HTMLFiles);
708 FRIEND_TEST_ALL_PREFIXES(NavigationControllerTest, HistoryNavigate);
709 FRIEND_TEST_ALL_PREFIXES(RenderFrameHostManagerTest, PageDoesBackAndReload);
710 FRIEND_TEST_ALL_PREFIXES(SitePerProcessBrowserTest, CrossSiteIframe);
711 FRIEND_TEST_ALL_PREFIXES(SitePerProcessAccessibilityBrowserTest,
712 CrossSiteIframeAccessibility);
714 // So InterstitialPageImpl can access SetIsLoading.
715 friend class InterstitialPageImpl;
717 // TODO(brettw) TestWebContents shouldn't exist!
718 friend class TestWebContents;
720 class DestructionObserver;
722 // See WebContents::Create for a description of these parameters.
723 WebContentsImpl(BrowserContext* browser_context,
724 WebContentsImpl* opener);
726 // Add and remove observers for page navigation notifications. The order in
727 // which notifications are sent to observers is undefined. Clients must be
728 // sure to remove the observer before they go away.
729 void AddObserver(WebContentsObserver* observer);
730 void RemoveObserver(WebContentsObserver* observer);
732 // Clears this tab's opener if it has been closed.
733 void OnWebContentsDestroyed(WebContentsImpl* web_contents);
735 // Creates and adds to the map a destruction observer watching |web_contents|.
736 // No-op if such an observer already exists.
737 void AddDestructionObserver(WebContentsImpl* web_contents);
739 // Deletes and removes from the map a destruction observer
740 // watching |web_contents|. No-op if there is no such observer.
741 void RemoveDestructionObserver(WebContentsImpl* web_contents);
743 // Traverses all the RenderFrameHosts in the FrameTree and creates a set
744 // all the unique RenderWidgetHostViews.
745 std::set<RenderWidgetHostView*> GetRenderWidgetHostViewsInTree();
747 // Callback function when showing JavaScript dialogs. Takes in a routing ID
748 // pair to identify the RenderFrameHost that opened the dialog, because it's
749 // possible for the RenderFrameHost to be deleted by the time this is called.
750 void OnDialogClosed(int render_process_id,
752 IPC::Message* reply_msg,
753 bool dialog_was_suppressed,
755 const base::string16& user_input);
757 // Callback function when requesting permission to access the PPAPI broker.
758 // |result| is true if permission was granted.
759 void OnPpapiBrokerPermissionResult(int routing_id, bool result);
761 bool OnMessageReceived(RenderViewHost* render_view_host,
762 RenderFrameHost* render_frame_host,
763 const IPC::Message& message);
765 // IPC message handlers.
766 void OnThemeColorChanged(SkColor theme_color);
767 void OnDidLoadResourceFromMemoryCache(const GURL& url,
768 const std::string& security_info,
769 const std::string& http_request,
770 const std::string& mime_type,
771 ResourceType resource_type);
772 void OnDidDisplayInsecureContent();
773 void OnDidRunInsecureContent(const std::string& security_origin,
774 const GURL& target_url);
775 void OnDocumentLoadedInFrame();
776 void OnDidFinishLoad(const GURL& url);
777 void OnDidStartLoading(bool to_different_document);
778 void OnDidStopLoading();
779 void OnDidChangeLoadProgress(double load_progress);
780 void OnGoToEntryAtOffset(int offset);
781 void OnUpdateZoomLimits(int minimum_percent,
782 int maximum_percent);
783 void OnEnumerateDirectory(int request_id, const base::FilePath& path);
785 void OnRegisterProtocolHandler(const std::string& protocol,
787 const base::string16& title,
789 void OnUnregisterProtocolHandler(const std::string& protocol,
792 void OnFindReply(int request_id,
793 int number_of_matches,
794 const gfx::Rect& selection_rect,
795 int active_match_ordinal,
797 #if defined(OS_ANDROID)
798 void OnFindMatchRectsReply(int version,
799 const std::vector<gfx::RectF>& rects,
800 const gfx::RectF& active_rect);
802 void OnOpenDateTimeDialog(
803 const ViewHostMsg_DateTimeDialogValue_Params& value);
805 void OnPepperPluginHung(int plugin_child_id,
806 const base::FilePath& path,
808 void OnPluginCrashed(const base::FilePath& plugin_path,
809 base::ProcessId plugin_pid);
810 void OnDomOperationResponse(const std::string& json_string,
812 void OnAppCacheAccessed(const GURL& manifest_url, bool blocked_by_policy);
813 void OnOpenColorChooser(int color_chooser_id,
815 const std::vector<ColorSuggestion>& suggestions);
816 void OnEndColorChooser(int color_chooser_id);
817 void OnSetSelectedColorInColorChooser(int color_chooser_id, SkColor color);
818 void OnWebUISend(const GURL& source_url,
819 const std::string& name,
820 const base::ListValue& args);
821 void OnRequestPpapiBrokerPermission(int routing_id,
823 const base::FilePath& plugin_path);
824 void OnBrowserPluginMessage(const IPC::Message& message);
825 void OnDidDownloadImage(int id,
826 int http_status_code,
827 const GURL& image_url,
828 const std::vector<SkBitmap>& bitmaps,
829 const std::vector<gfx::Size>& original_bitmap_sizes);
830 void OnUpdateFaviconURL(const std::vector<FaviconURL>& candidates);
831 void OnFirstVisuallyNonEmptyPaint();
832 void OnMediaPlayingNotification(int64 player_cookie,
835 void OnMediaPausedNotification(int64 player_cookie);
836 void OnShowValidationMessage(const gfx::Rect& anchor_in_root_view,
837 const base::string16& main_text,
838 const base::string16& sub_text);
839 void OnHideValidationMessage();
840 void OnMoveValidationMessage(const gfx::Rect& anchor_in_root_view);
842 // Called by derived classes to indicate that we're no longer waiting for a
843 // response. This won't actually update the throbber, but it will get picked
844 // up at the next animation step if the throbber is going.
845 void SetNotWaitingForResponse() { waiting_for_response_ = false; }
847 // Navigation helpers --------------------------------------------------------
849 // These functions are helpers for Navigate() and DidNavigate().
851 // Handles post-navigation tasks in DidNavigate AFTER the entry has been
852 // committed to the navigation controller. Note that the navigation entry is
853 // not provided since it may be invalid/changed after being committed. The
854 // current navigation entry is in the NavigationController at this point.
856 // If our controller was restored, update the max page ID associated with the
857 // given RenderViewHost to be larger than the number of restored entries.
858 // This is called in CreateRenderView before any navigations in the RenderView
859 // have begun, to prevent any races in updating RenderView::next_page_id.
860 void UpdateMaxPageIDIfNecessary(RenderViewHost* rvh);
862 // Saves the given title to the navigation entry and does associated work. It
863 // will update history and the view for the new title, and also synthesize
864 // titles for file URLs that have none (so we require that the URL of the
865 // entry already be set).
867 // This is used as the backend for state updates, which include a new title,
868 // or the dedicated set title message. It returns true if the new title is
869 // different and was therefore updated.
870 bool UpdateTitleForEntry(NavigationEntryImpl* entry,
871 const base::string16& title);
873 // Recursively creates swapped out RenderViews for this tab's opener chain
874 // (including this tab) in the given SiteInstance, allowing other tabs to send
875 // cross-process JavaScript calls to their opener(s). Returns the route ID of
876 // this tab's RenderView for |instance|.
877 int CreateOpenerRenderViews(SiteInstance* instance);
879 // Helper for CreateNewWidget/CreateNewFullscreenWidget.
880 void CreateNewWidget(int render_process_id,
883 blink::WebPopupType popup_type);
885 // Helper for ShowCreatedWidget/ShowCreatedFullscreenWidget.
886 void ShowCreatedWidget(int route_id,
888 const gfx::Rect& initial_pos);
890 // Finds the new RenderWidgetHost and returns it. Note that this can only be
891 // called once as this call also removes it from the internal map.
892 RenderWidgetHostView* GetCreatedWidget(int route_id);
894 // Finds the new WebContentsImpl by route_id, initializes it for
895 // renderer-initiated creation, and returns it. Note that this can only be
896 // called once as this call also removes it from the internal map.
897 WebContentsImpl* GetCreatedWindow(int route_id);
899 // Tracking loading progress -------------------------------------------------
901 // Resets the tracking state of the current load.
902 void ResetLoadProgressState();
904 // Calculates the progress of the current load and notifies the delegate.
905 void SendLoadProgressChanged();
907 // Called once when the last frame on the page has stopped loading.
908 void DidStopLoading(RenderFrameHost* render_frame_host);
910 // Misc non-view stuff -------------------------------------------------------
912 // Helper functions for sending notifications.
913 void NotifyViewSwapped(RenderViewHost* old_host, RenderViewHost* new_host);
914 void NotifyFrameSwapped(RenderFrameHost* old_host, RenderFrameHost* new_host);
915 void NotifyDisconnected();
917 void SetEncoding(const std::string& encoding);
919 // TODO(creis): This should take in a FrameTreeNode to know which node's
920 // render manager to return. For now, we just return the root's.
921 RenderFrameHostManager* GetRenderManager() const;
923 RenderViewHostImpl* GetRenderViewHostImpl();
925 // Removes browser plugin embedder if there is one.
926 void RemoveBrowserPluginEmbedder();
928 // Clear |render_frame_host|'s tracking entry for its power save blockers.
929 void ClearPowerSaveBlockers(RenderFrameHost* render_frame_host);
931 // Clear tracking entries for all RenderFrameHosts, clears
932 // |audio_power_save_blocker_| and |video_power_save_blocker_|.
933 void ClearAllPowerSaveBlockers();
935 // Creates an audio or video power save blocker respectively.
936 void CreateAudioPowerSaveBlocker();
937 void CreateVideoPowerSaveBlocker();
939 // Releases the audio power save blockers if |active_audio_players_| is empty.
940 // Likewise, releases the video power save blockers if |active_video_players_|
942 void MaybeReleasePowerSaveBlockers();
944 // Helper function to invoke WebContentsDelegate::GetSizeForNewRenderView().
945 gfx::Size GetSizeForNewRenderView();
947 void OnFrameRemoved(RenderFrameHost* render_frame_host);
949 // Helper method that's called whenever |preferred_size_| or
950 // |preferred_size_for_capture_| changes, to propagate the new value to the
952 void OnPreferredSizeChanged(const gfx::Size& old_size);
954 // Helper methods for adding or removing player entries in |player_map| under
955 // the key |render_frame_message_source_|.
956 typedef std::vector<int64> PlayerList;
957 typedef std::map<uintptr_t, PlayerList> ActiveMediaPlayerMap;
958 void AddMediaPlayerEntry(int64 player_cookie,
959 ActiveMediaPlayerMap* player_map);
960 void RemoveMediaPlayerEntry(int64 player_cookie,
961 ActiveMediaPlayerMap* player_map);
962 // Removes all entries from |player_map| for |render_frame_host|.
963 void RemoveAllMediaPlayerEntries(RenderFrameHost* render_frame_host,
964 ActiveMediaPlayerMap* player_map);
966 // Adds/removes a callback called on creation of each new WebContents.
967 // Deprecated, about to remove.
968 static void AddCreatedCallback(const CreatedCallback& callback);
969 static void RemoveCreatedCallback(const CreatedCallback& callback);
971 // Data for core operation ---------------------------------------------------
973 // Delegate for notifying our owner about stuff. Not owned by us.
974 WebContentsDelegate* delegate_;
976 // Handles the back/forward list and loading.
977 NavigationControllerImpl controller_;
979 // The corresponding view.
980 scoped_ptr<WebContentsView> view_;
982 // The view of the RVHD. Usually this is our WebContentsView implementation,
983 // but if an embedder uses a different WebContentsView, they'll need to
985 RenderViewHostDelegateView* render_view_host_delegate_view_;
987 // Tracks created WebContentsImpl objects that have not been shown yet. They
988 // are identified by the route ID passed to CreateNewWindow.
989 typedef std::map<int, WebContentsImpl*> PendingContents;
990 PendingContents pending_contents_;
992 // These maps hold on to the widgets that we created on behalf of the renderer
993 // that haven't shown yet.
994 typedef std::map<int, RenderWidgetHostView*> PendingWidgetViews;
995 PendingWidgetViews pending_widget_views_;
997 typedef std::map<WebContentsImpl*, DestructionObserver*> DestructionObservers;
998 DestructionObservers destruction_observers_;
1000 // A list of observers notified when page state changes. Weak references.
1001 // This MUST be listed above frame_tree_ since at destruction time the
1002 // latter might cause RenderViewHost's destructor to call us and we might use
1003 // the observer list then.
1004 ObserverList<WebContentsObserver> observers_;
1006 // The tab that opened this tab, if any. Will be set to null if the opener
1008 WebContentsImpl* opener_;
1010 // True if this tab was opened by another tab. This is not unset if the opener
1012 bool created_with_opener_;
1015 gfx::NativeViewAccessible accessible_parent_;
1018 // Helper classes ------------------------------------------------------------
1020 // Tracking variables and associated power save blockers for media playback.
1021 ActiveMediaPlayerMap active_audio_players_;
1022 ActiveMediaPlayerMap active_video_players_;
1023 scoped_ptr<PowerSaveBlocker> audio_power_save_blocker_;
1024 scoped_ptr<PowerSaveBlocker> video_power_save_blocker_;
1026 // Manages the frame tree of the page and process swaps in each node.
1027 FrameTree frame_tree_;
1029 // SavePackage, lazily created.
1030 scoped_refptr<SavePackage> save_package_;
1032 // Data for loading state ----------------------------------------------------
1034 // Indicates whether we're currently loading a resource.
1037 // Indicates whether the current load is to a different document. Only valid
1038 // if is_loading_ is true.
1039 bool is_load_to_different_document_;
1041 // Indicates if the tab is considered crashed.
1042 base::TerminationStatus crashed_status_;
1043 int crashed_error_code_;
1045 // Whether this WebContents is waiting for a first-response for the
1046 // main resource of the page. This controls whether the throbber state is
1047 // "waiting" or "loading."
1048 bool waiting_for_response_;
1050 // Map of SiteInstance ID to max page ID for this tab. A page ID is specific
1051 // to a given tab and SiteInstance, and must be valid for the lifetime of the
1053 std::map<int32, int32> max_page_ids_;
1055 // The current load state and the URL associated with it.
1056 net::LoadStateWithParam load_state_;
1057 base::string16 load_state_host_;
1059 // LoadingProgressMap maps FrameTreeNode IDs to a double representing that
1060 // frame's completion (from 0 to 1).
1061 typedef base::hash_map<int64, double> LoadingProgressMap;
1062 LoadingProgressMap loading_progresses_;
1063 double loading_total_progress_;
1065 base::TimeTicks loading_last_progress_update_;
1067 // Counter to track how many frames have sent start notifications but not
1068 // stop notifications.
1069 int loading_frames_in_progress_;
1071 // Upload progress, for displaying in the status bar.
1072 // Set to zero when there is no significant upload happening.
1073 uint64 upload_size_;
1074 uint64 upload_position_;
1076 // Data for current page -----------------------------------------------------
1078 // When a title cannot be taken from any entry, this title will be used.
1079 base::string16 page_title_when_no_navigation_entry_;
1081 // When a navigation occurs, we record its contents MIME type. It can be
1082 // used to check whether we can do something for some special contents.
1083 std::string contents_mime_type_;
1085 // The last reported character encoding, not canonicalized.
1086 std::string last_reported_encoding_;
1088 // The canonicalized character encoding.
1089 std::string canonical_encoding_;
1091 // True if this is a secure page which displayed insecure content.
1092 bool displayed_insecure_content_;
1094 // Whether the initial empty page has been accessed by another page, making it
1095 // unsafe to show the pending URL. Usually false unless another window tries
1096 // to modify the blank page. Always false after the first commit.
1097 bool has_accessed_initial_document_;
1099 // Data for misc internal state ----------------------------------------------
1101 // When > 0, the WebContents is currently being captured (e.g., for
1102 // screenshots or mirroring); and the underlying RenderWidgetHost should not
1103 // be told it is hidden.
1104 int capturer_count_;
1106 // Tracks whether RWHV should be visible once capturer_count_ becomes zero.
1107 bool should_normally_be_visible_;
1109 // See getter above.
1110 bool is_being_destroyed_;
1112 // Indicates whether we should notify about disconnection of this
1113 // WebContentsImpl. This is used to ensure disconnection notifications only
1114 // happen if a connection notification has happened and that they happen only
1116 bool notify_disconnection_;
1118 // Pointer to the JavaScript dialog manager, lazily assigned. Used because the
1119 // delegate of this WebContentsImpl is nulled before its destructor is called.
1120 JavaScriptDialogManager* dialog_manager_;
1122 // Set to true when there is an active "before unload" dialog. When true,
1123 // we've forced the throbber to start in Navigate, and we need to remember to
1124 // turn it off in OnJavaScriptMessageBoxClosed if the navigation is canceled.
1125 bool is_showing_before_unload_dialog_;
1127 // Settings that get passed to the renderer process.
1128 RendererPreferences renderer_preferences_;
1130 // The time that this WebContents was last made active. The initial value is
1131 // the WebContents creation time.
1132 base::TimeTicks last_active_time_;
1134 // See description above setter.
1135 bool closed_by_user_gesture_;
1137 // Minimum/maximum zoom percent.
1138 int minimum_zoom_percent_;
1139 int maximum_zoom_percent_;
1141 // The raw accumulated zoom value and the actual zoom increments made for an
1142 // an in-progress pinch gesture.
1143 float totalPinchGestureAmount_;
1144 int currentPinchZoomStepDelta_;
1146 // The intrinsic size of the page.
1147 gfx::Size preferred_size_;
1149 // The preferred size for content screen capture. When |capturer_count_| > 0,
1150 // this overrides |preferred_size_|.
1151 gfx::Size preferred_size_for_capture_;
1153 #if defined(OS_ANDROID)
1154 // Date time chooser opened by this tab.
1155 // Only used in Android since all other platforms use a multi field UI.
1156 scoped_ptr<DateTimeChooserAndroid> date_time_chooser_;
1159 // Holds information about a current color chooser dialog, if one is visible.
1160 struct ColorChooserInfo {
1161 ColorChooserInfo(int render_process_id,
1162 int render_frame_id,
1163 ColorChooser* chooser,
1165 ~ColorChooserInfo();
1167 int render_process_id;
1168 int render_frame_id;
1170 // Color chooser that was opened by this tab.
1171 scoped_ptr<ColorChooser> chooser;
1173 // A unique identifier for the current color chooser. Identifiers are
1174 // unique across a renderer process. This avoids race conditions in
1175 // synchronizing the browser and renderer processes. For example, if a
1176 // renderer closes one chooser and opens another, and simultaneously the
1177 // user picks a color in the first chooser, the IDs can be used to drop the
1178 // "chose a color" message rather than erroneously tell the renderer that
1179 // the user picked a color in the second chooser.
1183 scoped_ptr<ColorChooserInfo> color_chooser_info_;
1185 // Manages the embedder state for browser plugins, if this WebContents is an
1186 // embedder; NULL otherwise.
1187 scoped_ptr<BrowserPluginEmbedder> browser_plugin_embedder_;
1188 // Manages the guest state for browser plugin, if this WebContents is a guest;
1190 scoped_ptr<BrowserPluginGuest> browser_plugin_guest_;
1192 // This must be at the end, or else we might get notifications and use other
1193 // member variables that are gone.
1194 NotificationRegistrar registrar_;
1196 // Used during IPC message dispatching from the RenderView/RenderFrame so that
1197 // the handlers can get a pointer to the RVH through which the message was
1199 RenderViewHost* render_view_message_source_;
1200 RenderFrameHost* render_frame_message_source_;
1202 // All live RenderWidgetHostImpls that are created by this object and may
1204 std::set<RenderWidgetHostImpl*> created_widgets_;
1206 // Routing id of the shown fullscreen widget or MSG_ROUTING_NONE otherwise.
1207 int fullscreen_widget_routing_id_;
1209 // At the time the fullscreen widget was being shut down, did it have focus?
1210 // This is used to restore focus to the WebContentsView after both: 1) the
1211 // fullscreen widget is destroyed, and 2) the WebContentsDelegate has
1212 // completed making layout changes to effect an exit from fullscreen mode.
1213 bool fullscreen_widget_had_focus_at_shutdown_;
1215 // Maps the ids of pending image downloads to their callbacks
1216 typedef std::map<int, ImageDownloadCallback> ImageDownloadMap;
1217 ImageDownloadMap image_download_map_;
1219 // Whether this WebContents is responsible for displaying a subframe in a
1220 // different process from its parent page.
1223 // Whether overscroll should be unconditionally disabled.
1224 bool force_disable_overscroll_content_;
1226 // Whether the last JavaScript dialog shown was suppressed. Used for testing.
1227 bool last_dialog_suppressed_;
1229 scoped_ptr<GeolocationDispatcherHost> geolocation_dispatcher_host_;
1231 scoped_ptr<MidiDispatcherHost> midi_dispatcher_host_;
1233 scoped_ptr<ScreenOrientationDispatcherHost>
1234 screen_orientation_dispatcher_host_;
1236 scoped_ptr<ManifestManagerHost> manifest_manager_host_;
1238 // The accessibility mode for all frames. This is queried when each frame
1239 // is created, and broadcast to all frames when it changes.
1240 AccessibilityMode accessibility_mode_;
1242 // Monitors power levels for audio streams associated with this WebContents.
1243 AudioStreamMonitor audio_stream_monitor_;
1245 // Created on-demand to mute all audio output from this WebContents.
1246 scoped_ptr<WebContentsAudioMuter> audio_muter_;
1248 base::WeakPtrFactory<WebContentsImpl> loading_weak_factory_;
1250 DISALLOW_COPY_AND_ASSIGN(WebContentsImpl);
1253 } // namespace content
1255 #endif // CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_IMPL_H_