Upstream version 11.39.250.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / cocoa / browser_window_cocoa.mm
index 63731fe..e62920f 100644 (file)
 #include "chrome/browser/download/download_shelf.h"
 #include "chrome/browser/extensions/tab_helper.h"
 #include "chrome/browser/fullscreen.h"
-#include "chrome/browser/password_manager/chrome_password_manager_client.h"
 #include "chrome/browser/profiles/profile.h"
 #include "chrome/browser/shell_integration.h"
-#include "chrome/browser/translate/translate_tab_helper.h"
+#include "chrome/browser/signin/signin_header_helper.h"
+#include "chrome/browser/translate/chrome_translate_client.h"
 #include "chrome/browser/ui/browser.h"
 #include "chrome/browser/ui/browser_command_controller.h"
 #include "chrome/browser/ui/browser_commands_mac.h"
 #include "chrome/browser/ui/browser_list.h"
 #include "chrome/browser/ui/browser_window_state.h"
-#import "chrome/browser/ui/cocoa/browser/avatar_base_controller.h"
-#import "chrome/browser/ui/cocoa/browser/avatar_menu_bubble_controller.h"
 #import "chrome/browser/ui/cocoa/browser/edit_search_engine_cocoa_controller.h"
-#import "chrome/browser/ui/cocoa/browser/password_generation_bubble_controller.h"
 #import "chrome/browser/ui/cocoa/browser_window_controller.h"
 #import "chrome/browser/ui/cocoa/browser_window_utils.h"
 #import "chrome/browser/ui/cocoa/chrome_event_processing_window.h"
 #import "chrome/browser/ui/cocoa/info_bubble_view.h"
 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h"
 #import "chrome/browser/ui/cocoa/nsmenuitem_additions.h"
+#import "chrome/browser/ui/cocoa/profiles/avatar_base_controller.h"
+#import "chrome/browser/ui/cocoa/profiles/avatar_menu_bubble_controller.h"
 #include "chrome/browser/ui/cocoa/restart_browser.h"
 #include "chrome/browser/ui/cocoa/status_bubble_mac.h"
 #include "chrome/browser/ui/cocoa/task_manager_mac.h"
 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h"
 #import "chrome/browser/ui/cocoa/web_dialog_window_controller.h"
-#import "chrome/browser/ui/cocoa/website_settings_bubble_controller.h"
+#import "chrome/browser/ui/cocoa/website_settings/website_settings_bubble_controller.h"
+#include "chrome/browser/ui/fullscreen/fullscreen_controller.h"
 #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/common/chrome_switches.h"
 #include "chrome/common/pref_names.h"
-#include "components/autofill/core/common/password_form.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 "content/public/browser/web_contents_view.h"
-#include "grit/chromium_strings.h"
-#include "grit/generated_resources.h"
 #include "ui/base/l10n/l10n_util_mac.h"
 #include "ui/gfx/rect.h"
 
