summaryrefslogtreecommitdiffstats
path: root/chrome/browser/tab_contents
diff options
context:
space:
mode:
authorxiyuan@chromium.org <xiyuan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-17 08:39:51 +0000
committerxiyuan@chromium.org <xiyuan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-17 08:39:51 +0000
commited54318708245efdfcf7454d3aaebfd419f4448c (patch)
tree8e233da9e3ca2c2cb8b57f04d75dde3d1cf1f704 /chrome/browser/tab_contents
parent80cf356e08919b18f502f20864d6f6b72b48eb60 (diff)
downloadchromium_src-ed54318708245efdfcf7454d3aaebfd419f4448c.zip
chromium_src-ed54318708245efdfcf7454d3aaebfd419f4448c.tar.gz
chromium_src-ed54318708245efdfcf7454d3aaebfd419f4448c.tar.bz2
Implement web app shortcuts natively per issue 25528
- Implement a CreateApplicationShortcutView similar to the current Gears-based one; - Add a few profile prefs to persist user's last checked shortcut locations - Implement a web_app::CreateShortcut that stores icon under "<profile>/Web Applications" in a similar layout as gears (i.e. <host>/<scheme_port>/<web_app_title>.ico) and calls file_util code to creates shortcut on Windows; - Add Win7 taskbar pin/unpin support function to file_util; - Update TabContents to replace gears with new code; Note: - Gears dialog is modaless but this one is a modal dialog. - Gear's icon store is not migrated because gears icons could still be used by shortcuts created by gears and thus we could not delete them even after migration. And we are not using the local ico files in the dialog even if they exists. - New CreateApplicationShortcutView is included when TOOLKIT_VIEW is defined. However on platforms other than Windows, the actual CreateShortCut code is not implemented. Right now it calls ShellIntegration's CreateDesktopShort if OS_LINUX is defined and NOTREACHED() for other platforms. BUG=25528 TEST=Verify the new UI provides the same functionality as gears under XP/Vista and support pinning on Win 7. Review URL: http://codereview.chromium.org/372012 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@32165 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/tab_contents')
-rw-r--r--chrome/browser/tab_contents/tab_contents.cc93
-rw-r--r--chrome/browser/tab_contents/tab_contents.h37
-rw-r--r--chrome/browser/tab_contents/tab_contents_delegate.h9
3 files changed, 20 insertions, 119 deletions
diff --git a/chrome/browser/tab_contents/tab_contents.cc b/chrome/browser/tab_contents/tab_contents.cc
index c373a6a..055d68f 100644
--- a/chrome/browser/tab_contents/tab_contents.cc
+++ b/chrome/browser/tab_contents/tab_contents.cc
@@ -29,7 +29,6 @@
#include "chrome/browser/extensions/extensions_service.h"
#include "chrome/browser/favicon_service.h"
#include "chrome/browser/form_field_history_manager.h"
-#include "chrome/browser/gears_integration.h"
#include "chrome/browser/google_util.h"
#include "chrome/browser/hung_renderer_dialog.h"
#include "chrome/browser/jsmessage_box_handler.h"
@@ -78,11 +77,6 @@
#include <gdk/gdk.h>
#endif // defined(OS_CHROMEOS)
-#if defined(OS_LINUX)
-#include "chrome/browser/gtk/create_application_shortcuts_dialog_gtk.h"
-#include "chrome/browser/gtk/gtk_theme_provider.h"
-#endif // defined(OS_LINUX)
-
// Cross-Site Navigations
//
// If a TabContents is told to navigate to a different web site (as determined
@@ -211,23 +205,6 @@ void MakeNavigateParams(Profile* profile, const NavigationEntry& entry,
// static
int TabContents::find_request_id_counter_ = -1;
-class TabContents::GearsCreateShortcutCallbackFunctor {
- public:
- explicit GearsCreateShortcutCallbackFunctor(TabContents* contents)
- : contents_(contents) {}
-
- void Run(const GearsShortcutData2& shortcut_data, bool success) {
- if (contents_)
- contents_->OnGearsCreateShortcutDone(shortcut_data, success);
- delete this;
- }
- void Cancel() {
- contents_ = NULL;
- }
-
- private:
- TabContents* contents_;
-};
TabContents::TabContents(Profile* profile,
SiteInstance* site_instance,
@@ -249,7 +226,6 @@ TabContents::TabContents(Profile* profile,
plugin_installer_(),
ALLOW_THIS_IN_INITIALIZER_LIST(fav_icon_helper_(this)),
select_file_dialog_(),
- pending_install_(),
is_loading_(false),
is_crashed_(false),
waiting_for_response_(false),
@@ -283,9 +259,6 @@ TabContents::TabContents(Profile* profile,
suppress_javascript_messages_(false),
is_showing_before_unload_dialog_(false),
opener_dom_ui_type_(DOMUIFactory::kNoDOMUI) {
- pending_install_.page_id = 0;
- pending_install_.callback_functor = NULL;
-
#if defined(OS_CHROMEOS)
// Make sure the thumbnailer is started before starting the render manager.
// The thumbnailer will want to listen for RVH creations, one of which will
@@ -348,9 +321,6 @@ TabContents::~TabContents() {
NotifyDisconnected();
HungRendererDialog::HideForTabContents(this);
- if (pending_install_.callback_functor)
- pending_install_.callback_functor->Cancel();
-
// First cleanly close all child windows.
// TODO(mpcomplete): handle case if MaybeCloseChildWindows() already asked
// some of these to close. CloseWindows is async, so it might get called
@@ -780,38 +750,6 @@ TabContents* TabContents::Clone() {
return tc;
}
-void TabContents::CreateShortcut() {
- NavigationEntry* entry = controller_.GetLastCommittedEntry();
- if (!entry)
- return;
-
-#if defined(OS_LINUX) && !defined(TOOLKIT_VIEWS)
- SkBitmap bitmap;
- if (FavIconIsValid())
- bitmap = GetFavIcon();
- CreateApplicationShortcutsDialogGtk::Show(view()->GetTopLevelNativeWindow(),
- GetURL(), GetTitle(), bitmap);
-#else
- // We only allow one pending install request. By resetting the page id we
- // effectively cancel the pending install request.
- pending_install_.page_id = entry->page_id();
- pending_install_.icon = GetFavIcon();
- pending_install_.title = GetTitle();
- pending_install_.url = GetURL();
- if (pending_install_.callback_functor) {
- pending_install_.callback_functor->Cancel();
- pending_install_.callback_functor = NULL;
- }
- DCHECK(!pending_install_.icon.isNull()) << "Menu item should be disabled.";
- if (pending_install_.title.empty())
- pending_install_.title = UTF8ToUTF16(GetURL().spec());
-
- // Request the application info. When done OnDidGetApplicationInfo is invoked
- // and we'll create the shortcut.
- render_view_host()->GetApplicationInfo(pending_install_.page_id);
-#endif
-}
-
void TabContents::ShowPageInfo(const GURL& url,
const NavigationEntry::SSLStatus& ssl,
bool show_history) {
@@ -1296,24 +1234,6 @@ void TabContents::ExpireInfoBars(
}
}
-void TabContents::OnGearsCreateShortcutDone(
- const GearsShortcutData2& shortcut_data, bool success) {
- NavigationEntry* current_entry = controller_.GetLastCommittedEntry();
- bool same_page =
- current_entry && pending_install_.page_id == current_entry->page_id();
-
- if (success && same_page) {
- // Only switch to app mode if the user chose to create a shortcut and
- // we're still on the same page that it corresponded to.
- if (delegate())
- delegate()->ConvertContentsToApplication(this);
- }
-
- // Reset the page id to indicate no requests are pending.
- pending_install_.page_id = 0;
- pending_install_.callback_functor = NULL;
-}
-
DOMUI* TabContents::GetDOMUIForCurrentState() {
// When there is a pending navigation entry, we want to use the pending DOMUI
// that goes along with it to control the basic flags. For example, we want to
@@ -1789,15 +1709,10 @@ void TabContents::OnCrashedWorker() {
void TabContents::OnDidGetApplicationInfo(
int32 page_id,
const webkit_glue::WebApplicationInfo& info) {
- if (pending_install_.page_id != page_id)
- return; // The user clicked create on a separate page. Ignore this.
-
- pending_install_.callback_functor =
- new GearsCreateShortcutCallbackFunctor(this);
- GearsCreateShortcut(
- info, pending_install_.title, pending_install_.url, pending_install_.icon,
- NewCallback(pending_install_.callback_functor,
- &GearsCreateShortcutCallbackFunctor::Run));
+ web_app_info_ = info;
+
+ if (delegate())
+ delegate()->OnDidGetApplicationInfo(this, page_id);
}
void TabContents::DidStartProvisionalLoadForFrame(
diff --git a/chrome/browser/tab_contents/tab_contents.h b/chrome/browser/tab_contents/tab_contents.h
index b8e84a7..1b1bd13 100644
--- a/chrome/browser/tab_contents/tab_contents.h
+++ b/chrome/browser/tab_contents/tab_contents.h
@@ -32,12 +32,12 @@
#include "chrome/browser/tab_contents/navigation_entry.h"
#include "chrome/browser/tab_contents/page_navigator.h"
#include "chrome/browser/tab_contents/render_view_host_manager.h"
-#include "chrome/common/gears_api.h"
#include "chrome/common/navigation_types.h"
#include "chrome/common/notification_registrar.h"
#include "chrome/common/property_bag.h"
#include "chrome/common/renderer_preferences.h"
#include "net/base/load_states.h"
+#include "webkit/glue/dom_operations.h"
#include "webkit/glue/password_form.h"
#include "webkit/glue/webpreferences.h"
@@ -61,9 +61,6 @@ namespace base {
class WaitableEvent;
}
-namespace webkit_glue {
-struct WebApplicationInfo;
-}
namespace IPC {
class Message;
@@ -245,6 +242,10 @@ class TabContents : public PageNavigator,
encoding_.clear();
}
+ const webkit_glue::WebApplicationInfo& web_app_info() const {
+ return web_app_info_;
+ }
+
// Internal state ------------------------------------------------------------
// This flag indicates whether the tab contents is currently being
@@ -332,9 +333,6 @@ class TabContents : public PageNavigator,
// heap-allocated pointer is owned by the caller.
virtual TabContents* Clone();
- // Tell Gears to create a shortcut for the current page.
- void CreateShortcut();
-
// Shows the page info.
void ShowPageInfo(const GURL& url,
const NavigationEntry::SSLStatus& ssl,
@@ -657,21 +655,6 @@ class TabContents : public PageNavigator,
// So InterstitialPage can access SetIsLoading.
friend class InterstitialPage;
- // When CreateShortcut is invoked RenderViewHost::GetApplicationInfo is
- // invoked. CreateShortcut caches the state of the page needed to create the
- // shortcut in PendingInstall. When OnDidGetApplicationInfo is invoked, it
- // uses the information from PendingInstall and the WebApplicationInfo
- // to create the shortcut.
- class GearsCreateShortcutCallbackFunctor;
- struct PendingInstall {
- int32 page_id;
- SkBitmap icon;
- string16 title;
- GURL url;
- // This object receives the GearsCreateShortcutCallback and routes the
- // message back to the TabContents, if we haven't been deleted.
- GearsCreateShortcutCallbackFunctor* callback_functor;
- };
// TODO(brettw) TestTabContents shouldn't exist!
friend class TestTabContents;
@@ -720,12 +703,6 @@ class TabContents : public PageNavigator,
void ExpireInfoBars(
const NavigationController::LoadCommittedDetails& details);
- // Called when the user dismisses the shortcut creation dialog. 'success' is
- // true if the shortcut was created.
- void OnGearsCreateShortcutDone(const GearsShortcutData2& shortcut_data,
- bool success);
-
-
// Returns the DOMUI for the current state of the tab. This will either be
// the pending DOMUI, the committed DOMUI, or NULL.
DOMUI* GetDOMUIForCurrentState();
@@ -1035,8 +1012,8 @@ class TabContents : public PageNavigator,
// Dialog box used for choosing files to upload from file form fields.
scoped_refptr<SelectFileDialog> select_file_dialog_;
- // Web app installation.
- PendingInstall pending_install_;
+ // Cached web app info data.
+ webkit_glue::WebApplicationInfo web_app_info_;
// Data for loading state ----------------------------------------------------
diff --git a/chrome/browser/tab_contents/tab_contents_delegate.h b/chrome/browser/tab_contents/tab_contents_delegate.h
index b4d3009..a9f52d2 100644
--- a/chrome/browser/tab_contents/tab_contents_delegate.h
+++ b/chrome/browser/tab_contents/tab_contents_delegate.h
@@ -25,6 +25,10 @@ class RenderViewHost;
class TabContents;
class TemplateURL;
+namespace webkit_glue {
+struct WebApplicationInfo;
+}
+
// Objects implement this interface to get notified about changes in the
// TabContents and to provide necessary functionality.
class TabContentsDelegate {
@@ -247,6 +251,11 @@ class TabContentsDelegate {
// Returns whether this tab contents should add navigations to history.
virtual bool ShouldAddNavigationsToHistory() const { return true; }
+ // Notification when web app info data is available
+ virtual void OnDidGetApplicationInfo(TabContents* tab_contents,
+ int32 page_id) {
+ }
+
protected:
~TabContentsDelegate() {}
};