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 "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "chrome/browser/extensions/extension_service.h" | 8 #include "chrome/browser/extensions/extension_service.h" |
| 9 #include "chrome/browser/extensions/webstore_inline_installer.h" |
9 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
10 #include "chrome/browser/sessions/restore_tab_helper.h" | 11 #include "chrome/browser/sessions/restore_tab_helper.h" |
11 #include "chrome/browser/ui/browser.h" | 12 #include "chrome/browser/ui/browser.h" |
12 #include "chrome/browser/ui/browser_list.h" | 13 #include "chrome/browser/ui/browser_list.h" |
13 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 14 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
14 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper_delegate.h" | 15 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper_delegate.h" |
15 #include "chrome/common/chrome_notification_types.h" | 16 #include "chrome/common/chrome_notification_types.h" |
16 #include "chrome/common/chrome_switches.h" | 17 #include "chrome/common/chrome_switches.h" |
17 #include "chrome/common/extensions/extension_action.h" | 18 #include "chrome/common/extensions/extension_action.h" |
18 #include "chrome/common/extensions/extension_constants.h" | 19 #include "chrome/common/extensions/extension_constants.h" |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 wrapper_->delegate()->OnInstallApplication(wrapper_, info); | 148 wrapper_->delegate()->OnInstallApplication(wrapper_, info); |
148 } | 149 } |
149 | 150 |
150 void ExtensionTabHelper::OnInlineWebstoreInstall( | 151 void ExtensionTabHelper::OnInlineWebstoreInstall( |
151 const std::string& webstore_item_id) { | 152 const std::string& webstore_item_id) { |
152 if (!CommandLine::ForCurrentProcess()->HasSwitch( | 153 if (!CommandLine::ForCurrentProcess()->HasSwitch( |
153 switches::kEnableInlineWebstoreInstall)) { | 154 switches::kEnableInlineWebstoreInstall)) { |
154 return; | 155 return; |
155 } | 156 } |
156 | 157 |
157 // For now there is no inline installation UI, we just open the item's Web | 158 scoped_refptr<WebstoreInlineInstaller> installer(new WebstoreInlineInstaller( |
158 // Store page in a new tab. | 159 tab_contents(), webstore_item_id, this)); |
159 GURL webstore_item_url = | 160 installer->BeginInstall(); |
160 GURL(extension_urls::GetWebstoreItemDetailURLPrefix() + webstore_item_id); | |
161 GetBrowser()->OpenURL(OpenURLParams( | |
162 webstore_item_url, | |
163 GetBrowser()->GetSelectedTabContents()->GetURL(), | |
164 NEW_FOREGROUND_TAB, | |
165 PageTransition::AUTO_BOOKMARK)); | |
166 } | 161 } |
167 | 162 |
168 void ExtensionTabHelper::OnRequest( | 163 void ExtensionTabHelper::OnRequest( |
169 const ExtensionHostMsg_Request_Params& request) { | 164 const ExtensionHostMsg_Request_Params& request) { |
170 extension_function_dispatcher_.Dispatch(request, | 165 extension_function_dispatcher_.Dispatch(request, |
171 tab_contents()->render_view_host()); | 166 tab_contents()->render_view_host()); |
172 } | 167 } |
173 | 168 |
174 void ExtensionTabHelper::UpdateExtensionAppIcon(const Extension* extension) { | 169 void ExtensionTabHelper::UpdateExtensionAppIcon(const Extension* extension) { |
175 extension_app_icon_.reset(); | 170 extension_app_icon_.reset(); |
(...skipping 30 matching lines...) Expand all Loading... |
206 TabContents* contents = tab_contents(); | 201 TabContents* contents = tab_contents(); |
207 TabContentsIterator tab_iterator; | 202 TabContentsIterator tab_iterator; |
208 for (; !tab_iterator.done(); ++tab_iterator) { | 203 for (; !tab_iterator.done(); ++tab_iterator) { |
209 if (contents == (*tab_iterator)->tab_contents()) | 204 if (contents == (*tab_iterator)->tab_contents()) |
210 return tab_iterator.browser(); | 205 return tab_iterator.browser(); |
211 } | 206 } |
212 | 207 |
213 return NULL; | 208 return NULL; |
214 } | 209 } |
215 | 210 |
| 211 void ExtensionTabHelper::OnInlineInstallSuccess() { |
| 212 Send(new ExtensionMsg_InlineWebstoreInstallResponse(routing_id(), true, "")); |
| 213 } |
| 214 |
| 215 void ExtensionTabHelper::OnInlineInstallFailure(const std::string& error) { |
| 216 Send(new ExtensionMsg_InlineWebstoreInstallResponse( |
| 217 routing_id(), false, error)); |
| 218 } |
| 219 |
216 TabContents* ExtensionTabHelper::GetAssociatedTabContents() const { | 220 TabContents* ExtensionTabHelper::GetAssociatedTabContents() const { |
217 return tab_contents(); | 221 return tab_contents(); |
218 } | 222 } |
219 | 223 |
220 gfx::NativeWindow ExtensionTabHelper::GetCustomFrameNativeWindow() { | |
221 if (GetBrowser()) | |
222 return NULL; | |
223 | |
224 // If there was no browser associated with the function dispatcher delegate, | |
225 // then this WebUI may be hosted in an ExternalTabContainer, and a framing | |
226 // window will be accessible through the tab_contents. | |
227 TabContentsDelegate* tab_contents_delegate = tab_contents()->delegate(); | |
228 if (tab_contents_delegate) | |
229 return tab_contents_delegate->GetFrameNativeWindow(); | |
230 else | |
231 return NULL; | |
232 } | |
233 | |
234 gfx::NativeView ExtensionTabHelper::GetNativeViewOfHost() { | 224 gfx::NativeView ExtensionTabHelper::GetNativeViewOfHost() { |
235 RenderWidgetHostView* rwhv = tab_contents()->GetRenderWidgetHostView(); | 225 RenderWidgetHostView* rwhv = tab_contents()->GetRenderWidgetHostView(); |
236 return rwhv ? rwhv->GetNativeView() : NULL; | 226 return rwhv ? rwhv->GetNativeView() : NULL; |
237 } | 227 } |
OLD | NEW |