Commit da4b8ca7 authored by benwells's avatar benwells Committed by Commit bot

Create bookmark apps at the end of the process.

Prior to this change bookmark apps were created as soon as the user
started the process. If the user quit the process the app was then
removed. This made the flow feel strange, and also caused any matching
app that previously existed to be deleted if the user quit the process.

BUG=438019

Review URL: https://codereview.chromium.org/899443002

Cr-Commit-Position: refs/heads/master@{#314720}
parent c3bb5e1e
...@@ -132,8 +132,7 @@ class ChromeAppForLinkDelegate : public extensions::AppForLinkDelegate { ...@@ -132,8 +132,7 @@ class ChromeAppForLinkDelegate : public extensions::AppForLinkDelegate {
} }
bookmark_app_helper_.reset(new extensions::BookmarkAppHelper( bookmark_app_helper_.reset(new extensions::BookmarkAppHelper(
extensions::ExtensionSystem::Get(context)->extension_service(), web_app, Profile::FromBrowserContext(context), web_app, NULL));
NULL));
bookmark_app_helper_->Create( bookmark_app_helper_->Create(
base::Bind(&extensions::ManagementGenerateAppForLinkFunction:: base::Bind(&extensions::ManagementGenerateAppForLinkFunction::
FinishCreateBookmarkApp, FinishCreateBookmarkApp,
......
...@@ -6,18 +6,30 @@ ...@@ -6,18 +6,30 @@
#include <cctype> #include <cctype>
#include "base/prefs/pref_service.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/extensions/crx_installer.h" #include "chrome/browser/extensions/crx_installer.h"
#include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/favicon_downloader.h" #include "chrome/browser/extensions/favicon_downloader.h"
#include "chrome/browser/extensions/launch_util.h"
#include "chrome/browser/extensions/tab_helper.h" #include "chrome/browser/extensions/tab_helper.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/app_list/app_list_service.h"
#include "chrome/browser/ui/app_list/app_list_util.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/host_desktop.h"
#include "chrome/common/extensions/extension_constants.h" #include "chrome/common/extensions/extension_constants.h"
#include "chrome/common/extensions/manifest_handlers/app_launch_info.h" #include "chrome/common/extensions/manifest_handlers/app_launch_info.h"
#include "chrome/common/url_constants.h"
#include "content/public/browser/notification_service.h" #include "content/public/browser/notification_service.h"
#include "content/public/browser/notification_source.h" #include "content/public/browser/notification_source.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "extensions/browser/extension_system.h"
#include "extensions/browser/image_loader.h" #include "extensions/browser/image_loader.h"
#include "extensions/browser/notification_types.h" #include "extensions/browser/notification_types.h"
#include "extensions/browser/pref_names.h"
#include "extensions/common/constants.h" #include "extensions/common/constants.h"
#include "extensions/common/extension.h" #include "extensions/common/extension.h"
#include "extensions/common/manifest_handlers/icons_handler.h" #include "extensions/common/manifest_handlers/icons_handler.h"
...@@ -38,6 +50,16 @@ ...@@ -38,6 +50,16 @@
#include "ui/gfx/image/image.h" #include "ui/gfx/image/image.h"
#include "ui/gfx/image/image_family.h" #include "ui/gfx/image/image_family.h"
#if defined(OS_MACOSX)
#include "base/command_line.h"
#include "chrome/browser/web_applications/web_app_mac.h"
#include "chrome/common/chrome_switches.h"
#endif
#if defined(USE_ASH)
#include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h"
#endif
namespace { namespace {
// Overlays a shortcut icon over the bottom left corner of a given image. // Overlays a shortcut icon over the bottom left corner of a given image.
...@@ -218,12 +240,19 @@ void BookmarkAppHelper::GenerateIcon(std::map<int, SkBitmap>* bitmaps, ...@@ -218,12 +240,19 @@ void BookmarkAppHelper::GenerateIcon(std::map<int, SkBitmap>* bitmaps,
icon_image.bitmap()->deepCopyTo(&(*bitmaps)[output_size]); icon_image.bitmap()->deepCopyTo(&(*bitmaps)[output_size]);
} }
BookmarkAppHelper::BookmarkAppHelper(ExtensionService* service, BookmarkAppHelper::BookmarkAppHelper(Profile* profile,
WebApplicationInfo web_app_info, WebApplicationInfo web_app_info,
content::WebContents* contents) content::WebContents* contents)
: contents_(contents), : profile_(profile),
contents_(contents),
web_app_info_(web_app_info), web_app_info_(web_app_info),
crx_installer_(extensions::CrxInstaller::CreateSilent(service)) { crx_installer_(extensions::CrxInstaller::CreateSilent(
ExtensionSystem::Get(profile)->extension_service())) {
web_app_info_.open_as_window =
profile_->GetPrefs()->GetInteger(
extensions::pref_names::kBookmarkAppCreationLaunchType) ==
extensions::LAUNCH_TYPE_WINDOW;
registrar_.Add(this, registrar_.Add(this,
extensions::NOTIFICATION_CRX_INSTALLER_DONE, extensions::NOTIFICATION_CRX_INSTALLER_DONE,
content::Source<CrxInstaller>(crx_installer_.get())); content::Source<CrxInstaller>(crx_installer_.get()));
...@@ -279,7 +308,7 @@ void BookmarkAppHelper::OnIconsDownloaded( ...@@ -279,7 +308,7 @@ void BookmarkAppHelper::OnIconsDownloaded(
// app creation. // app creation.
if (!success) { if (!success) {
favicon_downloader_.reset(); favicon_downloader_.reset();
callback_.Run(NULL, web_app_info_); callback_.Run(nullptr, web_app_info_);
return; return;
} }
...@@ -335,10 +364,93 @@ void BookmarkAppHelper::OnIconsDownloaded( ...@@ -335,10 +364,93 @@ void BookmarkAppHelper::OnIconsDownloaded(
web_app_info_.generated_icon_color, &generated_icons); web_app_info_.generated_icon_color, &generated_icons);
ReplaceWebAppIcons(generated_icons, &web_app_info_); ReplaceWebAppIcons(generated_icons, &web_app_info_);
// Install the app.
crx_installer_->InstallWebApp(web_app_info_);
favicon_downloader_.reset(); favicon_downloader_.reset();
if (!contents_) {
// The web contents can be null in tests.
OnBubbleCompleted(true, web_app_info_);
return;
}
Browser* browser = chrome::FindBrowserWithWebContents(contents_);
if (!browser) {
// The browser can be null in tests.
OnBubbleCompleted(true, web_app_info_);
return;
}
browser->window()->ShowBookmarkAppBubble(
web_app_info_, base::Bind(&BookmarkAppHelper::OnBubbleCompleted,
base::Unretained(this)));
}
void BookmarkAppHelper::OnBubbleCompleted(
bool user_accepted,
const WebApplicationInfo& web_app_info) {
if (user_accepted) {
web_app_info_ = web_app_info;
crx_installer_->InstallWebApp(web_app_info_);
} else {
callback_.Run(nullptr, web_app_info_);
}
}
void BookmarkAppHelper::FinishInstallation(const Extension* extension) {
// Set the default 'open as' preference for use next time the dialog is
// shown.
extensions::LaunchType launch_type = web_app_info_.open_as_window
? extensions::LAUNCH_TYPE_WINDOW
: extensions::LAUNCH_TYPE_REGULAR;
profile_->GetPrefs()->SetInteger(
extensions::pref_names::kBookmarkAppCreationLaunchType, launch_type);
// Set the launcher type for the app.
extensions::SetLaunchType(profile_, extension->id(), launch_type);
if (!contents_) {
// The web contents can be null in tests.
callback_.Run(extension, web_app_info_);
return;
}
Browser* browser = chrome::FindBrowserWithWebContents(contents_);
if (!browser) {
// The browser can be null in tests.
callback_.Run(extension, web_app_info_);
return;
}
// Pin the app to the shelf on Ash.
chrome::HostDesktopType desktop = browser->host_desktop_type();
#if defined(USE_ASH)
if (desktop == chrome::HOST_DESKTOP_TYPE_ASH)
ChromeLauncherController::instance()->PinAppWithID(extension->id());
#endif
// Show the newly installed app in the app launcher, in finder (on Mac) or
// chrome://apps.
Profile* current_profile = profile_->GetOriginalProfile();
if (IsAppLauncherEnabled()) {
AppListService::Get(desktop)
->ShowForAppInstall(current_profile, extension->id(), false);
#if defined(OS_MACOSX)
} else if (base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kEnableHostedAppShimCreation)) {
web_app::RevealAppShimInFinderForApp(profile_, extension);
#endif
} else {
chrome::NavigateParams params(current_profile,
GURL(chrome::kChromeUIAppsURL),
ui::PAGE_TRANSITION_LINK);
params.disposition = SINGLETON_TAB;
chrome::Navigate(&params);
content::NotificationService::current()->Notify(
chrome::NOTIFICATION_APP_INSTALLED_TO_NTP,
content::Source<content::WebContents>(params.target_contents),
content::Details<const std::string>(&extension->id()));
}
callback_.Run(extension, web_app_info_);
} }
void BookmarkAppHelper::Observe(int type, void BookmarkAppHelper::Observe(int type,
...@@ -351,11 +463,11 @@ void BookmarkAppHelper::Observe(int type, ...@@ -351,11 +463,11 @@ void BookmarkAppHelper::Observe(int type,
DCHECK(extension); DCHECK(extension);
DCHECK_EQ(AppLaunchInfo::GetLaunchWebURL(extension), DCHECK_EQ(AppLaunchInfo::GetLaunchWebURL(extension),
web_app_info_.app_url); web_app_info_.app_url);
callback_.Run(extension, web_app_info_); FinishInstallation(extension);
break; break;
} }
case extensions::NOTIFICATION_EXTENSION_INSTALL_ERROR: case extensions::NOTIFICATION_EXTENSION_INSTALL_ERROR:
callback_.Run(NULL, web_app_info_); callback_.Run(nullptr, web_app_info_);
break; break;
default: default:
NOTREACHED(); NOTREACHED();
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
class ExtensionService; class ExtensionService;
class FaviconDownloader; class FaviconDownloader;
class Profile;
class SkBitmap; class SkBitmap;
namespace content { namespace content {
...@@ -39,8 +40,10 @@ class BookmarkAppHelper : public content::NotificationObserver { ...@@ -39,8 +40,10 @@ class BookmarkAppHelper : public content::NotificationObserver {
// This helper class will create a bookmark app out of |web_app_info| and // This helper class will create a bookmark app out of |web_app_info| and
// install it to |service|. Icons will be downloaded from the URLs in // install it to |service|. Icons will be downloaded from the URLs in
// |web_app_info.icons| using |contents| if |contents| is not NULL. // |web_app_info.icons| using |contents| if |contents| is not NULL.
// All existing icons from WebApplicationInfo will also be used. // All existing icons from WebApplicationInfo will also be used. The user
BookmarkAppHelper(ExtensionService* service, // will then be prompted to edit the creation information via a bubble and
// will have a chance to cancel the operation.
BookmarkAppHelper(Profile* profile,
WebApplicationInfo web_app_info, WebApplicationInfo web_app_info,
content::WebContents* contents); content::WebContents* contents);
~BookmarkAppHelper() override; ~BookmarkAppHelper() override;
...@@ -80,11 +83,23 @@ class BookmarkAppHelper : public content::NotificationObserver { ...@@ -80,11 +83,23 @@ class BookmarkAppHelper : public content::NotificationObserver {
void OnIconsDownloaded(bool success, void OnIconsDownloaded(bool success,
const std::map<GURL, std::vector<SkBitmap> >& bitmaps); const std::map<GURL, std::vector<SkBitmap> >& bitmaps);
// Called after the bubble has been shown, and the user has either accepted or
// the dialog was dismissed.
void OnBubbleCompleted(bool user_accepted,
const WebApplicationInfo& web_app_info);
// Called when the installation of the app is complete to perform the final
// installation steps.
void FinishInstallation(const Extension* extension);
// Overridden from content::NotificationObserver: // Overridden from content::NotificationObserver:
void Observe(int type, void Observe(int type,
const content::NotificationSource& source, const content::NotificationSource& source,
const content::NotificationDetails& details) override; const content::NotificationDetails& details) override;
// The profile that the bookmark app is being added to.
Profile* profile_;
// The web contents that the bookmark app is being created for. // The web contents that the bookmark app is being created for.
content::WebContents* contents_; content::WebContents* contents_;
......
...@@ -117,7 +117,7 @@ class TestBookmarkAppHelper : public BookmarkAppHelper { ...@@ -117,7 +117,7 @@ class TestBookmarkAppHelper : public BookmarkAppHelper {
TestBookmarkAppHelper(ExtensionService* service, TestBookmarkAppHelper(ExtensionService* service,
WebApplicationInfo web_app_info, WebApplicationInfo web_app_info,
content::WebContents* contents) content::WebContents* contents)
: BookmarkAppHelper(service, web_app_info, contents) {} : BookmarkAppHelper(service->profile(), web_app_info, contents) {}
~TestBookmarkAppHelper() override {} ~TestBookmarkAppHelper() override {}
......
...@@ -26,7 +26,6 @@ ...@@ -26,7 +26,6 @@
#include "chrome/browser/ui/browser_commands.h" #include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_dialogs.h" #include "chrome/browser/ui/browser_dialogs.h"
#include "chrome/browser/ui/browser_finder.h" #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/host_desktop.h"
#include "chrome/browser/web_applications/web_app.h" #include "chrome/browser/web_applications/web_app.h"
#include "chrome/common/extensions/chrome_extension_messages.h" #include "chrome/common/extensions/chrome_extension_messages.h"
...@@ -60,10 +59,6 @@ ...@@ -60,10 +59,6 @@
#include "extensions/common/feature_switch.h" #include "extensions/common/feature_switch.h"
#include "extensions/common/manifest_handlers/icons_handler.h" #include "extensions/common/manifest_handlers/icons_handler.h"
#if defined(OS_CHROMEOS)
#include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h"
#endif
#if defined(OS_WIN) #if defined(OS_WIN)
#include "chrome/browser/web_applications/web_app_win.h" #include "chrome/browser/web_applications/web_app_win.h"
#endif #endif
...@@ -198,19 +193,6 @@ void TabHelper::FinishCreateBookmarkApp( ...@@ -198,19 +193,6 @@ void TabHelper::FinishCreateBookmarkApp(
const Extension* extension, const Extension* extension,
const WebApplicationInfo& web_app_info) { const WebApplicationInfo& web_app_info) {
pending_web_app_action_ = NONE; pending_web_app_action_ = NONE;
// There was an error with downloading the icons or installing the app.
if (!extension)
return;
#if defined(OS_CHROMEOS)
ChromeLauncherController::instance()->PinAppWithID(extension->id());
#endif
Browser* browser = chrome::FindBrowserWithWebContents(web_contents());
if (browser) {
browser->window()->ShowBookmarkAppBubble(web_app_info, extension->id());
}
} }
void TabHelper::RenderViewCreated(RenderViewHost* render_view_host) { void TabHelper::RenderViewCreated(RenderViewHost* render_view_host) {
...@@ -319,9 +301,8 @@ void TabHelper::OnDidGetWebApplicationInfo(const WebApplicationInfo& info) { ...@@ -319,9 +301,8 @@ void TabHelper::OnDidGetWebApplicationInfo(const WebApplicationInfo& info) {
if (web_app_info_.title.empty()) if (web_app_info_.title.empty())
web_app_info_.title = base::UTF8ToUTF16(web_app_info_.app_url.spec()); web_app_info_.title = base::UTF8ToUTF16(web_app_info_.app_url.spec());
bookmark_app_helper_.reset(new BookmarkAppHelper( bookmark_app_helper_.reset(
ExtensionSystem::Get(profile_)->extension_service(), new BookmarkAppHelper(profile_, web_app_info_, web_contents()));
web_app_info_, web_contents()));
bookmark_app_helper_->Create(base::Bind( bookmark_app_helper_->Create(base::Bind(
&TabHelper::FinishCreateBookmarkApp, weak_ptr_factory_.GetWeakPtr())); &TabHelper::FinishCreateBookmarkApp, weak_ptr_factory_.GetWeakPtr()));
break; break;
......
...@@ -221,14 +221,20 @@ class BrowserWindow : public ui::BaseWindow { ...@@ -221,14 +221,20 @@ class BrowserWindow : public ui::BaseWindow {
// |already_bookmarked| is true if the url is already bookmarked. // |already_bookmarked| is true if the url is already bookmarked.
virtual void ShowBookmarkBubble(const GURL& url, bool already_bookmarked) = 0; virtual void ShowBookmarkBubble(const GURL& url, bool already_bookmarked) = 0;
// Callback type used with the ShowBookmarkAppBubble() method. The boolean
// parameter is true when the user accepts the dialog. The WebApplicationInfo
// parameter contains the WebApplicationInfo as edited by the user.
typedef base::Callback<void(bool, const WebApplicationInfo&)>
ShowBookmarkAppBubbleCallback;
// Shows the Bookmark App bubble. // Shows the Bookmark App bubble.
// See Extension::InitFromValueFlags::FROM_BOOKMARK for a description of // See Extension::InitFromValueFlags::FROM_BOOKMARK for a description of
// bookmark apps. // bookmark apps.
// //
// |web_app_info| is the WebApplicationInfo being converted into an app. // |web_app_info| is the WebApplicationInfo being converted into an app.
// |extension_id| is the id of the bookmark app. virtual void ShowBookmarkAppBubble(
virtual void ShowBookmarkAppBubble(const WebApplicationInfo& web_app_info, const WebApplicationInfo& web_app_info,
const std::string& extension_id) = 0; const ShowBookmarkAppBubbleCallback& callback) = 0;
// Shows the translate bubble. // Shows the translate bubble.
// //
......
...@@ -106,8 +106,9 @@ class BrowserWindowCocoa : ...@@ -106,8 +106,9 @@ class BrowserWindowCocoa :
Profile* profile) override; Profile* profile) override;
void ShowUpdateChromeDialog() override; void ShowUpdateChromeDialog() override;
void ShowBookmarkBubble(const GURL& url, bool already_bookmarked) override; void ShowBookmarkBubble(const GURL& url, bool already_bookmarked) override;
void ShowBookmarkAppBubble(const WebApplicationInfo& web_app_info, void ShowBookmarkAppBubble(
const std::string& extension_id) override; const WebApplicationInfo& web_app_info,
const ShowBookmarkAppBubbleCallback& callback) override;
void ShowTranslateBubble(content::WebContents* contents, void ShowTranslateBubble(content::WebContents* contents,
translate::TranslateStep step, translate::TranslateStep step,
translate::TranslateErrors::Type error_type, translate::TranslateErrors::Type error_type,
......
...@@ -14,17 +14,12 @@ ...@@ -14,17 +14,12 @@
#include "chrome/app/chrome_command_ids.h" #include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/download/download_shelf.h" #include "chrome/browser/download/download_shelf.h"
#include "chrome/browser/extensions/bookmark_app_helper.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/launch_util.h"
#include "chrome/browser/extensions/tab_helper.h" #include "chrome/browser/extensions/tab_helper.h"
#include "chrome/browser/fullscreen.h" #include "chrome/browser/fullscreen.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/shell_integration.h" #include "chrome/browser/shell_integration.h"
#include "chrome/browser/signin/signin_header_helper.h" #include "chrome/browser/signin/signin_header_helper.h"
#include "chrome/browser/translate/chrome_translate_client.h" #include "chrome/browser/translate/chrome_translate_client.h"
#include "chrome/browser/ui/app_list/app_list_util.h"
#include "chrome/browser/ui/app_list/app_list_service.h"
#include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_command_controller.h" #include "chrome/browser/ui/browser_command_controller.h"
#include "chrome/browser/ui/browser_commands_mac.h" #include "chrome/browser/ui/browser_commands_mac.h"
...@@ -52,7 +47,6 @@ ...@@ -52,7 +47,6 @@
#include "chrome/browser/ui/search/search_model.h" #include "chrome/browser/ui/search/search_model.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h" #include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/web_applications/web_app.h" #include "chrome/browser/web_applications/web_app.h"
#include "chrome/browser/web_applications/web_app_mac.h"
#include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h" #include "chrome/common/pref_names.h"
#include "chrome/grit/generated_resources.h" #include "chrome/grit/generated_resources.h"
...@@ -64,7 +58,6 @@ ...@@ -64,7 +58,6 @@
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "extensions/browser/extension_registry.h" #include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_system.h" #include "extensions/browser/extension_system.h"
#include "extensions/browser/pref_names.h"
#include "extensions/common/constants.h" #include "extensions/common/constants.h"
#include "ui/base/l10n/l10n_util_mac.h" #include "ui/base/l10n/l10n_util_mac.h"
#include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/rect.h"
...@@ -503,9 +496,7 @@ void BrowserWindowCocoa::ShowBookmarkBubble(const GURL& url, ...@@ -503,9 +496,7 @@ void BrowserWindowCocoa::ShowBookmarkBubble(const GURL& url,
void BrowserWindowCocoa::ShowBookmarkAppBubble( void BrowserWindowCocoa::ShowBookmarkAppBubble(
const WebApplicationInfo& web_app_info, const WebApplicationInfo& web_app_info,
const std::string& extension_id) { const ShowBookmarkAppBubbleCallback& callback) {
Profile* profile = browser_->profile();
base::scoped_nsobject<NSAlert> alert([[NSAlert alloc] init]); base::scoped_nsobject<NSAlert> alert([[NSAlert alloc] init]);
[alert setMessageText:l10n_util::GetNSString(IDS_BOOKMARK_APP_BUBBLE_TITLE)]; [alert setMessageText:l10n_util::GetNSString(IDS_BOOKMARK_APP_BUBBLE_TITLE)];
[alert setAlertStyle:NSInformationalAlertStyle]; [alert setAlertStyle:NSInformationalAlertStyle];
...@@ -522,10 +513,7 @@ void BrowserWindowCocoa::ShowBookmarkAppBubble( ...@@ -522,10 +513,7 @@ void BrowserWindowCocoa::ShowBookmarkAppBubble(
[open_as_window_checkbox setButtonType:NSSwitchButton]; [open_as_window_checkbox setButtonType:NSSwitchButton];
[open_as_window_checkbox [open_as_window_checkbox
setTitle:l10n_util::GetNSString(IDS_BOOKMARK_APP_BUBBLE_OPEN_AS_WINDOW)]; setTitle:l10n_util::GetNSString(IDS_BOOKMARK_APP_BUBBLE_OPEN_AS_WINDOW)];
[open_as_window_checkbox setState: [open_as_window_checkbox setState:web_app_info.open_as_window];
profile->GetPrefs()->GetInteger(
extensions::pref_names::kBookmarkAppCreationLaunchType) ==
extensions::LAUNCH_TYPE_WINDOW];
[open_as_window_checkbox sizeToFit]; [open_as_window_checkbox sizeToFit];
base::scoped_nsobject<NSTextField> app_title([[NSTextField alloc] base::scoped_nsobject<NSTextField> app_title([[NSTextField alloc]
...@@ -557,59 +545,18 @@ void BrowserWindowCocoa::ShowBookmarkAppBubble( ...@@ -557,59 +545,18 @@ void BrowserWindowCocoa::ShowBookmarkAppBubble(
} }
} }
ExtensionService* service =
extensions::ExtensionSystem::Get(profile)->extension_service();
if ([alert runModal] == NSAlertFirstButtonReturn) { if ([alert runModal] == NSAlertFirstButtonReturn) {
// Save launch type preferences for later when creating another hosted app. WebApplicationInfo updated_info = web_app_info;
extensions::LaunchType launch_type = updated_info.open_as_window = [open_as_window_checkbox state] == NSOnState;
[open_as_window_checkbox state] == NSOnState
? extensions::LAUNCH_TYPE_WINDOW
: extensions::LAUNCH_TYPE_REGULAR;
profile->GetPrefs()->SetInteger(
extensions::pref_names::kBookmarkAppCreationLaunchType, launch_type);
extensions::SetLaunchType(profile, extension_id, launch_type);
// Update name of app.
NSString* new_title = [app_title stringValue]; NSString* new_title = [app_title stringValue];
if (![original_title isEqualToString:new_title]) { updated_info.title = base::SysNSStringToUTF16(new_title);
WebApplicationInfo new_web_app_info(web_app_info);
new_web_app_info.title = base::SysNSStringToUTF16(new_title);
extensions::CreateOrUpdateBookmarkApp(service, &new_web_app_info);
}
// If we're not creating app shims, no need to reveal it in Finder. callback.Run(true, updated_info);
// Otherwise reveal the app in the app launcher. If not installed, return;
// then open the chrome://apps page.
if (base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kEnableHostedAppShimCreation)) {
extensions::ExtensionRegistry* registry =
extensions::ExtensionRegistry::Get(profile);
const extensions::Extension* app = registry->GetExtensionById(
extension_id, extensions::ExtensionRegistry::ENABLED);
web_app::RevealAppShimInFinderForApp(profile, app);
} else {
if (IsAppLauncherEnabled()) {
AppListService::Get(chrome::GetHostDesktopTypeForNativeWindow(
browser_->window()->GetNativeWindow()))
->ShowForAppInstall(profile, extension_id, false);
} else {
chrome::NavigateParams params(profile, GURL(chrome::kChromeUIAppsURL),
ui::PAGE_TRANSITION_LINK);
params.disposition = SINGLETON_TAB;
chrome::Navigate(&params);
content::NotificationService::current()->Notify(
chrome::NOTIFICATION_APP_INSTALLED_TO_NTP,
content::Source<content::WebContents>(params.target_contents),
content::Details<const std::string>(&extension_id));
}
}
} else {
service->UninstallExtension(extension_id,
extensions::UNINSTALL_REASON_INSTALL_CANCELED,
base::Bind(&base::DoNothing), NULL);
} }
callback.Run(false, web_app_info);
} }
void BrowserWindowCocoa::ShowTranslateBubble( void BrowserWindowCocoa::ShowTranslateBubble(
......
...@@ -7,17 +7,11 @@ ...@@ -7,17 +7,11 @@
#include "base/basictypes.h" #include "base/basictypes.h"
#include "base/strings/string16.h" #include "base/strings/string16.h"
#include "chrome/browser/extensions/app_icon_loader.h" #include "chrome/browser/ui/browser_window.h"
#include "chrome/common/web_application_info.h" #include "chrome/common/web_application_info.h"
#include "ui/views/bubble/bubble_delegate.h" #include "ui/views/bubble/bubble_delegate.h"
#include "ui/views/controls/button/button.h" #include "ui/views/controls/button/button.h"
class Profile;
namespace extensions {
class AppIconLoader;
}
namespace gfx { namespace gfx {
class ImageSkia; class ImageSkia;
} }
...@@ -30,26 +24,25 @@ class Textfield; ...@@ -30,26 +24,25 @@ class Textfield;
} }
// BookmarkAppBubbleView is a view intended to be used as the content of a // BookmarkAppBubbleView is a view intended to be used as the content of a
// Bubble. BookmarkAppBubbleView provides views for editing the bookmark app it // Bubble. BookmarkAppBubbleView provides views for editing the details to
// is created with. Don't create a BookmarkAppBubbleView directly, instead use // create a bookmark app with. Don't create a BookmarkAppBubbleView directly,
// the static ShowBubble method. // instead use the static ShowBubble method.
class BookmarkAppBubbleView : public views::BubbleDelegateView, class BookmarkAppBubbleView : public views::BubbleDelegateView,
public views::ButtonListener, public views::ButtonListener {
public extensions::AppIconLoader::Delegate {
public: public:
~BookmarkAppBubbleView() override; ~BookmarkAppBubbleView() override;
static void ShowBubble(views::View* anchor_view, static void ShowBubble(
Profile* profile, views::View* anchor_view,
const WebApplicationInfo& web_app_info, const WebApplicationInfo& web_app_info,
const std::string& extension_id); const BrowserWindow::ShowBookmarkAppBubbleCallback& callback);
private: private:
// Creates a BookmarkAppBubbleView. // Creates a BookmarkAppBubbleView.
BookmarkAppBubbleView(views::View* anchor_view, BookmarkAppBubbleView(
Profile* profile, views::View* anchor_view,
const WebApplicationInfo& web_app_info, const WebApplicationInfo& web_app_info,
const std::string& extension_id); const BrowserWindow::ShowBookmarkAppBubbleCallback& callback);
// Overriden from views::BubbleDelegateView: // Overriden from views::BubbleDelegateView:
void Init() override; void Init() override;
...@@ -66,26 +59,17 @@ class BookmarkAppBubbleView : public views::BubbleDelegateView, ...@@ -66,26 +59,17 @@ class BookmarkAppBubbleView : public views::BubbleDelegateView,
// Closes the bubble or opens the edit dialog. // Closes the bubble or opens the edit dialog.
void ButtonPressed(views::Button* sender, const ui::Event& event) override; void ButtonPressed(views::Button* sender, const ui::Event& event) override;
// Overridden from extensions::AppIconLoader::Delegate:
void SetAppImage(const std::string& id, const gfx::ImageSkia& image) override;
// Handle the message when the user presses a button. // Handle the message when the user presses a button.
void HandleButtonPressed(views::Button* sender); void HandleButtonPressed(views::Button* sender);
// Sets the title and launch type of the app. // The WebApplicationInfo that the user is editing.
void ApplyEdits(); WebApplicationInfo web_app_info_;
// The bookmark app bubble, if we're showing one. // Whether the user has accepted the dialog.
static BookmarkAppBubbleView* bookmark_app_bubble_; bool user_accepted_;
// The profile. // The callback to be invoked when the dialog is completed.
Profile* profile_; BrowserWindow::ShowBookmarkAppBubbleCallback callback_;
// The WebApplicationInfo being used to create the app.
const WebApplicationInfo web_app_info_;
// The extension id of the bookmark app.
const std::string extension_id_;
// Button for removing the bookmark. // Button for removing the bookmark.
views::LabelButton* add_button_; views::LabelButton* add_button_;
...@@ -102,12 +86,6 @@ class BookmarkAppBubbleView : public views::BubbleDelegateView, ...@@ -102,12 +86,6 @@ class BookmarkAppBubbleView : public views::BubbleDelegateView,
// Image showing the icon of the app. // Image showing the icon of the app.
views::ImageView* icon_image_view_; views::ImageView* icon_image_view_;
// When the destructor is invoked should the app be removed?
bool remove_app_;
// Used to load the icon.
scoped_ptr<extensions::AppIconLoader> app_icon_loader_;
DISALLOW_COPY_AND_ASSIGN(BookmarkAppBubbleView); DISALLOW_COPY_AND_ASSIGN(BookmarkAppBubbleView);
}; };
......
...@@ -1234,11 +1234,8 @@ void BrowserView::ShowBookmarkBubble(const GURL& url, bool already_bookmarked) { ...@@ -1234,11 +1234,8 @@ void BrowserView::ShowBookmarkBubble(const GURL& url, bool already_bookmarked) {
void BrowserView::ShowBookmarkAppBubble( void BrowserView::ShowBookmarkAppBubble(
const WebApplicationInfo& web_app_info, const WebApplicationInfo& web_app_info,
const std::string& extension_id) { const ShowBookmarkAppBubbleCallback& callback) {
BookmarkAppBubbleView::ShowBubble(GetToolbarView(), BookmarkAppBubbleView::ShowBubble(GetToolbarView(), web_app_info, callback);
browser_->profile(),
web_app_info,
extension_id);
} }
void BrowserView::ShowTranslateBubble( void BrowserView::ShowTranslateBubble(
......
...@@ -308,8 +308,9 @@ class BrowserView : public BrowserWindow, ...@@ -308,8 +308,9 @@ class BrowserView : public BrowserWindow,
Profile* profile) override; Profile* profile) override;
void ShowUpdateChromeDialog() override; void ShowUpdateChromeDialog() override;
void ShowBookmarkBubble(const GURL& url, bool already_bookmarked) override; void ShowBookmarkBubble(const GURL& url, bool already_bookmarked) override;
void ShowBookmarkAppBubble(const WebApplicationInfo& web_app_info, void ShowBookmarkAppBubble(
const std::string& extension_id) override; const WebApplicationInfo& web_app_info,
const ShowBookmarkAppBubbleCallback& callback) override;
void ShowTranslateBubble(content::WebContents* contents, void ShowTranslateBubble(content::WebContents* contents,
translate::TranslateStep step, translate::TranslateStep step,
translate::TranslateErrors::Type error_type, translate::TranslateErrors::Type error_type,
......
...@@ -12,7 +12,8 @@ WebApplicationInfo::IconInfo::~IconInfo() { ...@@ -12,7 +12,8 @@ WebApplicationInfo::IconInfo::~IconInfo() {
WebApplicationInfo::WebApplicationInfo() WebApplicationInfo::WebApplicationInfo()
: mobile_capable(MOBILE_CAPABLE_UNSPECIFIED), : mobile_capable(MOBILE_CAPABLE_UNSPECIFIED),
generated_icon_color(SK_ColorTRANSPARENT) { generated_icon_color(SK_ColorTRANSPARENT),
open_as_window(false) {
} }
WebApplicationInfo::~WebApplicationInfo() { WebApplicationInfo::~WebApplicationInfo() {
......
...@@ -53,6 +53,10 @@ struct WebApplicationInfo { ...@@ -53,6 +53,10 @@ struct WebApplicationInfo {
// The color to use if an icon needs to be generated for the web app. // The color to use if an icon needs to be generated for the web app.
SkColor generated_icon_color; SkColor generated_icon_color;
// Whether the app should be opened in a window. If false, the app will be
// opened in a tab.
bool open_as_window;
}; };
#endif // CHROME_COMMON_WEB_APPLICATION_INFO_H_ #endif // CHROME_COMMON_WEB_APPLICATION_INFO_H_
...@@ -104,8 +104,9 @@ class TestBrowserWindow : public BrowserWindow { ...@@ -104,8 +104,9 @@ class TestBrowserWindow : public BrowserWindow {
Profile* profile) override {} Profile* profile) override {}
void ShowUpdateChromeDialog() override {} void ShowUpdateChromeDialog() override {}
void ShowBookmarkBubble(const GURL& url, bool already_bookmarked) override {} void ShowBookmarkBubble(const GURL& url, bool already_bookmarked) override {}
void ShowBookmarkAppBubble(const WebApplicationInfo& web_app_info, void ShowBookmarkAppBubble(
const std::string& extension_id) override {} const WebApplicationInfo& web_app_info,
const ShowBookmarkAppBubbleCallback& callback) override {}
void ShowTranslateBubble(content::WebContents* contents, void ShowTranslateBubble(content::WebContents* contents,
translate::TranslateStep step, translate::TranslateStep step,
translate::TranslateErrors::Type error_type, translate::TranslateErrors::Type error_type,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment