1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/chromeos/extensions/file_manager/action_choice_dialog.h"
8 #include "base/files/file_path.h"
9 #include "chrome/browser/chromeos/extensions/file_manager/app_id.h"
10 #include "chrome/browser/chromeos/extensions/file_manager/fileapi_util.h"
11 #include "chrome/browser/chromeos/extensions/file_manager/url_util.h"
12 #include "chrome/browser/extensions/extension_service.h"
13 #include "chrome/browser/extensions/extension_system.h"
14 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/profiles/profile_manager.h"
16 #include "chrome/browser/ui/browser.h"
17 #include "chrome/browser/ui/browser_iterator.h"
18 #include "chrome/browser/ui/browser_window.h"
19 #include "chrome/browser/ui/extensions/application_launch.h"
20 #include "chrome/browser/ui/tabs/tab_strip_model.h"
21 #include "content/public/browser/web_contents.h"
22 #include "ui/gfx/screen.h"
24 namespace file_manager
{
28 // Finds a browser instance showing the target URL. Returns NULL if not
30 Browser
* FindBrowserForUrl(GURL target_url
) {
31 for (chrome::BrowserIterator it
; !it
.done(); it
.Next()) {
32 Browser
* browser
= *it
;
33 TabStripModel
* tab_strip
= browser
->tab_strip_model();
34 for (int idx
= 0; idx
< tab_strip
->count(); idx
++) {
35 content::WebContents
* web_contents
= tab_strip
->GetWebContentsAt(idx
);
36 const GURL
& url
= web_contents
->GetLastCommittedURL();
37 if (url
== target_url
)
46 void OpenActionChoiceDialog(const base::FilePath
& file_path
,
48 const int kDialogWidth
= 394;
49 // TODO(dgozman): remove 50, which is a title height once popup window
50 // will have no title.
51 const int kDialogHeight
= 316 + 50;
53 Profile
* profile
= ProfileManager::GetDefaultProfileOrOffTheRecord();
55 base::FilePath virtual_path
;
56 if (!ConvertAbsoluteFilePathToRelativeFileSystemPath(
57 profile
, kFileManagerAppId
, file_path
, &virtual_path
))
59 GURL dialog_url
= GetActionChoiceUrl(virtual_path
, advanced_mode
);
61 const gfx::Size screen
= ash::Shell::GetScreen()->GetPrimaryDisplay().size();
62 const gfx::Rect
bounds((screen
.width() - kDialogWidth
) / 2,
63 (screen
.height() - kDialogHeight
) / 2,
67 Browser
* browser
= FindBrowserForUrl(dialog_url
);
70 browser
->window()->Show();
74 ExtensionService
* service
= extensions::ExtensionSystem::Get(profile
)->
79 const extensions::Extension
* extension
=
80 service
->GetExtensionById(kFileManagerAppId
, false);
84 chrome::AppLaunchParams
params(profile
, extension
,
85 extension_misc::LAUNCH_WINDOW
,
87 params
.override_url
= dialog_url
;
88 params
.override_bounds
= bounds
;
89 chrome::OpenApplication(params
);
93 } // namespace file_manager