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