@@ -74,7 +71,7 @@ namespace {
 NSPoint GetPointForBubble(content::WebContents* web_contents,
                           int x_offset,
                           int y_offset) {
-  NSView* view = web_contents->GetView()->GetNativeView();
+  NSView* view = web_contents->GetNativeView();
   NSRect bounds = [view bounds];
   NSPoint point;
   point.x = NSMinX(bounds) + x_offset;
@@ -354,24 +351,24 @@ void BrowserWindowCocoa::Restore() {
     [window() deminiaturize:controller_];
 }
 
-void BrowserWindowCocoa::EnterFullscreen(
-      const GURL& url, FullscreenExitBubbleType bubble_type) {
-  // When simplified fullscreen is enabled, always enter normal fullscreen.
-  const CommandLine* command_line = CommandLine::ForCurrentProcess();
-  if (command_line->HasSwitch(switches::kEnableSimplifiedFullscreen)) {
-    if (url.is_empty())
-      [controller_ enterFullscreen];
-    else
-      [controller_ enterFullscreenForURL:url bubbleType:bubble_type];
+// See browser_window_controller.h for a detailed explanation of the logic in
+// this method.
+void BrowserWindowCocoa::EnterFullscreen(const GURL& url,
+                                         FullscreenExitBubbleType bubble_type) {
+  if (browser_->fullscreen_controller()->IsWindowFullscreenForTabOrPending()) {
+    [controller_ enterWebContentFullscreenForURL:url bubbleType:bubble_type];
     return;
   }
 
-  [controller_ enterPresentationModeForURL:url
-                                bubbleType:bubble_type];
+  if (url.is_empty()) {
+    [controller_ enterPresentationMode];
+  } else {
+    [controller_ enterExtensionFullscreenForURL:url bubbleType:bubble_type];
+  }
 }
 
 void BrowserWindowCocoa::ExitFullscreen() {
-  [controller_ exitFullscreen];
+  [controller_ exitAnyFullscreen];
 }
 
 void BrowserWindowCocoa::UpdateFullscreenExitBubbleContent(
@@ -386,9 +383,7 @@ bool BrowserWindowCocoa::ShouldHideUIForFullscreen() const {
 }
 
 bool BrowserWindowCocoa::IsFullscreen() const {
-  if ([controller_ inPresentationMode])
-    CHECK([controller_ isFullscreen]);  // Presentation mode must be fullscreen.
-  return [controller_ isFullscreen];
+  return [controller_ isInAnyFullscreenMode];
 }
 
 bool BrowserWindowCocoa::IsFullscreenBubbleVisible() const {
@@ -447,7 +442,8 @@ void BrowserWindowCocoa::FocusInfobars() {
 }
 
 bool BrowserWindowCocoa::IsBookmarkBarVisible() const {
-  return browser_->profile()->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar);
+  return browser_->profile()->GetPrefs()->GetBoolean(
+      bookmarks::prefs::kShowBookmarkBar);
 }
 
 bool BrowserWindowCocoa::IsBookmarkBarAnimating() const {
@@ -493,11 +489,13 @@ void BrowserWindowCocoa::ShowBookmarkAppBubble(
 
 void BrowserWindowCocoa::ShowTranslateBubble(
     content::WebContents* contents,
-    TranslateTabHelper::TranslateStep step,
-    TranslateErrors::Type error_type) {
-  TranslateTabHelper* translate_tab_helper =
-      TranslateTabHelper::FromWebContents(contents);
-  LanguageState& language_state = translate_tab_helper->GetLanguageState();
+    translate::TranslateStep step,
+    translate::TranslateErrors::Type error_type,
+    bool is_user_gesture) {
+  ChromeTranslateClient* chrome_translate_client =
+      ChromeTranslateClient::FromWebContents(contents);
+  translate::LanguageState& language_state =
+      chrome_translate_client->GetLanguageState();
   language_state.SetTranslateEnabled(true);
 
   [controller_ showTranslateBubbleForWebContents:contents
@@ -534,6 +532,7 @@ bool BrowserWindowCocoa::IsDownloadShelfVisible() const {
 }
 
 DownloadShelf* BrowserWindowCocoa::GetDownloadShelf() {
+  [controller_ createAndAddDownloadShelf];
   DownloadShelfController* shelfController = [controller_ downloadShelf];
   return [shelfController bridge];
 }
@@ -579,7 +578,9 @@ bool BrowserWindowCocoa::PreHandleKeyboardEvent(
     return false;
 
   if (event.type == blink::WebInputEvent::RawKeyDown &&
-      [controller_ handledByExtensionCommand:event.os_event])
+      [controller_
+          handledByExtensionCommand:event.os_event
+                           priority:ui::AcceleratorManager::kHighPriority])
     return true;
 
   int id = [BrowserWindowUtils getCommandId:event];
@@ -615,39 +616,26 @@ void BrowserWindowCocoa::Paste() {
 }
 
 void BrowserWindowCocoa::EnterFullscreenWithChrome() {
-  // This method cannot be called if simplified fullscreen is enabled.
-  const CommandLine* command_line = CommandLine::ForCurrentProcess();
-  DCHECK(!command_line->HasSwitch(switches::kEnableSimplifiedFullscreen));
-
   CHECK(chrome::mac::SupportsSystemFullscreen());
-  if ([controller_ inPresentationMode])
-    [controller_ exitPresentationMode];
-  else
-    [controller_ enterFullscreen];
+  [controller_ enterFullscreenWithChrome];
+}
+
+void BrowserWindowCocoa::EnterFullscreenWithoutChrome() {
+  [controller_ enterPresentationMode];
 }
 
 bool BrowserWindowCocoa::IsFullscreenWithChrome() {
-  // The WithChrome mode does not exist when simplified fullscreen is enabled.
-  const CommandLine* command_line = CommandLine::ForCurrentProcess();
-  if (command_line->HasSwitch(switches::kEnableSimplifiedFullscreen))
-    return false;
   return IsFullscreen() && ![controller_ inPresentationMode];
 }
 
 bool BrowserWindowCocoa::IsFullscreenWithoutChrome() {
-  // Presentation mode does not exist if simplified fullscreen is enabled.  The
-  // WithoutChrome mode simply maps to whether or not the window is fullscreen.
-  const CommandLine* command_line = CommandLine::ForCurrentProcess();
-  if (command_line->HasSwitch(switches::kEnableSimplifiedFullscreen))
-    return IsFullscreen();
-
   return IsFullscreen() && [controller_ inPresentationMode];
 }
 
 WindowOpenDisposition BrowserWindowCocoa::GetDispositionForPopupBounds(
     const gfx::Rect& bounds) {
   // When using Cocoa's System Fullscreen mode, convert popups into tabs.
-  if ([controller_ isInSystemFullscreen])
+  if ([controller_ isInAppKitFullscreen])
     return NEW_FOREGROUND_TAB;
   return NEW_POPUP;
 }
@@ -706,32 +694,15 @@ void BrowserWindowCocoa::ShowAvatarBubble(WebContents* web_contents,
 }
 
 void BrowserWindowCocoa::ShowAvatarBubbleFromAvatarButton(
-    AvatarBubbleMode mode) {
+    AvatarBubbleMode mode,
+    const signin::ManageAccountsParams& manage_accounts_params) {
   AvatarBaseController* controller = [controller_ avatarButtonController];
-  [controller showAvatarBubble:[controller buttonView] withMode:mode];
-}
-
-void BrowserWindowCocoa::ShowPasswordGenerationBubble(
-    const gfx::Rect& rect,
-    const autofill::PasswordForm& form,
-    autofill::PasswordGenerator* password_generator) {
-  WebContents* web_contents =
-      browser_->tab_strip_model()->GetActiveWebContents();
-  // We want to point to the middle of the rect instead of the right side.
-  NSPoint point = GetPointForBubble(web_contents,
-                                    rect.x() + rect.width()/2,
-                                    rect.bottom());
-
-  PasswordGenerationBubbleController* controller = [
-          [PasswordGenerationBubbleController alloc]
-       initWithWindow:browser_->window()->GetNativeWindow()
-           anchoredAt:point
-       renderViewHost:web_contents->GetRenderViewHost()
-      passwordManager:ChromePasswordManagerClient::GetManagerFromWebContents(
-                          web_contents)
-       usingGenerator:password_generator
-              forForm:form];
-  [controller showWindow:nil];
+  NSView* anchor = [controller buttonView];
+  if ([anchor isHiddenOrHasHiddenAncestor])
+    anchor = [[controller_ toolbarController] wrenchButton];
+  [controller showAvatarBubbleAnchoredAt:anchor
+                                withMode:mode
+                         withServiceType:manage_accounts_params.service_type];
 }
 
 int
@@ -746,13 +717,3 @@ void BrowserWindowCocoa::ExecuteExtensionCommand(
     const extensions::Command& command) {
   [cocoa_controller() executeExtensionCommand:extension->id() command:command];
 }
-
-void BrowserWindowCocoa::ShowPageActionPopup(
-    const extensions::Extension* extension) {
-  [cocoa_controller() activatePageAction:extension->id()];
-}
-
-void BrowserWindowCocoa::ShowBrowserActionPopup(
-    const extensions::Extension* extension) {
-  [cocoa_controller() activateBrowserAction:extension->id()];
-}