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 "chrome/browser/extensions/extension_service.h" | 8 #include "chrome/browser/extensions/extension_service.h" |
8 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
9 #include "chrome/browser/sessions/restore_tab_helper.h" | 10 #include "chrome/browser/sessions/restore_tab_helper.h" |
10 #include "chrome/browser/ui/browser.h" | 11 #include "chrome/browser/ui/browser.h" |
11 #include "chrome/browser/ui/browser_list.h" | 12 #include "chrome/browser/ui/browser_list.h" |
12 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 13 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
13 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper_delegate.h" | 14 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper_delegate.h" |
14 #include "chrome/common/chrome_notification_types.h" | 15 #include "chrome/common/chrome_notification_types.h" |
| 16 #include "chrome/common/chrome_switches.h" |
15 #include "chrome/common/extensions/extension_action.h" | 17 #include "chrome/common/extensions/extension_action.h" |
| 18 #include "chrome/common/extensions/extension_constants.h" |
16 #include "chrome/common/extensions/extension_icon_set.h" | 19 #include "chrome/common/extensions/extension_icon_set.h" |
17 #include "chrome/common/extensions/extension_messages.h" | 20 #include "chrome/common/extensions/extension_messages.h" |
18 #include "chrome/common/extensions/extension_resource.h" | 21 #include "chrome/common/extensions/extension_resource.h" |
19 #include "content/browser/renderer_host/render_widget_host_view.h" | 22 #include "content/browser/renderer_host/render_widget_host_view.h" |
20 #include "content/browser/tab_contents/navigation_details.h" | 23 #include "content/browser/tab_contents/navigation_details.h" |
21 #include "content/browser/tab_contents/tab_contents.h" | 24 #include "content/browser/tab_contents/tab_contents.h" |
22 #include "content/common/notification_service.h" | 25 #include "content/common/notification_service.h" |
23 | 26 |
24 ExtensionTabHelper::ExtensionTabHelper(TabContentsWrapper* wrapper) | 27 ExtensionTabHelper::ExtensionTabHelper(TabContentsWrapper* wrapper) |
25 : TabContentsObserver(wrapper->tab_contents()), | 28 : TabContentsObserver(wrapper->tab_contents()), |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 } | 119 } |
117 } | 120 } |
118 | 121 |
119 bool ExtensionTabHelper::OnMessageReceived(const IPC::Message& message) { | 122 bool ExtensionTabHelper::OnMessageReceived(const IPC::Message& message) { |
120 bool handled = true; | 123 bool handled = true; |
121 IPC_BEGIN_MESSAGE_MAP(ExtensionTabHelper, message) | 124 IPC_BEGIN_MESSAGE_MAP(ExtensionTabHelper, message) |
122 IPC_MESSAGE_HANDLER(ExtensionHostMsg_DidGetApplicationInfo, | 125 IPC_MESSAGE_HANDLER(ExtensionHostMsg_DidGetApplicationInfo, |
123 OnDidGetApplicationInfo) | 126 OnDidGetApplicationInfo) |
124 IPC_MESSAGE_HANDLER(ExtensionHostMsg_InstallApplication, | 127 IPC_MESSAGE_HANDLER(ExtensionHostMsg_InstallApplication, |
125 OnInstallApplication) | 128 OnInstallApplication) |
| 129 IPC_MESSAGE_HANDLER(ExtensionHostMsg_InlineWebstoreInstall, |
| 130 OnInlineWebstoreInstall) |
126 IPC_MESSAGE_HANDLER(ExtensionHostMsg_Request, OnRequest) | 131 IPC_MESSAGE_HANDLER(ExtensionHostMsg_Request, OnRequest) |
127 IPC_MESSAGE_UNHANDLED(handled = false) | 132 IPC_MESSAGE_UNHANDLED(handled = false) |
128 IPC_END_MESSAGE_MAP() | 133 IPC_END_MESSAGE_MAP() |
129 return handled; | 134 return handled; |
130 } | 135 } |
131 | 136 |
132 void ExtensionTabHelper::OnDidGetApplicationInfo( | 137 void ExtensionTabHelper::OnDidGetApplicationInfo( |
133 int32 page_id, const WebApplicationInfo& info) { | 138 int32 page_id, const WebApplicationInfo& info) { |
134 web_app_info_ = info; | 139 web_app_info_ = info; |
135 | 140 |
136 if (wrapper_->delegate()) | 141 if (wrapper_->delegate()) |
137 wrapper_->delegate()->OnDidGetApplicationInfo(wrapper_, page_id); | 142 wrapper_->delegate()->OnDidGetApplicationInfo(wrapper_, page_id); |
138 } | 143 } |
139 | 144 |
140 void ExtensionTabHelper::OnInstallApplication(const WebApplicationInfo& info) { | 145 void ExtensionTabHelper::OnInstallApplication(const WebApplicationInfo& info) { |
141 if (wrapper_->delegate()) | 146 if (wrapper_->delegate()) |
142 wrapper_->delegate()->OnInstallApplication(wrapper_, info); | 147 wrapper_->delegate()->OnInstallApplication(wrapper_, info); |
143 } | 148 } |
144 | 149 |
| 150 void ExtensionTabHelper::OnInlineWebstoreInstall( |
| 151 const std::string& webstore_item_id) { |
| 152 if (!CommandLine::ForCurrentProcess()->HasSwitch( |
| 153 switches::kEnableInlineWebstoreInstall)) { |
| 154 return; |
| 155 } |
| 156 |
| 157 // For now there is no inline installation UI, we just open the item's Web |
| 158 // Store page in a new tab. |
| 159 GURL webstore_item_url = |
| 160 GURL(extension_misc::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 } |
| 167 |
145 void ExtensionTabHelper::OnRequest( | 168 void ExtensionTabHelper::OnRequest( |
146 const ExtensionHostMsg_Request_Params& request) { | 169 const ExtensionHostMsg_Request_Params& request) { |
147 extension_function_dispatcher_.Dispatch(request, | 170 extension_function_dispatcher_.Dispatch(request, |
148 tab_contents()->render_view_host()); | 171 tab_contents()->render_view_host()); |
149 } | 172 } |
150 | 173 |
151 void ExtensionTabHelper::UpdateExtensionAppIcon(const Extension* extension) { | 174 void ExtensionTabHelper::UpdateExtensionAppIcon(const Extension* extension) { |
152 extension_app_icon_.reset(); | 175 extension_app_icon_.reset(); |
153 | 176 |
154 if (extension) { | 177 if (extension) { |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 if (tab_contents_delegate) | 228 if (tab_contents_delegate) |
206 return tab_contents_delegate->GetFrameNativeWindow(); | 229 return tab_contents_delegate->GetFrameNativeWindow(); |
207 else | 230 else |
208 return NULL; | 231 return NULL; |
209 } | 232 } |
210 | 233 |
211 gfx::NativeView ExtensionTabHelper::GetNativeViewOfHost() { | 234 gfx::NativeView ExtensionTabHelper::GetNativeViewOfHost() { |
212 RenderWidgetHostView* rwhv = tab_contents()->GetRenderWidgetHostView(); | 235 RenderWidgetHostView* rwhv = tab_contents()->GetRenderWidgetHostView(); |
213 return rwhv ? rwhv->GetNativeView() : NULL; | 236 return rwhv ? rwhv->GetNativeView() : NULL; |
214 } | 237 } |
OLD | NEW |