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_view_host_impl.h"
28 #include "content/browser/renderer_host/render_widget_host_delegate.h"
29 #include "content/common/accessibility_mode_enums.h"
30 #include "content/common/content_export.h"
31 #include "content/public/browser/color_chooser.h"
32 #include "content/public/browser/notification_observer.h"
33 #include "content/public/browser/notification_registrar.h"
34 #include "content/public/browser/web_contents.h"
35 #include "content/public/common/renderer_preferences.h"
36 #include "content/public/common/resource_type.h"
37 #include "content/public/common/three_d_api_types.h"
38 #include "net/base/load_states.h"
39 #include "net/http/http_response_headers.h"
40 #include "third_party/WebKit/public/web/WebDragOperation.h"
41 #include "ui/base/page_transition_types.h"
42 #include "ui/gfx/geometry/rect_f.h"
43 #include "ui/gfx/geometry/size.h"
45 struct BrowserPluginHostMsg_ResizeGuest_Params
;
46 struct ViewHostMsg_DateTimeDialogValue_Params
;
49 class BrowserPluginEmbedder
;
50 class BrowserPluginGuest
;
51 class BrowserPluginGuestManager
;
52 class DateTimeChooserAndroid
;
54 class GeolocationServiceContext
;
55 class InterstitialPageImpl
;
56 class JavaScriptDialogManager
;
57 class ManifestManagerHost
;
58 class MediaWebContentsObserver
;
59 class PluginContentOriginWhitelist
;
60 class PowerSaveBlocker
;
62 class RenderViewHostDelegateView
;
63 class RenderWidgetHostImpl
;
64 class RenderWidgetHostInputEventRouter
;
66 class ScreenOrientationDispatcherHost
;
68 class TestWebContents
;
69 class WebContentsAudioMuter
;
70 class WebContentsDelegate
;
71 class WebContentsImpl
;
72 class WebContentsObserver
;
73 class WebContentsView
;
74 class WebContentsViewDelegate
;
75 struct AXEventNotificationDetails
;
76 struct ColorSuggestion
;
78 struct LoadNotificationDetails
;
79 struct ResourceRedirectDetails
;
80 struct ResourceRequestDetails
;
82 #if defined(OS_ANDROID)
83 class WebContentsAndroid
;
86 // Factory function for the implementations that content knows about. Takes
87 // ownership of |delegate|.
88 WebContentsView
* CreateWebContentsView(
89 WebContentsImpl
* web_contents
,
90 WebContentsViewDelegate
* delegate
,
91 RenderViewHostDelegateView
** render_view_host_delegate_view
);
93 class CONTENT_EXPORT WebContentsImpl
94 : public NON_EXPORTED_BASE(WebContents
),
95 public NON_EXPORTED_BASE(RenderFrameHostDelegate
),
96 public RenderViewHostDelegate
,
97 public RenderWidgetHostDelegate
,
98 public RenderFrameHostManager::Delegate
,
99 public NotificationObserver
,
100 public NON_EXPORTED_BASE(NavigationControllerDelegate
),
101 public NON_EXPORTED_BASE(NavigatorDelegate
) {
105 ~WebContentsImpl() override
;
107 static WebContentsImpl
* CreateWithOpener(
108 const WebContents::CreateParams
& params
,
109 FrameTreeNode
* opener
);
111 static std::vector
<WebContentsImpl
*> GetAllWebContents();
113 static WebContentsImpl
* FromFrameTreeNode(FrameTreeNode
* frame_tree_node
);
115 // Creates a swapped out RenderView. This is used by the browser plugin to
116 // create a swapped out RenderView in the embedder render process for the
117 // guest, to expose the guest's window object to the embedder.
118 // This returns the routing ID of the newly created swapped out RenderView.
119 int CreateSwappedOutRenderView(SiteInstance
* instance
);
121 // Complex initialization here. Specifically needed to avoid having
122 // members call back into our virtual functions in the constructor.
123 virtual void Init(const WebContents::CreateParams
& params
);
125 // Returns the SavePackage which manages the page saving job. May be NULL.
126 SavePackage
* save_package() const { return save_package_
.get(); }
128 #if defined(OS_ANDROID)
129 // In Android WebView, the RenderView needs created even there is no
130 // navigation entry, this allows Android WebViews to use
131 // javascript: URLs that load into the DOMWindow before the first page
132 // load. This is not safe to do in any context that a web page could get a
133 // reference to the DOMWindow before the first page load.
134 bool CreateRenderViewForInitialEmptyDocument();
137 // Expose the render manager for testing.
138 // TODO(creis): Remove this now that we can get to it via FrameTreeNode.
139 RenderFrameHostManager
* GetRenderManagerForTesting();
141 // Returns guest browser plugin object, or NULL if this WebContents is not a
143 BrowserPluginGuest
* GetBrowserPluginGuest() const;
145 // Sets a BrowserPluginGuest object for this WebContents. If this WebContents
146 // has a BrowserPluginGuest then that implies that it is being hosted by
147 // a BrowserPlugin object in an embedder renderer process.
148 void SetBrowserPluginGuest(BrowserPluginGuest
* guest
);
150 // Returns embedder browser plugin object, or NULL if this WebContents is not
152 BrowserPluginEmbedder
* GetBrowserPluginEmbedder() const;
154 // Creates a BrowserPluginEmbedder object for this WebContents if one doesn't
156 void CreateBrowserPluginEmbedderIfNecessary();
158 // Cancels modal dialogs in this WebContents, as well as in any browser
159 // plugins it is hosting.
160 void CancelActiveAndPendingDialogs();
162 // Gets the current fullscreen render widget's routing ID. Returns
163 // MSG_ROUTING_NONE when there is no fullscreen render widget.
164 int GetFullscreenWidgetRoutingID() const;
166 // Invoked when visible SSL state (as defined by SSLStatus) changes.
167 void DidChangeVisibleSSLState();
169 // Informs the render view host and the BrowserPluginEmbedder, if present, of
170 // a Drag Source End.
171 void DragSourceEndedAt(int client_x
, int client_y
, int screen_x
,
172 int screen_y
, blink::WebDragOperation operation
);
174 // A response has been received for a resource request.
175 void DidGetResourceResponseStart(
176 const ResourceRequestDetails
& details
);
178 // A redirect was received while requesting a resource.
179 void DidGetRedirectForResourceRequest(
180 RenderFrameHost
* render_frame_host
,
181 const ResourceRedirectDetails
& details
);
183 // Notify observers that the web contents has been focused.
184 void NotifyWebContentsFocused();
186 WebContentsView
* GetView() const;
188 ScreenOrientationDispatcherHost
* screen_orientation_dispatcher_host() {
189 return screen_orientation_dispatcher_host_
.get();
192 bool should_normally_be_visible() { return should_normally_be_visible_
; }
194 // Indicate if the window has been occluded, and pass this to the views, only
195 // if there is no active capture going on (otherwise it is dropped on the
198 void WasUnOccluded();
200 // Broadcasts the mode change to all frames.
201 void SetAccessibilityMode(AccessibilityMode mode
);
203 // Adds the given accessibility mode to the current accessibility mode
205 void AddAccessibilityMode(AccessibilityMode mode
);
207 // Removes the given accessibility mode from the current accessibility
208 // mode bitmap, managing the bits that are shared with other modes such
209 // that a bit will only be turned off when all modes that depend on it
210 // have been removed.
211 void RemoveAccessibilityMode(AccessibilityMode mode
);
213 // Request a one-time snapshot of the accessibility tree without changing
214 // the accessibility mode.
215 using AXTreeSnapshotCallback
=
216 base::Callback
<void(const ui::AXTreeUpdate
<ui::AXNodeData
>&)>;
217 void RequestAXTreeSnapshot(AXTreeSnapshotCallback callback
);
219 // WebContents ------------------------------------------------------
220 WebContentsDelegate
* GetDelegate() override
;
221 void SetDelegate(WebContentsDelegate
* delegate
) override
;
222 NavigationControllerImpl
& GetController() override
;
223 const NavigationControllerImpl
& GetController() const override
;
224 BrowserContext
* GetBrowserContext() const override
;
225 const GURL
& GetURL() const override
;
226 const GURL
& GetVisibleURL() const override
;
227 const GURL
& GetLastCommittedURL() const override
;
228 RenderProcessHost
* GetRenderProcessHost() const override
;
229 RenderFrameHostImpl
* GetMainFrame() override
;
230 RenderFrameHostImpl
* GetFocusedFrame() override
;
232 const base::Callback
<void(RenderFrameHost
*)>& on_frame
) override
;
233 void SendToAllFrames(IPC::Message
* message
) override
;
234 RenderViewHostImpl
* GetRenderViewHost() const override
;
235 int GetRoutingID() const override
;
236 RenderWidgetHostView
* GetRenderWidgetHostView() const override
;
237 void ClosePage() override
;
238 RenderWidgetHostView
* GetFullscreenRenderWidgetHostView() const override
;
239 SkColor
GetThemeColor() const override
;
240 WebUI
* CreateSubframeWebUI(const GURL
& url
,
241 const std::string
& frame_name
) override
;
242 WebUI
* GetWebUI() const override
;
243 WebUI
* GetCommittedWebUI() const override
;
244 void SetUserAgentOverride(const std::string
& override
) override
;
245 const std::string
& GetUserAgentOverride() const override
;
246 void EnableTreeOnlyAccessibilityMode() override
;
247 bool IsTreeOnlyAccessibilityModeForTesting() const override
;
248 bool IsFullAccessibilityModeForTesting() const override
;
250 void SetParentNativeViewAccessible(
251 gfx::NativeViewAccessible accessible_parent
) override
;
253 const base::string16
& GetTitle() const override
;
254 int32
GetMaxPageID() override
;
255 int32
GetMaxPageIDForSiteInstance(SiteInstance
* site_instance
) override
;
256 SiteInstanceImpl
* GetSiteInstance() const override
;
257 SiteInstanceImpl
* GetPendingSiteInstance() const override
;
258 bool IsLoading() const override
;
259 bool IsLoadingToDifferentDocument() const override
;
260 bool IsWaitingForResponse() const override
;
261 const net::LoadStateWithParam
& GetLoadState() const override
;
262 const base::string16
& GetLoadStateHost() const override
;
263 uint64
GetUploadSize() const override
;
264 uint64
GetUploadPosition() const override
;
265 std::set
<GURL
> GetSitesInTab() const override
;
266 const std::string
& GetEncoding() const override
;
267 bool DisplayedInsecureContent() const override
;
268 void IncrementCapturerCount(const gfx::Size
& capture_size
) override
;
269 void DecrementCapturerCount() override
;
270 int GetCapturerCount() const override
;
271 bool IsAudioMuted() const override
;
272 void SetAudioMuted(bool mute
) override
;
273 bool IsCrashed() const override
;
274 void SetIsCrashed(base::TerminationStatus status
, int error_code
) override
;
275 base::TerminationStatus
GetCrashedStatus() const override
;
276 bool IsBeingDestroyed() const override
;
277 void NotifyNavigationStateChanged(InvalidateTypes changed_flags
) override
;
278 base::TimeTicks
GetLastActiveTime() const override
;
279 void SetLastActiveTime(base::TimeTicks last_active_time
) override
;
280 void WasShown() override
;
281 void WasHidden() override
;
282 bool NeedToFireBeforeUnload() override
;
283 void DispatchBeforeUnload(bool for_cross_site_transition
) override
;
284 void AttachToOuterWebContentsFrame(
285 WebContents
* outer_web_contents
,
286 RenderFrameHost
* outer_contents_frame
) override
;
287 void Stop() override
;
288 WebContents
* Clone() override
;
289 void ReloadFocusedFrame(bool ignore_cache
) override
;
290 void Undo() override
;
291 void Redo() override
;
293 void Copy() override
;
294 void CopyToFindPboard() override
;
295 void Paste() override
;
296 void PasteAndMatchStyle() override
;
297 void Delete() override
;
298 void SelectAll() override
;
299 void Unselect() override
;
300 void Replace(const base::string16
& word
) override
;
301 void ReplaceMisspelling(const base::string16
& word
) override
;
302 void NotifyContextMenuClosed(
303 const CustomContextMenuContext
& context
) override
;
304 void ExecuteCustomContextMenuCommand(
306 const CustomContextMenuContext
& context
) override
;
307 gfx::NativeView
GetNativeView() override
;
308 gfx::NativeView
GetContentNativeView() override
;
309 gfx::NativeWindow
GetTopLevelNativeWindow() override
;
310 gfx::Rect
GetContainerBounds() override
;
311 gfx::Rect
GetViewBounds() override
;
312 DropData
* GetDropData() override
;
313 void Focus() override
;
314 void SetInitialFocus() override
;
315 void StoreFocus() override
;
316 void RestoreFocus() override
;
317 void FocusThroughTabTraversal(bool reverse
) override
;
318 bool ShowingInterstitialPage() const override
;
319 InterstitialPage
* GetInterstitialPage() const override
;
320 bool IsSavable() override
;
321 void OnSavePage() override
;
322 bool SavePage(const base::FilePath
& main_file
,
323 const base::FilePath
& dir_path
,
324 SavePageType save_type
) override
;
325 void SaveFrame(const GURL
& url
, const Referrer
& referrer
) override
;
326 void SaveFrameWithHeaders(const GURL
& url
,
327 const Referrer
& referrer
,
328 const std::string
& headers
) override
;
329 void GenerateMHTML(const base::FilePath
& file
,
330 const base::Callback
<void(int64
)>& callback
) override
;
331 const std::string
& GetContentsMimeType() const override
;
332 bool WillNotifyDisconnection() const override
;
333 void SetOverrideEncoding(const std::string
& encoding
) override
;
334 void ResetOverrideEncoding() override
;
335 RendererPreferences
* GetMutableRendererPrefs() override
;
336 void Close() override
;
337 void SystemDragEnded() override
;
338 void UserGestureDone() override
;
339 void SetClosedByUserGesture(bool value
) override
;
340 bool GetClosedByUserGesture() const override
;
341 void ViewSource() override
;
342 void ViewFrameSource(const GURL
& url
, const PageState
& page_state
) override
;
343 int GetMinimumZoomPercent() const override
;
344 int GetMaximumZoomPercent() const override
;
345 void ResetPageScale() override
;
346 gfx::Size
GetPreferredSize() const override
;
347 bool GotResponseToLockMouseRequest(bool allowed
) override
;
348 bool HasOpener() const override
;
349 WebContentsImpl
* GetOpener() const override
;
350 void DidChooseColorInColorChooser(SkColor color
) override
;
351 void DidEndColorChooser() override
;
352 int DownloadImage(const GURL
& url
,
354 uint32_t max_bitmap_size
,
356 const ImageDownloadCallback
& callback
) override
;
357 bool IsSubframe() const override
;
358 void Find(int request_id
,
359 const base::string16
& search_text
,
360 const blink::WebFindOptions
& options
) override
;
361 void StopFinding(StopFindAction action
) override
;
362 void InsertCSS(const std::string
& css
) override
;
363 bool WasRecentlyAudible() override
;
364 void GetManifest(const GetManifestCallback
&) override
;
365 void ExitFullscreen() override
;
366 void ResumeLoadingCreatedWebContents() override
;
367 #if defined(OS_ANDROID)
368 void OnMediaSessionStateChanged();
369 void ResumeMediaSession() override
;
370 void SuspendMediaSession() override
;
371 void StopMediaSession() override
;
373 base::android::ScopedJavaLocalRef
<jobject
> GetJavaWebContents() override
;
374 virtual WebContentsAndroid
* GetWebContentsAndroid();
375 #elif defined(OS_MACOSX)
376 void SetAllowOtherViews(bool allow
) override
;
377 bool GetAllowOtherViews() override
;
380 // Implementation of PageNavigator.
381 WebContents
* OpenURL(const OpenURLParams
& params
) override
;
383 // Implementation of IPC::Sender.
384 bool Send(IPC::Message
* message
) override
;
386 // RenderFrameHostDelegate ---------------------------------------------------
387 bool OnMessageReceived(RenderFrameHost
* render_frame_host
,
388 const IPC::Message
& message
) override
;
389 const GURL
& GetMainFrameLastCommittedURL() const override
;
390 void RenderFrameCreated(RenderFrameHost
* render_frame_host
) override
;
391 void RenderFrameDeleted(RenderFrameHost
* render_frame_host
) override
;
392 void SwappedOut(RenderFrameHost
* render_frame_host
) override
;
393 void ShowContextMenu(RenderFrameHost
* render_frame_host
,
394 const ContextMenuParams
& params
) override
;
395 void RunJavaScriptMessage(RenderFrameHost
* render_frame_host
,
396 const base::string16
& message
,
397 const base::string16
& default_prompt
,
398 const GURL
& frame_url
,
399 JavaScriptMessageType type
,
400 IPC::Message
* reply_msg
) override
;
401 void RunBeforeUnloadConfirm(RenderFrameHost
* render_frame_host
,
402 const base::string16
& message
,
404 IPC::Message
* reply_msg
) override
;
405 void DidAccessInitialDocument() override
;
406 void DidChangeName(RenderFrameHost
* render_frame_host
,
407 const std::string
& name
) override
;
408 void DocumentOnLoadCompleted(RenderFrameHost
* render_frame_host
) override
;
409 void UpdateTitle(RenderFrameHost
* render_frame_host
,
411 const base::string16
& title
,
412 base::i18n::TextDirection title_direction
) override
;
413 void UpdateEncoding(RenderFrameHost
* render_frame_host
,
414 const std::string
& encoding
) override
;
415 WebContents
* GetAsWebContents() override
;
416 bool IsNeverVisible() override
;
417 AccessibilityMode
GetAccessibilityMode() const override
;
418 void AccessibilityEventReceived(
419 const std::vector
<AXEventNotificationDetails
>& details
) override
;
420 RenderFrameHost
* GetGuestByInstanceID(
421 RenderFrameHost
* render_frame_host
,
422 int browser_plugin_instance_id
) override
;
423 GeolocationServiceContext
* GetGeolocationServiceContext() override
;
424 void EnterFullscreenMode(const GURL
& origin
) override
;
425 void ExitFullscreenMode() override
;
426 bool ShouldRouteMessageEvent(
427 RenderFrameHost
* target_rfh
,
428 SiteInstance
* source_site_instance
) const override
;
429 void EnsureOpenerProxiesExist(RenderFrameHost
* source_rfh
) override
;
431 gfx::NativeViewAccessible
GetParentNativeViewAccessible() override
;
434 // RenderViewHostDelegate ----------------------------------------------------
435 RenderViewHostDelegateView
* GetDelegateView() override
;
436 bool OnMessageReceived(RenderViewHost
* render_view_host
,
437 const IPC::Message
& message
) override
;
438 // RenderFrameHostDelegate has the same method, so list it there because this
439 // interface is going away.
440 // WebContents* GetAsWebContents() override;
441 gfx::Rect
GetRootWindowResizerRect() const override
;
442 void RenderViewCreated(RenderViewHost
* render_view_host
) override
;
443 void RenderViewReady(RenderViewHost
* render_view_host
) override
;
444 void RenderViewTerminated(RenderViewHost
* render_view_host
,
445 base::TerminationStatus status
,
446 int error_code
) override
;
447 void RenderViewDeleted(RenderViewHost
* render_view_host
) override
;
448 void UpdateState(RenderViewHost
* render_view_host
,
450 const PageState
& page_state
) override
;
451 void UpdateTargetURL(RenderViewHost
* render_view_host
,
452 const GURL
& url
) override
;
453 void Close(RenderViewHost
* render_view_host
) override
;
454 void RequestMove(const gfx::Rect
& new_bounds
) override
;
455 void DidCancelLoading() override
;
456 void DocumentAvailableInMainFrame(RenderViewHost
* render_view_host
) override
;
457 void RouteCloseEvent(RenderViewHost
* rvh
) override
;
458 bool AddMessageToConsole(int32 level
,
459 const base::string16
& message
,
461 const base::string16
& source_id
) override
;
462 RendererPreferences
GetRendererPrefs(
463 BrowserContext
* browser_context
) const override
;
464 void OnUserGesture() override
;
465 void OnIgnoredUIEvent() override
;
466 void RendererUnresponsive(RenderViewHost
* render_view_host
) override
;
467 void RendererResponsive(RenderViewHost
* render_view_host
) override
;
468 void LoadStateChanged(const GURL
& url
,
469 const net::LoadStateWithParam
& load_state
,
470 uint64 upload_position
,
471 uint64 upload_size
) override
;
472 void Activate() override
;
473 void Deactivate() override
;
474 void LostCapture() override
;
475 void RunFileChooser(RenderViewHost
* render_view_host
,
476 const FileChooserParams
& params
) override
;
477 bool IsFullscreenForCurrentTab() const override
;
478 blink::WebDisplayMode
GetDisplayMode() const override
;
479 void UpdatePreferredSize(const gfx::Size
& pref_size
) override
;
480 void ResizeDueToAutoResize(const gfx::Size
& new_size
) override
;
481 void RequestToLockMouse(bool user_gesture
,
482 bool last_unlocked_by_target
) override
;
483 void LostMouseLock() override
;
484 void CreateNewWindow(
485 SiteInstance
* source_site_instance
,
487 int main_frame_route_id
,
488 const ViewHostMsg_CreateWindow_Params
& params
,
489 SessionStorageNamespace
* session_storage_namespace
) override
;
490 void CreateNewWidget(int32 render_process_id
,
493 blink::WebPopupType popup_type
) override
;
494 void CreateNewFullscreenWidget(int32 render_process_id
,
496 int32 surface_id
) override
;
497 void ShowCreatedWindow(int route_id
,
498 WindowOpenDisposition disposition
,
499 const gfx::Rect
& initial_rect
,
500 bool user_gesture
) override
;
501 void ShowCreatedWidget(int route_id
, const gfx::Rect
& initial_rect
) override
;
502 void ShowCreatedFullscreenWidget(int route_id
) override
;
503 void RequestMediaAccessPermission(
504 const MediaStreamRequest
& request
,
505 const MediaResponseCallback
& callback
) override
;
506 bool CheckMediaAccessPermission(const GURL
& security_origin
,
507 MediaStreamType type
) override
;
508 SessionStorageNamespace
* GetSessionStorageNamespace(
509 SiteInstance
* instance
) override
;
510 SessionStorageNamespaceMap
GetSessionStorageNamespaceMap() override
;
511 FrameTree
* GetFrameTree() override
;
512 void SetIsVirtualKeyboardRequested(bool requested
) override
;
513 bool IsVirtualKeyboardRequested() override
;
515 // NavigatorDelegate ---------------------------------------------------------
517 void DidStartNavigation(NavigationHandle
* navigation_handle
) override
;
518 void DidRedirectNavigation(NavigationHandle
* navigation_handle
) override
;
519 void ReadyToCommitNavigation(NavigationHandle
* navigation_handle
) override
;
520 void DidCommitNavigation(NavigationHandle
* navigation_handle
) override
;
521 void DidFinishNavigation(NavigationHandle
* navigation_handle
) override
;
522 void DidStartProvisionalLoad(RenderFrameHostImpl
* render_frame_host
,
523 const GURL
& validated_url
,
525 bool is_iframe_srcdoc
) override
;
526 void DidFailProvisionalLoadWithError(
527 RenderFrameHostImpl
* render_frame_host
,
528 const FrameHostMsg_DidFailProvisionalLoadWithError_Params
& params
)
530 void DidFailLoadWithError(RenderFrameHostImpl
* render_frame_host
,
533 const base::string16
& error_description
,
534 bool was_ignored_by_handler
) override
;
535 void DidCommitProvisionalLoad(RenderFrameHostImpl
* render_frame_host
,
537 ui::PageTransition transition_type
) override
;
538 void DidNavigateMainFramePreCommit(bool navigation_is_within_page
) override
;
539 void DidNavigateMainFramePostCommit(
540 RenderFrameHostImpl
* render_frame_host
,
541 const LoadCommittedDetails
& details
,
542 const FrameHostMsg_DidCommitProvisionalLoad_Params
& params
) override
;
543 void DidNavigateAnyFramePostCommit(
544 RenderFrameHostImpl
* render_frame_host
,
545 const LoadCommittedDetails
& details
,
546 const FrameHostMsg_DidCommitProvisionalLoad_Params
& params
) override
;
547 void SetMainFrameMimeType(const std::string
& mime_type
) override
;
548 bool CanOverscrollContent() const override
;
549 void NotifyChangedNavigationState(InvalidateTypes changed_flags
) override
;
550 void AboutToNavigateRenderFrame(
551 RenderFrameHostImpl
* old_host
,
552 RenderFrameHostImpl
* new_host
) override
;
553 void DidStartNavigationToPendingEntry(
555 NavigationController::ReloadType reload_type
) override
;
556 void RequestOpenURL(RenderFrameHostImpl
* render_frame_host
,
557 const OpenURLParams
& params
) override
;
558 bool ShouldPreserveAbortedURLs() override
;
559 void DidStartLoading(FrameTreeNode
* frame_tree_node
,
560 bool to_different_document
) override
;
561 void DidStopLoading() override
;
562 void DidChangeLoadProgress() override
;
564 // RenderWidgetHostDelegate --------------------------------------------------
566 void RenderWidgetDeleted(RenderWidgetHostImpl
* render_widget_host
) override
;
567 void RenderWidgetGotFocus(RenderWidgetHostImpl
* render_widget_host
) override
;
568 void RenderWidgetWasResized(RenderWidgetHostImpl
* render_widget_host
,
569 bool width_changed
) override
;
570 void ScreenInfoChanged() override
;
571 bool PreHandleKeyboardEvent(const NativeWebKeyboardEvent
& event
,
572 bool* is_keyboard_shortcut
) override
;
573 void HandleKeyboardEvent(const NativeWebKeyboardEvent
& event
) override
;
574 bool HandleWheelEvent(const blink::WebMouseWheelEvent
& event
) override
;
575 bool PreHandleGestureEvent(const blink::WebGestureEvent
& event
) override
;
576 void DidSendScreenRects(RenderWidgetHostImpl
* rwh
) override
;
577 BrowserAccessibilityManager
* GetRootBrowserAccessibilityManager() override
;
578 BrowserAccessibilityManager
* GetOrCreateRootBrowserAccessibilityManager()
580 // The following 4 functions are already listed under WebContents overrides:
581 // void Cut() override;
582 // void Copy() override;
583 // void Paste() override;
584 // void SelectAll() override;
585 void MoveRangeSelectionExtent(const gfx::Point
& extent
) override
;
586 void SelectRange(const gfx::Point
& base
, const gfx::Point
& extent
) override
;
587 void AdjustSelectionByCharacterOffset(int start_adjust
, int end_adjust
)
589 RenderWidgetHostInputEventRouter
* GetInputEventRouter() override
;
591 // RenderFrameHostManager::Delegate ------------------------------------------
593 bool CreateRenderViewForRenderManager(
594 RenderViewHost
* render_view_host
,
595 int opener_frame_routing_id
,
596 int proxy_routing_id
,
597 const FrameReplicationState
& replicated_frame_state
) override
;
598 void CreateRenderWidgetHostViewForRenderManager(
599 RenderViewHost
* render_view_host
) override
;
600 bool CreateRenderFrameForRenderManager(
601 RenderFrameHost
* render_frame_host
,
602 int proxy_routing_id
,
603 int opener_routing_id
,
604 int parent_routing_id
,
605 int previous_sibling_routing_id
) override
;
606 void BeforeUnloadFiredFromRenderManager(
608 const base::TimeTicks
& proceed_time
,
609 bool* proceed_to_fire_unload
) override
;
610 void RenderProcessGoneFromRenderManager(
611 RenderViewHost
* render_view_host
) override
;
612 void UpdateRenderViewSizeForRenderManager() override
;
613 void CancelModalDialogsForRenderManager() override
;
614 void NotifySwappedFromRenderManager(RenderFrameHost
* old_host
,
615 RenderFrameHost
* new_host
,
616 bool is_main_frame
) override
;
617 void NotifyMainFrameSwappedFromRenderManager(
618 RenderViewHost
* old_host
,
619 RenderViewHost
* new_host
) override
;
620 NavigationControllerImpl
& GetControllerForRenderManager() override
;
621 scoped_ptr
<WebUIImpl
> CreateWebUIForRenderManager(const GURL
& url
) override
;
622 NavigationEntry
* GetLastCommittedNavigationEntryForRenderManager() override
;
623 bool FocusLocationBarByDefault() override
;
624 void SetFocusToLocationBar(bool select_all
) override
;
625 bool IsHidden() override
;
626 int GetOuterDelegateFrameTreeNodeID() override
;
628 // NotificationObserver ------------------------------------------------------
630 void Observe(int type
,
631 const NotificationSource
& source
,
632 const NotificationDetails
& details
) override
;
634 // NavigationControllerDelegate ----------------------------------------------
636 WebContents
* GetWebContents() override
;
637 void NotifyNavigationEntryCommitted(
638 const LoadCommittedDetails
& load_details
) override
;
640 // Invoked before a form repost warning is shown.
641 void NotifyBeforeFormRepostWarningShow() override
;
643 // Activate this WebContents and show a form repost warning.
644 void ActivateAndShowRepostFormWarningDialog() override
;
646 // Whether the initial empty page of this view has been accessed by another
647 // page, making it unsafe to show the pending URL. Always false after the
649 bool HasAccessedInitialDocument() override
;
651 // Updates the max page ID for the current SiteInstance in this
652 // WebContentsImpl to be at least |page_id|.
653 void UpdateMaxPageID(int32 page_id
) override
;
655 // Updates the max page ID for the given SiteInstance in this WebContentsImpl
656 // to be at least |page_id|.
657 void UpdateMaxPageIDForSiteInstance(SiteInstance
* site_instance
,
658 int32 page_id
) override
;
660 // Copy the current map of SiteInstance ID to max page ID from another tab.
661 // This is necessary when this tab adopts the NavigationEntries from
663 void CopyMaxPageIDsFrom(WebContents
* web_contents
) override
;
665 // Sets the history for this WebContentsImpl to |history_length| entries, with
666 // an offset of |history_offset|.
667 void SetHistoryOffsetAndLength(int history_offset
,
668 int history_length
) override
;
670 // Called by InterstitialPageImpl when it creates a RenderFrameHost.
671 void RenderFrameForInterstitialPageCreated(
672 RenderFrameHost
* render_frame_host
) override
;
674 // Sets the passed interstitial as the currently showing interstitial.
675 // No interstitial page should already be attached.
676 void AttachInterstitialPage(InterstitialPageImpl
* interstitial_page
) override
;
678 // Unsets the currently showing interstitial.
679 void DetachInterstitialPage() override
;
681 // Changes the IsLoading state and notifies the delegate as needed.
682 // |details| is used to provide details on the load that just finished
683 // (but can be null if not applicable).
684 void SetIsLoading(bool is_loading
,
685 bool to_different_document
,
686 LoadNotificationDetails
* details
) override
;
688 typedef base::Callback
<void(WebContents
*)> CreatedCallback
;
690 // Forces overscroll to be disabled (used by touch emulation).
691 void SetForceDisableOverscrollContent(bool force_disable
);
693 AudioStreamMonitor
* audio_stream_monitor() {
694 return &audio_stream_monitor_
;
697 bool has_audio_power_save_blocker_for_testing() const {
698 return audio_power_save_blocker_
;
701 bool has_video_power_save_blocker_for_testing() const {
702 return video_power_save_blocker_
;
705 #if defined(ENABLE_BROWSER_CDMS)
706 MediaWebContentsObserver
* media_web_contents_observer() {
707 return media_web_contents_observer_
.get();
712 friend class WebContentsObserver
;
713 friend class WebContents
; // To implement factory methods.
715 FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest
, NoJSMessageOnInterstitials
);
716 FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest
, UpdateTitle
);
717 FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest
, FindOpenerRVHWhenPending
);
718 FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest
,
719 CrossSiteCantPreemptAfterUnload
);
720 FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest
, PendingContents
);
721 FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest
, FrameTreeShape
);
722 FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest
, GetLastActiveTime
);
723 FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest
,
724 LoadResourceFromMemoryCacheWithBadSecurityInfo
);
725 FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest
,
726 LoadResourceFromMemoryCacheWithEmptySecurityInfo
);
727 FRIEND_TEST_ALL_PREFIXES(FormStructureBrowserTest
, HTMLFiles
);
728 FRIEND_TEST_ALL_PREFIXES(NavigationControllerTest
, HistoryNavigate
);
729 FRIEND_TEST_ALL_PREFIXES(RenderFrameHostManagerTest
, PageDoesBackAndReload
);
730 FRIEND_TEST_ALL_PREFIXES(SitePerProcessBrowserTest
, CrossSiteIframe
);
731 FRIEND_TEST_ALL_PREFIXES(SitePerProcessAccessibilityBrowserTest
,
732 CrossSiteIframeAccessibility
);
734 // So InterstitialPageImpl can access SetIsLoading.
735 friend class InterstitialPageImpl
;
737 // TODO(brettw) TestWebContents shouldn't exist!
738 friend class TestWebContents
;
740 class DestructionObserver
;
742 // Represents a WebContents node in a tree of WebContents structure.
744 // Two WebContents with separate FrameTrees can be connected by
745 // outer/inner relationship using this class. Note that their FrameTrees
746 // still remain disjoint.
747 // The parent is referred to as "outer WebContents" and the descendents are
748 // referred to as "inner WebContents".
749 // For each inner WebContents, the outer WebContents will have a
750 // corresponding FrameTreeNode.
751 struct WebContentsTreeNode
{
753 WebContentsTreeNode();
754 ~WebContentsTreeNode();
756 typedef std::set
<WebContentsTreeNode
*> ChildrenSet
;
758 void ConnectToOuterWebContents(WebContentsImpl
* outer_web_contents
,
759 RenderFrameHostImpl
* outer_contents_frame
);
761 WebContentsImpl
* outer_web_contents() { return outer_web_contents_
; }
762 int outer_contents_frame_tree_node_id() {
763 return outer_contents_frame_tree_node_id_
;
767 // The outer Webontents.
768 WebContentsImpl
* outer_web_contents_
;
769 // The ID of the FrameTreeNode in outer WebContents that is hosting us.
770 int outer_contents_frame_tree_node_id_
;
771 // List of inner WebContents that we host.
772 ChildrenSet inner_web_contents_tree_nodes_
;
775 // See WebContents::Create for a description of these parameters.
776 WebContentsImpl(BrowserContext
* browser_context
);
778 // Add and remove observers for page navigation notifications. The order in
779 // which notifications are sent to observers is undefined. Clients must be
780 // sure to remove the observer before they go away.
781 void AddObserver(WebContentsObserver
* observer
);
782 void RemoveObserver(WebContentsObserver
* observer
);
784 // Clears a pending contents that has been closed before being shown.
785 void OnWebContentsDestroyed(WebContentsImpl
* web_contents
);
787 // Creates and adds to the map a destruction observer watching |web_contents|.
788 // No-op if such an observer already exists.
789 void AddDestructionObserver(WebContentsImpl
* web_contents
);
791 // Deletes and removes from the map a destruction observer
792 // watching |web_contents|. No-op if there is no such observer.
793 void RemoveDestructionObserver(WebContentsImpl
* web_contents
);
795 // Traverses all the RenderFrameHosts in the FrameTree and creates a set
796 // all the unique RenderWidgetHostViews.
797 std::set
<RenderWidgetHostView
*> GetRenderWidgetHostViewsInTree();
799 // Callback function when showing JavaScript dialogs. Takes in a routing ID
800 // pair to identify the RenderFrameHost that opened the dialog, because it's
801 // possible for the RenderFrameHost to be deleted by the time this is called.
802 void OnDialogClosed(int render_process_id
,
804 IPC::Message
* reply_msg
,
805 bool dialog_was_suppressed
,
807 const base::string16
& user_input
);
809 bool OnMessageReceived(RenderViewHost
* render_view_host
,
810 RenderFrameHost
* render_frame_host
,
811 const IPC::Message
& message
);
813 // Checks whether render_frame_message_source_ is set to non-null value,
814 // otherwise it terminates the main frame renderer process.
815 bool HasValidFrameSource();
817 // IPC message handlers.
818 void OnThemeColorChanged(SkColor theme_color
);
819 void OnDidLoadResourceFromMemoryCache(const GURL
& url
,
820 const std::string
& security_info
,
821 const std::string
& http_request
,
822 const std::string
& mime_type
,
823 ResourceType resource_type
);
824 void OnDidDisplayInsecureContent();
825 void OnDidRunInsecureContent(const std::string
& security_origin
,
826 const GURL
& target_url
);
827 void OnDocumentLoadedInFrame();
828 void OnDidFinishLoad(const GURL
& url
);
829 void OnGoToEntryAtOffset(int offset
);
830 void OnUpdateZoomLimits(int minimum_percent
,
831 int maximum_percent
);
832 void OnEnumerateDirectory(int request_id
, const base::FilePath
& path
);
834 void OnRegisterProtocolHandler(const std::string
& protocol
,
836 const base::string16
& title
,
838 void OnUnregisterProtocolHandler(const std::string
& protocol
,
841 void OnFindReply(int request_id
,
842 int number_of_matches
,
843 const gfx::Rect
& selection_rect
,
844 int active_match_ordinal
,
846 #if defined(OS_ANDROID)
847 void OnFindMatchRectsReply(int version
,
848 const std::vector
<gfx::RectF
>& rects
,
849 const gfx::RectF
& active_rect
);
851 void OnOpenDateTimeDialog(
852 const ViewHostMsg_DateTimeDialogValue_Params
& value
);
854 void OnDomOperationResponse(const std::string
& json_string
,
856 void OnAppCacheAccessed(const GURL
& manifest_url
, bool blocked_by_policy
);
857 void OnOpenColorChooser(int color_chooser_id
,
859 const std::vector
<ColorSuggestion
>& suggestions
);
860 void OnEndColorChooser(int color_chooser_id
);
861 void OnSetSelectedColorInColorChooser(int color_chooser_id
, SkColor color
);
862 void OnWebUISend(const GURL
& source_url
,
863 const std::string
& name
,
864 const base::ListValue
& args
);
865 #if defined(ENABLE_PLUGINS)
866 void OnPepperInstanceCreated();
867 void OnPepperInstanceDeleted();
868 void OnPepperPluginHung(int plugin_child_id
,
869 const base::FilePath
& path
,
871 void OnPluginCrashed(const base::FilePath
& plugin_path
,
872 base::ProcessId plugin_pid
);
873 void OnRequestPpapiBrokerPermission(int routing_id
,
875 const base::FilePath
& plugin_path
);
877 // Callback function when requesting permission to access the PPAPI broker.
878 // |result| is true if permission was granted.
879 void OnPpapiBrokerPermissionResult(int routing_id
, bool result
);
881 void OnBrowserPluginMessage(RenderFrameHost
* render_frame_host
,
882 const IPC::Message
& message
);
883 #endif // defined(ENABLE_PLUGINS)
884 void OnUpdateFaviconURL(const std::vector
<FaviconURL
>& candidates
);
885 void OnFirstVisuallyNonEmptyPaint();
886 void OnMediaPlayingNotification(int64 player_cookie
,
890 void OnMediaPausedNotification(int64 player_cookie
);
891 void OnShowValidationMessage(const gfx::Rect
& anchor_in_root_view
,
892 const base::string16
& main_text
,
893 const base::string16
& sub_text
);
894 void OnHideValidationMessage();
895 void OnMoveValidationMessage(const gfx::Rect
& anchor_in_root_view
);
897 // Called by derived classes to indicate that we're no longer waiting for a
898 // response. This won't actually update the throbber, but it will get picked
899 // up at the next animation step if the throbber is going.
900 void SetNotWaitingForResponse() { waiting_for_response_
= false; }
902 // Navigation helpers --------------------------------------------------------
904 // These functions are helpers for Navigate() and DidNavigate().
906 // Handles post-navigation tasks in DidNavigate AFTER the entry has been
907 // committed to the navigation controller. Note that the navigation entry is
908 // not provided since it may be invalid/changed after being committed. The
909 // current navigation entry is in the NavigationController at this point.
911 // If our controller was restored, update the max page ID associated with the
912 // given RenderViewHost to be larger than the number of restored entries.
913 // This is called in CreateRenderView before any navigations in the RenderView
914 // have begun, to prevent any races in updating RenderView::next_page_id.
915 void UpdateMaxPageIDIfNecessary(RenderViewHost
* rvh
);
917 // Saves the given title to the navigation entry and does associated work. It
918 // will update history and the view for the new title, and also synthesize
919 // titles for file URLs that have none (so we require that the URL of the
920 // entry already be set).
922 // This is used as the backend for state updates, which include a new title,
923 // or the dedicated set title message. It returns true if the new title is
924 // different and was therefore updated.
925 bool UpdateTitleForEntry(NavigationEntryImpl
* entry
,
926 const base::string16
& title
);
928 // Helper for CreateNewWidget/CreateNewFullscreenWidget.
929 void CreateNewWidget(int32 render_process_id
,
933 blink::WebPopupType popup_type
);
935 // Helper for ShowCreatedWidget/ShowCreatedFullscreenWidget.
936 void ShowCreatedWidget(int route_id
,
938 const gfx::Rect
& initial_rect
);
940 // Finds the new RenderWidgetHost and returns it. Note that this can only be
941 // called once as this call also removes it from the internal map.
942 RenderWidgetHostView
* GetCreatedWidget(int route_id
);
944 // Finds the new WebContentsImpl by route_id, initializes it for
945 // renderer-initiated creation, and returns it. Note that this can only be
946 // called once as this call also removes it from the internal map.
947 WebContentsImpl
* GetCreatedWindow(int route_id
);
949 // Tracking loading progress -------------------------------------------------
951 // Resets the tracking state of the current load progress.
952 void ResetLoadProgressState();
954 // Notifies the delegate that the load progress was updated.
955 void SendChangeLoadProgress();
957 // Misc non-view stuff -------------------------------------------------------
959 // Sets the history for a specified RenderViewHost to |history_length|
960 // entries, with an offset of |history_offset|.
961 void SetHistoryOffsetAndLengthForView(RenderViewHost
* render_view_host
,
965 // Helper functions for sending notifications.
966 void NotifyViewSwapped(RenderViewHost
* old_host
, RenderViewHost
* new_host
);
967 void NotifyFrameSwapped(RenderFrameHost
* old_host
, RenderFrameHost
* new_host
);
968 void NotifyDisconnected();
970 void SetEncoding(const std::string
& encoding
);
972 // TODO(creis): This should take in a FrameTreeNode to know which node's
973 // render manager to return. For now, we just return the root's.
974 RenderFrameHostManager
* GetRenderManager() const;
976 // Removes browser plugin embedder if there is one.
977 void RemoveBrowserPluginEmbedder();
979 // Clear |render_frame_host|'s tracking entry for its power save blockers.
980 void ClearPowerSaveBlockers(RenderFrameHost
* render_frame_host
);
982 // Clear tracking entries for all RenderFrameHosts, clears
983 // |audio_power_save_blocker_| and |video_power_save_blocker_|.
984 void ClearAllPowerSaveBlockers();
986 // Creates an audio or video power save blocker respectively.
987 void CreateAudioPowerSaveBlocker();
988 void CreateVideoPowerSaveBlocker();
990 // Releases the audio power save blockers if |active_audio_players_| is empty.
991 // Likewise, releases the video power save blockers if |active_video_players_|
993 void MaybeReleasePowerSaveBlockers();
995 // Helper function to invoke WebContentsDelegate::GetSizeForNewRenderView().
996 gfx::Size
GetSizeForNewRenderView();
998 void OnFrameRemoved(RenderFrameHost
* render_frame_host
);
1000 // Helper method that's called whenever |preferred_size_| or
1001 // |preferred_size_for_capture_| changes, to propagate the new value to the
1003 void OnPreferredSizeChanged(const gfx::Size
& old_size
);
1005 // Helper methods for adding or removing player entries in |player_map| under
1006 // the key |render_frame_message_source_|.
1007 typedef std::vector
<int64
> PlayerList
;
1008 typedef std::map
<uintptr_t, PlayerList
> ActiveMediaPlayerMap
;
1009 void AddMediaPlayerEntry(int64 player_cookie
,
1010 ActiveMediaPlayerMap
* player_map
);
1011 void RemoveMediaPlayerEntry(int64 player_cookie
,
1012 ActiveMediaPlayerMap
* player_map
);
1013 // Removes all entries from |player_map| for |render_frame_host|.
1014 void RemoveAllMediaPlayerEntries(RenderFrameHost
* render_frame_host
,
1015 ActiveMediaPlayerMap
* player_map
);
1017 // Internal helper to create WebUI objects associated with |this|. |url| is
1018 // used to determine which WebUI should be created (if any). |frame_name|
1019 // corresponds to the name of a frame that the WebUI should be created for (or
1020 // the main frame if empty).
1021 WebUI
* CreateWebUI(const GURL
& url
, const std::string
& frame_name
);
1023 // Data for core operation ---------------------------------------------------
1025 // Delegate for notifying our owner about stuff. Not owned by us.
1026 WebContentsDelegate
* delegate_
;
1028 // Handles the back/forward list and loading.
1029 NavigationControllerImpl controller_
;
1031 // The corresponding view.
1032 scoped_ptr
<WebContentsView
> view_
;
1034 // The view of the RVHD. Usually this is our WebContentsView implementation,
1035 // but if an embedder uses a different WebContentsView, they'll need to
1037 RenderViewHostDelegateView
* render_view_host_delegate_view_
;
1039 // Tracks created WebContentsImpl objects that have not been shown yet. They
1040 // are identified by the route ID passed to CreateNewWindow.
1041 typedef std::map
<int, WebContentsImpl
*> PendingContents
;
1042 PendingContents pending_contents_
;
1044 // These maps hold on to the widgets that we created on behalf of the renderer
1045 // that haven't shown yet.
1046 typedef std::map
<int, RenderWidgetHostView
*> PendingWidgetViews
;
1047 PendingWidgetViews pending_widget_views_
;
1049 typedef std::map
<WebContentsImpl
*, DestructionObserver
*> DestructionObservers
;
1050 DestructionObservers destruction_observers_
;
1052 // A list of observers notified when page state changes. Weak references.
1053 // This MUST be listed above frame_tree_ since at destruction time the
1054 // latter might cause RenderViewHost's destructor to call us and we might use
1055 // the observer list then.
1056 base::ObserverList
<WebContentsObserver
> observers_
;
1058 // True if this tab was opened by another tab. This is not unset if the opener
1060 bool created_with_opener_
;
1063 gfx::NativeViewAccessible accessible_parent_
;
1066 // Helper classes ------------------------------------------------------------
1068 // Tracking variables and associated power save blockers for media playback.
1069 ActiveMediaPlayerMap active_audio_players_
;
1070 ActiveMediaPlayerMap active_video_players_
;
1071 scoped_ptr
<PowerSaveBlocker
> audio_power_save_blocker_
;
1072 scoped_ptr
<PowerSaveBlocker
> video_power_save_blocker_
;
1074 // Manages the frame tree of the page and process swaps in each node.
1075 FrameTree frame_tree_
;
1077 // If this WebContents is part of a "tree of WebContents", then this contains
1078 // information about the structure.
1079 scoped_ptr
<WebContentsTreeNode
> node_
;
1081 // SavePackage, lazily created.
1082 scoped_refptr
<SavePackage
> save_package_
;
1084 // Data for loading state ----------------------------------------------------
1086 // Indicates whether we're currently loading a resource.
1089 // Indicates whether the current load is to a different document. Only valid
1090 // if is_loading_ is true.
1091 bool is_load_to_different_document_
;
1093 // Indicates if the tab is considered crashed.
1094 base::TerminationStatus crashed_status_
;
1095 int crashed_error_code_
;
1097 // Whether this WebContents is waiting for a first-response for the
1098 // main resource of the page. This controls whether the throbber state is
1099 // "waiting" or "loading."
1100 bool waiting_for_response_
;
1102 // Map of SiteInstance ID to max page ID for this tab. A page ID is specific
1103 // to a given tab and SiteInstance, and must be valid for the lifetime of the
1105 std::map
<int32
, int32
> max_page_ids_
;
1107 // The current load state and the URL associated with it.
1108 net::LoadStateWithParam load_state_
;
1109 base::string16 load_state_host_
;
1111 base::TimeTicks loading_last_progress_update_
;
1113 // Upload progress, for displaying in the status bar.
1114 // Set to zero when there is no significant upload happening.
1115 uint64 upload_size_
;
1116 uint64 upload_position_
;
1118 // Tracks that this WebContents needs to unblock requests to the renderer.
1119 // See ResumeLoadingCreatedWebContents.
1120 bool is_resume_pending_
;
1122 // Data for current page -----------------------------------------------------
1124 // When a title cannot be taken from any entry, this title will be used.
1125 base::string16 page_title_when_no_navigation_entry_
;
1127 // When a navigation occurs, we record its contents MIME type. It can be
1128 // used to check whether we can do something for some special contents.
1129 std::string contents_mime_type_
;
1131 // The last reported character encoding, not canonicalized.
1132 std::string last_reported_encoding_
;
1134 // The canonicalized character encoding.
1135 std::string canonical_encoding_
;
1137 // True if this is a secure page which displayed insecure content.
1138 bool displayed_insecure_content_
;
1140 // Whether the initial empty page has been accessed by another page, making it
1141 // unsafe to show the pending URL. Usually false unless another window tries
1142 // to modify the blank page. Always false after the first commit.
1143 bool has_accessed_initial_document_
;
1145 // The theme color for the underlying document as specified
1146 // by theme-color meta tag.
1147 SkColor theme_color_
;
1149 // The last published theme color.
1150 SkColor last_sent_theme_color_
;
1152 // Whether the first visually non-empty paint has occurred.
1153 bool did_first_visually_non_empty_paint_
;
1155 // Data for misc internal state ----------------------------------------------
1157 // When > 0, the WebContents is currently being captured (e.g., for
1158 // screenshots or mirroring); and the underlying RenderWidgetHost should not
1159 // be told it is hidden.
1160 int capturer_count_
;
1162 // Tracks whether RWHV should be visible once capturer_count_ becomes zero.
1163 bool should_normally_be_visible_
;
1165 // See getter above.
1166 bool is_being_destroyed_
;
1168 // Indicates whether we should notify about disconnection of this
1169 // WebContentsImpl. This is used to ensure disconnection notifications only
1170 // happen if a connection notification has happened and that they happen only
1172 bool notify_disconnection_
;
1174 // Pointer to the JavaScript dialog manager, lazily assigned. Used because the
1175 // delegate of this WebContentsImpl is nulled before its destructor is called.
1176 JavaScriptDialogManager
* dialog_manager_
;
1178 // Set to true when there is an active "before unload" dialog. When true,
1179 // we've forced the throbber to start in Navigate, and we need to remember to
1180 // turn it off in OnJavaScriptMessageBoxClosed if the navigation is canceled.
1181 bool is_showing_before_unload_dialog_
;
1183 // Settings that get passed to the renderer process.
1184 RendererPreferences renderer_preferences_
;
1186 // The time that this WebContents was last made active. The initial value is
1187 // the WebContents creation time.
1188 base::TimeTicks last_active_time_
;
1190 // See description above setter.
1191 bool closed_by_user_gesture_
;
1193 // Minimum/maximum zoom percent.
1194 int minimum_zoom_percent_
;
1195 int maximum_zoom_percent_
;
1197 // The intrinsic size of the page.
1198 gfx::Size preferred_size_
;
1200 // The preferred size for content screen capture. When |capturer_count_| > 0,
1201 // this overrides |preferred_size_|.
1202 gfx::Size preferred_size_for_capture_
;
1204 #if defined(OS_ANDROID)
1205 // Date time chooser opened by this tab.
1206 // Only used in Android since all other platforms use a multi field UI.
1207 scoped_ptr
<DateTimeChooserAndroid
> date_time_chooser_
;
1210 // Holds information about a current color chooser dialog, if one is visible.
1211 struct ColorChooserInfo
{
1212 ColorChooserInfo(int render_process_id
,
1213 int render_frame_id
,
1214 ColorChooser
* chooser
,
1216 ~ColorChooserInfo();
1218 int render_process_id
;
1219 int render_frame_id
;
1221 // Color chooser that was opened by this tab.
1222 scoped_ptr
<ColorChooser
> chooser
;
1224 // A unique identifier for the current color chooser. Identifiers are
1225 // unique across a renderer process. This avoids race conditions in
1226 // synchronizing the browser and renderer processes. For example, if a
1227 // renderer closes one chooser and opens another, and simultaneously the
1228 // user picks a color in the first chooser, the IDs can be used to drop the
1229 // "chose a color" message rather than erroneously tell the renderer that
1230 // the user picked a color in the second chooser.
1234 scoped_ptr
<ColorChooserInfo
> color_chooser_info_
;
1236 // Manages the embedder state for browser plugins, if this WebContents is an
1237 // embedder; NULL otherwise.
1238 scoped_ptr
<BrowserPluginEmbedder
> browser_plugin_embedder_
;
1239 // Manages the guest state for browser plugin, if this WebContents is a guest;
1241 scoped_ptr
<BrowserPluginGuest
> browser_plugin_guest_
;
1243 #if defined(ENABLE_PLUGINS)
1244 // Manages the whitelist of plugin content origins exempt from power saving.
1245 scoped_ptr
<PluginContentOriginWhitelist
> plugin_content_origin_whitelist_
;
1248 // This must be at the end, or else we might get notifications and use other
1249 // member variables that are gone.
1250 NotificationRegistrar registrar_
;
1252 // Used during IPC message dispatching from the RenderView/RenderFrame so that
1253 // the handlers can get a pointer to the RVH through which the message was
1255 RenderViewHost
* render_view_message_source_
;
1256 RenderFrameHost
* render_frame_message_source_
;
1258 // All live RenderWidgetHostImpls that are created by this object and may
1260 std::set
<RenderWidgetHostImpl
*> created_widgets_
;
1262 // Routing id of the shown fullscreen widget or MSG_ROUTING_NONE otherwise.
1263 int fullscreen_widget_routing_id_
;
1265 // At the time the fullscreen widget was being shut down, did it have focus?
1266 // This is used to restore focus to the WebContentsView after both: 1) the
1267 // fullscreen widget is destroyed, and 2) the WebContentsDelegate has
1268 // completed making layout changes to effect an exit from fullscreen mode.
1269 bool fullscreen_widget_had_focus_at_shutdown_
;
1271 // Whether this WebContents is responsible for displaying a subframe in a
1272 // different process from its parent page.
1275 // When a new tab is created asynchronously, stores the OpenURLParams needed
1276 // to continue loading the page once the tab is ready.
1277 scoped_ptr
<OpenURLParams
> delayed_open_url_params_
;
1279 // Whether overscroll should be unconditionally disabled.
1280 bool force_disable_overscroll_content_
;
1282 // Whether the last JavaScript dialog shown was suppressed. Used for testing.
1283 bool last_dialog_suppressed_
;
1285 scoped_ptr
<GeolocationServiceContext
> geolocation_service_context_
;
1287 scoped_ptr
<ScreenOrientationDispatcherHost
>
1288 screen_orientation_dispatcher_host_
;
1290 scoped_ptr
<ManifestManagerHost
> manifest_manager_host_
;
1292 // The accessibility mode for all frames. This is queried when each frame
1293 // is created, and broadcast to all frames when it changes.
1294 AccessibilityMode accessibility_mode_
;
1296 // Monitors power levels for audio streams associated with this WebContents.
1297 AudioStreamMonitor audio_stream_monitor_
;
1299 // Created on-demand to mute all audio output from this WebContents.
1300 scoped_ptr
<WebContentsAudioMuter
> audio_muter_
;
1302 bool virtual_keyboard_requested_
;
1304 #if defined(ENABLE_BROWSER_CDMS)
1305 // Manages all the media player and CDM managers and forwards IPCs to them.
1306 scoped_ptr
<MediaWebContentsObserver
> media_web_contents_observer_
;
1309 scoped_ptr
<RenderWidgetHostInputEventRouter
> rwh_input_event_router_
;
1311 base::WeakPtrFactory
<WebContentsImpl
> loading_weak_factory_
;
1313 DISALLOW_COPY_AND_ASSIGN(WebContentsImpl
);
1316 // Dangerous methods which should never be made part of the public API, so we
1317 // grant their use only to an explicit friend list (c++ attorney/client idiom).
1318 class CONTENT_EXPORT
WebContentsImpl::FriendZone
{
1320 friend class TestNavigationObserver
;
1321 friend class WebContentsAddedObserver
;
1322 friend class ContentBrowserSanityChecker
;
1324 FriendZone(); // Not instantiable.
1326 // Adds/removes a callback called on creation of each new WebContents.
1327 static void AddCreatedCallbackForTesting(const CreatedCallback
& callback
);
1328 static void RemoveCreatedCallbackForTesting(const CreatedCallback
& callback
);
1330 DISALLOW_COPY_AND_ASSIGN(FriendZone
);
1333 } // namespace content
1335 #endif // CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_IMPL_H_