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_state_provider.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
;
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
) {
104 ~WebContentsImpl() override
;
106 static WebContentsImpl
* CreateWithOpener(
107 const WebContents::CreateParams
& params
,
108 FrameTreeNode
* opener
);
110 static std::vector
<WebContentsImpl
*> GetAllWebContents();
112 static WebContentsImpl
* FromFrameTreeNode(FrameTreeNode
* frame_tree_node
);
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 // Creates a BrowserPluginEmbedder object for this WebContents if one doesn't
155 void CreateBrowserPluginEmbedderIfNecessary();
157 // Cancels modal dialogs in this WebContents, as well as in any browser
158 // plugins it is hosting.
159 void CancelActiveAndPendingDialogs();
161 // Gets the current fullscreen render widget's routing ID. Returns
162 // MSG_ROUTING_NONE when there is no fullscreen render widget.
163 int GetFullscreenWidgetRoutingID() const;
165 // Invoked when visible SSL state (as defined by SSLStatus) changes.
166 void DidChangeVisibleSSLState();
168 // Informs the render view host and the BrowserPluginEmbedder, if present, of
169 // a Drag Source End.
170 void DragSourceEndedAt(int client_x
, int client_y
, int screen_x
,
171 int screen_y
, blink::WebDragOperation operation
);
173 // A response has been received for a resource request.
174 void DidGetResourceResponseStart(
175 const ResourceRequestDetails
& details
);
177 // A redirect was received while requesting a resource.
178 void DidGetRedirectForResourceRequest(
179 RenderFrameHost
* render_frame_host
,
180 const ResourceRedirectDetails
& details
);
182 // Notify observers that the web contents has been focused.
183 void NotifyWebContentsFocused();
185 WebContentsView
* GetView() const;
187 ScreenOrientationDispatcherHost
* screen_orientation_dispatcher_host() {
188 return screen_orientation_dispatcher_host_
.get();
191 bool should_normally_be_visible() { return should_normally_be_visible_
; }
193 // Indicate if the window has been occluded, and pass this to the views, only
194 // if there is no active capture going on (otherwise it is dropped on the
197 void WasUnOccluded();
199 // Broadcasts the mode change to all frames.
200 void SetAccessibilityMode(AccessibilityMode mode
);
202 // Adds the given accessibility mode to the current accessibility mode
204 void AddAccessibilityMode(AccessibilityMode mode
);
206 // Removes the given accessibility mode from the current accessibility
207 // mode bitmap, managing the bits that are shared with other modes such
208 // that a bit will only be turned off when all modes that depend on it
209 // have been removed.
210 void RemoveAccessibilityMode(AccessibilityMode mode
);
212 // Request a one-time snapshot of the accessibility tree without changing
213 // the accessibility mode.
214 typedef base::Callback
<void(const ui::AXTreeUpdate
&)>
215 AXTreeSnapshotCallback
;
216 void RequestAXTreeSnapshot(AXTreeSnapshotCallback callback
);
218 // WebContents ------------------------------------------------------
219 WebContentsDelegate
* GetDelegate() override
;
220 void SetDelegate(WebContentsDelegate
* delegate
) override
;
221 NavigationControllerImpl
& GetController() override
;
222 const NavigationControllerImpl
& GetController() const override
;
223 BrowserContext
* GetBrowserContext() const override
;
224 const GURL
& GetURL() const override
;
225 const GURL
& GetVisibleURL() const override
;
226 const GURL
& GetLastCommittedURL() const override
;
227 RenderProcessHost
* GetRenderProcessHost() const override
;
228 RenderFrameHostImpl
* GetMainFrame() override
;
229 RenderFrameHostImpl
* GetFocusedFrame() override
;
231 const base::Callback
<void(RenderFrameHost
*)>& on_frame
) override
;
232 void SendToAllFrames(IPC::Message
* message
) override
;
233 RenderViewHostImpl
* GetRenderViewHost() const override
;
234 int GetRoutingID() const override
;
235 RenderWidgetHostView
* GetRenderWidgetHostView() const override
;
236 void ClosePage() override
;
237 RenderWidgetHostView
* GetFullscreenRenderWidgetHostView() const override
;
238 SkColor
GetThemeColor() const override
;
239 WebUI
* CreateWebUI(const GURL
& url
) override
;
240 WebUI
* GetWebUI() const override
;
241 WebUI
* GetCommittedWebUI() const override
;
242 void SetUserAgentOverride(const std::string
& override
) override
;
243 const std::string
& GetUserAgentOverride() const override
;
244 void EnableTreeOnlyAccessibilityMode() override
;
245 bool IsTreeOnlyAccessibilityModeForTesting() const override
;
246 bool IsFullAccessibilityModeForTesting() const override
;
248 void SetParentNativeViewAccessible(
249 gfx::NativeViewAccessible accessible_parent
) override
;
251 const base::string16
& GetTitle() const override
;
252 int32
GetMaxPageID() override
;
253 int32
GetMaxPageIDForSiteInstance(SiteInstance
* site_instance
) override
;
254 SiteInstanceImpl
* GetSiteInstance() const override
;
255 SiteInstanceImpl
* GetPendingSiteInstance() const override
;
256 bool IsLoading() const override
;
257 bool IsLoadingToDifferentDocument() const override
;
258 bool IsWaitingForResponse() const override
;
259 const net::LoadStateWithParam
& GetLoadState() const override
;
260 const base::string16
& GetLoadStateHost() const override
;
261 uint64
GetUploadSize() const override
;
262 uint64
GetUploadPosition() const override
;
263 std::set
<GURL
> GetSitesInTab() const override
;
264 const std::string
& GetEncoding() const override
;
265 bool DisplayedInsecureContent() const override
;
266 void IncrementCapturerCount(const gfx::Size
& capture_size
) override
;
267 void DecrementCapturerCount() override
;
268 int GetCapturerCount() const override
;
269 bool IsAudioMuted() const override
;
270 void SetAudioMuted(bool mute
) override
;
271 bool IsCrashed() const override
;
272 void SetIsCrashed(base::TerminationStatus status
, int error_code
) override
;
273 base::TerminationStatus
GetCrashedStatus() const override
;
274 bool IsBeingDestroyed() const override
;
275 void NotifyNavigationStateChanged(InvalidateTypes changed_flags
) override
;
276 base::TimeTicks
GetLastActiveTime() const override
;
277 void SetLastActiveTime(base::TimeTicks last_active_time
) override
;
278 void WasShown() override
;
279 void WasHidden() override
;
280 bool NeedToFireBeforeUnload() override
;
281 void DispatchBeforeUnload(bool for_cross_site_transition
) override
;
282 void AttachToOuterWebContentsFrame(
283 WebContents
* outer_web_contents
,
284 RenderFrameHost
* outer_contents_frame
) override
;
285 void Stop() override
;
286 WebContents
* Clone() override
;
287 void ReloadFocusedFrame(bool ignore_cache
) override
;
288 void Undo() override
;
289 void Redo() override
;
291 void Copy() override
;
292 void CopyToFindPboard() override
;
293 void Paste() override
;
294 void PasteAndMatchStyle() override
;
295 void Delete() override
;
296 void SelectAll() override
;
297 void Unselect() override
;
298 void Replace(const base::string16
& word
) override
;
299 void ReplaceMisspelling(const base::string16
& word
) override
;
300 void NotifyContextMenuClosed(
301 const CustomContextMenuContext
& context
) override
;
302 void ExecuteCustomContextMenuCommand(
304 const CustomContextMenuContext
& context
) override
;
305 gfx::NativeView
GetNativeView() override
;
306 gfx::NativeView
GetContentNativeView() override
;
307 gfx::NativeWindow
GetTopLevelNativeWindow() override
;
308 gfx::Rect
GetContainerBounds() override
;
309 gfx::Rect
GetViewBounds() override
;
310 DropData
* GetDropData() override
;
311 void Focus() override
;
312 void SetInitialFocus() override
;
313 void StoreFocus() override
;
314 void RestoreFocus() override
;
315 void FocusThroughTabTraversal(bool reverse
) override
;
316 bool ShowingInterstitialPage() const override
;
317 InterstitialPage
* GetInterstitialPage() const override
;
318 bool IsSavable() override
;
319 void OnSavePage() override
;
320 bool SavePage(const base::FilePath
& main_file
,
321 const base::FilePath
& dir_path
,
322 SavePageType save_type
) override
;
323 void SaveFrame(const GURL
& url
, const Referrer
& referrer
) override
;
324 void SaveFrameWithHeaders(const GURL
& url
,
325 const Referrer
& referrer
,
326 const std::string
& headers
) override
;
327 void GenerateMHTML(const base::FilePath
& file
,
328 const base::Callback
<void(int64
)>& callback
) override
;
329 const std::string
& GetContentsMimeType() const override
;
330 bool WillNotifyDisconnection() const override
;
331 void SetOverrideEncoding(const std::string
& encoding
) override
;
332 void ResetOverrideEncoding() override
;
333 RendererPreferences
* GetMutableRendererPrefs() override
;
334 void Close() override
;
335 void SystemDragEnded() override
;
336 void UserGestureDone() override
;
337 void SetClosedByUserGesture(bool value
) override
;
338 bool GetClosedByUserGesture() const override
;
339 void ViewSource() override
;
340 void ViewFrameSource(const GURL
& url
, const PageState
& page_state
) override
;
341 int GetMinimumZoomPercent() const override
;
342 int GetMaximumZoomPercent() const override
;
343 void ResetPageScale() override
;
344 gfx::Size
GetPreferredSize() const override
;
345 bool GotResponseToLockMouseRequest(bool allowed
) override
;
346 bool HasOpener() const override
;
347 WebContentsImpl
* GetOpener() const override
;
348 void DidChooseColorInColorChooser(SkColor color
) override
;
349 void DidEndColorChooser() override
;
350 int DownloadImage(const GURL
& url
,
352 uint32_t max_bitmap_size
,
354 const ImageDownloadCallback
& callback
) override
;
355 bool IsSubframe() const override
;
356 void Find(int request_id
,
357 const base::string16
& search_text
,
358 const blink::WebFindOptions
& options
) override
;
359 void StopFinding(StopFindAction action
) override
;
360 void InsertCSS(const std::string
& css
) override
;
361 bool WasRecentlyAudible() override
;
362 void GetManifest(const GetManifestCallback
&) override
;
363 void ExitFullscreen() override
;
364 void ResumeLoadingCreatedWebContents() override
;
365 #if defined(OS_ANDROID)
366 void OnMediaSessionStateChanged();
367 void ResumeMediaSession() override
;
368 void SuspendMediaSession() override
;
370 base::android::ScopedJavaLocalRef
<jobject
> GetJavaWebContents() override
;
371 virtual WebContentsAndroid
* GetWebContentsAndroid();
372 #elif defined(OS_MACOSX)
373 void SetAllowOtherViews(bool allow
) override
;
374 bool GetAllowOtherViews() override
;
377 // Implementation of PageNavigator.
378 WebContents
* OpenURL(const OpenURLParams
& params
) override
;
380 // Implementation of IPC::Sender.
381 bool Send(IPC::Message
* message
) override
;
383 // RenderFrameHostDelegate ---------------------------------------------------
384 bool OnMessageReceived(RenderFrameHost
* render_frame_host
,
385 const IPC::Message
& message
) override
;
386 const GURL
& GetMainFrameLastCommittedURL() const override
;
387 void RenderFrameCreated(RenderFrameHost
* render_frame_host
) override
;
388 void RenderFrameDeleted(RenderFrameHost
* render_frame_host
) override
;
389 void SwappedOut(RenderFrameHost
* render_frame_host
) override
;
390 void ShowContextMenu(RenderFrameHost
* render_frame_host
,
391 const ContextMenuParams
& params
) override
;
392 void RunJavaScriptMessage(RenderFrameHost
* render_frame_host
,
393 const base::string16
& message
,
394 const base::string16
& default_prompt
,
395 const GURL
& frame_url
,
396 JavaScriptMessageType type
,
397 IPC::Message
* reply_msg
) override
;
398 void RunBeforeUnloadConfirm(RenderFrameHost
* render_frame_host
,
399 const base::string16
& message
,
401 IPC::Message
* reply_msg
) override
;
402 void DidAccessInitialDocument() override
;
403 void DidChangeName(RenderFrameHost
* render_frame_host
,
404 const std::string
& name
) override
;
405 void DocumentOnLoadCompleted(RenderFrameHost
* render_frame_host
) override
;
406 void UpdateTitle(RenderFrameHost
* render_frame_host
,
408 const base::string16
& title
,
409 base::i18n::TextDirection title_direction
) override
;
410 void UpdateEncoding(RenderFrameHost
* render_frame_host
,
411 const std::string
& encoding
) override
;
412 WebContents
* GetAsWebContents() override
;
413 bool IsNeverVisible() override
;
414 AccessibilityMode
GetAccessibilityMode() const override
;
415 void AccessibilityEventReceived(
416 const std::vector
<AXEventNotificationDetails
>& details
) override
;
417 RenderFrameHost
* GetGuestByInstanceID(
418 RenderFrameHost
* render_frame_host
,
419 int browser_plugin_instance_id
) override
;
420 GeolocationServiceContext
* GetGeolocationServiceContext() override
;
421 void EnterFullscreenMode(const GURL
& origin
) override
;
422 void ExitFullscreenMode() override
;
423 bool ShouldRouteMessageEvent(
424 RenderFrameHost
* target_rfh
,
425 SiteInstance
* source_site_instance
) const override
;
426 void EnsureOpenerProxiesExist(RenderFrameHost
* source_rfh
) override
;
428 gfx::NativeViewAccessible
GetParentNativeViewAccessible() override
;
431 // RenderViewHostDelegate ----------------------------------------------------
432 RenderViewHostDelegateView
* GetDelegateView() override
;
433 bool OnMessageReceived(RenderViewHost
* render_view_host
,
434 const IPC::Message
& message
) override
;
435 // RenderFrameHostDelegate has the same method, so list it there because this
436 // interface is going away.
437 // WebContents* GetAsWebContents() override;
438 gfx::Rect
GetRootWindowResizerRect() const override
;
439 void RenderViewCreated(RenderViewHost
* render_view_host
) override
;
440 void RenderViewReady(RenderViewHost
* render_view_host
) override
;
441 void RenderViewTerminated(RenderViewHost
* render_view_host
,
442 base::TerminationStatus status
,
443 int error_code
) override
;
444 void RenderViewDeleted(RenderViewHost
* render_view_host
) override
;
445 void UpdateState(RenderViewHost
* render_view_host
,
447 const PageState
& page_state
) override
;
448 void UpdateTargetURL(RenderViewHost
* render_view_host
,
449 const GURL
& url
) override
;
450 void Close(RenderViewHost
* render_view_host
) override
;
451 void RequestMove(const gfx::Rect
& new_bounds
) override
;
452 void DidCancelLoading() override
;
453 void DocumentAvailableInMainFrame(RenderViewHost
* render_view_host
) override
;
454 void RouteCloseEvent(RenderViewHost
* rvh
) override
;
455 bool AddMessageToConsole(int32 level
,
456 const base::string16
& message
,
458 const base::string16
& source_id
) override
;
459 RendererPreferences
GetRendererPrefs(
460 BrowserContext
* browser_context
) const override
;
461 void OnUserGesture() override
;
462 void OnIgnoredUIEvent() override
;
463 void RendererUnresponsive(RenderViewHost
* render_view_host
) override
;
464 void RendererResponsive(RenderViewHost
* render_view_host
) override
;
465 void LoadStateChanged(const GURL
& url
,
466 const net::LoadStateWithParam
& load_state
,
467 uint64 upload_position
,
468 uint64 upload_size
) override
;
469 void Activate() override
;
470 void Deactivate() override
;
471 void LostCapture() override
;
472 void RunFileChooser(RenderViewHost
* render_view_host
,
473 const FileChooserParams
& params
) override
;
474 bool IsFullscreenForCurrentTab() const override
;
475 blink::WebDisplayMode
GetDisplayMode() const override
;
476 void UpdatePreferredSize(const gfx::Size
& pref_size
) override
;
477 void ResizeDueToAutoResize(const gfx::Size
& new_size
) override
;
478 void RequestToLockMouse(bool user_gesture
,
479 bool last_unlocked_by_target
) override
;
480 void LostMouseLock() override
;
481 void CreateNewWindow(
482 SiteInstance
* source_site_instance
,
484 int main_frame_route_id
,
485 const ViewHostMsg_CreateWindow_Params
& params
,
486 SessionStorageNamespace
* session_storage_namespace
) override
;
487 void CreateNewWidget(int render_process_id
,
489 blink::WebPopupType popup_type
) override
;
490 void CreateNewFullscreenWidget(int render_process_id
, int route_id
) override
;
491 void ShowCreatedWindow(int route_id
,
492 WindowOpenDisposition disposition
,
493 const gfx::Rect
& initial_rect
,
494 bool user_gesture
) override
;
495 void ShowCreatedWidget(int route_id
, const gfx::Rect
& initial_rect
) override
;
496 void ShowCreatedFullscreenWidget(int route_id
) override
;
497 void RequestMediaAccessPermission(
498 const MediaStreamRequest
& request
,
499 const MediaResponseCallback
& callback
) override
;
500 bool CheckMediaAccessPermission(const GURL
& security_origin
,
501 MediaStreamType type
) override
;
502 SessionStorageNamespace
* GetSessionStorageNamespace(
503 SiteInstance
* instance
) override
;
504 SessionStorageNamespaceMap
GetSessionStorageNamespaceMap() override
;
505 FrameTree
* GetFrameTree() override
;
506 void SetIsVirtualKeyboardRequested(bool requested
) override
;
507 bool IsVirtualKeyboardRequested() override
;
509 // NavigatorDelegate ---------------------------------------------------------
511 void DidStartProvisionalLoad(RenderFrameHostImpl
* render_frame_host
,
512 const GURL
& validated_url
,
514 bool is_iframe_srcdoc
) override
;
515 void DidFailProvisionalLoadWithError(
516 RenderFrameHostImpl
* render_frame_host
,
517 const FrameHostMsg_DidFailProvisionalLoadWithError_Params
& params
)
519 void DidFailLoadWithError(RenderFrameHostImpl
* render_frame_host
,
522 const base::string16
& error_description
,
523 bool was_ignored_by_handler
) override
;
524 void DidCommitProvisionalLoad(RenderFrameHostImpl
* render_frame_host
,
526 ui::PageTransition transition_type
) override
;
527 void DidNavigateMainFramePreCommit(bool navigation_is_within_page
) override
;
528 void DidNavigateMainFramePostCommit(
529 RenderFrameHostImpl
* render_frame_host
,
530 const LoadCommittedDetails
& details
,
531 const FrameHostMsg_DidCommitProvisionalLoad_Params
& params
) override
;
532 void DidNavigateAnyFramePostCommit(
533 RenderFrameHostImpl
* render_frame_host
,
534 const LoadCommittedDetails
& details
,
535 const FrameHostMsg_DidCommitProvisionalLoad_Params
& params
) override
;
536 void SetMainFrameMimeType(const std::string
& mime_type
) override
;
537 bool CanOverscrollContent() const override
;
538 void NotifyChangedNavigationState(InvalidateTypes changed_flags
) override
;
539 void AboutToNavigateRenderFrame(
540 RenderFrameHostImpl
* old_host
,
541 RenderFrameHostImpl
* new_host
) override
;
542 void DidStartNavigationToPendingEntry(
544 NavigationController::ReloadType reload_type
) override
;
545 void RequestOpenURL(RenderFrameHostImpl
* render_frame_host
,
546 const OpenURLParams
& params
) override
;
547 bool ShouldPreserveAbortedURLs() override
;
548 void DidStartLoading(FrameTreeNode
* frame_tree_node
,
549 bool to_different_document
) override
;
550 void DidStopLoading() override
;
551 void DidChangeLoadProgress() override
;
553 // RenderWidgetHostDelegate --------------------------------------------------
555 void RenderWidgetDeleted(RenderWidgetHostImpl
* render_widget_host
) override
;
556 void RenderWidgetGotFocus(RenderWidgetHostImpl
* render_widget_host
) override
;
557 void RenderWidgetWasResized(RenderWidgetHostImpl
* render_widget_host
,
558 bool width_changed
) override
;
559 void ScreenInfoChanged() override
;
560 bool PreHandleKeyboardEvent(const NativeWebKeyboardEvent
& event
,
561 bool* is_keyboard_shortcut
) override
;
562 void HandleKeyboardEvent(const NativeWebKeyboardEvent
& event
) override
;
563 bool HandleWheelEvent(const blink::WebMouseWheelEvent
& event
) override
;
564 bool PreHandleGestureEvent(const blink::WebGestureEvent
& event
) override
;
565 void DidSendScreenRects(RenderWidgetHostImpl
* rwh
) override
;
566 BrowserAccessibilityManager
* GetRootBrowserAccessibilityManager() override
;
567 BrowserAccessibilityManager
* GetOrCreateRootBrowserAccessibilityManager()
569 // The following 4 functions are already listed under WebContents overrides:
570 // void Cut() override;
571 // void Copy() override;
572 // void Paste() override;
573 // void SelectAll() override;
574 void MoveRangeSelectionExtent(const gfx::Point
& extent
) override
;
575 void SelectRange(const gfx::Point
& base
, const gfx::Point
& extent
) override
;
576 void AdjustSelectionByCharacterOffset(int start_adjust
, int end_adjust
)
579 // RenderFrameHostManager::Delegate ------------------------------------------
581 bool CreateRenderViewForRenderManager(
582 RenderViewHost
* render_view_host
,
583 int opener_frame_routing_id
,
584 int proxy_routing_id
,
585 const FrameReplicationState
& replicated_frame_state
,
586 bool for_main_frame_navigation
) override
;
587 bool CreateRenderFrameForRenderManager(RenderFrameHost
* render_frame_host
,
588 int parent_routing_id
,
589 int previous_sibling_routing_id
,
590 int proxy_routing_id
) override
;
591 void BeforeUnloadFiredFromRenderManager(
593 const base::TimeTicks
& proceed_time
,
594 bool* proceed_to_fire_unload
) override
;
595 void RenderProcessGoneFromRenderManager(
596 RenderViewHost
* render_view_host
) override
;
597 void UpdateRenderViewSizeForRenderManager() override
;
598 void CancelModalDialogsForRenderManager() override
;
599 void NotifySwappedFromRenderManager(RenderFrameHost
* old_host
,
600 RenderFrameHost
* new_host
,
601 bool is_main_frame
) override
;
602 void NotifyMainFrameSwappedFromRenderManager(
603 RenderViewHost
* old_host
,
604 RenderViewHost
* new_host
) override
;
605 NavigationControllerImpl
& GetControllerForRenderManager() override
;
606 scoped_ptr
<WebUIImpl
> CreateWebUIForRenderManager(const GURL
& url
) override
;
607 NavigationEntry
* GetLastCommittedNavigationEntryForRenderManager() override
;
608 bool FocusLocationBarByDefault() override
;
609 void SetFocusToLocationBar(bool select_all
) override
;
610 bool IsHidden() override
;
611 int GetOuterDelegateFrameTreeNodeID() override
;
613 // NotificationObserver ------------------------------------------------------
615 void Observe(int type
,
616 const NotificationSource
& source
,
617 const NotificationDetails
& details
) override
;
619 // NavigationControllerDelegate ----------------------------------------------
621 WebContents
* GetWebContents() override
;
622 void NotifyNavigationEntryCommitted(
623 const LoadCommittedDetails
& load_details
) override
;
625 // Invoked before a form repost warning is shown.
626 void NotifyBeforeFormRepostWarningShow() override
;
628 // Activate this WebContents and show a form repost warning.
629 void ActivateAndShowRepostFormWarningDialog() override
;
631 // Whether the initial empty page of this view has been accessed by another
632 // page, making it unsafe to show the pending URL. Always false after the
634 bool HasAccessedInitialDocument() override
;
636 // Updates the max page ID for the current SiteInstance in this
637 // WebContentsImpl to be at least |page_id|.
638 void UpdateMaxPageID(int32 page_id
) override
;
640 // Updates the max page ID for the given SiteInstance in this WebContentsImpl
641 // to be at least |page_id|.
642 void UpdateMaxPageIDForSiteInstance(SiteInstance
* site_instance
,
643 int32 page_id
) override
;
645 // Copy the current map of SiteInstance ID to max page ID from another tab.
646 // This is necessary when this tab adopts the NavigationEntries from
648 void CopyMaxPageIDsFrom(WebContents
* web_contents
) override
;
650 // Sets the history for this WebContentsImpl to |history_length| entries, with
651 // an offset of |history_offset|.
652 void SetHistoryOffsetAndLength(int history_offset
,
653 int history_length
) override
;
655 // Called by InterstitialPageImpl when it creates a RenderFrameHost.
656 void RenderFrameForInterstitialPageCreated(
657 RenderFrameHost
* render_frame_host
) override
;
659 // Sets the passed interstitial as the currently showing interstitial.
660 // No interstitial page should already be attached.
661 void AttachInterstitialPage(InterstitialPageImpl
* interstitial_page
) override
;
663 // Unsets the currently showing interstitial.
664 void DetachInterstitialPage() override
;
666 // Changes the IsLoading state and notifies the delegate as needed.
667 // |details| is used to provide details on the load that just finished
668 // (but can be null if not applicable).
669 void SetIsLoading(bool is_loading
,
670 bool to_different_document
,
671 LoadNotificationDetails
* details
) override
;
673 typedef base::Callback
<void(WebContents
*)> CreatedCallback
;
675 // Forces overscroll to be disabled (used by touch emulation).
676 void SetForceDisableOverscrollContent(bool force_disable
);
678 AudioStateProvider
* audio_state_provider() {
679 return audio_state_provider_
.get();
682 bool has_audio_power_save_blocker_for_testing() const {
683 return audio_power_save_blocker_
;
686 bool has_video_power_save_blocker_for_testing() const {
687 return video_power_save_blocker_
;
690 #if defined(ENABLE_BROWSER_CDMS)
691 MediaWebContentsObserver
* media_web_contents_observer() {
692 return media_web_contents_observer_
.get();
697 friend class WebContentsObserver
;
698 friend class WebContents
; // To implement factory methods.
700 FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest
, NoJSMessageOnInterstitials
);
701 FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest
, UpdateTitle
);
702 FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest
, FindOpenerRVHWhenPending
);
703 FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest
,
704 CrossSiteCantPreemptAfterUnload
);
705 FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest
, PendingContents
);
706 FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest
, FrameTreeShape
);
707 FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest
, GetLastActiveTime
);
708 FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest
,
709 LoadResourceFromMemoryCacheWithBadSecurityInfo
);
710 FRIEND_TEST_ALL_PREFIXES(FormStructureBrowserTest
, HTMLFiles
);
711 FRIEND_TEST_ALL_PREFIXES(NavigationControllerTest
, HistoryNavigate
);
712 FRIEND_TEST_ALL_PREFIXES(RenderFrameHostManagerTest
, PageDoesBackAndReload
);
713 FRIEND_TEST_ALL_PREFIXES(SitePerProcessBrowserTest
, CrossSiteIframe
);
714 FRIEND_TEST_ALL_PREFIXES(SitePerProcessAccessibilityBrowserTest
,
715 CrossSiteIframeAccessibility
);
717 // So InterstitialPageImpl can access SetIsLoading.
718 friend class InterstitialPageImpl
;
720 // TODO(brettw) TestWebContents shouldn't exist!
721 friend class TestWebContents
;
723 class DestructionObserver
;
725 // Represents a WebContents node in a tree of WebContents structure.
727 // Two WebContents with separate FrameTrees can be connected by
728 // outer/inner relationship using this class. Note that their FrameTrees
729 // still remain disjoint.
730 // The parent is referred to as "outer WebContents" and the descendents are
731 // referred to as "inner WebContents".
732 // For each inner WebContents, the outer WebContents will have a
733 // corresponding FrameTreeNode.
734 struct WebContentsTreeNode
{
736 WebContentsTreeNode();
737 ~WebContentsTreeNode();
739 typedef std::set
<WebContentsTreeNode
*> ChildrenSet
;
741 void ConnectToOuterWebContents(WebContentsImpl
* outer_web_contents
,
742 RenderFrameHostImpl
* outer_contents_frame
);
744 WebContentsImpl
* outer_web_contents() { return outer_web_contents_
; }
745 int outer_contents_frame_tree_node_id() {
746 return outer_contents_frame_tree_node_id_
;
750 // The outer Webontents.
751 WebContentsImpl
* outer_web_contents_
;
752 // The ID of the FrameTreeNode in outer WebContents that is hosting us.
753 int outer_contents_frame_tree_node_id_
;
754 // List of inner WebContents that we host.
755 ChildrenSet inner_web_contents_tree_nodes_
;
758 // See WebContents::Create for a description of these parameters.
759 WebContentsImpl(BrowserContext
* browser_context
);
761 // Add and remove observers for page navigation notifications. The order in
762 // which notifications are sent to observers is undefined. Clients must be
763 // sure to remove the observer before they go away.
764 void AddObserver(WebContentsObserver
* observer
);
765 void RemoveObserver(WebContentsObserver
* observer
);
767 // Clears a pending contents that has been closed before being shown.
768 void OnWebContentsDestroyed(WebContentsImpl
* web_contents
);
770 // Creates and adds to the map a destruction observer watching |web_contents|.
771 // No-op if such an observer already exists.
772 void AddDestructionObserver(WebContentsImpl
* web_contents
);
774 // Deletes and removes from the map a destruction observer
775 // watching |web_contents|. No-op if there is no such observer.
776 void RemoveDestructionObserver(WebContentsImpl
* web_contents
);
778 // Traverses all the RenderFrameHosts in the FrameTree and creates a set
779 // all the unique RenderWidgetHostViews.
780 std::set
<RenderWidgetHostView
*> GetRenderWidgetHostViewsInTree();
782 // Callback function when showing JavaScript dialogs. Takes in a routing ID
783 // pair to identify the RenderFrameHost that opened the dialog, because it's
784 // possible for the RenderFrameHost to be deleted by the time this is called.
785 void OnDialogClosed(int render_process_id
,
787 IPC::Message
* reply_msg
,
788 bool dialog_was_suppressed
,
790 const base::string16
& user_input
);
792 bool OnMessageReceived(RenderViewHost
* render_view_host
,
793 RenderFrameHost
* render_frame_host
,
794 const IPC::Message
& message
);
796 // Checks whether render_frame_message_source_ is set to non-null value,
797 // otherwise it terminates the main frame renderer process.
798 bool HasValidFrameSource();
800 // IPC message handlers.
801 void OnThemeColorChanged(SkColor theme_color
);
802 void OnDidLoadResourceFromMemoryCache(const GURL
& url
,
803 const std::string
& security_info
,
804 const std::string
& http_request
,
805 const std::string
& mime_type
,
806 ResourceType resource_type
);
807 void OnDidDisplayInsecureContent();
808 void OnDidRunInsecureContent(const std::string
& security_origin
,
809 const GURL
& target_url
);
810 void OnDocumentLoadedInFrame();
811 void OnDidFinishLoad(const GURL
& url
);
812 void OnGoToEntryAtOffset(int offset
);
813 void OnUpdateZoomLimits(int minimum_percent
,
814 int maximum_percent
);
815 void OnEnumerateDirectory(int request_id
, const base::FilePath
& path
);
817 void OnRegisterProtocolHandler(const std::string
& protocol
,
819 const base::string16
& title
,
821 void OnUnregisterProtocolHandler(const std::string
& protocol
,
824 void OnFindReply(int request_id
,
825 int number_of_matches
,
826 const gfx::Rect
& selection_rect
,
827 int active_match_ordinal
,
829 #if defined(OS_ANDROID)
830 void OnFindMatchRectsReply(int version
,
831 const std::vector
<gfx::RectF
>& rects
,
832 const gfx::RectF
& active_rect
);
834 void OnOpenDateTimeDialog(
835 const ViewHostMsg_DateTimeDialogValue_Params
& value
);
837 void OnDomOperationResponse(const std::string
& json_string
,
839 void OnAppCacheAccessed(const GURL
& manifest_url
, bool blocked_by_policy
);
840 void OnOpenColorChooser(int color_chooser_id
,
842 const std::vector
<ColorSuggestion
>& suggestions
);
843 void OnEndColorChooser(int color_chooser_id
);
844 void OnSetSelectedColorInColorChooser(int color_chooser_id
, SkColor color
);
845 void OnWebUISend(const GURL
& source_url
,
846 const std::string
& name
,
847 const base::ListValue
& args
);
848 #if defined(ENABLE_PLUGINS)
849 void OnPepperInstanceCreated();
850 void OnPepperInstanceDeleted();
851 void OnPepperPluginHung(int plugin_child_id
,
852 const base::FilePath
& path
,
854 void OnPluginCrashed(const base::FilePath
& plugin_path
,
855 base::ProcessId plugin_pid
);
856 void OnRequestPpapiBrokerPermission(int routing_id
,
858 const base::FilePath
& plugin_path
);
860 // Callback function when requesting permission to access the PPAPI broker.
861 // |result| is true if permission was granted.
862 void OnPpapiBrokerPermissionResult(int routing_id
, bool result
);
864 void OnBrowserPluginMessage(RenderFrameHost
* render_frame_host
,
865 const IPC::Message
& message
);
866 #endif // defined(ENABLE_PLUGINS)
867 void OnUpdateFaviconURL(const std::vector
<FaviconURL
>& candidates
);
868 void OnFirstVisuallyNonEmptyPaint();
869 void OnMediaPlayingNotification(int64 player_cookie
,
873 void OnMediaPausedNotification(int64 player_cookie
);
874 void OnShowValidationMessage(const gfx::Rect
& anchor_in_root_view
,
875 const base::string16
& main_text
,
876 const base::string16
& sub_text
);
877 void OnHideValidationMessage();
878 void OnMoveValidationMessage(const gfx::Rect
& anchor_in_root_view
);
880 // Called by derived classes to indicate that we're no longer waiting for a
881 // response. This won't actually update the throbber, but it will get picked
882 // up at the next animation step if the throbber is going.
883 void SetNotWaitingForResponse() { waiting_for_response_
= false; }
885 // Navigation helpers --------------------------------------------------------
887 // These functions are helpers for Navigate() and DidNavigate().
889 // Handles post-navigation tasks in DidNavigate AFTER the entry has been
890 // committed to the navigation controller. Note that the navigation entry is
891 // not provided since it may be invalid/changed after being committed. The
892 // current navigation entry is in the NavigationController at this point.
894 // If our controller was restored, update the max page ID associated with the
895 // given RenderViewHost to be larger than the number of restored entries.
896 // This is called in CreateRenderView before any navigations in the RenderView
897 // have begun, to prevent any races in updating RenderView::next_page_id.
898 void UpdateMaxPageIDIfNecessary(RenderViewHost
* rvh
);
900 // Saves the given title to the navigation entry and does associated work. It
901 // will update history and the view for the new title, and also synthesize
902 // titles for file URLs that have none (so we require that the URL of the
903 // entry already be set).
905 // This is used as the backend for state updates, which include a new title,
906 // or the dedicated set title message. It returns true if the new title is
907 // different and was therefore updated.
908 bool UpdateTitleForEntry(NavigationEntryImpl
* entry
,
909 const base::string16
& title
);
911 // Helper for CreateNewWidget/CreateNewFullscreenWidget.
912 void CreateNewWidget(int render_process_id
,
915 blink::WebPopupType popup_type
);
917 // Helper for ShowCreatedWidget/ShowCreatedFullscreenWidget.
918 void ShowCreatedWidget(int route_id
,
920 const gfx::Rect
& initial_rect
);
922 // Finds the new RenderWidgetHost and returns it. Note that this can only be
923 // called once as this call also removes it from the internal map.
924 RenderWidgetHostView
* GetCreatedWidget(int route_id
);
926 // Finds the new WebContentsImpl by route_id, initializes it for
927 // renderer-initiated creation, and returns it. Note that this can only be
928 // called once as this call also removes it from the internal map.
929 WebContentsImpl
* GetCreatedWindow(int route_id
);
931 // Tracking loading progress -------------------------------------------------
933 // Resets the tracking state of the current load progress.
934 void ResetLoadProgressState();
936 // Notifies the delegate that the load progress was updated.
937 void SendChangeLoadProgress();
939 // Misc non-view stuff -------------------------------------------------------
941 // Sets the history for a specified RenderViewHost to |history_length|
942 // entries, with an offset of |history_offset|.
943 void SetHistoryOffsetAndLengthForView(RenderViewHost
* render_view_host
,
947 // Helper functions for sending notifications.
948 void NotifyViewSwapped(RenderViewHost
* old_host
, RenderViewHost
* new_host
);
949 void NotifyFrameSwapped(RenderFrameHost
* old_host
, RenderFrameHost
* new_host
);
950 void NotifyDisconnected();
952 void SetEncoding(const std::string
& encoding
);
954 // TODO(creis): This should take in a FrameTreeNode to know which node's
955 // render manager to return. For now, we just return the root's.
956 RenderFrameHostManager
* GetRenderManager() const;
958 // Removes browser plugin embedder if there is one.
959 void RemoveBrowserPluginEmbedder();
961 // Clear |render_frame_host|'s tracking entry for its power save blockers.
962 void ClearPowerSaveBlockers(RenderFrameHost
* render_frame_host
);
964 // Clear tracking entries for all RenderFrameHosts, clears
965 // |audio_power_save_blocker_| and |video_power_save_blocker_|.
966 void ClearAllPowerSaveBlockers();
968 // Creates an audio or video power save blocker respectively.
969 void CreateAudioPowerSaveBlocker();
970 void CreateVideoPowerSaveBlocker();
972 // Releases the audio power save blockers if |active_audio_players_| is empty.
973 // Likewise, releases the video power save blockers if |active_video_players_|
975 void MaybeReleasePowerSaveBlockers();
977 // Helper function to invoke WebContentsDelegate::GetSizeForNewRenderView().
978 gfx::Size
GetSizeForNewRenderView();
980 void OnFrameRemoved(RenderFrameHost
* render_frame_host
);
982 // Helper method that's called whenever |preferred_size_| or
983 // |preferred_size_for_capture_| changes, to propagate the new value to the
985 void OnPreferredSizeChanged(const gfx::Size
& old_size
);
987 // Helper methods for adding or removing player entries in |player_map| under
988 // the key |render_frame_message_source_|.
989 typedef std::vector
<int64
> PlayerList
;
990 typedef std::map
<uintptr_t, PlayerList
> ActiveMediaPlayerMap
;
991 void AddMediaPlayerEntry(int64 player_cookie
,
992 ActiveMediaPlayerMap
* player_map
);
993 void RemoveMediaPlayerEntry(int64 player_cookie
,
994 ActiveMediaPlayerMap
* player_map
);
995 // Removes all entries from |player_map| for |render_frame_host|.
996 void RemoveAllMediaPlayerEntries(RenderFrameHost
* render_frame_host
,
997 ActiveMediaPlayerMap
* player_map
);
999 // Data for core operation ---------------------------------------------------
1001 // Delegate for notifying our owner about stuff. Not owned by us.
1002 WebContentsDelegate
* delegate_
;
1004 // Handles the back/forward list and loading.
1005 NavigationControllerImpl controller_
;
1007 // The corresponding view.
1008 scoped_ptr
<WebContentsView
> view_
;
1010 // The view of the RVHD. Usually this is our WebContentsView implementation,
1011 // but if an embedder uses a different WebContentsView, they'll need to
1013 RenderViewHostDelegateView
* render_view_host_delegate_view_
;
1015 // Tracks created WebContentsImpl objects that have not been shown yet. They
1016 // are identified by the route ID passed to CreateNewWindow.
1017 typedef std::map
<int, WebContentsImpl
*> PendingContents
;
1018 PendingContents pending_contents_
;
1020 // These maps hold on to the widgets that we created on behalf of the renderer
1021 // that haven't shown yet.
1022 typedef std::map
<int, RenderWidgetHostView
*> PendingWidgetViews
;
1023 PendingWidgetViews pending_widget_views_
;
1025 typedef std::map
<WebContentsImpl
*, DestructionObserver
*> DestructionObservers
;
1026 DestructionObservers destruction_observers_
;
1028 // A list of observers notified when page state changes. Weak references.
1029 // This MUST be listed above frame_tree_ since at destruction time the
1030 // latter might cause RenderViewHost's destructor to call us and we might use
1031 // the observer list then.
1032 base::ObserverList
<WebContentsObserver
> observers_
;
1034 // True if this tab was opened by another tab. This is not unset if the opener
1036 bool created_with_opener_
;
1039 gfx::NativeViewAccessible accessible_parent_
;
1042 // Helper classes ------------------------------------------------------------
1044 // Tracking variables and associated power save blockers for media playback.
1045 ActiveMediaPlayerMap active_audio_players_
;
1046 ActiveMediaPlayerMap active_video_players_
;
1047 scoped_ptr
<PowerSaveBlocker
> audio_power_save_blocker_
;
1048 scoped_ptr
<PowerSaveBlocker
> video_power_save_blocker_
;
1050 // Tells whether this WebContents is actively producing sound.
1051 // Order is important: the |frame_tree_| destruction uses
1052 // |audio_state_provider_|.
1053 scoped_ptr
<AudioStateProvider
> audio_state_provider_
;
1055 // Manages the frame tree of the page and process swaps in each node.
1056 FrameTree frame_tree_
;
1058 // If this WebContents is part of a "tree of WebContents", then this contains
1059 // information about the structure.
1060 scoped_ptr
<WebContentsTreeNode
> node_
;
1062 // SavePackage, lazily created.
1063 scoped_refptr
<SavePackage
> save_package_
;
1065 // Data for loading state ----------------------------------------------------
1067 // Indicates whether we're currently loading a resource.
1070 // Indicates whether the current load is to a different document. Only valid
1071 // if is_loading_ is true.
1072 bool is_load_to_different_document_
;
1074 // Indicates if the tab is considered crashed.
1075 base::TerminationStatus crashed_status_
;
1076 int crashed_error_code_
;
1078 // Whether this WebContents is waiting for a first-response for the
1079 // main resource of the page. This controls whether the throbber state is
1080 // "waiting" or "loading."
1081 bool waiting_for_response_
;
1083 // Map of SiteInstance ID to max page ID for this tab. A page ID is specific
1084 // to a given tab and SiteInstance, and must be valid for the lifetime of the
1086 std::map
<int32
, int32
> max_page_ids_
;
1088 // The current load state and the URL associated with it.
1089 net::LoadStateWithParam load_state_
;
1090 base::string16 load_state_host_
;
1092 base::TimeTicks loading_last_progress_update_
;
1094 // Upload progress, for displaying in the status bar.
1095 // Set to zero when there is no significant upload happening.
1096 uint64 upload_size_
;
1097 uint64 upload_position_
;
1099 // Tracks that this WebContents needs to unblock requests to the renderer.
1100 // See ResumeLoadingCreatedWebContents.
1101 bool is_resume_pending_
;
1103 // Data for current page -----------------------------------------------------
1105 // When a title cannot be taken from any entry, this title will be used.
1106 base::string16 page_title_when_no_navigation_entry_
;
1108 // When a navigation occurs, we record its contents MIME type. It can be
1109 // used to check whether we can do something for some special contents.
1110 std::string contents_mime_type_
;
1112 // The last reported character encoding, not canonicalized.
1113 std::string last_reported_encoding_
;
1115 // The canonicalized character encoding.
1116 std::string canonical_encoding_
;
1118 // True if this is a secure page which displayed insecure content.
1119 bool displayed_insecure_content_
;
1121 // Whether the initial empty page has been accessed by another page, making it
1122 // unsafe to show the pending URL. Usually false unless another window tries
1123 // to modify the blank page. Always false after the first commit.
1124 bool has_accessed_initial_document_
;
1126 // The theme color for the underlying document as specified
1127 // by theme-color meta tag.
1128 SkColor theme_color_
;
1130 // The last published theme color.
1131 SkColor last_sent_theme_color_
;
1133 // Whether the first visually non-empty paint has occurred.
1134 bool did_first_visually_non_empty_paint_
;
1136 // Data for misc internal state ----------------------------------------------
1138 // When > 0, the WebContents is currently being captured (e.g., for
1139 // screenshots or mirroring); and the underlying RenderWidgetHost should not
1140 // be told it is hidden.
1141 int capturer_count_
;
1143 // Tracks whether RWHV should be visible once capturer_count_ becomes zero.
1144 bool should_normally_be_visible_
;
1146 // See getter above.
1147 bool is_being_destroyed_
;
1149 // Indicates whether we should notify about disconnection of this
1150 // WebContentsImpl. This is used to ensure disconnection notifications only
1151 // happen if a connection notification has happened and that they happen only
1153 bool notify_disconnection_
;
1155 // Pointer to the JavaScript dialog manager, lazily assigned. Used because the
1156 // delegate of this WebContentsImpl is nulled before its destructor is called.
1157 JavaScriptDialogManager
* dialog_manager_
;
1159 // Set to true when there is an active "before unload" dialog. When true,
1160 // we've forced the throbber to start in Navigate, and we need to remember to
1161 // turn it off in OnJavaScriptMessageBoxClosed if the navigation is canceled.
1162 bool is_showing_before_unload_dialog_
;
1164 // Settings that get passed to the renderer process.
1165 RendererPreferences renderer_preferences_
;
1167 // The time that this WebContents was last made active. The initial value is
1168 // the WebContents creation time.
1169 base::TimeTicks last_active_time_
;
1171 // See description above setter.
1172 bool closed_by_user_gesture_
;
1174 // Minimum/maximum zoom percent.
1175 int minimum_zoom_percent_
;
1176 int maximum_zoom_percent_
;
1178 // The intrinsic size of the page.
1179 gfx::Size preferred_size_
;
1181 // The preferred size for content screen capture. When |capturer_count_| > 0,
1182 // this overrides |preferred_size_|.
1183 gfx::Size preferred_size_for_capture_
;
1185 #if defined(OS_ANDROID)
1186 // Date time chooser opened by this tab.
1187 // Only used in Android since all other platforms use a multi field UI.
1188 scoped_ptr
<DateTimeChooserAndroid
> date_time_chooser_
;
1191 // Holds information about a current color chooser dialog, if one is visible.
1192 struct ColorChooserInfo
{
1193 ColorChooserInfo(int render_process_id
,
1194 int render_frame_id
,
1195 ColorChooser
* chooser
,
1197 ~ColorChooserInfo();
1199 int render_process_id
;
1200 int render_frame_id
;
1202 // Color chooser that was opened by this tab.
1203 scoped_ptr
<ColorChooser
> chooser
;
1205 // A unique identifier for the current color chooser. Identifiers are
1206 // unique across a renderer process. This avoids race conditions in
1207 // synchronizing the browser and renderer processes. For example, if a
1208 // renderer closes one chooser and opens another, and simultaneously the
1209 // user picks a color in the first chooser, the IDs can be used to drop the
1210 // "chose a color" message rather than erroneously tell the renderer that
1211 // the user picked a color in the second chooser.
1215 scoped_ptr
<ColorChooserInfo
> color_chooser_info_
;
1217 // Manages the embedder state for browser plugins, if this WebContents is an
1218 // embedder; NULL otherwise.
1219 scoped_ptr
<BrowserPluginEmbedder
> browser_plugin_embedder_
;
1220 // Manages the guest state for browser plugin, if this WebContents is a guest;
1222 scoped_ptr
<BrowserPluginGuest
> browser_plugin_guest_
;
1224 #if defined(ENABLE_PLUGINS)
1225 // Manages the whitelist of plugin content origins exempt from power saving.
1226 scoped_ptr
<PluginContentOriginWhitelist
> plugin_content_origin_whitelist_
;
1229 // This must be at the end, or else we might get notifications and use other
1230 // member variables that are gone.
1231 NotificationRegistrar registrar_
;
1233 // Used during IPC message dispatching from the RenderView/RenderFrame so that
1234 // the handlers can get a pointer to the RVH through which the message was
1236 RenderViewHost
* render_view_message_source_
;
1237 RenderFrameHost
* render_frame_message_source_
;
1239 // All live RenderWidgetHostImpls that are created by this object and may
1241 std::set
<RenderWidgetHostImpl
*> created_widgets_
;
1243 // Routing id of the shown fullscreen widget or MSG_ROUTING_NONE otherwise.
1244 int fullscreen_widget_routing_id_
;
1246 // At the time the fullscreen widget was being shut down, did it have focus?
1247 // This is used to restore focus to the WebContentsView after both: 1) the
1248 // fullscreen widget is destroyed, and 2) the WebContentsDelegate has
1249 // completed making layout changes to effect an exit from fullscreen mode.
1250 bool fullscreen_widget_had_focus_at_shutdown_
;
1252 // Whether this WebContents is responsible for displaying a subframe in a
1253 // different process from its parent page.
1256 // When a new tab is created asynchronously, stores the OpenURLParams needed
1257 // to continue loading the page once the tab is ready.
1258 scoped_ptr
<OpenURLParams
> delayed_open_url_params_
;
1260 // Whether overscroll should be unconditionally disabled.
1261 bool force_disable_overscroll_content_
;
1263 // Whether the last JavaScript dialog shown was suppressed. Used for testing.
1264 bool last_dialog_suppressed_
;
1266 scoped_ptr
<GeolocationServiceContext
> geolocation_service_context_
;
1268 scoped_ptr
<ScreenOrientationDispatcherHost
>
1269 screen_orientation_dispatcher_host_
;
1271 scoped_ptr
<ManifestManagerHost
> manifest_manager_host_
;
1273 // The accessibility mode for all frames. This is queried when each frame
1274 // is created, and broadcast to all frames when it changes.
1275 AccessibilityMode accessibility_mode_
;
1277 // Created on-demand to mute all audio output from this WebContents.
1278 scoped_ptr
<WebContentsAudioMuter
> audio_muter_
;
1280 bool virtual_keyboard_requested_
;
1282 #if defined(ENABLE_BROWSER_CDMS)
1283 // Manages all the media player and CDM managers and forwards IPCs to them.
1284 scoped_ptr
<MediaWebContentsObserver
> media_web_contents_observer_
;
1287 base::WeakPtrFactory
<WebContentsImpl
> loading_weak_factory_
;
1289 DISALLOW_COPY_AND_ASSIGN(WebContentsImpl
);
1292 // Dangerous methods which should never be made part of the public API, so we
1293 // grant their use only to an explicit friend list (c++ attorney/client idiom).
1294 class CONTENT_EXPORT
WebContentsImpl::FriendZone
{
1296 friend class TestNavigationObserver
;
1297 friend class WebContentsAddedObserver
;
1298 friend class ContentBrowserSanityChecker
;
1300 FriendZone(); // Not instantiable.
1302 // Adds/removes a callback called on creation of each new WebContents.
1303 static void AddCreatedCallbackForTesting(const CreatedCallback
& callback
);
1304 static void RemoveCreatedCallbackForTesting(const CreatedCallback
& callback
);
1306 DISALLOW_COPY_AND_ASSIGN(FriendZone
);
1309 } // namespace content
1311 #endif // CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_IMPL_H_