summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
authorTorne (Richard Coles) <torne@google.com>2013-10-22 16:41:35 +0100
committerTorne (Richard Coles) <torne@google.com>2013-10-22 16:41:35 +0100
commit8bcbed890bc3ce4d7a057a8f32cab53fa534672e (patch)
tree1390b6675d21328859f01f50203d9bde09105298 /apps
parent116fa16b45c9efe30e785b9fc32f09780ca23bec (diff)
downloadchromium_org-8bcbed890bc3ce4d7a057a8f32cab53fa534672e.tar.gz
Merge from Chromium at DEPS revision 230120
This commit was generated by merge_to_master.py. Change-Id: I54bc06b7ee8a07092e74ce3b68c6893508349042
Diffstat (limited to 'apps')
-rw-r--r--apps/DEPS1
-rw-r--r--apps/app_shim/app_shim_host_manager_mac.mm12
-rw-r--r--apps/apps.gypi2
-rw-r--r--apps/shell_window.cc194
-rw-r--r--apps/shell_window.h55
-rw-r--r--apps/ui/native_app_window.h4
6 files changed, 205 insertions, 63 deletions
diff --git a/apps/DEPS b/apps/DEPS
index 31e8bc855e..b7cf3e1e0b 100644
--- a/apps/DEPS
+++ b/apps/DEPS
@@ -40,6 +40,7 @@ include_rules = [
"+chrome/browser/extensions/extension_service.h",
"+chrome/browser/extensions/extension_system.h",
"+chrome/browser/extensions/extension_system_factory.h",
+ "+chrome/browser/extensions/extension_web_contents_observer.h",
"+chrome/browser/extensions/lazy_background_task_queue.h",
"+chrome/browser/extensions/suggest_permission_util.h",
"+chrome/browser/extensions/unpacked_installer.h",
diff --git a/apps/app_shim/app_shim_host_manager_mac.mm b/apps/app_shim/app_shim_host_manager_mac.mm
index 3e1772a4a9..eeaa114ade 100644
--- a/apps/app_shim/app_shim_host_manager_mac.mm
+++ b/apps/app_shim/app_shim_host_manager_mac.mm
@@ -7,12 +7,15 @@
#include "apps/app_shim/app_shim_handler_mac.h"
#include "apps/app_shim/app_shim_host_mac.h"
#include "base/bind.h"
+#include "base/command_line.h"
#include "base/files/file_path.h"
#include "base/logging.h"
#include "base/path_service.h"
#include "chrome/browser/browser_process.h"
#include "chrome/common/chrome_paths.h"
+#include "chrome/common/chrome_switches.h"
#include "chrome/common/mac/app_mode_common.h"
+#include "ipc/unix_domain_socket_util.h"
using content::BrowserThread;
@@ -54,6 +57,15 @@ void AppShimHostManager::InitOnFileThread() {
base::FilePath socket_path =
user_data_dir.Append(app_mode::kAppShimSocketName);
+ // This mirrors a check in unix_domain_socket_util.cc which will guarantee
+ // failure and spam log files on bots because they have deeply nested paths to
+ // |user_data_dir| when swarming. See http://crbug.com/240554. Shim tests that
+ // run on the bots must override the path using AppShimHostManagerTestApi.
+ if (socket_path.value().length() >= IPC::kMaxSocketNameLength &&
+ CommandLine::ForCurrentProcess()->HasSwitch(switches::kTestType)) {
+ return;
+ }
+
factory_.reset(new IPC::ChannelFactory(socket_path, this));
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
diff --git a/apps/apps.gypi b/apps/apps.gypi
index 2b8589aa9c..e956c460de 100644
--- a/apps/apps.gypi
+++ b/apps/apps.gypi
@@ -117,7 +117,7 @@
'apps',
'../base/base.gyp:base',
'../content/content.gyp:content',
- '../content/content.gyp:content_shell_lib',
+ '../content/content_shell_and_tests.gyp:content_shell_lib',
'../skia/skia.gyp:skia',
'../ui/shell/shell.gyp:shell',
'../ui/views/views.gyp:views',
diff --git a/apps/shell_window.cc b/apps/shell_window.cc
index 6c20a8783e..2b169d06df 100644
--- a/apps/shell_window.cc
+++ b/apps/shell_window.cc
@@ -13,6 +13,7 @@
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/extensions/extension_process_manager.h"
#include "chrome/browser/extensions/extension_system.h"
+#include "chrome/browser/extensions/extension_web_contents_observer.h"
#include "chrome/browser/extensions/suggest_permission_util.h"
#include "chrome/browser/lifetime/application_lifetime.h"
#include "chrome/browser/profiles/profile.h"
@@ -56,6 +57,65 @@ const int kDefaultHeight = 384;
namespace apps {
+ShellWindow::SizeConstraints::SizeConstraints()
+ : maximum_size_(kUnboundedSize, kUnboundedSize) {
+}
+
+ShellWindow::SizeConstraints::SizeConstraints(const gfx::Size& min_size,
+ const gfx::Size& max_size)
+ : minimum_size_(min_size),
+ maximum_size_(max_size) {
+}
+
+ShellWindow::SizeConstraints::~SizeConstraints() {}
+
+gfx::Size ShellWindow::SizeConstraints::ClampSize(gfx::Size size) const {
+ const gfx::Size max_size = GetMaximumSize();
+ if (max_size.width() != kUnboundedSize)
+ size.set_width(std::min(size.width(), GetMaximumSize().width()));
+ if (max_size.height() != kUnboundedSize)
+ size.set_height(std::min(size.height(), GetMaximumSize().height()));
+ size.SetToMax(GetMinimumSize());
+ return size;
+}
+
+bool ShellWindow::SizeConstraints::HasMinimumSize() const {
+ return GetMinimumSize().width() != kUnboundedSize ||
+ GetMinimumSize().height() != kUnboundedSize;
+}
+
+bool ShellWindow::SizeConstraints::HasMaximumSize() const {
+ const gfx::Size max_size = GetMaximumSize();
+ return max_size.width() != kUnboundedSize ||
+ max_size.height() != kUnboundedSize;
+}
+
+bool ShellWindow::SizeConstraints::HasFixedSize() const {
+ return !GetMinimumSize().IsEmpty() && GetMinimumSize() == GetMaximumSize();
+}
+
+gfx::Size ShellWindow::SizeConstraints::GetMinimumSize() const {
+ return minimum_size_;
+}
+
+gfx::Size ShellWindow::SizeConstraints::GetMaximumSize() const {
+ return gfx::Size(
+ maximum_size_.width() == kUnboundedSize ?
+ kUnboundedSize :
+ std::max(maximum_size_.width(), minimum_size_.width()),
+ maximum_size_.height() == kUnboundedSize ?
+ kUnboundedSize :
+ std::max(maximum_size_.height(), minimum_size_.height()));
+}
+
+void ShellWindow::SizeConstraints::set_minimum_size(const gfx::Size& min_size) {
+ minimum_size_ = min_size;
+}
+
+void ShellWindow::SizeConstraints::set_maximum_size(const gfx::Size& max_size) {
+ maximum_size_ = max_size;
+}
+
ShellWindow::CreateParams::CreateParams()
: window_type(ShellWindow::WINDOW_TYPE_DEFAULT),
frame(ShellWindow::FRAME_CHROME),
@@ -95,6 +155,7 @@ void ShellWindow::Init(const GURL& url,
WebContents* web_contents = shell_window_contents_->GetWebContents();
delegate_->InitWebContents(web_contents);
WebContentsModalDialogManager::CreateForWebContents(web_contents);
+ extensions::ExtensionWebContentsObserver::CreateForWebContents(web_contents);
web_contents->SetDelegate(this);
WebContentsModalDialogManager::FromWebContents(web_contents)->
@@ -102,67 +163,11 @@ void ShellWindow::Init(const GURL& url,
extensions::SetViewType(web_contents, extensions::VIEW_TYPE_APP_SHELL);
// Initialize the window
- window_type_ = params.window_type;
-
- gfx::Rect bounds = params.bounds;
-
- if (bounds.width() == 0)
- bounds.set_width(kDefaultWidth);
- if (bounds.height() == 0)
- bounds.set_height(kDefaultHeight);
-
- // If left and top are left undefined, the native shell window will center
- // the window on the main screen in a platform-defined manner.
-
- CreateParams new_params = params;
-
- // Load cached state if it exists.
- if (!params.window_key.empty()) {
- window_key_ = params.window_key;
-
- ShellWindowGeometryCache* cache = ShellWindowGeometryCache::Get(profile());
-
- gfx::Rect cached_bounds;
- gfx::Rect cached_screen_bounds;
- ui::WindowShowState cached_state = ui::SHOW_STATE_DEFAULT;
- if (cache->GetGeometry(extension()->id(), params.window_key, &cached_bounds,
- &cached_screen_bounds, &cached_state)) {
- // App window has cached screen bounds, make sure it fits on screen in
- // case the screen resolution changed.
- gfx::Screen* screen = gfx::Screen::GetNativeScreen();
- gfx::Display display = screen->GetDisplayMatching(cached_bounds);
- gfx::Rect current_screen_bounds = display.work_area();
- AdjustBoundsToBeVisibleOnScreen(cached_bounds,
- cached_screen_bounds,
- current_screen_bounds,
- params.minimum_size,
- &bounds);
- new_params.state = cached_state;
- }
- }
-
- gfx::Size& minimum_size = new_params.minimum_size;
- gfx::Size& maximum_size = new_params.maximum_size;
-
- // In the case that minimum size > maximum size, we consider the minimum
- // size to be more important.
- if (maximum_size.width() && maximum_size.width() < minimum_size.width())
- maximum_size.set_width(minimum_size.width());
- if (maximum_size.height() && maximum_size.height() < minimum_size.height())
- maximum_size.set_height(minimum_size.height());
-
- if (maximum_size.width() && bounds.width() > maximum_size.width())
- bounds.set_width(maximum_size.width());
- if (bounds.width() != INT_MIN && bounds.width() < minimum_size.width())
- bounds.set_width(minimum_size.width());
-
- if (maximum_size.height() && bounds.height() > maximum_size.height())
- bounds.set_height(maximum_size.height());
- if (bounds.height() != INT_MIN && bounds.height() < minimum_size.height())
- bounds.set_height(minimum_size.height());
-
- new_params.bounds = bounds;
-
+ CreateParams new_params = LoadDefaultsAndConstrain(params);
+ window_type_ = new_params.window_type;
+ window_key_ = new_params.window_key;
+ size_constraints_ = SizeConstraints(new_params.minimum_size,
+ new_params.maximum_size);
native_app_window_.reset(delegate_->CreateNativeAppWindow(this, new_params));
if (!new_params.hidden) {
@@ -191,7 +196,7 @@ void ShellWindow::Init(const GURL& url,
registrar_.Add(this, chrome::NOTIFICATION_APP_TERMINATING,
content::NotificationService::AllSources());
- shell_window_contents_->LoadContents(params.creator_process_id);
+ shell_window_contents_->LoadContents(new_params.creator_process_id);
// Prevent the browser process from shutting down while this window is open.
chrome::StartKeepAlive();
@@ -426,6 +431,16 @@ void ShellWindow::Restore() {
}
}
+void ShellWindow::SetMinimumSize(const gfx::Size& min_size) {
+ size_constraints_.set_minimum_size(min_size);
+ OnSizeConstraintsChanged();
+}
+
+void ShellWindow::SetMaximumSize(const gfx::Size& max_size) {
+ size_constraints_.set_maximum_size(max_size);
+ OnSizeConstraintsChanged();
+}
+
//------------------------------------------------------------------------------
// Private methods
@@ -473,6 +488,17 @@ void ShellWindow::UpdateExtensionAppIcon() {
app_icon_image_->image_skia().GetRepresentation(1.0f);
}
+void ShellWindow::OnSizeConstraintsChanged() {
+ native_app_window_->UpdateWindowMinMaxSize();
+ gfx::Rect bounds = GetClientBounds();
+ gfx::Size constrained_size = size_constraints_.ClampSize(bounds.size());
+ if (bounds.size() != constrained_size) {
+ bounds.set_size(constrained_size);
+ native_app_window_->SetBounds(bounds);
+ }
+ OnNativeWindowChanged();
+}
+
void ShellWindow::CloseContents(WebContents* contents) {
native_app_window_->Close();
}
@@ -644,6 +670,50 @@ void ShellWindow::AdjustBoundsToBeVisibleOnScreen(
}
}
+ShellWindow::CreateParams ShellWindow::LoadDefaultsAndConstrain(
+ CreateParams params) const {
+ gfx::Rect bounds = params.bounds;
+
+ if (bounds.width() == 0)
+ bounds.set_width(kDefaultWidth);
+ if (bounds.height() == 0)
+ bounds.set_height(kDefaultHeight);
+
+ // If left and top are left undefined, the native shell window will center
+ // the window on the main screen in a platform-defined manner.
+
+ // Load cached state if it exists.
+ if (!params.window_key.empty()) {
+ ShellWindowGeometryCache* cache = ShellWindowGeometryCache::Get(profile());
+
+ gfx::Rect cached_bounds;
+ gfx::Rect cached_screen_bounds;
+ ui::WindowShowState cached_state = ui::SHOW_STATE_DEFAULT;
+ if (cache->GetGeometry(extension()->id(), params.window_key,
+ &cached_bounds, &cached_screen_bounds,
+ &cached_state)) {
+ // App window has cached screen bounds, make sure it fits on screen in
+ // case the screen resolution changed.
+ gfx::Screen* screen = gfx::Screen::GetNativeScreen();
+ gfx::Display display = screen->GetDisplayMatching(cached_bounds);
+ gfx::Rect current_screen_bounds = display.work_area();
+ AdjustBoundsToBeVisibleOnScreen(cached_bounds,
+ cached_screen_bounds,
+ current_screen_bounds,
+ params.minimum_size,
+ &bounds);
+ params.state = cached_state;
+ }
+ }
+
+ SizeConstraints size_constraints(params.minimum_size, params.maximum_size);
+ params.bounds.set_size(size_constraints.ClampSize(bounds.size()));
+ params.minimum_size = size_constraints.GetMinimumSize();
+ params.maximum_size = size_constraints.GetMaximumSize();
+
+ return params;
+}
+
// static
SkRegion* ShellWindow::RawDraggableRegionsToSkRegion(
const std::vector<extensions::DraggableRegion>& regions) {
diff --git a/apps/shell_window.h b/apps/shell_window.h
index aee0cc59ab..efc69158a4 100644
--- a/apps/shell_window.h
+++ b/apps/shell_window.h
@@ -90,6 +90,41 @@ class ShellWindow : public content::NotificationObserver,
FRAME_NONE, // Frameless window.
};
+ class SizeConstraints {
+ public:
+ // The value SizeConstraints uses to represent an unbounded width or height.
+ // This is an enum so that it can be declared inline here.
+ enum { kUnboundedSize = 0 };
+
+ SizeConstraints();
+ SizeConstraints(const gfx::Size& min_size, const gfx::Size& max_size);
+ ~SizeConstraints();
+
+ // Returns the bounds with its size clamped to the min/max size.
+ gfx::Size ClampSize(gfx::Size size) const;
+
+ // When gfx::Size is used as a min/max size, a zero represents an unbounded
+ // component. This method checks whether either component is specified.
+ // Note we can't use gfx::Size::IsEmpty as it returns true if either width
+ // or height is zero.
+ bool HasMinimumSize() const;
+ bool HasMaximumSize() const;
+
+ // This returns true if all components are specified, and min and max are
+ // equal.
+ bool HasFixedSize() const;
+
+ gfx::Size GetMaximumSize() const;
+ gfx::Size GetMinimumSize() const;
+
+ void set_minimum_size(const gfx::Size& min_size);
+ void set_maximum_size(const gfx::Size& max_size);
+
+ private:
+ gfx::Size minimum_size_;
+ gfx::Size maximum_size_;
+ };
+
struct CreateParams {
CreateParams();
~CreateParams();
@@ -251,10 +286,19 @@ class ShellWindow : public content::NotificationObserver,
void Minimize();
void Restore();
+ // Set the minimum and maximum size that this window is allowed to be.
+ void SetMinimumSize(const gfx::Size& min_size);
+ void SetMaximumSize(const gfx::Size& max_size);
+
ShellWindowContents* shell_window_contents_for_test() {
return shell_window_contents_.get();
}
+ // Get the size constraints.
+ const SizeConstraints& size_constraints() const {
+ return size_constraints_;
+ }
+
protected:
virtual ~ShellWindow();
@@ -327,9 +371,17 @@ class ShellWindow : public content::NotificationObserver,
const gfx::Size& minimum_size,
gfx::Rect* bounds) const;
+ // Loads the appropriate default or cached window bounds and constrains them
+ // based on screen size and minimum/maximum size. Returns a new CreateParams
+ // that should be used to create the window.
+ CreateParams LoadDefaultsAndConstrain(CreateParams params) const;
+
// Load the app's image, firing a load state change when loaded.
void UpdateExtensionAppIcon();
+ // Called when size_constraints is changed.
+ void OnSizeConstraintsChanged();
+
// extensions::ExtensionKeybindingRegistry::Delegate implementation.
virtual extensions::ActiveTabPermissionGranter*
GetActiveTabPermissionGranter() OVERRIDE;
@@ -386,6 +438,9 @@ class ShellWindow : public content::NotificationObserver,
// The window content is visible.
bool is_content_visible_;
+ // Size constraints on the window.
+ SizeConstraints size_constraints_;
+
DISALLOW_COPY_AND_ASSIGN(ShellWindow);
};
diff --git a/apps/ui/native_app_window.h b/apps/ui/native_app_window.h
index c20e3b180e..37fbfbe55e 100644
--- a/apps/ui/native_app_window.h
+++ b/apps/ui/native_app_window.h
@@ -64,6 +64,10 @@ class NativeAppWindow : public ui::BaseWindow,
virtual void ShowWithApp() = 0;
virtual void HideWithApp() = 0;
+ // Updates the minimum and maximum size of the native window with the current
+ // size constraints.
+ virtual void UpdateWindowMinMaxSize() = 0;
+
virtual ~NativeAppWindow() {}
};