| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "extensions/browser/app_window/app_window.h" | 5 #include "extensions/browser/app_window/app_window.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 14 #include "base/values.h" | 14 #include "base/values.h" |
| 15 #include "components/native_app_window/draggable_region.h" |
| 16 #include "components/native_app_window/native_app_window.h" |
| 17 #include "components/native_app_window/size_constraints.h" |
| 15 #include "components/web_modal/web_contents_modal_dialog_manager.h" | 18 #include "components/web_modal/web_contents_modal_dialog_manager.h" |
| 16 #include "content/public/browser/browser_context.h" | 19 #include "content/public/browser/browser_context.h" |
| 17 #include "content/public/browser/invalidate_type.h" | 20 #include "content/public/browser/invalidate_type.h" |
| 18 #include "content/public/browser/navigation_entry.h" | 21 #include "content/public/browser/navigation_entry.h" |
| 19 #include "content/public/browser/render_view_host.h" | 22 #include "content/public/browser/render_view_host.h" |
| 20 #include "content/public/browser/resource_dispatcher_host.h" | 23 #include "content/public/browser/resource_dispatcher_host.h" |
| 21 #include "content/public/browser/web_contents.h" | 24 #include "content/public/browser/web_contents.h" |
| 22 #include "content/public/common/content_switches.h" | 25 #include "content/public/common/content_switches.h" |
| 23 #include "content/public/common/media_stream_request.h" | 26 #include "content/public/common/media_stream_request.h" |
| 24 #include "extensions/browser/app_window/app_delegate.h" | 27 #include "extensions/browser/app_window/app_delegate.h" |
| 25 #include "extensions/browser/app_window/app_web_contents_helper.h" | 28 #include "extensions/browser/app_window/app_web_contents_helper.h" |
| 26 #include "extensions/browser/app_window/app_window_client.h" | 29 #include "extensions/browser/app_window/app_window_client.h" |
| 27 #include "extensions/browser/app_window/app_window_geometry_cache.h" | 30 #include "extensions/browser/app_window/app_window_geometry_cache.h" |
| 28 #include "extensions/browser/app_window/app_window_registry.h" | 31 #include "extensions/browser/app_window/app_window_registry.h" |
| 29 #include "extensions/browser/app_window/native_app_window.h" | |
| 30 #include "extensions/browser/app_window/size_constraints.h" | |
| 31 #include "extensions/browser/extension_registry.h" | 32 #include "extensions/browser/extension_registry.h" |
| 32 #include "extensions/browser/extension_system.h" | 33 #include "extensions/browser/extension_system.h" |
| 33 #include "extensions/browser/extensions_browser_client.h" | 34 #include "extensions/browser/extensions_browser_client.h" |
| 34 #include "extensions/browser/process_manager.h" | 35 #include "extensions/browser/process_manager.h" |
| 35 #include "extensions/browser/suggest_permission_util.h" | 36 #include "extensions/browser/suggest_permission_util.h" |
| 36 #include "extensions/browser/view_type_utils.h" | 37 #include "extensions/browser/view_type_utils.h" |
| 37 #include "extensions/common/draggable_region.h" | |
| 38 #include "extensions/common/extension.h" | 38 #include "extensions/common/extension.h" |
| 39 #include "extensions/common/manifest_handlers/icons_handler.h" | 39 #include "extensions/common/manifest_handlers/icons_handler.h" |
| 40 #include "extensions/common/permissions/permissions_data.h" | 40 #include "extensions/common/permissions/permissions_data.h" |
| 41 #include "extensions/common/switches.h" | 41 #include "extensions/common/switches.h" |
| 42 #include "extensions/grit/extensions_browser_resources.h" | 42 #include "extensions/grit/extensions_browser_resources.h" |
| 43 #include "third_party/skia/include/core/SkRegion.h" | 43 #include "third_party/skia/include/core/SkRegion.h" |
| 44 #include "ui/base/resource/resource_bundle.h" | 44 #include "ui/base/resource/resource_bundle.h" |
| 45 #include "ui/gfx/screen.h" | 45 #include "ui/gfx/screen.h" |
| 46 | 46 |
| 47 #if !defined(OS_MACOSX) | 47 #if !defined(OS_MACOSX) |
| 48 #include "base/prefs/pref_service.h" | 48 #include "base/prefs/pref_service.h" |
| 49 #include "extensions/browser/pref_names.h" | 49 #include "extensions/browser/pref_names.h" |
| 50 #endif | 50 #endif |
| 51 | 51 |
| 52 using content::BrowserContext; | 52 using content::BrowserContext; |
| 53 using content::ConsoleMessageLevel; | 53 using content::ConsoleMessageLevel; |
| 54 using content::WebContents; | 54 using content::WebContents; |
| 55 using web_modal::WebContentsModalDialogHost; | 55 using web_modal::WebContentsModalDialogHost; |
| 56 using web_modal::WebContentsModalDialogManager; | 56 using web_modal::WebContentsModalDialogManager; |
| 57 using native_app_window::SizeConstraints; |
| 57 | 58 |
| 58 namespace extensions { | 59 namespace extensions { |
| 59 | 60 |
| 60 namespace { | 61 namespace { |
| 61 | 62 |
| 62 const int kDefaultWidth = 512; | 63 const int kDefaultWidth = 512; |
| 63 const int kDefaultHeight = 384; | 64 const int kDefaultHeight = 384; |
| 64 | 65 |
| 65 void SetConstraintProperty(const std::string& name, | 66 void SetConstraintProperty(const std::string& name, |
| 66 int value, | 67 int value, |
| (...skipping 20 matching lines...) Expand all Loading... |
| 87 SetConstraintProperty("minWidth", min_size.width(), bounds_properties.get()); | 88 SetConstraintProperty("minWidth", min_size.width(), bounds_properties.get()); |
| 88 SetConstraintProperty( | 89 SetConstraintProperty( |
| 89 "minHeight", min_size.height(), bounds_properties.get()); | 90 "minHeight", min_size.height(), bounds_properties.get()); |
| 90 SetConstraintProperty("maxWidth", max_size.width(), bounds_properties.get()); | 91 SetConstraintProperty("maxWidth", max_size.width(), bounds_properties.get()); |
| 91 SetConstraintProperty( | 92 SetConstraintProperty( |
| 92 "maxHeight", max_size.height(), bounds_properties.get()); | 93 "maxHeight", max_size.height(), bounds_properties.get()); |
| 93 | 94 |
| 94 window_properties->Set(bounds_name, bounds_properties.release()); | 95 window_properties->Set(bounds_name, bounds_properties.release()); |
| 95 } | 96 } |
| 96 | 97 |
| 97 // Combines the constraints of the content and window, and returns constraints | |
| 98 // for the window. | |
| 99 gfx::Size GetCombinedWindowConstraints(const gfx::Size& window_constraints, | |
| 100 const gfx::Size& content_constraints, | |
| 101 const gfx::Insets& frame_insets) { | |
| 102 gfx::Size combined_constraints(window_constraints); | |
| 103 if (content_constraints.width() > 0) { | |
| 104 combined_constraints.set_width( | |
| 105 content_constraints.width() + frame_insets.width()); | |
| 106 } | |
| 107 if (content_constraints.height() > 0) { | |
| 108 combined_constraints.set_height( | |
| 109 content_constraints.height() + frame_insets.height()); | |
| 110 } | |
| 111 return combined_constraints; | |
| 112 } | |
| 113 | |
| 114 // Combines the constraints of the content and window, and returns constraints | |
| 115 // for the content. | |
| 116 gfx::Size GetCombinedContentConstraints(const gfx::Size& window_constraints, | |
| 117 const gfx::Size& content_constraints, | |
| 118 const gfx::Insets& frame_insets) { | |
| 119 gfx::Size combined_constraints(content_constraints); | |
| 120 if (window_constraints.width() > 0) { | |
| 121 combined_constraints.set_width( | |
| 122 std::max(0, window_constraints.width() - frame_insets.width())); | |
| 123 } | |
| 124 if (window_constraints.height() > 0) { | |
| 125 combined_constraints.set_height( | |
| 126 std::max(0, window_constraints.height() - frame_insets.height())); | |
| 127 } | |
| 128 return combined_constraints; | |
| 129 } | |
| 130 | |
| 131 } // namespace | 98 } // namespace |
| 132 | 99 |
| 133 // AppWindow::BoundsSpecification | |
| 134 | |
| 135 const int AppWindow::BoundsSpecification::kUnspecifiedPosition = INT_MIN; | |
| 136 | |
| 137 AppWindow::BoundsSpecification::BoundsSpecification() | |
| 138 : bounds(kUnspecifiedPosition, kUnspecifiedPosition, 0, 0) {} | |
| 139 | |
| 140 AppWindow::BoundsSpecification::~BoundsSpecification() {} | |
| 141 | |
| 142 void AppWindow::BoundsSpecification::ResetBounds() { | |
| 143 bounds.SetRect(kUnspecifiedPosition, kUnspecifiedPosition, 0, 0); | |
| 144 } | |
| 145 | |
| 146 // AppWindow::CreateParams | |
| 147 | |
| 148 AppWindow::CreateParams::CreateParams() | |
| 149 : window_type(AppWindow::WINDOW_TYPE_DEFAULT), | |
| 150 frame(AppWindow::FRAME_CHROME), | |
| 151 has_frame_color(false), | |
| 152 active_frame_color(SK_ColorBLACK), | |
| 153 inactive_frame_color(SK_ColorBLACK), | |
| 154 alpha_enabled(false), | |
| 155 is_ime_window(false), | |
| 156 creator_process_id(0), | |
| 157 state(ui::SHOW_STATE_DEFAULT), | |
| 158 hidden(false), | |
| 159 resizable(true), | |
| 160 focused(true), | |
| 161 always_on_top(false), | |
| 162 visible_on_all_workspaces(false) { | |
| 163 } | |
| 164 | |
| 165 AppWindow::CreateParams::~CreateParams() {} | |
| 166 | |
| 167 gfx::Rect AppWindow::CreateParams::GetInitialWindowBounds( | |
| 168 const gfx::Insets& frame_insets) const { | |
| 169 // Combine into a single window bounds. | |
| 170 gfx::Rect combined_bounds(window_spec.bounds); | |
| 171 if (content_spec.bounds.x() != BoundsSpecification::kUnspecifiedPosition) | |
| 172 combined_bounds.set_x(content_spec.bounds.x() - frame_insets.left()); | |
| 173 if (content_spec.bounds.y() != BoundsSpecification::kUnspecifiedPosition) | |
| 174 combined_bounds.set_y(content_spec.bounds.y() - frame_insets.top()); | |
| 175 if (content_spec.bounds.width() > 0) { | |
| 176 combined_bounds.set_width( | |
| 177 content_spec.bounds.width() + frame_insets.width()); | |
| 178 } | |
| 179 if (content_spec.bounds.height() > 0) { | |
| 180 combined_bounds.set_height( | |
| 181 content_spec.bounds.height() + frame_insets.height()); | |
| 182 } | |
| 183 | |
| 184 // Constrain the bounds. | |
| 185 SizeConstraints constraints( | |
| 186 GetCombinedWindowConstraints( | |
| 187 window_spec.minimum_size, content_spec.minimum_size, frame_insets), | |
| 188 GetCombinedWindowConstraints( | |
| 189 window_spec.maximum_size, content_spec.maximum_size, frame_insets)); | |
| 190 combined_bounds.set_size(constraints.ClampSize(combined_bounds.size())); | |
| 191 | |
| 192 return combined_bounds; | |
| 193 } | |
| 194 | |
| 195 gfx::Size AppWindow::CreateParams::GetContentMinimumSize( | |
| 196 const gfx::Insets& frame_insets) const { | |
| 197 return GetCombinedContentConstraints(window_spec.minimum_size, | |
| 198 content_spec.minimum_size, | |
| 199 frame_insets); | |
| 200 } | |
| 201 | |
| 202 gfx::Size AppWindow::CreateParams::GetContentMaximumSize( | |
| 203 const gfx::Insets& frame_insets) const { | |
| 204 return GetCombinedContentConstraints(window_spec.maximum_size, | |
| 205 content_spec.maximum_size, | |
| 206 frame_insets); | |
| 207 } | |
| 208 | |
| 209 gfx::Size AppWindow::CreateParams::GetWindowMinimumSize( | |
| 210 const gfx::Insets& frame_insets) const { | |
| 211 return GetCombinedWindowConstraints(window_spec.minimum_size, | |
| 212 content_spec.minimum_size, | |
| 213 frame_insets); | |
| 214 } | |
| 215 | |
| 216 gfx::Size AppWindow::CreateParams::GetWindowMaximumSize( | |
| 217 const gfx::Insets& frame_insets) const { | |
| 218 return GetCombinedWindowConstraints(window_spec.maximum_size, | |
| 219 content_spec.maximum_size, | |
| 220 frame_insets); | |
| 221 } | |
| 222 | |
| 223 // AppWindow | 100 // AppWindow |
| 224 | 101 |
| 225 AppWindow::AppWindow(BrowserContext* context, | 102 AppWindow::AppWindow(BrowserContext* context, |
| 226 AppDelegate* app_delegate, | 103 AppDelegate* app_delegate, |
| 227 const Extension* extension) | 104 const Extension* extension) |
| 228 : browser_context_(context), | 105 : browser_context_(context), |
| 229 extension_id_(extension->id()), | 106 extension_id_(extension->id()), |
| 230 window_type_(WINDOW_TYPE_DEFAULT), | 107 window_type_(native_app_window::WINDOW_TYPE_DEFAULT), |
| 231 app_delegate_(app_delegate), | 108 app_delegate_(app_delegate), |
| 232 image_loader_ptr_factory_(this), | 109 image_loader_ptr_factory_(this), |
| 233 fullscreen_types_(FULLSCREEN_TYPE_NONE), | 110 fullscreen_types_(native_app_window::FULLSCREEN_TYPE_NONE), |
| 234 show_on_first_paint_(false), | 111 show_on_first_paint_(false), |
| 235 first_paint_complete_(false), | 112 first_paint_complete_(false), |
| 236 has_been_shown_(false), | 113 has_been_shown_(false), |
| 237 can_send_events_(false), | 114 can_send_events_(false), |
| 238 is_hidden_(false), | 115 is_hidden_(false), |
| 239 cached_always_on_top_(false), | 116 cached_always_on_top_(false), |
| 240 requested_alpha_enabled_(false) { | 117 requested_alpha_enabled_(false) { |
| 241 ExtensionsBrowserClient* client = ExtensionsBrowserClient::Get(); | 118 ExtensionsBrowserClient* client = ExtensionsBrowserClient::Get(); |
| 242 CHECK(!client->IsGuestSession(context) || context->IsOffTheRecord()) | 119 CHECK(!client->IsGuestSession(context) || context->IsOffTheRecord()) |
| 243 << "Only off the record window may be opened in the guest mode."; | 120 << "Only off the record window may be opened in the guest mode."; |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 Maximize(); | 182 Maximize(); |
| 306 else if (new_params.state == ui::SHOW_STATE_MINIMIZED) | 183 else if (new_params.state == ui::SHOW_STATE_MINIMIZED) |
| 307 Minimize(); | 184 Minimize(); |
| 308 | 185 |
| 309 OnNativeWindowChanged(); | 186 OnNativeWindowChanged(); |
| 310 | 187 |
| 311 ExtensionRegistry::Get(browser_context_)->AddObserver(this); | 188 ExtensionRegistry::Get(browser_context_)->AddObserver(this); |
| 312 | 189 |
| 313 // Close when the browser process is exiting. | 190 // Close when the browser process is exiting. |
| 314 app_delegate_->SetTerminatingCallback( | 191 app_delegate_->SetTerminatingCallback( |
| 315 base::Bind(&NativeAppWindow::Close, | 192 base::Bind(&native_app_window::NativeAppWindow::Close, |
| 316 base::Unretained(native_app_window_.get()))); | 193 base::Unretained(native_app_window_.get()))); |
| 317 | 194 |
| 318 app_window_contents_->LoadContents(new_params.creator_process_id); | 195 app_window_contents_->LoadContents(new_params.creator_process_id); |
| 319 | 196 |
| 320 if (CommandLine::ForCurrentProcess()->HasSwitch( | 197 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 321 extensions::switches::kEnableAppsShowOnFirstPaint)) { | 198 extensions::switches::kEnableAppsShowOnFirstPaint)) { |
| 322 // We want to show the window only when the content has been painted. For | 199 // We want to show the window only when the content has been painted. For |
| 323 // that to happen, we need to define a size for the content, otherwise the | 200 // that to happen, we need to define a size for the content, otherwise the |
| 324 // layout will happen in a 0x0 area. | 201 // layout will happen in a 0x0 area. |
| 325 gfx::Insets frame_insets = native_app_window_->GetFrameInsets(); | 202 gfx::Insets frame_insets = native_app_window_->GetFrameInsets(); |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 425 | 302 |
| 426 void AppWindow::DidFirstVisuallyNonEmptyPaint() { | 303 void AppWindow::DidFirstVisuallyNonEmptyPaint() { |
| 427 first_paint_complete_ = true; | 304 first_paint_complete_ = true; |
| 428 if (show_on_first_paint_) { | 305 if (show_on_first_paint_) { |
| 429 DCHECK(delayed_show_type_ == SHOW_ACTIVE || | 306 DCHECK(delayed_show_type_ == SHOW_ACTIVE || |
| 430 delayed_show_type_ == SHOW_INACTIVE); | 307 delayed_show_type_ == SHOW_INACTIVE); |
| 431 Show(delayed_show_type_); | 308 Show(delayed_show_type_); |
| 432 } | 309 } |
| 433 } | 310 } |
| 434 | 311 |
| 435 void AppWindow::OnNativeClose() { | |
| 436 AppWindowRegistry::Get(browser_context_)->RemoveAppWindow(this); | |
| 437 if (app_window_contents_) { | |
| 438 WebContents* web_contents = app_window_contents_->GetWebContents(); | |
| 439 WebContentsModalDialogManager::FromWebContents(web_contents) | |
| 440 ->SetDelegate(NULL); | |
| 441 app_window_contents_->NativeWindowClosed(); | |
| 442 } | |
| 443 delete this; | |
| 444 } | |
| 445 | |
| 446 void AppWindow::OnNativeWindowChanged() { | |
| 447 SaveWindowPosition(); | |
| 448 | |
| 449 #if defined(OS_WIN) | |
| 450 if (native_app_window_ && cached_always_on_top_ && !IsFullscreen() && | |
| 451 !native_app_window_->IsMaximized() && | |
| 452 !native_app_window_->IsMinimized()) { | |
| 453 UpdateNativeAlwaysOnTop(); | |
| 454 } | |
| 455 #endif | |
| 456 | |
| 457 if (app_window_contents_ && native_app_window_) | |
| 458 app_window_contents_->NativeWindowChanged(native_app_window_.get()); | |
| 459 } | |
| 460 | |
| 461 void AppWindow::OnNativeWindowActivated() { | |
| 462 AppWindowRegistry::Get(browser_context_)->AppWindowActivated(this); | |
| 463 } | |
| 464 | |
| 465 content::WebContents* AppWindow::web_contents() const { | 312 content::WebContents* AppWindow::web_contents() const { |
| 466 return app_window_contents_->GetWebContents(); | 313 return app_window_contents_->GetWebContents(); |
| 467 } | 314 } |
| 468 | 315 |
| 469 const Extension* AppWindow::GetExtension() const { | 316 const Extension* AppWindow::GetExtension() const { |
| 470 return ExtensionRegistry::Get(browser_context_) | 317 return ExtensionRegistry::Get(browser_context_) |
| 471 ->enabled_extensions() | 318 ->enabled_extensions() |
| 472 .GetByID(extension_id_); | 319 .GetByID(extension_id_); |
| 473 } | 320 } |
| 474 | 321 |
| 475 NativeAppWindow* AppWindow::GetBaseWindow() { return native_app_window_.get(); } | 322 native_app_window::NativeAppWindow* AppWindow::GetBaseWindow() { |
| 323 return native_app_window_.get(); |
| 324 } |
| 476 | 325 |
| 477 gfx::NativeWindow AppWindow::GetNativeWindow() { | 326 gfx::NativeWindow AppWindow::GetNativeWindow() { |
| 478 return GetBaseWindow()->GetNativeWindow(); | 327 return GetBaseWindow()->GetNativeWindow(); |
| 479 } | 328 } |
| 480 | 329 |
| 481 gfx::Rect AppWindow::GetClientBounds() const { | 330 gfx::Rect AppWindow::GetClientBounds() const { |
| 482 gfx::Rect bounds = native_app_window_->GetBounds(); | 331 gfx::Rect bounds = native_app_window_->GetBounds(); |
| 483 bounds.Inset(native_app_window_->GetFrameInsets()); | 332 bounds.Inset(native_app_window_->GetFrameInsets()); |
| 484 return bounds; | 333 return bounds; |
| 485 } | 334 } |
| 486 | 335 |
| 487 base::string16 AppWindow::GetTitle() const { | |
| 488 const Extension* extension = GetExtension(); | |
| 489 if (!extension) | |
| 490 return base::string16(); | |
| 491 | |
| 492 // WebContents::GetTitle() will return the page's URL if there's no <title> | |
| 493 // specified. However, we'd prefer to show the name of the extension in that | |
| 494 // case, so we directly inspect the NavigationEntry's title. | |
| 495 base::string16 title; | |
| 496 if (!web_contents() || !web_contents()->GetController().GetActiveEntry() || | |
| 497 web_contents()->GetController().GetActiveEntry()->GetTitle().empty()) { | |
| 498 title = base::UTF8ToUTF16(extension->name()); | |
| 499 } else { | |
| 500 title = web_contents()->GetTitle(); | |
| 501 } | |
| 502 base::RemoveChars(title, base::ASCIIToUTF16("\n"), &title); | |
| 503 return title; | |
| 504 } | |
| 505 | |
| 506 void AppWindow::SetAppIconUrl(const GURL& url) { | 336 void AppWindow::SetAppIconUrl(const GURL& url) { |
| 507 // If the same url is being used for the badge, ignore it. | 337 // If the same url is being used for the badge, ignore it. |
| 508 if (url == badge_icon_url_) | 338 if (url == badge_icon_url_) |
| 509 return; | 339 return; |
| 510 | 340 |
| 511 // Avoid using any previous icons that were being downloaded. | 341 // Avoid using any previous icons that were being downloaded. |
| 512 image_loader_ptr_factory_.InvalidateWeakPtrs(); | 342 image_loader_ptr_factory_.InvalidateWeakPtrs(); |
| 513 | 343 |
| 514 // Reset |app_icon_image_| to abort pending image load (if any). | 344 // Reset |app_icon_image_| to abort pending image load (if any). |
| 515 app_icon_image_.reset(); | 345 app_icon_image_.reset(); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 543 badge_icon_image_.reset(); | 373 badge_icon_image_.reset(); |
| 544 badge_icon_url_ = GURL(); | 374 badge_icon_url_ = GURL(); |
| 545 UpdateBadgeIcon(gfx::Image()); | 375 UpdateBadgeIcon(gfx::Image()); |
| 546 } | 376 } |
| 547 | 377 |
| 548 void AppWindow::UpdateShape(scoped_ptr<SkRegion> region) { | 378 void AppWindow::UpdateShape(scoped_ptr<SkRegion> region) { |
| 549 native_app_window_->UpdateShape(region.Pass()); | 379 native_app_window_->UpdateShape(region.Pass()); |
| 550 } | 380 } |
| 551 | 381 |
| 552 void AppWindow::UpdateDraggableRegions( | 382 void AppWindow::UpdateDraggableRegions( |
| 553 const std::vector<DraggableRegion>& regions) { | 383 const std::vector<native_app_window::DraggableRegion>& regions) { |
| 554 native_app_window_->UpdateDraggableRegions(regions); | 384 native_app_window_->UpdateDraggableRegions(regions); |
| 555 } | 385 } |
| 556 | 386 |
| 557 void AppWindow::UpdateAppIcon(const gfx::Image& image) { | 387 void AppWindow::UpdateAppIcon(const gfx::Image& image) { |
| 558 if (image.IsEmpty()) | 388 if (image.IsEmpty()) |
| 559 return; | 389 return; |
| 560 app_icon_ = image; | 390 app_icon_ = image; |
| 561 native_app_window_->UpdateWindowIcon(); | 391 native_app_window_->UpdateWindowIcon(); |
| 562 AppWindowRegistry::Get(browser_context_)->AppWindowIconChanged(this); | 392 AppWindowRegistry::Get(browser_context_)->AppWindowIconChanged(this); |
| 563 } | 393 } |
| 564 | 394 |
| 565 void AppWindow::SetFullscreen(FullscreenType type, bool enable) { | 395 void AppWindow::SetFullscreen(native_app_window::FullscreenType type, |
| 566 DCHECK_NE(FULLSCREEN_TYPE_NONE, type); | 396 bool enable) { |
| 397 DCHECK_NE(native_app_window::FULLSCREEN_TYPE_NONE, type); |
| 567 | 398 |
| 568 if (enable) { | 399 if (enable) { |
| 569 #if !defined(OS_MACOSX) | 400 #if !defined(OS_MACOSX) |
| 570 // Do not enter fullscreen mode if disallowed by pref. | 401 // Do not enter fullscreen mode if disallowed by pref. |
| 571 // TODO(bartfab): Add a test once it becomes possible to simulate a user | 402 // TODO(bartfab): Add a test once it becomes possible to simulate a user |
| 572 // gesture. http://crbug.com/174178 | 403 // gesture. http://crbug.com/174178 |
| 573 if (type != FULLSCREEN_TYPE_FORCED) { | 404 if (type != native_app_window::FULLSCREEN_TYPE_FORCED) { |
| 574 PrefService* prefs = | 405 PrefService* prefs = |
| 575 ExtensionsBrowserClient::Get()->GetPrefServiceForContext( | 406 ExtensionsBrowserClient::Get()->GetPrefServiceForContext( |
| 576 browser_context()); | 407 browser_context()); |
| 577 if (!prefs->GetBoolean(pref_names::kAppFullscreenAllowed)) | 408 if (!prefs->GetBoolean(pref_names::kAppFullscreenAllowed)) |
| 578 return; | 409 return; |
| 579 } | 410 } |
| 580 #endif | 411 #endif |
| 581 fullscreen_types_ |= type; | 412 fullscreen_types_ |= type; |
| 582 } else { | 413 } else { |
| 583 fullscreen_types_ &= ~type; | 414 fullscreen_types_ &= ~type; |
| 584 } | 415 } |
| 585 SetNativeWindowFullscreen(); | 416 SetNativeWindowFullscreen(); |
| 586 } | 417 } |
| 587 | 418 |
| 588 bool AppWindow::IsFullscreen() const { | 419 bool AppWindow::IsFullscreen() const { |
| 589 return fullscreen_types_ != FULLSCREEN_TYPE_NONE; | 420 return fullscreen_types_ != native_app_window::FULLSCREEN_TYPE_NONE; |
| 590 } | 421 } |
| 591 | 422 |
| 592 bool AppWindow::IsForcedFullscreen() const { | 423 bool AppWindow::IsForcedFullscreen() const { |
| 593 return (fullscreen_types_ & FULLSCREEN_TYPE_FORCED) != 0; | 424 return (fullscreen_types_ & native_app_window::FULLSCREEN_TYPE_FORCED) != 0; |
| 594 } | 425 } |
| 595 | 426 |
| 596 bool AppWindow::IsHtmlApiFullscreen() const { | 427 bool AppWindow::IsHtmlApiFullscreen() const { |
| 597 return (fullscreen_types_ & FULLSCREEN_TYPE_HTML_API) != 0; | 428 return (fullscreen_types_ & native_app_window::FULLSCREEN_TYPE_HTML_API) != 0; |
| 598 } | 429 } |
| 599 | 430 |
| 600 void AppWindow::Fullscreen() { | 431 void AppWindow::Fullscreen() { |
| 601 SetFullscreen(FULLSCREEN_TYPE_WINDOW_API, true); | 432 SetFullscreen(native_app_window::FULLSCREEN_TYPE_WINDOW_API, true); |
| 602 } | 433 } |
| 603 | 434 |
| 604 void AppWindow::Maximize() { GetBaseWindow()->Maximize(); } | 435 void AppWindow::Maximize() { GetBaseWindow()->Maximize(); } |
| 605 | 436 |
| 606 void AppWindow::Minimize() { GetBaseWindow()->Minimize(); } | 437 void AppWindow::Minimize() { GetBaseWindow()->Minimize(); } |
| 607 | 438 |
| 608 void AppWindow::Restore() { | 439 void AppWindow::Restore() { |
| 609 if (IsFullscreen()) { | 440 if (IsFullscreen()) { |
| 610 fullscreen_types_ = FULLSCREEN_TYPE_NONE; | 441 fullscreen_types_ = native_app_window::FULLSCREEN_TYPE_NONE; |
| 611 SetNativeWindowFullscreen(); | 442 SetNativeWindowFullscreen(); |
| 612 } else { | 443 } else { |
| 613 GetBaseWindow()->Restore(); | 444 GetBaseWindow()->Restore(); |
| 614 } | 445 } |
| 615 } | 446 } |
| 616 | 447 |
| 617 void AppWindow::OSFullscreen() { | 448 void AppWindow::OSFullscreen() { |
| 618 SetFullscreen(FULLSCREEN_TYPE_OS, true); | 449 SetFullscreen(native_app_window::FULLSCREEN_TYPE_OS, true); |
| 619 } | 450 } |
| 620 | 451 |
| 621 void AppWindow::ForcedFullscreen() { | 452 void AppWindow::ForcedFullscreen() { |
| 622 SetFullscreen(FULLSCREEN_TYPE_FORCED, true); | 453 SetFullscreen(native_app_window::FULLSCREEN_TYPE_FORCED, true); |
| 623 } | 454 } |
| 624 | 455 |
| 625 void AppWindow::SetContentSizeConstraints(const gfx::Size& min_size, | 456 void AppWindow::SetContentSizeConstraints(const gfx::Size& min_size, |
| 626 const gfx::Size& max_size) { | 457 const gfx::Size& max_size) { |
| 627 SizeConstraints constraints(min_size, max_size); | 458 SizeConstraints constraints(min_size, max_size); |
| 628 native_app_window_->SetContentSizeConstraints(constraints.GetMinimumSize(), | 459 native_app_window_->SetContentSizeConstraints(constraints.GetMinimumSize(), |
| 629 constraints.GetMaximumSize()); | 460 constraints.GetMaximumSize()); |
| 630 | 461 |
| 631 gfx::Rect bounds = GetClientBounds(); | 462 gfx::Rect bounds = GetClientBounds(); |
| 632 gfx::Size constrained_size = constraints.ClampSize(bounds.size()); | 463 gfx::Size constrained_size = constraints.ClampSize(bounds.size()); |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 909 bool enter_fullscreen) { | 740 bool enter_fullscreen) { |
| 910 const Extension* extension = GetExtension(); | 741 const Extension* extension = GetExtension(); |
| 911 if (!extension) | 742 if (!extension) |
| 912 return; | 743 return; |
| 913 | 744 |
| 914 if (!IsExtensionWithPermissionOrSuggestInConsole( | 745 if (!IsExtensionWithPermissionOrSuggestInConsole( |
| 915 APIPermission::kFullscreen, extension, source->GetRenderViewHost())) { | 746 APIPermission::kFullscreen, extension, source->GetRenderViewHost())) { |
| 916 return; | 747 return; |
| 917 } | 748 } |
| 918 | 749 |
| 919 SetFullscreen(FULLSCREEN_TYPE_HTML_API, enter_fullscreen); | 750 SetFullscreen(native_app_window::FULLSCREEN_TYPE_HTML_API, enter_fullscreen); |
| 920 } | 751 } |
| 921 | 752 |
| 922 bool AppWindow::IsFullscreenForTabOrPending(const content::WebContents* source) | 753 bool AppWindow::IsFullscreenForTabOrPending(const content::WebContents* source) |
| 923 const { | 754 const { |
| 924 return IsHtmlApiFullscreen(); | 755 return IsHtmlApiFullscreen(); |
| 925 } | 756 } |
| 926 | 757 |
| 927 void AppWindow::OnExtensionUnloaded(content::BrowserContext* browser_context, | 758 void AppWindow::OnExtensionUnloaded(content::BrowserContext* browser_context, |
| 928 const Extension* extension, | 759 const Extension* extension, |
| 929 UnloadedExtensionInfo::Reason reason) { | 760 UnloadedExtensionInfo::Reason reason) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 944 | 775 |
| 945 void AppWindow::SetWebContentsBlocked(content::WebContents* web_contents, | 776 void AppWindow::SetWebContentsBlocked(content::WebContents* web_contents, |
| 946 bool blocked) { | 777 bool blocked) { |
| 947 app_delegate_->SetWebContentsBlocked(web_contents, blocked); | 778 app_delegate_->SetWebContentsBlocked(web_contents, blocked); |
| 948 } | 779 } |
| 949 | 780 |
| 950 bool AppWindow::IsWebContentsVisible(content::WebContents* web_contents) { | 781 bool AppWindow::IsWebContentsVisible(content::WebContents* web_contents) { |
| 951 return app_delegate_->IsWebContentsVisible(web_contents); | 782 return app_delegate_->IsWebContentsVisible(web_contents); |
| 952 } | 783 } |
| 953 | 784 |
| 785 content::WebContents* AppWindow::GetWebContents() { |
| 786 return web_contents(); |
| 787 } |
| 788 |
| 789 content::BrowserContext* AppWindow::GetBrowserContext() { |
| 790 return browser_context(); |
| 791 } |
| 792 |
| 793 void AppWindow::OnNativeClose() { |
| 794 AppWindowRegistry::Get(browser_context_)->RemoveAppWindow(this); |
| 795 if (app_window_contents_) { |
| 796 WebContents* web_contents = app_window_contents_->GetWebContents(); |
| 797 WebContentsModalDialogManager::FromWebContents(web_contents) |
| 798 ->SetDelegate(NULL); |
| 799 app_window_contents_->NativeWindowClosed(); |
| 800 } |
| 801 delete this; |
| 802 } |
| 803 |
| 804 void AppWindow::OnNativeWindowChanged() { |
| 805 SaveWindowPosition(); |
| 806 |
| 807 #if defined(OS_WIN) |
| 808 if (native_app_window_ && cached_always_on_top_ && !IsFullscreen() && |
| 809 !native_app_window_->IsMaximized() && |
| 810 !native_app_window_->IsMinimized()) { |
| 811 UpdateNativeAlwaysOnTop(); |
| 812 } |
| 813 #endif |
| 814 |
| 815 if (app_window_contents_ && native_app_window_) |
| 816 app_window_contents_->NativeWindowChanged(native_app_window_.get()); |
| 817 } |
| 818 |
| 819 void AppWindow::OnNativeWindowActivated() { |
| 820 AppWindowRegistry::Get(browser_context_)->AppWindowActivated(this); |
| 821 } |
| 822 |
| 823 bool AppWindow::RequestedAlphaEnabled() const { |
| 824 return requested_alpha_enabled(); |
| 825 } |
| 826 |
| 827 base::string16 AppWindow::GetTitle() const { |
| 828 const Extension* extension = GetExtension(); |
| 829 if (!extension) |
| 830 return base::string16(); |
| 831 |
| 832 // WebContents::GetTitle() will return the page's URL if there's no <title> |
| 833 // specified. However, we'd prefer to show the name of the extension in that |
| 834 // case, so we directly inspect the NavigationEntry's title. |
| 835 base::string16 title; |
| 836 if (!web_contents() || !web_contents()->GetController().GetActiveEntry() || |
| 837 web_contents()->GetController().GetActiveEntry()->GetTitle().empty()) { |
| 838 title = base::UTF8ToUTF16(extension->name()); |
| 839 } else { |
| 840 title = web_contents()->GetTitle(); |
| 841 } |
| 842 base::RemoveChars(title, base::ASCIIToUTF16("\n"), &title); |
| 843 return title; |
| 844 } |
| 845 |
| 846 native_app_window::WindowType AppWindow::GetWindowType() const { |
| 847 return window_type(); |
| 848 } |
| 849 |
| 850 bool AppWindow::WindowTypeIsPanel() const { |
| 851 return window_type_is_panel(); |
| 852 } |
| 853 |
| 954 WebContentsModalDialogHost* AppWindow::GetWebContentsModalDialogHost() { | 854 WebContentsModalDialogHost* AppWindow::GetWebContentsModalDialogHost() { |
| 955 return native_app_window_.get(); | 855 return native_app_window_.get(); |
| 956 } | 856 } |
| 957 | 857 |
| 958 void AppWindow::SaveWindowPosition() { | 858 void AppWindow::SaveWindowPosition() { |
| 959 if (window_key_.empty()) | 859 if (window_key_.empty()) |
| 960 return; | 860 return; |
| 961 if (!native_app_window_) | 861 if (!native_app_window_) |
| 962 return; | 862 return; |
| 963 | 863 |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1046 | 946 |
| 1047 // Since we are restoring a cached state, reset the content bounds spec to | 947 // Since we are restoring a cached state, reset the content bounds spec to |
| 1048 // ensure it is not used. | 948 // ensure it is not used. |
| 1049 params.content_spec.ResetBounds(); | 949 params.content_spec.ResetBounds(); |
| 1050 } | 950 } |
| 1051 } | 951 } |
| 1052 | 952 |
| 1053 return params; | 953 return params; |
| 1054 } | 954 } |
| 1055 | 955 |
| 1056 // static | |
| 1057 SkRegion* AppWindow::RawDraggableRegionsToSkRegion( | |
| 1058 const std::vector<DraggableRegion>& regions) { | |
| 1059 SkRegion* sk_region = new SkRegion; | |
| 1060 for (std::vector<DraggableRegion>::const_iterator iter = regions.begin(); | |
| 1061 iter != regions.end(); | |
| 1062 ++iter) { | |
| 1063 const DraggableRegion& region = *iter; | |
| 1064 sk_region->op( | |
| 1065 region.bounds.x(), | |
| 1066 region.bounds.y(), | |
| 1067 region.bounds.right(), | |
| 1068 region.bounds.bottom(), | |
| 1069 region.draggable ? SkRegion::kUnion_Op : SkRegion::kDifference_Op); | |
| 1070 } | |
| 1071 return sk_region; | |
| 1072 } | |
| 1073 | |
| 1074 } // namespace extensions | 956 } // namespace extensions |
| OLD | NEW |