OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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_SITE_INSTANCE_IMPL_H_ | 5 #ifndef CONTENT_BROWSER_SITE_INSTANCE_IMPL_H_ |
6 #define CONTENT_BROWSER_SITE_INSTANCE_IMPL_H_ | 6 #define CONTENT_BROWSER_SITE_INSTANCE_IMPL_H_ |
7 | 7 |
8 #include "content/browser/renderer_host/render_process_host_impl.h" | 8 #include "content/browser/renderer_host/render_process_host_impl.h" |
9 #include "content/common/content_export.h" | 9 #include "content/common/content_export.h" |
10 #include "content/public/browser/notification_observer.h" | 10 #include "content/public/browser/notification_observer.h" |
11 #include "content/public/browser/notification_registrar.h" | 11 #include "content/public/browser/notification_registrar.h" |
12 #include "content/public/browser/site_instance.h" | 12 #include "content/public/browser/site_instance.h" |
13 #include "googleurl/src/gurl.h" | 13 #include "googleurl/src/gurl.h" |
14 | 14 |
15 namespace content { | 15 namespace content { |
16 class RenderProcessHostFactory; | 16 class RenderProcessHostFactory; |
17 } | |
18 | 17 |
19 class CONTENT_EXPORT SiteInstanceImpl : public content::SiteInstance, | 18 class CONTENT_EXPORT SiteInstanceImpl : public SiteInstance, |
20 public content::NotificationObserver { | 19 public NotificationObserver { |
21 public: | 20 public: |
22 // content::SiteInstance interface overrides. | 21 // SiteInstance interface overrides. |
23 virtual int32 GetId() OVERRIDE; | 22 virtual int32 GetId() OVERRIDE; |
24 virtual bool HasProcess() const OVERRIDE; | 23 virtual bool HasProcess() const OVERRIDE; |
25 virtual content::RenderProcessHost* GetProcess() OVERRIDE; | 24 virtual RenderProcessHost* GetProcess() OVERRIDE; |
26 virtual const GURL& GetSiteURL() const OVERRIDE; | 25 virtual const GURL& GetSiteURL() const OVERRIDE; |
27 virtual SiteInstance* GetRelatedSiteInstance(const GURL& url) OVERRIDE; | 26 virtual SiteInstance* GetRelatedSiteInstance(const GURL& url) OVERRIDE; |
28 virtual bool IsRelatedSiteInstance(const SiteInstance* instance) OVERRIDE; | 27 virtual bool IsRelatedSiteInstance(const SiteInstance* instance) OVERRIDE; |
29 virtual content::BrowserContext* GetBrowserContext() const OVERRIDE; | 28 virtual BrowserContext* GetBrowserContext() const OVERRIDE; |
30 | 29 |
31 // Set the web site that this SiteInstance is rendering pages for. | 30 // Set the web site that this SiteInstance is rendering pages for. |
32 // This includes the scheme and registered domain, but not the port. If the | 31 // This includes the scheme and registered domain, but not the port. If the |
33 // URL does not have a valid registered domain, then the full hostname is | 32 // URL does not have a valid registered domain, then the full hostname is |
34 // stored. | 33 // stored. |
35 void SetSite(const GURL& url); | 34 void SetSite(const GURL& url); |
36 bool HasSite() const; | 35 bool HasSite() const; |
37 | 36 |
38 // Returns whether there is currently a related SiteInstance (registered with | 37 // Returns whether there is currently a related SiteInstance (registered with |
39 // BrowsingInstance) for the site of the given url. If so, we should try to | 38 // BrowsingInstance) for the site of the given url. If so, we should try to |
40 // avoid dedicating an unused SiteInstance to it (e.g., in a new tab). | 39 // avoid dedicating an unused SiteInstance to it (e.g., in a new tab). |
41 bool HasRelatedSiteInstance(const GURL& url); | 40 bool HasRelatedSiteInstance(const GURL& url); |
42 | 41 |
43 // Returns whether this SiteInstance has a process that is the wrong type for | 42 // Returns whether this SiteInstance has a process that is the wrong type for |
44 // the given URL. If so, the browser should force a process swap when | 43 // the given URL. If so, the browser should force a process swap when |
45 // navigating to the URL. | 44 // navigating to the URL. |
46 bool HasWrongProcessForURL(const GURL& url) const; | 45 bool HasWrongProcessForURL(const GURL& url) const; |
47 | 46 |
48 // Sets the factory used to create new RenderProcessHosts. This will also be | 47 // Sets the factory used to create new RenderProcessHosts. This will also be |
49 // passed on to SiteInstances spawned by this one. | 48 // passed on to SiteInstances spawned by this one. |
50 // The factory must outlive the SiteInstance; ownership is not transferred. It | 49 // The factory must outlive the SiteInstance; ownership is not transferred. It |
51 // may be NULL, in which case the default BrowserRenderProcessHost will be | 50 // may be NULL, in which case the default BrowserRenderProcessHost will be |
52 // created (this is the behavior if you don't call this function). | 51 // created (this is the behavior if you don't call this function). |
53 void set_render_process_host_factory( | 52 void set_render_process_host_factory(RenderProcessHostFactory* rph_factory) { |
54 content::RenderProcessHostFactory* rph_factory) { | |
55 render_process_host_factory_ = rph_factory; | 53 render_process_host_factory_ = rph_factory; |
56 } | 54 } |
57 | 55 |
58 // Returns the site for the given URL, which includes only the scheme and | 56 // Returns the site for the given URL, which includes only the scheme and |
59 // registered domain. Returns an empty GURL if the URL has no host. | 57 // registered domain. Returns an empty GURL if the URL has no host. |
60 static GURL GetSiteForURL(content::BrowserContext* context, const GURL& url); | 58 static GURL GetSiteForURL(BrowserContext* context, const GURL& url); |
61 | 59 |
62 protected: | 60 protected: |
63 friend class BrowsingInstance; | 61 friend class BrowsingInstance; |
64 friend class content::SiteInstance; | 62 friend class SiteInstance; |
65 | 63 |
66 // Virtual to allow tests to extend it. | 64 // Virtual to allow tests to extend it. |
67 virtual ~SiteInstanceImpl(); | 65 virtual ~SiteInstanceImpl(); |
68 | 66 |
69 // Create a new SiteInstance. Protected to give access to BrowsingInstance | 67 // Create a new SiteInstance. Protected to give access to BrowsingInstance |
70 // and tests; most callers should use Create or GetRelatedSiteInstance | 68 // and tests; most callers should use Create or GetRelatedSiteInstance |
71 // instead. | 69 // instead. |
72 explicit SiteInstanceImpl(BrowsingInstance* browsing_instance); | 70 explicit SiteInstanceImpl(BrowsingInstance* browsing_instance); |
73 | 71 |
74 private: | 72 private: |
75 // Get the effective URL for the given actual URL. | 73 // Get the effective URL for the given actual URL. |
76 static GURL GetEffectiveURL(content::BrowserContext* browser_context, | 74 static GURL GetEffectiveURL(BrowserContext* browser_context, |
77 const GURL& url); | 75 const GURL& url); |
78 | 76 |
79 // content::NotificationObserver implementation. | 77 // NotificationObserver implementation. |
80 virtual void Observe(int type, | 78 virtual void Observe(int type, |
81 const content::NotificationSource& source, | 79 const NotificationSource& source, |
82 const content::NotificationDetails& details) OVERRIDE; | 80 const NotificationDetails& details) OVERRIDE; |
83 | 81 |
84 // Used to restrict a process' origin access rights. | 82 // Used to restrict a process' origin access rights. |
85 void LockToOrigin(); | 83 void LockToOrigin(); |
86 | 84 |
87 // The next available SiteInstance ID. | 85 // The next available SiteInstance ID. |
88 static int32 next_site_instance_id_; | 86 static int32 next_site_instance_id_; |
89 | 87 |
90 // A unique ID for this SiteInstance. | 88 // A unique ID for this SiteInstance. |
91 int32 id_; | 89 int32 id_; |
92 | 90 |
93 content::NotificationRegistrar registrar_; | 91 NotificationRegistrar registrar_; |
94 | 92 |
95 // BrowsingInstance to which this SiteInstance belongs. | 93 // BrowsingInstance to which this SiteInstance belongs. |
96 scoped_refptr<BrowsingInstance> browsing_instance_; | 94 scoped_refptr<BrowsingInstance> browsing_instance_; |
97 | 95 |
98 // Factory for new RenderProcessHosts, not owned by this class. NULL indiactes | 96 // Factory for new RenderProcessHosts, not owned by this class. NULL indiactes |
99 // that the default BrowserRenderProcessHost should be created. | 97 // that the default BrowserRenderProcessHost should be created. |
100 const content::RenderProcessHostFactory* render_process_host_factory_; | 98 const RenderProcessHostFactory* render_process_host_factory_; |
101 | 99 |
102 // Current RenderProcessHost that is rendering pages for this SiteInstance. | 100 // Current RenderProcessHost that is rendering pages for this SiteInstance. |
103 // This pointer will only change once the RenderProcessHost is destructed. It | 101 // This pointer will only change once the RenderProcessHost is destructed. It |
104 // will still remain the same even if the process crashes, since in that | 102 // will still remain the same even if the process crashes, since in that |
105 // scenario the RenderProcessHost remains the same. | 103 // scenario the RenderProcessHost remains the same. |
106 content::RenderProcessHost* process_; | 104 RenderProcessHost* process_; |
107 | 105 |
108 // The web site that this SiteInstance is rendering pages for. | 106 // The web site that this SiteInstance is rendering pages for. |
109 GURL site_; | 107 GURL site_; |
110 | 108 |
111 // Whether SetSite has been called. | 109 // Whether SetSite has been called. |
112 bool has_site_; | 110 bool has_site_; |
113 | 111 |
114 DISALLOW_COPY_AND_ASSIGN(SiteInstanceImpl); | 112 DISALLOW_COPY_AND_ASSIGN(SiteInstanceImpl); |
115 }; | 113 }; |
116 | 114 |
| 115 } // namespace content |
| 116 |
117 #endif // CONTENT_BROWSER_SITE_INSTANCE_IMPL_H_ | 117 #endif // CONTENT_BROWSER_SITE_INSTANCE_IMPL_H_ |
OLD | NEW |