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

Side by Side Diff: content/public/browser/site_instance.h

Issue 9146028: Define the public interface for content browser SiteInstance. This interface is implemented by th... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 8 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « content/public/browser/content_browser_client.h ('k') | content/public/browser/web_contents.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
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.
4
5 #ifndef CONTENT_PUBLIC_BROWSER_SITE_INSTANCE_H_
6 #define CONTENT_PUBLIC_BROWSER_SITE_INSTANCE_H_
7 #pragma once
8
9 #include "base/basictypes.h"
10 #include "base/memory/ref_counted.h"
11 #include "content/common/content_export.h"
12 #include "googleurl/src/gurl.h"
13
14 class BrowsingInstance;
15
16 namespace content {
17 class BrowserContext;
18 class RenderProcessHost;
19
20 ///////////////////////////////////////////////////////////////////////////////
21 // SiteInstance interface.
22 //
23 // A SiteInstance is a data structure that is associated with all pages in a
24 // given instance of a web site. Here, a web site is identified by its
25 // registered domain name and scheme. An instance includes all pages
26 // that are connected (i.e., either a user or a script navigated from one
27 // to the other). We represent instances using the BrowsingInstance class.
28 //
29 // In --process-per-tab, one SiteInstance is created for each tab (i.e., in the
30 // TabContents constructor), unless the tab is created by script (i.e., in
31 // TabContents::CreateNewView). This corresponds to one process per
32 // BrowsingInstance.
33 //
34 // In process-per-site-instance (the current default process model),
35 // SiteInstances are created (1) when the user manually creates a new tab
36 // (which also creates a new BrowsingInstance), and (2) when the user navigates
37 // across site boundaries (which uses the same BrowsingInstance). If the user
38 // navigates within a site, or opens links in new tabs within a site, the same
39 // SiteInstance is used.
40 //
41 // In --process-per-site, we consolidate all SiteInstances for a given site,
42 // throughout the entire browser context. This ensures that only one process
43 // will be dedicated to each site.
44 //
45 // Each NavigationEntry for a TabContents points to the SiteInstance that
46 // rendered it. Each RenderViewHost also points to the SiteInstance that it is
47 // associated with. A SiteInstance keeps track of the number of these
48 // references and deletes itself when the count goes to zero. This means that
49 // a SiteInstance is only live as long as it is accessible, either from new
50 // tabs with no NavigationEntries or in NavigationEntries in the history.
51 //
52 ///////////////////////////////////////////////////////////////////////////////
53 class CONTENT_EXPORT SiteInstance : public base::RefCounted<SiteInstance> {
54 public:
55 // Returns a unique ID for this SiteInstance.
56 virtual int32 GetId() = 0;
57
58 // Whether this SiteInstance has a running process associated with it.
59 virtual bool HasProcess() const = 0;
60
61 // Returns the current process being used to render pages in this
62 // SiteInstance. If the process has crashed or otherwise gone away, then
63 // this method will create a new process and update our host ID accordingly.
64 virtual content::RenderProcessHost* GetProcess() = 0;
65
66 // Browser context to which this SiteInstance (and all related
67 // SiteInstances) belongs.
68 virtual content::BrowserContext* GetBrowserContext() const = 0;
69
70 // Get the web site that this SiteInstance is rendering pages for.
71 // This includes the scheme and registered domain, but not the port.
72 virtual const GURL& GetSite() const = 0;
73
74 // Gets a SiteInstance for the given URL that shares the current
75 // BrowsingInstance, creating a new SiteInstance if necessary. This ensures
76 // that a BrowsingInstance only has one SiteInstance per site, so that pages
77 // in a BrowsingInstance have the ability to script each other. Callers
78 // should ensure that this SiteInstance becomes ref counted, by storing it in
79 // a scoped_refptr. (By having this method, we can hide the BrowsingInstance
80 // class from the rest of the codebase.)
81 // TODO(creis): This may be an argument to build a pass_refptr<T> class, as
82 // Darin suggests.
83 virtual SiteInstance* GetRelatedSiteInstance(const GURL& url) = 0;
84
85 // Factory method to create a new SiteInstance. This will create a new
86 // new BrowsingInstance, so it should only be used when creating a new tab
87 // from scratch (or similar circumstances). Callers should ensure that
88 // this SiteInstance becomes ref counted, by storing it in a scoped_refptr.
89 //
90 // The render process host factory may be NULL. See SiteInstance constructor.
91 //
92 // TODO(creis): This may be an argument to build a pass_refptr<T> class, as
93 // Darin suggests.
94 static SiteInstance* Create(content::BrowserContext* browser_context);
95
96 // Factory method to get the appropriate SiteInstance for the given URL, in
97 // a new BrowsingInstance. Use this instead of Create when you know the URL,
98 // since it allows special site grouping rules to be applied (for example,
99 // to group chrome-ui pages into the same instance).
100 static SiteInstance* CreateForURL(
101 content::BrowserContext* browser_context, const GURL& url);
102
103 // Return whether both URLs are part of the same web site, for the purpose of
104 // assigning them to processes accordingly. The decision is currently based
105 // on the registered domain of the URLs (google.com, bbc.co.uk), as well as
106 // the scheme (https, http). This ensures that two pages will be in
107 // the same process if they can communicate with other via JavaScript.
108 // (e.g., docs.google.com and mail.google.com have DOM access to each other
109 // if they both set their document.domain properties to google.com.)
110 static bool IsSameWebSite(content::BrowserContext* browser_context,
111 const GURL& url1, const GURL& url2);
112
113 protected:
114 friend class base::RefCounted<SiteInstance>;
115
116 SiteInstance() {}
117 virtual ~SiteInstance() {}
118 };
119
120 } // namespace content.
121
122 #endif // CONTENT_PUBLIC_BROWSER_SITE_INSTANCE_H_
OLDNEW
« no previous file with comments | « content/public/browser/content_browser_client.h ('k') | content/public/browser/web_contents.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698