Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(219)

Side by Side Diff: content/browser/frame_host/render_frame_host_impl.h

Issue 1352813006: Move WebUI ownership from the RenderFrameHostManager to the RenderFrameHost. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Doesn't try to create a WebUI if URL is invalid (fixes unit_tests). Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CONTENT_BROWSER_FRAME_HOST_RENDER_FRAME_HOST_IMPL_H_ 5 #ifndef CONTENT_BROWSER_FRAME_HOST_RENDER_FRAME_HOST_IMPL_H_
6 #define CONTENT_BROWSER_FRAME_HOST_RENDER_FRAME_HOST_IMPL_H_ 6 #define CONTENT_BROWSER_FRAME_HOST_RENDER_FRAME_HOST_IMPL_H_
7 7
8 #include <map> 8 #include <map>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/callback.h" 11 #include "base/callback.h"
12 #include "base/compiler_specific.h" 12 #include "base/compiler_specific.h"
13 #include "base/gtest_prod_util.h" 13 #include "base/gtest_prod_util.h"
14 #include "base/memory/weak_ptr.h" 14 #include "base/memory/weak_ptr.h"
15 #include "base/strings/string16.h" 15 #include "base/strings/string16.h"
16 #include "base/time/time.h" 16 #include "base/time/time.h"
17 #include "content/browser/accessibility/browser_accessibility_manager.h" 17 #include "content/browser/accessibility/browser_accessibility_manager.h"
18 #include "content/browser/site_instance_impl.h" 18 #include "content/browser/site_instance_impl.h"
19 #include "content/browser/webui/web_ui_impl.h"
19 #include "content/common/accessibility_mode_enums.h" 20 #include "content/common/accessibility_mode_enums.h"
20 #include "content/common/ax_content_node_data.h" 21 #include "content/common/ax_content_node_data.h"
21 #include "content/common/content_export.h" 22 #include "content/common/content_export.h"
22 #include "content/common/frame_message_enums.h" 23 #include "content/common/frame_message_enums.h"
23 #include "content/common/frame_replication_state.h" 24 #include "content/common/frame_replication_state.h"
24 #include "content/common/image_downloader/image_downloader.mojom.h" 25 #include "content/common/image_downloader/image_downloader.mojom.h"
25 #include "content/common/mojo/service_registry_impl.h" 26 #include "content/common/mojo/service_registry_impl.h"
26 #include "content/common/navigation_params.h" 27 #include "content/common/navigation_params.h"
27 #include "content/public/browser/render_frame_host.h" 28 #include "content/public/browser/render_frame_host.h"
28 #include "content/public/common/javascript_message_type.h" 29 #include "content/public/common/javascript_message_type.h"
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 int routing_id() const { return routing_id_; } 207 int routing_id() const { return routing_id_; }
207 void OnCreateChildFrame(int new_routing_id, 208 void OnCreateChildFrame(int new_routing_id,
208 blink::WebTreeScopeType scope, 209 blink::WebTreeScopeType scope,
209 const std::string& frame_name, 210 const std::string& frame_name,
210 blink::WebSandboxFlags sandbox_flags); 211 blink::WebSandboxFlags sandbox_flags);
211 212
212 RenderViewHostImpl* render_view_host() { return render_view_host_; } 213 RenderViewHostImpl* render_view_host() { return render_view_host_; }
213 RenderFrameHostDelegate* delegate() { return delegate_; } 214 RenderFrameHostDelegate* delegate() { return delegate_; }
214 FrameTreeNode* frame_tree_node() { return frame_tree_node_; } 215 FrameTreeNode* frame_tree_node() { return frame_tree_node_; }
215 216
217 // Returns the associated active WebUI or nullptr if none applies.
218 WebUIImpl* web_ui() const { return web_ui_.get(); }
219
220 // Returns the pending WebUI, or nullptr of none applies.
221 WebUIImpl* pending_web_ui() const {
222 return should_reuse_web_ui_ ? web_ui_.get() : pending_web_ui_.get();
223 }
224
216 // Returns this RenderFrameHost's loading state. This method is only used by 225 // Returns this RenderFrameHost's loading state. This method is only used by
217 // FrameTreeNode. The proper way to check whether a frame is loading is to 226 // FrameTreeNode. The proper way to check whether a frame is loading is to
218 // call FrameTreeNode::IsLoading. 227 // call FrameTreeNode::IsLoading.
219 bool is_loading() const { return is_loading_; } 228 bool is_loading() const { return is_loading_; }
220 229
221 // This returns the RenderFrameHost's owned RenderWidgetHost if it has one, 230 // This returns the RenderFrameHost's owned RenderWidgetHost if it has one,
222 // or else it returns nullptr. 231 // or else it returns nullptr.
223 // If the RenderFrameHost is the page's main frame, this returns instead a 232 // If the RenderFrameHost is the page's main frame, this returns instead a
224 // pointer to the RenderViewHost (which inherits RenderWidgetHost). 233 // pointer to the RenderViewHost (which inherits RenderWidgetHost).
225 RenderWidgetHostImpl* GetRenderWidgetHost(); 234 RenderWidgetHostImpl* GetRenderWidgetHost();
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 470
462 // Tears down the browser-side state relating to the Mojo connection between 471 // Tears down the browser-side state relating to the Mojo connection between
463 // this instance and its associated render frame. 472 // this instance and its associated render frame.
464 void InvalidateMojoConnection(); 473 void InvalidateMojoConnection();
465 474
466 // Returns whether the frame is focused. A frame is considered focused when it 475 // Returns whether the frame is focused. A frame is considered focused when it
467 // is the parent chain of the focused frame within the frame tree. In 476 // is the parent chain of the focused frame within the frame tree. In
468 // addition, its associated RenderWidgetHost has to be focused. 477 // addition, its associated RenderWidgetHost has to be focused.
469 bool IsFocused(); 478 bool IsFocused();
470 479
480 // Updates the pending WebUI data of this RenderFrameHost depending on the
481 // provided |dest_url|. If it doesn't demand a WebUI, the pending one is
482 // cleared. If a new WebUI is required and its type matches the existing
483 // pending one it will be reused. If the type matches the active one then the
484 // pending is cleared and the current one is set to be reused. Otherwise a new
485 // pending WebUI instance is set.
486 // If this is a history navigation its bindings from the NavigationEntry
487 // should be provided through |entry_bindings|. It will allow verifying that
488 // bindings are not being set differently this time around. Otherwise
489 // |entry_bindings| should be set to NavigationEntryImpl::kInvalidBindings.
490 void UpdatePendingWebUI(const GURL& dest_url, int entry_bindings);
491
492 // Updates the active WebUI with the pending data set by the last call to
493 // UpdatePendingWebUI and then clears any pending data. If UpdatePendingWebUI
494 // was not called the active WebUI will simply be cleared.
495 void CommitPendingWebUI();
496
497 // Destroys the pending WebUI and cleans up any related data.
498 void DiscardPendingWebUI();
499
471 // Returns the Mojo ImageDownloader service. 500 // Returns the Mojo ImageDownloader service.
472 const image_downloader::ImageDownloaderPtr& GetMojoImageDownloader(); 501 const image_downloader::ImageDownloaderPtr& GetMojoImageDownloader();
473 502
474 protected: 503 protected:
475 friend class RenderFrameHostFactory; 504 friend class RenderFrameHostFactory;
476 505
477 // |flags| is a combination of CreateRenderFrameFlags. 506 // |flags| is a combination of CreateRenderFrameFlags. The |dest_url| and
507 // |entry_bindings| parameters are used to create an associated WebUI if one
508 // is required (see UpdatePendingWebUI for further details).
478 // TODO(nasko): Remove dependency on RenderViewHost here. RenderProcessHost 509 // TODO(nasko): Remove dependency on RenderViewHost here. RenderProcessHost
479 // should be the abstraction needed here, but we need RenderViewHost to pass 510 // should be the abstraction needed here, but we need RenderViewHost to pass
480 // into WebContentsObserver::FrameDetached for now. 511 // into WebContentsObserver::FrameDetached for now.
481 RenderFrameHostImpl(SiteInstance* site_instance, 512 RenderFrameHostImpl(SiteInstance* site_instance,
482 RenderViewHostImpl* render_view_host, 513 RenderViewHostImpl* render_view_host,
483 RenderFrameHostDelegate* delegate, 514 RenderFrameHostDelegate* delegate,
484 RenderWidgetHostDelegate* rwh_delegate, 515 RenderWidgetHostDelegate* rwh_delegate,
485 FrameTree* frame_tree, 516 FrameTree* frame_tree,
486 FrameTreeNode* frame_tree_node, 517 FrameTreeNode* frame_tree_node,
487 int32 routing_id, 518 int32 routing_id,
488 int32 widget_routing_id, 519 int32 widget_routing_id,
489 int flags); 520 int flags,
521 const GURL& dest_url,
522 int entry_bindings);
490 523
491 private: 524 private:
492 friend class TestRenderFrameHost; 525 friend class TestRenderFrameHost;
493 friend class TestRenderViewHost; 526 friend class TestRenderViewHost;
494 527
495 FRIEND_TEST_ALL_PREFIXES(SitePerProcessBrowserTest, CrashSubframe); 528 FRIEND_TEST_ALL_PREFIXES(SitePerProcessBrowserTest, CrashSubframe);
496 529
497 // IPC Message handlers. 530 // IPC Message handlers.
498 void OnAddMessageToConsole(int32 level, 531 void OnAddMessageToConsole(int32 level,
499 const base::string16& message, 532 const base::string16& message,
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
615 RenderWidgetHostViewBase* GetViewForAccessibility(); 648 RenderWidgetHostViewBase* GetViewForAccessibility();
616 649
617 // Sends a navigate message to the RenderFrame and notifies DevTools about 650 // Sends a navigate message to the RenderFrame and notifies DevTools about
618 // navigation happening. Should be used instead of sending the message 651 // navigation happening. Should be used instead of sending the message
619 // directly. 652 // directly.
620 void SendNavigateMessage( 653 void SendNavigateMessage(
621 const content::CommonNavigationParams& common_params, 654 const content::CommonNavigationParams& common_params,
622 const content::StartNavigationParams& start_params, 655 const content::StartNavigationParams& start_params,
623 const content::RequestNavigationParams& request_params); 656 const content::RequestNavigationParams& request_params);
624 657
658 // Creates a WebUI object for the given URL if one applies and sets
659 // |web_ui_type| to its type, also ensuring that its bindings match
660 // |entry_bindings| (if provided and different than
661 // NavigationEntryImpl::kInvalidBindings). If no WebUI applies, returns
662 // nullptr and resets web_ui_type to WebUI::kNoWebUI. .
663 scoped_ptr<WebUIImpl> CreateWebUI(const GURL& dest_url,
664 int entry_bindings,
665 WebUI::TypeID* web_ui_type);
666
625 // For now, RenderFrameHosts indirectly keep RenderViewHosts alive via a 667 // For now, RenderFrameHosts indirectly keep RenderViewHosts alive via a
626 // refcount that calls Shutdown when it reaches zero. This allows each 668 // refcount that calls Shutdown when it reaches zero. This allows each
627 // RenderFrameHostManager to just care about RenderFrameHosts, while ensuring 669 // RenderFrameHostManager to just care about RenderFrameHosts, while ensuring
628 // we have a RenderViewHost for each RenderFrameHost. 670 // we have a RenderViewHost for each RenderFrameHost.
629 // TODO(creis): RenderViewHost will eventually go away and be replaced with 671 // TODO(creis): RenderViewHost will eventually go away and be replaced with
630 // some form of page context. 672 // some form of page context.
631 RenderViewHostImpl* render_view_host_; 673 RenderViewHostImpl* render_view_host_;
632 674
633 RenderFrameHostDelegate* delegate_; 675 RenderFrameHostDelegate* delegate_;
634 676
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
783 // Holder of Mojo connection with ImageDownloader service in RenderFrame. 825 // Holder of Mojo connection with ImageDownloader service in RenderFrame.
784 image_downloader::ImageDownloaderPtr mojo_image_downloader_; 826 image_downloader::ImageDownloaderPtr mojo_image_downloader_;
785 827
786 // Tracks a navigation happening in this frame. Note that while there can be 828 // Tracks a navigation happening in this frame. Note that while there can be
787 // two navigations in the same FrameTreeNode, there can only be one 829 // two navigations in the same FrameTreeNode, there can only be one
788 // navigation per RenderFrameHost. 830 // navigation per RenderFrameHost.
789 // PlzNavigate: before the navigation is ready to be committed, the 831 // PlzNavigate: before the navigation is ready to be committed, the
790 // NavigationHandle for it is owned by the NavigationRequest. 832 // NavigationHandle for it is owned by the NavigationRequest.
791 scoped_ptr<NavigationHandleImpl> navigation_handle_; 833 scoped_ptr<NavigationHandleImpl> navigation_handle_;
792 834
835 // The associated WebUIImpl and its type. They will be set if the current page
836 // is a WebUI page. Otherwise they will be nullptr and WebUI::kNoWebUI,
837 // respectively.
838 scoped_ptr<WebUIImpl> web_ui_;
839 WebUI::TypeID web_ui_type_;
840
841 // Stores a pending WebUIImpl and its type. These will only be set during a
842 // same-site navigation to a WebUI page (reusing this RenderFrameHost).
843 scoped_ptr<WebUIImpl> pending_web_ui_;
844 WebUI::TypeID pending_web_ui_type_;
845
846 // If true at commit time the current WebUI will simply be reused (no pending
847 // one will exist to be committed).
848 bool should_reuse_web_ui_;
849
793 // NOTE: This must be the last member. 850 // NOTE: This must be the last member.
794 base::WeakPtrFactory<RenderFrameHostImpl> weak_ptr_factory_; 851 base::WeakPtrFactory<RenderFrameHostImpl> weak_ptr_factory_;
795 852
796 DISALLOW_COPY_AND_ASSIGN(RenderFrameHostImpl); 853 DISALLOW_COPY_AND_ASSIGN(RenderFrameHostImpl);
797 }; 854 };
798 855
799 } // namespace content 856 } // namespace content
800 857
801 #endif // CONTENT_BROWSER_FRAME_HOST_RENDER_FRAME_HOST_IMPL_H_ 858 #endif // CONTENT_BROWSER_FRAME_HOST_RENDER_FRAME_HOST_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698