| Index: extensions/browser/app_window/app_window.cc
|
| diff --git a/extensions/browser/app_window/app_window.cc b/extensions/browser/app_window/app_window.cc
|
| index 83b44a263790f8352c4eea8a3551ffd0743eb66c..b6ef68a81b001982f151587c8ea6ab9486e5ce95 100644
|
| --- a/extensions/browser/app_window/app_window.cc
|
| +++ b/extensions/browser/app_window/app_window.cc
|
| @@ -12,6 +12,9 @@
|
| #include "base/strings/string_util.h"
|
| #include "base/strings/utf_string_conversions.h"
|
| #include "base/values.h"
|
| +#include "components/native_app_window/draggable_region.h"
|
| +#include "components/native_app_window/native_app_window.h"
|
| +#include "components/native_app_window/size_constraints.h"
|
| #include "components/web_modal/web_contents_modal_dialog_manager.h"
|
| #include "content/public/browser/browser_context.h"
|
| #include "content/public/browser/invalidate_type.h"
|
| @@ -26,15 +29,12 @@
|
| #include "extensions/browser/app_window/app_window_client.h"
|
| #include "extensions/browser/app_window/app_window_geometry_cache.h"
|
| #include "extensions/browser/app_window/app_window_registry.h"
|
| -#include "extensions/browser/app_window/native_app_window.h"
|
| -#include "extensions/browser/app_window/size_constraints.h"
|
| #include "extensions/browser/extension_registry.h"
|
| #include "extensions/browser/extension_system.h"
|
| #include "extensions/browser/extensions_browser_client.h"
|
| #include "extensions/browser/process_manager.h"
|
| #include "extensions/browser/suggest_permission_util.h"
|
| #include "extensions/browser/view_type_utils.h"
|
| -#include "extensions/common/draggable_region.h"
|
| #include "extensions/common/extension.h"
|
| #include "extensions/common/manifest_handlers/icons_handler.h"
|
| #include "extensions/common/permissions/permissions_data.h"
|
| @@ -54,6 +54,7 @@ using content::ConsoleMessageLevel;
|
| using content::WebContents;
|
| using web_modal::WebContentsModalDialogHost;
|
| using web_modal::WebContentsModalDialogManager;
|
| +using native_app_window::SizeConstraints;
|
|
|
| namespace extensions {
|
|
|
| @@ -94,132 +95,8 @@ void SetBoundsProperties(const gfx::Rect& bounds,
|
| window_properties->Set(bounds_name, bounds_properties.release());
|
| }
|
|
|
| -// Combines the constraints of the content and window, and returns constraints
|
| -// for the window.
|
| -gfx::Size GetCombinedWindowConstraints(const gfx::Size& window_constraints,
|
| - const gfx::Size& content_constraints,
|
| - const gfx::Insets& frame_insets) {
|
| - gfx::Size combined_constraints(window_constraints);
|
| - if (content_constraints.width() > 0) {
|
| - combined_constraints.set_width(
|
| - content_constraints.width() + frame_insets.width());
|
| - }
|
| - if (content_constraints.height() > 0) {
|
| - combined_constraints.set_height(
|
| - content_constraints.height() + frame_insets.height());
|
| - }
|
| - return combined_constraints;
|
| -}
|
| -
|
| -// Combines the constraints of the content and window, and returns constraints
|
| -// for the content.
|
| -gfx::Size GetCombinedContentConstraints(const gfx::Size& window_constraints,
|
| - const gfx::Size& content_constraints,
|
| - const gfx::Insets& frame_insets) {
|
| - gfx::Size combined_constraints(content_constraints);
|
| - if (window_constraints.width() > 0) {
|
| - combined_constraints.set_width(
|
| - std::max(0, window_constraints.width() - frame_insets.width()));
|
| - }
|
| - if (window_constraints.height() > 0) {
|
| - combined_constraints.set_height(
|
| - std::max(0, window_constraints.height() - frame_insets.height()));
|
| - }
|
| - return combined_constraints;
|
| -}
|
| -
|
| } // namespace
|
|
|
| -// AppWindow::BoundsSpecification
|
| -
|
| -const int AppWindow::BoundsSpecification::kUnspecifiedPosition = INT_MIN;
|
| -
|
| -AppWindow::BoundsSpecification::BoundsSpecification()
|
| - : bounds(kUnspecifiedPosition, kUnspecifiedPosition, 0, 0) {}
|
| -
|
| -AppWindow::BoundsSpecification::~BoundsSpecification() {}
|
| -
|
| -void AppWindow::BoundsSpecification::ResetBounds() {
|
| - bounds.SetRect(kUnspecifiedPosition, kUnspecifiedPosition, 0, 0);
|
| -}
|
| -
|
| -// AppWindow::CreateParams
|
| -
|
| -AppWindow::CreateParams::CreateParams()
|
| - : window_type(AppWindow::WINDOW_TYPE_DEFAULT),
|
| - frame(AppWindow::FRAME_CHROME),
|
| - has_frame_color(false),
|
| - active_frame_color(SK_ColorBLACK),
|
| - inactive_frame_color(SK_ColorBLACK),
|
| - alpha_enabled(false),
|
| - is_ime_window(false),
|
| - creator_process_id(0),
|
| - state(ui::SHOW_STATE_DEFAULT),
|
| - hidden(false),
|
| - resizable(true),
|
| - focused(true),
|
| - always_on_top(false),
|
| - visible_on_all_workspaces(false) {
|
| -}
|
| -
|
| -AppWindow::CreateParams::~CreateParams() {}
|
| -
|
| -gfx::Rect AppWindow::CreateParams::GetInitialWindowBounds(
|
| - const gfx::Insets& frame_insets) const {
|
| - // Combine into a single window bounds.
|
| - gfx::Rect combined_bounds(window_spec.bounds);
|
| - if (content_spec.bounds.x() != BoundsSpecification::kUnspecifiedPosition)
|
| - combined_bounds.set_x(content_spec.bounds.x() - frame_insets.left());
|
| - if (content_spec.bounds.y() != BoundsSpecification::kUnspecifiedPosition)
|
| - combined_bounds.set_y(content_spec.bounds.y() - frame_insets.top());
|
| - if (content_spec.bounds.width() > 0) {
|
| - combined_bounds.set_width(
|
| - content_spec.bounds.width() + frame_insets.width());
|
| - }
|
| - if (content_spec.bounds.height() > 0) {
|
| - combined_bounds.set_height(
|
| - content_spec.bounds.height() + frame_insets.height());
|
| - }
|
| -
|
| - // Constrain the bounds.
|
| - SizeConstraints constraints(
|
| - GetCombinedWindowConstraints(
|
| - window_spec.minimum_size, content_spec.minimum_size, frame_insets),
|
| - GetCombinedWindowConstraints(
|
| - window_spec.maximum_size, content_spec.maximum_size, frame_insets));
|
| - combined_bounds.set_size(constraints.ClampSize(combined_bounds.size()));
|
| -
|
| - return combined_bounds;
|
| -}
|
| -
|
| -gfx::Size AppWindow::CreateParams::GetContentMinimumSize(
|
| - const gfx::Insets& frame_insets) const {
|
| - return GetCombinedContentConstraints(window_spec.minimum_size,
|
| - content_spec.minimum_size,
|
| - frame_insets);
|
| -}
|
| -
|
| -gfx::Size AppWindow::CreateParams::GetContentMaximumSize(
|
| - const gfx::Insets& frame_insets) const {
|
| - return GetCombinedContentConstraints(window_spec.maximum_size,
|
| - content_spec.maximum_size,
|
| - frame_insets);
|
| -}
|
| -
|
| -gfx::Size AppWindow::CreateParams::GetWindowMinimumSize(
|
| - const gfx::Insets& frame_insets) const {
|
| - return GetCombinedWindowConstraints(window_spec.minimum_size,
|
| - content_spec.minimum_size,
|
| - frame_insets);
|
| -}
|
| -
|
| -gfx::Size AppWindow::CreateParams::GetWindowMaximumSize(
|
| - const gfx::Insets& frame_insets) const {
|
| - return GetCombinedWindowConstraints(window_spec.maximum_size,
|
| - content_spec.maximum_size,
|
| - frame_insets);
|
| -}
|
| -
|
| // AppWindow
|
|
|
| AppWindow::AppWindow(BrowserContext* context,
|
| @@ -227,10 +104,10 @@ AppWindow::AppWindow(BrowserContext* context,
|
| const Extension* extension)
|
| : browser_context_(context),
|
| extension_id_(extension->id()),
|
| - window_type_(WINDOW_TYPE_DEFAULT),
|
| + window_type_(native_app_window::WINDOW_TYPE_DEFAULT),
|
| app_delegate_(app_delegate),
|
| image_loader_ptr_factory_(this),
|
| - fullscreen_types_(FULLSCREEN_TYPE_NONE),
|
| + fullscreen_types_(native_app_window::FULLSCREEN_TYPE_NONE),
|
| show_on_first_paint_(false),
|
| first_paint_complete_(false),
|
| has_been_shown_(false),
|
| @@ -312,7 +189,7 @@ void AppWindow::Init(const GURL& url,
|
|
|
| // Close when the browser process is exiting.
|
| app_delegate_->SetTerminatingCallback(
|
| - base::Bind(&NativeAppWindow::Close,
|
| + base::Bind(&native_app_window::NativeAppWindow::Close,
|
| base::Unretained(native_app_window_.get())));
|
|
|
| app_window_contents_->LoadContents(new_params.creator_process_id);
|
| @@ -432,36 +309,6 @@ void AppWindow::DidFirstVisuallyNonEmptyPaint() {
|
| }
|
| }
|
|
|
| -void AppWindow::OnNativeClose() {
|
| - AppWindowRegistry::Get(browser_context_)->RemoveAppWindow(this);
|
| - if (app_window_contents_) {
|
| - WebContents* web_contents = app_window_contents_->GetWebContents();
|
| - WebContentsModalDialogManager::FromWebContents(web_contents)
|
| - ->SetDelegate(NULL);
|
| - app_window_contents_->NativeWindowClosed();
|
| - }
|
| - delete this;
|
| -}
|
| -
|
| -void AppWindow::OnNativeWindowChanged() {
|
| - SaveWindowPosition();
|
| -
|
| -#if defined(OS_WIN)
|
| - if (native_app_window_ && cached_always_on_top_ && !IsFullscreen() &&
|
| - !native_app_window_->IsMaximized() &&
|
| - !native_app_window_->IsMinimized()) {
|
| - UpdateNativeAlwaysOnTop();
|
| - }
|
| -#endif
|
| -
|
| - if (app_window_contents_ && native_app_window_)
|
| - app_window_contents_->NativeWindowChanged(native_app_window_.get());
|
| -}
|
| -
|
| -void AppWindow::OnNativeWindowActivated() {
|
| - AppWindowRegistry::Get(browser_context_)->AppWindowActivated(this);
|
| -}
|
| -
|
| content::WebContents* AppWindow::web_contents() const {
|
| return app_window_contents_->GetWebContents();
|
| }
|
| @@ -472,7 +319,9 @@ const Extension* AppWindow::GetExtension() const {
|
| .GetByID(extension_id_);
|
| }
|
|
|
| -NativeAppWindow* AppWindow::GetBaseWindow() { return native_app_window_.get(); }
|
| +native_app_window::NativeAppWindow* AppWindow::GetBaseWindow() {
|
| + return native_app_window_.get();
|
| +}
|
|
|
| gfx::NativeWindow AppWindow::GetNativeWindow() {
|
| return GetBaseWindow()->GetNativeWindow();
|
| @@ -484,25 +333,6 @@ gfx::Rect AppWindow::GetClientBounds() const {
|
| return bounds;
|
| }
|
|
|
| -base::string16 AppWindow::GetTitle() const {
|
| - const Extension* extension = GetExtension();
|
| - if (!extension)
|
| - return base::string16();
|
| -
|
| - // WebContents::GetTitle() will return the page's URL if there's no <title>
|
| - // specified. However, we'd prefer to show the name of the extension in that
|
| - // case, so we directly inspect the NavigationEntry's title.
|
| - base::string16 title;
|
| - if (!web_contents() || !web_contents()->GetController().GetActiveEntry() ||
|
| - web_contents()->GetController().GetActiveEntry()->GetTitle().empty()) {
|
| - title = base::UTF8ToUTF16(extension->name());
|
| - } else {
|
| - title = web_contents()->GetTitle();
|
| - }
|
| - base::RemoveChars(title, base::ASCIIToUTF16("\n"), &title);
|
| - return title;
|
| -}
|
| -
|
| void AppWindow::SetAppIconUrl(const GURL& url) {
|
| // If the same url is being used for the badge, ignore it.
|
| if (url == badge_icon_url_)
|
| @@ -550,7 +380,7 @@ void AppWindow::UpdateShape(scoped_ptr<SkRegion> region) {
|
| }
|
|
|
| void AppWindow::UpdateDraggableRegions(
|
| - const std::vector<DraggableRegion>& regions) {
|
| + const std::vector<native_app_window::DraggableRegion>& regions) {
|
| native_app_window_->UpdateDraggableRegions(regions);
|
| }
|
|
|
| @@ -562,15 +392,16 @@ void AppWindow::UpdateAppIcon(const gfx::Image& image) {
|
| AppWindowRegistry::Get(browser_context_)->AppWindowIconChanged(this);
|
| }
|
|
|
| -void AppWindow::SetFullscreen(FullscreenType type, bool enable) {
|
| - DCHECK_NE(FULLSCREEN_TYPE_NONE, type);
|
| +void AppWindow::SetFullscreen(native_app_window::FullscreenType type,
|
| + bool enable) {
|
| + DCHECK_NE(native_app_window::FULLSCREEN_TYPE_NONE, type);
|
|
|
| if (enable) {
|
| #if !defined(OS_MACOSX)
|
| // Do not enter fullscreen mode if disallowed by pref.
|
| // TODO(bartfab): Add a test once it becomes possible to simulate a user
|
| // gesture. http://crbug.com/174178
|
| - if (type != FULLSCREEN_TYPE_FORCED) {
|
| + if (type != native_app_window::FULLSCREEN_TYPE_FORCED) {
|
| PrefService* prefs =
|
| ExtensionsBrowserClient::Get()->GetPrefServiceForContext(
|
| browser_context());
|
| @@ -586,19 +417,19 @@ void AppWindow::SetFullscreen(FullscreenType type, bool enable) {
|
| }
|
|
|
| bool AppWindow::IsFullscreen() const {
|
| - return fullscreen_types_ != FULLSCREEN_TYPE_NONE;
|
| + return fullscreen_types_ != native_app_window::FULLSCREEN_TYPE_NONE;
|
| }
|
|
|
| bool AppWindow::IsForcedFullscreen() const {
|
| - return (fullscreen_types_ & FULLSCREEN_TYPE_FORCED) != 0;
|
| + return (fullscreen_types_ & native_app_window::FULLSCREEN_TYPE_FORCED) != 0;
|
| }
|
|
|
| bool AppWindow::IsHtmlApiFullscreen() const {
|
| - return (fullscreen_types_ & FULLSCREEN_TYPE_HTML_API) != 0;
|
| + return (fullscreen_types_ & native_app_window::FULLSCREEN_TYPE_HTML_API) != 0;
|
| }
|
|
|
| void AppWindow::Fullscreen() {
|
| - SetFullscreen(FULLSCREEN_TYPE_WINDOW_API, true);
|
| + SetFullscreen(native_app_window::FULLSCREEN_TYPE_WINDOW_API, true);
|
| }
|
|
|
| void AppWindow::Maximize() { GetBaseWindow()->Maximize(); }
|
| @@ -607,7 +438,7 @@ void AppWindow::Minimize() { GetBaseWindow()->Minimize(); }
|
|
|
| void AppWindow::Restore() {
|
| if (IsFullscreen()) {
|
| - fullscreen_types_ = FULLSCREEN_TYPE_NONE;
|
| + fullscreen_types_ = native_app_window::FULLSCREEN_TYPE_NONE;
|
| SetNativeWindowFullscreen();
|
| } else {
|
| GetBaseWindow()->Restore();
|
| @@ -615,11 +446,11 @@ void AppWindow::Restore() {
|
| }
|
|
|
| void AppWindow::OSFullscreen() {
|
| - SetFullscreen(FULLSCREEN_TYPE_OS, true);
|
| + SetFullscreen(native_app_window::FULLSCREEN_TYPE_OS, true);
|
| }
|
|
|
| void AppWindow::ForcedFullscreen() {
|
| - SetFullscreen(FULLSCREEN_TYPE_FORCED, true);
|
| + SetFullscreen(native_app_window::FULLSCREEN_TYPE_FORCED, true);
|
| }
|
|
|
| void AppWindow::SetContentSizeConstraints(const gfx::Size& min_size,
|
| @@ -916,7 +747,7 @@ void AppWindow::ToggleFullscreenModeForTab(content::WebContents* source,
|
| return;
|
| }
|
|
|
| - SetFullscreen(FULLSCREEN_TYPE_HTML_API, enter_fullscreen);
|
| + SetFullscreen(native_app_window::FULLSCREEN_TYPE_HTML_API, enter_fullscreen);
|
| }
|
|
|
| bool AppWindow::IsFullscreenForTabOrPending(const content::WebContents* source)
|
| @@ -951,6 +782,75 @@ bool AppWindow::IsWebContentsVisible(content::WebContents* web_contents) {
|
| return app_delegate_->IsWebContentsVisible(web_contents);
|
| }
|
|
|
| +content::WebContents* AppWindow::GetWebContents() {
|
| + return web_contents();
|
| +}
|
| +
|
| +content::BrowserContext* AppWindow::GetBrowserContext() {
|
| + return browser_context();
|
| +}
|
| +
|
| +void AppWindow::OnNativeClose() {
|
| + AppWindowRegistry::Get(browser_context_)->RemoveAppWindow(this);
|
| + if (app_window_contents_) {
|
| + WebContents* web_contents = app_window_contents_->GetWebContents();
|
| + WebContentsModalDialogManager::FromWebContents(web_contents)
|
| + ->SetDelegate(NULL);
|
| + app_window_contents_->NativeWindowClosed();
|
| + }
|
| + delete this;
|
| +}
|
| +
|
| +void AppWindow::OnNativeWindowChanged() {
|
| + SaveWindowPosition();
|
| +
|
| +#if defined(OS_WIN)
|
| + if (native_app_window_ && cached_always_on_top_ && !IsFullscreen() &&
|
| + !native_app_window_->IsMaximized() &&
|
| + !native_app_window_->IsMinimized()) {
|
| + UpdateNativeAlwaysOnTop();
|
| + }
|
| +#endif
|
| +
|
| + if (app_window_contents_ && native_app_window_)
|
| + app_window_contents_->NativeWindowChanged(native_app_window_.get());
|
| +}
|
| +
|
| +void AppWindow::OnNativeWindowActivated() {
|
| + AppWindowRegistry::Get(browser_context_)->AppWindowActivated(this);
|
| +}
|
| +
|
| +bool AppWindow::RequestedAlphaEnabled() const {
|
| + return requested_alpha_enabled();
|
| +}
|
| +
|
| +base::string16 AppWindow::GetTitle() const {
|
| + const Extension* extension = GetExtension();
|
| + if (!extension)
|
| + return base::string16();
|
| +
|
| + // WebContents::GetTitle() will return the page's URL if there's no <title>
|
| + // specified. However, we'd prefer to show the name of the extension in that
|
| + // case, so we directly inspect the NavigationEntry's title.
|
| + base::string16 title;
|
| + if (!web_contents() || !web_contents()->GetController().GetActiveEntry() ||
|
| + web_contents()->GetController().GetActiveEntry()->GetTitle().empty()) {
|
| + title = base::UTF8ToUTF16(extension->name());
|
| + } else {
|
| + title = web_contents()->GetTitle();
|
| + }
|
| + base::RemoveChars(title, base::ASCIIToUTF16("\n"), &title);
|
| + return title;
|
| +}
|
| +
|
| +native_app_window::WindowType AppWindow::GetWindowType() const {
|
| + return window_type();
|
| +}
|
| +
|
| +bool AppWindow::WindowTypeIsPanel() const {
|
| + return window_type_is_panel();
|
| +}
|
| +
|
| WebContentsModalDialogHost* AppWindow::GetWebContentsModalDialogHost() {
|
| return native_app_window_.get();
|
| }
|
| @@ -1053,22 +953,4 @@ AppWindow::CreateParams AppWindow::LoadDefaults(CreateParams params)
|
| return params;
|
| }
|
|
|
| -// static
|
| -SkRegion* AppWindow::RawDraggableRegionsToSkRegion(
|
| - const std::vector<DraggableRegion>& regions) {
|
| - SkRegion* sk_region = new SkRegion;
|
| - for (std::vector<DraggableRegion>::const_iterator iter = regions.begin();
|
| - iter != regions.end();
|
| - ++iter) {
|
| - const DraggableRegion& region = *iter;
|
| - sk_region->op(
|
| - region.bounds.x(),
|
| - region.bounds.y(),
|
| - region.bounds.right(),
|
| - region.bounds.bottom(),
|
| - region.draggable ? SkRegion::kUnion_Op : SkRegion::kDifference_Op);
|
| - }
|
| - return sk_region;
|
| -}
|
| -
|
| } // namespace extensions
|
|
|