Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / ash / launcher / browser_shortcut_launcher_item_controller.cc
index 3fdb5f4..d35a1f8 100644 (file)
 #include "chrome/browser/ui/browser_finder.h"
 #include "chrome/browser/ui/browser_list.h"
 #include "chrome/browser/ui/browser_window.h"
+#include "chrome/browser/ui/chrome_pages.h"
 #include "chrome/browser/ui/tabs/tab_strip_model.h"
 #include "chrome/browser/web_applications/web_app.h"
 #include "chrome/common/extensions/extension_constants.h"
 #include "content/public/browser/web_contents.h"
+#include "content/public/common/url_constants.h"
 #include "grit/ash_resources.h"
 #include "grit/chromium_strings.h"
 #include "grit/generated_resources.h"
@@ -34,7 +36,7 @@
 #include "ui/base/resource/resource_bundle.h"
 #include "ui/events/event.h"
 #include "ui/gfx/image/image.h"
-#include "ui/views/corewm/window_animations.h"
+#include "ui/wm/core/window_animations.h"
 
 BrowserShortcutLauncherItemController::BrowserShortcutLauncherItemController(
     ChromeLauncherController* launcher_controller)
@@ -58,7 +60,7 @@ void BrowserShortcutLauncherItemController::UpdateBrowserItemState() {
   // Determine the new browser's active state and change if necessary.
   int browser_index = model->GetItemIndexForType(ash::TYPE_BROWSER_SHORTCUT);
   DCHECK_GE(browser_index, 0);
-  ash::LauncherItem browser_item = model->items()[browser_index];
+  ash::ShelfItem browser_item = model->items()[browser_index];
   ash::ShelfItemStatus browser_status = ash::STATUS_CLOSED;
 
   aura::Window* window = ash::wm::GetActiveWindow();
@@ -74,7 +76,7 @@ void BrowserShortcutLauncherItemController::UpdateBrowserItemState() {
       content::WebContents* contents =
           browser->tab_strip_model()->GetActiveWebContents();
       if (contents &&
-          (launcher_controller()->GetLauncherIDForWebContents(contents) !=
+          (launcher_controller()->GetShelfIDForWebContents(contents) !=
               browser_item.id))
         browser_status = ash::STATUS_RUNNING;
     }
@@ -98,6 +100,16 @@ void BrowserShortcutLauncherItemController::UpdateBrowserItemState() {
   }
 }
 
+void BrowserShortcutLauncherItemController::SetShelfIDForBrowserWindowContents(
+    Browser* browser,
+    content::WebContents* web_contents) {
+  if (!IsBrowserRepresentedInBrowserList(browser))
+    return;
+  ash::SetShelfIDForWindow(
+      launcher_controller()->GetShelfIDForWebContents(web_contents),
+      browser->window()->GetNativeWindow());
+}
+
 bool BrowserShortcutLauncherItemController::IsOpen() const {
   const BrowserList* ash_browser_list =
       BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH);
@@ -224,8 +236,8 @@ base::string16 BrowserShortcutLauncherItemController::GetTitle() {
 
 ui::MenuModel* BrowserShortcutLauncherItemController::CreateContextMenu(
     aura::Window* root_window) {
-  ash::LauncherItem item =
-      *(launcher_controller()->model()->ItemByID(launcher_id()));
+  ash::ShelfItem item =
+      *(launcher_controller()->model()->ItemByID(shelf_id()));
   return new LauncherContextMenu(launcher_controller(), &item, root_window);
 }
 
@@ -244,10 +256,10 @@ bool BrowserShortcutLauncherItemController::ShouldShowTooltip() {
 
 gfx::Image BrowserShortcutLauncherItemController::GetBrowserListIcon(
     content::WebContents* web_contents) const {
-  ResourceBundle& rb = ResourceBundle::GetSharedInstance();
+  ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
   return rb.GetImageNamed(IsIncognito(web_contents) ?
-      IDR_AURA_LAUNCHER_LIST_INCOGNITO_BROWSER :
-      IDR_AURA_LAUNCHER_LIST_BROWSER);
+      IDR_ASH_SHELF_LIST_INCOGNITO_BROWSER :
+      IDR_ASH_SHELF_LIST_BROWSER);
 }
 
 base::string16 BrowserShortcutLauncherItemController::GetBrowserListTitle(
@@ -289,7 +301,7 @@ void BrowserShortcutLauncherItemController::ActivateOrAdvanceToNextBrowser() {
     // bounce it (if it is already active).
     if (browser == items[0]) {
       AnimateWindow(browser->window()->GetNativeWindow(),
-                    views::corewm::WINDOW_ANIMATION_TYPE_BOUNCE);
+                    wm::WINDOW_ANIMATION_TYPE_BOUNCE);
       return;
     }
     browser = items[0];
@@ -317,13 +329,23 @@ void BrowserShortcutLauncherItemController::ActivateOrAdvanceToNextBrowser() {
 
 bool BrowserShortcutLauncherItemController::IsBrowserRepresentedInBrowserList(
     Browser* browser) {
-  return (browser &&
-          launcher_controller()->IsBrowserFromActiveUser(browser) &&
-          browser->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH &&
-          (browser->is_type_tabbed() ||
-           !browser->is_app() ||
-           !browser->is_type_popup() ||
-           launcher_controller()->
-               GetLauncherIDForAppID(web_app::GetExtensionIdFromApplicationName(
-                   browser->app_name())) <= 0));
+  // Only Ash desktop browser windows for the active user are represented.
+  if (!browser ||
+      !launcher_controller()->IsBrowserFromActiveUser(browser) ||
+      browser->host_desktop_type() != chrome::HOST_DESKTOP_TYPE_ASH)
+    return false;
+
+  // v1 App popup windows with a valid app id have their own icon.
+  if (browser->is_app() &&
+      browser->is_type_popup() &&
+      launcher_controller()->GetShelfIDForAppID(
+          web_app::GetExtensionIdFromApplicationName(browser->app_name())) > 0)
+    return false;
+
+  // Stand-alone chrome:// windows (e.g. settings) have their own icon.
+  if (chrome::IsTrustedPopupWindowWithScheme(browser, content::kChromeUIScheme))
+    return false;
+
+  // Tabbed browser and other popup windows are all represented.
+  return true;
 }