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 #include "chrome/browser/background/background_contents.h" | 5 #include "chrome/browser/background/background_contents.h" |
6 | 6 |
7 #include "base/lazy_instance.h" | |
7 #include "chrome/browser/background/background_contents_service.h" | 8 #include "chrome/browser/background/background_contents_service.h" |
8 #include "chrome/browser/chrome_notification_types.h" | 9 #include "chrome/browser/chrome_notification_types.h" |
9 #include "chrome/browser/extensions/chrome_extension_web_contents_observer.h" | 10 #include "chrome/browser/extensions/chrome_extension_web_contents_observer.h" |
10 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
11 #include "chrome/browser/renderer_preferences_util.h" | 12 #include "chrome/browser/renderer_preferences_util.h" |
12 #include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h" | 13 #include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h" |
13 #include "chrome/common/url_constants.h" | 14 #include "chrome/common/url_constants.h" |
14 #include "content/public/browser/notification_service.h" | 15 #include "content/public/browser/notification_service.h" |
15 #include "content/public/browser/render_view_host.h" | 16 #include "content/public/browser/render_view_host.h" |
16 #include "content/public/browser/session_storage_namespace.h" | 17 #include "content/public/browser/session_storage_namespace.h" |
17 #include "content/public/browser/site_instance.h" | 18 #include "content/public/browser/site_instance.h" |
18 #include "content/public/browser/web_contents.h" | 19 #include "content/public/browser/web_contents.h" |
20 #include "extensions/browser/extension_host_queue.h" | |
21 #include "extensions/browser/serial_extension_host_queue.h" | |
19 #include "extensions/browser/view_type_utils.h" | 22 #include "extensions/browser/view_type_utils.h" |
20 #include "ui/gfx/geometry/rect.h" | 23 #include "ui/gfx/geometry/rect.h" |
21 | 24 |
22 using content::SiteInstance; | 25 using content::SiteInstance; |
23 using content::WebContents; | 26 using content::WebContents; |
24 | 27 |
28 namespace { | |
29 | |
30 // Singleton which wraps the chosen ExtensionHostQueue implementation. | |
31 struct QueueWrapper { | |
Devlin
2015/02/18 23:22:12
Should we have two separate queues for extension h
Yoyo Zhou
2015/02/19 02:55:37
I don't have a strong preference either way. I thi
Devlin
2015/02/19 16:41:43
I think Ben's trying to make it easy to switch bet
not at google - send to devlin
2015/02/19 18:07:41
Note that I will probably need to modify the way t
Yoyo Zhou
2015/02/19 23:57:58
Turns out we have an ExtensionHostDelegate which w
not at google - send to devlin
2015/02/20 00:28:33
Sweet, that's where I put it as well (in my unfini
| |
32 QueueWrapper() : queue(new extensions::SerialExtensionHostQueue()) {} | |
33 scoped_ptr<extensions::ExtensionHostQueue> queue; | |
34 }; | |
35 base::LazyInstance<QueueWrapper> g_queue_wrapper = LAZY_INSTANCE_INITIALIZER; | |
36 | |
37 } // namespace | |
38 | |
25 BackgroundContents::BackgroundContents( | 39 BackgroundContents::BackgroundContents( |
26 SiteInstance* site_instance, | 40 SiteInstance* site_instance, |
27 int routing_id, | 41 int routing_id, |
28 int main_frame_routing_id, | 42 int main_frame_routing_id, |
29 Delegate* delegate, | 43 Delegate* delegate, |
30 const std::string& partition_id, | 44 const std::string& partition_id, |
31 content::SessionStorageNamespace* session_storage_namespace) | 45 content::SessionStorageNamespace* session_storage_namespace) |
32 : delegate_(delegate) { | 46 : delegate_(delegate) { |
33 profile_ = Profile::FromBrowserContext( | 47 profile_ = Profile::FromBrowserContext( |
34 site_instance->GetBrowserContext()); | 48 site_instance->GetBrowserContext()); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
75 | 89 |
76 // Unregister for any notifications before notifying observers that we are | 90 // Unregister for any notifications before notifying observers that we are |
77 // going away - this prevents any re-entrancy due to chained notifications | 91 // going away - this prevents any re-entrancy due to chained notifications |
78 // (http://crbug.com/237781). | 92 // (http://crbug.com/237781). |
79 registrar_.RemoveAll(); | 93 registrar_.RemoveAll(); |
80 | 94 |
81 content::NotificationService::current()->Notify( | 95 content::NotificationService::current()->Notify( |
82 chrome::NOTIFICATION_BACKGROUND_CONTENTS_DELETED, | 96 chrome::NOTIFICATION_BACKGROUND_CONTENTS_DELETED, |
83 content::Source<Profile>(profile_), | 97 content::Source<Profile>(profile_), |
84 content::Details<BackgroundContents>(this)); | 98 content::Details<BackgroundContents>(this)); |
99 | |
100 g_queue_wrapper.Get().queue->Remove(this); | |
85 } | 101 } |
86 | 102 |
87 const GURL& BackgroundContents::GetURL() const { | 103 const GURL& BackgroundContents::GetURL() const { |
88 return web_contents_.get() ? web_contents_->GetURL() : GURL::EmptyGURL(); | 104 return web_contents_.get() ? web_contents_->GetURL() : GURL::EmptyGURL(); |
89 } | 105 } |
90 | 106 |
107 void BackgroundContents::CreateRenderViewSoon(const GURL& url) { | |
108 initial_url_ = url; | |
109 g_queue_wrapper.Get().queue->Add(this); | |
110 } | |
111 | |
112 void BackgroundContents::CreateRenderViewNow() { | |
113 web_contents()->GetController().LoadURL(initial_url_, content::Referrer(), | |
114 ui::PAGE_TRANSITION_LINK, | |
115 std::string()); | |
116 } | |
117 | |
91 void BackgroundContents::CloseContents(WebContents* source) { | 118 void BackgroundContents::CloseContents(WebContents* source) { |
92 content::NotificationService::current()->Notify( | 119 content::NotificationService::current()->Notify( |
93 chrome::NOTIFICATION_BACKGROUND_CONTENTS_CLOSED, | 120 chrome::NOTIFICATION_BACKGROUND_CONTENTS_CLOSED, |
94 content::Source<Profile>(profile_), | 121 content::Source<Profile>(profile_), |
95 content::Details<BackgroundContents>(this)); | 122 content::Details<BackgroundContents>(this)); |
96 delete this; | 123 delete this; |
97 } | 124 } |
98 | 125 |
99 bool BackgroundContents::ShouldSuppressDialogs(WebContents* source) { | 126 bool BackgroundContents::ShouldSuppressDialogs(WebContents* source) { |
100 return true; | 127 return true; |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
153 case chrome::NOTIFICATION_PROFILE_DESTROYED: | 180 case chrome::NOTIFICATION_PROFILE_DESTROYED: |
154 case chrome::NOTIFICATION_APP_TERMINATING: { | 181 case chrome::NOTIFICATION_APP_TERMINATING: { |
155 delete this; | 182 delete this; |
156 break; | 183 break; |
157 } | 184 } |
158 default: | 185 default: |
159 NOTREACHED() << "Unexpected notification sent."; | 186 NOTREACHED() << "Unexpected notification sent."; |
160 break; | 187 break; |
161 } | 188 } |
162 } | 189 } |
OLD | NEW |