diff options
author | jackhou@chromium.org <jackhou@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-03 18:18:05 +0000 |
---|---|---|
committer | jackhou@chromium.org <jackhou@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-03 18:18:05 +0000 |
commit | 2d1d16f1498a988a09c74ac33b475dbd428af495 (patch) | |
tree | e3bb918d971da1ffdf9548fb2dad468641ee87dc | |
parent | 3f3abff5f7332dc24a3b82c90423ceddc3969a55 (diff) | |
download | chromium_src-2d1d16f1498a988a09c74ac33b475dbd428af495.zip chromium_src-2d1d16f1498a988a09c74ac33b475dbd428af495.tar.gz chromium_src-2d1d16f1498a988a09c74ac33b475dbd428af495.tar.bz2 |
Remove web_app_ui.[cc|h].
The UpdateShortcutWorker class is windows specific and is moved to its own file.
UpdateShortcutForTabContents is moved to web_app_win.
GetShortcutInfoForTab is moved to web_app.
TBR=sky@chromium.org
BUG=356889
Review URL: https://codereview.chromium.org/213113005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@261481 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | apps/app_shim/DEPS | 1 | ||||
-rw-r--r-- | chrome/browser/extensions/tab_helper.cc | 5 | ||||
-rw-r--r-- | chrome/browser/ui/gtk/create_application_shortcuts_dialog_gtk.cc | 1 | ||||
-rw-r--r-- | chrome/browser/ui/views/apps/chrome_native_app_window_views_win.cc | 1 | ||||
-rw-r--r-- | chrome/browser/ui/views/create_application_shortcut_view.cc | 2 | ||||
-rw-r--r-- | chrome/browser/ui/web_applications/web_app_ui.h | 37 | ||||
-rw-r--r-- | chrome/browser/web_applications/update_shortcut_worker_win.cc (renamed from chrome/browser/ui/web_applications/web_app_ui.cc) | 129 | ||||
-rw-r--r-- | chrome/browser/web_applications/update_shortcut_worker_win.h | 89 | ||||
-rw-r--r-- | chrome/browser/web_applications/web_app.cc | 30 | ||||
-rw-r--r-- | chrome/browser/web_applications/web_app.h | 15 | ||||
-rw-r--r-- | chrome/browser/web_applications/web_app_unittest.cc | 1 | ||||
-rw-r--r-- | chrome/browser/web_applications/web_app_win.cc | 7 | ||||
-rw-r--r-- | chrome/browser/web_applications/web_app_win.h | 4 | ||||
-rw-r--r-- | chrome/chrome_browser.gypi | 2 | ||||
-rw-r--r-- | chrome/chrome_browser_ui.gypi | 2 |
15 files changed, 161 insertions, 165 deletions
diff --git a/apps/app_shim/DEPS b/apps/app_shim/DEPS index 6c77a25..e836a97 100644 --- a/apps/app_shim/DEPS +++ b/apps/app_shim/DEPS @@ -7,7 +7,6 @@ include_rules = [ "+chrome/browser/ui/extensions/application_launch.h", "+chrome/browser/ui/extensions/extension_enable_flow.h", "+chrome/browser/ui/extensions/extension_enable_flow_delegate.h", - "+chrome/browser/ui/web_applications/web_app_ui.h", "+chrome/browser/ui/webui/ntp/core_app_launcher_handler.h", "+chrome/browser/web_applications/web_app_mac.h", "+chrome/common/chrome_constants.h", diff --git a/chrome/browser/extensions/tab_helper.cc b/chrome/browser/extensions/tab_helper.cc index 402c89b..d38c151 100644 --- a/chrome/browser/extensions/tab_helper.cc +++ b/chrome/browser/extensions/tab_helper.cc @@ -34,7 +34,6 @@ #include "chrome/browser/ui/browser_finder.h" #include "chrome/browser/ui/browser_window.h" #include "chrome/browser/ui/host_desktop.h" -#include "chrome/browser/ui/web_applications/web_app_ui.h" #include "chrome/browser/web_applications/web_app.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/extensions/chrome_extension_messages.h" @@ -70,6 +69,10 @@ #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" #endif +#if defined(OS_WIN) +#include "chrome/browser/web_applications/web_app_win.h" +#endif + using content::NavigationController; using content::NavigationEntry; using content::RenderViewHost; diff --git a/chrome/browser/ui/gtk/create_application_shortcuts_dialog_gtk.cc b/chrome/browser/ui/gtk/create_application_shortcuts_dialog_gtk.cc index 625b2a8..503bff6 100644 --- a/chrome/browser/ui/gtk/create_application_shortcuts_dialog_gtk.cc +++ b/chrome/browser/ui/gtk/create_application_shortcuts_dialog_gtk.cc @@ -17,7 +17,6 @@ #include "chrome/browser/ui/browser_dialogs.h" #include "chrome/browser/ui/browser_finder.h" #include "chrome/browser/ui/gtk/gtk_util.h" -#include "chrome/browser/ui/web_applications/web_app_ui.h" #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" #include "chrome/browser/web_applications/web_app.h" #include "chrome/common/extensions/manifest_handlers/icons_handler.h" diff --git a/chrome/browser/ui/views/apps/chrome_native_app_window_views_win.cc b/chrome/browser/ui/views/apps/chrome_native_app_window_views_win.cc index 18b5b82..2c7ef56 100644 --- a/chrome/browser/ui/views/apps/chrome_native_app_window_views_win.cc +++ b/chrome/browser/ui/views/apps/chrome_native_app_window_views_win.cc @@ -18,7 +18,6 @@ #include "chrome/browser/metro_utils/metro_chrome_win.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/shell_integration.h" -#include "chrome/browser/ui/web_applications/web_app_ui.h" #include "chrome/browser/web_applications/web_app.h" #include "chrome/browser/web_applications/web_app_win.h" #include "chrome/common/chrome_icon_resources_win.h" diff --git a/chrome/browser/ui/views/create_application_shortcut_view.cc b/chrome/browser/ui/views/create_application_shortcut_view.cc index d2d90a7..238e6ed 100644 --- a/chrome/browser/ui/views/create_application_shortcut_view.cc +++ b/chrome/browser/ui/views/create_application_shortcut_view.cc @@ -19,8 +19,8 @@ #include "chrome/browser/ui/browser_commands.h" #include "chrome/browser/ui/browser_finder.h" #include "chrome/browser/ui/views/constrained_window_views.h" -#include "chrome/browser/ui/web_applications/web_app_ui.h" #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" +#include "chrome/browser/web_applications/web_app.h" #include "chrome/common/chrome_constants.h" #include "chrome/common/pref_names.h" #include "content/public/browser/render_view_host.h" diff --git a/chrome/browser/ui/web_applications/web_app_ui.h b/chrome/browser/ui/web_applications/web_app_ui.h deleted file mode 100644 index 0758119..0000000 --- a/chrome/browser/ui/web_applications/web_app_ui.h +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_UI_WEB_APPLICATIONS_WEB_APP_UI_H_ -#define CHROME_BROWSER_UI_WEB_APPLICATIONS_WEB_APP_UI_H_ - -#include <vector> - -#include "chrome/browser/shell_integration.h" - -namespace content { -class WebContents; -} - -namespace extensions { -class Extension; -} - -class Profile; - -namespace web_app { - -// Extracts shortcut info of the given WebContents. -void GetShortcutInfoForTab(content::WebContents* web_contents, - ShellIntegration::ShortcutInfo* info); - -// Updates web app shortcut of the WebContents. This function checks and -// updates web app icon and shortcuts if needed. For icon, the check is based -// on MD5 hash of icon image. For shortcuts, it checks the desktop, start menu -// and quick launch (as well as pinned shortcut) for shortcut and only -// updates (recreates) them if they exits. -void UpdateShortcutForTabContents(content::WebContents* web_contents); - -} // namespace web_app - -#endif // CHROME_BROWSER_UI_WEB_APPLICATIONS_WEB_APP_UI_H_ diff --git a/chrome/browser/ui/web_applications/web_app_ui.cc b/chrome/browser/web_applications/update_shortcut_worker_win.cc index 759491a..11e2c91 100644 --- a/chrome/browser/ui/web_applications/web_app_ui.cc +++ b/chrome/browser/web_applications/update_shortcut_worker_win.cc @@ -1,111 +1,37 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2014 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/browser/ui/web_applications/web_app_ui.h" +#include "chrome/browser/web_applications/update_shortcut_worker_win.h" + +#include <algorithm> #include "base/bind.h" #include "base/bind_helpers.h" #include "base/file_util.h" #include "base/path_service.h" #include "base/strings/utf_string_conversions.h" +#include "base/win/shortcut.h" +#include "base/win/windows_version.h" #include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/extensions/tab_helper.h" #include "chrome/browser/favicon/favicon_tab_helper.h" #include "chrome/browser/history/select_favicon_frames.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/web_applications/web_app.h" +#include "chrome/browser/web_applications/web_app_win.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/notification_details.h" -#include "content/public/browser/notification_registrar.h" #include "content/public/browser/notification_source.h" #include "content/public/browser/web_contents.h" -#include "url/gurl.h" - -#if defined(OS_POSIX) && !defined(OS_MACOSX) -#include "base/environment.h" -#endif - -#if defined(OS_WIN) -#include "base/win/shortcut.h" -#include "base/win/windows_version.h" -#include "chrome/browser/web_applications/web_app_win.h" #include "ui/gfx/icon_util.h" -#endif +#include "url/gurl.h" using content::BrowserThread; using content::NavigationController; using content::WebContents; -namespace { - -// TODO(jackhou): Move all win-specific code to web_app_win. -#if defined(OS_WIN) -// UpdateShortcutWorker holds all context data needed for update shortcut. -// It schedules a pre-update check to find all shortcuts that needs to be -// updated. If there are such shortcuts, it schedules icon download and -// update them when icons are downloaded. It observes TAB_CLOSING notification -// and cancels all the work when the underlying tab is closing. -class UpdateShortcutWorker : public content::NotificationObserver { - public: - explicit UpdateShortcutWorker(WebContents* web_contents); - - void Run(); - - private: - // Overridden from content::NotificationObserver: - virtual void Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details); - - // Downloads icon via the FaviconTabHelper. - void DownloadIcon(); - - // Favicon download callback. - void DidDownloadFavicon( - int requested_size, - int id, - int http_status_code, - const GURL& image_url, - const std::vector<SkBitmap>& bitmaps, - const std::vector<gfx::Size>& original_bitmap_sizes); - - // Checks if shortcuts exists on desktop, start menu and quick launch. - void CheckExistingShortcuts(); - - // Update shortcut files and icons. - void UpdateShortcuts(); - void UpdateShortcutsOnFileThread(); - - // Callback after shortcuts are updated. - void OnShortcutsUpdated(bool); - - // Deletes the worker on UI thread where it gets created. - void DeleteMe(); - void DeleteMeOnUIThread(); - - content::NotificationRegistrar registrar_; - - // Underlying WebContents whose shortcuts will be updated. - WebContents* web_contents_; - - // Icons info from web_contents_'s web app data. - web_app::IconInfoList unprocessed_icons_; - - // Cached shortcut data from the web_contents_. - ShellIntegration::ShortcutInfo shortcut_info_; - - // Our copy of profile path. - base::FilePath profile_path_; - - // File name of shortcut/ico file based on app title. - base::FilePath file_name_; - - // Existing shortcuts. - std::vector<base::FilePath> shortcut_files_; - - DISALLOW_COPY_AND_ASSIGN(UpdateShortcutWorker); -}; +namespace web_app { UpdateShortcutWorker::UpdateShortcutWorker(WebContents* web_contents) : web_contents_(web_contents), @@ -312,42 +238,5 @@ void UpdateShortcutWorker::DeleteMeOnUIThread() { DCHECK_CURRENTLY_ON(BrowserThread::UI); delete this; } -#endif // defined(OS_WIN) - -} // namespace - -namespace web_app { - -void GetShortcutInfoForTab(WebContents* web_contents, - ShellIntegration::ShortcutInfo* info) { - DCHECK(info); // Must provide a valid info. - - const FaviconTabHelper* favicon_tab_helper = - FaviconTabHelper::FromWebContents(web_contents); - const extensions::TabHelper* extensions_tab_helper = - extensions::TabHelper::FromWebContents(web_contents); - const WebApplicationInfo& app_info = extensions_tab_helper->web_app_info(); - - info->url = app_info.app_url.is_empty() ? web_contents->GetURL() : - app_info.app_url; - info->title = app_info.title.empty() ? - (web_contents->GetTitle().empty() ? base::UTF8ToUTF16(info->url.spec()) : - web_contents->GetTitle()) : - app_info.title; - info->description = app_info.description; - info->favicon.Add(favicon_tab_helper->GetFavicon()); - - Profile* profile = - Profile::FromBrowserContext(web_contents->GetBrowserContext()); - info->profile_path = profile->GetPath(); -} - -void UpdateShortcutForTabContents(WebContents* web_contents) { -#if defined(OS_WIN) - // UpdateShortcutWorker will delete itself when it's done. - UpdateShortcutWorker* worker = new UpdateShortcutWorker(web_contents); - worker->Run(); -#endif // defined(OS_WIN) -} } // namespace web_app diff --git a/chrome/browser/web_applications/update_shortcut_worker_win.h b/chrome/browser/web_applications/update_shortcut_worker_win.h new file mode 100644 index 0000000..fcfa000 --- /dev/null +++ b/chrome/browser/web_applications/update_shortcut_worker_win.h @@ -0,0 +1,89 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_WEB_APPLICATIONS_UPDATE_SHORTCUT_WORKER_WIN_H_ +#define CHROME_BROWSER_WEB_APPLICATIONS_UPDATE_SHORTCUT_WORKER_WIN_H_ + +#include "chrome/browser/shell_integration.h" +#include "chrome/browser/web_applications/web_app.h" +#include "content/public/browser/notification_observer.h" +#include "content/public/browser/notification_registrar.h" + +namespace content { +class NotificationDetails; +class NotificationSource; +class WebContents; +} + +namespace web_app { + +// UpdateShortcutWorker holds all context data needed for update shortcut. +// It schedules a pre-update check to find all shortcuts that needs to be +// updated. If there are such shortcuts, it schedules icon download and +// update them when icons are downloaded. It observes TAB_CLOSING notification +// and cancels all the work when the underlying tab is closing. +class UpdateShortcutWorker : public content::NotificationObserver { + public: + explicit UpdateShortcutWorker(content::WebContents* web_contents); + + void Run(); + + private: + // Overridden from content::NotificationObserver: + virtual void Observe(int type, + const content::NotificationSource& source, + const content::NotificationDetails& details); + + // Downloads icon via the FaviconTabHelper. + void DownloadIcon(); + + // Favicon download callback. + void DidDownloadFavicon( + int requested_size, + int id, + int http_status_code, + const GURL& image_url, + const std::vector<SkBitmap>& bitmaps, + const std::vector<gfx::Size>& original_bitmap_sizes); + + // Checks if shortcuts exists on desktop, start menu and quick launch. + void CheckExistingShortcuts(); + + // Update shortcut files and icons. + void UpdateShortcuts(); + void UpdateShortcutsOnFileThread(); + + // Callback after shortcuts are updated. + void OnShortcutsUpdated(bool); + + // Deletes the worker on UI thread where it gets created. + void DeleteMe(); + void DeleteMeOnUIThread(); + + content::NotificationRegistrar registrar_; + + // Underlying WebContents whose shortcuts will be updated. + content::WebContents* web_contents_; + + // Icons info from web_contents_'s web app data. + web_app::IconInfoList unprocessed_icons_; + + // Cached shortcut data from the web_contents_. + ShellIntegration::ShortcutInfo shortcut_info_; + + // Our copy of profile path. + base::FilePath profile_path_; + + // File name of shortcut/ico file based on app title. + base::FilePath file_name_; + + // Existing shortcuts. + std::vector<base::FilePath> shortcut_files_; + + DISALLOW_COPY_AND_ASSIGN(UpdateShortcutWorker); +}; + +} // namespace web_app + +#endif // CHROME_BROWSER_WEB_APPLICATIONS_UPDATE_SHORTCUT_WORKER_WIN_H_ diff --git a/chrome/browser/web_applications/web_app.cc b/chrome/browser/web_applications/web_app.cc index 5149be7..0d90975 100644 --- a/chrome/browser/web_applications/web_app.cc +++ b/chrome/browser/web_applications/web_app.cc @@ -13,6 +13,8 @@ #include "base/strings/utf_string_conversions.h" #include "base/threading/thread.h" #include "chrome/browser/extensions/image_loader.h" +#include "chrome/browser/extensions/tab_helper.h" +#include "chrome/browser/favicon/favicon_tab_helper.h" #include "chrome/browser/profiles/profile.h" #include "chrome/common/chrome_constants.h" #include "chrome/common/chrome_version_info.h" @@ -134,6 +136,34 @@ base::FilePath GetSanitizedFileName(const base::string16& name) { } // namespace internals +void GetShortcutInfoForTab(content::WebContents* web_contents, + ShellIntegration::ShortcutInfo* info) { + DCHECK(info); // Must provide a valid info. + + const FaviconTabHelper* favicon_tab_helper = + FaviconTabHelper::FromWebContents(web_contents); + const extensions::TabHelper* extensions_tab_helper = + extensions::TabHelper::FromWebContents(web_contents); + const WebApplicationInfo& app_info = extensions_tab_helper->web_app_info(); + + info->url = app_info.app_url.is_empty() ? web_contents->GetURL() : + app_info.app_url; + info->title = app_info.title.empty() ? + (web_contents->GetTitle().empty() ? base::UTF8ToUTF16(info->url.spec()) : + web_contents->GetTitle()) : + app_info.title; + info->description = app_info.description; + info->favicon.Add(favicon_tab_helper->GetFavicon()); + + Profile* profile = + Profile::FromBrowserContext(web_contents->GetBrowserContext()); + info->profile_path = profile->GetPath(); +} + +#if !defined(OS_WIN) +void UpdateShortcutForTabContents(content::WebContents* web_contents) {} +#endif + ShellIntegration::ShortcutInfo ShortcutInfoForExtensionAndProfile( const extensions::Extension* app, Profile* profile) { ShellIntegration::ShortcutInfo shortcut_info; diff --git a/chrome/browser/web_applications/web_app.h b/chrome/browser/web_applications/web_app.h index 986dcf1..79ea5a5 100644 --- a/chrome/browser/web_applications/web_app.h +++ b/chrome/browser/web_applications/web_app.h @@ -17,6 +17,10 @@ class Profile; +namespace content { +class WebContents; +} + namespace extensions { class Extension; } @@ -37,6 +41,17 @@ enum ShortcutCreationReason { typedef base::Callback<void(const ShellIntegration::ShortcutInfo&)> ShortcutInfoCallback; +// Extracts shortcut info of the given WebContents. +void GetShortcutInfoForTab(content::WebContents* web_contents, + ShellIntegration::ShortcutInfo* info); + +// Updates web app shortcut of the WebContents. This function checks and +// updates web app icon and shortcuts if needed. For icon, the check is based +// on MD5 hash of icon image. For shortcuts, it checks the desktop, start menu +// and quick launch (as well as pinned shortcut) for shortcut and only +// updates (recreates) them if they exits. +void UpdateShortcutForTabContents(content::WebContents* web_contents); + ShellIntegration::ShortcutInfo ShortcutInfoForExtensionAndProfile( const extensions::Extension* app, Profile* profile); diff --git a/chrome/browser/web_applications/web_app_unittest.cc b/chrome/browser/web_applications/web_app_unittest.cc index 3e145d0..4866102 100644 --- a/chrome/browser/web_applications/web_app_unittest.cc +++ b/chrome/browser/web_applications/web_app_unittest.cc @@ -9,7 +9,6 @@ #include "base/strings/utf_string_conversions.h" #include "chrome/browser/extensions/tab_helper.h" #include "chrome/browser/favicon/favicon_tab_helper.h" -#include "chrome/browser/ui/web_applications/web_app_ui.h" #include "chrome/browser/web_applications/web_app.h" #include "chrome/common/extensions/chrome_extension_messages.h" #include "chrome/test/base/chrome_render_view_host_test_harness.h" diff --git a/chrome/browser/web_applications/web_app_win.cc b/chrome/browser/web_applications/web_app_win.cc index 3178d67..d1dccce 100644 --- a/chrome/browser/web_applications/web_app_win.cc +++ b/chrome/browser/web_applications/web_app_win.cc @@ -17,6 +17,7 @@ #include "base/strings/utf_string_conversions.h" #include "base/win/shortcut.h" #include "base/win/windows_version.h" +#include "chrome/browser/web_applications/update_shortcut_worker_win.h" #include "chrome/browser/web_applications/web_app.h" #include "chrome/common/chrome_switches.h" #include "chrome/installer/util/browser_distribution.h" @@ -548,4 +549,10 @@ base::FilePath GetIconFilePath(const base::FilePath& web_app_path, } // namespace internals +void UpdateShortcutForTabContents(content::WebContents* web_contents) { + // UpdateShortcutWorker will delete itself when it's done. + UpdateShortcutWorker* worker = new UpdateShortcutWorker(web_contents); + worker->Run(); +} + } // namespace web_app diff --git a/chrome/browser/web_applications/web_app_win.h b/chrome/browser/web_applications/web_app_win.h index 3c0dafe..4f4c541 100644 --- a/chrome/browser/web_applications/web_app_win.h +++ b/chrome/browser/web_applications/web_app_win.h @@ -8,6 +8,10 @@ #include "base/files/file_path.h" #include "chrome/browser/shell_integration.h" +namespace content { +class WebContents; +} + namespace gfx { class ImageFamily; } diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 3074c51..31d07b5 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -2585,6 +2585,8 @@ 'browser/usb/usb_context.h', 'browser/usb/usb_service.cc', 'browser/usb/usb_service.h', + 'browser/web_applications/update_shortcut_worker_win.cc', + 'browser/web_applications/update_shortcut_worker_win.h', 'browser/web_applications/web_app.cc', 'browser/web_applications/web_app.h', 'browser/web_applications/web_app_android.cc', diff --git a/chrome/chrome_browser_ui.gypi b/chrome/chrome_browser_ui.gypi index 4e90367..6e6b106 100644 --- a/chrome/chrome_browser_ui.gypi +++ b/chrome/chrome_browser_ui.gypi @@ -2211,8 +2211,6 @@ 'browser/ui/views/website_settings/permission_selector_view_observer.h', 'browser/ui/views/website_settings/website_settings_popup_view.cc', 'browser/ui/views/website_settings/website_settings_popup_view.h', - 'browser/ui/web_applications/web_app_ui.cc', - 'browser/ui/web_applications/web_app_ui.h', 'browser/ui/website_settings/permission_bubble_manager.cc', 'browser/ui/website_settings/permission_bubble_manager.h', 'browser/ui/website_settings/permission_bubble_request.h', |