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

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: 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..5db7ce0be84eacc8aba4ad96f8ca1986fa7baafa 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"
@@ -62,6 +71,7 @@
#import "chrome/browser/ui/cocoa/one_click_signin_dialog_controller.h"
#endif
+using content::BrowserThread;
using content::NativeWebKeyboardEvent;
using content::SSLStatus;
using content::WebContents;
@@ -497,7 +507,92 @@ 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:NSMakeRect(0,24,200,22)];
jackhou1 2014/12/03 05:12:05 Constants need to be declared at the top of the fi
mitchellj 2014/12/04 04:53:53 Done.
+ NSString* original_title = SysUTF16ToNSString(web_app_info.title);
+ [app_title.cell setWraps:NO];
jackhou1 2014/12/03 05:12:05 It should probably be a single line field.
mitchellj 2014/12/04 04:53:53 The parameter setWraps:NO makes sure that no wrapp
+ [app_title.cell setScrollable:YES];
+ [app_title setStringValue:original_title];
+
+ NSView* view = [[NSView alloc] initWithFrame:NSMakeRect(0,0,200,46)];
+ [view addSubview:open_as_tab_checkbox];
+ [view addSubview:app_title];
+ [alert setAccessoryView:view];
+
+ const int kIconPreviewTargetSize = 64;
+
+ // 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];
+ if (info.width >= kIconPreviewTargetSize &&
+ 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);
+
+ BrowserThread::PostTask(
+ BrowserThread::FILE,
+ FROM_HERE,
+ base::Bind(&web_app::internals::RevealAppShimInFinderForApp,
+ profile, app->path()));
+ } 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