OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/extensions/extension_tab_helper.h" | 5 #include "chrome/browser/extensions/extension_tab_helper.h" |
6 | 6 |
7 #include "chrome/browser/extensions/extension_service.h" | 7 #include "chrome/browser/extensions/extension_service.h" |
8 #include "chrome/browser/extensions/webstore_inline_installer.h" | 8 #include "chrome/browser/extensions/webstore_inline_installer.h" |
9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
10 #include "chrome/browser/sessions/restore_tab_helper.h" | 10 #include "chrome/browser/sessions/restore_tab_helper.h" |
11 #include "chrome/browser/ui/browser.h" | 11 #include "chrome/browser/ui/browser.h" |
12 #include "chrome/browser/ui/browser_list.h" | 12 #include "chrome/browser/ui/browser_list.h" |
13 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 13 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
14 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper_delegate.h" | 14 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper_delegate.h" |
15 #include "chrome/common/chrome_notification_types.h" | 15 #include "chrome/common/chrome_notification_types.h" |
16 #include "chrome/common/extensions/extension_action.h" | 16 #include "chrome/common/extensions/extension_action.h" |
17 #include "chrome/common/extensions/extension_constants.h" | 17 #include "chrome/common/extensions/extension_constants.h" |
18 #include "chrome/common/extensions/extension_icon_set.h" | 18 #include "chrome/common/extensions/extension_icon_set.h" |
19 #include "chrome/common/extensions/extension_messages.h" | 19 #include "chrome/common/extensions/extension_messages.h" |
20 #include "chrome/common/extensions/extension_resource.h" | 20 #include "chrome/common/extensions/extension_resource.h" |
21 #include "content/browser/renderer_host/render_view_host.h" | |
21 #include "content/browser/renderer_host/render_widget_host_view.h" | 22 #include "content/browser/renderer_host/render_widget_host_view.h" |
22 #include "content/browser/tab_contents/navigation_details.h" | 23 #include "content/browser/tab_contents/navigation_details.h" |
23 #include "content/browser/tab_contents/tab_contents.h" | 24 #include "content/browser/tab_contents/tab_contents.h" |
24 #include "content/common/notification_service.h" | 25 #include "content/common/notification_service.h" |
25 | 26 |
26 ExtensionTabHelper::ExtensionTabHelper(TabContentsWrapper* wrapper) | 27 ExtensionTabHelper::ExtensionTabHelper(TabContentsWrapper* wrapper) |
27 : TabContentsObserver(wrapper->tab_contents()), | 28 : TabContentsObserver(wrapper->tab_contents()), |
28 extension_app_(NULL), | 29 extension_app_(NULL), |
29 ALLOW_THIS_IN_INITIALIZER_LIST( | 30 ALLOW_THIS_IN_INITIALIZER_LIST( |
30 extension_function_dispatcher_(wrapper->profile(), this)), | 31 extension_function_dispatcher_(wrapper->profile(), this)), |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
120 | 121 |
121 bool ExtensionTabHelper::OnMessageReceived(const IPC::Message& message) { | 122 bool ExtensionTabHelper::OnMessageReceived(const IPC::Message& message) { |
122 bool handled = true; | 123 bool handled = true; |
123 IPC_BEGIN_MESSAGE_MAP(ExtensionTabHelper, message) | 124 IPC_BEGIN_MESSAGE_MAP(ExtensionTabHelper, message) |
124 IPC_MESSAGE_HANDLER(ExtensionHostMsg_DidGetApplicationInfo, | 125 IPC_MESSAGE_HANDLER(ExtensionHostMsg_DidGetApplicationInfo, |
125 OnDidGetApplicationInfo) | 126 OnDidGetApplicationInfo) |
126 IPC_MESSAGE_HANDLER(ExtensionHostMsg_InstallApplication, | 127 IPC_MESSAGE_HANDLER(ExtensionHostMsg_InstallApplication, |
127 OnInstallApplication) | 128 OnInstallApplication) |
128 IPC_MESSAGE_HANDLER(ExtensionHostMsg_InlineWebstoreInstall, | 129 IPC_MESSAGE_HANDLER(ExtensionHostMsg_InlineWebstoreInstall, |
129 OnInlineWebstoreInstall) | 130 OnInlineWebstoreInstall) |
131 IPC_MESSAGE_HANDLER(ExtensionHostMsg_GetAppNotifyChannel, | |
132 OnGetAppNotifyChannel) | |
130 IPC_MESSAGE_HANDLER(ExtensionHostMsg_Request, OnRequest) | 133 IPC_MESSAGE_HANDLER(ExtensionHostMsg_Request, OnRequest) |
131 IPC_MESSAGE_UNHANDLED(handled = false) | 134 IPC_MESSAGE_UNHANDLED(handled = false) |
132 IPC_END_MESSAGE_MAP() | 135 IPC_END_MESSAGE_MAP() |
133 return handled; | 136 return handled; |
134 } | 137 } |
135 | 138 |
136 void ExtensionTabHelper::OnDidGetApplicationInfo( | 139 void ExtensionTabHelper::OnDidGetApplicationInfo( |
137 int32 page_id, const WebApplicationInfo& info) { | 140 int32 page_id, const WebApplicationInfo& info) { |
138 web_app_info_ = info; | 141 web_app_info_ = info; |
139 | 142 |
140 if (wrapper_->delegate()) | 143 if (wrapper_->delegate()) |
141 wrapper_->delegate()->OnDidGetApplicationInfo(wrapper_, page_id); | 144 wrapper_->delegate()->OnDidGetApplicationInfo(wrapper_, page_id); |
142 } | 145 } |
143 | 146 |
144 void ExtensionTabHelper::OnInstallApplication(const WebApplicationInfo& info) { | 147 void ExtensionTabHelper::OnInstallApplication(const WebApplicationInfo& info) { |
145 if (wrapper_->delegate()) | 148 if (wrapper_->delegate()) |
146 wrapper_->delegate()->OnInstallApplication(wrapper_, info); | 149 wrapper_->delegate()->OnInstallApplication(wrapper_, info); |
147 } | 150 } |
148 | 151 |
149 void ExtensionTabHelper::OnInlineWebstoreInstall( | 152 void ExtensionTabHelper::OnInlineWebstoreInstall( |
150 int install_id, | 153 int install_id, |
151 const std::string& webstore_item_id, | 154 const std::string& webstore_item_id, |
152 const GURL& requestor_url) { | 155 const GURL& requestor_url) { |
153 scoped_refptr<WebstoreInlineInstaller> installer(new WebstoreInlineInstaller( | 156 scoped_refptr<WebstoreInlineInstaller> installer(new WebstoreInlineInstaller( |
154 tab_contents(), install_id, webstore_item_id, requestor_url, this)); | 157 tab_contents(), install_id, webstore_item_id, requestor_url, this)); |
155 installer->BeginInstall(); | 158 installer->BeginInstall(); |
156 } | 159 } |
157 | 160 |
161 void ExtensionTabHelper::OnGetAppNotifyChannel( | |
162 int request_id, | |
163 const GURL& requestor_url, | |
164 const std::string& client_id) { | |
165 | |
166 // Check for permission first. | |
167 Profile* profile = | |
168 Profile::FromBrowserContext(tab_contents()->browser_context()); | |
169 ExtensionService* extension_service = profile->GetExtensionService(); | |
170 ExtensionProcessManager* process_manager = | |
171 profile->GetExtensionProcessManager(); | |
172 RenderProcessHost* process = | |
173 tab_contents_wrapper()->render_view_host()->process(); | |
174 const Extension* extension = | |
175 extension_service->GetInstalledApp(requestor_url); | |
Aaron Boodman
2011/10/06 20:29:28
Are you sure this works correctly for hosted apps?
asargent_no_longer_on_chrome
2011/10/06 22:37:38
The process check below is:
(extension->is_hosted
Aaron Boodman
2011/10/06 22:40:26
I see, ok.
| |
176 bool allowed = | |
177 extension && | |
178 extension->is_app() && | |
179 extension->HasAPIPermission( | |
180 ExtensionAPIPermission::kExperimental) && | |
181 (extension->is_hosted_app() || | |
182 process_manager->GetExtensionProcess(requestor_url) == process); | |
183 if (!allowed) { | |
184 AppNotifyChannelSetupComplete(request_id, "", "permission_error"); | |
185 return; | |
186 } | |
187 | |
188 scoped_refptr<AppNotifyChannelSetup> channel_setup( | |
189 new AppNotifyChannelSetup(request_id, | |
190 client_id, | |
191 requestor_url, | |
192 this->AsWeakPtr())); | |
193 channel_setup->Start(); | |
194 // We'll get called back in AppNotifyChannelSetupComplete. | |
195 } | |
196 | |
197 void ExtensionTabHelper::AppNotifyChannelSetupComplete( | |
198 int request_id, const std::string& client_id, const std::string& error) { | |
199 Send(new ExtensionMsg_GetAppNotifyChannelResponse( | |
200 routing_id(), request_id, client_id, error)); | |
201 } | |
202 | |
158 void ExtensionTabHelper::OnRequest( | 203 void ExtensionTabHelper::OnRequest( |
159 const ExtensionHostMsg_Request_Params& request) { | 204 const ExtensionHostMsg_Request_Params& request) { |
160 extension_function_dispatcher_.Dispatch(request, | 205 extension_function_dispatcher_.Dispatch(request, |
161 tab_contents()->render_view_host()); | 206 tab_contents()->render_view_host()); |
162 } | 207 } |
163 | 208 |
164 void ExtensionTabHelper::UpdateExtensionAppIcon(const Extension* extension) { | 209 void ExtensionTabHelper::UpdateExtensionAppIcon(const Extension* extension) { |
165 extension_app_icon_.reset(); | 210 extension_app_icon_.reset(); |
166 | 211 |
167 if (extension) { | 212 if (extension) { |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
215 } | 260 } |
216 | 261 |
217 TabContents* ExtensionTabHelper::GetAssociatedTabContents() const { | 262 TabContents* ExtensionTabHelper::GetAssociatedTabContents() const { |
218 return tab_contents(); | 263 return tab_contents(); |
219 } | 264 } |
220 | 265 |
221 gfx::NativeView ExtensionTabHelper::GetNativeViewOfHost() { | 266 gfx::NativeView ExtensionTabHelper::GetNativeViewOfHost() { |
222 RenderWidgetHostView* rwhv = tab_contents()->GetRenderWidgetHostView(); | 267 RenderWidgetHostView* rwhv = tab_contents()->GetRenderWidgetHostView(); |
223 return rwhv ? rwhv->GetNativeView() : NULL; | 268 return rwhv ? rwhv->GetNativeView() : NULL; |
224 } | 269 } |
OLD | NEW |