OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/ui/extensions/shell_window.h" | 5 #include "chrome/browser/ui/extensions/shell_window.h" |
6 | 6 |
7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
8 #include "base/values.h" | 8 #include "base/values.h" |
9 #include "chrome/browser/extensions/app_window_contents.h" | 9 #include "chrome/browser/extensions/app_window_contents.h" |
10 #include "chrome/browser/extensions/extension_process_manager.h" | 10 #include "chrome/browser/extensions/extension_process_manager.h" |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 const int kPreferredIconSize = extension_misc::EXTENSION_ICON_SMALL; | 66 const int kPreferredIconSize = extension_misc::EXTENSION_ICON_SMALL; |
67 #endif | 67 #endif |
68 | 68 |
69 } // namespace | 69 } // namespace |
70 | 70 |
71 ShellWindow::CreateParams::CreateParams() | 71 ShellWindow::CreateParams::CreateParams() |
72 : window_type(ShellWindow::WINDOW_TYPE_DEFAULT), | 72 : window_type(ShellWindow::WINDOW_TYPE_DEFAULT), |
73 frame(ShellWindow::FRAME_CHROME), | 73 frame(ShellWindow::FRAME_CHROME), |
74 transparent_background(false), | 74 transparent_background(false), |
75 bounds(INT_MIN, INT_MIN, 0, 0), | 75 bounds(INT_MIN, INT_MIN, 0, 0), |
76 creator_process_id(0), hidden(false), resizable(true), focused(true) { | 76 creator_process_id(0), |
| 77 state(STATE_NORMAL), |
| 78 hidden(false), |
| 79 resizable(true), |
| 80 focused(true) { |
77 } | 81 } |
78 | 82 |
79 ShellWindow::CreateParams::~CreateParams() { | 83 ShellWindow::CreateParams::~CreateParams() { |
80 } | 84 } |
81 | 85 |
82 ShellWindow* ShellWindow::Create(Profile* profile, | 86 ShellWindow* ShellWindow::Create(Profile* profile, |
83 const extensions::Extension* extension, | 87 const extensions::Extension* extension, |
84 const GURL& url, | 88 const GURL& url, |
85 const CreateParams& params) { | 89 const CreateParams& params) { |
86 // This object will delete itself when the window is closed. | 90 // This object will delete itself when the window is closed. |
87 ShellWindow* window = new ShellWindow(profile, extension); | 91 ShellWindow* window = new ShellWindow(profile, extension); |
88 window->Init(url, new AppWindowContents(window), params); | 92 window->Init(url, new AppWindowContents(window), params); |
89 extensions::ShellWindowRegistry::Get(profile)->AddShellWindow(window); | 93 extensions::ShellWindowRegistry::Get(profile)->AddShellWindow(window); |
90 return window; | 94 return window; |
91 } | 95 } |
92 | 96 |
93 ShellWindow::ShellWindow(Profile* profile, | 97 ShellWindow::ShellWindow(Profile* profile, |
94 const extensions::Extension* extension) | 98 const extensions::Extension* extension) |
95 : profile_(profile), | 99 : profile_(profile), |
96 extension_(extension), | 100 extension_(extension), |
97 window_type_(WINDOW_TYPE_DEFAULT), | 101 window_type_(WINDOW_TYPE_DEFAULT), |
98 ALLOW_THIS_IN_INITIALIZER_LIST(image_loader_ptr_factory_(this)) { | 102 ALLOW_THIS_IN_INITIALIZER_LIST(image_loader_ptr_factory_(this)), |
| 103 fullscreen_for_window_api_(false), |
| 104 fullscreen_for_tab_(false) { |
99 } | 105 } |
100 | 106 |
101 void ShellWindow::Init(const GURL& url, | 107 void ShellWindow::Init(const GURL& url, |
102 ShellWindowContents* shell_window_contents, | 108 ShellWindowContents* shell_window_contents, |
103 const ShellWindow::CreateParams& params) { | 109 const ShellWindow::CreateParams& params) { |
104 // Initialize the render interface and web contents | 110 // Initialize the render interface and web contents |
105 shell_window_contents_.reset(shell_window_contents); | 111 shell_window_contents_.reset(shell_window_contents); |
106 shell_window_contents_->Initialize(profile(), url); | 112 shell_window_contents_->Initialize(profile(), url); |
107 WebContents* web_contents = shell_window_contents_->GetWebContents(); | 113 WebContents* web_contents = shell_window_contents_->GetWebContents(); |
108 WebContentsModalDialogManager::CreateForWebContents(web_contents); | 114 WebContentsModalDialogManager::CreateForWebContents(web_contents); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 if (maximum_size.height() && bounds.height() > maximum_size.height()) | 162 if (maximum_size.height() && bounds.height() > maximum_size.height()) |
157 bounds.set_height(maximum_size.height()); | 163 bounds.set_height(maximum_size.height()); |
158 if (bounds.height() != INT_MIN && bounds.height() < minimum_size.height()) | 164 if (bounds.height() != INT_MIN && bounds.height() < minimum_size.height()) |
159 bounds.set_height(minimum_size.height()); | 165 bounds.set_height(minimum_size.height()); |
160 | 166 |
161 new_params.bounds = bounds; | 167 new_params.bounds = bounds; |
162 | 168 |
163 native_app_window_.reset(NativeAppWindow::Create(this, new_params)); | 169 native_app_window_.reset(NativeAppWindow::Create(this, new_params)); |
164 OnNativeWindowChanged(); | 170 OnNativeWindowChanged(); |
165 | 171 |
| 172 switch (params.state) { |
| 173 case CreateParams::STATE_NORMAL: |
| 174 break; |
| 175 case CreateParams::STATE_FULLSCREEN: |
| 176 Fullscreen(); |
| 177 break; |
| 178 case CreateParams::STATE_MAXIMIZED: |
| 179 Maximize(); |
| 180 break; |
| 181 case CreateParams::STATE_MINIMIZED: |
| 182 Minimize(); |
| 183 break; |
| 184 } |
| 185 |
166 if (!params.hidden) { | 186 if (!params.hidden) { |
167 if (window_type_is_panel()) | 187 if (window_type_is_panel()) |
168 GetBaseWindow()->ShowInactive(); // Panels are not activated by default. | 188 GetBaseWindow()->ShowInactive(); // Panels are not activated by default. |
169 else | 189 else |
170 GetBaseWindow()->Show(); | 190 GetBaseWindow()->Show(); |
171 } | 191 } |
172 | 192 |
173 // When the render view host is changed, the native window needs to know | 193 // When the render view host is changed, the native window needs to know |
174 // about it in case it has any setup to do to make the renderer appear | 194 // about it in case it has any setup to do to make the renderer appear |
175 // properly. In particular, on Windows, the view's clickthrough region needs | 195 // properly. In particular, on Windows, the view's clickthrough region needs |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
373 } | 393 } |
374 | 394 |
375 void ShellWindow::UpdateAppIcon(const gfx::Image& image) { | 395 void ShellWindow::UpdateAppIcon(const gfx::Image& image) { |
376 if (image.IsEmpty()) | 396 if (image.IsEmpty()) |
377 return; | 397 return; |
378 app_icon_ = image; | 398 app_icon_ = image; |
379 native_app_window_->UpdateWindowIcon(); | 399 native_app_window_->UpdateWindowIcon(); |
380 extensions::ShellWindowRegistry::Get(profile_)->ShellWindowIconChanged(this); | 400 extensions::ShellWindowRegistry::Get(profile_)->ShellWindowIconChanged(this); |
381 } | 401 } |
382 | 402 |
| 403 void ShellWindow::Fullscreen() { |
| 404 fullscreen_for_window_api_ = true; |
| 405 GetBaseWindow()->SetFullscreen(true); |
| 406 } |
| 407 |
| 408 void ShellWindow::Maximize() { |
| 409 GetBaseWindow()->Maximize(); |
| 410 } |
| 411 |
| 412 void ShellWindow::Minimize() { |
| 413 GetBaseWindow()->Minimize(); |
| 414 } |
| 415 |
| 416 void ShellWindow::Restore() { |
| 417 fullscreen_for_window_api_ = false; |
| 418 fullscreen_for_tab_ = false; |
| 419 if (GetBaseWindow()->IsFullscreenOrPending()) { |
| 420 GetBaseWindow()->SetFullscreen(false); |
| 421 } else { |
| 422 GetBaseWindow()->Restore(); |
| 423 } |
| 424 } |
| 425 |
383 //------------------------------------------------------------------------------ | 426 //------------------------------------------------------------------------------ |
384 // Private methods | 427 // Private methods |
385 | 428 |
386 void ShellWindow::OnImageLoaded(const gfx::Image& image) { | 429 void ShellWindow::OnImageLoaded(const gfx::Image& image) { |
387 UpdateAppIcon(image); | 430 UpdateAppIcon(image); |
388 } | 431 } |
389 | 432 |
390 void ShellWindow::DidDownloadFavicon(int id, | 433 void ShellWindow::DidDownloadFavicon(int id, |
391 const GURL& image_url, | 434 const GURL& image_url, |
392 int requested_size, | 435 int requested_size, |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
446 void ShellWindow::NavigationStateChanged( | 489 void ShellWindow::NavigationStateChanged( |
447 const content::WebContents* source, unsigned changed_flags) { | 490 const content::WebContents* source, unsigned changed_flags) { |
448 if (changed_flags & content::INVALIDATE_TYPE_TITLE) | 491 if (changed_flags & content::INVALIDATE_TYPE_TITLE) |
449 native_app_window_->UpdateWindowTitle(); | 492 native_app_window_->UpdateWindowTitle(); |
450 else if (changed_flags & content::INVALIDATE_TYPE_TAB) | 493 else if (changed_flags & content::INVALIDATE_TYPE_TAB) |
451 native_app_window_->UpdateWindowIcon(); | 494 native_app_window_->UpdateWindowIcon(); |
452 } | 495 } |
453 | 496 |
454 void ShellWindow::ToggleFullscreenModeForTab(content::WebContents* source, | 497 void ShellWindow::ToggleFullscreenModeForTab(content::WebContents* source, |
455 bool enter_fullscreen) { | 498 bool enter_fullscreen) { |
456 bool has_permission = IsExtensionWithPermissionOrSuggestInConsole( | 499 if (!IsExtensionWithPermissionOrSuggestInConsole( |
457 APIPermission::kFullscreen, | 500 APIPermission::kFullscreen, |
458 extension_, | 501 extension_, |
459 source->GetRenderViewHost()); | 502 source->GetRenderViewHost())) { |
| 503 return; |
| 504 } |
460 | 505 |
461 if (has_permission) | 506 fullscreen_for_tab_ = enter_fullscreen; |
462 native_app_window_->SetFullscreen(enter_fullscreen); | 507 |
| 508 if (enter_fullscreen) { |
| 509 native_app_window_->SetFullscreen(true); |
| 510 } else if (!fullscreen_for_window_api_) { |
| 511 native_app_window_->SetFullscreen(false); |
| 512 } |
463 } | 513 } |
464 | 514 |
465 bool ShellWindow::IsFullscreenForTabOrPending( | 515 bool ShellWindow::IsFullscreenForTabOrPending( |
466 const content::WebContents* source) const { | 516 const content::WebContents* source) const { |
467 return native_app_window_->IsFullscreenOrPending(); | 517 return fullscreen_for_tab_; |
468 } | 518 } |
469 | 519 |
470 void ShellWindow::Observe(int type, | 520 void ShellWindow::Observe(int type, |
471 const content::NotificationSource& source, | 521 const content::NotificationSource& source, |
472 const content::NotificationDetails& details) { | 522 const content::NotificationDetails& details) { |
473 switch (type) { | 523 switch (type) { |
474 case content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED: { | 524 case content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED: { |
475 // TODO(jianli): once http://crbug.com/123007 is fixed, we'll no longer | 525 // TODO(jianli): once http://crbug.com/123007 is fixed, we'll no longer |
476 // need to make the native window (ShellWindowViews specially) update | 526 // need to make the native window (ShellWindowViews specially) update |
477 // the clickthrough region for the new RVH. | 527 // the clickthrough region for the new RVH. |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
532 const extensions::DraggableRegion& region = *iter; | 582 const extensions::DraggableRegion& region = *iter; |
533 sk_region->op( | 583 sk_region->op( |
534 region.bounds.x(), | 584 region.bounds.x(), |
535 region.bounds.y(), | 585 region.bounds.y(), |
536 region.bounds.right(), | 586 region.bounds.right(), |
537 region.bounds.bottom(), | 587 region.bounds.bottom(), |
538 region.draggable ? SkRegion::kUnion_Op : SkRegion::kDifference_Op); | 588 region.draggable ? SkRegion::kUnion_Op : SkRegion::kDifference_Op); |
539 } | 589 } |
540 return sk_region; | 590 return sk_region; |
541 } | 591 } |
OLD | NEW |