Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3829)

Unified Diff: chrome/browser/ui/cocoa/browser_window_cocoa.mm

Issue 777543002: Create hosted app shims on Mac. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed unnecessary forward declaration Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/cocoa/browser_window_cocoa.mm
diff --git a/chrome/browser/ui/cocoa/browser_window_cocoa.mm b/chrome/browser/ui/cocoa/browser_window_cocoa.mm
index b694868a3cd9c436f6fd54d6f0bf813ef2bc6157..f4f6b40019c6cd4a291d0fdf33abe3762162137d 100644
--- a/chrome/browser/ui/cocoa/browser_window_cocoa.mm
+++ b/chrome/browser/ui/cocoa/browser_window_cocoa.mm
@@ -15,6 +15,9 @@
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/chrome_notification_types.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/fullscreen.h"
#include "chrome/browser/profiles/profile.h"
@@ -47,13 +50,19 @@
#include "chrome/browser/ui/search/search_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_mac.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
+#include "chrome/grit/generated_resources.h"
#include "components/translate/core/browser/language_state.h"
#include "content/public/browser/native_web_keyboard_event.h"
#include "content/public/browser/notification_details.h"
#include "content/public/browser/notification_source.h"
#include "content/public/browser/web_contents.h"
+#include "extensions/common/constants.h"
+#include "extensions/browser/extension_system.h"
+#include "extensions/browser/extension_registry.h"
+#include "extensions/browser/pref_names.h"
#include "ui/base/l10n/l10n_util_mac.h"
#include "ui/gfx/rect.h"
@@ -68,6 +77,9 @@ using content::WebContents;
namespace {
+const NSRect kAppTitleTextFieldSize = {{0, 24}, {200, 22}};
+const NSRect kBookmarkAppBubbleAccessoryViewSize = {{0, 0}, {200, 46}};
+
NSPoint GetPointForBubble(content::WebContents* web_contents,
int x_offset,
int y_offset) {
@@ -497,7 +509,88 @@ void BrowserWindowCocoa::ShowBookmarkBubble(const GURL& url,
void BrowserWindowCocoa::ShowBookmarkAppBubble(
const WebApplicationInfo& web_app_info,
const std::string& extension_id) {
- NOTIMPLEMENTED();
+ Profile* profile = browser_->profile();
+
+ base::scoped_nsobject<NSAlert> alert([[NSAlert alloc] init]);
+ [alert setMessageText:l10n_util::GetNSString(IDS_BOOKMARK_APP_BUBBLE_TITLE)];
+ [alert setAlertStyle:NSInformationalAlertStyle];
+
+ NSButton* continue_button =
+ [alert addButtonWithTitle:l10n_util::GetNSString(IDS_OK)];
+ [continue_button setKeyEquivalent:@"\r"];
+ NSButton* cancel_button =
+ [alert addButtonWithTitle:l10n_util::GetNSString(IDS_CANCEL)];
+ [cancel_button setKeyEquivalent:@"\033"];
+
+ base::scoped_nsobject<NSButton> open_as_tab_checkbox(
+ [[NSButton alloc] initWithFrame:NSZeroRect]);
+ [open_as_tab_checkbox setButtonType:NSSwitchButton];
+ [open_as_tab_checkbox
+ setTitle:l10n_util::GetNSString(IDS_BOOKMARK_APP_BUBBLE_OPEN_AS_TAB)];
+ [open_as_tab_checkbox
+ setState:profile->GetPrefs()->GetInteger(
+ extensions::pref_names::kBookmarkAppCreationLaunchType) ==
+ extensions::LAUNCH_TYPE_REGULAR];
+ [open_as_tab_checkbox sizeToFit];
+
+ NSTextField* app_title =
+ [[NSTextField alloc] initWithFrame:kAppTitleTextFieldSize];
+ NSString* original_title = SysUTF16ToNSString(web_app_info.title);
+ [app_title.cell setWraps:NO];
+ [app_title.cell setScrollable:YES];
+ [app_title setStringValue:original_title];
+
+ NSView* view =
+ [[NSView alloc] initWithFrame:kBookmarkAppBubbleAccessoryViewSize];
+ [view addSubview:open_as_tab_checkbox];
+ [view addSubview:app_title];
+ [alert setAccessoryView:view];
+
+ const int kIconPreviewTargetSize = 64;
jackhou1 2014/12/04 06:37:11 Move this constant up to the top as well.
mitchellj 2014/12/04 22:48:40 Done.
+
+ // Find the image with target size.
+ // Assumes that the icons are sorted in ascending order of size.
+ WebApplicationInfo::IconInfo info =
+ web_app_info.icons[web_app_info.icons.size() - 1];
jackhou1 2014/12/04 06:37:11 Can |web_app_info.icons| ever be empty?
mitchellj 2014/12/04 22:48:40 Not completely sure, given that the icons seem to
+ if (info.width >= kIconPreviewTargetSize &&
jackhou1 2014/12/04 06:37:11 What happens if the icon is not big enough? Does i
mitchellj 2014/12/04 22:48:40 It just shows the Chromium icon if there isn't a b
+ info.height >= kIconPreviewTargetSize) {
+ NSImage* icon_image = gfx::Image::CreateFrom1xBitmap(info.data).ToNSImage();
+ [icon_image
+ setSize:NSMakeSize(kIconPreviewTargetSize, kIconPreviewTargetSize)];
+ [alert setIcon:icon_image];
+ }
+
+ ExtensionService* service =
+ extensions::ExtensionSystem::Get(profile)->extension_service();
+ if ([alert runModal] == NSAlertFirstButtonReturn) {
+ // Save launch type preferences for later when creating another hosted app.
+ extensions::LaunchType launch_type =
+ [open_as_tab_checkbox state] == NSOnState
+ ? extensions::LAUNCH_TYPE_REGULAR
+ : extensions::LAUNCH_TYPE_WINDOW;
+ profile->GetPrefs()->SetInteger(
+ extensions::pref_names::kBookmarkAppCreationLaunchType, launch_type);
+ extensions::SetLaunchType(service, extension_id, launch_type);
+
+ // Update name of app.
+ NSString* new_title = [app_title stringValue];
+ if (![original_title isEqualToString: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);
+ }
+
+ extensions::ExtensionRegistry* registry =
+ extensions::ExtensionRegistry::Get(profile);
+ const extensions::Extension* app = registry->GetExtensionById(
+ extension_id, extensions::ExtensionRegistry::ENABLED);
+
+ web_app::WebAppShortcutCreator::RevealAppShimInFinderForApp(profile, app);
+ } else {
+ service->UninstallExtension(extension_id,
+ extensions::UNINSTALL_REASON_INSTALL_CANCELED,
+ base::Bind(&base::DoNothing), NULL);
+ }
}
void BrowserWindowCocoa::ShowTranslateBubble(

Powered by Google App Engine
This is Rietveld 408576698