| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/ash/launcher/app_shortcut_launcher_item_controller.h
" | 5 #include "chrome/browser/ui/ash/launcher/app_shortcut_launcher_item_controller.h
" |
| 6 | 6 |
| 7 #include "ash/wm/window_util.h" | 7 #include "ash/wm/window_util.h" |
| 8 #include "chrome/browser/favicon/favicon_tab_helper.h" | 8 #include "chrome/browser/favicon/favicon_tab_helper.h" |
| 9 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item.h" | 9 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item.h" |
| 10 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item_tab.h" | 10 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item_tab.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 // item with the appropriate LauncherItemController type). | 26 // item with the appropriate LauncherItemController type). |
| 27 AppShortcutLauncherItemController::AppShortcutLauncherItemController( | 27 AppShortcutLauncherItemController::AppShortcutLauncherItemController( |
| 28 const std::string& app_id, | 28 const std::string& app_id, |
| 29 ChromeLauncherControllerPerApp* controller) | 29 ChromeLauncherControllerPerApp* controller) |
| 30 : LauncherItemController(TYPE_SHORTCUT, app_id, controller), | 30 : LauncherItemController(TYPE_SHORTCUT, app_id, controller), |
| 31 app_controller_(controller) { | 31 app_controller_(controller) { |
| 32 // To detect V1 applications we use their domain and match them against the | 32 // To detect V1 applications we use their domain and match them against the |
| 33 // used URL. This will also work with applications like Google Drive. | 33 // used URL. This will also work with applications like Google Drive. |
| 34 const Extension* extension = | 34 const Extension* extension = |
| 35 launcher_controller()->GetExtensionForAppID(app_id); | 35 launcher_controller()->GetExtensionForAppID(app_id); |
| 36 refocus_url_ = GURL(extension->launch_web_url() + "*"); | 36 // Some unit tests have no real extension and will set their |
| 37 if (extension) |
| 38 refocus_url_ = GURL(extension->launch_web_url() + "*"); |
| 37 } | 39 } |
| 38 | 40 |
| 39 AppShortcutLauncherItemController::~AppShortcutLauncherItemController() { | 41 AppShortcutLauncherItemController::~AppShortcutLauncherItemController() { |
| 40 } | 42 } |
| 41 | 43 |
| 42 string16 AppShortcutLauncherItemController::GetTitle() { | 44 string16 AppShortcutLauncherItemController::GetTitle() { |
| 43 return GetAppTitle(); | 45 return GetAppTitle(); |
| 44 } | 46 } |
| 45 | 47 |
| 46 bool AppShortcutLauncherItemController::HasWindow(aura::Window* window) const { | 48 bool AppShortcutLauncherItemController::HasWindow(aura::Window* window) const { |
| 47 std::vector<content::WebContents*> content = | 49 std::vector<content::WebContents*> content = |
| 48 app_controller_->GetV1ApplicationsFromAppId(app_id()); | 50 app_controller_->GetV1ApplicationsFromAppId(app_id()); |
| 49 for (size_t i = 0; i < content.size(); i++) { | 51 for (size_t i = 0; i < content.size(); i++) { |
| 50 Browser* browser = chrome::FindBrowserWithWebContents(content[i]); | 52 Browser* browser = chrome::FindBrowserWithWebContents(content[i]); |
| 51 if (browser && browser->window()->GetNativeWindow() == window) | 53 if (browser && browser->window()->GetNativeWindow() == window) |
| 52 return true; | 54 return true; |
| 53 } | 55 } |
| 54 return false; | 56 return false; |
| 55 } | 57 } |
| 56 | 58 |
| 57 bool AppShortcutLauncherItemController::IsOpen() const { | 59 bool AppShortcutLauncherItemController::IsOpen() const { |
| 58 return !app_controller_->GetV1ApplicationsFromAppId(app_id()).empty(); | 60 return !app_controller_->GetV1ApplicationsFromAppId(app_id()).empty(); |
| 59 } | 61 } |
| 60 | 62 |
| 61 void AppShortcutLauncherItemController::Launch(int event_flags) { | 63 void AppShortcutLauncherItemController::Launch(int event_flags) { |
| 62 app_controller_->LaunchApp(app_id(), event_flags); | 64 app_controller_->LaunchApp(app_id(), event_flags); |
| 63 } | 65 } |
| 64 | 66 |
| 65 void AppShortcutLauncherItemController::Activate() { | 67 void AppShortcutLauncherItemController::Activate() { |
| 66 std::vector<content::WebContents*> content = | 68 std::vector<content::WebContents*> content = GetRunningApplications(); |
| 67 app_controller_->GetV1ApplicationsFromAppId(app_id()); | |
| 68 if (content.empty()) { | 69 if (content.empty()) { |
| 69 Launch(ui::EF_NONE); | 70 Launch(ui::EF_NONE); |
| 70 return; | 71 return; |
| 71 } | 72 } |
| 72 Browser* browser = chrome::FindBrowserWithWebContents(content[0]); | 73 Browser* browser = chrome::FindBrowserWithWebContents(content[0]); |
| 73 TabStripModel* tab_strip = browser->tab_strip_model(); | 74 TabStripModel* tab_strip = browser->tab_strip_model(); |
| 74 int index = tab_strip->GetIndexOfWebContents(content[0]); | 75 int index = tab_strip->GetIndexOfWebContents(content[0]); |
| 75 DCHECK_NE(TabStripModel::kNoTab, index); | 76 DCHECK_NE(TabStripModel::kNoTab, index); |
| 76 tab_strip->ActivateTabAt(index, false); | 77 tab_strip->ActivateTabAt(index, false); |
| 77 browser->window()->Show(); | 78 browser->window()->Show(); |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 // time, and might therefore loose it's "app" status. | 161 // time, and might therefore loose it's "app" status. |
| 161 if (refocus_pattern.MatchesURL(tab_url) && | 162 if (refocus_pattern.MatchesURL(tab_url) && |
| 162 (!refocus_pattern.match_all_urls() || | 163 (!refocus_pattern.match_all_urls() || |
| 163 launcher_controller()->GetPerAppInterface()-> | 164 launcher_controller()->GetPerAppInterface()-> |
| 164 IsWebContentHandledByApplication(web_contents, app_id()))) | 165 IsWebContentHandledByApplication(web_contents, app_id()))) |
| 165 items.push_back(web_contents); | 166 items.push_back(web_contents); |
| 166 } | 167 } |
| 167 } | 168 } |
| 168 return items; | 169 return items; |
| 169 } | 170 } |
| OLD | NEW |