Chromium Code Reviews
|
| OLD | NEW |
|---|---|
| (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; | |
|
jam
2012/01/24 03:29:33
nit: no need for two "namespace content", just mov
ananta
2012/01/24 23:46:26
Done.
| |
| 18 } | |
| 19 | |
| 20 namespace content { | |
| 21 | |
| 22 // Interface that represents a site instance, which is a data structure that | |
|
jam
2012/01/24 03:29:33
we usually move the entire comment from the impl c
ananta
2012/01/24 23:46:26
Done.
| |
| 23 // is associated with all pages in a given instance of a web site. | |
| 24 class CONTENT_EXPORT SiteInstance : public base::RefCounted<SiteInstance> { | |
| 25 public: | |
| 26 // Returns a unique ID for this SiteInstance. | |
| 27 virtual int32 GetId() = 0; | |
| 28 | |
| 29 // Whether this SiteInstance has a running process associated with it. | |
| 30 virtual bool HasProcess() const = 0; | |
| 31 | |
| 32 // Returns the current process being used to render pages in this | |
| 33 // SiteInstance. If the process has crashed or otherwise gone away, then | |
| 34 // this method will create a new process and update our host ID accordingly. | |
| 35 virtual content::RenderProcessHost* GetProcess() = 0; | |
| 36 | |
| 37 // Set / Get the web site that this SiteInstance is rendering pages for. | |
| 38 // This includes the scheme and registered domain, but not the port. If the | |
| 39 // URL does not have a valid registered domain, then the full hostname is | |
| 40 // stored. | |
| 41 virtual void SetSite(const GURL& url) = 0; | |
|
jam
2012/01/24 03:29:33
this is only called by code in content. so it shou
ananta
2012/01/24 23:46:26
Done.
| |
| 42 virtual const GURL& GetSite() const = 0; | |
| 43 | |
| 44 virtual bool HasSite() const = 0; | |
| 45 | |
| 46 // Returns whether there is currently a related SiteInstance (registered with | |
| 47 // BrowsingInstance) for the site of the given url. If so, we should try to | |
| 48 // avoid dedicating an unused SiteInstance to it (e.g., in a new tab). | |
| 49 virtual bool HasRelatedSiteInstance(const GURL& url) = 0; | |
|
jam
2012/01/24 03:29:33
ditto
ananta
2012/01/24 23:46:26
Done.
| |
| 50 | |
| 51 // Gets a SiteInstance for the given URL that shares the current | |
| 52 // BrowsingInstance, creating a new SiteInstance if necessary. This ensures | |
| 53 // that a BrowsingInstance only has one SiteInstance per site, so that pages | |
| 54 // in a BrowsingInstance have the ability to script each other. Callers | |
| 55 // should ensure that this SiteInstance becomes ref counted, by storing it in | |
| 56 // a scoped_refptr. (By having this method, we can hide the BrowsingInstance | |
| 57 // class from the rest of the codebase.) | |
| 58 // TODO(creis): This may be an argument to build a pass_refptr<T> class, as | |
| 59 // Darin suggests. | |
| 60 virtual SiteInstance* GetRelatedSiteInstance(const GURL& url) = 0; | |
| 61 | |
| 62 // Returns whether this SiteInstance has a process that is the wrong type for | |
| 63 // the given URL. If so, the browser should force a process swap when | |
| 64 // navigating to the URL. | |
| 65 virtual bool HasWrongProcessForURL(const GURL& url) const = 0; | |
|
jam
2012/01/24 03:29:33
ditto
ananta
2012/01/24 23:46:26
Done.
| |
| 66 | |
| 67 // Browser context to which this SiteInstance (and all related | |
| 68 // SiteInstances) belongs. | |
| 69 virtual content::BrowserContext* GetBrowserContext() const = 0; | |
| 70 | |
| 71 // Returns the BrowsingInstance associated with this SiteInstance. | |
| 72 virtual BrowsingInstance* GetBrowsingInstance() const = 0; | |
|
jam
2012/01/24 03:29:33
ditto. we're supposed to be hiding BrowsingInstanc
ananta
2012/01/24 23:46:26
Done.
| |
| 73 | |
| 74 // Factory method to create a new SiteInstance. This will create a new | |
| 75 // new BrowsingInstance, so it should only be used when creating a new tab | |
| 76 // from scratch (or similar circumstances). Callers should ensure that | |
| 77 // this SiteInstance becomes ref counted, by storing it in a scoped_refptr. | |
| 78 // | |
| 79 // The render process host factory may be NULL. See SiteInstance constructor. | |
| 80 // | |
| 81 // TODO(creis): This may be an argument to build a pass_refptr<T> class, as | |
| 82 // Darin suggests. | |
| 83 static SiteInstance* CreateSiteInstance( | |
|
jam
2012/01/24 03:29:33
nit: I realize this was already called that, but f
ananta
2012/01/24 23:46:26
Done.
| |
| 84 content::BrowserContext* browser_context); | |
| 85 | |
| 86 // Factory method to get the appropriate SiteInstance for the given URL, in | |
| 87 // a new BrowsingInstance. Use this instead of CreateSiteInstance when you | |
| 88 // know the URL, since it allows special site grouping rules to be applied | |
| 89 // (for example, to group chrome-ui pages into the same instance). | |
| 90 static SiteInstance* CreateSiteInstanceForURL( | |
| 91 content::BrowserContext* browser_context, const GURL& url); | |
| 92 | |
| 93 // Returns the site for the given URL, which includes only the scheme and | |
| 94 // registered domain. Returns an empty GURL if the URL has no host. | |
| 95 static GURL GetSiteForURL(content::BrowserContext* context, const GURL& url); | |
|
jam
2012/01/24 03:29:33
ditto (only called from content)
ananta
2012/01/24 23:46:26
Done.
jam
2012/01/25 02:02:17
it's still here?
ananta
2012/01/25 02:16:29
Sorry. This one missed out :(. Done.
| |
| 96 | |
| 97 // Return whether both URLs are part of the same web site, for the purpose of | |
| 98 // assigning them to processes accordingly. The decision is currently based | |
| 99 // on the registered domain of the URLs (google.com, bbc.co.uk), as well as | |
| 100 // the scheme (https, http). This ensures that two pages will be in | |
| 101 // the same process if they can communicate with other via JavaScript. | |
| 102 // (e.g., docs.google.com and mail.google.com have DOM access to each other | |
| 103 // if they both set their document.domain properties to google.com.) | |
| 104 static bool IsSameWebSite(content::BrowserContext* browser_context, | |
| 105 const GURL& url1, const GURL& url2); | |
| 106 | |
| 107 protected: | |
| 108 friend class base::RefCounted<SiteInstance>; | |
| 109 | |
| 110 SiteInstance() {} | |
| 111 ~SiteInstance() {} | |
| 112 | |
| 113 // Get the effective URL for the given actual URL. | |
| 114 static GURL GetEffectiveURL(content::BrowserContext* browser_context, | |
|
jam
2012/01/24 03:29:33
why is this in the interface?
ananta
2012/01/24 23:46:26
Done.
| |
| 115 const GURL& url); | |
| 116 }; | |
| 117 | |
| 118 } // namespace content. | |
| 119 | |
| 120 #endif // CONTENT_PUBLIC_BROWSER_SITE_INSTANCE_H_ | |
| OLD | NEW |