Supervised user whitelists: Cleanup
[chromium-blink-merge.git] / content / browser / web_contents / web_contents_impl.h
bloba3780b0906d307be5df4388eddbd6cdeefd3b181
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/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;
48 namespace content {
49 class BrowserPluginEmbedder;
50 class BrowserPluginGuest;
51 class BrowserPluginGuestManager;
52 class DateTimeChooserAndroid;
53 class DownloadItem;
54 class GeolocationServiceContext;
55 class InterstitialPageImpl;
56 class JavaScriptDialogManager;
57 class ManifestManagerHost;
58 class MediaWebContentsObserver;
59 class PluginContentOriginWhitelist;
60 class PowerSaveBlocker;
61 class RenderViewHost;
62 class RenderViewHostDelegateView;
63 class RenderWidgetHostImpl;
64 class SavePackage;
65 class ScreenOrientationDispatcherHost;
66 class SiteInstance;
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;
76 struct FaviconURL;
77 struct LoadNotificationDetails;
78 struct ResourceRedirectDetails;
79 struct ResourceRequestDetails;
81 #if defined(OS_ANDROID)
82 class WebContentsAndroid;
83 #endif
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) {
101 public:
102 class FriendZone;
104 ~WebContentsImpl() override;
106 static WebContentsImpl* CreateWithOpener(
107 const WebContents::CreateParams& params,
108 WebContentsImpl* opener);
110 static std::vector<WebContentsImpl*> GetAllWebContents();
112 // Returns the opener WebContentsImpl, if any. This can be set to null if the
113 // opener is closed or the page clears its window.opener.
114 WebContentsImpl* opener() const { return opener_; }
116 // Creates a swapped out RenderView. This is used by the browser plugin to
117 // create a swapped out RenderView in the embedder render process for the
118 // guest, to expose the guest's window object to the embedder.
119 // This returns the routing ID of the newly created swapped out RenderView.
120 int CreateSwappedOutRenderView(SiteInstance* instance);
122 // Complex initialization here. Specifically needed to avoid having
123 // members call back into our virtual functions in the constructor.
124 virtual void Init(const WebContents::CreateParams& params);
126 // Returns the SavePackage which manages the page saving job. May be NULL.
127 SavePackage* save_package() const { return save_package_.get(); }
129 #if defined(OS_ANDROID)
130 // In Android WebView, the RenderView needs created even there is no
131 // navigation entry, this allows Android WebViews to use
132 // javascript: URLs that load into the DOMWindow before the first page
133 // load. This is not safe to do in any context that a web page could get a
134 // reference to the DOMWindow before the first page load.
135 bool CreateRenderViewForInitialEmptyDocument();
136 #endif
138 // Expose the render manager for testing.
139 // TODO(creis): Remove this now that we can get to it via FrameTreeNode.
140 RenderFrameHostManager* GetRenderManagerForTesting();
142 // Returns guest browser plugin object, or NULL if this WebContents is not a
143 // guest.
144 BrowserPluginGuest* GetBrowserPluginGuest() const;
146 // Sets a BrowserPluginGuest object for this WebContents. If this WebContents
147 // has a BrowserPluginGuest then that implies that it is being hosted by
148 // a BrowserPlugin object in an embedder renderer process.
149 void SetBrowserPluginGuest(BrowserPluginGuest* guest);
151 // Returns embedder browser plugin object, or NULL if this WebContents is not
152 // an embedder.
153 BrowserPluginEmbedder* GetBrowserPluginEmbedder() const;
155 // Creates a BrowserPluginEmbedder object for this WebContents if one doesn't
156 // already exist.
157 void CreateBrowserPluginEmbedderIfNecessary();
159 // Gets the current fullscreen render widget's routing ID. Returns
160 // MSG_ROUTING_NONE when there is no fullscreen render widget.
161 int GetFullscreenWidgetRoutingID() const;
163 // Invoked when visible SSL state (as defined by SSLStatus) changes.
164 void DidChangeVisibleSSLState();
166 // Informs the render view host and the BrowserPluginEmbedder, if present, of
167 // a Drag Source End.
168 void DragSourceEndedAt(int client_x, int client_y, int screen_x,
169 int screen_y, blink::WebDragOperation operation);
171 // A response has been received for a resource request.
172 void DidGetResourceResponseStart(
173 const ResourceRequestDetails& details);
175 // A redirect was received while requesting a resource.
176 void DidGetRedirectForResourceRequest(
177 RenderFrameHost* render_frame_host,
178 const ResourceRedirectDetails& details);
180 // Notify observers that the web contents has been focused.
181 void NotifyWebContentsFocused();
183 WebContentsView* GetView() const;
185 ScreenOrientationDispatcherHost* screen_orientation_dispatcher_host() {
186 return screen_orientation_dispatcher_host_.get();
189 bool should_normally_be_visible() { return should_normally_be_visible_; }
191 // Indicate if the window has been occluded, and pass this to the views, only
192 // if there is no active capture going on (otherwise it is dropped on the
193 // floor).
194 void WasOccluded();
195 void WasUnOccluded();
197 // Broadcasts the mode change to all frames.
198 void SetAccessibilityMode(AccessibilityMode mode);
200 // Adds the given accessibility mode to the current accessibility mode
201 // bitmap.
202 void AddAccessibilityMode(AccessibilityMode mode);
204 // Removes the given accessibility mode from the current accessibility
205 // mode bitmap, managing the bits that are shared with other modes such
206 // that a bit will only be turned off when all modes that depend on it
207 // have been removed.
208 void RemoveAccessibilityMode(AccessibilityMode mode);
210 // Request a one-time snapshot of the accessibility tree without changing
211 // the accessibility mode.
212 typedef base::Callback<void(const ui::AXTreeUpdate&)>
213 AXTreeSnapshotCallback;
214 void RequestAXTreeSnapshot(AXTreeSnapshotCallback callback);
216 // Clear the navigation transition data when the user navigates back to Chrome
217 // from a native app.
218 void ClearNavigationTransitionData();
220 // WebContents ------------------------------------------------------
221 WebContentsDelegate* GetDelegate() override;
222 void SetDelegate(WebContentsDelegate* delegate) override;
223 NavigationControllerImpl& GetController() override;
224 const NavigationControllerImpl& GetController() const override;
225 BrowserContext* GetBrowserContext() const override;
226 const GURL& GetURL() const override;
227 const GURL& GetVisibleURL() const override;
228 const GURL& GetLastCommittedURL() const override;
229 RenderProcessHost* GetRenderProcessHost() const override;
230 RenderFrameHostImpl* GetMainFrame() override;
231 RenderFrameHost* GetFocusedFrame() override;
232 void ForEachFrame(
233 const base::Callback<void(RenderFrameHost*)>& on_frame) override;
234 void SendToAllFrames(IPC::Message* message) override;
235 RenderViewHostImpl* GetRenderViewHost() const override;
236 int GetRoutingID() const override;
237 RenderWidgetHostView* GetRenderWidgetHostView() const override;
238 RenderWidgetHostView* GetFullscreenRenderWidgetHostView() const override;
239 SkColor GetThemeColor() const override;
240 WebUI* CreateWebUI(const GURL& url) override;
241 WebUI* GetWebUI() const override;
242 WebUI* GetCommittedWebUI() const override;
243 void SetUserAgentOverride(const std::string& override) override;
244 const std::string& GetUserAgentOverride() const override;
245 void EnableTreeOnlyAccessibilityMode() override;
246 bool IsTreeOnlyAccessibilityModeForTesting() const override;
247 bool IsFullAccessibilityModeForTesting() const override;
248 #if defined(OS_WIN)
249 virtual void SetParentNativeViewAccessible(
250 gfx::NativeViewAccessible accessible_parent) override;
251 #endif
252 const base::string16& GetTitle() const override;
253 int32 GetMaxPageID() override;
254 int32 GetMaxPageIDForSiteInstance(SiteInstance* site_instance) override;
255 SiteInstanceImpl* GetSiteInstance() const override;
256 SiteInstanceImpl* GetPendingSiteInstance() const override;
257 bool IsLoading() const override;
258 bool IsLoadingToDifferentDocument() const override;
259 bool IsWaitingForResponse() const override;
260 const net::LoadStateWithParam& GetLoadState() const override;
261 const base::string16& GetLoadStateHost() const override;
262 uint64 GetUploadSize() const override;
263 uint64 GetUploadPosition() const override;
264 std::set<GURL> GetSitesInTab() const override;
265 const std::string& GetEncoding() const override;
266 bool DisplayedInsecureContent() const override;
267 void IncrementCapturerCount(const gfx::Size& capture_size) override;
268 void DecrementCapturerCount() override;
269 int GetCapturerCount() const override;
270 bool IsAudioMuted() const override;
271 void SetAudioMuted(bool mute) override;
272 bool IsCrashed() const override;
273 void SetIsCrashed(base::TerminationStatus status, int error_code) override;
274 base::TerminationStatus GetCrashedStatus() const override;
275 bool IsBeingDestroyed() const override;
276 void NotifyNavigationStateChanged(InvalidateTypes changed_flags) override;
277 base::TimeTicks GetLastActiveTime() const override;
278 void WasShown() override;
279 void WasHidden() override;
280 bool NeedToFireBeforeUnload() override;
281 void DispatchBeforeUnload(bool for_cross_site_transition) override;
282 void Stop() override;
283 WebContents* Clone() override;
284 void ReloadFocusedFrame(bool ignore_cache) override;
285 void Undo() override;
286 void Redo() override;
287 void Cut() override;
288 void Copy() override;
289 void CopyToFindPboard() override;
290 void Paste() override;
291 void PasteAndMatchStyle() override;
292 void Delete() override;
293 void SelectAll() override;
294 void Unselect() override;
295 void Replace(const base::string16& word) override;
296 void ReplaceMisspelling(const base::string16& word) override;
297 void NotifyContextMenuClosed(
298 const CustomContextMenuContext& context) override;
299 void ExecuteCustomContextMenuCommand(
300 int action,
301 const CustomContextMenuContext& context) override;
302 gfx::NativeView GetNativeView() override;
303 gfx::NativeView GetContentNativeView() override;
304 gfx::NativeWindow GetTopLevelNativeWindow() override;
305 gfx::Rect GetContainerBounds() override;
306 gfx::Rect GetViewBounds() override;
307 DropData* GetDropData() override;
308 void Focus() override;
309 void SetInitialFocus() override;
310 void StoreFocus() override;
311 void RestoreFocus() override;
312 void FocusThroughTabTraversal(bool reverse) override;
313 bool ShowingInterstitialPage() const override;
314 InterstitialPage* GetInterstitialPage() const override;
315 bool IsSavable() override;
316 void OnSavePage() override;
317 bool SavePage(const base::FilePath& main_file,
318 const base::FilePath& dir_path,
319 SavePageType save_type) override;
320 void SaveFrame(const GURL& url, const Referrer& referrer) override;
321 void SaveFrameWithHeaders(const GURL& url,
322 const Referrer& referrer,
323 const std::string& headers) override;
324 void GenerateMHTML(const base::FilePath& file,
325 const base::Callback<void(int64)>& callback) override;
326 const std::string& GetContentsMimeType() const override;
327 bool WillNotifyDisconnection() const override;
328 void SetOverrideEncoding(const std::string& encoding) override;
329 void ResetOverrideEncoding() override;
330 RendererPreferences* GetMutableRendererPrefs() override;
331 void Close() override;
332 void SystemDragEnded() override;
333 void UserGestureDone() override;
334 void SetClosedByUserGesture(bool value) override;
335 bool GetClosedByUserGesture() const override;
336 void ViewSource() override;
337 void ViewFrameSource(const GURL& url, const PageState& page_state) override;
338 int GetMinimumZoomPercent() const override;
339 int GetMaximumZoomPercent() const override;
340 void ResetPageScale() override;
341 gfx::Size GetPreferredSize() const override;
342 bool GotResponseToLockMouseRequest(bool allowed) override;
343 bool HasOpener() const override;
344 WebContents* GetOpener() const override;
345 void DidChooseColorInColorChooser(SkColor color) override;
346 void DidEndColorChooser() override;
347 int DownloadImage(const GURL& url,
348 bool is_favicon,
349 uint32_t max_bitmap_size,
350 bool bypass_cache,
351 const ImageDownloadCallback& callback) override;
352 bool IsSubframe() const override;
353 void Find(int request_id,
354 const base::string16& search_text,
355 const blink::WebFindOptions& options) override;
356 void StopFinding(StopFindAction action) override;
357 void InsertCSS(const std::string& css) override;
358 bool WasRecentlyAudible() override;
359 void GetManifest(const GetManifestCallback&) override;
360 void ExitFullscreen() override;
361 #if defined(OS_ANDROID)
362 base::android::ScopedJavaLocalRef<jobject> GetJavaWebContents() override;
363 virtual WebContentsAndroid* GetWebContentsAndroid();
364 #elif defined(OS_MACOSX)
365 void SetAllowOtherViews(bool allow) override;
366 bool GetAllowOtherViews() override;
367 #endif
369 // Implementation of PageNavigator.
370 WebContents* OpenURL(const OpenURLParams& params) override;
372 // Implementation of IPC::Sender.
373 bool Send(IPC::Message* message) override;
375 // RenderFrameHostDelegate ---------------------------------------------------
376 bool OnMessageReceived(RenderFrameHost* render_frame_host,
377 const IPC::Message& message) override;
378 const GURL& GetMainFrameLastCommittedURL() const override;
379 void RenderFrameCreated(RenderFrameHost* render_frame_host) override;
380 void RenderFrameDeleted(RenderFrameHost* render_frame_host) override;
381 void SwappedOut(RenderFrameHost* render_frame_host) override;
382 void DidDeferAfterResponseStarted(
383 const TransitionLayerData& transition_data) override;
384 bool WillHandleDeferAfterResponseStarted() override;
385 void WorkerCrashed(RenderFrameHost* render_frame_host) override;
386 void ShowContextMenu(RenderFrameHost* render_frame_host,
387 const ContextMenuParams& params) override;
388 void RunJavaScriptMessage(RenderFrameHost* render_frame_host,
389 const base::string16& message,
390 const base::string16& default_prompt,
391 const GURL& frame_url,
392 JavaScriptMessageType type,
393 IPC::Message* reply_msg) override;
394 void RunBeforeUnloadConfirm(RenderFrameHost* render_frame_host,
395 const base::string16& message,
396 bool is_reload,
397 IPC::Message* reply_msg) override;
398 void DidAccessInitialDocument() override;
399 void DidChangeName(RenderFrameHost* render_frame_host,
400 const std::string& name) override;
401 void DidDisownOpener(RenderFrameHost* render_frame_host) override;
402 void DocumentOnLoadCompleted(RenderFrameHost* render_frame_host) override;
403 void UpdateTitle(RenderFrameHost* render_frame_host,
404 int32 page_id,
405 const base::string16& title,
406 base::i18n::TextDirection title_direction) override;
407 void UpdateEncoding(RenderFrameHost* render_frame_host,
408 const std::string& encoding) override;
409 WebContents* GetAsWebContents() override;
410 bool IsNeverVisible() override;
411 AccessibilityMode GetAccessibilityMode() const override;
412 void AccessibilityEventReceived(
413 const std::vector<AXEventNotificationDetails>& details) override;
414 RenderFrameHost* GetGuestByInstanceID(
415 RenderFrameHost* render_frame_host,
416 int browser_plugin_instance_id) override;
417 GeolocationServiceContext* GetGeolocationServiceContext() override;
418 void EnterFullscreenMode(const GURL& origin) override;
419 void ExitFullscreenMode() override;
420 bool ShouldRouteMessageEvent(
421 RenderFrameHost* target_rfh,
422 SiteInstance* source_site_instance) const override;
423 int EnsureOpenerRenderViewsExist(RenderFrameHost* source_rfh) override;
424 #if defined(OS_WIN)
425 gfx::NativeViewAccessible GetParentNativeViewAccessible() override;
426 #endif
428 // RenderViewHostDelegate ----------------------------------------------------
429 RenderViewHostDelegateView* GetDelegateView() override;
430 bool OnMessageReceived(RenderViewHost* render_view_host,
431 const IPC::Message& message) override;
432 // RenderFrameHostDelegate has the same method, so list it there because this
433 // interface is going away.
434 // virtual WebContents* GetAsWebContents() override;
435 gfx::Rect GetRootWindowResizerRect() const override;
436 void RenderViewCreated(RenderViewHost* render_view_host) override;
437 void RenderViewReady(RenderViewHost* render_view_host) override;
438 void RenderViewTerminated(RenderViewHost* render_view_host,
439 base::TerminationStatus status,
440 int error_code) override;
441 void RenderViewDeleted(RenderViewHost* render_view_host) override;
442 void UpdateState(RenderViewHost* render_view_host,
443 int32 page_id,
444 const PageState& page_state) override;
445 void UpdateTargetURL(RenderViewHost* render_view_host,
446 const GURL& url) override;
447 void Close(RenderViewHost* render_view_host) override;
448 void RequestMove(const gfx::Rect& new_bounds) override;
449 void DidCancelLoading() override;
450 void DocumentAvailableInMainFrame(RenderViewHost* render_view_host) override;
451 void RouteCloseEvent(RenderViewHost* rvh) override;
452 bool AddMessageToConsole(int32 level,
453 const base::string16& message,
454 int32 line_no,
455 const base::string16& source_id) override;
456 RendererPreferences GetRendererPrefs(
457 BrowserContext* browser_context) const override;
458 void OnUserGesture() override;
459 void OnIgnoredUIEvent() override;
460 void RendererUnresponsive(RenderViewHost* render_view_host) override;
461 void RendererResponsive(RenderViewHost* render_view_host) override;
462 void LoadStateChanged(const GURL& url,
463 const net::LoadStateWithParam& load_state,
464 uint64 upload_position,
465 uint64 upload_size) override;
466 void Activate() override;
467 void Deactivate() override;
468 void LostCapture() override;
469 void RunFileChooser(RenderViewHost* render_view_host,
470 const FileChooserParams& params) override;
471 bool IsFullscreenForCurrentTab() const override;
472 blink::WebDisplayMode GetDisplayMode() const override;
473 void UpdatePreferredSize(const gfx::Size& pref_size) override;
474 void ResizeDueToAutoResize(const gfx::Size& new_size) override;
475 void RequestToLockMouse(bool user_gesture,
476 bool last_unlocked_by_target) override;
477 void LostMouseLock() override;
478 void CreateNewWindow(
479 int render_process_id,
480 int route_id,
481 int main_frame_route_id,
482 const ViewHostMsg_CreateWindow_Params& params,
483 SessionStorageNamespace* session_storage_namespace) override;
484 void CreateNewWidget(int render_process_id,
485 int route_id,
486 blink::WebPopupType popup_type) override;
487 void CreateNewFullscreenWidget(int render_process_id, int route_id) override;
488 void ShowCreatedWindow(int route_id,
489 WindowOpenDisposition disposition,
490 const gfx::Rect& initial_rect,
491 bool user_gesture) override;
492 void ShowCreatedWidget(int route_id, const gfx::Rect& initial_rect) override;
493 void ShowCreatedFullscreenWidget(int route_id) override;
494 void RequestMediaAccessPermission(
495 const MediaStreamRequest& request,
496 const MediaResponseCallback& callback) override;
497 bool CheckMediaAccessPermission(const GURL& security_origin,
498 MediaStreamType type) override;
499 SessionStorageNamespace* GetSessionStorageNamespace(
500 SiteInstance* instance) override;
501 SessionStorageNamespaceMap GetSessionStorageNamespaceMap() override;
502 FrameTree* GetFrameTree() override;
503 void SetIsVirtualKeyboardRequested(bool requested) override;
504 bool IsVirtualKeyboardRequested() override;
507 // NavigatorDelegate ---------------------------------------------------------
509 void DidStartProvisionalLoad(RenderFrameHostImpl* render_frame_host,
510 const GURL& validated_url,
511 bool is_error_page,
512 bool is_iframe_srcdoc) override;
513 void DidStartNavigationTransition(
514 RenderFrameHostImpl* render_frame_host) override;
515 void DidFailProvisionalLoadWithError(
516 RenderFrameHostImpl* render_frame_host,
517 const FrameHostMsg_DidFailProvisionalLoadWithError_Params& params)
518 override;
519 void DidFailLoadWithError(RenderFrameHostImpl* render_frame_host,
520 const GURL& url,
521 int error_code,
522 const base::string16& error_description) override;
523 void DidCommitProvisionalLoad(RenderFrameHostImpl* render_frame_host,
524 const GURL& url,
525 ui::PageTransition transition_type) override;
526 void DidNavigateMainFramePreCommit(bool navigation_is_within_page) override;
527 void DidNavigateMainFramePostCommit(
528 RenderFrameHostImpl* render_frame_host,
529 const LoadCommittedDetails& details,
530 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) override;
531 void DidNavigateAnyFramePostCommit(
532 RenderFrameHostImpl* render_frame_host,
533 const LoadCommittedDetails& details,
534 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) override;
535 void SetMainFrameMimeType(const std::string& mime_type) override;
536 bool CanOverscrollContent() const override;
537 void NotifyChangedNavigationState(InvalidateTypes changed_flags) override;
538 void AboutToNavigateRenderFrame(
539 RenderFrameHostImpl* old_host,
540 RenderFrameHostImpl* new_host) override;
541 void DidStartNavigationToPendingEntry(
542 const GURL& url,
543 NavigationController::ReloadType reload_type) override;
544 void RequestOpenURL(RenderFrameHostImpl* render_frame_host,
545 const OpenURLParams& params) override;
546 bool ShouldPreserveAbortedURLs() override;
547 void DidStartLoading(FrameTreeNode* frame_tree_node,
548 bool to_different_document) override;
549 void DidStopLoading() override;
550 void DidChangeLoadProgress() override;
552 // RenderWidgetHostDelegate --------------------------------------------------
554 void RenderWidgetDeleted(RenderWidgetHostImpl* render_widget_host) override;
555 void RenderWidgetGotFocus(RenderWidgetHostImpl* render_widget_host) override;
556 void RenderWidgetWasResized(RenderWidgetHostImpl* render_widget_host,
557 bool width_changed) override;
558 void ScreenInfoChanged() override;
559 bool PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event,
560 bool* is_keyboard_shortcut) override;
561 void HandleKeyboardEvent(const NativeWebKeyboardEvent& event) override;
562 bool HandleWheelEvent(const blink::WebMouseWheelEvent& event) override;
563 bool PreHandleGestureEvent(const blink::WebGestureEvent& event) override;
564 void DidSendScreenRects(RenderWidgetHostImpl* rwh) override;
565 BrowserAccessibilityManager* GetRootBrowserAccessibilityManager() override;
566 BrowserAccessibilityManager* GetOrCreateRootBrowserAccessibilityManager()
567 override;
569 // RenderFrameHostManager::Delegate ------------------------------------------
571 bool CreateRenderViewForRenderManager(
572 RenderViewHost* render_view_host,
573 int opener_route_id,
574 int proxy_routing_id,
575 bool for_main_frame_navigation) override;
576 bool CreateRenderFrameForRenderManager(RenderFrameHost* render_frame_host,
577 int parent_routing_id,
578 int proxy_routing_id) override;
579 void BeforeUnloadFiredFromRenderManager(
580 bool proceed,
581 const base::TimeTicks& proceed_time,
582 bool* proceed_to_fire_unload) override;
583 void RenderProcessGoneFromRenderManager(
584 RenderViewHost* render_view_host) override;
585 void UpdateRenderViewSizeForRenderManager() override;
586 void CancelModalDialogsForRenderManager() override;
587 void NotifySwappedFromRenderManager(RenderFrameHost* old_host,
588 RenderFrameHost* new_host,
589 bool is_main_frame) override;
590 void NotifyMainFrameSwappedFromRenderManager(
591 RenderViewHost* old_host,
592 RenderViewHost* new_host) override;
593 int CreateOpenerRenderViewsForRenderManager(SiteInstance* instance) override;
594 NavigationControllerImpl& GetControllerForRenderManager() override;
595 scoped_ptr<WebUIImpl> CreateWebUIForRenderManager(const GURL& url) override;
596 NavigationEntry* GetLastCommittedNavigationEntryForRenderManager() override;
597 bool FocusLocationBarByDefault() override;
598 void SetFocusToLocationBar(bool select_all) override;
599 bool IsHidden() override;
601 // NotificationObserver ------------------------------------------------------
603 void Observe(int type,
604 const NotificationSource& source,
605 const NotificationDetails& details) override;
607 // NavigationControllerDelegate ----------------------------------------------
609 WebContents* GetWebContents() override;
610 void NotifyNavigationEntryCommitted(
611 const LoadCommittedDetails& load_details) override;
613 // Invoked before a form repost warning is shown.
614 void NotifyBeforeFormRepostWarningShow() override;
616 // Activate this WebContents and show a form repost warning.
617 void ActivateAndShowRepostFormWarningDialog() override;
619 // Whether the initial empty page of this view has been accessed by another
620 // page, making it unsafe to show the pending URL. Always false after the
621 // first commit.
622 bool HasAccessedInitialDocument() override;
624 // Updates the max page ID for the current SiteInstance in this
625 // WebContentsImpl to be at least |page_id|.
626 void UpdateMaxPageID(int32 page_id) override;
628 // Updates the max page ID for the given SiteInstance in this WebContentsImpl
629 // to be at least |page_id|.
630 void UpdateMaxPageIDForSiteInstance(SiteInstance* site_instance,
631 int32 page_id) override;
633 // Copy the current map of SiteInstance ID to max page ID from another tab.
634 // This is necessary when this tab adopts the NavigationEntries from
635 // |web_contents|.
636 void CopyMaxPageIDsFrom(WebContents* web_contents) override;
638 // Called by the NavigationController to cause the WebContentsImpl to navigate
639 // to the current pending entry. The NavigationController should be called
640 // back with RendererDidNavigate on success or DiscardPendingEntry on failure.
641 // The callbacks can be inside of this function, or at some future time.
643 // The entry has a PageID of -1 if newly created (corresponding to navigation
644 // to a new URL).
646 // If this method returns false, then the navigation is discarded (equivalent
647 // to calling DiscardPendingEntry on the NavigationController).
648 bool NavigateToPendingEntry(
649 NavigationController::ReloadType reload_type) override;
651 // Sets the history for this WebContentsImpl to |history_length| entries, with
652 // an offset of |history_offset|.
653 void SetHistoryOffsetAndLength(int history_offset,
654 int history_length) override;
656 // Called by InterstitialPageImpl when it creates a RenderFrameHost.
657 void RenderFrameForInterstitialPageCreated(
658 RenderFrameHost* render_frame_host) override;
660 // Sets the passed interstitial as the currently showing interstitial.
661 // No interstitial page should already be attached.
662 void AttachInterstitialPage(InterstitialPageImpl* interstitial_page) override;
664 // Unsets the currently showing interstitial.
665 void DetachInterstitialPage() override;
667 // Changes the IsLoading state and notifies the delegate as needed.
668 // |details| is used to provide details on the load that just finished
669 // (but can be null if not applicable).
670 void SetIsLoading(bool is_loading,
671 bool to_different_document,
672 LoadNotificationDetails* details) override;
674 typedef base::Callback<void(WebContents*)> CreatedCallback;
676 // Requests the renderer to move the selection extent to a new position.
677 void MoveRangeSelectionExtent(const gfx::Point& extent);
679 // Requests the renderer to select the region between two points in the
680 // currently focused frame.
681 void SelectRange(const gfx::Point& base, const gfx::Point& extent);
683 // Notifies the main frame that it can continue navigation (if it was deferred
684 // immediately at first response).
685 void ResumeResponseDeferredAtStart();
687 // Forces overscroll to be disabled (used by touch emulation).
688 void SetForceDisableOverscrollContent(bool force_disable);
690 AudioStateProvider* audio_state_provider() {
691 return audio_state_provider_.get();
694 bool has_audio_power_save_blocker_for_testing() const {
695 return audio_power_save_blocker_;
698 bool has_video_power_save_blocker_for_testing() const {
699 return video_power_save_blocker_;
702 #if defined(ENABLE_BROWSER_CDMS)
703 MediaWebContentsObserver* media_web_contents_observer() {
704 return media_web_contents_observer_.get();
706 #endif
708 private:
709 friend class WebContentsObserver;
710 friend class WebContents; // To implement factory methods.
712 FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest, NoJSMessageOnInterstitials);
713 FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest, UpdateTitle);
714 FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest, FindOpenerRVHWhenPending);
715 FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest,
716 CrossSiteCantPreemptAfterUnload);
717 FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest, PendingContents);
718 FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest, FrameTreeShape);
719 FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest, GetLastActiveTime);
720 FRIEND_TEST_ALL_PREFIXES(FormStructureBrowserTest, HTMLFiles);
721 FRIEND_TEST_ALL_PREFIXES(NavigationControllerTest, HistoryNavigate);
722 FRIEND_TEST_ALL_PREFIXES(RenderFrameHostManagerTest, PageDoesBackAndReload);
723 FRIEND_TEST_ALL_PREFIXES(SitePerProcessBrowserTest, CrossSiteIframe);
724 FRIEND_TEST_ALL_PREFIXES(SitePerProcessAccessibilityBrowserTest,
725 CrossSiteIframeAccessibility);
727 // So InterstitialPageImpl can access SetIsLoading.
728 friend class InterstitialPageImpl;
730 // TODO(brettw) TestWebContents shouldn't exist!
731 friend class TestWebContents;
733 class DestructionObserver;
735 // See WebContents::Create for a description of these parameters.
736 WebContentsImpl(BrowserContext* browser_context,
737 WebContentsImpl* opener);
739 // Add and remove observers for page navigation notifications. The order in
740 // which notifications are sent to observers is undefined. Clients must be
741 // sure to remove the observer before they go away.
742 void AddObserver(WebContentsObserver* observer);
743 void RemoveObserver(WebContentsObserver* observer);
745 // Clears this tab's opener if it has been closed.
746 void OnWebContentsDestroyed(WebContentsImpl* web_contents);
748 // Creates and adds to the map a destruction observer watching |web_contents|.
749 // No-op if such an observer already exists.
750 void AddDestructionObserver(WebContentsImpl* web_contents);
752 // Deletes and removes from the map a destruction observer
753 // watching |web_contents|. No-op if there is no such observer.
754 void RemoveDestructionObserver(WebContentsImpl* web_contents);
756 // Traverses all the RenderFrameHosts in the FrameTree and creates a set
757 // all the unique RenderWidgetHostViews.
758 std::set<RenderWidgetHostView*> GetRenderWidgetHostViewsInTree();
760 // Callback function when showing JavaScript dialogs. Takes in a routing ID
761 // pair to identify the RenderFrameHost that opened the dialog, because it's
762 // possible for the RenderFrameHost to be deleted by the time this is called.
763 void OnDialogClosed(int render_process_id,
764 int render_frame_id,
765 IPC::Message* reply_msg,
766 bool dialog_was_suppressed,
767 bool success,
768 const base::string16& user_input);
770 bool OnMessageReceived(RenderViewHost* render_view_host,
771 RenderFrameHost* render_frame_host,
772 const IPC::Message& message);
774 // Checks whether render_frame_message_source_ is set to non-null value,
775 // otherwise it terminates the main frame renderer process.
776 bool HasValidFrameSource();
778 // IPC message handlers.
779 void OnThemeColorChanged(SkColor theme_color);
780 void OnDidLoadResourceFromMemoryCache(const GURL& url,
781 const std::string& security_info,
782 const std::string& http_request,
783 const std::string& mime_type,
784 ResourceType resource_type);
785 void OnDidDisplayInsecureContent();
786 void OnDidRunInsecureContent(const std::string& security_origin,
787 const GURL& target_url);
788 void OnDocumentLoadedInFrame();
789 void OnDidFinishLoad(const GURL& url);
790 void OnGoToEntryAtOffset(int offset);
791 void OnUpdateZoomLimits(int minimum_percent,
792 int maximum_percent);
793 void OnEnumerateDirectory(int request_id, const base::FilePath& path);
795 void OnRegisterProtocolHandler(const std::string& protocol,
796 const GURL& url,
797 const base::string16& title,
798 bool user_gesture);
799 void OnUnregisterProtocolHandler(const std::string& protocol,
800 const GURL& url,
801 bool user_gesture);
802 void OnFindReply(int request_id,
803 int number_of_matches,
804 const gfx::Rect& selection_rect,
805 int active_match_ordinal,
806 bool final_update);
807 #if defined(OS_ANDROID)
808 void OnFindMatchRectsReply(int version,
809 const std::vector<gfx::RectF>& rects,
810 const gfx::RectF& active_rect);
812 void OnOpenDateTimeDialog(
813 const ViewHostMsg_DateTimeDialogValue_Params& value);
814 #endif
815 void OnDomOperationResponse(const std::string& json_string,
816 int automation_id);
817 void OnAppCacheAccessed(const GURL& manifest_url, bool blocked_by_policy);
818 void OnOpenColorChooser(int color_chooser_id,
819 SkColor color,
820 const std::vector<ColorSuggestion>& suggestions);
821 void OnEndColorChooser(int color_chooser_id);
822 void OnSetSelectedColorInColorChooser(int color_chooser_id, SkColor color);
823 void OnWebUISend(const GURL& source_url,
824 const std::string& name,
825 const base::ListValue& args);
826 #if defined(ENABLE_PLUGINS)
827 void OnPepperPluginHung(int plugin_child_id,
828 const base::FilePath& path,
829 bool is_hung);
830 void OnPluginCrashed(const base::FilePath& plugin_path,
831 base::ProcessId plugin_pid);
832 void OnRequestPpapiBrokerPermission(int routing_id,
833 const GURL& url,
834 const base::FilePath& plugin_path);
836 // Callback function when requesting permission to access the PPAPI broker.
837 // |result| is true if permission was granted.
838 void OnPpapiBrokerPermissionResult(int routing_id, bool result);
840 void OnBrowserPluginMessage(RenderFrameHost* render_frame_host,
841 const IPC::Message& message);
842 #endif // defined(ENABLE_PLUGINS)
843 void OnDidDownloadImage(int id,
844 int http_status_code,
845 const GURL& image_url,
846 const std::vector<SkBitmap>& bitmaps,
847 const std::vector<gfx::Size>& original_bitmap_sizes);
848 void OnUpdateFaviconURL(const std::vector<FaviconURL>& candidates);
849 void OnFirstVisuallyNonEmptyPaint();
850 void OnMediaPlayingNotification(int64 player_cookie,
851 bool has_video,
852 bool has_audio,
853 bool is_remote);
854 void OnMediaPausedNotification(int64 player_cookie);
855 void OnShowValidationMessage(const gfx::Rect& anchor_in_root_view,
856 const base::string16& main_text,
857 const base::string16& sub_text);
858 void OnHideValidationMessage();
859 void OnMoveValidationMessage(const gfx::Rect& anchor_in_root_view);
861 // Called by derived classes to indicate that we're no longer waiting for a
862 // response. This won't actually update the throbber, but it will get picked
863 // up at the next animation step if the throbber is going.
864 void SetNotWaitingForResponse() { waiting_for_response_ = false; }
866 // Navigation helpers --------------------------------------------------------
868 // These functions are helpers for Navigate() and DidNavigate().
870 // Handles post-navigation tasks in DidNavigate AFTER the entry has been
871 // committed to the navigation controller. Note that the navigation entry is
872 // not provided since it may be invalid/changed after being committed. The
873 // current navigation entry is in the NavigationController at this point.
875 // If our controller was restored, update the max page ID associated with the
876 // given RenderViewHost to be larger than the number of restored entries.
877 // This is called in CreateRenderView before any navigations in the RenderView
878 // have begun, to prevent any races in updating RenderView::next_page_id.
879 void UpdateMaxPageIDIfNecessary(RenderViewHost* rvh);
881 // Saves the given title to the navigation entry and does associated work. It
882 // will update history and the view for the new title, and also synthesize
883 // titles for file URLs that have none (so we require that the URL of the
884 // entry already be set).
886 // This is used as the backend for state updates, which include a new title,
887 // or the dedicated set title message. It returns true if the new title is
888 // different and was therefore updated.
889 bool UpdateTitleForEntry(NavigationEntryImpl* entry,
890 const base::string16& title);
892 // Recursively creates swapped out RenderViews for this tab's opener chain
893 // (including this tab) in the given SiteInstance, allowing other tabs to send
894 // cross-process JavaScript calls to their opener(s). Returns the route ID of
895 // this tab's RenderView for |instance|.
896 int CreateOpenerRenderViews(SiteInstance* instance);
898 // Helper for CreateNewWidget/CreateNewFullscreenWidget.
899 void CreateNewWidget(int render_process_id,
900 int route_id,
901 bool is_fullscreen,
902 blink::WebPopupType popup_type);
904 // Helper for ShowCreatedWidget/ShowCreatedFullscreenWidget.
905 void ShowCreatedWidget(int route_id,
906 bool is_fullscreen,
907 const gfx::Rect& initial_rect);
909 // Finds the new RenderWidgetHost and returns it. Note that this can only be
910 // called once as this call also removes it from the internal map.
911 RenderWidgetHostView* GetCreatedWidget(int route_id);
913 // Finds the new WebContentsImpl by route_id, initializes it for
914 // renderer-initiated creation, and returns it. Note that this can only be
915 // called once as this call also removes it from the internal map.
916 WebContentsImpl* GetCreatedWindow(int route_id);
918 // Tracking loading progress -------------------------------------------------
920 // Resets the tracking state of the current load progress.
921 void ResetLoadProgressState();
923 // Notifies the delegate that the load progress was updated.
924 void SendChangeLoadProgress();
926 // Misc non-view stuff -------------------------------------------------------
928 // Sets the history for a specified RenderViewHost to |history_length|
929 // entries, with an offset of |history_offset|.
930 void SetHistoryOffsetAndLengthForView(RenderViewHost* render_view_host,
931 int history_offset,
932 int history_length);
934 // Helper functions for sending notifications.
935 void NotifyViewSwapped(RenderViewHost* old_host, RenderViewHost* new_host);
936 void NotifyFrameSwapped(RenderFrameHost* old_host, RenderFrameHost* new_host);
937 void NotifyDisconnected();
939 void SetEncoding(const std::string& encoding);
941 // TODO(creis): This should take in a FrameTreeNode to know which node's
942 // render manager to return. For now, we just return the root's.
943 RenderFrameHostManager* GetRenderManager() const;
945 // Removes browser plugin embedder if there is one.
946 void RemoveBrowserPluginEmbedder();
948 // Clear |render_frame_host|'s tracking entry for its power save blockers.
949 void ClearPowerSaveBlockers(RenderFrameHost* render_frame_host);
951 // Clear tracking entries for all RenderFrameHosts, clears
952 // |audio_power_save_blocker_| and |video_power_save_blocker_|.
953 void ClearAllPowerSaveBlockers();
955 // Creates an audio or video power save blocker respectively.
956 void CreateAudioPowerSaveBlocker();
957 void CreateVideoPowerSaveBlocker();
959 // Releases the audio power save blockers if |active_audio_players_| is empty.
960 // Likewise, releases the video power save blockers if |active_video_players_|
961 // is empty.
962 void MaybeReleasePowerSaveBlockers();
964 // Helper function to invoke WebContentsDelegate::GetSizeForNewRenderView().
965 gfx::Size GetSizeForNewRenderView();
967 void OnFrameRemoved(RenderFrameHost* render_frame_host);
969 // Helper method that's called whenever |preferred_size_| or
970 // |preferred_size_for_capture_| changes, to propagate the new value to the
971 // |delegate_|.
972 void OnPreferredSizeChanged(const gfx::Size& old_size);
974 // Helper methods for adding or removing player entries in |player_map| under
975 // the key |render_frame_message_source_|.
976 typedef std::vector<int64> PlayerList;
977 typedef std::map<uintptr_t, PlayerList> ActiveMediaPlayerMap;
978 void AddMediaPlayerEntry(int64 player_cookie,
979 ActiveMediaPlayerMap* player_map);
980 void RemoveMediaPlayerEntry(int64 player_cookie,
981 ActiveMediaPlayerMap* player_map);
982 // Removes all entries from |player_map| for |render_frame_host|.
983 void RemoveAllMediaPlayerEntries(RenderFrameHost* render_frame_host,
984 ActiveMediaPlayerMap* player_map);
986 // Data for core operation ---------------------------------------------------
988 // Delegate for notifying our owner about stuff. Not owned by us.
989 WebContentsDelegate* delegate_;
991 // Handles the back/forward list and loading.
992 NavigationControllerImpl controller_;
994 // The corresponding view.
995 scoped_ptr<WebContentsView> view_;
997 // The view of the RVHD. Usually this is our WebContentsView implementation,
998 // but if an embedder uses a different WebContentsView, they'll need to
999 // provide this.
1000 RenderViewHostDelegateView* render_view_host_delegate_view_;
1002 // Tracks created WebContentsImpl objects that have not been shown yet. They
1003 // are identified by the route ID passed to CreateNewWindow.
1004 typedef std::map<int, WebContentsImpl*> PendingContents;
1005 PendingContents pending_contents_;
1007 // These maps hold on to the widgets that we created on behalf of the renderer
1008 // that haven't shown yet.
1009 typedef std::map<int, RenderWidgetHostView*> PendingWidgetViews;
1010 PendingWidgetViews pending_widget_views_;
1012 typedef std::map<WebContentsImpl*, DestructionObserver*> DestructionObservers;
1013 DestructionObservers destruction_observers_;
1015 // A list of observers notified when page state changes. Weak references.
1016 // This MUST be listed above frame_tree_ since at destruction time the
1017 // latter might cause RenderViewHost's destructor to call us and we might use
1018 // the observer list then.
1019 ObserverList<WebContentsObserver> observers_;
1021 // The tab that opened this tab, if any. Will be set to null if the opener
1022 // is closed.
1023 WebContentsImpl* opener_;
1025 // True if this tab was opened by another tab. This is not unset if the opener
1026 // is closed.
1027 bool created_with_opener_;
1029 #if defined(OS_WIN)
1030 gfx::NativeViewAccessible accessible_parent_;
1031 #endif
1033 // Helper classes ------------------------------------------------------------
1035 // Tracking variables and associated power save blockers for media playback.
1036 ActiveMediaPlayerMap active_audio_players_;
1037 ActiveMediaPlayerMap active_video_players_;
1038 scoped_ptr<PowerSaveBlocker> audio_power_save_blocker_;
1039 scoped_ptr<PowerSaveBlocker> video_power_save_blocker_;
1041 // Tells whether this WebContents is actively producing sound.
1042 // Order is important: the |frame_tree_| destruction uses
1043 // |audio_state_provider_|.
1044 scoped_ptr<AudioStateProvider> audio_state_provider_;
1046 // Manages the frame tree of the page and process swaps in each node.
1047 FrameTree frame_tree_;
1049 // SavePackage, lazily created.
1050 scoped_refptr<SavePackage> save_package_;
1052 // Data for loading state ----------------------------------------------------
1054 // Indicates whether we're currently loading a resource.
1055 bool is_loading_;
1057 // Indicates whether the current load is to a different document. Only valid
1058 // if is_loading_ is true.
1059 bool is_load_to_different_document_;
1061 // Indicates if the tab is considered crashed.
1062 base::TerminationStatus crashed_status_;
1063 int crashed_error_code_;
1065 // Whether this WebContents is waiting for a first-response for the
1066 // main resource of the page. This controls whether the throbber state is
1067 // "waiting" or "loading."
1068 bool waiting_for_response_;
1070 // Map of SiteInstance ID to max page ID for this tab. A page ID is specific
1071 // to a given tab and SiteInstance, and must be valid for the lifetime of the
1072 // WebContentsImpl.
1073 std::map<int32, int32> max_page_ids_;
1075 // The current load state and the URL associated with it.
1076 net::LoadStateWithParam load_state_;
1077 base::string16 load_state_host_;
1079 base::TimeTicks loading_last_progress_update_;
1081 // Upload progress, for displaying in the status bar.
1082 // Set to zero when there is no significant upload happening.
1083 uint64 upload_size_;
1084 uint64 upload_position_;
1086 // Data for current page -----------------------------------------------------
1088 // When a title cannot be taken from any entry, this title will be used.
1089 base::string16 page_title_when_no_navigation_entry_;
1091 // When a navigation occurs, we record its contents MIME type. It can be
1092 // used to check whether we can do something for some special contents.
1093 std::string contents_mime_type_;
1095 // The last reported character encoding, not canonicalized.
1096 std::string last_reported_encoding_;
1098 // The canonicalized character encoding.
1099 std::string canonical_encoding_;
1101 // True if this is a secure page which displayed insecure content.
1102 bool displayed_insecure_content_;
1104 // Whether the initial empty page has been accessed by another page, making it
1105 // unsafe to show the pending URL. Usually false unless another window tries
1106 // to modify the blank page. Always false after the first commit.
1107 bool has_accessed_initial_document_;
1109 // The theme color for the underlying document as specified
1110 // by theme-color meta tag.
1111 SkColor theme_color_;
1113 // The last published theme color.
1114 SkColor last_sent_theme_color_;
1116 // Data for misc internal state ----------------------------------------------
1118 // When > 0, the WebContents is currently being captured (e.g., for
1119 // screenshots or mirroring); and the underlying RenderWidgetHost should not
1120 // be told it is hidden.
1121 int capturer_count_;
1123 // Tracks whether RWHV should be visible once capturer_count_ becomes zero.
1124 bool should_normally_be_visible_;
1126 // See getter above.
1127 bool is_being_destroyed_;
1129 // Indicates whether we should notify about disconnection of this
1130 // WebContentsImpl. This is used to ensure disconnection notifications only
1131 // happen if a connection notification has happened and that they happen only
1132 // once.
1133 bool notify_disconnection_;
1135 // Pointer to the JavaScript dialog manager, lazily assigned. Used because the
1136 // delegate of this WebContentsImpl is nulled before its destructor is called.
1137 JavaScriptDialogManager* dialog_manager_;
1139 // Set to true when there is an active "before unload" dialog. When true,
1140 // we've forced the throbber to start in Navigate, and we need to remember to
1141 // turn it off in OnJavaScriptMessageBoxClosed if the navigation is canceled.
1142 bool is_showing_before_unload_dialog_;
1144 // Settings that get passed to the renderer process.
1145 RendererPreferences renderer_preferences_;
1147 // The time that this WebContents was last made active. The initial value is
1148 // the WebContents creation time.
1149 base::TimeTicks last_active_time_;
1151 // See description above setter.
1152 bool closed_by_user_gesture_;
1154 // Minimum/maximum zoom percent.
1155 int minimum_zoom_percent_;
1156 int maximum_zoom_percent_;
1158 // The intrinsic size of the page.
1159 gfx::Size preferred_size_;
1161 // The preferred size for content screen capture. When |capturer_count_| > 0,
1162 // this overrides |preferred_size_|.
1163 gfx::Size preferred_size_for_capture_;
1165 #if defined(OS_ANDROID)
1166 // Date time chooser opened by this tab.
1167 // Only used in Android since all other platforms use a multi field UI.
1168 scoped_ptr<DateTimeChooserAndroid> date_time_chooser_;
1169 #endif
1171 // Holds information about a current color chooser dialog, if one is visible.
1172 struct ColorChooserInfo {
1173 ColorChooserInfo(int render_process_id,
1174 int render_frame_id,
1175 ColorChooser* chooser,
1176 int identifier);
1177 ~ColorChooserInfo();
1179 int render_process_id;
1180 int render_frame_id;
1182 // Color chooser that was opened by this tab.
1183 scoped_ptr<ColorChooser> chooser;
1185 // A unique identifier for the current color chooser. Identifiers are
1186 // unique across a renderer process. This avoids race conditions in
1187 // synchronizing the browser and renderer processes. For example, if a
1188 // renderer closes one chooser and opens another, and simultaneously the
1189 // user picks a color in the first chooser, the IDs can be used to drop the
1190 // "chose a color" message rather than erroneously tell the renderer that
1191 // the user picked a color in the second chooser.
1192 int identifier;
1195 scoped_ptr<ColorChooserInfo> color_chooser_info_;
1197 // Manages the embedder state for browser plugins, if this WebContents is an
1198 // embedder; NULL otherwise.
1199 scoped_ptr<BrowserPluginEmbedder> browser_plugin_embedder_;
1200 // Manages the guest state for browser plugin, if this WebContents is a guest;
1201 // NULL otherwise.
1202 scoped_ptr<BrowserPluginGuest> browser_plugin_guest_;
1204 #if defined(ENABLE_PLUGINS)
1205 // Manages the whitelist of plugin content origins exempt from power saving.
1206 scoped_ptr<PluginContentOriginWhitelist> plugin_content_origin_whitelist_;
1207 #endif
1209 // This must be at the end, or else we might get notifications and use other
1210 // member variables that are gone.
1211 NotificationRegistrar registrar_;
1213 // Used during IPC message dispatching from the RenderView/RenderFrame so that
1214 // the handlers can get a pointer to the RVH through which the message was
1215 // received.
1216 RenderViewHost* render_view_message_source_;
1217 RenderFrameHost* render_frame_message_source_;
1219 // All live RenderWidgetHostImpls that are created by this object and may
1220 // outlive it.
1221 std::set<RenderWidgetHostImpl*> created_widgets_;
1223 // Routing id of the shown fullscreen widget or MSG_ROUTING_NONE otherwise.
1224 int fullscreen_widget_routing_id_;
1226 // At the time the fullscreen widget was being shut down, did it have focus?
1227 // This is used to restore focus to the WebContentsView after both: 1) the
1228 // fullscreen widget is destroyed, and 2) the WebContentsDelegate has
1229 // completed making layout changes to effect an exit from fullscreen mode.
1230 bool fullscreen_widget_had_focus_at_shutdown_;
1232 // Maps the ids of pending image downloads to their callbacks
1233 typedef std::map<int, ImageDownloadCallback> ImageDownloadMap;
1234 ImageDownloadMap image_download_map_;
1236 // Whether this WebContents is responsible for displaying a subframe in a
1237 // different process from its parent page.
1238 bool is_subframe_;
1240 // Whether overscroll should be unconditionally disabled.
1241 bool force_disable_overscroll_content_;
1243 // Whether the last JavaScript dialog shown was suppressed. Used for testing.
1244 bool last_dialog_suppressed_;
1246 scoped_ptr<GeolocationServiceContext> geolocation_service_context_;
1248 scoped_ptr<ScreenOrientationDispatcherHost>
1249 screen_orientation_dispatcher_host_;
1251 scoped_ptr<ManifestManagerHost> manifest_manager_host_;
1253 // The accessibility mode for all frames. This is queried when each frame
1254 // is created, and broadcast to all frames when it changes.
1255 AccessibilityMode accessibility_mode_;
1257 // Created on-demand to mute all audio output from this WebContents.
1258 scoped_ptr<WebContentsAudioMuter> audio_muter_;
1260 bool virtual_keyboard_requested_;
1262 #if defined(ENABLE_BROWSER_CDMS)
1263 // Manages all the media player and CDM managers and forwards IPCs to them.
1264 scoped_ptr<MediaWebContentsObserver> media_web_contents_observer_;
1265 #endif
1267 base::WeakPtrFactory<WebContentsImpl> loading_weak_factory_;
1269 DISALLOW_COPY_AND_ASSIGN(WebContentsImpl);
1272 // Dangerous methods which should never be made part of the public API, so we
1273 // grant their use only to an explicit friend list (c++ attorney/client idiom).
1274 class CONTENT_EXPORT WebContentsImpl::FriendZone {
1275 private:
1276 friend class TestNavigationObserver;
1277 friend class WebContentsAddedObserver;
1278 friend class ContentBrowserSanityChecker;
1280 FriendZone(); // Not instantiable.
1282 // Adds/removes a callback called on creation of each new WebContents.
1283 static void AddCreatedCallbackForTesting(const CreatedCallback& callback);
1284 static void RemoveCreatedCallbackForTesting(const CreatedCallback& callback);
1286 DISALLOW_COPY_AND_ASSIGN(FriendZone);
1289 } // namespace content
1291 #endif // CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_IMPL_H_