| 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/ui/web_applications/web_app_ui.h" | 5 #include "chrome/browser/ui/web_applications/web_app_ui.h" |
| 6 | 6 |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
| 9 #include "base/task.h" | 9 #include "base/task.h" |
| 10 #include "base/win/windows_version.h" | 10 #include "base/win/windows_version.h" |
| 11 #include "chrome/browser/extensions/extension_tab_helper.h" |
| 11 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/browser/web_applications/web_app.h" | 13 #include "chrome/browser/web_applications/web_app.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/common/chrome_paths.h" | 15 #include "chrome/common/chrome_paths.h" |
| 15 #include "content/browser/browser_thread.h" | 16 #include "content/browser/browser_thread.h" |
| 16 #include "content/browser/tab_contents/tab_contents.h" | 17 #include "content/browser/tab_contents/tab_contents.h" |
| 17 #include "content/common/notification_registrar.h" | 18 #include "content/common/notification_registrar.h" |
| 18 | 19 |
| 19 #if defined(OS_LINUX) | 20 #if defined(OS_LINUX) |
| 20 #include "base/environment.h" | 21 #include "base/environment.h" |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 // Existing shortcuts. | 86 // Existing shortcuts. |
| 86 std::vector<FilePath> shortcut_files_; | 87 std::vector<FilePath> shortcut_files_; |
| 87 | 88 |
| 88 DISALLOW_COPY_AND_ASSIGN(UpdateShortcutWorker); | 89 DISALLOW_COPY_AND_ASSIGN(UpdateShortcutWorker); |
| 89 }; | 90 }; |
| 90 | 91 |
| 91 UpdateShortcutWorker::UpdateShortcutWorker(TabContentsWrapper* tab_contents) | 92 UpdateShortcutWorker::UpdateShortcutWorker(TabContentsWrapper* tab_contents) |
| 92 : tab_contents_(tab_contents), | 93 : tab_contents_(tab_contents), |
| 93 profile_path_(tab_contents->profile()->GetPath()) { | 94 profile_path_(tab_contents->profile()->GetPath()) { |
| 94 web_app::GetShortcutInfoForTab(tab_contents_, &shortcut_info_); | 95 web_app::GetShortcutInfoForTab(tab_contents_, &shortcut_info_); |
| 95 web_app::GetIconsInfo(tab_contents_->tab_contents()->web_app_info(), | 96 web_app::GetIconsInfo(tab_contents_->extension_tab_helper()->web_app_info(), |
| 96 &unprocessed_icons_); | 97 &unprocessed_icons_); |
| 97 file_name_ = web_app::internals::GetSanitizedFileName(shortcut_info_.title); | 98 file_name_ = web_app::internals::GetSanitizedFileName(shortcut_info_.title); |
| 98 | 99 |
| 99 registrar_.Add(this, NotificationType::TAB_CLOSING, | 100 registrar_.Add(this, NotificationType::TAB_CLOSING, |
| 100 Source<NavigationController>(&tab_contents_->controller())); | 101 Source<NavigationController>(&tab_contents_->controller())); |
| 101 } | 102 } |
| 102 | 103 |
| 103 void UpdateShortcutWorker::Run() { | 104 void UpdateShortcutWorker::Run() { |
| 104 // Starting by downloading app icon. | 105 // Starting by downloading app icon. |
| 105 DownloadIcon(); | 106 DownloadIcon(); |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 DISABLE_RUNNABLE_METHOD_REFCOUNT(UpdateShortcutWorker); | 286 DISABLE_RUNNABLE_METHOD_REFCOUNT(UpdateShortcutWorker); |
| 286 #endif // defined(OS_WIN) | 287 #endif // defined(OS_WIN) |
| 287 | 288 |
| 288 namespace web_app { | 289 namespace web_app { |
| 289 | 290 |
| 290 void GetShortcutInfoForTab(TabContentsWrapper* tab_contents_wrapper, | 291 void GetShortcutInfoForTab(TabContentsWrapper* tab_contents_wrapper, |
| 291 ShellIntegration::ShortcutInfo* info) { | 292 ShellIntegration::ShortcutInfo* info) { |
| 292 DCHECK(info); // Must provide a valid info. | 293 DCHECK(info); // Must provide a valid info. |
| 293 const TabContents* tab_contents = tab_contents_wrapper->tab_contents(); | 294 const TabContents* tab_contents = tab_contents_wrapper->tab_contents(); |
| 294 | 295 |
| 295 const WebApplicationInfo& app_info = tab_contents->web_app_info(); | 296 const WebApplicationInfo& app_info = |
| 297 tab_contents_wrapper->extension_tab_helper()->web_app_info(); |
| 296 | 298 |
| 297 info->url = app_info.app_url.is_empty() ? tab_contents->GetURL() : | 299 info->url = app_info.app_url.is_empty() ? tab_contents->GetURL() : |
| 298 app_info.app_url; | 300 app_info.app_url; |
| 299 info->title = app_info.title.empty() ? | 301 info->title = app_info.title.empty() ? |
| 300 (tab_contents->GetTitle().empty() ? UTF8ToUTF16(info->url.spec()) : | 302 (tab_contents->GetTitle().empty() ? UTF8ToUTF16(info->url.spec()) : |
| 301 tab_contents->GetTitle()) : | 303 tab_contents->GetTitle()) : |
| 302 app_info.title; | 304 app_info.title; |
| 303 info->description = app_info.description; | 305 info->description = app_info.description; |
| 304 info->favicon = tab_contents->GetFavicon(); | 306 info->favicon = tab_contents->GetFavicon(); |
| 305 } | 307 } |
| 306 | 308 |
| 307 void UpdateShortcutForTabContents(TabContentsWrapper* tab_contents) { | 309 void UpdateShortcutForTabContents(TabContentsWrapper* tab_contents) { |
| 308 #if defined(OS_WIN) | 310 #if defined(OS_WIN) |
| 309 // UpdateShortcutWorker will delete itself when it's done. | 311 // UpdateShortcutWorker will delete itself when it's done. |
| 310 UpdateShortcutWorker* worker = new UpdateShortcutWorker(tab_contents); | 312 UpdateShortcutWorker* worker = new UpdateShortcutWorker(tab_contents); |
| 311 worker->Run(); | 313 worker->Run(); |
| 312 #endif // defined(OS_WIN) | 314 #endif // defined(OS_WIN) |
| 313 } | 315 } |
| 314 | 316 |
| 315 } // namespace web_app | 317 } // namespace web_app |
| OLD | NEW |