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

Unified Diff: apps/shell_window.cc

Issue 16702003: Move ShellWindow into apps component. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Self review Created 7 years, 6 months 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: apps/shell_window.cc
diff --git a/chrome/browser/ui/extensions/shell_window.cc b/apps/shell_window.cc
similarity index 82%
rename from chrome/browser/ui/extensions/shell_window.cc
rename to apps/shell_window.cc
index 6e30846329c6aed4fbd27f8be0c410d652b6c9fa..d6f0aee3537ea9b40a5631339378b733505686c5 100644
--- a/chrome/browser/ui/extensions/shell_window.cc
+++ b/apps/shell_window.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/browser/ui/extensions/shell_window.h"
+#include "apps/shell_window.h"
#include "apps/shell_window_geometry_cache.h"
#include "base/strings/utf_string_conversions.h"
@@ -13,18 +13,8 @@
#include "chrome/browser/extensions/image_loader.h"
#include "chrome/browser/extensions/shell_window_registry.h"
#include "chrome/browser/extensions/suggest_permission_util.h"
-#include "chrome/browser/favicon/favicon_tab_helper.h"
-#include "chrome/browser/file_select_helper.h"
#include "chrome/browser/lifetime/application_lifetime.h"
-#include "chrome/browser/media/media_capture_devices_dispatcher.h"
-#include "chrome/browser/platform_util.h"
#include "chrome/browser/profiles/profile.h"
-#include "chrome/browser/sessions/session_id.h"
-#include "chrome/browser/ui/browser.h"
-#include "chrome/browser/ui/browser_dialogs.h"
-#include "chrome/browser/ui/browser_finder.h"
-#include "chrome/browser/ui/browser_tabstrip.h"
-#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/extensions/native_app_window.h"
#include "chrome/common/chrome_notification_types.h"
#include "chrome/common/extensions/extension.h"
@@ -47,10 +37,6 @@
#include "third_party/skia/include/core/SkRegion.h"
#include "ui/gfx/image/image_skia.h"
-#if defined(USE_ASH)
-#include "ash/launcher/launcher_types.h"
-#endif
-
using content::ConsoleMessageLevel;
using content::WebContents;
using extensions::APIPermission;
@@ -61,32 +47,10 @@ namespace {
const int kDefaultWidth = 512;
const int kDefaultHeight = 384;
-// The preferred icon size for displaying the app icon.
-#if defined(USE_ASH)
-const int kPreferredIconSize = ash::kLauncherPreferredSize;
-#else
-const int kPreferredIconSize = extension_misc::EXTENSION_ICON_SMALL;
-#endif
-
-static bool disable_external_open_for_testing_ = false;
-
-class ShellWindowLinkDelegate : public content::WebContentsDelegate {
- private:
- virtual content::WebContents* OpenURLFromTab(
- content::WebContents* source,
- const content::OpenURLParams& params) OVERRIDE;
-};
-
-content::WebContents* ShellWindowLinkDelegate::OpenURLFromTab(
- content::WebContents* source,
- const content::OpenURLParams& params) {
- platform_util::OpenExternal(params.url);
- delete source;
- return NULL;
-}
-
} // namespace
+namespace apps {
+
ShellWindow::CreateParams::CreateParams()
: window_type(ShellWindow::WINDOW_TYPE_DEFAULT),
frame(ShellWindow::FRAME_CHROME),
@@ -96,29 +60,32 @@ ShellWindow::CreateParams::CreateParams()
state(ui::SHOW_STATE_DEFAULT),
hidden(false),
resizable(true),
- focused(true) {
-}
+ focused(true) {}
-ShellWindow::CreateParams::~CreateParams() {
-}
+ShellWindow::CreateParams::~CreateParams() {}
+
+ShellWindow::Delegate::~Delegate() {}
ShellWindow* ShellWindow::Create(Profile* profile,
+ Delegate* delegate,
const extensions::Extension* extension,
const GURL& url,
const CreateParams& params) {
// This object will delete itself when the window is closed.
- ShellWindow* window = new ShellWindow(profile, extension);
+ ShellWindow* window = new ShellWindow(profile, delegate, extension);
window->Init(url, new AppWindowContents(window), params);
extensions::ShellWindowRegistry::Get(profile)->AddShellWindow(window);
return window;
}
ShellWindow::ShellWindow(Profile* profile,
+ Delegate* delegate,
const extensions::Extension* extension)
: profile_(profile),
extension_(extension),
extension_id_(extension->id()),
window_type_(WINDOW_TYPE_DEFAULT),
+ delegate_(delegate),
image_loader_ptr_factory_(this),
fullscreen_for_window_api_(false),
fullscreen_for_tab_(false) {
@@ -131,8 +98,8 @@ void ShellWindow::Init(const GURL& url,
shell_window_contents_.reset(shell_window_contents);
shell_window_contents_->Initialize(profile(), url);
WebContents* web_contents = shell_window_contents_->GetWebContents();
+ delegate_->InitWebContents(web_contents);
WebContentsModalDialogManager::CreateForWebContents(web_contents);
- FaviconTabHelper::CreateForWebContents(web_contents);
web_contents->SetDelegate(this);
WebContentsModalDialogManager::FromWebContents(web_contents)->
@@ -156,8 +123,7 @@ void ShellWindow::Init(const GURL& url,
if (!params.window_key.empty()) {
window_key_ = params.window_key;
- apps::ShellWindowGeometryCache* cache =
- apps::ShellWindowGeometryCache::Get(profile());
+ ShellWindowGeometryCache* cache = ShellWindowGeometryCache::Get(profile());
gfx::Rect cached_bounds;
if (cache->GetGeometry(extension()->id(), params.window_key,
@@ -220,9 +186,7 @@ void ShellWindow::Init(const GURL& url,
&web_contents->GetController()));
registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED,
content::Source<Profile>(profile_));
- // Close when the browser is exiting.
- // TODO(mihaip): we probably don't want this in the long run (when platform
- // apps are no longer tied to the browser process).
+ // Close when the browser process is exiting.
registrar_.Add(this, chrome::NOTIFICATION_APP_TERMINATING,
content::NotificationService::AllSources());
@@ -247,8 +211,8 @@ void ShellWindow::RequestMediaAccessPermission(
content::WebContents* web_contents,
const content::MediaStreamRequest& request,
const content::MediaResponseCallback& callback) {
- MediaCaptureDevicesDispatcher::GetInstance()->ProcessMediaAccessRequest(
- web_contents, request, callback, extension());
+ delegate_->RequestMediaAccessPermission(web_contents, request, callback,
+ extension());
}
WebContents* ShellWindow::OpenURLFromTab(WebContents* source,
@@ -274,16 +238,9 @@ WebContents* ShellWindow::OpenURLFromTab(WebContents* source,
return NULL;
}
- // Force all links to open in a new tab, even if they were trying to open a
- // window.
- chrome::NavigateParams new_tab_params(
- static_cast<Browser*>(NULL), params.url, params.transition);
- new_tab_params.disposition =
- disposition == NEW_BACKGROUND_TAB ? disposition : NEW_FOREGROUND_TAB;
- new_tab_params.initiating_profile = profile_;
- chrome::Navigate(&new_tab_params);
-
- if (!new_tab_params.target_contents) {
+ WebContents* contents = delegate_->OpenURLFromTab(profile_, source,
+ params);
+ if (!contents) {
AddMessageToDevToolsConsole(
content::CONSOLE_MESSAGE_LEVEL_ERROR,
base::StringPrintf(
@@ -291,7 +248,7 @@ WebContents* ShellWindow::OpenURLFromTab(WebContents* source,
params.url.spec().c_str()));
}
- return new_tab_params.target_contents;
+ return contents;
}
void ShellWindow::AddNewContents(WebContents* source,
@@ -302,29 +259,8 @@ void ShellWindow::AddNewContents(WebContents* source,
bool* was_blocked) {
DCHECK(Profile::FromBrowserContext(new_contents->GetBrowserContext()) ==
profile_);
-#if defined(OS_LINUX) || defined(OS_MACOSX) || defined(OS_WIN)
- if (disable_external_open_for_testing_) {
- Browser* browser =
- chrome::FindOrCreateTabbedBrowser(profile_, chrome::GetActiveDesktop());
- // Force all links to open in a new tab, even if they were trying to open a
- // new window.
- disposition =
- disposition == NEW_BACKGROUND_TAB ? disposition : NEW_FOREGROUND_TAB;
- chrome::AddWebContents(browser, NULL, new_contents, disposition,
- initial_pos, user_gesture, was_blocked);
- } else {
- new_contents->SetDelegate(new ShellWindowLinkDelegate());
- }
-#else
- Browser* browser =
- chrome::FindOrCreateTabbedBrowser(profile_, chrome::GetActiveDesktop());
- // Force all links to open in a new tab, even if they were trying to open a
- // new window.
- disposition =
- disposition == NEW_BACKGROUND_TAB ? disposition : NEW_FOREGROUND_TAB;
- chrome::AddWebContents(browser, NULL, new_contents, disposition, initial_pos,
- user_gesture, was_blocked);
-#endif
+ delegate_->AddNewContents(profile_, new_contents, disposition,
+ initial_pos, user_gesture, was_blocked);
}
void ShellWindow::HandleKeyboardEvent(
@@ -404,7 +340,12 @@ string16 ShellWindow::GetTitle() const {
web_contents()->GetController().GetActiveEntry()->GetTitle().empty())
return UTF8ToUTF16(extension()->name());
string16 title = web_contents()->GetTitle();
- Browser::FormatTitleForDisplay(&title);
+ size_t current_index = 0;
+ size_t match_index;
+ while ((match_index = title.find(L'\n', current_index)) != string16::npos) {
miket_OOO 2013/06/14 20:07:51 I think this deletes newlines. If I'm correct, ple
benwells 2013/06/19 09:00:21 Done. I've also made it strip newlines from the ex
+ title.replace(match_index, 1, string16());
+ current_index = match_index;
+ }
return title;
}
@@ -414,7 +355,7 @@ void ShellWindow::SetAppIconUrl(const GURL& url) {
app_icon_url_ = url;
web_contents()->DownloadImage(
- url, true, kPreferredIconSize,
+ url, true, delegate_->PreferredIconSize(),
base::Bind(&ShellWindow::DidDownloadFavicon,
image_loader_ptr_factory_.GetWeakPtr()));
}
@@ -474,7 +415,7 @@ void ShellWindow::DidDownloadFavicon(int id,
// whose height >= the preferred size.
int largest_index = 0;
for (size_t i = 1; i < bitmaps.size(); ++i) {
- if (bitmaps[i].height() < kPreferredIconSize)
+ if (bitmaps[i].height() < delegate_->PreferredIconSize())
break;
largest_index = i;
}
@@ -491,9 +432,9 @@ void ShellWindow::UpdateExtensionAppIcon() {
loader->LoadImageAsync(
extension(),
extensions::IconsInfo::GetIconResource(extension(),
- kPreferredIconSize,
+ delegate_->PreferredIconSize(),
ExtensionIconSet::MATCH_BIGGER),
- gfx::Size(kPreferredIconSize, kPreferredIconSize),
+ gfx::Size(delegate_->PreferredIconSize(), delegate_->PreferredIconSize()),
base::Bind(&ShellWindow::OnImageLoaded,
image_loader_ptr_factory_.GetWeakPtr()));
}
@@ -508,7 +449,7 @@ bool ShellWindow::ShouldSuppressDialogs() {
content::ColorChooser* ShellWindow::OpenColorChooser(WebContents* web_contents,
SkColor initial_color) {
- return chrome::ShowColorChooser(web_contents, initial_color);
+ return delegate_->ShowColorChooser(web_contents, initial_color);
}
void ShellWindow::RunFileChooser(WebContents* tab,
@@ -520,7 +461,8 @@ void ShellWindow::RunFileChooser(WebContents* tab,
LOG(WARNING) << "File dialog opened by panel.";
return;
}
- FileSelectHelper::RunFileChooser(tab, params);
+
+ delegate_->RunFileChooser(tab, params);
}
bool ShellWindow::IsPopupOrPanel(const WebContents* source) const {
@@ -589,6 +531,15 @@ void ShellWindow::Observe(int type,
}
}
+void ShellWindow::SetWebContentsBlocked(content::WebContents* web_contents,
+ bool blocked) {
+ delegate_->SetWebContentsBlocked(web_contents, blocked);
+}
+
+bool ShellWindow::IsWebContentsVisible(content::WebContents* web_contents) {
+ return delegate_->IsWebContentsVisible(web_contents);
+}
+
extensions::ActiveTabPermissionGranter*
ShellWindow::GetActiveTabPermissionGranter() {
// Shell windows don't support the activeTab permission.
@@ -612,8 +563,7 @@ void ShellWindow::SaveWindowPosition() {
if (!native_app_window_)
return;
- apps::ShellWindowGeometryCache* cache =
- apps::ShellWindowGeometryCache::Get(profile());
+ ShellWindowGeometryCache* cache = ShellWindowGeometryCache::Get(profile());
gfx::Rect bounds = native_app_window_->GetRestoredBounds();
bounds.Inset(native_app_window_->GetFrameInsets());
@@ -639,7 +589,4 @@ SkRegion* ShellWindow::RawDraggableRegionsToSkRegion(
return sk_region;
}
-void ShellWindow::DisableExternalOpenForTesting() {
- disable_external_open_for_testing_ = true;
-}
-
+} // namespace apps

Powered by Google App Engine
This is Rietveld 408576698