Chromium Code Reviews| 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/extensions/tab_helper.h" | 5 #include "chrome/browser/extensions/tab_helper.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
| 9 #include "chrome/browser/chrome_notification_types.h" | 9 #include "chrome/browser/chrome_notification_types.h" |
| 10 #include "chrome/browser/extensions/activity_log/activity_log.h" | 10 #include "chrome/browser/extensions/activity_log/activity_log.h" |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 27 #include "chrome/browser/profiles/profile.h" | 27 #include "chrome/browser/profiles/profile.h" |
| 28 #include "chrome/browser/sessions/session_id.h" | 28 #include "chrome/browser/sessions/session_id.h" |
| 29 #include "chrome/browser/sessions/session_tab_helper.h" | 29 #include "chrome/browser/sessions/session_tab_helper.h" |
| 30 #include "chrome/browser/shell_integration.h" | 30 #include "chrome/browser/shell_integration.h" |
| 31 #include "chrome/browser/ui/app_list/app_list_service.h" | 31 #include "chrome/browser/ui/app_list/app_list_service.h" |
| 32 #include "chrome/browser/ui/app_list/app_list_util.h" | 32 #include "chrome/browser/ui/app_list/app_list_util.h" |
| 33 #include "chrome/browser/ui/browser_commands.h" | 33 #include "chrome/browser/ui/browser_commands.h" |
| 34 #include "chrome/browser/ui/browser_dialogs.h" | 34 #include "chrome/browser/ui/browser_dialogs.h" |
| 35 #include "chrome/browser/ui/browser_finder.h" | 35 #include "chrome/browser/ui/browser_finder.h" |
| 36 #include "chrome/browser/ui/host_desktop.h" | 36 #include "chrome/browser/ui/host_desktop.h" |
| 37 #include "chrome/browser/ui/web_applications/hosted_app_tab_helper.h" | |
| 37 #include "chrome/browser/ui/web_applications/web_app_ui.h" | 38 #include "chrome/browser/ui/web_applications/web_app_ui.h" |
| 38 #include "chrome/browser/web_applications/web_app.h" | 39 #include "chrome/browser/web_applications/web_app.h" |
| 39 #include "chrome/common/extensions/extension.h" | 40 #include "chrome/common/extensions/extension.h" |
| 40 #include "chrome/common/extensions/extension_constants.h" | 41 #include "chrome/common/extensions/extension_constants.h" |
| 41 #include "chrome/common/extensions/extension_icon_set.h" | 42 #include "chrome/common/extensions/extension_icon_set.h" |
| 42 #include "chrome/common/extensions/extension_messages.h" | 43 #include "chrome/common/extensions/extension_messages.h" |
| 43 #include "chrome/common/extensions/feature_switch.h" | 44 #include "chrome/common/extensions/feature_switch.h" |
| 44 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" | 45 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" |
| 45 #include "chrome/common/extensions/manifest_handlers/icons_handler.h" | 46 #include "chrome/common/extensions/manifest_handlers/icons_handler.h" |
| 46 #include "chrome/common/render_messages.h" | 47 #include "chrome/common/render_messages.h" |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 294 const WebApplicationInfo& info) { | 295 const WebApplicationInfo& info) { |
| 295 // Android does not implement BrowserWindow. | 296 // Android does not implement BrowserWindow. |
| 296 #if !defined(OS_MACOSX) && !defined(OS_ANDROID) | 297 #if !defined(OS_MACOSX) && !defined(OS_ANDROID) |
| 297 web_app_info_ = info; | 298 web_app_info_ = info; |
| 298 | 299 |
| 299 NavigationEntry* entry = | 300 NavigationEntry* entry = |
| 300 web_contents()->GetController().GetLastCommittedEntry(); | 301 web_contents()->GetController().GetLastCommittedEntry(); |
| 301 if (!entry || (entry->GetPageID() != page_id)) | 302 if (!entry || (entry->GetPageID() != page_id)) |
| 302 return; | 303 return; |
| 303 | 304 |
| 304 switch (pending_web_app_action_) { | 305 switch (pending_web_app_action_) { |
|
benwells
2013/11/13 21:55:17
We should remove all this pending_web_app_action_
calamity
2013/11/15 04:25:50
Maybe. The update stuff may still apply. We still
| |
| 305 case CREATE_SHORTCUT: { | 306 case CREATE_SHORTCUT: { |
| 306 chrome::ShowCreateWebAppShortcutsDialog( | 307 chrome::ShowCreateWebAppShortcutsDialog( |
| 307 web_contents()->GetView()->GetTopLevelNativeWindow(), | 308 web_contents()->GetView()->GetTopLevelNativeWindow(), |
| 308 web_contents()); | 309 web_contents()); |
| 309 break; | 310 break; |
| 310 } | 311 } |
| 311 case CREATE_HOSTED_APP: { | 312 case CREATE_HOSTED_APP: { |
| 312 CreateHostedApp(info); | 313 HostedAppTabHelper::FromWebContents(web_contents())-> |
| 314 CreateHostedApp(info); | |
| 313 break; | 315 break; |
| 314 } | 316 } |
| 315 case UPDATE_SHORTCUT: { | 317 case UPDATE_SHORTCUT: { |
| 316 web_app::UpdateShortcutForTabContents(web_contents()); | 318 web_app::UpdateShortcutForTabContents(web_contents()); |
| 317 break; | 319 break; |
| 318 } | 320 } |
| 319 default: | 321 default: |
| 320 NOTREACHED(); | 322 NOTREACHED(); |
| 321 break; | 323 break; |
| 322 } | 324 } |
| 323 | 325 |
| 324 // The hosted app action will be cleared once the installation completes or | 326 // The hosted app action will be cleared once the installation completes or |
| 325 // fails. | 327 // fails. |
| 326 if (pending_web_app_action_ != CREATE_HOSTED_APP) | 328 if (pending_web_app_action_ != CREATE_HOSTED_APP) |
| 327 pending_web_app_action_ = NONE; | 329 pending_web_app_action_ = NONE; |
| 328 #endif | 330 #endif |
| 329 } | 331 } |
| 330 | 332 |
| 331 void TabHelper::CreateHostedApp(const WebApplicationInfo& info) { | |
| 332 ShellIntegration::ShortcutInfo shortcut_info; | |
| 333 web_app::GetShortcutInfoForTab(web_contents(), &shortcut_info); | |
| 334 WebApplicationInfo web_app_info; | |
| 335 | |
| 336 web_app_info.is_bookmark_app = true; | |
| 337 web_app_info.app_url = shortcut_info.url; | |
| 338 web_app_info.title = shortcut_info.title; | |
| 339 web_app_info.urls.push_back(web_app_info.app_url); | |
| 340 | |
| 341 // TODO(calamity): this should attempt to download the best icon that it can | |
| 342 // from |info.icons| rather than just using the favicon as it scales up badly. | |
| 343 // Fix this once |info.icons| gets populated commonly. | |
| 344 | |
| 345 // Get the smallest icon in the icon family (should have only 1). | |
| 346 const gfx::Image* icon = shortcut_info.favicon.GetBest(0, 0); | |
| 347 SkBitmap bitmap = icon ? icon->AsBitmap() : SkBitmap(); | |
| 348 | |
| 349 if (!icon->IsEmpty()) { | |
| 350 WebApplicationInfo::IconInfo icon_info; | |
| 351 icon_info.data = bitmap; | |
| 352 icon_info.width = icon_info.data.width(); | |
| 353 icon_info.height = icon_info.data.height(); | |
| 354 web_app_info.icons.push_back(icon_info); | |
| 355 } | |
| 356 | |
| 357 ExtensionService* service = profile_->GetExtensionService(); | |
| 358 scoped_refptr<extensions::CrxInstaller> installer( | |
| 359 extensions::CrxInstaller::CreateSilent(service)); | |
| 360 installer->set_error_on_unsupported_requirements(true); | |
| 361 installer->InstallWebApp(web_app_info); | |
| 362 } | |
| 363 | |
| 364 void TabHelper::OnInlineWebstoreInstall( | 333 void TabHelper::OnInlineWebstoreInstall( |
| 365 int install_id, | 334 int install_id, |
| 366 int return_route_id, | 335 int return_route_id, |
| 367 const std::string& webstore_item_id, | 336 const std::string& webstore_item_id, |
| 368 const GURL& requestor_url) { | 337 const GURL& requestor_url) { |
| 369 WebstoreStandaloneInstaller::Callback callback = | 338 WebstoreStandaloneInstaller::Callback callback = |
| 370 base::Bind(&TabHelper::OnInlineInstallComplete, base::Unretained(this), | 339 base::Bind(&TabHelper::OnInlineInstallComplete, base::Unretained(this), |
| 371 install_id, return_route_id); | 340 install_id, return_route_id); |
| 372 scoped_refptr<WebstoreInlineInstaller> installer( | 341 scoped_refptr<WebstoreInlineInstaller> installer( |
| 373 webstore_inline_installer_factory_->CreateInstaller( | 342 webstore_inline_installer_factory_->CreateInstaller( |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 599 } | 568 } |
| 600 } | 569 } |
| 601 | 570 |
| 602 void TabHelper::SetTabId(RenderViewHost* render_view_host) { | 571 void TabHelper::SetTabId(RenderViewHost* render_view_host) { |
| 603 render_view_host->Send( | 572 render_view_host->Send( |
| 604 new ExtensionMsg_SetTabId(render_view_host->GetRoutingID(), | 573 new ExtensionMsg_SetTabId(render_view_host->GetRoutingID(), |
| 605 SessionID::IdForTab(web_contents()))); | 574 SessionID::IdForTab(web_contents()))); |
| 606 } | 575 } |
| 607 | 576 |
| 608 } // namespace extensions | 577 } // namespace extensions |
| OLD | NEW |